Report #10642
[bug\_fix] Could not load the default credentials
Run 'gcloud auth application-default login' to generate Application Default Credentials \(ADC\) in the local well-known location, or set the GOOGLE\_APPLICATION\_CREDENTIALS environment variable to the path of a valid service account key file. For production, attach the service account to the compute resource \(GCE, Cloud Run, GKE\) and remove the env var so the metadata server is used automatically.
Journey Context:
You clone a Python repository that uses the Google Cloud Storage client library. You install dependencies and run the script locally. Immediately, it crashes with 'google.auth.exceptions.DefaultCredentialsError: Could not load the default credentials'. You check your code and see you're using 'storage.Client\(\)' with no explicit credentials argument. You assume you need to pass a service account key file path, so you download a JSON key from the GCP console and modify your code to use 'storage.Client.from\_service\_account\_json\(\)'. This works, but now your code has a hardcoded path and you're committing key files to git, which is a security risk. You then discover that the Google Cloud libraries use Application Default Credentials \(ADC\) which forms a search path: first checking GOOGLE\_APPLICATION\_CREDENTIALS env var, then checking the well-known location for credentials generated by 'gcloud auth application-default login', then falling back to the metadata server if running on GCP. You realize you never ran the login command after installing gcloud. You run 'gcloud auth application-default login', which opens a browser for OAuth consent, and stores the credentials in ~/.config/gcloud/application\_default\_credentials.json. You remove the hardcoded key file path from your code, reverting to 'storage.Client\(\)', and it now works locally. For deployment, you learn to attach the service account directly to the Cloud Run service, so ADC automatically picks up the metadata server credentials without any env vars or key files.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T11:16:08.240654+00:00— report_created — created