Join our Newsletter — 33% off our NHI Course
Home› Guides› How to Investigate a Compromised Google Cloud Service…
Guide Incident Response & Forensics

How to Investigate a Compromised Google Cloud Service Account Key in Cloud Audit Logs: Fields, Queries and Scope

PDF for newsletter subscribers · free to read online

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

Once a Google Cloud service account key is known or suspected to be compromised, the size of the incident depends on one question: what did that key do, and what did it create that will outlive it? Cloud Audit Logs hold the answer, but only if you anchor on the right field, search every project the service account can reach, follow the short-lived credentials and impersonation chains the key may have started, and are honest about the log types that were never enabled. This guide is the investigation half of the response: the audit log fields that identify key use, the queries to run in Logs Explorer and Log Analytics, how to follow impersonation, and how to turn the results into a scoped list of credentials to revoke and resources to assess. It is written for cloud security engineers and incident responders. Responding to Google's own exposure alert is covered in How to respond to a Google Cloud exposed service account key alert, and containment across a whole project in the Google Cloud Project Compromise Playbook; this page assumes the key is disabled or about to be.

This is an independent guide from NHI Mgmt Group, based on Google Cloud's public documentation as of November 2026. It is not sponsored or reviewed by Google. Product features change, so confirm settings against Google Cloud's current documentation.

Key takeaways

  • Anchor on serviceAccountKeyName, not only the account: Google documents that when a key is used, the target service's audit log records the service account in principalEmail and the key in protoPayload.authenticationInfo.serviceAccountKeyName, which separates the compromised key from the account's other keys and attached identities.
  • Some services do not record the key: Google notes that App Engine and Compute Engine do not log serviceAccountKeyName, so pivot on caller IP, user agent and timing as well as the key field.
  • Impersonation evidence sits in Data Access logs: GenerateAccessToken calls to iamcredentials.googleapis.com are written to the data_access log only if IAM Data Access audit logs were enabled before the incident.
  • Retention sets your horizon: Admin Activity logs sit in the _Required bucket for 400 days; Data Access logs land in _Default, retained for 30 days unless you changed it. Search the full exposure window, not just the time since detection.
  • The deliverable is two lists: every credential, key, binding or identity the key created (to revoke) and every resource it read or changed (to assess), each with timestamps and the evidence gaps stated.

When you need this investigation

Run it whenever a service account key may have been used by someone other than its workload:

  • Exposure found: a JSON key file in a public or internal repository, container image, CI log, ticket or shared drive (ATT&CK T1552.001 Credentials In Files), or a Google exposed-key notification.
  • Detection fired: a Security Command Center finding about leaked credentials, a new key created for persistence (T1098.001 Additional Cloud Credentials) or an anomalous grant (T1098.003 Additional Cloud Roles).
  • Behaviour changed: a key authenticating from a new network, a dormant service account suddenly active (T1078.004 Cloud Accounts), unexpected GPU instances (T1496.001 Compute Hijacking) or data copied to another project (T1537 Transfer Data to Cloud Account).
  • Supplier or laptop incident: a vendor, CI system or developer machine that held the key file was compromised.

Before you query: confirm what logs exist

Write down the evidence boundary first, because it changes every conclusion that follows. Google's audit log types behave differently:

Audit log typeDefault state (as documented)Bucket and default retentionWhy it matters here
Admin Activity (cloudaudit.googleapis.com%2Factivity)Always written, cannot be disabled_Required, 400 days, not configurableKey creation, IAM policy changes, resource creation: the persistence evidence
System Event (%2Fsystem_event)Always written_Required, 400 daysChanges made by Google systems, useful for separating platform action from attacker action
Policy Denied (%2Fpolicy)On by default; can be excluded from storage_Default, 30 days unless changedCalls blocked by security policy (for example VPC Service Controls) show what the attacker tried
Data Access (%2Fdata_access)Off by default except BigQuery; must be enabled per service_Default, 30 days unless changedReads of data and metadata, and GenerateAccessToken impersonation events
  • Retention check: confirm the _Default bucket retention and whether an aggregated sink sends logs to a central project, bucket or BigQuery dataset with longer retention. User-defined buckets can keep logs from 1 to 3,650 days.
  • Data Access coverage: list which services had Data Access logs enabled during the window (organisation, folder and project audit config). If Cloud Storage DATA_READ was off, you cannot prove from audit logs whether objects were read.
  • Public resources: Google documents that resources granted to allUsers or allAuthenticatedUsers do not generate audit logs, so access to public buckets is invisible here.
  • Permissions: viewing Data Access logs in _Default needs the Private Logs Viewer role (roles/logging.privateLogViewer); Logs Viewer alone is not enough.
  • Preserve: audit log entries are immutable, but _Default entries age out. Export the relevant window to a dedicated bucket or BigQuery dataset on day one. The Google Cloud Audit Logs and Log Sinks Guide covers sink design.

The fields that identify key use

