When Google Cloud detects that a service account key has been exposed publicly, it will usually have disabled the key before anyone on your team reads the alert, so the first job is not containment but working out what broke, what the attacker could have done with the key and whether the key should ever be switched back on. This guide walks through the response in order: reading the alert and the key metadata, scoping impact from audit logs, deciding whether a temporary re-enable is justified, replacing the key and closing the policy gaps that let it leak.
For the background on service account keys, the organisation policy constraints and the hardening baseline, read the Google Cloud Service Account Keys Security Guide. For the planned, non-emergency project of removing keys, see How to inventory Google Cloud service account keys and replace them with federation. This page covers the incident in between.
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
- Auto-disable is the default. Google documents that since 16 June 2024, if the
iam.serviceAccountKeyExposureResponseconstraint has no value set, Google Cloud behaves as if it were set toDISABLE_KEY: it disables an exposed key, writes a Cloud Audit Logs event and notifies project owners and security contacts. - A disabled key is not the end of the incident. The key was public for some period before detection. Disabling it stops new authentication with the key, but Google documents that disabling does not revoke short-lived credentials already issued from it.
- The metadata tells you where it leaked. A key disabled for exposure carries a disable reason of exposure, an extended status of key exposed and, when available, a link to where the key was detected. The extended status persists even after re-enabling.
- Re-enabling is an outage measure, not a fix. Google allows re-enabling an exposed key to resolve an outage but recommends disabling it again as soon as possible. Every minute it is enabled, anyone who copied it can use it.
- Deleting the file from the repository is not enough. Google states the key must be deleted in IAM as quickly as possible, and that removing it from source code alone is not sufficient.
- Detection is not guaranteed. Google states it does not guarantee it will detect exposed keys, so the alert is a backstop, not a control.
What the alert means
Google Cloud scans for service account keys exposed in public places. When it finds one, Google documents the following sequence:
- An abuse event is created in the Abuse Event logs.
- If the exposure response is
DISABLE_KEY(set explicitly or by default), the key is disabled automatically, and the audit logs show the principal[email protected]as the actor that disabled it. - The key's
extendedStatus.valuefield is set, including the location where the leak was detected. - Project owners and security contacts are notified.
The constraint has two documented values:
| Value | Documented behaviour |
|---|---|
DISABLE_KEY | Google Cloud automatically disables the exposed key, creates an audit log event and sends notifications. Google strongly recommends this value. |
WAIT_FOR_ABUSE | Google Cloud does not proactively disable the key, though it might still disable it if it is used in ways that adversely affect the platform. An audit log event and notifications are still created. Google warns this value increases the risk that exposed keys will be misused. |
If your organisation set WAIT_FOR_ABUSE, the alert reaches you with the key still live, and containment is your first step rather than your last.
There is one more variant to recognise. Google documents that for keys exposed between 16 January 2024 and 16 June 2024, audit logs were generated retroactively, the URL in extendedStatus.value contains #HISTORIC_EXPOSED_KEY_EXPOSURE_DATE, and none of those keys were disabled automatically. Google strongly advises rotating such keys as soon as possible. If you find this marker during a review, treat it as an open exposure, not historic noise.
Triage in the first hour
1. Confirm the alert and identify the key
From the notification or the audit log event, record the project, the service account email and the key ID. Check the key's metadata. Google documents these values for a key disabled because it leaked:
| Field | Value | What it tells you |
|---|---|---|
disable_reason | SERVICE_ACCOUNT_KEY_DISABLE_REASON_EXPOSED | Google disabled the key because it was exposed, not a team member |
extended_status | SERVICE_ACCOUNT_KEY_EXTENDED_STATUS_KEY_EXPOSED | The key has been flagged as exposed; this persists after re-enabling |
extended_status_message | A link to the exposure, when available | Where Google found the key |
In the audit logs, look for the disable action by [email protected] to fix the time the key stopped working.
2. Follow the exposure link
Use the link to find the file, commit or page where the key appeared. You need to know four things: who published it, when it was first published, whether it is still there, and whether other secrets were exposed alongside it. A key committed to a public repository is often accompanied by other credentials in the same file or history. Treat the location as a possible source of more exposures and scan it; the Developer Secret Scanning Triage guide covers how to do this quickly.
3. Find out what broke
A disabled key cannot authenticate with Google APIs. Somewhere a workload is now failing. Ask the service account's owner, check monitoring for authentication errors from the systems that hold the key, and record the business impact. This decides whether you face pressure to re-enable, so get it in writing early.
4. Open an incident
A public credential exposure is a security incident even when the key was disabled automatically. Assign an incident lead, a service owner and someone to run log analysis, and start a timeline with: first exposure time, detection time, disable time and every action you take from here.
Assess the impact
The question is what anyone holding the key could have done between first exposure and disablement, and whether they did it.
What could the key reach
List every IAM role granted to the service account, at project, folder and organisation level and on individual resources. Include roles that let the account act as other service accounts, because those extend the reach of the key beyond the account itself. The answer defines the maximum blast radius and the services whose audit logs you need.
What did the key do
Search Cloud Audit Logs for activity by the service account over the full exposure window, starting from the earliest publication time you found, not the detection time. Google documents two fields that help:
principalEmailidentifies the principal that initiated each audited action.serviceAccountKeyName, which many services add to their audit records, identifies the key that was used, which separates activity by the exposed key from activity by the account's other keys or attached identities.
Look for activity from caller IP addresses and user agents that do not match the legitimate workload, actions the workload never performs, creation of new keys or new service accounts, IAM policy changes, and data reads or exports from storage and databases. Google also documents a Key Authentication Events metric that shows when a key was last used and how often it authenticated, which gives a quick first view before detailed log work.
Be explicit about gaps: check which audit log types were enabled for each service and how far back retention reaches, and record which services you could and could not examine. If the window predates your log retention, say so in the incident record rather than concluding "no activity found". The Cloud Forensics Guide covers evidence preservation and timelines in more depth.
Look for persistence
An attacker who used the key may have created a foothold that survives its disablement. Check for:
- New keys created on this or any other service account during the window.
- New service accounts, or new IAM bindings granting roles to unfamiliar principals.
- Changes to organisation policies, logging sinks or other controls.
- New compute resources, which can indicate resource abuse.
If you find any, the incident is a confirmed compromise. Escalate under your cloud incident process and use the Leaked Secret Validation Detection guide to look for the pattern of an attacker testing the credential before use.
Contain
With DISABLE_KEY, the key is already disabled. Containment then means making sure nothing else lets the attacker back in:
- If the key is still enabled (for example under
WAIT_FOR_ABUSE), disable it now. Google documents that you cannot disable a key from the console; use the gcloud CLI or the REST API:gcloud iam service-accounts keys disable KEY_ID --iam-account=SA_NAME@PROJECT_ID.iam.gserviceaccount.com --project=PROJECT_ID - Consider already-issued credentials. Google documents that disabling a key does not revoke short-lived credentials already issued from it, and that revoking those requires disabling or deleting the service account, which stops every workload using it. If you see suspicious activity continuing after the disable time, this is the lever, and it is a business decision because of the wider outage.
- Remove persistence you found: delete keys and service accounts created by the attacker, and revert IAM and policy changes.
- Remove the key from where it was published, while keeping a copy of the evidence for the incident record. Google is clear this is not sufficient on its own; the IAM key still has to be deleted.
Deciding whether to re-enable the key
This is the decision teams most often get wrong under pressure. Google documents that you can re-enable an exposed key to resolve an outage, and recommends disabling it again as soon as possible. The re-enable command is:
gcloud iam service-accounts keys enable KEY_ID --iam-account=SA_NAME@PROJECT_ID.iam.gserviceaccount.com --project=PROJECT_ID
Enabling, like disabling, is not available in the console. The Service Account Key Admin role (roles/iam.serviceAccountKeyAdmin) on the project or the service account provides the permissions.
Use a short written test before anyone runs that command:
| Question | If the answer is no |
|---|---|
| Is the outage serious enough that the business owner accepts that anyone with a copy of the key can use it while enabled? | Do not re-enable; restore service with a new credential instead |
| Has impact assessment found no sign of malicious use so far? | Do not re-enable; treat as confirmed compromise |
| Is the key's public copy removed, and is a replacement credential being prepared now? | Fix those first |
| Is there a named owner, a fixed end time and someone watching the account's audit logs while it is enabled? | Do not re-enable without them |
In most cases the faster safe route is to issue the workload a new credential rather than revive the exposed one. If you do re-enable, record the window, monitor the key's activity throughout, and disable and delete it at the end. The exposed status stays on the key after re-enabling, so it will continue to show up in reviews until it is deleted.
Recover: replace the credential and delete the key
Recovery has two parts: get the workload running on a credential that was never public, then delete the exposed key in IAM.
- Pick the replacement. The best outcome is no key at all: an attached service account for workloads on Google Cloud, or workload identity federation for workloads elsewhere. The planned migration steps are in How to inventory Google Cloud service account keys and replace them with federation, and federation from other clouds is covered in Cross-cloud workload identity federation. If a key is the only option in the time available, create a new key, store it in a secrets manager rather than a file in the repository, and plan its removal.
- Review the account's roles. If the account had broader roles than the workload needs, narrow them now, while the owner's attention is on it.
- Cut over and confirm the workload authenticates with the new credential.
- Delete the exposed key in IAM. Google is explicit that the key must be deleted in IAM as quickly as possible and that deleting it from the repository alone is not sufficient. Confirm the cutover first, because the key is not coming back after this step.
- Clean the history. If the key was committed to version control, it remains in history even after the file is deleted. Rewriting history is optional once the key is deleted in IAM, because the key no longer works, but scan the history for other secrets.
Prevent recurrence
- Set the exposure response explicitly. Even though
DISABLE_KEYis the default when unset, set it at the organisation root so the intent is visible and nobody changes it quietly. Google documents that this constraint cannot be merged with a parent policy; you replace the parent policy to enforce it. The documented gcloud form isgcloud resource-manager org-policies allow iam.serviceAccountKeyExposureResponse DISABLE_KEY --organization=ORGANIZATION_ID. - Stop new keys. The
iam.disableServiceAccountKeyCreationconstraint prevents the creation of new external service account keys, and Google documents that it is enforced by default for organisations created on or after 3 May 2024;iam.disableServiceAccountKeyUploadhas the same default. Older organisations should enforce them deliberately, with exception projects for the remaining key users. - Use one key per machine where keys remain. Google notes that a dedicated key per machine makes
serviceAccountKeyNameuseful for tracing where activity came from, which would have shortened this investigation. - Make sure the alert reaches people. Notifications go to project owners and security contacts. Review security contacts in Essential Contacts so alerts reach a team that acts on them, and if you keep
WAIT_FOR_ABUSEanywhere, Google advises subscribing to the Cloud Audit Logs events. - Scan before Google does. Because Google does not guarantee detection, run secret scanning on commits and pushes; see the Git Secret Scanning Guide.
- Keep a rotation runbook. Google notes that an established key rotation process helps you act quickly on a suspected compromise.
Common failure patterns
- Re-enabling to make the outage go away, then forgetting to disable the key again. The key stays usable by whoever copied it.
- Scoping from detection time. The key was public before Google found it. Start log searches from the first publication time.
- Treating auto-disable as closure. The incident record says "key disabled by Google" and nobody checks for attacker activity or persistence.
- Deleting the file but not the key. Google states this is not sufficient.
- Ignoring historic exposures. Keys marked with
#HISTORIC_EXPOSED_KEY_EXPOSURE_DATEwere never disabled automatically and may still work. - Alerts going to a departed project owner. The notification is only as useful as the contact list.
- Replacing the key with another key in the same place. If the new key is committed to the same repository, the cycle repeats.
Practitioner checklist
- Record project, service account, key ID, disable time and the exposure link from the key metadata.
- Confirm the disable action by
[email protected]in the audit logs, or disable the key yourself if it is still enabled. - Find the first publication time and remove the public copy, keeping evidence.
- List every role the service account holds, including roles over other service accounts.
- Search audit logs from first publication to disable time using
principalEmailandserviceAccountKeyName; record services with no available logs. - Check for new keys, service accounts, IAM bindings, policy changes and compute resources created in the window.
- Apply the re-enable test in writing; if re-enabled, set an end time, monitor and disable again.
- Move the workload to an attached service account, federation or, at minimum, a new key held in a secrets manager.
- Delete the exposed key in IAM after cutover.
- Set
iam.serviceAccountKeyExposureResponsetoDISABLE_KEYat the organisation root and enforce key creation and upload restrictions. - Review Essential Contacts security contacts and project owners for the affected projects.
Standards and references
- Google Cloud: Restricting service account usage (organisation policy constraints)
- Google Cloud: Disable and enable service account keys
- Google Cloud: Best practices for managing service account keys
- OWASP: Non-Human Identities Top 10 2025
- MITRE ATT&CK: Valid Accounts: Cloud Accounts (T1078.004)
- MITRE ATT&CK: Credentials In Files (T1552.001)
- NIST SP 800-53 Rev. 5: IA-5 Authenticator Management and AC-6 Least Privilege
Related NHI Mgmt Group resources: Google Cloud Service Account Keys Security Guide · How to inventory Google Cloud service account keys and replace them with federation · Cloud Forensics Guide · Developer Secret Scanning Triage