-
Notifications
You must be signed in to change notification settings - Fork 603
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
AWS SDK is unable to fetch AWS credentials from AWS IAM Identity Center if the Identity Center access token for an SSO session expiry time is between 5 and 15 minutes from now #4798
Comments
… AWS IAM Identity Center tokens Previously credential-provider-sso would throw an error if an sso-session based access token was expiring within 15 minutes. However, the sso token provider would only trigger refresh if the token was expiring within 5 minutes. This lead to situation where the sso token provider would did not refresh the token before it had 5 minutes of validity left while the credential-provider-sso rejected the token as expired already at 15 minutes of validity left. This commit updates credential-provider-sso module to not check the expiry time of sso-session based AWS IAM Identity Center access tokens. The sso token provider already has a lot of logic to make sure it only ever returns valid access tokens. This also aligns the SDK with other AWS SDKs that do not check the expiry time of refreshable sso-session tokens but try to refresh the token automatically some time before it expires or if the token has already expired (botocore, aws-sdk-js v2, aws-sdk-java v2 and aws-sdk-go-v2 at least work like this). The credential-provider-sso module will still check the expiry of a cached, non-refreshable AWS IAM Identity Center token, reject the token and prompt the user to reauthenticate 15 minutes before the token expires. Fixes aws#4798.
Proposed a potential fix to this issue at #4812 |
Just to confirm that any fix for these issues will also fix the issue where it seems aws-cdk doesn't engage the token refreshing at all? Because aws/aws-cdk#24782 has been said to be tracked by the changes on ☝️. And so I hope that carries over to this too! |
It's not entirely clear if this is the issue that causes the CDK issue you linked to. Currently CDK uses both SDK v2 and v3 internally and I'm not sure which SDK is used for the credential resolution over there. However, it's very likely that the CDK problem is caused by either this or aws/aws-sdk-js#4441 depending on which SDK version is used there. I guess we'll see that when fix to this and aws/aws-sdk-js#4441 is merged and released, and CDK is updated to take newer version of SDKs into use. |
This was fixed in the Java SDK by simply removing the 15 minute expiration check from the SSO credential provider: aws/aws-sdk-java-v2#4157. Possibly this is safe to do here as well? Pull created in #5124, but I will discuss further with the team. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
Checkboxes for prior research
Describe the bug
When using AWS IAM Identity Center based profile with the sso_session option, aws-sdk-js-v3 fails to resolve AWS credentials if the AWS IAM Identity Center SSO session access token expires between 5 and 15 minutes from now.
SDK version number
@aws-sdk/[email protected]
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
v18.16.0
Reproduction Steps
config
with following content (fill in your AWS IAM Identity Center details):aws sso login --session-name mysso
index.js
with following content:Alternatively, you may manually set the
expiresAt
field value to ~15 minutes from now in token cache files in~/.aws/sso/cache/
folder to simulate a token that is about to expire in 15 minutes from now without having to wait full hour to get there.Observed Behavior
When AWS IAM Identity Center access token expiry time is > 15 minutes from now, AWS SDK is able to fetch AWS credentials from AWS IAM Identity Center with the valid access token.
When AWS IAM Identity Center access token expiry time is < 15 minutes but > 5 minutes from now, AWS SDK rejects the access token as expired and prompts the user to refresh it manually (all AWS API calls fail during this time):
When AWS IAM Identity Center access token expiry time is < 5 minutes from now, AWS SDK automatically refreshes the token and is able to fetch AWS credentials again using the new token.
Expected Behavior
AWS SDK either accepts the token until it hits the 5 minute mark or refreshes the token automatically already at the 15 minute mark without user intervention.
Possible Solution
Reason for the issue is that the AWS IAM Identity Center token-providers package considers tokens with > 5 minute lifetime as valid and only refreshes them at the 5 minute mark:
aws-sdk-js-v3/packages/token-providers/src/fromSso.ts
Lines 84 to 87 in 7529755
aws-sdk-js-v3/packages/token-providers/src/constants.ts
Line 7 in 7529755
However, the user of these tokens, the credential-provider-sso package, rejects AWS IAM Identity Center access token if its lifetime is < 15 minutes:
aws-sdk-js-v3/packages/credential-provider-sso/src/resolveSSOCredentials.ts
Lines 55 to 60 in 7529755
aws-sdk-js-v3/packages/credential-provider-sso/src/resolveSSOCredentials.ts
Lines 9 to 15 in 7529755
Hence, if token is set to expire between 5 and 15 minutes from now, token-providers package considers the tokens to be valid while the credential-provider-sso package considers the tokens to be expired.
Additional Information/Context
No response
The text was updated successfully, but these errors were encountered: