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

OIDC: Can't assume role containing "github" #1093

Open
bbergeron0 opened this issue Jun 19, 2024 · 5 comments
Open

OIDC: Can't assume role containing "github" #1093

bbergeron0 opened this issue Jun 19, 2024 · 5 comments
Labels
bug Something isn't working p2

Comments

@bbergeron0
Copy link

bbergeron0 commented Jun 19, 2024

Describe the bug

Just like #953, OIDC seems to break down when the IAM role contains "GitHub." The runner couldn't assume the role of "github-action-deploy-to-staging" or "test-github-cicd," but assumed the role of "deploy-to-staging" without a hic, with the only difference between these roles being their name. After finding the aforementioned issue, I gave the solution a try and it worked.

Expected Behavior

I expect it to work even if the role contains "github".

Current Behavior

In GH action logs:

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

As I said, the role must contains "github" to fail. Here's the failing step in question; (Also, permissions.id-token = write)

    - name: Configure AWS credentials
      uses: aws-actions/configure-aws-credentials@v4
      with:
        role-to-assume: arn:aws:iam::[redacted]:role/github-said-hi
        role-session-name: samplerolesession
        aws-region: ${{ env.AWS_REGION }}

Possible Solution

#954 suggested to "either highlighting this restricted role name in the documentation, or fixing the issue preventing use of this role name." I'd like to vote for the second option this time around ;)

Additional Information/Context

No response

@bbergeron0 bbergeron0 added bug Something isn't working needs-triage This issue still needs to be triaged labels Jun 19, 2024
@gyfchong
Copy link

@tim-finnigan
Copy link
Contributor

This note was added to the README:

Note: Naming your role "GitHubActions" has been reported to not work. See #953.

More investigation is needed into why a role containing "github" doesn't work and what could be done about it.

@tim-finnigan tim-finnigan removed their assignment Jul 3, 2024
@tim-finnigan tim-finnigan added p2 and removed needs-triage This issue still needs to be triaged investigating labels Jul 3, 2024
@kuber-
Copy link

kuber- commented Aug 13, 2024

Had the same issue. Issue being - if the assumed role name is (in our case, it was exact match) GitHub, it fails as originally reported. Renaming the role (for example, changing to gh-oidc-role) with no other changes works. A couple of interesting things,

  1. We have 3 AWS accounts and only 2 out of 3 have this issue. The third has a role name exactly GitHub and it works!
  2. All three with role name GitHub were working for many months and aforementioned two stopped working around 31 july 2024!

For reference, action is invoked as follows,

uses: aws-actions/[email protected]
with:
  role-to-assume: arn:aws:iam::xxxx:role/GitHub
  role-session-name: GitHub_to_AWS_via_FederatedOIDC

@rahedges
Copy link

rahedges commented Sep 3, 2024

I had the same issue:

      role-to-assume: arn:aws:iam::XXXXX:role/GitHubActionXXXXX

It was fixed by changing to role name to:

      role-to-assume: arn:aws:iam::XXXXX:role/GHAXXXXXX

@ajoman
Copy link

ajoman commented Nov 12, 2024

For anyone still facing this issue. I have used GitHubActions literally in the role name and it is working for me. The problem I was having was that I didn't add the :* at the end of the repositories allowed in the trust relationship.

This is my role ARN:

arn:aws:iam::[redacted]:role/GitHubActions

And this is the trust policy of that role:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Federated": "arn:aws:iam::[redacted]:oidc-provider/token.actions.githubusercontent.com"
            },
            "Action": "sts:AssumeRoleWithWebIdentity",
            "Condition": {
                "StringEquals": {
                    "token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
                },
                "ForAnyValue:StringLike": {
                    "token.actions.githubusercontent.com:sub": [
                        "repo:{organization}/{repository-a}:*",
                        "repo:{organization}/{repository-b}:*"
                    ]
                }
            }
        }
    ]
}

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p2
Projects
None yet
Development

No branches or pull requests

6 participants