使用 VSTS 中的服务主体的 Azure Graph 403 Authorization_RequestDenied

标签 azure azure-devops azure-active-directory azure-ad-graph-api azure-ad-powershell-v2

我有一个 VSTS 使用的服务主体来运行 Azure Powershell 脚本。我尝试调用的命令是 Get-AzureRmRoleAssignment。我收到以下错误消息

  "Exception": {
     "Request": {
       "Method": "POST",
       "RequestUri": "https://graph.windows.net/********/getObjectsByObjectIds?api-version=1.6",
       "Properties": "System.Collections.Generic.Dictionary`2[System.String,System.Object]",
       "Headers": "System.Collections.Generic.Dictionary`2[System.String,System.Collections.Generic.IEnumerable`1[System.String]]"
     },
     "Response": {
       "StatusCode": 403,
       "ReasonPhrase": "Forbidden",
       "Content": {
         "odata.error": {
           "code": "Authorization_RequestDenied",
           "message": {
             "lang": "en",
             "value": "Insufficient privileges to complete the operation."
           }
         }
       },
       "Headers": "System.Collections.Generic.Dictionary`2[System.String,System.Collections.Generic.IEnumerable`1[System.String]]"
}
}

我已验证服务主体具有角色分配的读取访问权限。

最佳答案

实际上,这个powershell脚本Get-AzureRmRoleAssignment不仅需要使用 Azure REST API 权限进行角色分配的读取访问权限,还需要使用 Azure AD Graph API 的读取目录数据权限

我们可以使用Fiddler来找出该命令调用了哪个API:

enter image description here

这意味着Get-AzureRmRoleAssignment需要调用3个API来完成操作。其中两个是 Azure REST API,其中之一是 Azure AD Graph API:

POST https://graph.windows.net/<tenantID>/getObjectsByObjectIds?api-version=1.6

解决方案:

因此,请检查您的 sp 是否具有读取目录数据的权限。(您最好添加 Read directory data 权限,同时添加应用程序权限和委派权限,然后单击授予权限按钮)。这是我的测试结果: enter image description here

希望这有帮助!

关于使用 VSTS 中的服务主体的 Azure Graph 403 Authorization_RequestDenied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49695689/

相关文章:

ASP.NET Core 2.1 API 缓存

c# - 无法在 NuGet 包上找到 Microsoft.Azure.Services.AppAuthentication

azure - 无法使用 SSL 连接到 Azure Redis 缓存

azure - 如何仅从一个 .sln 中的多个项目中发布更改项目?

azure - 在 Azure DevOps Pipelines 中不同阶段的步骤之间共享变量

javascript - Power BI API 身份验证

azure - FFMPEG 输出放在 azure 的 blob 上

azure - 拉取请求装饰在带有 azure devops 的 sonarqube 中不起作用

azure - 如何为 SSO 配置 Azure Active Directory?

Azure AD Graph API 演示示例无法运行 : The identity of the calling application could not be established