Report #47082
[bug\_fix] GCP Application Default Credentials using end-user identity instead of service account - 'Client is unauthorized to retrieve access tokens' or 403 with personal gmail
Set the environment variable \`GOOGLE\_APPLICATION\_CREDENTIALS\` to the file path of the service account JSON key, or use \`gcloud auth application-default login [email protected]\`. This works because ADC searches for credentials in a defined hierarchy; without the env var, it falls back to user credentials from \`gcloud auth application-default login\`, which are 'authorized\_user' type lacking the necessary IAM roles for GCP service APIs.
Journey Context:
A developer runs a Python script using \`google-cloud-storage\` and receives a 403 'Forbidden: Permission denied' with an error payload showing their personal Gmail address instead of the expected service account email. They check the IAM policy for the target bucket and see the service account has 'Storage Object Viewer'. They add debug logging to print \`credentials.refresh\_token\` and realize the token is associated with an 'authorized\_user' type. They check \`~/.config/gcloud/application\_default\_credentials.json\` and see it was created by \`gcloud auth application-default login\`. They realize ADC is picking up their personal user identity, which lacks the required permissions. They export \`GOOGLE\_APPLICATION\_CREDENTIALS=/path/to/sa-key.json\` and rerun; the script succeeds because ADC now loads the service account identity with the correct IAM bindings.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:30:04.737011+00:00— report_created — created