# IAM policy example: cross-account role with external ID, with a least privilege rewrite

Facts read 16 Nov 2026. Page reviewed 16 Nov 2026.

Lets a third-party account, 111122223333, assume a role only when the request carries the agreed sts:ExternalId value. The external ID guards against the confused deputy problem. The original trusts the whole account, and the rewrite names one role in it.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ThirdParty",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::111122223333:root"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "StringEquals": {
          "sts:ExternalId": "EXAMPLE-EXTERNAL-ID-12345"
        }
      }
    }
  ]
}
```

## What it allows

- Allows any principal in account 111122223333 that presents the external ID to assume the role.

- Allows AWS arn:aws:iam::111122223333:root to sts:AssumeRole when sts:ExternalId StringEquals EXAMPLE-EXTERNAL-ID-12345.

Checks:
- No flags.

Any identity in the vendor account that knows the external ID can assume the role, including roles unrelated to the integration.

## Least privilege rewrite

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ThirdPartyRole",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::111122223333:role/vendor-integration"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "StringEquals": {
          "sts:ExternalId": "EXAMPLE-EXTERNAL-ID-12345"
        }
      }
    }
  ]
}
```

The rewrite names one role in the vendor account and keeps the external ID. Other roles in that account can no longer assume this role.

- Allows AWS arn:aws:iam::111122223333:role/vendor-integration to sts:AssumeRole when sts:ExternalId StringEquals EXAMPLE-EXTERNAL-ID-12345.

Checks:
- No flags.

- [Paste it into the workbench](/)
- [Every STS action and its access level](/actions/sts/)

## Related pages

- [IAM policy example: trust GitHub Actions through OIDC](/examples/trust-policy-github-actions-oidc/)
- [IAM policy example: trust one EKS service account](/examples/trust-policy-eks-service-account-irsa/)
- [IAM policy example: trust a service for one resource only](/examples/trust-policy-service-with-source-arn/)
- [All of them](/examples/)

## Sources

- IAM User Guide: access to third-party accounts with an external ID: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-user_externalid.html (read 16 Nov 2026)
- IAM User Guide: the confused deputy problem: https://docs.aws.amazon.com/IAM/latest/UserGuide/confused-deputy.html (read 16 Nov 2026)
- AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026): https://docs.aws.amazon.com/service-authorization/latest/reference/service-reference.html (read 16 Nov 2026)

Last reviewed 16 Nov 2026. Canonical: https://iampolicygenerator.com/examples/trust-policy-cross-account-external-id/

This site is not affiliated with Amazon Web Services. AWS service and product names are used only to describe AWS services.
