使用管理组大规模管理 Azure 订阅

如果你的组织有多个订阅,则可能需要一种方法来高效地管理这些订阅的访问权限、策略和符合性。 Azure 管理组提供订阅上的作用域级别。 可将订阅组织到名为“管理组”的容器中,并将管理条件应用到管理组。 管理组中的所有订阅都将自动继承应用于管理组的条件。

不管使用什么类型的订阅,管理组都能提供大规模的企业级管理。 有关管理组的详细信息,请参阅使用 Azure 管理组整理资源

注意

本文介绍如何删除设备或服务中的个人数据,并且可用于为 GDPR 下的义务提供支持。 有关 GDPR 的常规信息,请参阅 Microsoft 信任中心的 GDPR 部分服务信任门户的 GDPR 部分

重要

Azure 资源管理器用户令牌和管理组缓存持续 30 分钟后才会被强制刷新。 执行任何操作(如移动管理组或订阅)后,最多可能需要 30 分钟才会显示该操作。 如果想更快看到更新,需要通过刷新浏览器、登录并注销来更新令牌,或者请求新令牌。

重要

AzManagementGroup 相关 Az PowerShell cmdlet 提到 -GroupId 是 -GroupName 参数的别名,因此,我们可以使用其中任一参数提供管理组 ID 作为字符串值。

更改管理组的名称

可以使用门户、PowerShell 或 Azure CLI 更改管理组的名称。

在门户中更改名称

  1. 登录到 Azure 门户

  2. 选择“所有服务”>“管理组”。

  3. 选择要重命名的管理组。

  4. 选择“详细信息”。

  5. 选择页面顶部的“重命名组”选项。

    Screenshot of the action bar and the 'Rename Group' button on the management group page.

  6. 菜单打开后,请输入要显示的新名称。

    Screenshot of the Rename Group window and options to rename a management group.

  7. 选择“保存”。

在 PowerShell 中更改名称

若要更新显示名称,请使用 Update-AzManagementGroup。 例如,若要将管理组的显示名称从“Contoso IT”更改为“Contoso Group”,可运行以下命令:

Update-AzManagementGroup -GroupId 'ContosoIt' -DisplayName 'Contoso Group'

在 Azure CLI 中更改名称

在 Azure CLI 中使用 update 命令。

az account management-group update --name 'Contoso' --display-name 'Contoso Group'

删除管理组

若要删除某个管理组,必须满足以下要求:

  1. 该管理组下面没有任何子管理组或订阅。 若要将订阅或管理组移到另一个管理组,请参阅在层次结构中移动管理组和订阅

  2. 你需要拥有对管理组的写入权限(“所有者”、“参与者”或“管理组参与者”)。 若要查看自己拥有哪些权限,请选择管理组,然后选择“IAM”。 若要详细了解 Azure 角色,请参阅 Azure 基于角色的访问控制 (Azure RBAC)

在门户中删除

  1. 登录到 Azure 门户

  2. 选择“所有服务”>“管理组”。

  3. 选择要删除的管理组。

  4. 选择“详细信息”。

  5. 选择“删除”

    Screenshot of the Management group page with the 'Delete' button highlighted.

    提示

    如果该图标已禁用,将鼠标指针悬停在该图标上可显示原因。

  6. 此时会打开一个窗口,让你确认是否要删除该管理组。

    Screenshot of the 'Delete group' confirmation dialog for deleting a management group.

  7. 选择 “是”

在 PowerShell 中删除

在 PowerShell 中使用 Remove-AzManagementGroup 命令删除管理组。

Remove-AzManagementGroup -GroupId 'Contoso'

在 Azure CLI 中删除

在 Azure CLI 中,可以使用 az account management-group delete 命令。

az account management-group delete --name 'Contoso'

查看管理组

可以查看你对其拥有直接管理角色或继承 Azure 角色的任何管理组。

在门户中查看

  1. 登录到 Azure 门户

  2. 选择“所有服务”>“管理组”。

  3. 将加载管理组层次结构页。 可以在此页面中浏览你有权访问的所有管理组和订阅。 选择组名会将你带到层次结构的较低级别。 导航的工作方式与文件资源管理器一样。

  4. 若要查看管理组的详细信息,请选择管理组标题旁边的“(详细信息)”链接。 如果此链接不可用,则表示你无权查看该管理组。

    Screenshot of the Management groups page showing child management groups and subscriptions.

在 PowerShell 中查看

