共用方式為


了解 Azure RBAC 的範圍

範圍 是受存取限制的資源集。 當您指派角色時,請務必瞭解範圍,以便只授與安全性主體真正需要的存取權。 藉由限制範圍,您可以限制安全性主體遭到入侵時面臨風險的資源。

範圍層級

在 Azure 中,您可以在四個層級指定範圍: 管理群組、訂用帳戶、 資源群組和資源。 範圍的結構為父子式關聯性。 階層的每個層級都會讓範圍更具體。 您可以在任何範圍層級指派角色。 您選取的層級會決定角色的套用範圍。 較低層級會從較高層級繼承角色權限。

角色指派的範圍圖表。

管理群組是在訂用帳戶之上更高的範圍層次,並且支援更複雜的階層結構。 下圖顯示您可以定義的管理群組和訂用帳戶階層範例。 如需管理群組的詳細資訊,請參閱 什麼是 Azure 管理群組?

管理群組和訂閱階層的圖表。

範圍格式

如果您使用命令列指派角色,則需要指定範圍。 針對命令列工具,範疇是一段可能很長的字串,可以用來識別角色指派的確切範圍。 在 Azure 入口網站中,此範圍通常會列為 資源識別碼

範圍由一系列以斜線 (/) 字元分隔的識別碼組成。 您可以將此字串視為表示下列階層,其中沒有預留位置 ({}) 的文字是固定識別碼:

/subscriptions
    /{subscriptionId}
        /resourcegroups
            /{resourceGroupName}
                /providers
                    /{providerName}
                        /{resourceType}
                            /{resourceSubType1}
                                /{resourceSubType2}
                                    /{resourceName}
  • {subscriptionId} 是要使用的訂閱識別碼 (GUID)。
  • {resourceGroupName} 是包含資源群組的名稱。
  • {providerName} 是處理資源的 資源提供者 名稱,然後 {resourceType} 識別 {resourceSubType*} 該資源提供者內的其他層級。
  • {resourceName} 是字串中識別特定資源的最後一部分。

管理群組是訂用帳戶之上的層級,而且具有最廣泛 (最不具體) 的範圍。 此層級的角色指派會套用至管理群組之中的訂用帳戶。 管理群組的範圍具有下列格式:

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

範圍範例

Scope Example
管理團隊 /providers/Microsoft.Management/managementGroups/marketing-group
Subscription /subscriptions/00000000-0000-0000-0000-000000000000
資源群組 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Example-Storage-rg
/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/pharma-sales
Resource /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Example-Storage-rg/providers/Microsoft.Storage/storageAccounts/azurestorage12345/blobServices/default/containers/blob-container-01
/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MyVirtualNetworkResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVirtualNetwork12345

如何判斷資源的範圍

判斷管理群組、訂用帳戶或資源群組的範圍相當簡單。 您只需要知道名稱和訂閱 ID。 不過,判斷資源的範圍需要更多工作。 以下是您可以判斷資源範圍的幾種方式。

  • 在 Azure 入口網站中,開啟資源,然後查看屬性。 資源應該列出您可以判斷範圍的 資源識別碼 。 例如,以下是儲存體帳戶的資源識別碼。

    Azure 入口網站中儲存體帳戶資源識別碼的螢幕擷取畫面。

  • 另一種方式是使用 Azure 入口網站在資源範圍暫時指派角色,然後使用 Azure PowerShellAzure CLI 列出角色指派。 在輸出中,範圍會列為屬性。

    RoleAssignmentId   : /subscriptions/<subscriptionId>/resourceGroups/test-rg/providers/Microsoft.Storage/storageAccounts/azurestorage12345/blobServices/default/containers/blob-container-01/pro
                         viders/Microsoft.Authorization/roleAssignments/<roleAssignmentId>
    Scope              : /subscriptions/<subscriptionId>/resourceGroups/test-rg/providers/Microsoft.Storage/storageAccounts/azurestorage12345/blobServices/default/containers/blob-container-01
    DisplayName        : User
    SignInName         : user@contoso.com
    RoleDefinitionName : Storage Blob Data Reader
    RoleDefinitionId   : 2a2b9908-6ea1-4ae2-8e65-a410df84e7d1
    ObjectId           : <principalId>
    ObjectType         : User
    CanDelegate        : False
    Description        :
    ConditionVersion   :
    Condition          :
    
    {
        "canDelegate": null,
        "condition": null,
        "conditionVersion": null,
        "description": null,
        "id": "/subscriptions/{subscriptionId}/resourceGroups/Example-Storage-rg/providers/Microsoft.Storage/storageAccounts/azurestorage12345/blobServices/default/containers/blob-container-01/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentId}",
        "name": "{roleAssignmentId}",
        "principalId": "{principalId}",
        "principalName": "user@contoso.com",
        "principalType": "User",
        "resourceGroup": "test-rg",
        "roleDefinitionId": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/2a2b9908-6ea1-4ae2-8e65-a410df84e7d1",
        "roleDefinitionName": "Storage Blob Data Reader",
        "scope": "/subscriptions/{subscriptionId}/resourceGroups/Example-Storage-rg/providers/Microsoft.Storage/storageAccounts/azurestorage12345/blobServices/default/containers/blob-container-01",
        "type": "Microsoft.Authorization/roleAssignments"
      }
    

範圍和 ARM 範本

角色指派是 Azure Resource Manager 中的特殊類型,稱為 延伸模組資源。 擴展資源是增強另一個資源功能的資源。 它們總是以另一個資源的擴充(類似於子資源)的形式存在。 例如,訂用帳戶範圍的角色指派是訂用帳戶的延伸模組資源。 角色指派的名稱一律是您要延伸的資源名稱加上/Microsoft.Authorization/roleAssignments/{roleAssignmentId}。 使用 Azure Resource Manager 範本 (ARM 範本) 指派角色時,您通常不需要提供範圍。 原因是範圍欄位一律以您要延伸的資源所使用的識別碼結尾。 範圍可以從角色指派本身的識別碼來決定。 下表顯示角色指派識別碼和對應範圍的範例:

角色指派識別碼 Scope
/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentId} /subscriptions/{subscriptionId}
/subscriptions/{subscriptionId}/resourceGroups/Example-Storage-rg/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentId} /subscriptions/{subscriptionId}/resourceGroups/Example-Storage-rg

如需範圍和 ARM 範本的詳細資訊,請參閱 使用 Azure Resource Manager 範本指派 Azure 角色。 如需延伸模組資源類型的完整清單,請參閱 擴充其他資源功能的資源類型

後續步驟