1. Resources
  2. Detection rules
  3. Service Account Key Created

Service Account Key Created detection rules

An attacker creates a user-managed key for a Google Cloud service account and keeps using it from outside the environment, with the service account's roles and no expiry by default.

Platform
Google Cloud
Severity
High
Log source
Google Cloud Audit Logs
Last updated
Rule formats
Sigmaand queries for: SplunkMicrosoft SentinelIBM QRadar
What an attacker needs
The iam.serviceAccountKeys.create permission on the target service account, with key creation or upload not blocked by organization policy.
Impact
Durable access with the service account's roles wherever it has bindings, which with Owner, Editor or IAM admin roles means control of the project or organization.
Response
Disable the key at once and delete it once no legitimate workload depends on it, and remove the key creation right from the identity that created it.
Mitigation
Enforce the organization policies that disable service account key creation and key upload, and use Workload Identity Federation for external workloads.
API methods
google.iam.admin.v1.CreateServiceAccountKeygoogle.iam.admin.v1.UploadServiceAccountKey
Threat groups
Storm-0501

How the attack works

Service accounts authenticate either with short-lived Google-managed credentials or with user-managed keys: JSON key files that can be downloaded once and used from anywhere until they are deleted. A principal with iam.serviceAccountKeys.create on a service account (part of the basic roles Owner and Editor, of Service Account Key Admin and IAM Admin, and of any custom role that includes it) can create such a key for it. The same permission allows uploading the public half of a key pair the caller generated, which works the same way.

Attackers create keys for service accounts that hold broad roles, then authenticate as them from their own infrastructure. The activity looks like ordinary service account traffic, and the key keeps working after the original foothold is cleaned up. Key files also leak. When Google finds a key exposed in a public place it disables the key by default and records that in the audit log, which a rule on this page reads.

What an attacker needs

  • Permission to create keys on the target service account (iam.serviceAccountKeys.create), at project, folder, organization or service account level.
  • Key creation not blocked by the iam.disableServiceAccountKeyCreation organization policy (or key upload by iam.disableServiceAccountKeyUpload), or their iam.managed equivalents.

Impact

Durable access with the service account's roles across every project where it has bindings. Service accounts with Owner, Editor or IAM admin roles turn this into control of the whole project or organization.

Detection rules

Exposed Service Account Key Disabled by Google

Detects an IAM action by the principal Google uses for its exposure response. Google documents that when it finds a service account key exposed, for example in a public repository, and disables it, the audit logs contain the disable action by the principal gcp-compromised-key-response@system.gserviceaccount.com (organization policy constraint iam.serviceAccountKeyExposureResponse, where DISABLE_KEY is the default). The caller is not an attacker, but the entry says that the key has leaked: anyone who found it could have used it before Google did. Google's page names the principal and not the method, so the rule matches any IAM API entry of that principal. With the constraint set to WAIT_FOR_ABUSE Google does not disable exposed keys proactively and this entry is not written.

LevelHighStatusExperimentalLog sourceGoogle Cloud Audit Logs
title: Exposed Service Account Key Disabled by Google
id: 1aa0c67f-c452-4a8f-a2df-e1b847dbcb9a
status: experimental
description: >-
  Detects an IAM action by the principal Google uses for its exposure
  response. Google documents that when it finds a service account key
  exposed, for example in a public repository, and disables it, the audit
  logs contain the disable action by the principal
  gcp-compromised-key-response@system.gserviceaccount.com (organization
  policy constraint iam.serviceAccountKeyExposureResponse, where DISABLE_KEY
  is the default). The caller is not an attacker, but the entry says that
  the key has leaked: anyone who found it could have used it before Google
  did. Google's page names the principal and not the method, so the rule
  matches any IAM API entry of that principal. With the constraint set to
  WAIT_FOR_ABUSE Google does not disable exposed keys proactively and this
  entry is not written.
references:
  - https://docs.cloud.google.com/resource-manager/docs/organization-policy/restricting-service-accounts
  - https://docs.cloud.google.com/iam/docs/keys-disable-enable
  - https://attack.mitre.org/techniques/T1098/001/
author: Forestall
date: 2026-11-18
tags:
  - attack.persistence
  - attack.t1098.001
logsource:
  product: gcp
  service: gcp.audit
detection:
  selection:
    protoPayload.serviceName: iam.googleapis.com
    protoPayload.authenticationInfo.principalEmail: gcp-compromised-key-response@system.gserviceaccount.com
  condition: selection
