我有一个 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:
这意味着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
权限,同时添加应用程序权限和委派权限,然后单击授予权限按钮)。这是我的测试结果:
希望这有帮助!
关于使用 VSTS 中的服务主体的 Azure Graph 403 Authorization_RequestDenied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49695689/