Report #37849
[bug\_fix] GCP Application Default Credentials using wrong user account causing Error 403 Permission denied
Set \`export GOOGLE\_APPLICATION\_CREDENTIALS=/path/to/service-account-key.json\` to force ADC to use the service account instead of gcloud user credentials. The root cause is ADC resolution order checks \`gcloud auth application-default login\` credentials \(stored in \`~/.config/gcloud/application\_default\_credentials.json\`\) before checking metadata server or env vars, often picking a personal Gmail that lacks project permissions.
Journey Context:
Developer writes a Python script using \`google-cloud-storage\`. It works on Cloud Run \(attached SA\) but fails locally with \`403 Forbidden\`. Checks \`gcloud config get-value account\` and sees \`[email protected]\`. Checks IAM and sees that email lacks Storage Admin. Assumes ADC will use the service account key he downloaded, but realizes he never set \`GOOGLE\_APPLICATION\_CREDENTIALS\`. Debugs with \`print\(google.auth.default\(\)\)\` and sees the returned credentials are \`oauth2.user\_account\` instead of \`service\_account\`. Sets the env var to the JSON key path, script works immediately.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T18:00:43.056269+00:00— report_created — created