Join our Newsletter — 33% off our NHI Course
Home› Guides› How to fix Google Cloud Application Default Credentials…
Guide Cloud & Workload Identity

How to fix Google Cloud Application Default Credentials errors without downloading keys: a safe fix for every common error

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 18 November 2026 16 min read
On this page

Almost every Application Default Credentials (ADC) error can be fixed by giving ADC a short-lived identity it can find, so there is no need to download a service account key. When a Google Cloud client library cannot find credentials it fails with a message such as "Could not automatically determine credentials" or "default credentials were not found". The fastest fix that appears in forum answers is to create a service account key, save the JSON file and point GOOGLE_APPLICATION_CREDENTIALS at it. That works, but it leaves a long-lived secret on a laptop, in a container image or in a CI variable, where it can be copied and reused by anyone who obtains it.

This guide explains how ADC searches for credentials, maps each common error to its real cause, and gives a key-free fix for each place your code runs: a developer workstation, Google Cloud compute, GKE, and workloads outside Google Cloud such as CI pipelines or other clouds. It deals with "I have no credentials" and "I have the wrong credentials" problems. If your code authenticates but then receives a 403, use the Google Cloud PERMISSION_DENIED Troubleshooting Guide instead.

Key takeaways

  • ADC checks three places in order: the GOOGLE_APPLICATION_CREDENTIALS environment variable, the local file written by gcloud auth application-default login, and the attached service account from the metadata server. Most errors mean none of the three is present, or the wrong one wins.
  • On a workstation, run gcloud auth application-default login, using --impersonate-service-account when you need to test as a workload identity. No key file is needed.
  • On Google Cloud compute, attach a user-managed service account to the resource. Google describes this as the preferred production method.
  • On GKE, use Workload Identity Federation for GKE so pods get ADC through the GKE metadata server.
  • Outside Google Cloud, use Workload Identity Federation and point GOOGLE_APPLICATION_CREDENTIALS at a credential configuration file, which holds no secret, rather than at a key.
  • Remember that gcloud auth login and ADC are separate. A working gcloud command proves nothing about what your application will use.

How ADC finds credentials

ADC is a search strategy built into Google's authentication libraries. According to Google's ADC documentation, it looks in this order and uses the first credential it finds:

  1. The GOOGLE_APPLICATION_CREDENTIALS environment variable. This points to a JSON file. Google lists three types it can be: a Workforce Identity Federation credential configuration file (for users signing in through an external identity provider), a Workload Identity Federation credential configuration file (for workloads authenticating through an external identity provider), or a service account key file.
  2. The local ADC file from the gcloud CLI. Running gcloud auth application-default login writes it to $HOME/.config/gcloud/application_default_credentials.json on Linux and macOS, or %APPDATA%\gcloud\application_default_credentials.json on Windows. It can hold user credentials or impersonated service account credentials.
  3. The attached service account, retrieved from the metadata server on Compute Engine, Cloud Run, Cloud Functions, GKE and similar services.

Two consequences matter for troubleshooting. First, the environment variable wins: if it is set, even to a stale or wrong file, ADC will not fall back to your local login or the metadata server. Second, ADC credentials are separate from the credentials the gcloud CLI uses for its own commands. Google states this directly. A developer can have a perfectly valid gcloud auth login session and still have no ADC file at all.

Of the three file types the environment variable accepts, only the service account key is a secret that works on its own. Google's documentation warns that keys are a security risk and that, unlike the other file types, a compromised key can be used by anyone who has it with no additional information. That is the reason the fixes below avoid it.

Reading the error message

Client libraries in each language word the failure differently, but the messages fall into a few groups. Identify the group before changing anything.

