Report #35247
[bug\_fix] DefaultCredentialsError when confusing gcloud credentials with Application Default Credentials
Execute \`gcloud auth application-default login\` to generate the \`application\_default\_credentials.json\` file in \`~/.config/gcloud/\`, or set the \`GOOGLE\_APPLICATION\_CREDENTIALS\` environment variable to point to a valid service account key JSON; the root cause is that GCP client libraries use Application Default Credentials \(ADC\) which searches for credentials in a specific order \(env var, then metadata server, then local ADC file at \`~/.config/gcloud/application\_default\_credentials.json\`\), whereas \`gcloud auth login\` only populates gcloud's own SQLite credential store for CLI commands, not the ADC location used by Python/Java/Go libraries.
Journey Context:
Developer installs Google Cloud SDK and runs \`gcloud auth login\`, selecting their @company.com account. They verify authentication with \`gcloud config list\` and \`gcloud auth list\`, showing an active access token. They then write a Python script using \`google-cloud-storage\` to list GCS buckets: \`from google.cloud import storage; client = storage.Client\(\); list\(client.list\_buckets\(\)\)\`. Running the script raises \`google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE\_APPLICATION\_CREDENTIALS or explicitly create credentials...\`. The developer is confused because they are "logged in". They check \`env \| grep GOOGLE\` and find nothing. They search StackOverflow and find suggestions to download a service account JSON key and set \`export GOOGLE\_APPLICATION\_CREDENTIALS=/path/to/key.json\`, but they want to use their user credentials for development to avoid managing keys. They discover the file \`~/.config/gcloud/application\_default\_credentials.json\` does not exist, while \`~/.config/gcloud/credentials.db\` does. They realize \`gcloud auth login\` populates the SQLite DB for CLI use only. After running \`gcloud auth application-default login\`, which opens a browser flow and creates \`application\_default\_credentials.json\` with a valid OAuth2 refresh token, the Python script executes successfully without any environment variables.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T13:37:56.349304+00:00— report_created — created