-
Notifications
You must be signed in to change notification settings - Fork 597
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
Cannot use AWS SSO with assume role when source_profile uses the sso_session option #4757
Comments
…urce_profile Previously, when credential-provider-ini resolved credentials for a source profile, it loaded the profile properties, checked if the profile was an SSO profile, validated that all required sso_* properties were present and then resolved credentials with credential-provider-sso module. When source profile was an SSO profile that did not use an SSO session, this logic worked fine as the profile must include all the sso_* properties for SSO to succeed. However, when source profile was an SSO profile that used an SSO session, credential-provider-ini only resolved profile properties directly from the profile but not from the related SSO session. This caused sso-session based profiles to fail validation as some of the required sso_* properties are only defined in the referenced sso-session section. And hence the provider failed to resolve credentials for SSO session based source_profiles. This commit changes credential-provider-ini module to not resolve or validate SSO profile properties but delegate that all to the credential-provider-sso module that already contains all the logic needed to load and resolve profile properties and AWS credentials for both sso-session and non-sso-session based profiles. Instead of passing profile properties to credential-provider-sso fromSSO() method, new version only passes the profile name there and lets the credential-provider-sso module load and resolve the SSO profile with the logic that already exist in that module. Unit tests have been adjusted to function with the updated behavior. Following scenarios were also tested manually: * Resolve credentials for SSO profile without sso_session option * Resolve credentials for SSO profile with sso_session option * Resolve credentials for an assumed role profile whose source profile is an SSO profile without sso_session option * Resolve credentials for an assumed role profile whose source profile is an SSO profile with sso_session option AWS SDK resolved credentials correctly in all four cases. Fixes aws#4757.
I need this fixed. I have a terminal cli that uses AWS SDK for several tasks and allows to specify a profile with a
|
I believe the issue and the workaround you describe are not exactly the same that is described here. The SDK is able to load credentials for profiles that use sso-session option. Setting AWS_PROFILE to an sso-session based profile works just fine with the default credential provider. There's no issue with that. This issue is specifically about using an sso-session based profile as a source_profile for a profile with role_arn option (profile that assumes a role using credentials of the source profile). The SDK is unable to resolve the source_profile correctly when the source profile is sso-session based. If you set AWS_PROFILE to a profile whose source_profile points to sso-session based profile, the SDK fails to resolve credentials regardless of how the SDK is used. Using AWS_PROFILE variable is not a workaround for the issue with the SDK itself. But it can work around the sso-session profile loading issue in CLI apps depending on how they are using the SDK. |
@RanVaknin Please remove the workaround-available label. As @sjakthol notes, the stated work around does not work for the issue described here. |
I am also experiencing this issue. I get the following error if
This format does not work:
This format (which I believe is equivalent, but does not use sessions) works fine:
|
Hi @sjakthol, @gastonsilva, @asibs, this seems to be a limitation for JS SDK v3, where if we use a profile that references to another profile that uses sso_session then, the required fields for sso will not be resolved from that referenced profile, and hence it will complain about it. I tested this with JS and PHP SDKs and I got the same issue.
and we use the profile first_profile then, we will not have any issues. I will mark this issue with a needs-review label so we can analyze this further. Code to reproduce: import {GetCallerIdentityCommand, STSClient} from "@aws-sdk/client-sts"
process.env.AWS_CONFIG_FILE="../config"
process.env.AWS_PROFILE="second_profile"
process.env.AWS_SDK_LOAD_CONFIG=1
const client = new STSClient({
region : "us-east-2"
});
const cmd = new GetCallerIdentityCommand({})
console.log(await client.send(cmd)) config
Thanks! |
@yenfryherrerafeliz: Any chance to get some eyes from the team to check this issue? There's an open pull request with a fix to this issue available: #4820. Would be great if you or someone else from the SDK team would have some time to review that. Thanks! |
AWS SDK JS v3 is unable to resolve credentials when a source_profile points to a profile using sso_session option: aws/aws-sdk-js-v3#4757. This commit monkeypatches the problematic function, catches failure and tries to load credentials again using fromSSO() method that has more extensive logic for resolving credentials for SSO profiles. Versions of involved packages have been pinned to exact versions to avoid sudden breakage if the methods in question change.
AWS SDK JS v3 is unable to resolve credentials when a source_profile points to a profile using sso_session option: aws/aws-sdk-js-v3#4757. This commit monkeypatches the problematic function, catches failure and tries to load credentials again using fromSSO() method that has more extensive logic for resolving credentials for SSO profiles. Versions of involved packages have been pinned to exact versions to avoid sudden breakage if the methods in question change.
AWS SDK JS v3 is unable to resolve credentials when a source_profile points to a profile using sso_session option: aws/aws-sdk-js-v3#4757. This commit monkeypatches the problematic function, catches failure and tries to load credentials again using fromSSO() method that has more extensive logic for resolving credentials for SSO profiles. Versions of involved packages have been pinned to exact versions to avoid sudden breakage if the methods in question change.
AWS SDK JS v3 is unable to resolve credentials when a source_profile points to a profile using sso_session option: aws/aws-sdk-js-v3#4757. This commit monkeypatches the problematic function, catches failure and tries to load credentials again using fromSSO() method that has more extensive logic for resolving credentials for SSO profiles. Versions of involved packages have been pinned to exact versions to avoid sudden breakage if the methods in question change.
AWS SDK JS v3 is unable to resolve credentials when a source_profile points to a profile using sso_session option: aws/aws-sdk-js-v3#4757. This commit monkeypatches the problematic function, catches failure and tries to load credentials again using fromSSO() method that has more extensive logic for resolving credentials for SSO profiles. Versions of involved packages have been pinned to exact versions to avoid sudden breakage if the methods in question change.
Gentle bump – any chance someone from the SDK team can take a look at the proposed fix in #4820? |
Hi everyone on the thread. I appreciate your patience on this. I will re-review this with the team and see if we can assign a higher priority to this. Thanks again, |
…urce_profile Previously, when credential-provider-ini resolved credentials for a source profile, it loaded the profile properties, checked if the profile was an SSO profile, validated that all required sso_* properties were present and then resolved credentials with credential-provider-sso module. When source profile was an SSO profile that did not use an SSO session, this logic worked fine as the profile must include all the sso_* properties for SSO to succeed. However, when source profile was an SSO profile that used an SSO session, credential-provider-ini only resolved profile properties directly from the profile but not from the related SSO session. This caused sso-session based profiles to fail validation as some of the required sso_* properties are only defined in the referenced sso-session section. And hence the provider failed to resolve credentials for SSO session based source_profiles. This commit changes credential-provider-ini module to not resolve or validate SSO profile properties but delegate that all to the credential-provider-sso module that already contains all the logic needed to load and resolve profile properties and AWS credentials for both sso-session and non-sso-session based profiles. Instead of passing profile properties to credential-provider-sso fromSSO() method, new version only passes the profile name there and lets the credential-provider-sso module load and resolve the SSO profile with the logic that already exist in that module. Unit tests have been adjusted to function with the updated behavior. Following scenarios were also tested manually: * Resolve credentials for SSO profile without sso_session option * Resolve credentials for SSO profile with sso_session option * Resolve credentials for an assumed role profile whose source profile is an SSO profile without sso_session option * Resolve credentials for an assumed role profile whose source profile is an SSO profile with sso_session option AWS SDK resolved credentials correctly in all four cases. Fixes aws#4757.
…urce_profile Previously, when credential-provider-ini resolved credentials for a source profile, it loaded the profile properties, checked if the profile was an SSO profile, validated that all required sso_* properties were present and then resolved credentials with credential-provider-sso module. When source profile was an SSO profile that did not use an SSO session, this logic worked fine as the profile must include all the sso_* properties for SSO to succeed. However, when source profile was an SSO profile that used an SSO session, credential-provider-ini only resolved profile properties directly from the profile but not from the related SSO session. This caused sso-session based profiles to fail validation as some of the required sso_* properties are only defined in the referenced sso-session section. And hence the provider failed to resolve credentials for SSO session based source_profiles. This commit changes credential-provider-ini module to not resolve or validate SSO profile properties but delegate that all to the credential-provider-sso module that already contains all the logic needed to load and resolve profile properties and AWS credentials for both sso-session and non-sso-session based profiles. Instead of passing profile properties to credential-provider-sso fromSSO() method, new version only passes the profile name there and lets the credential-provider-sso module load and resolve the SSO profile with the logic that already exist in that module. Unit tests have been adjusted to function with the updated behavior. Following scenarios were also tested manually: * Resolve credentials for SSO profile without sso_session option * Resolve credentials for SSO profile with sso_session option * Resolve credentials for an assumed role profile whose source profile is an SSO profile without sso_session option * Resolve credentials for an assumed role profile whose source profile is an SSO profile with sso_session option AWS SDK resolved credentials correctly in all four cases. Fixes aws#4757.
…urce_profile (#4820) Previously, when credential-provider-ini resolved credentials for a source profile, it loaded the profile properties, checked if the profile was an SSO profile, validated that all required sso_* properties were present and then resolved credentials with credential-provider-sso module. When source profile was an SSO profile that did not use an SSO session, this logic worked fine as the profile must include all the sso_* properties for SSO to succeed. However, when source profile was an SSO profile that used an SSO session, credential-provider-ini only resolved profile properties directly from the profile but not from the related SSO session. This caused sso-session based profiles to fail validation as some of the required sso_* properties are only defined in the referenced sso-session section. And hence the provider failed to resolve credentials for SSO session based source_profiles. This commit changes credential-provider-ini module to not resolve or validate SSO profile properties but delegate that all to the credential-provider-sso module that already contains all the logic needed to load and resolve profile properties and AWS credentials for both sso-session and non-sso-session based profiles. Instead of passing profile properties to credential-provider-sso fromSSO() method, new version only passes the profile name there and lets the credential-provider-sso module load and resolve the SSO profile with the logic that already exist in that module. Unit tests have been adjusted to function with the updated behavior. Following scenarios were also tested manually: * Resolve credentials for SSO profile without sso_session option * Resolve credentials for SSO profile with sso_session option * Resolve credentials for an assumed role profile whose source profile is an SSO profile without sso_session option * Resolve credentials for an assumed role profile whose source profile is an SSO profile with sso_session option AWS SDK resolved credentials correctly in all four cases. Fixes #4757.
Is there any reason I would suddenly start experiencing this issue? As of today? |
Reverting the sdk version from |
@chlorophant @nick-kang Could you show your configuration of profiles and the error message? |
My Profile looks like:
As for the error, it presented itself when using the aws-sdk bedrock-runtime package in my app |
What is the error message in your case? And you are using the default credential lookup chain by initializing the client with no credential configuration? |
I am able to reproduce the issue with index.js sample code from the issue description and first_profile of the example configuration. My guess is that the following extra check added yesterday in d27301d is causing the trouble here:
Before that check, the default provider would always call @aws-sdk/credential-provider-sso fromSSO for the profile that was being resolved regardless of its options. fromSSO has extra logic that is missing from the new check to resolve ssoStartUrl and ssoRegion variables from the linked ssoSession instead of expecting them to be defined in the profile directly. Now with that extra check in place, the default provider no longer invokes fromSSO method for profiles that use the ssoSession option to provide ssoStartUrl and ssoRegion options. If all SSO related options are not defined in the profile directly, the provider moves over to @aws-sdk/credential-provider-ini fromIni method as the next provider in the chain. Unfortunately that provider is not able to resolve ssoSession based profiles and thus credential resolution fails. This is not exactly the same issue that was originally discussed here. But it's actually very close and the fix for this issue also fixes this fresh issue by accident. The commit that was meant to fix this issue (b87f5e0) was not part of SDK version 3.502.0. I did not notice this fresh issue in my testing yesterday as the fix I made here also happened to fix the issue introduced by d27301d. As part of b87f5e0, fromIni method got the ability to resolve credentials for ssoSession backed profiles. And now that ssoSession backed profiles fall through to fromIni based resolution, it works when commit b87f5e0 is in (next SDK release) but fails if that's missing (latest SDK release). Anyway, the fix from commit b87f5e0 to this fresh issue is a pure accident. Probably a better fix for the fresh issue is to amend the check at
|
I've opened a PR to modify the skip condition in the defaultProvider #5746. The defaultProvider chain contains two (2) paths to the SSO provider. One is at the top level, if the user inputs SSO related fields in code. The second is in a later step via the INI provider. With the added skip-check, it was incorrectly abandoning the direct SSO provider if any single field was missing. This is incompatible because there are two different sets of information that constitute a valid SSO initialization, one of which is the session based configuration. If the profile still had SSO information, the second path to the SSO provider via INI would still work. |
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
AWS SDK JS v3 is not able to resolve credentials of a profile with
role_arn
andsource_profile
fields when the source profile uses thesso_session
option.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:index.js
with following content:Please note that the configuration with placeholder values for sso_start_url, sso_account_id, sso_role_name and role_arn fields is sufficient to reproduce the issue with the SDK (valid values are not required for exception to be thrown). However, to verify potential fixes you'll need to fill in real values in the configuration.
Observed Behavior
AWS SDK JS v3 fails to resolve credentials with validation error on the source profile ("first_profile" in the example):
Expected Behavior
AWS SDK JS v3 is able to resolve credentials for the profile that assumes a role using a profile that for which an SSO session provides some of the SSO related configuration values. Here's how the same config works with AWS CLI v2:
Possible Solution
No response
Additional Information/Context
No response
The text was updated successfully, but these errors were encountered: