Report #4322
[bug\_fix] DefaultCredentialsError: Could not automatically determine credentials
Run \`gcloud auth application-default login\` in your local shell to populate the Application Default Credentials \(ADC\) file at ~/.config/gcloud/application\_default\_credentials.json \(or equivalent on Windows\). This stores OAuth 2.0 refresh tokens for your user account, which the Google Auth library exchanges for access tokens automatically. Alternatively, download a service account JSON key and set the GOOGLE\_APPLICATION\_CREDENTIALS environment variable to its absolute path. For CI/CD, set GOOGLE\_APPLICATION\_CREDENTIALS to a mounted service account key or use workload identity federation. The root cause is that the ADC strategy searches for credentials in a fixed order: env var -> metadata server \(169.254.169.254, only on GCP\) -> local ADC file. Local workstations lack the metadata server, so they require explicit configuration via the env var or the gcloud login flow.
Journey Context:
A developer clones a Go repository using the Cloud Storage client. They run \`go test ./...\` locally. It immediately fails with \`google: could not find default credentials\`. The developer checks \`gcloud auth list\` and sees they are logged in with their work account. They try exporting GOOGLE\_APPLICATION\_CREDENTIALS pointing to \`~/.config/gcloud/credentials.db\`, which fails because that's a SQLite database, not the ADC JSON format. They search StackOverflow and find conflicting advice about \`gcloud auth login\` vs \`gcloud auth application-default login\`. They try the latter, complete the browser OAuth flow, and a new file appears at \`~/.config/gcloud/application\_default\_credentials.json\`. The tests pass immediately. They later deploy to Cloud Run where it works without changes because the metadata server provides credentials, realizing the local environment was the gap.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:14:01.655782+00:00— report_created — created