4 methods
of GCP service account impersonation: iam.serviceAccounts.actAs IAM binding, domain-wide delegation for Google Workspace APIs, workload identity federation grants, and exfiltrated key files that impersonate without audit log visibility
iam.serviceAccounts.actAs
is the IAM permission that enables direct impersonation -- any principal holding this permission on a service account can generate access tokens as that service account and chain to any further impersonation grants that service account holds
key files
are the highest-risk impersonation method because they provide long-lived credentials that work offline, do not expire without manual rotation, and generate authentication events that are attributable to the service account rather than the key holder
Organization Policy
constraints/iam.disableServiceAccountKeyCreation blocks creation of new service account key files at the organization level -- this is the most reliable control for preventing new key file exposure

SponsoredRetool

Retool's new app builder is where AI-generated code ships safely

Building apps with AI is easy. Getting them to production safely is another story.

Start building for free today

Service account impersonation in GCP is a feature, not a bug. It enables secure service-to-service authentication by allowing a service account to call APIs on behalf of another without sharing long-lived credentials. When used as designed -- with minimum-privilege bindings, short-lived tokens, and audit logging -- it is the right way to handle cross-service authentication in GCP.

The problem is that impersonation chains accumulate without visibility into the full graph. A developer grants Service Account A the ability to impersonate Service Account B so a data pipeline can access BigQuery. Six months later, Service Account B gets a new IAM binding for broader Compute Engine access. A year later, Service Account A is used by a Cloud Run service that is exposed to the internet. Nobody drew the full chain: internet-accessible Cloud Run service account can impersonate a service account with broad Compute Engine access.

The audit goal is to produce a complete impersonation graph for the GCP environment: every actAs binding, every domain-wide delegation grant, every workload identity federation trust, and every active service account key file. From the complete graph, you identify chains where a low-privilege or externally-accessible service account can reach high-privilege service accounts through one or more hops.

This guide covers how to enumerate the full impersonation graph, what each impersonation method looks like in Cloud Audit Logs, and the remediation sequence that tightens impersonation grants without breaking legitimate workflows.

Four Impersonation Methods and Their Attack Surface

Each impersonation method has a different risk profile and requires different enumeration and detection approaches.

Method 1: iam.serviceAccounts.actAs IAM binding. The most direct impersonation method. When a principal (user, service account, or group) has the iam.serviceAccounts.actAs permission on a service account, they can call the generateAccessToken or generateIdToken API to obtain credentials for that service account. This permission is often granted implicitly via the roles/iam.serviceAccountUser role. The risk: any principal with actAs on Service Account B can call any API that Service Account B is authorized for.

