【问题标题】:Access Google Container builder logs with a service account - 403 Forbidden Error使用服务帐户访问 Google Container 构建器日志 - 403 禁止错误
【发布时间】:2018-01-10 11:14:06
【问题描述】:

我有一个在 Google Container Builder 上触发构建的服务帐号。这工作正常,但现在我想使用该服务帐户检索构建日志。

这里是获取日志的代码(令牌是使用google-auto-auth包获取的,这部分在其他地方运行良好,所以我真的不认为这是问题):

var url = logsBucket + '/log-' + buildId + '.txt';
debug('Requesting log at %s', url);
request
  .get(url)
  .set('Authorization', 'Bearer ' + token)
  .end(function(err, res) {
    if (err) return cb(err);
    var log = res.body;
    debug('Received build log : %o', log);
    cb(null, log);
  });

目前,尽管服务帐户有权访问以下角色,但此操作失败并显示 401 Unauthorized:

  • 管理 Kubernetes 引擎
  • 管理存储
  • 存储中的管理对象
  • 云容器构建器
  • Reader Cloud 容器构建器
  • 读取器存储对象

这是错误:

{
  "message": "Forbidden",
  "stack": "Error: Forbidden\n    at Request.callback (/app/node_modules/superagent/lib/node/index.js:696:15)\n [...]",
  "status": 403,
  "response": {
    "req": {
      "method": "GET",
      "url": "https://storage.googleapis.com/{PROJECT_ID}.cloudbuild-logs.googleusercontent.com/log-42602b35-af02-4e75-8100-8a3bd0e720fb.txt",
      "headers": {
        "user-agent": "node-superagent/3.8.2",
        "authorization": "Bearer {BEARER_TOKEN}"
      }
    },
    "header": {
      "x-guploader-uploadid": "{SOME-UPLOAD-ID}",
      "content-type": "application/xml; charset=UTF-8",
      "content-length": "337",
      "date": "Wed, 10 Jan 2018 11:06:54 GMT",
      "expires": "Wed, 10 Jan 2018 11:06:54 GMT",
      "cache-control": "private, max-age=0",
      "server": "UploadServer",
      "alt-svc": "...",
      "connection": "close"
    },
    "status": 403
  }
}

知道为什么请求失败并出现 403 吗?它可能来自缺少的范围吗?到目前为止我只设置了scopes: 'https://www.googleapis.com/auth/cloud-platform'

【问题讨论】:

  • 这有什么更新吗?
  • 明天我会试试你的答案,随时通知你

标签: node.js google-cloud-platform google-container-builder


【解决方案1】:

GCS 权限早于 IAM,因此工作方式略有不同。

要查看构建日志,相关服务帐户除了具有Builder Editor角色外,还需要是项目的Viewer

  • role/viewer 包括角色 role/cloudbuild.builds.viewer
  • role/cloudbuild.builds.editor

作为最后一步,您可能希望:(不必要)

  • 禁用 Container Builder API 并重新启用它。这样做应该会让您的服务帐号再次访问您的项目。

也请看:docs

【讨论】:

  • 缺少的角色完成了这项工作,无需重新启动 API。非常感谢
猜你喜欢
  • 1970-01-01
  • 2023-04-09
  • 2020-08-28
  • 2019-01-04
  • 2012-08-23
  • 2017-11-04
  • 1970-01-01
  • 2017-05-07
  • 1970-01-01
相关资源
最近更新 更多