Every investigation query is built from a handful of AuditLog fields. Google's AuditLog reference defines serviceAccountKeyName as the name of the service account key used to create or exchange credentials, in the form //iam.googleapis.com/projects/PROJECT_ID/serviceAccounts/ACCOUNT/keys/KEY_ID. The GCP Audit Log Principal Fields page explains the principal fields in general; the table below is the subset that matters for a key investigation.

FieldWhat it tells youHow to use it
protoPayload.authenticationInfo.serviceAccountKeyNameThe specific key behind the callPrimary anchor: match on the compromised KEY_ID with the substring operator
protoPayload.authenticationInfo.principalEmailThe authenticated principal (the service account for key use)Secondary anchor for services that omit the key field
protoPayload.authenticationInfo.serviceAccountDelegationInfo[]Delegation history when the caller impersonated a service accountFind calls made by another service account that the compromised one impersonated
protoPayload.requestMetadata.callerIp, callerSuppliedUserAgentNetwork source and client stringSeparate the legitimate workload from the attacker; the user agent is caller-supplied and can be forged
protoPayload.serviceName, methodName, resourceNameWhich API, which operation, on which resourceBuild the action list and the affected resource list
protoPayload.status.codeResult of the call (google.rpc.Code; absent or 0 for success)Permission denied errors show what was attempted and failed
logNameWhich audit log type the entry came fromConfirms whether a gap is a coverage gap or genuine inactivity

Step-by-step investigation

  1. Fix the identifiers and the window. Record the project, service account email, unique ID and key ID. Set the window start at the earliest time the key could have been exposed (the commit date, image build date or file share date), not the detection time, and the end at the disable time plus a margin for short-lived tokens already issued. Google documents that disabling a key does not revoke short-lived credentials issued from it.
  2. Get a fast usage picture. In Cloud Monitoring, the metric iam.googleapis.com/service_account/key/authn_events_count (console name "Service account key authentication events") shows authentication traffic per key, successful or failed, filterable by key ID. Google keeps these metrics for six weeks and notes that a key can appear when it is listed during authentication (for example with Cloud Storage signed URLs) even if it was not used to sign in. Treat the metric as triage, not proof.
  3. Define the search scope. List every place the service account holds roles: project, folder and organisation bindings, plus resource-level bindings on buckets, datasets, secrets and topics. Each of those projects needs searching. The Cloud Asset Inventory Guide covers searching IAM policies across an organisation.
  4. Find every call made with the key. In Logs Explorer at organisation or folder scope, or against a central sink, filter on the key ID (sample query, replace values): protoPayload.authenticationInfo.serviceAccountKeyName:"KEY_ID" AND timestamp >= "2026-10-01T00:00:00Z". Export the results rather than reading them on screen.
  5. Catch calls that omit the key field. Run a second query on the service account for the same window: protoPayload.authenticationInfo.principalEmail="SA_NAME@PROJECT_ID.iam.gserviceaccount.com". Entries without serviceAccountKeyName may be the legitimate attached identity or a service that does not log the key; separate them by callerIp, user agent and the workload's known behaviour.
  6. Baseline the legitimate workload. From the weeks before exposure, list the caller IPs, user agents and methods the real workload uses. Anything outside that baseline in the window is a lead. Validation calls from a new network shortly after exposure often mark first attacker use.
  7. Follow impersonation. Query the data_access log for protoPayload.serviceName="iamcredentials.googleapis.com" AND protoPayload.authenticationInfo.principalEmail="SA_NAME@PROJECT_ID.iam.gserviceaccount.com" to find GenerateAccessToken, GenerateIdToken, SignBlob and SignJwt calls made by the compromised account. Each target service account (resource.labels.email_id) then needs its own search, filtering on serviceAccountDelegationInfo, where the compromised account appears as the first-party principal. See How to Audit GCP Service Account Impersonation Rights.
  8. Hunt for persistence. In the activity log, search the window for methodName values CreateServiceAccountKey, UploadServiceAccountKey, CreateServiceAccount, EnableServiceAccountKey, SetIamPolicy (on projects, folders, the organisation and individual resources), CreateRole and UpdateRole, plus organisation policy changes and new logging sinks or exclusions. Check new keys on any service account, not only the compromised one.
  9. Build the data access list. Where Data Access logs were enabled, search for reads and exports by the key or its child identities: storage object reads, BigQuery jobs and extracts, Secret Manager AccessSecretVersion, and snapshot or image creation. BigQuery Data Access logs are on by default, so they are often the best data evidence available.
  10. Review failures. Filter on status codes for permission denied and the policy log. Failed attempts show intent (for example, an attempt to read Secret Manager or to grant Owner) and tell you which controls held.
  11. Aggregate with SQL. For large windows, an upgraded log bucket in Log Analytics or a linked BigQuery dataset lets you group calls by caller IP, method and project. Google notes that logs written before an upgrade are backfilled, which may take several days, so upgrade early or query the BigQuery sink directly.
  12. Write the findings. Produce the two lists (created identities and credentials; resources read or changed), the timeline, and a coverage statement naming every service and period you could not examine.

What to look for: indicators by method

