GCP Service Account Impersonation Role Grant Detection
Adversaries can gain unauthorized access to Google Cloud Platform environments by granting themselves service account impersonation roles, enabling long-term persistence and privilege escalation that survives credential rotation.
Adversaries with sufficient GCP administrative privileges can establish durable, key-less persistence by granting themselves or an attacker-controlled principal specific IAM roles on a target service account. The roles roles/iam.serviceAccountTokenCreator, roles/iam.serviceAccountUser, and roles/iam.serviceAccountOpenIdTokenCreator allow a principal to mint OAuth2 access tokens, generate OpenID Connect identity tokens, or attach (actAs) the target service account to new cloud resources. Because these roles leverage GCP's native IAM trust relationship rather than long-lived static service account keys, the resulting access is unaffected by traditional credential rotation or password reset procedures. This technique is commonly used to pivot from a compromised low-privileged identity to a higher-privileged service account with broader project or organization-level permissions. Defenders should monitor for unexpected SetIamPolicy operations, particularly when the principal performing the grant has not historically performed such actions.
Impact
Successful exploitation allows an adversary to maintain long-term access to a GCP environment regardless of security team efforts to rotate credentials. It facilitates significant privilege escalation if the target service account possesses broad IAM permissions. In enterprise environments, this can lead to unauthorized data access, infrastructure manipulation, and cross-project movement within the GCP organization.
Recommendation
- Deploy detection rules to monitor
SetIamPolicyoperations that add impersonation roles to service accounts. - Baseline administrative and CI/CD service accounts (such as Terraform or Jenkins) that legitimately perform IAM modifications to reduce false positives.
- Restrict the ability to set IAM policies on service accounts and implement a peer-review or justification-based approval process for IAM changes.
- Review existing IAM bindings for unauthorized principals or external accounts that have been granted impersonation rights.
Immediate actions
Deploy detection rule to identify service account impersonation grants.
Threat Hunt
Identify all service accounts with roles/iam.serviceAccountUser or similar impersonation roles currently bound.
Data: GCP IAM Policy exports
Mitigations
Review and audit all current service account IAM policies for unauthorized impersonation bindings.
Persistent access via cloud roles
Detection coverage 1
Detect GCP IAM Service Account Impersonation Role Granted
mediumDetects when a service account impersonation role (e.g., serviceAccountTokenCreator) is added to a service account via SetIamPolicy.
Detection queries are available on the platform. Get full rules →