What you seeGroupLikely cause
"Could not automatically determine credentials", "default credentials were not found", "Your default credentials were not found"No credential foundNone of the three ADC sources exists in this environment
"Neither metadata server or valid service account credentials are found"Unsupported local fileA local ADC file created with impersonation, used by a library that does not support it
"Error creating credential from JSON. Unrecognized credential type"Wrong file typeAn OAuth client ID file was supplied as a credential
Messages saying user credentials are not supported, the API is not enabled, or no quota project is setQuota projectUser credentials calling a client-based API without a quota project
"Unknown project 764086051850 used for request"Quota projectRequests billed to the gcloud CLI's own project because project and quota project are not set
"This app is blocked" or "Access blocked: Authorization Error" during loginScopesRequesting scopes, such as Google Drive, that the default ADC login does not support
Code authenticates as an unexpected identity, or a warning that credentials are being ignoredWrong source winsA leftover GOOGLE_APPLICATION_CREDENTIALS value, or an API key overriding ADC

The middle groups come straight from Google's ADC troubleshooting page. The first group is the generic "nothing found" failure, and the fix depends entirely on where the code is running, which is covered in the next four sections.

Fix on a developer workstation

For local development, the key-free fix is the gcloud ADC login. Google's local development setup page gives two options.

Option 1: your own user credentials

Run:

gcloud auth application-default login

A browser sign-in opens and the result is stored in the local ADC file. If your organisation signs users in through an external identity provider using Workforce Identity Federation, Google says to run gcloud init and sign in with your federated identity first. Your code then runs with your own IAM roles, which is usually what you want while writing it.

Option 2: impersonate a service account

If you need to test with the same permissions your workload will have in production, impersonate the service account instead of downloading its key:

gcloud auth application-default login --impersonate-service-account SERVICE_ACCT_EMAIL

You need the Service Account Token Creator role (roles/iam.serviceAccountTokenCreator) on that service account. Google lists support for this local credential type in C#, C++, Go, Java, Node.js, PHP, Python, Ruby and Rust, and notes that some authentication libraries do not support it. That is the cause of the "Neither metadata server or valid service account credentials are found" error: the fix Google gives is to recreate the ADC file with plain user credentials, or to run the code where a metadata server is available.

Grant Token Creator on a specific service account, not at project level. A project-level grant lets the holder impersonate every service account in the project. Our guide on How to Audit GCP Service Account Impersonation Rights covers how to find over-broad grants.

Look after the local file

The local ADC file is not a key, but it is still a credential. Google notes that it contains your refresh token and that any user with access to your file system can use it to get a valid access token. Keep it out of repositories, container builds and synced folders. Revoke it when you leave a project or hand back a machine with gcloud auth application-default revoke. Also note that the file is tied to your user account, not to your gcloud configuration, so switching gcloud configurations does not change which identity ADC uses.

Fix on Compute Engine, Cloud Run and other Google Cloud services

Code running on Google Cloud should never need a key file. Google's ADC documentation calls the attached service account the preferred production method: create a user-managed service account, grant it the least privileged roles possible, and attach it to the resource running the code. The library then gets tokens from the metadata server automatically.

If you see a "no credentials" error on Google Cloud compute, check these in order:

  1. Is GOOGLE_APPLICATION_CREDENTIALS set in the image or deployment? A value copied from a developer's environment, pointing to a file that does not exist in the container, stops ADC before it reaches the metadata server. Remove it.
  2. Is a service account attached? Check the resource configuration. A service with no attached account, or with the account removed, has nothing for the metadata server to return.
  3. Can the process reach the metadata server? Custom network settings, sidecars or proxies inside the container can block the metadata endpoint.

A common anti-pattern is attaching the default compute service account and then, when it lacks a role, baking a key for a different account into the image. Attach the right user-managed account instead and grant it only the roles the workload uses.

Fix on GKE with Workload Identity Federation

On GKE, pods should get credentials from Workload Identity Federation for GKE. According to Google's GKE documentation, requests to the instance metadata endpoint are routed to the GKE metadata server, so client libraries work without code changes.

  • Autopilot clusters: federation is always on.
  • Standard clusters: enable it at cluster level with --workload-pool=PROJECT_ID.svc.id.goog, then on each node pool with --workload-metadata=GKE_METADATA. Google recommends passing --workload-metadata=GKE_METADATA when creating node pools so the command fails if the cluster is not enabled. Updating an existing node pool takes effect immediately for running workloads and can cut off access to the node service account, so plan the change.
  • Grant roles to the Kubernetes ServiceAccount using the principal identifier principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/PROJECT_ID.svc.id.goog/subject/ns/NAMESPACE/sa/KSA_NAME. Use the project number, not the project ID.

