Skip to content
Latchkey

OIDC GCP "Unable to acquire impersonated credentials" in CI

google-github-actions/auth exchanged the OIDC token for a federated identity but could not impersonate the target service account. The provider attribute condition or the IAM binding on the service account does not permit this repository.

What this error means

The auth step fails with "Unable to acquire impersonated credentials" and a permission-denied detail for the service account. The OIDC exchange itself succeeded.

.github/workflows/ci.yml
Error: google-github-actions/auth failed with: failed to generate
Google Cloud federated token ... Unable to acquire impersonated credentials:
... PERMISSION_DENIED

Diagnose it: what token do you actually have?

Permission failures in Actions are almost never about your repository settings alone. Three things combine: the default GITHUB_TOKEN permission set for the repo or organization, the permissions: block in the workflow, and whether the event is a fork pull request, which downgrades the token to read-only regardless of everything else.

.github/workflows/ci.yml
- name: Show the token scopes actually granted
  run: |
    curl -sI -H "Authorization: Bearer $GITHUB_TOKEN" \
      https://api.github.com/ | grep -i "^x-oauth-scopes\|^x-accepted"
    echo "event: ${{ github.event_name }}"
    echo "fork PR: ${{ github.event.pull_request.head.repo.fork }}"
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Common causes

The service account lacks the workloadIdentityUser binding

The GitHub principal is not granted roles/iam.workloadIdentityUser on the service account, so impersonation is denied.

The provider attribute condition rejects the repo

The WIF provider's attribute mapping or condition (for example on assertion.repository) does not match this repo, blocking the exchange.

How to fix it

Bind the GitHub principal to the service account

  1. Grant roles/iam.workloadIdentityUser on the service account to the WIF principalSet for your repo.
  2. Confirm the provider attribute condition allows assertion.repository.
  3. Re-run the auth step.
Terminal
gcloud iam service-accounts add-iam-policy-binding \
  gha@PROJECT.iam.gserviceaccount.com \
  --role roles/iam.workloadIdentityUser \
  --member "principalSet://iam.googleapis.com/projects/NUM/locations/global/workloadIdentityPools/POOL/attribute.repository/my-org/my-repo"

Pass the correct provider and service account

Reference the full provider resource name and the service account to impersonate in the action.

.github/workflows/ci.yml
- uses: google-github-actions/auth@v2
  with:
    workload_identity_provider: projects/NUM/locations/global/workloadIdentityPools/POOL/providers/PROVIDER
    service_account: gha@PROJECT.iam.gserviceaccount.com

Grant the narrowest permission that works

Declaring a permissions: block switches the job from the repository default to exactly what you list, so an incomplete block is a common cause of a new failure right after someone tightened security. List every scope the job needs, not just the one that failed.

.github/workflows/ci.yml
permissions:
  contents: read        # checkout
  packages: write       # push to GHCR
  id-token: write       # OIDC to a cloud provider
  pull-requests: write  # comment on or label a PR
  checks: write         # publish check runs

How to prevent it

  • Bind workloadIdentityUser to the exact repo principalSet.
  • Keep the provider attribute condition aligned with assertion.repository.
  • Use the full provider resource path in the auth step.

Frequently asked questions

What causes OIDC GCP "Unable to acquire impersonated credentials" in CI?
There are 2 common causes: the service account lacks the workloadidentityuser binding and the provider attribute condition rejects the repo. The GitHub principal is not granted roles/iam.workloadIdentityUser on the service account, so impersonation is denied.
How do I fix OIDC GCP "Unable to acquire impersonated credentials" in CI?
There are 2 fixes depending on which cause you have: bind the github principal to the service account and pass the correct provider and service account. Work through them in order, since the first is the most common.
What does OIDC GCP "Unable to acquire impersonated credentials" in CI actually mean?
The auth step fails with "Unable to acquire impersonated credentials" and a permission-denied detail for the service account.
How do I stop OIDC GCP "Unable to acquire impersonated credentials" in CI happening again?
Bind workloadIdentityUser to the exact repo principalSet. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card