Skip to content
IAM Policy Generator

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

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.

Open the workbench ยท All examples

{
  "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.

What it allows

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

    Action or patternActionsAccess levels
    sts:AssumeRole1Write 1

Checks

No flags from the six checks.

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

Least privilege rewrite

{
  "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.

What it allows

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

    Action or patternActionsAccess levels
    sts:AssumeRole1Write 1

Checks

No flags from the six checks.

Sources

  1. IAM User Guide: access to third-party accounts with an external ID, read 16 Nov 2026
  2. IAM User Guide: the confused deputy problem, read 16 Nov 2026
  3. AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026), read 16 Nov 2026

Last reviewed 16 Nov 2026.