代码之家  ›  专栏  ›  技术社区  ›  user9360564

Azure Graph 403 Authorization\u RequestDenied使用VSTS中的服务主体

  •  3
  • user9360564  · 技术社区  · 7 年前

    我有一个服务主体,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]]"
    }
    }
    

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

    1 回复  |  直到 7 年前
        1
  •  1
  •   Sa Yang    7 年前

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

    我们可以使用Fiddler找出此命令调用的API:

    enter image description here

    这意味着 获取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

    希望这有帮助!