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.
Open the workbench ยท All examples
{
"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.
What it allows
Allow 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/*.
Action or pattern Actions Access levels sts:AssumeRoleWithWebIdentity1 Write 1
Checks
No flags from the six checks.
Any repository in the organization, including a new or forked one, can obtain the role's credentials.
Least privilege rewrite
{
"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.
What it allows
Allow 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.
Action or pattern Actions Access levels sts:AssumeRoleWithWebIdentity1 Write 1
Checks
No flags from the six checks.
Related pages
Sources
- IAM User Guide: create a role for OpenID Connect federation, read 16 Nov 2026
- AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026), read 16 Nov 2026
Last reviewed 16 Nov 2026.