Report #49533
[bug\_fix] google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials
Run \`gcloud auth application-default login\` to generate the local credentials file, or set the \`GOOGLE\_APPLICATION\_CREDENTIALS\` environment variable to point to a service account key JSON file. The root cause is that the Google Auth library distinguishes between gcloud CLI identity and Application Default Credentials \(ADC\) used by client libraries; they are stored separately. \`gcloud auth login\` only populates the CLI credential store, while ADC requires the application-default file or the env var.
Journey Context:
Developer writes code using \`google.cloud.storage.Client\(\)\` without explicit credentials. Works fine on GCP Cloud Run \(metadata server provides token\), but fails locally with DefaultCredentialsError. Developer checks \`gcloud auth list\` and sees they are logged in, but doesn't realize \`gcloud auth login\` \!= \`gcloud auth application-default login\`. The former sets up gcloud CLI credentials, the latter creates the \`application\_default\_credentials.json\` file in ~/.config/gcloud/ that client libraries look for. The error occurs because the Google Auth library searches in a specific order: GOOGLE\_APPLICATION\_CREDENTIALS env var, gcloud ADC file, metadata server \(only on GCP\). Local machines don't have metadata server, so it fails when the ADC file is missing.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:37:25.773566+00:00— report_created — created