Azure Active Directory - graphrbac.GroupsClient#List:响应请求失败:StatusCode=403

mar*_*ark 6 azure terraform

我的服务主体尝试使用以下 terraform 代码读取某个 AD 组:

data "azuread_group" "hosting_ad_group" {
  name = local.hosting_ad_group_name
}
Run Code Online (Sandbox Code Playgroud)

根据https://www.terraform.io/docs/providers/azuread/d/group.html的文档:

注意:如果您使用服务主体进行身份验证,则它必须具有读取 Windows Azure Active Directory API 中的目录数据的权限。

事实上我的 SP 有这个权限: 在此输入图像描述

然而,当我运行 terraform apply 作为此 SP 时,我得到以下信息:

Error: Error finding Azure AD Group with display name "AdminRole-Product-DFDevelopmentOps": Error listing Azure AD Groups for filter "displayName eq 'AdminRole-Product-DFDevelopmentOps'": graphrbac.GroupsClient#List: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="Unknown" Message="Unknown service error" Details=[{"odata.error":{"code":"Authorization_RequestDenied","date":"2020-02-09T13:59:32","message":{"lang":"en","value":"Insufficient privileges to complete the operation."},"requestId":"b4f52aca-7306-4d12-95c9-cf922ae59483"}}]
Run Code Online (Sandbox Code Playgroud)

我缺少什么?

编辑1

这是我从 terraform 设置 API 权限的方法:

resource "azuread_application" "app" {
  name = local.ctx.HostingAppName

  # AAD Graph API   
  required_resource_access {
    resource_app_id = "00000002-0000-0000-c000-000000000000"

    # Sign in and read user profile
    resource_access {
      id   = "311a71cc-e848-46a1-bdf8-97ff7156d8e6"
      type = "Scope"
    }

    # Manage apps that this app creates or owns
    resource_access {
      id   = "824c81eb-e3f8-4ee6-8f6d-de7f50d565b7"
      type = "Role"
    }

    # Read directory data
    resource_access {
      id   = "5778995a-e1bf-45b8-affa-663a9f3f4d04"
      type = "Scope"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Ton*_* Ju 3

请注意,应用程序权限与委派权限不同。如果您使用服务主体来调用api,您应该授予您的应用程序应用权限。

在此输入图像描述

参考:

权限类型