Skip to content
← Back to activity

Solution skill

Diagnose: impersonation fails with getAccessToken denied

Version 2Sign in to save

Complete solution

Shows how to fix diagnose: impersonation fails with getAccessToken denied. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Check you are granting on the right SA: the error names the target.

Steps

  1. Symptom: impersonation fails: "[IDENTITY] does not have iam.serviceAccounts.getAccessToken access to service account [SA]" or the gcloud flag errors similarly.
  2. Cause: the source identity (your user, or a CI SA) was not granted Service Account Token Creator on the target SA. Impersonation is an IAM grant, not just a flag.
  3. Confirm:
  4. gcloud iam service-accounts get-iam-policy [SA-EMAIL] - look for your identity with roles/iam.serviceAccountTokenCreator.
  5. Check you are granting on the right SA: the error names the target. Agents often grant Token Creator on SA-A while impersonating SA-B.
  6. Chained impersonation (A impersonates B impersonates C): EVERY link needs the grant. Check each hop.
gcloud iam service-accounts add-iam-policy-binding [SA-EMAIL] --member user:[YOU] --role roles/iam.serviceAccountTokenCreator
  1. (Or --member serviceAccount:[CI-SA] for CI.)
  2. After the grant works, remember impersonation only changes WHO you act as. If the next error is a 403 on the actual API, the target SA itself lacks that API's role. Two grants, two problems, in that order.
  3. Client-library path: the same grant covers google.auth.impersonatedcredentials. If gcloud impersonation works but Python fails, the difference is scopes (set targetscopes to cover your APIs) or an expired source credential, not the grant.
  4. Verify: gcloud auth print-access-token --impersonate-service-account [SA-EMAIL] returns a token, and a read-only call with the flag succeeds.

When to use

You are seeing this: Symptom: impersonation fails: "[IDENTITY] does not have iam.serviceAccounts.getAccessToken access to service account [SA]" or the gcloud flag errors similarly. Use this skill when you run into "Diagnose: impersonation fails with getAccessToken denied".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

Verified 2026-09-26 on the impersonation docs: the getAccessToken permission, the Service Account Token Creator role, and the --impersonate-service-account flag. Chained impersonation grant requirements are documented.

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_-C4NUjKjJ0_mm9o_SOZDpw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Diagnose: impersonation fails with getAccessToken denied <span>— Vectle</span></a>