【问题标题】:Calling the IAM API but getting error - "Method ListRoles not found for service iam.googleapis.com"调用 IAM API 但出现错误 - “未找到服务 iam.googleapis.com 的方法 ListRoles”
【发布时间】:2017-07-18 01:35:48
【问题描述】:

我正在尝试使用 curl 调用 IAM api,特别是 organizations.roles.list 方法。

https://cloud.google.com/iam/reference/rest/v1/organizations.roles/list

根据文档,我的请求应该是这样构造的:

https://iam.googleapis.com/v1/organizations/<org-id>/roles

但是,调用它会导致此错误:

{ “错误”:{ “代码”:404, "message": "找不到服务 iam.googleapis.com 的方法 ListRoles", “状态”:“NOT_FOUND”} }

完整请求:curl -H "Authorization: Bearer $(gcloud auth print-access-token)" https://iam.googleapis.com/v1/organizations/<org-id>/roles

我做错了什么?

【问题讨论】:

  • 我猜这个问题已经过时了(将近 1 年),但我已经复制粘贴了您的 curl 请求,并且它正确返回了我的组织中的自定义角色。如果这对您来说仍然失败,那么在您尝试 curl -H"Authorization: Bearer $(gcloud auth print-access-token)" -H'content-type: application/json' https://cloudresourcemana ger.googleapis.com/v1/organizations:search -d'{}' 时是否会显示组织 ID?
  • 我刚刚检查了 the release notes for the IAM API,似乎自定义角色直到 17 年 9 月才进入测试阶段。由于您的问题来自 17 年 7 月,我假设它现在可以正常工作,并且该错误与当时未发布有关。

标签: google-cloud-platform google-cloud-iam


【解决方案1】:

According to the docs,端点https://iam.googleapis.com/v1/organizations/<ORG_ID>/roles用于列出在组织级别定义的角色(即自定义角色)。

要获取默认角色列表(预定义角色、策划角色,无论您想如何称呼它们...),您必须在不指定任何资源的情况下调用 API:

curl -H"Authorization: Bearer $(gcloud auth print-access-token)" https://iam.googleapis.com/v1/roles

因此,要获取资源(无论是项目还是组织)中的完整角色列表,您必须获取精选角色并将它们聚合到资源级别定义的自定义角色,以及定义的自定义角色在父资源上(因此,要获得项目中的角色,您需要获得策划的角色+项目自定义角色+父组织自定义角色)。

关于您收到的错误,我现在测试时没有收到。我已经运行了一些测试并且收到了:

  • 403 当我没有适当的权限时
  • 当没有定义自定义角色时,200 响应为空 ({})
  • 当资源中定义了自定义角色时,200 带有角色列表as defined in the docs

由于问题来自 17 年 7 月,自定义角色 started their beta on Sep '17,我假设您测试 API 太快了,这就是您收到 404 的原因。

【讨论】:

    猜你喜欢
    • 2016-04-21
    • 1970-01-01
    • 2023-01-13
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多