GOOGLE_APPLICATION_CREDENTIALS
SensitiveThe file path to a Google Cloud service account key JSON file. Used by Google Cloud client libraries for authentication via Application Default Credentials (ADC). This is the most common way to authenticate server-to-server communication with GCP services.
Last updated:
GOOGLE_APPLICATION_CREDENTIALS holds a filesystem path (not the JSON itself) to a credentials file that Google's client libraries load via Application Default Credentials (ADC). It is first in the ADC lookup order, so setting it overrides gcloud user credentials and any attached service account. The modern guidance from Google is to avoid downloaded service-account key files entirely — they are long-lived secrets that leak — and instead use Workload Identity Federation or attached service accounts, where ADC finds credentials automatically and GOOGLE_APPLICATION_CREDENTIALS is left unset.
- Provider
- Google Cloud
- Category
- authentication
- Set by
- Set manually to the path of a downloaded service account key JSON file
- Example
- /path/to/service-account-key.json
How to set GOOGLE_APPLICATION_CREDENTIALS
bash (local dev with a key file)
export GOOGLE_APPLICATION_CREDENTIALS=/secrets/sa-key.json
gcloud auth application-default print-access-tokenpreferred local dev: no key file
gcloud auth application-default login
# ADC is written to ~/.config/gcloud; leave the env var unsetdocker-compose (mount the key, set the path)
services:
app:
environment:
GOOGLE_APPLICATION_CREDENTIALS: /secrets/sa-key.json
volumes:
- ./sa-key.json:/secrets/sa-key.json:roReferences
Frequently Asked Questions
Do I need GOOGLE_APPLICATION_CREDENTIALS on Cloud Run or GKE?
No. On GCP compute, Application Default Credentials automatically uses the attached service account through the metadata server, so leave it unset. Set it only when running outside GCP (or locally) and even then prefer Workload Identity Federation over a downloaded key file.
Can it hold the JSON content instead of a file path?
No — GOOGLE_APPLICATION_CREDENTIALS must be a path to a file on disk. If you only have the JSON as a string (e.g. a CI secret), write it to a temp file first and point the variable at that file, or use the library-specific 'credentials from JSON string' API instead.
Stay up to date
Get notified about new guides, tools, and cheatsheets.