falsepositives:
  - None expected. Every match means Google found one of your keys exposed. Test keys published on purpose are the only harmless case.
level: high

False positives

  • None expected. Every match means Google found one of your keys exposed. Test keys published on purpose are the only harmless case.

User-Managed Service Account Key Created in Google Cloud

Detects creation of a user-managed key for a Google Cloud service account (Admin Activity audit log). In environments that use Workload Identity Federation, any new key is unexpected.

LevelMediumStatusExperimentalLog sourceGoogle Cloud Audit Logs
title: User-Managed Service Account Key Created in Google Cloud
id: 27383280-3765-4183-9e49-68ae66b11f4b
status: experimental
description: >-
  Detects creation of a user-managed key for a Google Cloud service account
  (Admin Activity audit log). In environments that use Workload Identity
  Federation, any new key is unexpected.
references:
  - https://attack.mitre.org/techniques/T1098/001/
author: Forestall
date: 2026-11-10
tags:
  - attack.persistence
  - attack.t1098.001
logsource:
  product: gcp
  service: gcp.audit
detection:
  selection:
    protoPayload.serviceName: iam.googleapis.com
    protoPayload.methodName: google.iam.admin.v1.CreateServiceAccountKey
  condition: selection
falsepositives:
  - Legacy workloads that still rely on key files; track them and migrate to Workload Identity Federation.
level: medium

False positives

  • Legacy workloads that still rely on key files; track them and migrate to Workload Identity Federation.

Public Key Uploaded to a Service Account in Google Cloud

Detects the upload of a public key to a Google Cloud service account (Admin Activity audit log). The caller keeps the private half, so the uploaded key authenticates as the service account exactly like a key created through Google. Uploads need the same iam.serviceAccountKeys.create permission and have their own organization policy constraint (key upload), separate from the key creation constraint.

LevelMediumStatusExperimentalLog sourceGoogle Cloud Audit Logs
title: Public Key Uploaded to a Service Account in Google Cloud
id: 5d0b7a4e-3c1f-4c59-9a0e-6b1f2c8d7e31
status: experimental
description: >-
  Detects the upload of a public key to a Google Cloud service account (Admin
  Activity audit log). The caller keeps the private half, so the uploaded key
  authenticates as the service account exactly like a key created through
  Google. Uploads need the same iam.serviceAccountKeys.create permission and
  have their own organization policy constraint (key upload), separate from
  the key creation constraint.
references:
  - https://docs.cloud.google.com/iam/docs/audit-logging
  - https://docs.cloud.google.com/resource-manager/docs/organization-policy/restricting-service-accounts
author: Forestall
date: 2026-11-11
tags:
  - attack.persistence
  - attack.t1098.001
logsource:
  product: gcp
  service: gcp.audit
detection:
  selection:
    protoPayload.serviceName: iam.googleapis.com
    protoPayload.methodName: google.iam.admin.v1.UploadServiceAccountKey
  condition: selection
falsepositives:
  - Workloads that bring their own key pair, for example keys held in a hardware security module; uploads are rare, so review each one and allow-list the service account by protoPayload.resourceName.
level: medium

False positives

  • Workloads that bring their own key pair, for example keys held in a hardware security module; uploads are rare, so review each one and allow-list the service account by protoPayload.resourceName.

Detection logic

Patterns that need more than one event, a baseline or knowledge of your own environment. Each is a hypothesis to build and tune in your SIEM, not a ready rule.

New key used from an address the service account has not used before

Detection hypothesisSequence of eventsJoins two logsNeeds a baseline

A key created for persistence leaves the environment and is used from the attacker's own infrastructure. Google records in each entry the key that authenticated the call, so a key name that first appears soon after a key was created for the account, from an address the account has not used, ties the creation to use from outside.

  1. A google.iam.admin.v1.CreateServiceAccountKey entry from iam.googleapis.com. Google's example gives the service account in protoPayload.request.name and the creator in authenticationInfo.principalEmail. Note the creator's requestMetadata.callerIp as well.
  2. Within 7 days, entries whose authenticationInfo.principalEmail is that service account and whose authenticationInfo.serviceAccountKeyName holds a key name not seen for the account before the creation. Google documents that this field names the key used to authenticate the call.
  3. Compare the requestMetadata.callerIp of those entries with the addresses the service account used in the past 30 days and with your own egress ranges. Raise a new key used from an address outside both, together with the creator and the first methods the key was used for.

Eventsgoogle.iam.admin.v1.CreateServiceAccountKey

