# IAM policy example: trust GitHub Actions through OIDC, with a least privilege rewrite

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

Lets a GitHub Actions workflow assume a role through the GitHub OIDC provider when the token audience is sts.amazonaws.com and the subject matches a repository. The original accepts any repository in the organization. The rewrite pins one repository and branch.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "GitHubOrg",
      "Effect": "Allow",
      "Principal": {
        "Federated": "arn:aws:iam::111122223333:oidc-provider/token.actions.githubusercontent.com"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringEquals": {
          "token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
        },
        "StringLike": {
          "token.actions.githubusercontent.com:sub": "repo:octo-org/*"
        }
      }
    }
  ]
}
```

## What it allows

- Allows workflows in any repository of the octo-org organization to assume the role, on any branch, tag or pull request.

- Allows Federated arn:aws:iam::111122223333:oidc-provider/token.actions.githubusercontent.com to sts:AssumeRoleWithWebIdentity when token.actions.githubusercontent.com:aud StringEquals sts.amazonaws.com and token.actions.githubusercontent.com:sub StringLike repo:octo-org/*.

Checks:
- No flags.

Any repository in the organization, including a new or forked one, can obtain the role's credentials.

## Least privilege rewrite

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "GitHubMain",
      "Effect": "Allow",
      "Principal": {
        "Federated": "arn:aws:iam::111122223333:oidc-provider/token.actions.githubusercontent.com"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringEquals": {
          "token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
          "token.actions.githubusercontent.com:sub": "repo:octo-org/octo-repo:ref:refs/heads/main"
        }
      }
    }
  ]
}
```

The rewrite uses an exact subject for one repository on the main branch. Other repositories, branches and pull requests cannot assume the role.

- Allows Federated arn:aws:iam::111122223333:oidc-provider/token.actions.githubusercontent.com to sts:AssumeRoleWithWebIdentity when token.actions.githubusercontent.com:aud StringEquals sts.amazonaws.com and token.actions.githubusercontent.com:sub StringEquals repo:octo-org/octo-repo:ref:refs/heads/main.

Checks:
- No flags.

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

## Related pages

- [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/)
- [IAM policy example: trust a SAML identity provider](/examples/trust-policy-saml-federation/)
- [All of them](/examples/)

## Sources

- IAM User Guide: create a role for OpenID Connect federation: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc.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-github-actions-oidc/

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