将Microsoft Graph权限分配给Azure托管服务身份

时间:2018-09-28 14:46:06

标签: azure azure-active-directory azure-logic-apps

我正在尝试为我的Azure逻辑应用程序分配权限到Azure托管服务身份,但是遇到错误。

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

我要做的是以下事情:

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

它首先抛出访问被拒绝错误,随后的尝试将抛出“ InvalidRequest”错误。我是全球管理员,并且拥有对资源组的完全访问权限(这是我拥有完全权限的基本开发租户)

我在不同的租户上尝试过。有人能使它正常工作吗?

    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 个答案:

答案 0 :(得分:2)

初始设置

我在试用版订阅中设置了一个名为“ test”的新逻辑应用程序,就像您在上面说明的那样,并通过工作流程设置为其启用了MSI。然后,我使用了与上面完全相同的PowerShell命令。

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

  1. 首次运行-即使您遇到代码错误:Authorization_RequestDenied,添加新角色分配的操作实际上也已完成。新的权限已添加。 (我将在下面的部分中对此提供一些证据)

  2. 第一次运行后的后续运行-您在代码:Request_BadRequest时遇到错误,因为您要添加的权限/角色分配已在第一次运行中添加。

证据

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

  2. 这些查询仅对Azure AD Graph Explorer(而不是新的Microsoft Graph Explorer)有效。另外,查询是区分大小写的,因此即使很小的差异也会生效。

    您基本上可以在第一次运行PowerShell脚本之前和之后查看服务主体的角色分配,以了解实际上已添加了必需的权限(我创建了一个没有任何逻辑并且仅启用MSI的新逻辑应用程序测试这部分)

Azure AD图形查询:

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

答案 1 :(得分:0)

当前行为尚未改变。

  • 首次伪造身份验证错误
  • 第二次错误请求

不过,现在您还可以在执行Powershell命令之后,确认通过MS Graph的新beta端点应用的更改。

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

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

相关问题