通过ServicePrincipal将Get-AzureRmRoleAssignment用作应用程序所需的精确权限是什么

时间:2018-04-10 05:44:50

标签: azure azure-active-directory azure-ad-powershell-v2

我见过帖子like this one,在使用Login-AzureRmAccount登录时,确切地说允许ServicePrincipal调用Get-AzureRmRoleAssignment需要什么权限才会产生混淆。

在我的情况下,如果我使用-debug标志调用Get-AzureRmRoleAssignment,我可以在HTTP响应的正文中捕获以下错误:

Body:
{
  "odata.error": {
    "code": "Authorization_RequestDenied",
    "message": {
      "lang": "en",
      "value": "Insufficient privileges to complete the operation."
    }
  }
}

我已为应用程序设置了perms,如下所示...首先是Azure AD访问:

Azure AD perms

然后是Microsoft Graph访问:

MS Graph perms

这仍然会导致authZ失败错误。我甚至尝试过一个实验,我为每个API提供了应用程序所有权限,但仍然没有用。

缺少什么?需要什么样的权限才能允许只读编程访问以列出此调用的角色分配?

1 个答案:

答案 0 :(得分:0)

首先,正如我在这种情况下所回答的那样,Get-AzureRmRoleAssignment不仅需要具有Azure REST API权限的read access for role assignment,还需要具有Azure AD Graph API的Read directory data权限。添加权限后,

添加AAD图谱API权限:

您还需要点击Grant permissions按钮进行管理员同意

enter image description here

添加Azure REST API Persmssions:

此外,在为sp添加AAD图API权限之前,请通过从订阅RBAC(IAM)为其分配角色(例如,贡献者角色)来确保您的sp具有Azure REST API的权限。

enter image description here

我测试了这个并且成功了。

相关问题