IndicatorWhere (service and method)InterpretationATT&CK
New key on any service accountiam.googleapis.com CreateServiceAccountKey or UploadServiceAccountKey (Admin Activity)Persistence that survives disabling the original keyT1098.001
Role grant to an unfamiliar principalSetIamPolicy on project, folder, organisation or resourcePersistence or privilege escalation, often to an external accountT1098.003
Token minted for another service accountiamcredentials.googleapis.com GenerateAccessToken (Data Access)Lateral movement to a more privileged identityT1078.004
Key authenticating from a new networkAny service, entries with serviceAccountKeyName and an unknown callerIpUse of the key outside the workloadT1078.004
New compute or GPU instancescompute.googleapis.com instance insert (Admin Activity)Resource abuse, often crypto-miningT1496.001
Data copied to another projectBigQuery extract or copy jobs, storage rewrite or copyExfiltration to an attacker-controlled projectT1537
Logging sinks or exclusions changedlogging.googleapis.com sink or exclusion methods (Admin Activity)Attempt to reduce future visibilityDefense Impairment tactic (TA0112)

For ongoing detections built from these patterns see How to Detect Service Account Misuse.

Decision guidance

  • Logs Explorer or Log Analytics: Logs Explorer is fine for a single project and a short window. For an organisation-wide search over weeks, use a central sink to BigQuery or an upgraded bucket so you can aggregate and keep the result set as evidence.
  • Disable the key or the service account: disabling the key stops new authentication with it. If you see activity continuing after the disable time, short-lived tokens or child impersonation tokens are still live, and only disabling or deleting the service account (or a deny policy) stops them, at the cost of an outage for every workload using it.
  • When to widen to a project compromise: any confirmed persistence (new key, new binding, new service account) or impersonation of a more privileged account means you are no longer investigating one key. Move to the Google Cloud Project Compromise Playbook.
  • Small and large estates: a single project with Data Access logs off can be investigated in an afternoon, with a short coverage statement. An organisation with shared VPCs, folder-level roles and many impersonation paths needs a central sink, a scripted query set and a second analyst to check the scope.

Where identity fits

The investigation is only as good as the inventory behind it. A service account with an owner, a documented workload and a single key makes the baseline obvious; a shared account used by several teams makes every log line ambiguous. After the incident, the identity work is to remove the conditions that made this key dangerous: replace downloaded keys with attached service accounts or Workload Identity Federation, enforce the organisation policy constraints that block key creation and upload, and remove broad impersonation grants. See the Google Cloud Service Account Keys Security Guide and How to Federate GitHub Actions to Google Cloud.

Detection and measurement

  • Data Access coverage: percentage of production projects with Data Access logs enabled for IAM, Cloud Storage and Secret Manager, checked before the next incident.
  • Retention horizon: days of audit logs available in a central, longer-retention destination (target well beyond 30 days for Data Access logs).
  • Key-based share: percentage of service account API calls carrying serviceAccountKeyName, trending down as keys are replaced.
  • Time to scoped findings: hours from incident open to the two finished lists with a coverage statement.
  • Keys per service account: count of user-managed keys in the organisation and the number of accounts with more than one active key.

Framework mapping

Investigation activityNIST CSF 2.0NIST SP 800-53 Rev. 5
Analysing key activity and building the timelineRS.AN-03, DE.AE-02AU-6 Audit Record Review, Analysis, and Reporting; IR-4 Incident Handling
Log retention and Data Access coverageDE.CM-01AU-11 Audit Record Retention
Revoking created keys, accounts and bindingsRS.MI (incident mitigation)AC-2 Account Management; IR-4

Common failure patterns

  • Searching from detection time: the window starts when the alert fired rather than when the key was first exposed, missing weeks of use.
  • Single-project search: the analyst searches the key's home project while the service account holds roles in other projects or at folder level.
  • Treating "no results" as "no activity": Data Access logs were off or aged out of _Default, and the report does not say so.
  • Stopping at the first identity: GenerateAccessToken calls to a more privileged account are not followed, so the real blast radius is missed.
  • Relying on the key field alone: services that do not log serviceAccountKeyName hide activity that a principalEmail and callerIp search would have found.
  • Revoking before preserving: keys and bindings are deleted before the window is exported, and the _Default entries expire during a long incident.

Practitioner checklist

  • Record project, service account email, unique ID and key ID, and set the window from earliest exposure.
  • Export the window from every relevant project to a preserved bucket or BigQuery dataset on day one.
  • Write the coverage statement: which log types and services were enabled and for how long.
  • Check the key authentication metric for a first view, then confirm in audit logs.
  • Query by serviceAccountKeyName and separately by principalEmail, and compare against the workload baseline.
  • Follow every GenerateAccessToken, SignBlob and SignJwt call to the target service accounts.
  • Hunt for new keys, service accounts, IAM bindings, roles and logging changes across the organisation.
  • Deliver the two lists, the timeline and the gaps, then hand off to containment and eradication.
  • After closure, enable Data Access logs for IAM and key data services and extend retention centrally.

Standards and references

Related NHI Mgmt Group resources: Google Cloud IAM and Service Accounts Guide · Google Cloud Service Account Keys Security Guide · How to respond to a Google Cloud exposed service account key alert · GCP Audit Log Principal Fields

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.