【问题标题】:ARM template for RoleAssignment at Mgmt Group Level用于管理组级别 RoleAssignment 的 ARM 模板
【发布时间】:2021-02-06 05:21:03
【问题描述】:

我正在尝试创建一个将 RBAC 角色分配给管理组级别的组的 arm 模板。我可以通过 CLI 和 PowerShell 来实现,但无法通过 ARM 模板实现

{
    "$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "roleDefinitionId": {
            "type": "string",
            "defaultValue": "xxxx",
            "metadata": {
                "description": "roleDefinition for the assignment - default is reader"
            }
        }
    },
    "variables": {
        "roleAssignmentName": "[guid('/', variables('xxx'), parameters('roleDefinitionId'))]"
    },
    "resources": [
        {
            "name": "[variables('roleAssignmentName')]",
            "type": "Microsoft.Authorization/roleAssignments",
            "apiVersion": "2020-04-01-preview",
            "scope": "/providers/Microsoft.Management/managementGroups/xxxx",
            "properties": {
                "mode": "Incremental",
                "roleDefinitionId": "xxx",
                "principalId": "xxxx",
                "principalType": "Group"
            }
        }
    ]
}

有谁知道是否支持 MGMT 组,如果支持,我做错了什么?

这是 ARM Role Assignment https://docs.microsoft.com/en-us/azure/role-based-access-control/role-assignments-template 的官方文档,它显示为 Subs 和 Resources Groups 执行此操作

【问题讨论】:

  • 你能告诉我你的错误信息吗?
  • 这是我遇到的错误之一validResourceType", "message": "The resource type 'managementGroups' could not be found in the namespace 'Microsoft.Management' for api version '2020-04-01-preview'. The supported api-versions are '2020-10-01,2020-05-01,2020-02-01,2019-11-01,2018-03-01-preview,2018-01-01-preview,2017-11-01-preview,2017-08-31-preview,2017-06-30-preview,2017-05-31-preview,2018-03-01-beta'."
  • 你只是想将模板部署到一组吗?
  • 是的,尝试了顶部列出的 api 版本之一,但都不起作用

标签: azure azure-resource-manager arm-template rbac


【解决方案1】:

从资源定义中删除范围属性...

TLDR; roleAssignments 只能在它们被分配到的范围内部署,因此该属性是无关的。此外,范围属性不适用于 managementGroup 扩展资源(我知道令人困惑),这只是一个时间间隔。 scope 属性通常用于将资源定位到不同的范围(即与模板部署本身不同),但由于 roleAssignments 无法重新定位,因此您不需要它,并且在这种情况下会给您带来问题。

这是我的示例(注意我没有 principalType 属性,所以它使用默认值):

{
    "$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "principalId": {
        "type": "string",
        "metadata": {
          "description": "principalId if the user that will be given contributor access to the resourceGroup"
        }
      },
      "roleDefinitionId": {
        "type": "string",
        "defaultValue": "b24988ac-6180-42a0-ab88-20f7382dd24c",
        "metadata": {
          "description": "roleDefinition for the assignment - default is contributor"
        }
      },
      "managementGroupName": {
        "type": "string",
        "metadata": {
          "description": "Name of the managementGroup for the roleAssignment"
        }
      }
    },
    "variables": {
      // this creates an idempotent GUID for the role assignment
      "roleAssignmentName": "[guid(parameters('managementGroupName'), parameters('principalId'), parameters('roleDefinitionId'))]"
     },
    "resources": [
      {
        "type": "Microsoft.Authorization/roleAssignments",
        "apiVersion": "2020-04-01-preview",
        "name": "[variables('roleAssignmentName')]",
        "properties": {
          "roleDefinitionId": "[tenantResourceId('Microsoft.Authorization/roleDefinitions', parameters('roleDefinitionId'))]",
          "principalId": "[parameters('principalId')]"
        }
      }
    ]
  }

【讨论】:

    猜你喜欢
    • 2020-05-14
    • 2020-12-08
    • 1970-01-01
    • 2020-12-13
    • 2021-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多