Search code examples
google-cloud-platformgoogle-cloud-firestoreoauth-2.0google-apigoogle-cloud-storage

Google Cloud Storage API: can't generate access token, access denied


I'm new to Google APIs and I've been trying for days to use a service account to upload content to a Google Cloud Storage bucket. I'm able to accomplish this, but only with a temporary access token obtained from the Google API playground, and I need to be able to get new access tokens so the service account can always upload content.

I've been experimenting with the following, but I keep getting access denied, even though the account in question has 'owner' permissions.

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/[email protected]:generateAccessToken

response:

{ "error": { "code": 403, "message": "The caller does not have permission", "status": "PERMISSION_DENIED" } }

When I run gcloud config list I get the correct project, and the account is my work email, which is also in Google Cloud as an owner.

Thanks in advance!


Solution

  • Your curl command is attempting to use a service account identity to generate an Access Token. The command is failing because you do not have permission.

    Add the role roles/iam.serviceAccountTokenCreator to the identity running the command.