GitHub Actions cannot get a Google Cloud token through Workload Identity Federation
Unable to acquire impersonated credentialsShort answer
The auth step trades a GitHub OIDC token for a Google token, then impersonates a service account. It fails when the job cannot request the OIDC token, when the provider's attribute mapping or condition rejects the token, or when the service account lacks a Workload Identity User binding for your repository.
Fix it fast
1Find out which cause you have
Check which step fails. A federated-token message points to the pool and provider; an OAuth or impersonation message points to the service account binding.
gcloud iam service-accounts get-iam-policy SA_NAME@PROJECT_ID.iam.gserviceaccount.com2Match what you see, then jump to its fix
- 1
The workflow has no permissions block, or one that sets only contentsThe job is not allowed to request a GitHub ID tokenFix - 2
The policy from the first step has no roles/iam.workloadIdentityUser member with a principalSet for your poolThe service account has no Workload Identity User binding for the repositoryFix - 3
Failed to generate Google Cloud federated tokenThe provider rejects the token (mapping or condition mismatch)Fix
- 1
What does the error look like?
Unable to acquire impersonated credentialsNo access token or invalid expiration in responsePermission 'iam.serviceAccounts.getAccessToken' deniedFailed to generate Google Cloud federated token
Cause 1 of 3
The job is not allowed to request a GitHub ID token
1Check
Federation needs the job to fetch an OIDC token from GitHub. Open the workflow and look for id-token under permissions.
grep -n -A3 permissions .github/workflows/*.yml2Fix
Add id-token write to the job, next to contents read.
permissions:
contents: 'read'
id-token: 'write'3Verify
Re-run the job; the auth step should get past token creation.
git commit --allow-empty -m 'retry auth' && git pushConfirmed by github.com
Cause 2 of 3
The service account has no Workload Identity User binding for the repository
1Check
Impersonation works only if the service account lets the federated identity act as it. The member must use the project number, not the project ID.
gcloud iam service-accounts get-iam-policy SA_NAME@PROJECT_ID.iam.gserviceaccount.com2Fix
Bind the role to a principalSet that matches an attribute you mapped, such as the repository.
gcloud iam service-accounts add-iam-policy-binding SA_NAME@PROJECT_ID.iam.gserviceaccount.com \
--role=roles/iam.workloadIdentityUser \
--member="principalSet://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/POOL_ID/attribute.repository/OWNER/REPO"3Verify
Read the policy again and re-run the workflow.
gcloud iam service-accounts get-iam-policy SA_NAME@PROJECT_ID.iam.gserviceaccount.comConfirmed by docs.cloud.google.com
Cause 3 of 3
The provider rejects the token (mapping or condition mismatch)
1Check
A claim used in an attribute condition or in a principalSet must be mapped to an attribute first, and its capitalization must match the GitHub token exactly.
grep -n -B2 -A4 workload_identity_provider .github/workflows/*.yml2Fix
Map every claim you use, and make the condition match your real owner name. The documented provider setup is shown here; adjust the existing provider in the console or recreate it with the same fields.
gcloud iam workload-identity-pools providers create-oidc PROVIDER_ID \
--location="global" \
--workload-identity-pool="POOL_ID" \
--issuer-uri="https://token.actions.githubusercontent.com/" \
--attribute-mapping="google.subject=assertion.sub,attribute.repository=assertion.repository,attribute.repository_owner=assertion.repository_owner" \
--attribute-condition="assertion.repository_owner=='OWNER'"3Verify
Re-run the workflow; the federated token step should pass.
git commit --allow-empty -m 'retry auth' && git pushConfirmed by github.com
How do I stop it coming back?
- Set the id-token permission on the job that authenticates, not only at the top of a different job.
- Use the project number in workload identity paths and the project ID in service account emails.
- Always keep an attribute condition that limits the provider to your own organization.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Back end
Google Cloud denies iam.serviceAccounts.getAccessToken when impersonating a service account
Permission 'iam.serviceAccounts.getAccessToken' denied on resource
This error appears when you or your app impersonate a service account without the right to create tokens for it.
2 causes, each with a fixServers
Docker push to Artifact Registry fails from GitHub Actions with a permission error
Permission 'artifactregistry.repositories.uploadArtifacts' denied on resource
The identity your workflow authenticates as lacks the permission artifactregistry.repositories.uploadArtifacts on the target repository.
4 causes, each with a fixServers
docker pull or push to ghcr.io fails with 'denied'
Error response from daemon: denied
ghcr.io refuses a pull or push when Docker is not logged in, when the token lacks the package scope, or when the workflow's GITHUB_TOKEN has no packages permission or no access to that package.
4 causes, each with a fixServers
git says it could not read Username for https://github.com in a build or CI job
fatal: could not read Username for 'https://github.com': No such device or address
Git asked for HTTPS credentials and there was no terminal to ask on, so it gave up.
3 causes, each with a fixServers
upload-artifact fails because the artifact storage quota is full
Create Artifact Container failed: Artifact storage quota has been hit. Unable to upload any new artifacts
Uploads fail when your account's shared artifact storage is used up.
3 causes, each with a fixServers
configure-aws-credentials says no OpenID Connect provider exists for GitHub
No OpenIDConnect provider found in your account for https://token.actions.githubusercontent.com
AWS has no IAM identity provider for GitHub's token issuer in the account that holds the role.
3 causes, each with a fix