代码之家  ›  专栏  ›  技术社区  ›  Mark Priem

将Microsoft Graph权限分配给Azure托管服务标识

  •  2
  • Mark Priem  · 技术社区  · 6 年前

    我使用的是2.0.1.16版本的AzureAD powershell模块。

    我所做的是:

    1. 创建逻辑应用程序
    2. 在该逻辑应用程序的工作流设置中生成Azure托管服务标识。
    3. 执行下面的PowerShell,为group.readwrite.all角色分配托管服务标识。

    我在不同的房客身上试过。有人能让这个工作吗?

        PS C:\Users\markp> $msi = Get-AzureADServicePrincipal | ?{$_.DisplayName -ieq "test"}
    PS C:\Users\markp> $mai
    PS C:\Users\markp> $msi
    
    ObjectId                             AppId                                DisplayName
    --------                             -----                                -----------
    8d87a1f9-fab0-45a9-a6f3-1e93b2d99b52 032c3c1c-2530-4eae-b390-153e3b0eb3c6 TEST
    
    
    PS C:\Users\markp> $graph = Get-AzureADServicePrincipal -Filter "AppId eq '00000003-0000-0000-c000-000000000000'"
    PS C:\Users\markp> $graph
    
    ObjectId                             AppId                                DisplayName
    --------                             -----                                -----------
    5a634981-6bbe-4c81-9aef-185a71df56f7 00000003-0000-0000-c000-000000000000 Microsoft Graph
    
    
    PS C:\Users\markp> $role = $graph.AppRoles | ?{$_.Value -imatch "group.read.all" }
    PS C:\Users\markp> $role
    
    
    AllowedMemberTypes : {Application}
    Description        : Allows the app to read group properties and memberships, and read the calendar and conversations f
                         or all groups, without a signed-in user.
    DisplayName        : Read all groups
    Id                 : 5b567255-7703-4780-807c-7be8301ae99b
    IsEnabled          : True
    Value              : Group.Read.All
    
    
    
    PS C:\Users\markp> New-AzureADServiceAppRoleAssignment -ObjectId $msi.ObjectId -PrincipalId $msi.ObjectId -Id $role.Id -ResourceId $graph.ObjectId
    New-AzureADServiceAppRoleAssignment : Error occurred while executing NewServicePrincipalAppRoleAssignment
    Code: Authorization_RequestDenied
    Message: Insufficient privileges to complete the operation.
    HttpStatusCode: Forbidden
    HttpStatusDescription: Forbidden
    HttpResponseStatus: Completed
    At line:1 char:1
    + New-AzureADServiceAppRoleAssignment -ObjectId $msi.ObjectId -Principa ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [New-AzureADServiceAppRoleAssignment], ApiException
        + FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.NewServ
       icePrincipalAppRoleAssignment
    
    PS C:\Users\markp> New-AzureADServiceAppRoleAssignment -ObjectId $msi.ObjectId -PrincipalId $msi.ObjectId -Id $role.Id -ResourceId $graph.ObjectId
    New-AzureADServiceAppRoleAssignment : Error occurred while executing NewServicePrincipalAppRoleAssignment
    Code: Request_BadRequest
    Message: One or more properties are invalid.
    RequestId: 57ef7908-dd8b-4a21-b48e-f2692d324264
    DateTimeStamp: Fri, 28 Sep 2018 14:36:55 GMT
    HttpStatusCode: BadRequest
    HttpStatusDescription: Bad Request
    HttpResponseStatus: Completed
    At line:1 char:1
    + New-AzureADServiceAppRoleAssignment -ObjectId $msi.ObjectId -Principa ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [New-AzureADServiceAppRoleAssignment], ApiException
        + FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.NewServ
       icePrincipalAppRoleAssignment
    
    2 回复  |  直到 6 年前
        1
  •  2
  •   Community Nick Dandoulakis    4 年前

    初始设置

    解释正在发生的两件最重要的事情

    1. 第一次运行-即使您得到错误代码:Authorization\u RequestDenied,添加新角色分配的操作实际上已经完成了它的工作。已添加新权限(我将在下面的一节中对此提供一些证据)

    证据

    1. PowerShell脚本完全来自您的帖子。 enter image description here

    2. 这些查询只在azureadgraphexplorer(而不是新的microsoftgraphexplorer)中对我有效。而且,查询是区分大小写的,所以即使是很小的差异也会产生影响。

    Azure AD Graph Query: https://graph.windows.net/{tenant Id}/servicePrincipals/{MSI Service Principal ID}/appRoleAssignments
        
    {MSI Service Principal ID} is 8d87a1f9-fab0-45a9-a6f3-1e93b2d99b52 in your case.
    

    在使用上述查询首次运行New-AzureADServiceAppRoleAssignment之前,为MSI服务主体分配角色。

    enter image description here

    使用上述查询首次运行New AzureADServiceAppRoleAssignment后MSI服务主体的角色分配。

    enter image description here

    This SO post 提到了您正在使用的几乎相同的PowerShell脚本。有趣的是,对于许多人来说,脚本似乎也没有出错。 但请注意用户Olandese的最后一条评论

    enter image description here

        2
  •  0
  •   Joost VdC    6 年前

    • 第一次假身份验证错误
    • 第二次错误请求

    导航到 https://developer.microsoft.com/en-us/graph/graph-explorer &向您的用户进行身份验证(应在左侧边栏中指明)

    然后,您可以通过以下方式查询应用的角色: https://graph.microsoft.com/beta/servicePrincipals/