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

Assume Role with OIDC with more than 1 hour #354

Closed
amit-disc opened this issue Jan 12, 2022 · 5 comments
Closed

Assume Role with OIDC with more than 1 hour #354

amit-disc opened this issue Jan 12, 2022 · 5 comments
Labels
needs-reproduction This issue needs reproduction. p2

Comments

@amit-disc
Copy link

Hi,

I am using OIDC provider to assume a role with maximum duration set to 8 hours.
I use role-duration-seconds: 21600 but the credentials expire after 1 hour.

Is it limited to 1 hour?

@christopher-dG
Copy link

This seems like a bug on GitHub's end.

A simple repro is something like this:

- uses: aws-actions/configure-aws-credentials@v1
  with:
    region: ***
    role-to-assume: arn:aws:iam::***role/***
- run: aws sts get-caller-identity
- run: sleep 61m
- run: aws sts get-caller-identity

The second call will fail with ExpiredToken.

You can also observe that trying to refresh credentials results in the exact same credentials being given back, e.g. with AWS.jl:

using AWS
config = global_aws_config()
@show config.credentials.expiry
sleep(5)
check_credentials(config.credentials; force_refresh=true)
@show config.credentials.expiry

In an EKS K8s pod with IAM roles via service accounts, the expiry will be updated, as it actually gets new credentials from the EKS provider. Running the same code in an Action where the credentials come from the GH provider results in no new credentials, even after they've expired.

@christopher-dG
Copy link

christopher-dG commented Jan 13, 2022

After some further investigation, I think I know the root cause: this action sets credentials as environment variables, and doesn't leave any breadcrumbs for SDKs in future steps to refresh them. When assuming a role via OIDC, it should be saving the WebIdentity token and exporting its path as AWS_WEB_IDENTITY_TOKEN_FILE. Then, SDKs can fetch credentials and refresh them properly using that file.

Barring error handling/setting the value as secret/properly exporting the variable to future steps, actually getting the token is just:

export AWS_ROLE_ARN="arn:aws:iam::$AWS_ACCOUNT:role/$AWS_ROLE"  # set $AWS_ACCOUNT and $AWS_ROLE yourself
export AWS_WEB_IDENTITY_TOKEN_FILE="$(mktemp)"
curl -s -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=sts.amazonaws.com" | jq -r .value > "$AWS_WEB_IDENTITY_TOKEN_FILE"

@christopher-dG
Copy link

christopher-dG commented Jan 14, 2022

Ha, just realized that the default session duration for OIDC is 1 hour not 6, it's right in the README. So just make sure your role has a long max session duration and then set role-session-duration in this action and you can have the session last more than an hour. The credentials still won't refresh though.

edit: oops, just re-read the original issue contents, looks like you've already done that

@peterwoodworth peterwoodworth added needs-triage This issue still needs to be triaged needs-reproduction This issue needs reproduction. p2 and removed needs-triage This issue still needs to be triaged labels Oct 4, 2022
@peterwoodworth
Copy link
Contributor

I'm not able to reproduce this even when using the simple sleep 61m repro. I recommend double checking that your role itself has a higher maximum duration than 1 hour, and that you've correctly set the inputs for this action.

Thanks for creating #359 @christopher-dG, it may be the source of the issue. Think we can close this and track that issue instead. If anyone has any reason to believe these are separate issues, ping me and I can look into it

@github-actions
Copy link

github-actions bot commented Oct 6, 2022

⚠️Comment Visibility Warning⚠️

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.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-reproduction This issue needs reproduction. p2
Projects
None yet
Development

No branches or pull requests

3 participants