You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Role trust policy is incorrect for environment-based workflows #1238
But I dont' understand how adding environment changes the repo's URL syntax. Can anybody show me how so I can make more specific & least privileged URL syntax. I am expecting something like this
@maximillianus I recently implemented this. When you add an environment to a GitHub Actions job, it indeed changes the format of the sub claim in the OIDC token. This change is not immediately obvious and can cause confusion when setting up IAM roles for OIDC authentication.
When an environment is specified in a job, the sub claim in the OIDC token changes from:
repo:<GitHubOrg>/<GitHubRepo>:ref:refs/heads/<GitHubBranch>
to
repo:<GitHubOrg>/<GitHubRepo>:environment:<EnvironmentName>
This change occurs because GitHub treats environment-based workflows differently from branch-based workflows for security reasons. Read over the docs.
Thanks @jsandov . Those exactly what I did too after further research, but discovering this is not exactly straightforward. I wish there is some documentation from the aws-action Github team here. Again, while * wildcard works fine (and convenient), I prefer least privileged style with more control.
@maximillianus I linked the TF modules above. You will need to handle this at the infrastructure as code level. More precisely at the at the trust policy level which goes into the IAM role. This is how I am handling the different repos and environments that can be plugged in. Hopefully this helps!
Here is a trust policy I created for least privileged access to repo and environment.
trust_policy = {
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Principal = {
Federated = local.provider_arn
}
Action = "sts:AssumeRoleWithWebIdentity"
Condition = {
StringEquals = {
"token.actions.githubusercontent.com:aud" = "sts.amazonaws.com"
}
StringLike = {
"token.actions.githubusercontent.com:sub" = flatten([
for repo, envs in var.repository_environments : [
for env in envs :
"repo:${repo}:environment:${env}"
]
])
}
}
}
]
}
changed the title [-]Could not assume role with OIDC: Not authorized to perform sts:AssumeRoleWithWebIdentity - Why?[/-][+]Role trust policy is incorrect for environment-based workflows[/+]on Aug 27, 2025
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
Activity
Update aws_create_deployment.yml
jsandov commentedon Jan 7, 2025
@maximillianus I recently implemented this. When you add an environment to a GitHub Actions job, it indeed changes the format of the sub claim in the OIDC token. This change is not immediately obvious and can cause confusion when setting up IAM roles for OIDC authentication.
When an environment is specified in a job, the sub claim in the OIDC token changes from:
repo:<GitHubOrg>/<GitHubRepo>:ref:refs/heads/<GitHubBranch>to
repo:<GitHubOrg>/<GitHubRepo>:environment:<EnvironmentName>This change occurs because GitHub treats environment-based workflows differently from branch-based workflows for security reasons. Read over the docs.
jsandov commentedon Jan 7, 2025
@maximillianus Using both formats If you need more precise control, you can include conditions for both formats:
"StringLike": { "token.actions.githubusercontent.com:sub": [ "repo:<GitHubOrg>/<GitHubRepo>:ref:refs/heads/*", "repo:<GitHubOrg>/<GitHubRepo>:environment:*" ] }Adjusting your IAM role configurations accordingly
jsandov commentedon Jan 7, 2025
These are the Terraform modules I used for AWS:
maximillianus commentedon Jan 7, 2025
Thanks @jsandov . Those exactly what I did too after further research, but discovering this is not exactly straightforward. I wish there is some documentation from the aws-action Github team here. Again, while * wildcard works fine (and convenient), I prefer least privileged style with more control.
Thanks for the answer.
jsandov commentedon Jan 7, 2025
@maximillianus I linked the TF modules above. You will need to handle this at the infrastructure as code level. More precisely at the at the trust policy level which goes into the IAM role. This is how I am handling the different repos and environments that can be plugged in. Hopefully this helps!
Here is a trust policy I created for least privileged access to repo and environment.
[-]Could not assume role with OIDC: Not authorized to perform sts:AssumeRoleWithWebIdentity - Why?[/-][+]Role trust policy is incorrect for environment-based workflows[/+]chore: update documentation for environment workflows
chore: update documentation for environment workflows
chore: update documentation for environment workflows (#1766)
github-actions commentedon May 11, 2026
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
chore: replay 6.2 devel changes onto main (#1800)
chore: replay 6.2 devel changes onto main (#1807)
Merge branch 'main' into branch 'devel' (#1852)