Skip to content

Role trust policy is incorrect for environment-based workflows #1238

Description

@maximillianus

Describe the issue

Referring to this error in assuming role using OIDC (issues 1137).

I wonder what's the actual issue? This issue came up when I use environment in my workflow.

I resolve this by making my sub to be more generic and it works.
Was:

"StringLike": {
          "token.actions.githubusercontent.com:sub": "repo:GitHubOrg/GitHubRepo:ref:refs/heads/GitHubBranch"
        }

Now:

"StringLike": {
          "token.actions.githubusercontent.com:sub": "repo:GitHubOrg/GitHubRepo:*"
        }

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

"StringLike": {
          "token.actions.githubusercontent.com:sub": "repo:GitHubOrg/GitHubRepo:environment:*ref:refs/heads/GithubBranch*"
        }

Activity

  1. added
    documentation
    needs-triage
    on Jan 2, 2025
  2. added a commit that references this issue on Jan 3, 2025
  3. jsandov commented on Jan 7, 2025

    @jsandov

    @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.

  4. jsandov commented on Jan 7, 2025

    @jsandov

    @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

  5. jsandov commented on Jan 7, 2025

    @jsandov

    These are the Terraform modules I used for AWS:

  6. maximillianus commented on Jan 7, 2025

    @maximillianus
    Author

    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.

  7. jsandov commented on Jan 7, 2025

    @jsandov

    @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}"
                  ]
                ])
              }
            }
          }
        ]
      }
    
  8. added
    feature-request
    and removed
    needs-triage
    on Aug 27, 2025
  9. 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
  10. added 2 commits that reference this issue on May 11, 2026
    7b62bc9
    78c0f96
  11. added a commit that references this issue on May 11, 2026
    3f7e1b6
  12. github-actions commented on May 11, 2026

    @github-actions

    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.

  13. added 2 commits that reference this issue on May 26, 2026
    87eb0cf
    4ab3589
  14. added a commit that references this issue on Jun 26, 2026
    628f21f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationfeature-requestp2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions