Report #24078
[bug\_fix] Permission 'iam.serviceAccounts.getAccessToken' denied on resource when using GCP Application Default Credentials with service account impersonation
Grant the calling identity \(user or service account\) the \`roles/iam.serviceAccountTokenCreator\` IAM role specifically on the target service account resource \(not just at the project level\). Root cause: GCP IAM is deny-by-default for service account impersonation. Being a Project Owner or Editor does NOT implicitly grant the permission to generate OAuth2 access tokens for service accounts within that project. The IAM policy must explicitly allow the principal to call \`generateAccessToken\` on the specific service account resource to prevent privilege escalation paths where a compromised owner account can impersonate sensitive service accounts without explicit authorization.
Journey Context:
A developer sets up a local Python script using \`google.auth.impersonated\_credentials\`. They authenticate themselves via \`gcloud auth application-default login\` \(user credentials\). The script attempts to impersonate \`[email protected]\` to access Cloud Storage. It fails with: \`google.api\_core.exceptions.PermissionDenied: 403 Permission 'iam.serviceAccounts.getAccessToken' denied on resource \(or it may not exist\)\`. The developer checks the IAM Console and sees they have "Owner" role on the project. They assume Owner implies all permissions. They check if the service account exists - it does. They try adding "Service Account User" \(roles/iam.serviceAccountUser\) to themselves at the project level - same error. They read the error message carefully and realize it says \`getAccessToken\`, not \`actAs\`. They research and find that \`roles/iam.serviceAccountTokenCreator\` is required specifically for generating OAuth tokens for impersonation. They grant themselves \`Service Account Token Creator\` on the specific service account resource \(not project level\). The script works. The "why": GCP separates the permission to "act as" a service account \(for attaching to resources\) from the permission to "impersonate" and mint tokens for that service account. This prevents a project owner from silently assuming the identity of a high-privilege service account unless explicitly authorized via IAM policy on that specific SA.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T18:49:26.742349+00:00— report_created — created