了解 Azure 角色定義

如果您嘗試瞭解 Azure 角色的運作方式,或正在建立自己的 Azure 自定義角色,瞭解角色的定義方式會很有説明。 本文說明角色定義的詳細數據,並提供一些範例。

角色定義

角色定義是一個權限集合。 它有時只是被稱為角色。 角色定義會列出可執行的動作,例如讀取、寫入和刪除。 它也可以列出從允許的動作或基礎數據相關的動作中排除的動作。

以下顯示使用 Azure PowerShell 顯示的角色定義中屬性範例:

Name
Id
IsCustom
Description
Actions []
NotActions []
DataActions []
NotDataActions []
AssignableScopes []
Condition
ConditionVersion

以下顯示使用 Azure CLIREST API 顯示的角色定義中屬性範例:

roleName
name
id
roleType
type
description
actions []
notActions []
dataActions []
notDataActions []
assignableScopes []
condition
conditionVersion
createdOn
updatedOn
createdBy
updatedBy

下表描述角色屬性的意義。

屬性 說明
Name
roleName
角色的顯示名稱。
Id
name
角色的唯一標識碼。 內建角色在雲端之間具有相同的角色標識碼。
id 角色的完整唯一標識碼。
IsCustom
roleType
指出此角色是否為自定義角色。 設定為 trueCustomRole 用於自定義角色。 設定為 falseBuiltInRole 用於內建角色。
type 物件的類型。 設定為 Microsoft.Authorization/roleDefinitions
Description
description
角色的描述。
Actions
actions
字串陣列,指定角色允許執行的控制平面動作。
NotActions
notActions
字串陣列,指定從允許 Actions排除的控制平面動作。
DataActions
dataActions
字串數位,指定角色允許對該物件內的數據執行的數據平面動作。
NotDataActions
notDataActions
字串陣列,指定從允許 DataActions排除的數據平面動作。
AssignableScopes
assignableScopes
字串數位,指定角色可供指派的範圍。
Condition
condition
針對內建角色,根據角色定義中的一或多個動作,條件語句。
ConditionVersion
conditionVersion
條件版本號碼。 默認為 2.0,且是唯一支援的版本。
createdOn 建立日期和時間角色。
updatedOn 上次更新日期和時間角色。
createdBy 針對自定義角色,建立角色的主體。
updatedBy 針對自定義角色,更新角色的主體。

動作格式

動作會以具有下列格式的字串指定:

  • {Company}.{ProviderName}/{resourceType}/{action}

{action}動作字串的部分會指定您可以在資源類型上執行的動作類型。 例如,您會在 中看到 {action}下列子字串:

動作子字串 描述
* 通配符會授與符合字串之所有動作的存取權。
read 啟用讀取動作(GET)。
write 啟用寫入動作(PUT 或 PATCH)。
action 啟用自定義動作,例如重新啟動虛擬機 (POST)。
delete 啟用刪除動作 (DELETE)。

角色定義範例

以下是 Azure PowerShell 和 Azure CLI 中顯示的參與者 角色定義。 下的Actions通配符 (*) 動作表示指派給此角色的主體可以執行所有動作,或者換句話說,它可以管理所有專案。 這包括未來 Azure 新增資源類型時所定義的動作。 底下的 NotActions 動作會從 Actions減去。 在參與者角色的情況下NotActions移除此角色管理資源的存取權,以及管理 Azure 藍圖指派的能力。

Azure PowerShell 中顯示的參與者角色:

{
  "Name": "Contributor",
  "Id": "b24988ac-6180-42a0-ab88-20f7382dd24c",
  "IsCustom": false,
  "Description": "Grants full access to manage all resources, but does not allow you to assign roles in Azure RBAC, manage assignments in Azure Blueprints, or share image galleries.",
  "Actions": [
    "*"
  ],
  "NotActions": [
    "Microsoft.Authorization/*/Delete",
    "Microsoft.Authorization/*/Write",
    "Microsoft.Authorization/elevateAccess/Action",
    "Microsoft.Blueprint/blueprintAssignments/write",
    "Microsoft.Blueprint/blueprintAssignments/delete",
    "Microsoft.Compute/galleries/share/action",
    "Microsoft.Purview/consents/write",
    "Microsoft.Purview/consents/delete"
  ],
  "DataActions": [],
  "NotDataActions": [],
  "AssignableScopes": [
    "/"
  ],
  "Condition": null,
  "ConditionVersion": null
}

