首页 > 解决方案 > 带有托管标识的事件网格 API 连接的 ARM 模板

问题描述

从逻辑应用创建新的事件网格连接时,可以从以下 3 种连接身份验证方法中进行选择:

  1. 登入
  2. 服务主体
  3. 托管身份

#1 登录要求用户以交互方式登录/验证。

#2 服务主体需要提供TenantClient IDClient Secret值。

很明显,需要如何修改此类 API 连接的 ARM 模板:parameterValues需要添加如下。

"parameterValues": {
  "token:clientId": "[parameters('ConnectionClientId')]",
  "token:clientSecret": "[parameters('ConnectionClientSecret')]",
  "token:TenantId": "[parameters('ConnectionTenantId')]",
  "token:resourceUri": "https://management.core.windows.net/",
  "token:grantType": "client_credentials"
}

#3 托管标识只需要选择托管标识。虽然很清楚如何以交互方式创建这样的 API 连接,但我找不到关于这种身份验证方法的 ARM 模板格式的任何信息。

所以问题是 - 用于事件网格连接的 ARM 模板与(更新用户分配的)托管标识应该是什么样子的?这样创建的 API 连接如下所示:

与托管标识的 API 连接

更新:我需要在我的逻辑应用程序中使用用户分配的托管标识。下面提供了一个答案,该答案适用于系统分配的托管身份,但不适用于用户分配的身份。如果有人可以为使用用户分配的托管标识的 API 连接提供 ARM 模板,我们将不胜感激。

标签: azureazure-logic-appsazure-resource-managerazure-eventgrid

解决方案


由于您可以拥有多个用户托管身份,因此仅选择 ManagedServiceIdentity 是不够的。相反,您必须包含您希望使用的身份的 ID。

扩展@jim-xu 的回答:

示例连接:

    {
        "type": "Microsoft.Web/connections",
        "apiVersion": "2016-06-01",
        "name": "[variables('eventApiConnectionName')]",
        "location": "[resourceGroup().location]",
        "kind": "V1",
        "tags": "[parameters('resourceTags')]",
        "properties": {
            "displayName": "[variables('eventApiConnectionName')]",
            "customParameterValues": {},
            "api": {
                "id": "[subscriptionResourceId('Microsoft.Web/locations/managedApis', resourceGroup().location, 'azureeventgrid')]"
            },
            "parameterValueType": "Alternative"
        }
    }

这里的 parameterValueType 是一个重要的设置。如微软文档中所述:

如果使用 ARM 模板自动部署,并且逻辑应用工作流包含使用托管标识的托管连接器触发器或操作,请确认基础连接资源定义包含 parameterValueType 属性,其中 Alternative 作为属性值。否则,您的 ARM 部署将不会设置连接以使用托管标识进行身份验证...

然后逻辑应用引用该连接,并将标识作为 resourceId 包含在内:

"$connections": {
                    "value": {
                        "azureeventgrid": {
                            "connectionId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Web/connections/', variables('eventApiConnectionName'))]",
                            "connectionName": "[variables('eventApiConnectionName')]",
                            "connectionProperties": {
                                "authentication": {
                                    "type": "ManagedServiceIdentity",
                                    "identity": "[parameters('userManagedIdentity')]"
                                }
                            },
                            "id": "[concat('/subscriptions/',subscription().subscriptionId, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/azureeventgrid')]"
                        }
                    }
                }

请注意在eventgrid 连接部分中添加的identity字段。authentication

有关这方面的更多信息,请参阅 Microsoft 文档:https ://docs.microsoft.com/en-us/azure/logic-apps/create-managed-service-identity?tabs=consumption#create-user-assigned-identity -in-an-arm-template-consumption-only

标识值应该是托管标识的 ID。您可以通过 Azure 门户查看托管标识的 JSON 视图来获取该信息。


推荐阅读