1. Resources
  2. Detection rules
  3. Impersonation Rights Granted on a Service Account in Google Cloud

Impersonation Rights Granted on a Service Account in Google Cloud detection rules

An attacker changes the allow policy of one service account so that an identity they control can mint its tokens, attach it to resources or manage its keys, a quiet backdoor that no project-level IAM change reveals.

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.serviceAccounts.setIamPolicy permission on the target service account, granted on the account itself or inherited from its project, folder or organization.
Impact
The added principal can act with the service account's roles for as long as the binding exists, from wherever it signs in.
Response
Remove the added binding from the service account's allow policy, and delete any keys that were created or uploaded for the account after the binding was added.
Mitigation
Limit Service Account Admin, Security Admin and Owner on projects that hold privileged service accounts, and manage service account policies as code.
API method
google.iam.admin.v1.SetIAMPolicy

How the attack works

Every service account is also a resource with its own allow policy. A binding on that policy decides who may act as the account: Service Account Token Creator lets a principal mint its access and ID tokens, Service Account User lets a principal attach it to a VM, function or job, Workload Identity User lets a federated identity impersonate it, and Service Account Key Admin and Service Account Admin let a principal create keys for it or rewrite the policy again.

Attackers who can set this policy (iam.serviceAccounts.setIamPolicy, part of Owner, Security Admin, IAM Admin and Service Account Admin) add their own user, an external account or a federated principal to a privileged service account. The project's allow policy does not change, so reviews and detections that only watch project, folder and organization policies miss it. The IAM API records the call as google.iam.admin.v1.SetIAMPolicy in the Admin Activity audit log, with the added binding in serviceData.policyDelta.bindingDeltas.

What an attacker needs

  • iam.serviceAccounts.setIamPolicy on the target service account, granted on the account itself or inherited from its project, folder or organization.
  • A principal to add. External accounts work unless domain restricted sharing is enforced.

Impact

The added principal can act with the service account's roles for as long as the binding exists, from wherever it signs in. Token requests made through it are only recorded when Data Access audit logs are enabled for the IAM API.

Detection rules

Impersonation or Key Management Role Granted on a Google Cloud Service Account

Detects a change to the allow policy of a single service account (google.iam.admin.v1.SetIAMPolicy) whose policy delta adds a binding for a role that lets the member act as the account or manage its keys or policy: Service Account Token Creator, Service Account User, Workload Identity User, OpenID Connect Identity Token Creator, Service Account Key Admin or Service Account Admin (Admin Activity audit log). The action and the role are matched in the serialized bindingDeltas list, so a call that removes one of these roles while adding another binding also matches. Google's documented example for this method is abbreviated; the policyDelta shape used here follows published log samples and should be confirmed on a live entry before the rule is relied on.

LevelMediumStatusExperimentalLog sourceGoogle Cloud Audit Logs
title: Impersonation or Key Management Role Granted on a Google Cloud Service Account
id: ec7d1899-c3e3-4961-aad0-8b71e73ec728
status: experimental
description: >-
  Detects a change to the allow policy of a single service account
  (google.iam.admin.v1.SetIAMPolicy) whose policy delta adds a binding for a
  role that lets the member act as the account or manage its keys or policy:
  Service Account Token Creator, Service Account User, Workload Identity User,
  OpenID Connect Identity Token Creator, Service Account Key Admin or Service
  Account Admin (Admin Activity audit log). The action and the role are matched
  in the serialized bindingDeltas list, so a call that removes one of these
  roles while adding another binding also matches. Google's documented example
  for this method is abbreviated; the policyDelta shape used here follows
  published log samples and should be confirmed on a live entry before the rule
  is relied on.
references:
  - https://docs.cloud.google.com/iam/docs/audit-logging
  - https://docs.cloud.google.com/iam/docs/service-account-permissions
  - https://stratus-red-team.cloud/attack-techniques/GCP/gcp.persistence.backdoor-service-account-policy/
author: Forestall
date: 2026-11-11
tags:
  - attack.persistence
  - attack.privilege-escalation
  - attack.t1098.003
logsource:
  product: gcp
  service: gcp.audit