Method 2: Domain-wide delegation (DWD). A service account with domain-wide delegation configured can impersonate any Google Workspace user in the domain for the delegated OAuth scopes. DWD is required for some G Suite API integrations, but a service account with DWD grants and broad OAuth scopes (e.g., https://www.googleapis.com/auth/gmail.readonly for all users) can read the email of any user in the organization. This is a high-privilege capability that often exists in environments with legacy G Suite integrations.

Method 3: Workload identity federation. Workload identity federation allows external identities (GitHub Actions tokens, AWS IAM roles, on-premises service accounts) to impersonate GCP service accounts without key files. Misconfigured federation trusts can allow broader external access than intended -- for example, a federation trust that allows any token from a GitHub organization's OIDC provider, rather than specifically scoped repository and workflow conditions.

Method 4: Service account key files. Downloaded JSON key files provide long-lived service account credentials that work without network connectivity to GCP. Key files do not expire unless the private key is rotated. Authentication using a key file generates Cloud Audit Logs entries attributable to the service account, not to the key holder -- making attribution difficult without additional logging. Key files that were downloaded and then forgotten represent indefinite impersonation access.

Enumerating Impersonation Chains Across a GCP Project

Enumeration produces a complete list of impersonation relationships. Run these commands across every project in the organization.

Enumerate all actAs bindings across an organization:

gcloud asset search-all-iam-policies \
  --scope="organizations/[ORG_ID]" \
  --query="roles/iam.serviceAccountUser OR roles/iam.serviceAccountTokenCreator OR policy.role.permissions:iam.serviceAccounts.actAs" \
  --format="json" | jq '.[] | {resource: .resource, bindings: .policy.bindings}'

This returns every IAM binding that grants actAs capabilities, across all projects in the organization.

Enumerate all service accounts with domain-wide delegation:

gcloud iam service-accounts list --project=[PROJECT_ID] --format="json" |   jq '.[] | select(.oauth2ClientId != null) | {email: .email, clientId: .oauth2ClientId}'

Service accounts with a non-null oauth2ClientId have DWD configured. Cross-reference with the Google Workspace Admin SDK to see which OAuth scopes are authorized for each service account.

Enumerate all workload identity federation pools and providers:

gcloud iam workload-identity-pools list --location="global" --project=[PROJECT_ID] --format="json"
gcloud iam workload-identity-pools providers list \
  --workload-identity-pool=[POOL_ID] \
  --location="global" --project=[PROJECT_ID] --format="json"

For each provider, review the attribute conditions to determine which external identities are trusted.

Enumerate active service account key files:

gcloud iam service-accounts keys list \
  --iam-account=[SA_EMAIL] --managed-by="user" --format="json" |   jq '.[] | {keyId: .name, created: .validAfterTime, expires: .validBeforeTime}'

User-managed keys (--managed-by=user) are the downloaded JSON key files. Google-managed keys are short-lived and managed automatically. List all user-managed keys across all service accounts in every project.

Free daily briefing

Briefings like this, every morning before 9am.

Threat intel, active CVEs, and campaign alerts, distilled for practitioners. 50,000+ subscribers. No noise.

Detecting Impersonation Abuse via Cloud Audit Logs

Cloud Audit Logs records impersonation events. The following log patterns indicate impersonation activity and require review.

Detecting actAs impersonation in Cloud Audit Logs:

Filter in Cloud Logging for impersonation events:

resource.type="service_account"
protoPayload.methodName="GenerateAccessToken" OR
protoPayload.methodName="GenerateIdToken"

The protoPayload.authenticationInfo.principalEmail field shows who requested the impersonation. The protoPayload.request.name field shows which service account was impersonated. Alert when any impersonation request originates from a principal outside the expected set of callers for that service account.

Detecting domain-wide delegation usage:

resource.type="service_account"
protoPayload.request.delegates!=""

The delegates field in the request indicates that the service account is acting on behalf of a specific Google Workspace user. Alert when delegation events occur for users who are not expected to have APIs called on their behalf, or when the OAuth scopes used exceed what is required for the integration.

Detecting unusual key file usage:

Authentication with a service account key file generates protoPayload.authenticationInfo.serviceAccountKeyName in the audit log. Alert when authentication using a service account key file occurs from an IP address that is not in the expected range for the application that uses that key.

Detecting impersonation chains:

A principal that generates access tokens for multiple different service accounts within a short time window is potentially exploring the impersonation graph. Build a detection that alerts when a single principal calls GenerateAccessToken for more than three different service accounts within one hour.

Remediation: Removing Grants and Eliminating Key Files

Remediation follows the same sequence regardless of which impersonation method is being addressed: document the legitimate use case, remove the over-broad grant, and replace it with a minimum-privilege alternative.

Remediation sequence for actAs bindings:

  1. For each actAs binding found, contact the team that owns the binding. Determine whether it is actively used and what it is used for.
  2. If unused: revoke immediately. gcloud projects remove-iam-policy-binding [PROJECT] --member=[PRINCIPAL] --role=roles/iam.serviceAccountUser
  3. If used: replace with a more specific binding scoped to the minimum required service account. If Service Account A currently has actAs on all service accounts in the project, restrict it to actAs on only the specific service account it needs.

Remediation sequence for DWD grants:

  1. In the Google Workspace Admin console, review the OAuth scopes authorized for each service account with DWD.
  2. Remove DWD for service accounts where the integration no longer requires it.
  3. For remaining DWD grants, reduce OAuth scopes to the minimum required. A service account that reads calendar events does not need gmail.readonly.

Remediation sequence for key files:

  1. For each user-managed key file, determine whether it is actively used by checking recent authentication events in Cloud Audit Logs using the key ID.
  2. For unused key files: delete immediately. gcloud iam service-accounts keys delete [KEY_ID] --iam-account=[SA_EMAIL]
  3. For active key files: work with the application team to migrate to workload identity federation (for external callers) or actAs impersonation with short-lived tokens (for GCP-internal callers). Set a migration deadline -- 90 days is typical.
  4. After migration: delete the key file.

Organization Policy Constraints That Prevent New Exposure

After remediating existing impersonation chains, Organization Policy constraints prevent new ones from being created without explicit approval.

Disable service account key creation:

gcloud resource-manager org-policies set-policy \
  --organization=[ORG_ID] \
  disable-sa-key-creation-policy.json

Where the policy file contains:

{
  "constraint": "constraints/iam.disableServiceAccountKeyCreation",
  "booleanPolicy": { "enforced": true }
}

This prevents creation of new service account key files at the organization level. Applications that currently use key files must migrate before this policy is enforced.

Disable service account creation in production projects:

In GCP environments that use separate projects for different environments, restrict service account creation in production to the platform engineering team: constraints/iam.disableServiceAccountCreation on production projects, with exceptions for the infrastructure team's service account.

Require workload identity federation for external callers:

Enforce workload identity federation as the only mechanism for external callers (GitHub Actions, on-premises systems, other cloud providers) to authenticate to GCP. This is a cultural and process constraint rather than a technical one -- document the requirement in the infrastructure onboarding process and include it in code review checklists for new GCP integrations.

Monitor for new DWD grants:

Create a Cloud Monitoring alert policy on Cloud Audit Logs for any DWD grant creation event:

resource.type="service_account"
protoPayload.methodName="google.iam.admin.v1.UpdateServiceAccount"
protoPayload.request.service_account.oauth2_client_id!=""

This detects when DWD is enabled for a service account and routes it to the security team for review before the grant becomes operational.

The bottom line

GCP service account impersonation chains create lateral movement paths that are invisible to IAM policy reviews that look only at direct role bindings. Complete enumeration requires covering all four impersonation methods: actAs IAM bindings, domain-wide delegation grants, workload identity federation trust configurations, and active service account key files. The enumeration commands across these four methods produce an impersonation graph where you can trace chains from internet-accessible or low-privilege starting points to high-privilege service accounts. Detection in Cloud Audit Logs focuses on GenerateAccessToken and GenerateIdToken events from unexpected principals, DWD usage outside expected patterns, and key file authentication from unexpected IP ranges. Remediation replaces key files with workload identity federation or short-lived actAs impersonation and scopes all actAs bindings to the minimum required service accounts. Organization policy constraints prevent new key file creation and alert on new DWD grants.

Frequently asked questions

What is the difference between service account impersonation and service account key files?

Service account impersonation uses the IAM API to generate short-lived access tokens (1 hour maximum) for a service account, requiring the caller to have the actAs IAM permission and generating audit log entries showing the caller's identity. Service account key files are long-lived credentials (no automatic expiry, unless you set a max age) that can authenticate as the service account from anywhere without network access to GCP's IAM API. Key files are riskier because they do not expire, do not require the actAs permission on the target service account, and authenticate without showing the key holder's identity in audit logs.

What is domain-wide delegation and when is it legitimate?

Domain-wide delegation allows a GCP service account to call Google Workspace APIs on behalf of any user in the organization for the specified OAuth scopes. It is legitimate for specific integration scenarios: a calendar integration that reads meeting data for scheduling automation, a Google Drive integration that manages files on behalf of users, or an admin tool that manages user lifecycle. The risk is scope creep -- a service account with DWD and overly broad OAuth scopes can read the email, calendar, and drive contents of every user in the organization.

How do I migrate from service account key files to workload identity federation?

For GitHub Actions: configure a workload identity pool with a GitHub OIDC provider, add attribute conditions that scope trust to specific repositories and workflows, and replace the key file authentication in the workflow with the google-github-actions/auth action using the workload identity provider. For AWS workloads: configure a pool with an AWS provider and scope trust to specific IAM roles. For on-premises systems: use a pool with a custom OIDC provider or SAML provider. The migration replaces the key file download with a federation trust configuration that generates short-lived tokens automatically during each execution.

Can I audit impersonation across an entire GCP organization in one command?

The gcloud asset search-all-iam-policies command with an organization scope covers all projects in the organization for actAs bindings. For service account keys, you must enumerate per-project because the iam.serviceAccounts.keys.list API is project-scoped. Automation scripts that iterate over all projects returned by gcloud projects list and run the key file enumeration for each project produce organization-wide key inventory. Cloud Asset Inventory can also export the full IAM policy for all resources in the organization to a BigQuery table for analysis.

What is the Workload Identity Federation attribute condition and why does it matter?

The attribute condition in a workload identity federation provider is an expression that restricts which external tokens are trusted. Without an attribute condition, any valid token from the external identity provider can impersonate the GCP service accounts in the pool. A GitHub Actions provider without an attribute condition trusts any GitHub Actions token from any repository in any organization -- which means a compromised GitHub account in any organization can authenticate to your GCP environment. The condition should be scoped to specific repository names, organizations, and workflow ref conditions.

How do I find service account impersonation chains that span multiple hops?

Build an impersonation graph by recording all actAs relationships as directed edges (Principal A has actAs permission on Service Account B). Then trace paths from each node: if Service Account C has actAs on Service Account B, and Service Account B has actAs on Service Account A (high-privilege), then any principal with actAs on Service Account C can reach Service Account A in two hops. Graph traversal across the actAs relationship edges reveals chains that would not be apparent from reviewing individual IAM bindings in isolation. The gcloud asset search-all-iam-policies output provides the edge data for building this graph.

Sources & references

  1. Google Cloud: Service Account Impersonation Best Practices
  2. Google Cloud: Cloud Audit Logs for IAM Events
  3. Google Cloud: Workload Identity Federation
  4. GCP Privilege Escalation: Service Account Impersonation Chains

Free resources

25
Free download

Critical CVE Reference Card 2025–2026

25 actively exploited vulnerabilities with CVSS scores, exploit status, and patch availability. Print it, pin it, share it with your SOC team.

No spam. Unsubscribe anytime.

Free download

Ransomware Incident Response Playbook

Step-by-step 24-hour IR checklist covering detection, containment, eradication, and recovery. Built for SOC teams, IR leads, and CISOs.

No spam. Unsubscribe anytime.

Free newsletter

Get threat intel before your inbox does.

50,000+ security professionals read Decryption Digest for early warnings on zero-days, ransomware, and nation-state campaigns. Free, daily, no spam.

Unsubscribe anytime. We never sell your data.

Eric Bang
Author

Founder & Cybersecurity Evangelist, Decryption Digest

Cybersecurity professional with expertise in threat intelligence, vulnerability research, and enterprise security. Covers zero-days, ransomware, and nation-state operations for 50,000+ security professionals every morning.

Black Hat Giveaway

Win a $2,495 Black Hat pass.

Full-access to Black Hat USA 2026 in Las Vegas. Subscribe free to enter.

Joins Decryption Digest daily briefing. Unsubscribe anytime.

Giveaway: Black Hat USA 2026 Full-Access Pass ($2,495 value)

Details →
Daily Briefing

Subscribe to enter the giveaway

Every subscriber is automatically entered. You also get daily threat intel every morning: zero-days, ransomware, and nation-state campaigns. Free. No spam.

Already subscribed? You're already entered.

Giveaway

Win a $2,495 Black Hat USA 2026 pass.