How it works
Google Cloud IAM stores access as allow policies attached to resources. An allow policy is a list of bindings, and each binding grants one role to a set of principals, with an optional condition. Policies are inherited down the resource hierarchy: organization, folders, projects, then individual resources.
An attacker who lands on any credential wants three answers: what can this identity do, which identities can do more, and how to become one of them. Almost all of it is readable through ordinary APIs:
- The hierarchy. Which organization, folders and projects exist, and which project sits under which folder.
- Allow policies. Who holds which role at each level. A service account appears in policies in two directions: as a principal that was granted roles on a project, and as a resource with its own allow policy that says who may impersonate it. Both directions matter, and they are separate reads.
- Role contents. A binding names a role, not permissions. Custom roles have to be resolved to their
includedPermissions, at the project or organization where they are defined. - Group membership. Bindings often name a Google group. Membership lives in Cloud Identity or Google Workspace, can be nested, and is not expanded by any IAM read.
- Enabled services. The APIs enabled in a project show what the project is used for and which escalation paths exist there.
Two properties make this reconnaissance cheap. First, broad read roles are common: the basic Viewer role can read allow policies and inventories across a whole project. Second, testIamPermissions exists on most resources. It takes a list of permissions and returns the subset the caller holds. Google provides it so that user interfaces can hide buttons the user may not press, and it works for any authenticated caller. An attacker with a credential of unknown scope sends the full permission list in batches and gets back exactly what the credential can do, without reading a single policy.
Prerequisites
- A valid credential for any principal: a user's gcloud session, a service account key file, or an access token taken from a workload.
- Network access to the Google Cloud APIs. No position inside the victim's network is needed.
- For policy reads:
resourcemanager.projects.getIamPolicy,iam.serviceAccounts.list,iam.roles.getand similar read permissions, which Viewer-type roles include. - For organization-wide search:
cloudasset.assets.searchAllIamPolicieson the scope being searched. - For permission probing: nothing beyond the credential.
Attack steps
For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.
1. Establish who you are and where
gcloud auth list
gcloud config list
gcloud organizations list
gcloud resource-manager folders list --organization=123456789012
gcloud projects list
gcloud projects list returns every project the credential can see, which is often more than the one it was found in.
2. Read the allow policies
# Bindings attached to one project
gcloud projects get-iam-policy lab-project-0001 --format=json
# The project and every ancestor (folders and organization) in one call
gcloud projects get-ancestors-iam-policy lab-project-0001 --format=json
# Flatten to one row per member and filter for one identity
gcloud projects get-iam-policy lab-project-0001 \
--flatten="bindings[].members" \
--filter="bindings.members:serviceAccount:app-sa@lab-project-0001.iam.gserviceaccount.com" \
--format="table(bindings.role)"
A conditional binding is only visible in full when the policy is returned in version 3. Read the condition block before assuming a grant applies.
3. Inventory service accounts and who can use them
gcloud iam service-accounts list --project=lab-project-0001
# The second policy direction: who may impersonate or attach this account
gcloud iam service-accounts get-iam-policy \
app-sa@lab-project-0001.iam.gserviceaccount.com
# User-managed keys that exist for it
gcloud iam service-accounts keys list \
--iam-account=app-sa@lab-project-0001.iam.gserviceaccount.com --managed-by=user
A binding of roles/iam.serviceAccountTokenCreator or roles/iam.serviceAccountUser on a service account, or on the project that owns it, is the lead for service account impersonation and actAs escalation.
4. Resolve roles and services
# What a predefined role contains
gcloud iam roles describe roles/iam.serviceAccountTokenCreator
# Custom roles defined in the project, and the contents of one
gcloud iam roles list --project=lab-project-0001
gcloud iam roles describe customDeployer --project=lab-project-0001
# What the project is used for
gcloud services list --enabled --project=lab-project-0001
5. Search the whole organization with Cloud Asset Inventory
When the credential has Cloud Asset roles, one query replaces thousands of per-resource reads:
# Every binding, on any resource, that names one principal
gcloud asset search-all-iam-policies \
--scope='organizations/123456789012' \
--query='policy:alice@corp.example.com'
# Every binding of a role that contains a dangerous permission
gcloud asset search-all-iam-policies \
--scope='organizations/123456789012' \
--query='policy.role.permissions:iam.serviceAccounts.getAccessToken'
# Who can act as a given service account, with groups expanded
gcloud asset analyze-iam-policy --organization=123456789012 \
--full-resource-name='//iam.googleapis.com/projects/lab-project-0001/serviceAccounts/app-sa@lab-project-0001.iam.gserviceaccount.com' \
--permissions='iam.serviceAccounts.actAs' --expand-groups
6. Expand groups
gcloud identity groups memberships search-transitive-memberships \
--group-email=cloud-admins@corp.example.com
A group that holds a role can contain other groups. The policy read shows the group; only the directory shows who is in it, and the answer changes over time.
7. Probe with testIamPermissions
When the credential cannot read policies, ask what it holds instead:
TOKEN=$(gcloud auth print-access-token)
curl -s -X POST \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"permissions": ["resourcemanager.projects.setIamPolicy", "iam.serviceAccounts.getAccessToken", "iam.serviceAccountKeys.create", "iam.serviceAccounts.actAs", "compute.instances.setMetadata"]}' \
"https://cloudresourcemanager.googleapis.com/v3/projects/lab-project-0001:testIamPermissions"
The response lists the permissions from the request that the caller has on the project. Wildcards are not accepted, so tools send the complete permission list in batches. gcloud iam list-testable-permissions returns the permissions that apply to a resource, and bf_my_gcp_permissions automates the loop with a credentials file or a raw token:
gcloud iam list-testable-permissions \
//cloudresourcemanager.googleapis.com/projects/lab-project-0001
python3 bf_my_gcp_perms.py -p lab-project-0001 -t "$TOKEN"
Impact
Enumeration changes nothing in the environment. Its value is the map: which principals hold setIamPolicy, who can mint tokens for which service account, which service accounts have user-managed keys, which custom roles hide a powerful permission, and which groups carry roles and are easy to join.
Every Google Cloud privilege escalation starts from this map. A defender who knows how little a low-privileged credential should be able to read can treat anything more as a finding of its own.
OPSEC and artifacts
- Reads go to Data Access logs. IAM and Resource Manager read methods need permissions of type
ADMIN_READorDATA_READ, and Google writes those calls to Data Access audit logs. Except for BigQuery, Data Access logs are disabled by default, so in many projects the policy reads leave no audit entry at all. - One organization-level search instead of many project reads. A Cloud Asset Inventory query collects every binding in one request. It is a read like the others, so it is recorded only where Data Access logging covers the Cloud Asset API.
- Probing instead of reading.
testIamPermissionscalls are made by normal user interfaces all day. For IAM resources Google listsTestIAMPermissionsamong the methods that generate Data Access entries, so a burst of them from one principal is visible only where those logs are enabled. - Trying real methods is the loud option. Calling APIs to see which fail produces denied calls. Denied attempts to change something land in Admin Activity logs, which are always on, with
protoPayload.status.code7 (PERMISSION_DENIED). - Using the workload's own identity and address. Enumeration run from the compromised VM arrives from the expected
callerIp. Run from the attacker's machine with a stolen token or key, the same calls carry a new address and a gcloud or script user agent inrequestMetadata.callerSuppliedUserAgent.
Detection
- Enable Data Access logs where it matters. At minimum
ADMIN_READfor IAM and Resource Manager on the organization or on sensitive folders. Without them there is nothing to query. - Service accounts reading allow policies. A workload rarely needs
getIamPolicyon its own project, folder or organization. The permission probing rules include a rule for exactly this, and rules for one principal collecting denied calls across many methods and services. - Enumeration by an identity that never did it before. A first-time
ListServiceAccounts,ListRolesor asset search from a principal, address or user agent outside its history. - Volume and spread. One principal reading policies in many projects within minutes.
log_id("cloudaudit.googleapis.com/data_access")
AND (
(protoPayload.serviceName="iam.googleapis.com"
AND (protoPayload.methodName="google.iam.admin.v1.ListServiceAccounts"
OR protoPayload.methodName="google.iam.admin.v1.ListRoles"
OR protoPayload.methodName="google.iam.admin.v1.GetIAMPolicy"))
OR
(protoPayload.serviceName="cloudresourcemanager.googleapis.com"
AND protoPayload.methodName =~ "(?i)(^|[.])getiampolicy$")
)
AND protoPayload.authenticationInfo.principalEmail =~ "gserviceaccount.com$"
Read protoPayload.authenticationInfo.principalEmail for the caller, protoPayload.resourceName for the target and protoPayload.status for the outcome. A zero-match result means little until the audit configuration, exemptions and log retention for the period have been checked: the _Default log bucket keeps entries for 30 days unless it was configured otherwise. Inventory jobs, posture scanners and the console itself make these calls routinely, so build the allow list from your own baseline.
Mitigation
- Stop granting basic roles. Viewer, Editor and Owner carry read access to almost everything in a project. Use narrow predefined roles or custom roles, following least privilege in Google Cloud IAM.
- Bind low in the hierarchy. A role granted on the organization or a folder is readable and usable in every project beneath it.
- Give each workload its own service account with only the roles it needs, so that a stolen workload credential can read little and
testIamPermissionsreturns a short list. - Restrict Cloud Asset Inventory.
roles/cloudasset.viewerat the organization level is a search engine over every allow policy. Grant it to named security tooling only. - Replace service account keys with attached identities and workload identity federation, so that credentials cannot be carried off and used for enumeration from outside.
- Use deny policies and conditions to keep sensitive reads and impersonation rights away from broad groups.
- Review group-based grants. Know which groups hold roles, who can add members to them, and whether external or nested members are allowed.
Detection rules for this attack
FAQ
What can an attacker enumerate with a low-privileged Google Cloud credential?
Whatever its roles allow to be read, and more than most teams expect. Viewer-type roles expose allow policies, role definitions, service accounts and enabled services. With no read role at all, testIamPermissions still answers which permissions from a list the caller holds on a resource.
Why is Google Cloud IAM enumeration hard to detect?
The calls are reads. Google writes them to Data Access audit logs, and those are disabled by default for every service except BigQuery. Where they are enabled, the same calls are made all day by consoles, inventory tools and security scanners.
Does a getIamPolicy response show everything a principal can do?
No. It returns only the bindings attached to that one resource. Roles inherited from the folder and organization, memberships of groups named in the bindings, deny policies and principal access boundaries all change the effective answer and have to be collected separately.
How do you limit what enumeration reveals?
Grant narrow predefined or custom roles in place of Viewer and Editor, bind roles at the lowest resource that works, restrict Cloud Asset Inventory roles at the organization and folder level, and give each workload its own service account so that a stolen credential has little to read.
References
- Account Discovery: Cloud Account, T1087.004 (MITRE ATT&CK)
- Cloud Infrastructure Discovery, T1580 (MITRE ATT&CK)
- Allow policies (Google Cloud IAM documentation)
- Test permissions for custom user interfaces: testIamPermissions (Google Cloud IAM documentation)
- gcloud asset search-all-iam-policies (gcloud CLI reference)
- IAM audit logging (Google Cloud IAM documentation)
- Cloud Audit Logs overview (Google Cloud Logging documentation)
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.