建立自定義角色來管理 Microsoft Entra 識別碼中的企業應用程式

本文說明如何建立具有許可權的自定義角色,以在 Microsoft Entra ID 中管理使用者和群組的企業應用程式指派。 如需角色指派的元素,以及子類型、許可權和屬性集等詞彙的意義,請參閱 自定義角色概觀

必要條件

  • Microsoft Entra ID P1 或 P2 授權
  • 特殊權限角色管理員或全域管理員
  • 使用 PowerShell 時安裝的 Microsoft Graph PowerShell SDK
  • 針對 Microsoft Graph API 使用 Graph 總管時的管理員同意

如需詳細資訊,請參閱 使用PowerShell或 Graph 總管的必要條件。

企業應用程式角色許可權

本文將討論兩個企業應用程式許可權。 所有範例都使用更新權限。

  • 若要讀取範圍內的使用者和群組指派,請授與 microsoft.directory/servicePrincipals/appRoleAssignedTo/read 權限
  • 若要管理範圍內的使用者和群組指派,請授與 microsoft.directory/servicePrincipals/appRoleAssignedTo/update 權限

授與更新權限會導致受託人能夠管理對企業應用程式的使用者和群組指派。 使用者和/或群組指派的範圍可以授與單一應用程式或授與所有應用程式。 如果是在整個組織層級授與,則受託人可以管理所有應用程式的指派。 如果是在應用層級進行,則被指派者只能管理指定應用程式的指派。

授與更新權限有兩個步驟:

  1. 使用許可權建立自定義角色 microsoft.directory/servicePrincipals/appRoleAssignedTo/update
  2. 授與管理企業應用程式的使用者和群組指派的使用者或群組權限。 這是您可以將範圍設定為整個組織的層級,或設定為單一應用程式的時機。

Microsoft Entra 系統管理中心

建立新的自定義角色

提示

本文中的步驟可能會根據您從開始的入口網站稍有不同。

注意

自定義角色是在全組織層級建立和管理,而且只能從組織的 [概觀] 頁面取得。

  1. 以至少 [特殊權限角色管理員] 身分登入 Microsoft Entra 系統管理中心

  2. 流覽至 [身分>識別角色] 和 [系統管理員>角色] 和 [系統管理員]。

  3. 選取 [新增自訂角色]

    Add a new custom role from the roles list in Microsoft Entra ID

  4. 在 [ 基本] 索引 標籤上,提供角色名稱的 [管理使用者和群組指派],併為角色描述提供 [授與管理使用者和群組指派的許可權],然後選取 [下一步]。

    Provide a name and description for the custom role

  5. 在 [ 許可權] 索引卷標上,於搜尋方塊中輸入 “microsoft.directory/servicePrincipals/appRoleAssignedTo/update”,然後選取所需許可權旁的複選框,然後選取 [ 下一步]。

    Add the permissions to the custom role

  6. 在 [檢閱 + 建立] 索引標籤上檢閱權限,然後選取 [建立]

    Now you can create the custom role

使用 Microsoft Entra 系統管理中心將角色指派給使用者

  1. 以至少 [特殊權限角色管理員] 身分登入 Microsoft Entra 系統管理中心

  2. 流覽至 [身分>識別角色] 和 [系統管理員>角色] 和 [系統管理員]。

  3. 選取 [ 管理使用者和群組指派 ] 角色。

    Open Roles and Administrators and search for the custom role

  4. 選取 [新增指派],選取所需的使用者,然後按兩下 [ 選取 ] 將角色指派新增至使用者。

    Add an assignment for the custom role to the user

指派秘訣

  • 若要授與被指派者來管理所有企業應用程式組織的使用者和群組存取權,請從您組織的 [Microsoft Entra ID 概觀] 頁面上的全組織角色和 管理員 角色清單開始。

  • 若要授與指派者管理特定企業應用程式的使用者和群組存取權的許可權,請移至 Microsoft Entra 識別碼中的該應用程式,然後在該應用程式的角色和 管理員 istrators 清單中開啟。 選取新的自定義角色並完成使用者或群組指派。 受指派者只能針對特定應用程式管理使用者和群組存取權。

  • 若要測試自定義角色指派,請以被指派者身分登入,並開啟應用程式的 [使用者和群組 ] 頁面,以確認 [新增使用者 ] 選項已啟用。

    Verify the user permissions

PowerShell

如需詳細資訊,請參閱 在 Microsoft Entra ID 中建立和指派自定義角色,以及 使用 PowerShell 使用資源範圍指派自定義角色。

建立自訂角色

使用下列 PowerShell 腳本建立新角色:

# Basic role information
$description = "Can manage user and group assignments for Applications"
$displayName = "Manage user and group assignments"
$templateId = (New-Guid).Guid

# Set of permissions to grant
$allowedResourceAction = @("microsoft.directory/servicePrincipals/appRoleAssignedTo/update")
$rolePermission = @{'allowedResourceActions'= $allowedResourceAction}
$rolePermissions = $rolePermission

# Create new custom admin role
$customRole = New-MgRoleManagementDirectoryRoleDefinition -Description $description `
   -DisplayName $displayName -RolePermissions $rolePermissions -TemplateId $templateId -IsEnabled

指派自定義角色

使用此 PowerShell 腳本指派角色。

# Get the user and role definition you want to link
$user =  Get-MgUser -Filter "userPrincipalName eq 'chandra@example.com'"
$roleDefinition = Get-MgRoleManagementDirectoryRoleDefinition -Filter "displayName eq 'Manage user and group assignments'"

# Get app registration and construct scope for assignment.
$appRegistration = Get-MgApplication -Filter "displayName eq 'My Filter Photos'"
$directoryScope = '/' + $appRegistration.Id

# Create a scoped role assignment
$roleAssignment = New-MgRoleManagementDirectoryRoleAssignment -DirectoryScopeId $directoryScope `
   -PrincipalId $user.Id -RoleDefinitionId $roleDefinition.Id

Microsoft Graph API

使用建立 unifiedRoleDefinition API 來建立自定義角色。 如需詳細資訊,請參閱使用 Microsoft Graph API 在 Microsoft Entra ID 中建立和指派自定義角色和指派自定義管理員角色。

POST https://graph.microsoft.com/v1.0/roleManagement/directory/roleDefinitions

{
    "description": "Can manage user and group assignments for Applications.",
    "displayName": "Manage user and group assignments",
    "isEnabled": true,
    "rolePermissions":
    [
        {
            "allowedResourceActions":
            [
                "microsoft.directory/servicePrincipals/appRoleAssignedTo/update"
            ]
        }
    ],
    "templateId": "<PROVIDE NEW GUID HERE>",
    "version": "1"
}

使用 Microsoft Graph API 指派自定義角色

使用建立 unifiedRoleAssignment API 來指派自定義角色。 角色指派結合了安全性主體標識碼(可以是使用者或服務主體)、角色定義標識符,以及 Microsoft Entra 資源範圍。 如需角色指派元素的詳細資訊,請參閱 自定義角色概觀

POST https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments

{
    "@odata.type": "#microsoft.graph.unifiedRoleAssignment",
    "principalId": "<PROVIDE OBJECTID OF USER TO ASSIGN HERE>",
    "roleDefinitionId": "<PROVIDE OBJECTID OF ROLE DEFINITION HERE>",
    "directoryScopeId": "/"
}

下一步