When pods on GKE report missing or wrong credentials, check that the pod is on a node pool with the GKE metadata server enabled (on Standard clusters, pods need the iam.gke.io/gke-metadata-server-enabled: "true" node selector), that the target API supports federation, and that the IAM Service Account Credentials API is enabled. If an API has limitations, Google's alternative is to link the Kubernetes ServiceAccount to an IAM service account with a roles/iam.workloadIdentityUser binding and an annotation. With Istio or Cloud Service Mesh, containers can start before the proxy is ready and fail their first token request; Google points to the holdApplicationUntilProxyStarts annotation for this.

Fix outside Google Cloud with Workload Identity Federation

CI pipelines, workloads on AWS or Azure, and on-premises services are where keys are most often created, because there is no metadata server to fall back on. Workload Identity Federation fills that gap. Google's federation documentation says it lets on-premises and multicloud workloads access Google Cloud using federated identities instead of service account keys, and that it removes the maintenance and security burden that comes with keys.

Supported identity sources include AWS, Azure, X.509 client certificates, on-premises Active Directory, deployment pipelines such as GitHub and GitLab, Kubernetes clusters, Terraform, and any provider that supports OIDC or SAML 2.0. The building blocks are:

  • A workload identity pool per environment, such as development, staging and production, as Google generally recommends.
  • A provider describing the trust with the external identity provider. Google Security Token Service verifies the external credential and returns a federated token.
  • Attribute mappings, where google.subject is required, and attribute conditions, CEL expressions that reject any credential that does not match. Use conditions to pin access to a specific repository, branch, AWS account or cluster.
  • Access, either granted directly to federated principals on resources, which Google recommends, or through service account impersonation, where the service account needs roles/iam.workloadIdentityUser.

The workload then sets GOOGLE_APPLICATION_CREDENTIALS to a credential configuration file. That file describes where to obtain the external token and which provider to exchange it with. It is not a secret on its own, so it can live in the repository or image. The ADC search order is the same as before; only the file type changes.

Google warns that granting access to all identities in a pool can incur risk and recommends limiting access with attributes and conditions. A provider with no condition, trusting every token from a public CI issuer, is the federation equivalent of a shared key. For GitHub specifically, see the GitHub Actions OIDC Federation Hardening Guide.

Quota project, scope and file type errors

Several ADC errors are not about missing identity at all, and creating a key does not fix them.

Quota project errors

When you use user credentials with a client-based API, Google needs a quota project for billing and quota, and the API must be enabled in it. Google's troubleshooting page gives three fixes: gcloud auth application-default set-quota-project YOUR_PROJECT, gcloud config set billing/quota_project YOUR_PROJECT for gcloud itself, or the x-goog-user-project header on direct REST or RPC calls. You need serviceusage.services.use, included in the Service Usage Consumer role, on the project you choose. The "Unknown project 764086051850" error has the same fix: that number is the gcloud CLI's own project, and your requests are being attributed to it because neither project nor quota project is set.

Scope errors during login

By default, tokens from a user credential ADC file include the cloud-platform scope only. Requesting other scopes, such as Google Drive, triggers "This app is blocked" or "Access blocked: Authorization Error". Google's fixes are to create an OAuth client ID and run gcloud auth application-default login --client-id-file=CLIENT_ID_FILE --scopes=SCOPES, or to impersonate a service account with --impersonate-service-account=SERVICE_ACCOUNT_EMAIL --scopes=SCOPES.

Unrecognised credential type

"Error creating credential from JSON. Unrecognized credential type" means an OAuth client ID file was supplied. ADC does not accept client ID files as credentials. Use user credentials from the gcloud login, or a federation credential configuration file.

