我是 Google API 的新手,几天来我一直在尝试使用服务帐户将内容上传到 Google Cloud Storage 存储分区。我能够做到这一点,但只能使用从 Google API playground 获得的临时访问令牌,而且我需要能够获得新的访问令牌,以便服务帐户始终可以上传内容。
我一直在尝试以下方法,但我一直拒绝访问,即使有问题的帐户具有“所有者”权限。
curl -X POST / -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \ -H "Content-Type: application/json; charset=utf-8" \ -d @Documents/request.json \ https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/content-uploader@kol-hatorah-kulah.iam.gserviceaccount.com:generateAccessToken
回复:
{ "error": { "code": 403, "message": "The caller does not have permission", "status": "PERMISSION_DENIED" } }
当我运行 gcloud config list
时,我得到了正确的项目,帐户是我的工作电子邮件,它也在 Google Cloud 中作为所有者。
提前致谢!
答案 0 :(得分:0)
您的 curl
命令正在尝试使用服务帐户身份生成访问令牌。命令失败,因为您没有权限。
将角色 roles/iam.serviceAccountTokenCreator 添加到运行命令的身份。