az role definition

管理角色定義。

命令

名稱 Description 類型 狀態
az role definition create

建立自訂角色定義。

核心 GA
az role definition delete

刪除角色定義。

核心 GA
az role definition list

列出角色定義。

核心 GA
az role definition update

更新角色定義。

核心 GA

az role definition create

建立自訂角色定義。

az role definition create --role-definition

範例

建立具有儲存體和網路資源唯讀存取權的角色,以及啟動或重新開機 VM 的能力。 (巴什)

az role definition create --role-definition '{
    "Name": "Contoso On-call",
    "Description": "Perform VM actions and read storage and network information.",
    "Actions": [
        "Microsoft.Compute/*/read",
        "Microsoft.Compute/virtualMachines/start/action",
        "Microsoft.Compute/virtualMachines/restart/action",
        "Microsoft.Network/*/read",
        "Microsoft.Storage/*/read",
        "Microsoft.Authorization/*/read",
        "Microsoft.Resources/subscriptions/resourceGroups/read",
        "Microsoft.Resources/subscriptions/resourceGroups/resources/read",
        "Microsoft.Insights/alertRules/*",
        "Microsoft.Support/*"
    ],
    "DataActions": [
        "Microsoft.Storage/storageAccounts/blobServices/containers/blobs/*"
    ],
    "NotDataActions": [
        "Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write"
    ],
    "AssignableScopes": ["/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"]
}'

從包含 JSON 描述的檔案建立角色。

az role definition create --role-definition @ad-role.json

必要參數

--role-definition

角色描述為 JSON,或包含 JSON 描述的檔案路徑。

全域參數
--debug

增加記錄詳細資訊,以顯示所有偵錯記錄。

--help -h

顯示此說明訊息並結束。

--only-show-errors

只顯示錯誤,隱藏警告。

--output -o

輸出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
預設值: json
--query

JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--verbose

增加記錄詳細資訊。 使用 --debug 來取得完整偵錯記錄。

az role definition delete

刪除角色定義。

az role definition delete --name
                          [--custom-role-only {false, true}]
                          [--resource-group]
                          [--scope]

範例

刪除角色定義。 (自動產生)

az role definition delete --name MyRole

必要參數

--name -n

角色的名稱。

選擇性參數

--custom-role-only

僅限自訂角色(與內建角色的比較)。

接受的值: false, true
預設值: False
--resource-group -g

只有在資源群組層級新增角色或指派時,才使用它。

--scope

角色指派或定義適用的範圍,例如 /subscriptions/0b1f6471-1bf0-4dda-aec3-1111222223333、/subscriptions/0b1f6471-1bf0-4dda-aec3-11112222333/resourceGroups/myGroup, 或 /subscriptions/0b1f6471-1bf0-4dda-aec3-111112222333/resourceGroups/myGroup/providers/Microsoft.Compute/virtualMachines/myVM。

全域參數
--debug

增加記錄詳細資訊,以顯示所有偵錯記錄。

--help -h

顯示此說明訊息並結束。

--only-show-errors

只顯示錯誤,隱藏警告。

--output -o

輸出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
預設值: json
--query

JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--verbose

增加記錄詳細資訊。 使用 --debug 來取得完整偵錯記錄。

az role definition list

列出角色定義。

az role definition list [--custom-role-only {false, true}]
                        [--name]
                        [--resource-group]
                        [--scope]

選擇性參數

--custom-role-only

僅限自訂角色(與內建角色的比較)。

接受的值: false, true
預設值: False
--name -n

角色的名稱。

--resource-group -g

只有在資源群組層級新增角色或指派時,才使用它。

--scope

角色指派或定義適用的範圍,例如 /subscriptions/0b1f6471-1bf0-4dda-aec3-1111222223333、/subscriptions/0b1f6471-1bf0-4dda-aec3-11112222333/resourceGroups/myGroup, 或 /subscriptions/0b1f6471-1bf0-4dda-aec3-111112222333/resourceGroups/myGroup/providers/Microsoft.Compute/virtualMachines/myVM。

全域參數
--debug

增加記錄詳細資訊,以顯示所有偵錯記錄。

--help -h

顯示此說明訊息並結束。

--only-show-errors

只顯示錯誤,隱藏警告。

--output -o

輸出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
預設值: json
--query

JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--verbose

增加記錄詳細資訊。 使用 --debug 來取得完整偵錯記錄。

az role definition update

更新角色定義。

az role definition update --role-definition

範例

使用 「az role definition list」 的輸出來更新角色。 (巴什)

az role definition update --role-definition '{
    "roleName": "Contoso On-call",
    "Description": "Perform VM actions and read storage and network information.",
    "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.Authorization/roleDefinitions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "roleType": "CustomRole",
    "type": "Microsoft.Authorization/roleDefinitions",
    "Actions": [
        "Microsoft.Compute/*/read",
        "Microsoft.Compute/virtualMachines/start/action",
        "Microsoft.Compute/virtualMachines/restart/action",
        "Microsoft.Network/*/read",
        "Microsoft.Storage/*/read",
        "Microsoft.Authorization/*/read",
        "Microsoft.Resources/subscriptions/resourceGroups/read",
        "Microsoft.Resources/subscriptions/resourceGroups/resources/read",
        "Microsoft.Support/*"
    ],
    "DataActions": [
        "Microsoft.Storage/storageAccounts/blobServices/containers/blobs/*"
    ],
    "NotDataActions": [
        "Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write"
    ],
    "AssignableScopes": ["/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"]
}'

必要參數

--role-definition

現有角色的描述為 JSON,或包含 JSON 描述的檔案路徑。

全域參數
--debug

增加記錄詳細資訊,以顯示所有偵錯記錄。

--help -h

顯示此說明訊息並結束。

--only-show-errors

只顯示錯誤,隱藏警告。

--output -o

輸出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
預設值: json
--query

JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--verbose

增加記錄詳細資訊。 使用 --debug 來取得完整偵錯記錄。