分享方式:


管理 Azure 負載測試的存取權

在本文中,您將了解如何管理 Azure 負載測試資源的存取權 (授權)。 Azure 角色型存取控制 (Azure RBAC) 可用來管理 Azure 資源的存取權,例如是否能夠建立新資源或使用現有資源。 您可以使用 Azure 入口網站、Azure 命令列工具或 Azure 管理 API,授與使用者角色型存取權。

必要條件

若要指派 Azure 角色,您的 Azure 帳戶必須具有:

若要建立新的負載測試資源,您的 Azure 帳戶必須具有:

  • 在負載測試資源的資源群組中建立資源的權限,例如參與者擁有者角色。

Azure 負載測試中的角色

在 Azure 負載測試中,系統會將適當的 Azure 角色指派給負載測試資源範圍中的使用者、群組和應用程式,以授與存取權。 以下是負載測試資源所支援的內建角色:

角色 描述
負載測試讀取者 負載測試資源中的唯讀動作。 讀者可以列出及檢視資源中的測試和測試回合。 讀者無法建立、更新或執行測試。
負載測試參與者 在負載測試資源中檢視、建立、編輯或刪除 (適用的話) 測試和測試回合。
負載測試擁有者 可完整存取負載測試資源,包括能夠在負載測試資源中檢視、建立、編輯或刪除 (如果適用) 資產。 例如,您可以修改或刪除負載測試資源。

如果您有訂用帳戶層級的擁有者參與者負載測試擁有者角色,則會自動擁有與資源層級的負載測試擁有者相同的權限。

重要

您可以將角色存取權的範圍限制在 Azure 中的多個層級。 例如,具有資源擁有者存取權的人員,可能沒有該資源所屬資源群組的擁有者存取權。 如需詳細資訊,請參閱 Azure RBAC 的運作方式

角色權限

下表描述賦予每個角色的特定權限。 這些權限可能包括授與權限的 Actions 和限制權限的 Not Actions

負載測試擁有者

「負載測試擁有者」可以管理所有項目,包括存取權。 下表顯示授與角色的權限:

動作​​ 描述
Microsoft.Resources/deployments/* 建立和管理資源群組部署。
Microsoft.Resources/subscriptions/resourceGroups/read 取得或列出資源群組。
Microsoft.Insights/alertRules/* 建立和管理警示規則。
Microsoft.Authorization/*/read 讀取授權。
Microsoft.LoadTestService/* 建立和管理負載測試資源。
DataActions 描述
Microsoft.LoadTestService/loadtests/* 啟動、停止及管理負載測試。

負載測試參與者

「負載測試參與者」可以管理存取權以外的所有項目。 下表顯示授與角色的權限:

動作​​ 描述
Microsoft.Resources/deployments/* 建立和管理資源群組部署。
Microsoft.Resources/subscriptions/resourceGroups/read 取得或列出資源群組。
Microsoft.Insights/alertRules/* 建立和管理警示規則。
Microsoft.Authorization/*/read 讀取授權。
Microsoft.LoadTestService/*/read 建立和管理負載測試資源。
DataActions 描述
Microsoft.LoadTestService/loadtests/* 啟動、停止及管理負載測試。

負載測試讀取者

負載測試讀取者可以檢視負載測試資源中的所有資源,但無法進行任何變更。 下表顯示授與角色的權限:

動作​​ 描述
Microsoft.Resources/deployments/* 建立和管理資源群組部署。
Microsoft.Resources/subscriptions/resourceGroups/read 取得或列出資源群組。
Microsoft.Insights/alertRules/* 建立和管理警示規則。
Microsoft.Authorization/*/read 讀取授權。
Microsoft.LoadTestService/*/read 建立和管理負載測試資源。
DataActions 描述
Microsoft.LoadTestService/loadtests/readTest/action 讀取負載測試。

為您的負載測試資源設定 Azure RBAC

下一節會說明如何透過 Azure 入口網站和 PowerShell,在您的負載測試資源上設定 Azure RBAC。

使用 Azure 入口網站設定 Azure RBAC

  1. 登入 Azure 入口網站,然後從 [Azure 負載測試] 頁面開啟負載測試資源。

  2. 選取 [存取控制 (IAM)],然後從可用角色清單中選取角色。 您可以選擇 Azure 負載測試資源所支援的任何可用內建角色,也可以選擇您可能已定義的任何自訂角色。 將角色指派給想要向其授與權限的使用者。

    如需詳細步驟,請參閱使用 Azure 入口網站指派 Azure 角色

從使用者移除角色指派

您可以針對未管理 Azure 負載測試資源的使用者,或不再為組織工作的使用者,移除存取權限。 下列步驟說明如何從使用者移除角色指派。 如需詳細步驟,請參閱移除 Azure 角色指派

  1. 針對您要移除存取權的範圍 (例如管理群組、訂用帳戶、資源群組或資源) 開啟 [存取控制 (IAM)]

  2. 請選取 [角色指派] 索引標籤以檢視此範圍中的所有角色指派。

  3. 在角色指派清單中,於想要移除其角色指派的使用者旁加上核取記號。

  4. 選取 [移除],然後選取 [是] 以確認。

使用 PowerShell 設定 Azure RBAC

您也可以使用下列 Azure PowerShell Cmdlet,設定負載測試資源的角色型存取權:

  • Get-AzRoleDefinition 會列出 Microsoft Entra ID 中可用的所有 Azure 角色。 您可以使用此 Cmdlet 搭配 Name 參數,列出特定角色可以執行的所有動作。

    Get-AzRoleDefinition -Name 'Load Test Contributor'
    

    下列片段是範例輸出:

    Name             : Load Test Contributor
    Id               : 00000000-0000-0000-0000-000000000000
    IsCustom         : False
    Description      : View, create, update, delete and execute load tests. View and list load test resources but can not make any changes.
    Actions          : {Microsoft.LoadTestService/*/read, Microsoft.Authorization/*/read, Microsoft.Resources/deployments/*, Microsoft.Resources/subscriptions/resourceGroups/read…}
    NotActions       : {}
    DataActions      : {Microsoft.LoadTestService/loadtests/*}
    NotDataActions   : {}
    AssignableScopes : {/}
    
  • Get-AzRoleAssignment 會列出在指定範圍的 Azure 角色指派。 如果沒有任何參數,此 Cmdlet 會傳回在訂閱下所做的所有角色指派。 使用 ExpandPrincipalGroups 參數,列出指定使用者以及該使用者所屬群組的存取權指派。

    範例:使用下列 Cmdlet 來列出負載測試資源中的所有使用者及其角色。

    Get-AzRoleAssignment -Scope '/subscriptions/<SubscriptionID>/resourcegroups/<Resource Group Name>/Providers/Microsoft.LoadTestService/loadtests/<Load Test Name>'
    
  • 使用 New-AzRoleAssignment 可將特定範圍的存取權指派給使用者、群組及應用程式。

    範例:使用下列命令為負載測試資源範圍中的使用者指派「負載測試讀者」角色。

    New-AzRoleAssignment -SignInName <sign-in Id of a user you wish to grant access> -RoleDefinitionName 'Load Test Reader' -Scope '/subscriptions/<SubscriptionID>/resourcegroups/<Resource Group Name>/Providers/Microsoft.LoadTestService/loadtests/<Load Testing resource name>'
    
  • 使用 Remove-AzRoleAssignment 從特定範圍移除所指定使用者、群組或應用程式的存取權。

    範例:使用下列命令將使用者從負載測試資源範圍中的「負載測試讀者」角色移除。

    Remove-AzRoleAssignment -SignInName <sign-in Id of a user you wish to remove> -RoleDefinitionName 'Load Test Reader' -Scope '/subscriptions/<SubscriptionID>/resourcegroups/<Resource Group Name>/Providers/Microsoft.LoadTestService/loadtests/<Load Testing resource name>'
    

疑難排解

本節列出針對 Azure 負載測試中使用者存取常見問題進行疑難解答的步驟。

因為 You are not authorized to use this resource 而無法建立或執行測試

如果您的 Azure 帳戶沒有管理測試的必要權限,您就會遇到此訊息。 請務必對負載測試資源授與使用者負載測試擁有者負載測試參與者角色。

Screenshot that shows an error message in the Azure portal that you're not authorized to use the Azure Load Testing resource.