问题描述
我正在尝试通过 ARM 模板将服务总线接收器角色添加到用户分配的托管标识。
这是模板
// User Assigned Managed Identity
{
"type": "Microsoft.ManagedIdentity/userAssignedIdentities","apiVersion": "2018-11-30","name": "MyManagedIdentity","location": "[resourceGroup().location]",},// User Assigned Managed Identity Role
{
"type": "Microsoft.Authorization/roleAssignments","apiVersion": "2020-04-01-preview","name": "[guid(resourceGroup().id)]","dependsOn": [
"[resourceID('Microsoft.ManagedIdentity/userAssignedIdentities/','MyManagedIdentity')]"
],"properties": {
"roleDeFinitionId": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleDeFinitions/090c5cfd-751d-490a-894a-3ce6f1109419","principalId": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities','MyManagedIdentity'),'2018-11-30').principalId]",}
},
它返回这个错误。
状态消息:不允许更新租户 ID、应用程序 ID、主体 ID 和范围。 (代码:RoleAssignmentUpdateNotPermitted)
我不确定出了什么问题。
我看过这个快速入门。 https://docs.microsoft.com/en-us/azure/role-based-access-control/quickstart-role-assignments-template
principalId 应该来自我认为的托管身份。以及来自服务总线角色的 id 的 roleDeFinitionId。
解决方法
您面临的问题是当您第一次部署 ARM 模板时,最近创建的身份尚未完全复制,因此 您可能会注意到安全主体(用户、组、服务主体或托管标识)被列为未找到身份,具有未知类型。
当您尝试通过重新部署模板来更新相同的角色分配时,它会给您错误“租户 ID、应用程序 ID、主体 ID 和范围不允许更新”,因为角色分配同名ID已存在且不允许更新。
更好的选择是您首先使用单独的模板创建身份,然后创建角色分配。对于Azure 服务总线数据接收器,模板中的 ID 应为:
/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/4f6d3b9b-027b-4f4c-9142-0e5a2a2247e0
有关详细信息,请参阅此 documentation。