azure - 带有托管标识的事件网格 API 连接的 ARM 模板
问题描述
从逻辑应用创建新的事件网格连接时,可以从以下 3 种连接身份验证方法中进行选择:
- 登入
- 服务主体
- 托管身份
#1 登录要求用户以交互方式登录/验证。
#2 服务主体需要提供Tenant、Client ID和Client 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 连接提供 ARM 模板,我们将不胜感激。
解决方案
由于您可以拥有多个用户托管身份,因此仅选择 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 视图来获取该信息。
推荐阅读
- php - 使用 while 循环根据从 SQL 数据库中提取的信息创建 HTML 表单
- excel - 如何写入现有的excel文件
- spring-cloud-task - 如何从外部应用程序触发 Spring Cloud 任务?
- json - Swift 从 JSON 请求生成通用函数
- react-admin - 在 react-admin 中编辑嵌套 protobuf 字段的最佳方法?
- apache - apache2反向代理配置
- android - 对象是如何创建的?
- ruby - 在`main`对象上调用RSpec测试方法
- mysql - 使用 javadriver 将 Matlab 连接到没有数据库工具箱的 MY SQL 数据库
- c# - 如何验证贝宝付款是否真实 C#