detection:
  selection:
    protoPayload.serviceName: iam.googleapis.com
    protoPayload.methodName: google.iam.admin.v1.SetIAMPolicy
    protoPayload.serviceData.policyDelta.bindingDeltas|contains: '"ADD"'
  selection_role:
    protoPayload.serviceData.policyDelta.bindingDeltas|contains:
      - roles/iam.serviceAccountTokenCreator
      - roles/iam.serviceAccountUser
      - roles/iam.workloadIdentityUser
      - roles/iam.serviceAccountOpenIdTokenCreator
      - roles/iam.serviceAccountKeyAdmin
      - roles/iam.serviceAccountAdmin
  condition: selection and selection_role
falsepositives:
  - Granting these roles on one service account is the recommended alternative to project-level grants, so deployment pipelines and Workload Identity Federation set-up produce it; exclude known automation by principalEmail and review grants to people, external accounts and whole pools.
level: medium

False positives

  • Granting these roles on one service account is the recommended alternative to project-level grants, so deployment pipelines and Workload Identity Federation set-up produce it; exclude known automation by principalEmail and review grants to people, external accounts and whole pools.

Allow Policy Changed on a Google Cloud Service Account

Detects any change to the allow policy of a single service account (google.iam.admin.v1.SetIAMPolicy, Admin Activity audit log). Use it as a baseline signal where such changes are rare, or scoped to privileged service accounts; the companion rule raises the roles that grant impersonation.

LevelLowStatusExperimentalLog sourceGoogle Cloud Audit Logs
title: Allow Policy Changed on a Google Cloud Service Account
id: 5fc185fa-4560-44a1-aa80-a24e82f39027
status: experimental
description: >-
  Detects any change to the allow policy of a single service account
  (google.iam.admin.v1.SetIAMPolicy, Admin Activity audit log). Use it as a
  baseline signal where such changes are rare, or scoped to privileged service
  accounts; the companion rule raises the roles that grant impersonation.
references:
  - https://docs.cloud.google.com/iam/docs/audit-logging
  - https://docs.cloud.google.com/iam/docs/audit-logging/examples-service-accounts
author: Forestall
date: 2026-11-11
tags:
  - attack.persistence
  - attack.privilege-escalation
  - attack.t1098.003
logsource:
  product: gcp
  service: gcp.audit
detection:
  selection:
    protoPayload.serviceName: iam.googleapis.com
    protoPayload.methodName: google.iam.admin.v1.SetIAMPolicy
  condition: selection
falsepositives:
  - Infrastructure-as-code runs and Workload Identity Federation set-up that manage service account policies; exclude the pipeline identity by principalEmail, or limit the rule to privileged service accounts.
  - Calls that only remove bindings also match.
level: low

False positives

  • Infrastructure-as-code runs and Workload Identity Federation set-up that manage service account policies; exclude the pipeline identity by principalEmail, or limit the rule to privileged service accounts.
  • Calls that only remove bindings also match.

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.

Impersonation right granted on a service account and used by the new member soon after

Detection hypothesisSequence of eventsJoins two logs

A Token Creator binding on one service account is a backdoor that waits to be used. The new member minting a credential for that account within hours shows the binding in use, and ties the grant to whatever the account does next.

  1. A google.iam.admin.v1.SetIAMPolicy entry from iam.googleapis.com whose serviceData.policyDelta.bindingDeltas add roles/iam.serviceAccountTokenCreator or roles/iam.serviceAccountOpenIdTokenCreator. Note the member without its user: or serviceAccount: prefix and the account in resource.labels.email_id.
  2. Within 24 hours, a GenerateAccessToken, GenerateIdToken, SignJwt or SignBlob entry from iamcredentials.googleapis.com (Data Access) whose authenticationInfo.principalEmail is that member and whose resource.labels.email_id is the same service account.
  3. Where Data Access logs are off, look instead for Admin Activity entries whose authenticationInfo.principalEmail is the service account and whose serviceAccountDelegationInfo names the member in firstPartyPrincipal.principalEmail.
  4. Raise the pair, with high priority when the caller of the grant and the new member are the same identity or the member is outside your organization.

Eventsgoogle.iam.admin.v1.SetIAMPolicyGenerateAccessTokenGenerateIdTokenSignJwtSignBlob