Azure CLI 中顯示的參與者角色:

[
  {
    "assignableScopes": [
      "/"
    ],
    "createdBy": null,
    "createdOn": "2015-02-02T21:55:09.880642+00:00",
    "description": "Grants full access to manage all resources, but does not allow you to assign roles in Azure RBAC, manage assignments in Azure Blueprints, or share image galleries.",
    "id": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c",
    "name": "b24988ac-6180-42a0-ab88-20f7382dd24c",
    "permissions": [
      {
        "actions": [
          "*"
        ],
        "condition": null,
        "conditionVersion": null,
        "dataActions": [],
        "notActions": [
          "Microsoft.Authorization/*/Delete",
          "Microsoft.Authorization/*/Write",
          "Microsoft.Authorization/elevateAccess/Action",
          "Microsoft.Blueprint/blueprintAssignments/write",
          "Microsoft.Blueprint/blueprintAssignments/delete",
          "Microsoft.Compute/galleries/share/action",
          "Microsoft.Purview/consents/write",
          "Microsoft.Purview/consents/delete"
        ],
        "notDataActions": []
      }
    ],
    "roleName": "Contributor",
    "roleType": "BuiltInRole",
    "type": "Microsoft.Authorization/roleDefinitions",
    "updatedBy": null,
    "updatedOn": "2023-07-10T15:10:53.947865+00:00"
  }
]

控制件和數據動作

控制平面動作的角色型訪問控制是在角色定義的 和 NotActions 屬性中Actions指定。 以下是 Azure 中控制平面動作的一些範例:

  • 管理記憶體帳戶的存取權
  • 建立、更新或刪除 Blob 容器
  • 刪除資源群組及其所有資源

控制平面存取不會繼承至您的數據平面,前提是容器驗證方法設定為 Azure AD 用戶帳戶 ,而不是 存取密鑰。 此區隔可防止具有通配符的角色 (*) 對您的數據進行不受限制的存取。 例如,如果使用者在訂用帳戶上具有 讀者 角色,則他們可以檢視記憶體帳戶,但根據預設,他們無法檢視基礎數據。

先前,角色型訪問控制不會用於數據動作。 數據動作的授權會因資源提供者而異。 用於控制平面動作的相同角色型訪問控制授權模型已延伸至數據平面動作。

為了支持數據平面動作,新的資料屬性已新增至角色定義。 數據平面動作是在 和 NotDataActions 屬性中DataActions指定。 藉由新增這些數據屬性,會維護控制平面和數據平面之間的分隔。 這可避免目前具有萬用字元 (*) 的角色指派突然存取資料。 以下是可以在和 NotDataActionsDataActions指定一些數據平面動作:

  • 讀取容器中的 Blob 清單
  • 在容器中寫入儲存體 Blob
  • 刪除佇列中的訊息

以下是 儲存體 Blob 資料讀取器角色定義,其中包含 和 DataActions 屬性中的Actions動作。 此角色可讓您讀取 Blob 容器,以及基礎 Blob 數據。

儲存體 Azure PowerShell 中顯示的 Blob 數據讀取者角色:

{
  "Name": "Storage Blob Data Reader",
  "Id": "2a2b9908-6ea1-4ae2-8e65-a410df84e7d1",
  "IsCustom": false,
  "Description": "Allows for read access to Azure Storage blob containers and data",
  "Actions": [
    "Microsoft.Storage/storageAccounts/blobServices/containers/read",
    "Microsoft.Storage/storageAccounts/blobServices/generateUserDelegationKey/action"
  ],
  "NotActions": [],
  "DataActions": [
    "Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read"
  ],
  "NotDataActions": [],
  "AssignableScopes": [
    "/"
  ],
  "Condition": null,
  "ConditionVersion": null
}

儲存體 Azure CLI 中顯示的 Blob 資料讀取者角色:

