Api 正在 Azure 容器应用程序上运行,用户分配的身份为 uai_1。 Apim 正在使用用户分配的身份 uai_2 运行。我已经设置了 api 策略(请参阅下面的代码),以便 apim 可以调用 api,这是正确的方法吗?我没有以任何方式保护 api - 任何有关这方面的指导将不胜感激,例如为 api 等创建 azure 广告应用程序注册 - 不确定。
<policies>
<inbound>
<authentication-managed-identity resource="client id of user assigned identity uai_1" client-id="client id of user assigned identity uai_2" ignore-error="false"/>
</inbound>
</policies>
这是文档所说的https://learn.microsoft.com/en-us/azure/api-management/authentication-management-identity-policy
API 策略使用其用户分配的身份与后端 api 来验证 apim,该后端 api 受 azure ad 或 easy auth 保护:
<inbound>
<cors allow-credentials="true">
<allowed-origins>
<origin>the origin url of web app</origin>
</allowed-origins>
<allowed-methods preflight-result-max-age="300">
<method>*</method>
</allowed-methods>
<allowed-headers>
<header>*</header>
</allowed-headers>
<expose-headers>
<header>*</header>
</expose-headers>
</cors>
<authentication-managed-identity resource="b147569f-643a-4d3b-b0e4-55750750f770" client-id="e880ad99-c842-49ee-9d71-5f51e40c8a08" output-token-variable-name="msi-access-token" ignore-error="false"/>
<set-header name="Authorization" exists-action="override">
<value>@("Bearer " + (string)context.Variables["msi-access-token"])</value>
</set-header>
</inbound>
b147569f-643a-4d3b-b0e4-55750750f770 是后端 api 的
client_id
e880ad99-c842-49ee-9d71-5f51e40c8a08 是 apim uai 的
client_id