你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

az role assignment

管理角色分配。

命令

az role assignment create

为用户、组或服务主体创建新的角色分配。

az role assignment delete

删除角色分配。

az role assignment list

列出角色分配。

az role assignment list-changelogs

列出角色分配的更改日志。

az role assignment update

更新用户、组或服务主体的现有角色分配。

az role assignment create

为用户、组或服务主体创建新的角色分配。

--scope 参数将成为在 2023 年秋季的中断性变更版本中创建角色分配所必需的。 请显式指定 --scope。

az role assignment create --role
                          [--assignee]
                          [--assignee-object-id]
                          [--assignee-principal-type {ForeignGroup, Group, ServicePrincipal, User}]
                          [--condition]
                          [--condition-version]
                          [--description]
                          [--name]
                          [--resource-group]
                          [--scope]

示例

创建角色分配,向指定的受让人授予 Azure 虚拟机上的“读取者”角色。

az role assignment create --assignee sp_name --role Reader --scope /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/virtualMachines/MyVm

为具有说明和条件的被代理人创建角色分配。

az role assignment create --role Owner --scope /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MyResourceGroup/providers/Microsoft.Storage/storageAccounts/MyStorageAccount --assignee "John.Doe@Contoso.com" --description "Role assignment foo to check on bar" --condition "@Resource[Microsoft.Storage/storageAccounts/blobServices/containers:Name] stringEquals 'foo'" --condition-version "2.0"

使用自己的分配名称创建角色分配。

az role assignment create --assignee-object-id 00000000-0000-0000-0000-000000000000 --assignee-principal-type ServicePrincipal --role Reader --scope /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MyResourceGroup --name 00000000-0000-0000-0000-000000000000

必需参数

--role

角色名称或 ID。

可选参数

--assignee

表示用户、组或服务主体。 支持的格式:对象 ID、用户登录名或服务主体名称。

--assignee-object-id

如果权限不足,请使用此参数而不是“--assignee”来绕过图形 API调用。 此参数仅适用于用户、组、服务主体和托管标识的对象 ID。 对于托管标识,请使用主体 ID。对于服务主体,请使用对象 ID,而不是应用 ID。

--assignee-principal-type

将 与 --assignee-object-id 一起使用,以避免 AAD Graph 中的传播延迟导致的错误。

接受的值: ForeignGroup, Group, ServicePrincipal, User
--condition

可授予用户权限的条件。

--condition-version

条件语法的版本。 如果指定了不带 --condition-version 的 --condition,则默认为 2.0。

--description

角色分配的说明。

--name -n

角色分配的 GUID。 对于每个角色分配,它必须唯一且不同。 如果省略,则会生成新的 GUID。

--resource-group -g

仅当角色或分配是在资源组级别添加的时,才使用它。

--scope

角色分配或定义应用于的范围,例如/subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333、/subscriptions/0b1f6471-1bf0-4dda-aec3-11112222333/resourceGroups/myGroup, 或 /subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333/resourceGroups/myGroups/myGroup/providers/Microsoft.Compute/virtualMachines/myVM。

az role assignment delete

删除角色分配。

az role assignment delete [--assignee]
                          [--ids]
                          [--include-inherited]
                          [--resource-group]
                          [--role]
                          [--scope]
                          [--yes]

示例

删除角色分配。 (自动生成的)

az role assignment delete --assignee 00000000-0000-0000-0000-000000000000 --role "Storage Account Key Operator Service Role"

可选参数

--assignee

表示用户、组或服务主体。 支持的格式:对象 ID、用户登录名或服务主体名称。

--ids

以空格分隔的角色分配 ID。

--include-inherited

包括应用于父范围的分配。

默认值: False
--resource-group -g

仅当角色或分配是在资源组级别添加的时,才使用它。

--role

角色名称或 ID。

--scope

角色分配或定义应用于的范围,例如/subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333、/subscriptions/0b1f6471-1bf0-4dda-aec3-11112222333/resourceGroups/myGroup, 或 /subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333/resourceGroups/myGroups/myGroup/providers/Microsoft.Compute/virtualMachines/myVM。

--yes -y

继续删除订阅下的所有分配。

az role assignment list

列出角色分配。

默认情况下,只会列出局限于订阅的分配。 若要查看按资源或组来确定范围的分配,请使用 --all

az role assignment list [--all]
                        [--assignee]
                        [--include-classic-administrators {false, true}]
                        [--include-groups]
                        [--include-inherited]
                        [--resource-group]
                        [--role]
                        [--scope]

可选参数

--all

显示当前订阅下的所有分配。

默认值: False
--assignee

表示用户、组或服务主体。 支持的格式:对象 ID、用户登录名或服务主体名称。

--include-classic-administrators

列出订阅经典管理员(又名共同管理员)的默认角色分配。

接受的值: false, true
默认值: False
--include-groups

包括用户所属的组的额外分配, (可传递) 。

默认值: False
--include-inherited

包括应用于父范围的分配。

默认值: False
--resource-group -g

仅当角色或分配是在资源组级别添加的时,才使用它。

--role

角色名称或 ID。

--scope

角色分配或定义应用于的范围,例如/subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333、/subscriptions/0b1f6471-1bf0-4dda-aec3-11112222333/resourceGroups/myGroup, 或 /subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333/resourceGroups/myGroups/myGroup/providers/Microsoft.Compute/virtualMachines/myVM。

az role assignment list-changelogs

列出角色分配的更改日志。

az role assignment list-changelogs [--end-time]
                                   [--start-time]

可选参数

--end-time

查询的结束时间,格式为 %Y-%m-%dT%H:%M:%SZ,例如 2000-12-31T12:59:59Z。 默认为当前时间。

--start-time

查询的开始时间,格式为 %Y-%m-%dT%H:%M:%SZ,例如 2000-12-31T12:59:59Z。 默认为当前时间之前的 1 小时。

az role assignment update

更新用户、组或服务主体的现有角色分配。

az role assignment update --role-assignment

示例

从 JSON 文件更新角色分配。

az role assignment update --role-assignment assignment.json

从 JSON 字符串更新角色分配。 (Bash)

az role assignment update --role-assignment '{
    "canDelegate": null,
    "condition": "@Resource[Microsoft.Storage/storageAccounts/blobServices/containers:Name] stringEquals '"'"'foo'"'"'",
    "conditionVersion": "2.0",
    "description": "Role assignment foo to check on bar",
    "id": "/subscriptions/00000001-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.Authorization/roleAssignments/3eabdd43-375b-4dbd-8dc4-04acd15ce56b",
    "name": "3eabdd43-375b-4dbd-8dc4-04acd15ce56b",
    "principalId": "00000002-0000-0000-0000-000000000000",
    "principalType": "User",
    "resourceGroup": "rg1",
    "roleDefinitionId": "/subscriptions/00000001-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/acdd72a7-3385-48ef-bd42-f606fba81ae7",
    "scope": "/subscriptions/00000001-0000-0000-0000-000000000000/resourceGroups/rg1",
    "type": "Microsoft.Authorization/roleAssignments"
}'

必需参数

--role-assignment

描述 JSON 形式的现有角色分配,或包含 JSON 说明的文件的路径。