[
  {
    "assignableScopes": [
      "/"
    ],
    "createdBy": null,
    "createdOn": "2017-12-21T00:01:24.797231+00:00",
    "description": "Allows for read access to Azure Storage blob containers and data",
    "id": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/2a2b9908-6ea1-4ae2-8e65-a410df84e7d1",
    "name": "2a2b9908-6ea1-4ae2-8e65-a410df84e7d1",
    "permissions": [
      {
        "actions": [
          "Microsoft.Storage/storageAccounts/blobServices/containers/read",
          "Microsoft.Storage/storageAccounts/blobServices/generateUserDelegationKey/action"
        ],
        "condition": null,
        "conditionVersion": null,
        "dataActions": [
          "Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read"
        ],
        "notActions": [],
        "notDataActions": []
      }
    ],
    "roleName": "Storage Blob Data Reader",
    "roleType": "BuiltInRole",
    "type": "Microsoft.Authorization/roleDefinitions",
    "updatedBy": null,
    "updatedOn": "2021-11-11T20:13:55.297507+00:00"
  }
]

只有數據平面動作可以新增至 DataActionsNotDataActions 屬性。 資源提供者會將 屬性設定 isDataActiontrue,以識別哪些動作是數據動作。 若要查看其中 isDataActiontrue的動作清單,請參閱 資源提供者作業。 沒有數據動作的角色不需要在角色定義中具有 DataActionsNotDataActions 屬性。

Azure Resource Manager 會處理所有控制平面 API 呼叫的授權。 數據平面 API 呼叫的授權是由資源提供者或 Azure Resource Manager 處理。

數據動作範例

為了進一步瞭解控制平面和數據平面動作的運作方式,讓我們考慮一個特定的範例。 Alice 已獲指派 訂用帳戶範圍的擁有者 角色。 Bob 已獲指派記憶體帳戶範圍 儲存體 Blob 數據參與者角色。 下圖顯示此範例。

Role-based access control has been extended to support both control plane and data plane actions

Alice 的擁有者角色和 Bob 儲存體 Blob 數據參與者角色具有下列動作:

負責人

    動作
    *

儲存體 Blob 資料參與者

    動作
    Microsoft.Storage/storageAccounts/blobServices/containers/delete
    Microsoft.Storage/storageAccounts/blobServices/containers/read
    Microsoft.Storage/storageAccounts/blobServices/containers/write
    Microsoft.Storage/storageAccounts/blobServices/generateUserDelegationKey/action
    DataActions
    Microsoft.Storage/storageAccounts/blobServices/containers/blobs/delete
    Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read
    Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write
    Microsoft.Storage/storageAccounts/blobServices/containers/blobs/move/action
    Microsoft.Storage/storageAccounts/blobServices/containers/blobs/add/action

由於Alice在訂用帳戶範圍有通配符 (*) 動作,因此其許可權會繼承下來,讓他們能夠執行所有控制平面動作。 Alice 可以讀取、寫入和刪除容器。 不過,Alice 無法在不採取其他步驟的情況下執行數據平面動作。 例如,根據預設,Alice 無法讀取容器內的 Blob。 若要讀取 Blob,Alice 必須擷取記憶體存取密鑰,並使用它們來存取 Blob。

Bob 的權限限於 Actions 儲存體 Blob 資料參與者角色中指定的 DataActions 。 根據角色,Bob 可以同時執行控制平面和數據平面動作。 例如,Bob 可以在指定的記憶體帳戶中讀取、寫入和刪除容器,也可以讀取、寫入和刪除 Blob。

如需記憶體控制和數據平面安全性的詳細資訊,請參閱 Azure 儲存體 安全性指南

哪些工具支援使用 Azure 角色執行資料動作?

若要檢視和使用資料動作,您必須擁有正確的工具或 SDK 版本:

工具 版本
Azure PowerShell 1.1.0 或更新版本
Azure CLI 2.0.30 或更新版本
適用於 .NET 的 Azure 2.8.0-preview 或更新版本
Azure SDK for Go 15.0.0 或更新版本
適用於 Java 的 Azure 1.9.0 或更新版本
適用於 Python 的 Azure 0.40.0 或更新版本
Azure SDK for Ruby 0.17.1 或更新版本