使用 Get-AzManagementGroup 命令可检索所有组。 请参阅 Az.Resources 模块,查看管理组 GET PowerShell 命令的完整列表。

Get-AzManagementGroup

若要查看单个管理组的信息,请使用 -GroupId 参数

Get-AzManagementGroup -GroupId 'Contoso'

若要返回特定管理组及其下层次结构的所有级别,请使用 -Expand 和 -Recurse 参数。

PS C:\> $response = Get-AzManagementGroup -GroupId TestGroupParent -Expand -Recurse
PS C:\> $response

Id                : /providers/Microsoft.Management/managementGroups/TestGroupParent
Type              : /providers/Microsoft.Management/managementGroups
Name              : TestGroupParent
TenantId          : 00000000-0000-0000-0000-000000000000
DisplayName       : TestGroupParent
UpdatedTime       : 2/1/2018 11:15:46 AM
UpdatedBy         : 00000000-0000-0000-0000-000000000000
ParentId          : /providers/Microsoft.Management/managementGroups/00000000-0000-0000-0000-000000000000
ParentName        : 00000000-0000-0000-0000-000000000000
ParentDisplayName : 00000000-0000-0000-0000-000000000000
Children          : {TestGroup1DisplayName, TestGroup2DisplayName}

PS C:\> $response.Children[0]

Type        : /managementGroup
Id          : /providers/Microsoft.Management/managementGroups/TestGroup1
Name        : TestGroup1
DisplayName : TestGroup1DisplayName
Children    : {TestRecurseChild}

PS C:\> $response.Children[0].Children[0]

Type        : /managementGroup
Id          : /providers/Microsoft.Management/managementGroups/TestRecurseChild
Name        : TestRecurseChild
DisplayName : TestRecurseChild
Children    :

在 Azure CLI 中查看

使用 list 命令可以检索所有组。

az account management-group list

若要查看单个管理组的信息,请使用 show 命令

az account management-group show --name 'Contoso'

若要返回特定管理组及其下层次结构的所有级别,请使用 -Expand 和 -Recurse 参数。

az account management-group show --name 'Contoso' -e -r

移动管理组和订阅

创建管理组的原因之一是将订阅捆绑在一起。 只能将管理组和订阅设置为另一个管理组的子级。 移到管理组的订阅从父管理组继承所有用户访问权限和策略

将管理组或订阅移动为另一个管理组的子项时,三项规则的计算结果都需要为 true。

如果要执行移动操作,则需要对以下各层具有权限:

  • 子订阅/管理组
    • Microsoft.management/managementgroups/write
    • Microsoft.management/managementgroups/subscription/write(仅适用于订阅)
    • Microsoft.Authorization/roleAssignments/write
    • Microsoft.Authorization/roleAssignments/delete
    • Microsoft.Management/register/action
  • 目标父管理组
    • Microsoft.management/managementgroups/write
  • 当前父管理组
    • Microsoft.management/managementgroups/write

例外:如果目标或现有父管理组不是根管理组,则权限要求不适用。 由于根管理组是所有新管理组和订阅的默认登陆点,因此不需在其上具有相关权限即可移动某个项。

如果订阅上的“所有者”角色继承自当前管理组,则你的移动目标会受限。 只能将订阅移到你在其中拥有“所有者”角色的另一管理组。 不能将订阅移到你在其中仅是参与者的管理组,因为你会失去订阅的所有权。 如果你已被直接分配了订阅的“所有者”角色,则可将它移到你在其中是参与者的任何管理组。

若要查看自己在 Azure 门户中拥有哪些权限,请选择管理组,然后选择“IAM”。 若要详细了解 Azure 角色,请参阅 Azure 基于角色的访问控制 (Azure RBAC)

移动订阅

在门户中将现有订阅添加到管理组

  1. 登录到 Azure 门户

  2. 选择“所有服务”>“管理组”。

  3. 选择要设为父级的管理组。

  4. 在页面顶部,选择“添加订阅”。

  5. 在列表中选择具有正确 ID 的订阅。

    Screenshot of the 'Add subscription' options for selecting an existing subscription to add to a management group.

  6. 选择“保存”。

在门户中从管理组删除订阅

  1. 登录到 Azure 门户

  2. 选择“所有服务”>“管理组”。

  3. 选择要设为当前父级的管理组。

  4. 在列表中,选择要移动的订阅所在行末尾的椭圆。

    Screenshot of the alternative menu for a subscription to select the 'Move' option.

  5. 选择“移动”。

  6. 在打开的菜单中,选择“父管理组”。

    Screenshot of the 'Move' window and options for moving a subscription to a different management group.

  7. 选择“保存”。

