【发布时间】:2022-06-13 18:07:40
【问题描述】:
在二头肌中,我正在配置一个 Azure API 管理策略,该策略为特定后端应用服务启用托管服务标识。
这通常通过像这样设置一个 XML 片段来完成:
<policies>
<inbound>
<authentication-managed-identity resource="4d192d04-XXXX-461f-a6ab-XXXXXXXXXXXX" />
<base />
</inbound>
</policies>
我现在正在寻找的是如何在我的二头肌模板中从现有应用服务中检索特定的 resource id。
下面是我现有的二头肌模板的一些片段:
// The App Service declaration
@description('API Website')
resource backendapi 'Microsoft.Web/sites@2021-03-01' = {
name: 'backend-${environment}'
kind: 'app,linux,container'
location: location
// left out properties, etc for brevity
// This is where I want to retrieve the client ID from that web app, but this fails:
var managed_identity_id = backendapi.identity.principalId
部署上述模板时,出现以下异常(尽管 Visual Studio Code 智能感知指示 identity.principalId 有效。
语言表达式属性 'identity' 不存在,可用属性有 'apiVersion, location, tags, kind, properties, condition, deploymentResourceLineInfo, existing, isConditionTrue, subscriptionId, resourceGroupName, scope, resourceId, referenceApiVersion, isTemplateResource, isAction , 供应操作'
所以我的问题是,如何从应用服务访问二头肌文件中的属性。属性值如下图所示:
【问题讨论】:
-
您指定了身份吗?身份:{类型:'SystemAssigned'}
-
是的,您正在尝试获取应用注册的客户端 ID 以对您的应用进行身份验证,而不是您应用的托管身份。身份验证设置应该为您提供所需的内容。
标签: azure azure-api-management azure-appservice azure-bicep