若要檢視及使用 REST API 中的數據動作,您必須將 api-version 參數設定為下列版本或更新版本:

  • 2018-07-01

動作

Actions許可權會指定角色允許執行的控制平面動作。 這是識別 Azure 資源提供者安全性實體動作的字串集合。 以下是可在 中使用 Actions之控制平面動作的一些範例。

動作字串 描述
*/read 授與所有 Azure 資源提供者之所有資源類型讀取動作的存取權。
Microsoft.Compute/* 授與 Microsoft.Compute 資源提供者中所有資源類型之所有動作的存取權。
Microsoft.Network/*/read 授與 Microsoft.Network 資源提供者中所有資源類型的讀取動作存取權。
Microsoft.Compute/virtualMachines/* 授與虛擬機及其子資源類型之所有動作的存取權。
microsoft.web/sites/restart/Action 授與重新啟動 Web 應用程式的存取權。

NotActions

NotActions許可權會指定從允許Actions具有通配符 (*) 的 減去或排除的控制平面動作。 NotActions如果想要允許的動作集更容易定義,請從具有通配符 (*) 的減去Actions來定義許可權。 角色所授與的存取權(有效許可權)是藉由從動作減去 NotActions 動作 Actions 來計算。

Actions - NotActions = Effective control plane permissions

下表顯示 Microsoft.CostManagement 通配符動作的有效控制平面許可權兩個範例:

動作 NotActions 有效的控制平面許可權
Microsoft.CostManagement/exports/* none Microsoft.CostManagement/exports/action
Microsoft.CostManagement/exports/read
Microsoft.CostManagement/exports/write
Microsoft.CostManagement/exports/delete
Microsoft.CostManagement/exports/run/action
Microsoft.CostManagement/exports/* Microsoft.CostManagement/exports/delete Microsoft.CostManagement/exports/action
Microsoft.CostManagement/exports/read
Microsoft.CostManagement/exports/write
Microsoft.CostManagement/exports/run/action

注意

如果用戶獲指派的角色,該角色會排除 中的 NotActions動作,並獲指派第二個角色來授與相同動作的存取權,則允許使用者執行該動作。 NotActions 不是拒絕規則 , 只是在需要排除特定動作時建立一組允許動作的便利方式。

NotActions 與拒絕指派之間的差異

NotActions 和拒絕指派不同,且用途不同。 NotActions 是從通配符 (*) 動作減去特定動作的便利方式。

拒絕指派會阻止使用者執行特定動作,即使角色指派授與他們存取權也一樣。 如需詳細資訊,請參閱 瞭解 Azure 拒絕指派

DataActions

DataActions許可權會指定角色允許在該物件內對您的數據執行的數據平面動作。 例如,如果使用者已讀取記憶體帳戶的 Blob 數據存取權,則他們可以讀取該記憶體帳戶內的 Blob。 以下是可用於的 DataActions一些數據動作範例。

數據動作字串 描述
Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read 傳回 Blob 或 Blob 清單。
Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write 傳回寫入 Blob 的結果。
Microsoft.Storage/storageAccounts/queueServices/queues/messages/read 傳回訊息。
Microsoft.Storage/storageAccounts/queueServices/queues/messages/* 傳回訊息或寫入或刪除訊息的結果。

NotDataActions

NotDataActions許可權會指定從具有通配符 (*) 的允許DataActions中減去或排除的數據平面動作。 NotDataActions如果想要允許的動作集更容易定義,請從具有通配符 (*) 的減去DataActions來定義許可權。 角色所授與的存取權(有效許可權)是藉由從動作減去 NotDataActions 動作 DataActions 來計算。 每個資源提供者都會提供其個別的 API 集合,以履行數據動作。

DataActions - NotDataActions = Effective data plane permissions

下表顯示 Microsoft.儲存體 通配符動作之有效日期平面許可權的兩個範例:

DataActions NotDataActions 有效的數據平面許可權
Microsoft.Storage/storageAccounts/queueServices/queues/messages/* none Microsoft.Storage/storageAccounts/queueServices/queues/messages/read
Microsoft.Storage/storageAccounts/queueServices/queues/messages/write
Microsoft.Storage/storageAccounts/queueServices/queues/messages/delete
Microsoft.Storage/storageAccounts/queueServices/queues/messages/add/action
Microsoft.Storage/storageAccounts/queueServices/queues/messages/process/action
Microsoft.Storage/storageAccounts/queueServices/queues/messages/* Microsoft.Storage/storageAccounts/queueServices/queues/messages/delete
Microsoft.Storage/storageAccounts/queueServices/queues/messages/read
Microsoft.Storage/storageAccounts/queueServices/queues/messages/write
Microsoft.Storage/storageAccounts/queueServices/queues/messages/add/action
Microsoft.Storage/storageAccounts/queueServices/queues/messages/process/action

注意

如果使用者被指派的角色,該角色會排除 中的數據 NotDataActions動作,並獲指派第二個角色來授與相同數據動作的存取權,則允許使用者執行該數據動作。 NotDataActions 不是拒絕規則, 只是在需要排除特定數據動作時,建立一組允許的數據動作的便利方式。

AssignableScopes

屬性 AssignableScopes 會指定可指派角色定義的範圍(根目錄、管理群組、訂用帳戶或資源群組)。 您可以只讓自定義角色在需要該角色的管理群組、訂用帳戶或資源群組中指派。 您必須至少使用一個管理群組、訂用帳戶或資源群組。

例如,如果 AssignableScopes 設定為訂用帳戶,這表示自定義角色可用於指定訂用帳戶的訂用帳戶範圍指派、訂用帳戶中任何資源群組的資源群組範圍,或訂用帳戶中任何資源的資源範圍。

內建角色已 AssignableScopes 設定為根範圍 ("/")。 根範圍表示角色可用於所有範圍中的指派。

有效可指派範圍的範例包括:

角色可用於指派 範例
一個訂用帳戶 "/subscriptions/{subscriptionId1}"
兩個訂用帳戶 "/subscriptions/{subscriptionId1}", "/subscriptions/{subscriptionId2}"
網路資源群組 "/subscriptions/{subscriptionId1}/resourceGroups/Network"
一個管理群組 "/providers/Microsoft.Management/managementGroups/{groupId1}"
管理群組和訂用帳戶 "/providers/Microsoft.Management/managementGroups/{groupId1}", "/subscriptions/{subscriptionId1}",
所有範圍(僅適用於內建角色) "/"

您只能在自訂角色的 AssignableScopes 中定義一個管理群組。

雖然您可以使用命令行,在 中 AssignableScopes 建立具有資源實例的自定義角色,但不建議這麼做。 每個租使用者最多支援5,000個自定義角色。 使用此策略可能會耗盡您可用的自定義角色。 最後,存取層級取決於自訂角色指派(範圍 + 角色許可權 + 安全性主體),而不是 AssignableScopes 自定義角色中列出的 。 因此,使用管理群組、訂用 AssignableScopes 帳戶或資源群組建立您的自定義角色,但指派範圍較窄的自定義角色,例如資源或資源群組。

如需自定義角色的詳細資訊 AssignableScopes ,請參閱 Azure 自定義角色

特殊許可權系統管理員角色定義

特殊許可權系統管理員角色是授與特殊許可權系統管理員存取權的角色,例如能夠管理 Azure 資源或將角色指派給其他使用者。 如果內建或自定義角色包含下列任何動作,則會將其視為特殊許可權。 如需詳細資訊,請參閱 列出或管理特殊許可權系統管理員角色指派

動作字串 描述
* 建立和管理所有類型的資源。
*/delete 刪除所有類型的資源。
*/write 寫入所有類型的資源。
Microsoft.Authorization/denyAssignments/delete 刪除指定範圍中的拒絕指派。
Microsoft.Authorization/denyAssignments/write 在指定的範圍建立拒絕指派。
Microsoft.Authorization/roleAssignments/delete 刪除指定範圍的角色指派。
Microsoft.Authorization/roleAssignments/write 在指定的範圍建立角色指派。
Microsoft.Authorization/roleDefinitions/delete 刪除指定的自定義角色定義。
Microsoft.Authorization/roleDefinitions/write 建立或更新具有指定許可權和可指派範圍的自定義角色定義。

下一步