LimitsGoogle notes that App Engine and Compute Engine do not log the key name, and calls from inside Google Cloud can show private or gce-internal-ip instead of an address. A workload moved to a new host looks the same. A key used only for reads shows up only where Data Access logs are on, and uploaded keys are not covered by the first step. The 7 and 30 days are starting points.

Key created for a service account that has not been used for months

Detection hypothesisCompares with an earlier valueNeeds a baseline

Old service accounts keep their roles after the workloads that used them are gone, and nobody watches them. A key created for such an account gives an attacker an identity whose activity no owner questions. Google's Event Threat Detection treats a user-managed service account inactive for more than 180 days as dormant and reports a key created for one.

  1. A google.iam.admin.v1.CreateServiceAccountKey or google.iam.admin.v1.UploadServiceAccountKey entry from iam.googleapis.com. Note the service account, in protoPayload.request.name for a created key, and the caller in authenticationInfo.principalEmail.
  2. Search the audit logs of the past 180 days for any entry whose authenticationInfo.principalEmail is that service account. Where the SIEM keeps less, use what it keeps and say so in the alert.
  3. Raise the key when there is none, with higher priority when the account holds roles on a project, folder or organization.

Eventsgoogle.iam.admin.v1.CreateServiceAccountKeygoogle.iam.admin.v1.UploadServiceAccountKey

LimitsAn account that only reads data writes Data Access entries, which exist only where those logs are on, so it can look unused when it is not. Accounts for rare jobs, such as yearly reports or disaster recovery, look dormant too. Google's response steps point to Activity Analyzer to confirm the last use of the account. The 180 days follow Google's definition and are a starting point.

Triage

  • Identify the service account (protoPayload.resourceName) and the creator (principalEmail); keys created by a human for a production service account need a reason.
  • Review the service account's role bindings to size the impact.
  • Disable or delete unexplained keys and search the audit logs for their key ID afterwards.

Response

Once the attack is confirmed:

  1. Disable the key at once, and delete it when you are sure that no legitimate workload uses it. Check the other keys of the service account too, including uploaded ones, because the same permission allows adding several.
  2. Do not rely on the key alone. Access tokens that were obtained with the key cannot be revoked and stay valid until they expire, by default up to 60 minutes. For a privileged service account, disable the account for at least that long, which cuts off every workload that uses it.
  3. Remove the key creation right from the identity that created or uploaded the key, and contain that identity.
  4. Review what the service account did while the key existed, and undo it. Look for new bindings, keys created on other service accounts and new resources.
  5. Check whether the organization policy that blocks key creation or key upload was changed shortly before the key appeared. A lifted constraint is part of the same intrusion and has to be restored.

Mitigation

  • Enforce the organization policies iam.managed.disableServiceAccountKeyCreation and iam.managed.disableServiceAccountKeyUpload (or the legacy constraints/iam.disableServiceAccountKeyCreation and constraints/iam.disableServiceAccountKeyUpload) and use Workload Identity Federation for external workloads.
  • Set constraints/iam.serviceAccountKeyExpiryHours where keys are unavoidable, and delete unused keys.
  • Keep admin roles off service accounts and avoid granting key-creation rights at project or higher scope.

Frequently asked questions

Does deleting the key end the attacker's access immediately?

Not entirely. A deleted key can no longer be used to obtain new tokens, but access tokens that were already issued exist separately from the key and cannot be revoked. They remain valid until they expire, by default up to 60 minutes. To block them sooner, Google's guidance is to disable the service account or apply a deny policy for it.

Is an uploaded key less dangerous than a key created through Google?

No. With an upload the caller generates the key pair and keeps the private half, and the uploaded public key authenticates as the service account exactly like a created key. It needs the same `iam.serviceAccountKeys.create` permission. It has its own audit method (`UploadServiceAccountKey`) and its own organization policy constraint, so blocking key creation alone does not block uploads.

How long does a user-managed service account key stay valid?

Until it is deleted. User-managed keys have no expiry by default, which is why a key created during an intrusion keeps working after the original foothold is cleaned up. Where keys are unavoidable, the organization policy `constraints/iam.serviceAccountKeyExpiryHours` sets an expiry.

When is a new service account key expected?

Where legacy workloads still rely on key files, or bring their own key pair, for example from a hardware security module. In environments that use Workload Identity Federation, any new key is unexpected. A key that a person creates for a production service account needs a reason in either case.

References

We respect your privacy

We use cookies to keep this site secure and working properly. With your permission, we also use optional cookies to understand usage and improve the experience. Cookie Policy

You can change your choice at any time.