LimitsA member that is a group or a federated principal set does not match principalEmail directly. Giving a pipeline the right to impersonate its deployer account is the same sequence. Grants on a project or folder are Cloud Resource Manager events and not seen here. Google notes that App Engine and Google Kubernetes Engine do not log the delegating identity. The 24 hours are a starting point.

Impersonation right granted on a service account that has not been used for months

Detection hypothesisCompares with an earlier valueNeeds a baseline

An unused service account that still holds its roles is a quiet target. A Token Creator or Service Account User binding on it hands those roles to the new member, and no workload owner notices the activity. Google's Event Threat Detection reports impersonation roles granted on a service account inactive for more than 180 days.

  1. A match of the role rule on this page: a google.iam.admin.v1.SetIAMPolicy entry whose serviceData.policyDelta.bindingDeltas add an impersonation or key management role. Note the service account in resource.labels.email_id.
  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 grant when there is none, and watch the first entries of the account after the grant.

Eventsgoogle.iam.admin.v1.SetIAMPolicy

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 kept for rare jobs or disaster recovery look dormant too. The 180 days follow Google's definition of a dormant service account and are a starting point.

Triage

  • Read the role and member in bindingDeltas and the service account in resource.labels.email_id (protoPayload.resourceName holds its numeric ID).
  • Check what the service account can do (its role bindings across the organization) to size the impact.
  • Confirm the change with the account's owner. A person, an external account or a whole federated pool gaining Token Creator on a production service account needs a reason.
  • Remove unexplained bindings and review activity under the service account since the change, including entries whose serviceAccountDelegationInfo names the new member.

Response

Once the attack is confirmed:

  1. Remove the added binding from the allow policy of the service account. The member can then no longer mint tokens for the account, attach it to resources or manage its keys.
  2. Deal with tokens that already exist. Access tokens issued for a service account cannot be revoked and stay valid until they expire, by default up to 60 minutes. If the account is privileged, disable it for at least that long, knowing that every workload that uses it loses access immediately.
  3. List the keys of the service account and delete any that were created or uploaded after the binding was added. A member with Service Account Key Admin or Service Account Admin could have left a key that outlives the binding.
  4. Check whether the service account was attached to a new VM, function or job after the change. Service Account User allows this, and such a resource keeps running as the account after the binding is gone.
  5. Contain the identity that changed the policy, and remove its iam.serviceAccounts.setIamPolicy rights on the account and on the project, folder or organization it inherits them from.
  6. Review the allow policies of the other service accounts in the project for the same member.

Mitigation

  • Limit Service Account Admin, Security Admin and Owner on projects that hold privileged service accounts, and manage service account policies as code.
  • Enforce domain restricted sharing (iam.managed.allowedPolicyMembers or the legacy iam.allowedPolicyMemberDomains) so that external accounts cannot be added.
  • Keep admin roles off service accounts, so that a backdoored account gives little.
  • Enable Data Access audit logs for the IAM API so that later impersonation is recorded.

Frequently asked questions

Why does a review of the project's IAM policy not show this backdoor?

The binding is on the allow policy of the service account itself, not on the project. Every service account is also a resource with its own allow policy, and a change to it leaves the project, folder and organization policies untouched. The IAM API records it as `google.iam.admin.v1.SetIAMPolicy`, which reviews and detections that watch only project, folder and organization policies miss.

Are the tokens that the new member mints for the service account logged?

Only if Data Access audit logs are enabled for the IAM API. Without them, token requests made through the binding leave no entry. What was done with a token is logged under the service account's email, and entries whose `serviceAccountDelegationInfo` names the member show the actions taken through impersonation.

What does each role in the rule let the member do with the service account?

Service Account Token Creator lets the member mint access and ID tokens for the account. Service Account User lets the member attach it to a VM, function or job. Workload Identity User lets a federated identity impersonate it. Service Account Key Admin and Service Account Admin let the member create keys for it or rewrite its allow policy again.

Is a grant of these roles on one service account always suspicious?

No. Granting them on a single service account is the recommended alternative to project-level grants, so deployment pipelines and Workload Identity Federation set-up produce the same event. What needs a reason is a person, an external account or a whole federated pool gaining them on a privileged production service account.

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.