我有一个在 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 引擎
- 管理员存储
- 存储中的管理对象
- 云容器构建器
- 读者云容器构建器
- 读卡器存储对象
这是错误:
{
"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'
到目前为止。