-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Handle sso session names with quotes/spaces #2895
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -359,12 +359,8 @@ def sso_credentials_from_profile(cfg, profile) | |
!(prof_config.keys & SSO_CREDENTIAL_PROFILE_KEYS).empty? | ||
|
||
if sso_session_name = prof_config['sso_session'] | ||
sso_session = cfg["sso-session #{sso_session_name}"] | ||
unless sso_session | ||
raise ArgumentError, | ||
"sso-session #{sso_session_name} must be defined in the config file. " \ | ||
"Referenced by profile #{profile}" | ||
end | ||
sso_session = sso_session(cfg, profile, sso_session_name) | ||
|
||
sso_region = sso_session['sso_region'] | ||
sso_start_url = sso_session['sso_start_url'] | ||
|
||
|
@@ -389,7 +385,7 @@ def sso_credentials_from_profile(cfg, profile) | |
sso_role_name: prof_config['sso_role_name'], | ||
sso_session: prof_config['sso_session'], | ||
sso_region: sso_region, | ||
sso_start_url: prof_config['sso_start_url'] | ||
sso_start_url: sso_start_url | ||
) | ||
end | ||
end | ||
|
@@ -402,16 +398,7 @@ def sso_token_from_profile(cfg, profile) | |
!(prof_config.keys & SSO_TOKEN_PROFILE_KEYS).empty? | ||
|
||
sso_session_name = prof_config['sso_session'] | ||
sso_session = cfg["sso-session #{sso_session_name}"] | ||
unless sso_session | ||
raise ArgumentError, | ||
"sso-session #{sso_session_name} must be defined in the config file." \ | ||
"Referenced by profile #{profile}" | ||
end | ||
|
||
unless sso_session['sso_region'] | ||
raise ArgumentError, "sso-session #{sso_session_name} missing required parameter: sso_region" | ||
end | ||
sso_session = sso_session(cfg, profile, sso_session_name) | ||
|
||
SSOTokenProvider.new( | ||
sso_session: sso_session_name, | ||
|
@@ -469,5 +456,22 @@ def determine_profile(options) | |
ret ||= 'default' | ||
ret | ||
end | ||
|
||
def sso_session(cfg, profile, sso_session_name) | ||
# aws sso-configure may add quotes around sso session names with whitespace | ||
sso_session = cfg["sso-session #{sso_session_name}"] || cfg["sso-session '#{sso_session_name}'"] | ||
|
||
unless sso_session | ||
raise ArgumentError, | ||
"sso-session #{sso_session_name} must be defined in the config file. " \ | ||
"Referenced by profile #{profile}" | ||
end | ||
|
||
unless sso_session['sso_region'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The SSOCredentials will fail if sso_region is unset, so this moves the failure case up to here (with hopefully slightly. more info). |
||
raise ArgumentError, "sso-session #{sso_session_name} missing required parameter: sso_region" | ||
end | ||
|
||
sso_session | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change should be safe since the non-legacy flow does NOT use the sso_start_url, see: https://github.com/aws/aws-sdk-ruby/blob/version-3/gems/aws-sdk-core/lib/aws-sdk-core/sso_credentials.rb#L82