Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not assume role with OIDC: Not authorized to perform sts:AssumeRoleWithWebIdentity #1137

Closed
kaykhan opened this issue Aug 20, 2024 · 7 comments
Labels
bug Something isn't working needs-triage This issue still needs to be triaged

Comments

@kaykhan
Copy link

kaykhan commented Aug 20, 2024

Describe the bug

Fails to assume role with OIDC.

Expected Behavior

Expect to assume the role

Current Behavior

Run aws-actions/configure-aws-credentials@v4
Assuming role with OIDC
Assuming role with OIDC
Assuming role with OIDC
Assuming role with OIDC
Assuming role with OIDC
Assuming role with OIDC
Assuming role with OIDC
Assuming role with OIDC
Assuming role with OIDC
Assuming role with OIDC
Assuming role with OIDC
Assuming role with OIDC
Error: Could not assume role with OIDC: Not authorized to perform sts:AssumeRoleWithWebIdentity

Reproduction Steps

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Federated": "arn:aws:iam::<ACOUNT_ID>:oidc-provider/token.actions.githubusercontent.com"
            },
            "Action": "sts:AssumeRoleWithWebIdentity",
            "Condition": {
                "StringEquals": {
                    "token.actions.githubusercontent.com:sub": "repo:<ORG>/*",
                    "token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
                }
            }
        }
    ]
}
permissions:
  id-token: write
  contents: read
  ...
      - name: Checkout
        uses: actions/checkout@master
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: arn:aws:iam::<account_id>:role/<org>-gh-actions-role
          role-session-name: cdk
          aws-region: ${{ env.AWS_REGION }}

Possible Solution

No response

Additional Information/Context

No response

@kaykhan kaykhan added bug Something isn't working needs-triage This issue still needs to be triaged labels Aug 20, 2024
@JulienAdaly
Copy link

Faced the same bug when using environment-level secrets in a job (e.g. below)

...

jobs:

  do-something:

    runs-on: ubuntu-latest

    permissions:
      id-token: write
      contents: read

    environment: production

    steps:
    - uses: actions/checkout@v4
 
   ...

When I remove the associated line (i.e. environment: production) it works fine.

@kaykhan
Copy link
Author

kaykhan commented Aug 23, 2024

I was able to resolve this changing StringEquals to StringLike

https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-idp_oidc.html#idp_oidc_Create_GitHub

@kaykhan kaykhan closed this as completed Aug 23, 2024
Copy link

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.

@mini-ninja-64
Copy link

@kaykhan If u wanna use StringEquals, I think the JWT sub is different for environment managed workflows it does not contain refs, instead following this format:

repo:$ORG/$REPO:environment:$ENV

I guess because refs would be limited by ur github environment anyway 🤷‍♀️

@kaykhan
Copy link
Author

kaykhan commented Aug 25, 2024

@kaykhan If u wanna use StringEquals, I think the JWT sub is different for environment managed workflows it does not contain refs, instead following this format:

repo:$ORG/$REPO:environment:$ENV

I guess because refs would be limited by ur github environment anyway 🤷‍♀️

StringLike is a suitable solution for us as we don't want to explcitiy define the repostiory or environment.

@theJaxon
Copy link

theJaxon commented Jan 1, 2025

I received the same error but in my case it was because i've used the organization name in all lower case.
What wasn't working: repo:thejaxon/terraform-gitops

What works:

"StringLike": {
   "token.actions.githubusercontent.com:sub":"repo:theJaxon/terraform-gitops:*"
}

Reference

@maximillianus
Copy link

I got this problem too when environment variable is defined within the jobs. I understand the solution now based on conversation above.

However I still do not understand how adding environment change something in the sub value here repo:<GitHubOrg>/<GitHubRepo>:ref:refs/heads/<GitHubBranch>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage This issue still needs to be triaged
Projects
None yet
Development

No branches or pull requests

5 participants