Report #61766
[bug\_fix] GCP Service Account Impersonation failed with "Request had insufficient authentication scopes" or "IAM Service Account Credentials API has not been used in project"
Grant the caller \(the impersonating identity\) the "Service Account Token Creator" IAM role \(roles/iam.serviceAccountTokenCreator\) on the target service account \(the one being impersonated\), not just on the project. Additionally, ensure the IAM Service Account Credentials API \(iamcredentials.googleapis.com\) is enabled in the project that owns the calling identity \(if the caller is a service account\). The root cause is that generating an access token for a service account \(impersonation\) requires explicit permission on the service account resource itself, and requires the API to be enabled to issue short-lived tokens.
Journey Context:
Developer is setting up a CI/CD pipeline using Workload Identity Federation or simply running a local script that impersonates a service account to access Cloud Storage. They configure the client library to use impersonation via ADC or explicit configuration. They run the script and get google.api\_core.exceptions.PermissionDenied: 403 Request had insufficient authentication scopes or alternatively Error: IAM Service Account Credentials API has not been used in project 123456 before or it is disabled. Developer checks the service account permissions and sees it has Storage Admin on the bucket. They check their own user permissions and see they have Project Owner. Confused, they realize that impersonation is a two-step authorization: 1\) The caller needs permission to impersonate \(create tokens for\) the service account, and 2\) The service account needs permission on the resource. They run gcloud iam service-accounts add-iam-policy-binding TARGET\_SA --member="user:[email protected]" --role="roles/iam.serviceAccountTokenCreator" and try again. Now they get the "IAM Service Account Credentials API has not been used" error. They navigate to the Cloud Console > APIs & Services > Library, search for "IAM Service Account Credentials API", and enable it in the project where their user account resides \(or where the workload runs\). After enabling, the impersonation succeeds because the iamcredentials.googleapis.com endpoint is now available to mint the short-lived access token for the target service account.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T10:09:54.363831+00:00— report_created — created