Credentials ignored or the wrong identity used

Google lists four reasons credentials are not found or do not give the expected access: gcloud is using gcloud auth login credentials rather than ADC; GOOGLE_APPLICATION_CREDENTIALS is set when it should not be; the principal lacks IAM roles; or an API key is overriding ADC. Google's guidance is to set the environment variable only when using a key or other JSON credential file, and to unset it if you are using an API key and see an ignored credentials warning.

A key-free triage procedure

  1. Record the exact error and the environment. Language, library version, and whether the code runs on a laptop, Google Cloud compute, GKE or elsewhere.
  2. Check the environment variable. Print GOOGLE_APPLICATION_CREDENTIALS. If it is set, confirm the file exists, identify its type (key, federation configuration, or something else), and ask whether it should be set at all.
  3. Check the local ADC file on workstations. If it is missing, run the gcloud ADC login. If it was created with impersonation and your library rejects it, recreate it with user credentials.
  4. Check the metadata path on Google Cloud and GKE: attached service account, GKE metadata server enabled on the node pool, and network access to the metadata endpoint.
  5. Check federation outside Google Cloud: credential configuration file present, provider condition matching the token's claims, and the federated principal or service account holding the right roles.
  6. Separate identity from permission. Once a token is obtained, a 403 is an IAM problem, not an ADC problem. Move to the permission troubleshooting guide.
  7. Do not create a key to get past the error. If a team believes a key is the only option, record why, set an expiry date for the exception, and track it in your key inventory.

Detection and prevention

Every key created to fix an ADC error is a future exposure, so measure how often it happens. Useful signals are new service account key creation events in Cloud Audit Logs, keys whose first use comes from a developer IP range or CI runner, and container images or repositories containing "type": "service_account" JSON. Organisation policy constraints can block key creation and upload entirely, which forces teams to use the federation paths above. Our Google Cloud Service Account Keys Security Guide covers those controls, and How to inventory Google Cloud service account keys and replace them with federation covers migrating keys that already exist.

Give developers a short internal page that maps each environment to its approved ADC method. Most keys created to fix ADC errors are created because the developer did not know another way existed.

Common failure patterns

  • "It works in gcloud but not in my code". The developer has a gcloud auth login session but no ADC file. Run the ADC login.
  • Stale environment variable in an image. GOOGLE_APPLICATION_CREDENTIALS copied from a Dockerfile or shell profile blocks the metadata server on Cloud Run or GKE.
  • Key downloaded to bypass a quota project error. The real fix was set-quota-project, and the key now sits in a downloads folder.
  • Project-level Token Creator for local impersonation. Granting the role at project level to make impersonation work lets developers impersonate every service account in the project.
  • Federation provider with no attribute condition. Any token from the issuer is accepted, so any repository or account on that platform can obtain access.
  • Node pool not using the GKE metadata server. Pods fall back to the node service account or fail, and someone mounts a key as a Kubernetes Secret.
  • Local ADC file shipped in a build. A developer's refresh token ends up in an image because the home directory was copied.

Practitioner checklist

  • Identify which of the three ADC sources should supply credentials in each environment.
  • Remove GOOGLE_APPLICATION_CREDENTIALS from any environment that should use the metadata server.
  • Use gcloud auth application-default login, with impersonation where needed, on workstations.
  • Grant Service Account Token Creator on individual service accounts only.
  • Attach least privileged user-managed service accounts to Google Cloud compute.
  • Enable Workload Identity Federation for GKE on every Standard node pool.
  • Use Workload Identity Federation with attribute conditions for CI and other clouds.
  • Fix quota project and scope errors with the documented commands, not with keys.
  • Alert on new service account key creation and enforce key creation restrictions through organisation policy.
  • Revoke local ADC credentials when a developer leaves a project.

Standards and references

Related NHI Mgmt Group resources: Google Cloud PERMISSION_DENIED Troubleshooting Guide · Google Cloud Service Account Keys Security Guide · How to inventory Google Cloud service account keys and replace them with federation · Cloud Workload Identity Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.