在 PowerShell 中移动订阅

若要在 PowerShell 中移动订阅,请使用 New-AzManagementGroupSubscription 命令。

New-AzManagementGroupSubscription -GroupId 'Contoso' -SubscriptionId '12345678-1234-1234-1234-123456789012'

若要删除订阅与管理组之间的链接,请使用 Remove-AzManagementGroupSubscription 命令。

Remove-AzManagementGroupSubscription -GroupId 'Contoso' -SubscriptionId '12345678-1234-1234-1234-123456789012'

在 Azure CLI 中移动订阅

若要在 CLI 中移动订阅,请使用 add 命令。

az account management-group subscription add --name 'Contoso' --subscription '12345678-1234-1234-1234-123456789012'

若要从管理组中删除订阅,请使用 subscription remove 命令。

az account management-group subscription remove --name 'Contoso' --subscription '12345678-1234-1234-1234-123456789012'

在 ARM 模板中移动订阅

若要在 Azure 资源管理器模板(ARM 模板)中移动订阅,请使用以下模板并将其部署在租户级别上。

{
    "$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "targetMgId": {
            "type": "string",
            "metadata": {
                "description": "Provide the ID of the management group that you want to move the subscription to."
            }
        },
        "subscriptionId": {
            "type": "string",
            "metadata": {
                "description": "Provide the ID of the existing subscription to move."
            }
        }
    },
    "resources": [
        {
            "scope": "/",
            "type": "Microsoft.Management/managementGroups/subscriptions",
            "apiVersion": "2020-05-01",
            "name": "[concat(parameters('targetMgId'), '/', parameters('subscriptionId'))]",
            "properties": {
            }
        }
    ],
    "outputs": {}
}

或者,以下 Bicep 文件。

targetScope = 'managementGroup'

@description('Provide the ID of the management group that you want to move the subscription to.')
param targetMgId string

@description('Provide the ID of the existing subscription to move.')
param subscriptionId string

resource subToMG 'Microsoft.Management/managementGroups/subscriptions@2020-05-01' = {
  scope: tenant()
  name: '${targetMgId}/${subscriptionId}'
}

移动管理组

在门户中移动管理组

  1. 登录到 Azure 门户

  2. 选择“所有服务”>“管理组”。

  3. 选择要设为父级的管理组。

  4. 在页面顶部,选择“添加管理组”。

  5. 在打开的菜单中,选择要使用新管理组或现有管理组。

    • 选择新管理组将创建一个新管理组。
    • 选择现有管理组将显示所有管理组的下拉列表,这些管理组可移动到此管理组。

    Screenshot of the 'Add management group' options for creating a new management group.

  6. 选择“保存”。

在 PowerShell 中移动管理组

在 PowerShell 中使用 Update-AzManagementGroup 命令将管理组移到不同的组下面。

$parentGroup = Get-AzManagementGroup -GroupId ContosoIT
Update-AzManagementGroup -GroupId 'Contoso' -ParentId $parentGroup.id

在 Azure CLI 中移动管理组

在 Azure CLI 中使用 update 命令移动管理组。

az account management-group update --name 'Contoso' --parent ContosoIT

使用活动日志审核管理组

Azure 活动日志支持管理组。 可查询发生在与其他 Azure 资源位于相同中心位置的管理组上的所有事件。 例如,可以看到对特定管理组所做的所有角色分配或策略分配更改。

Screenshot of Activity Logs and operations related to the selected management group.

如果要在 Azure 门户外针对管理组进行查询,管理组的目标范围将如下所示: "/providers/Microsoft.Management/managementGroups/{yourMgID}"

从其他资源提供程序引用管理组

从其他资源提供程序的操作引用管理组时,请使用以下路径作为作用域。 使用 PowerShell、Azure CLI 和 REST API 时,将使用此路径。

/providers/Microsoft.Management/managementGroups/{yourMgID}

在 PowerShell 中向管理组分配新的角色分配时使用此路径的示例:

New-AzRoleAssignment -Scope "/providers/Microsoft.Management/managementGroups/Contoso"

在管理组处检索策略定义时使用相同的范围路径。

GET https://management.chinacloudapi.cn/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming?api-version=2019-09-01

后续步骤

若要了解有关管理组的详细信息,请参阅: