@@ -13,6 +13,12 @@ export interface SsoCredentialsParameters {
13
13
*/
14
14
ssoStartUrl : string ;
15
15
16
+ /**
17
+ * SSO session identifier.
18
+ * Presence implies usage of the SSOTokenProvider.
19
+ */
20
+ ssoSession ?: string ;
21
+
16
22
/**
17
23
* The ID of the AWS account to use for temporary credentials.
18
24
*/
@@ -36,35 +42,65 @@ export interface FromSSOInit extends SourceProfileInit {
36
42
/**
37
43
* Creates a credential provider that will read from a credential_process specified
38
44
* in ini files.
45
+ *
46
+ * The SSO credential provider must support both
47
+ *
48
+ * 1. the legacy profile format,
49
+ * @example
50
+ * ```
51
+ * [profile sample-profile]
52
+ * sso_account_id = 012345678901
53
+ * sso_region = us-east-1
54
+ * sso_role_name = SampleRole
55
+ * sso_start_url = https://www.....com/start
56
+ * ```
57
+ *
58
+ * 2. and the profile format for SSO Token Providers.
59
+ * @example
60
+ * ```
61
+ * [profile sso-profile]
62
+ * sso_session = dev
63
+ * sso_account_id = 012345678901
64
+ * sso_role_name = SampleRole
65
+ *
66
+ * [sso-session dev]
67
+ * sso_region = us-east-1
68
+ * sso_start_url = https://www.....com/start
69
+ * ```
39
70
*/
40
71
export const fromSSO =
41
72
( init : FromSSOInit & Partial < SsoCredentialsParameters > = { } ) : CredentialProvider =>
42
73
async ( ) => {
43
- const { ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoClient } = init ;
44
- if ( ! ssoStartUrl && ! ssoAccountId && ! ssoRegion && ! ssoRoleName ) {
74
+ const { ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoClient, ssoSession } = init ;
75
+ if ( ! ssoStartUrl && ! ssoAccountId && ! ssoRegion && ! ssoRoleName && ! ssoSession ) {
45
76
// Load the SSO config from shared AWS config file.
46
77
const profiles = await parseKnownFiles ( init ) ;
47
78
const profileName = getProfileName ( init ) ;
48
79
const profile = profiles [ profileName ] ;
49
80
81
+ // TODO(sso): merge [sso-session X] data into the profile if sso_session exists in it.
82
+ // TODO(sso): if the sso profile and the sso-session both have region and start URL,
83
+ // TODO(sso): they must match or an error shall be thrown.
84
+
50
85
if ( ! isSsoProfile ( profile ) ) {
51
86
throw new CredentialsProviderError ( `Profile ${ profileName } is not configured with SSO credentials.` ) ;
52
87
}
53
88
54
- const { sso_start_url, sso_account_id, sso_region, sso_role_name } = validateSsoProfile ( profile ) ;
89
+ const { sso_start_url, sso_account_id, sso_region, sso_role_name, sso_session } = validateSsoProfile ( profile ) ;
55
90
return resolveSSOCredentials ( {
56
91
ssoStartUrl : sso_start_url ,
92
+ ssoSession : sso_session ,
57
93
ssoAccountId : sso_account_id ,
58
94
ssoRegion : sso_region ,
59
95
ssoRoleName : sso_role_name ,
60
96
ssoClient : ssoClient ,
61
97
} ) ;
62
- } else if ( ! ssoStartUrl || ! ssoAccountId || ! ssoRegion || ! ssoRoleName ) {
98
+ } else if ( ! ssoStartUrl || ! ssoAccountId || ! ssoRegion || ! ssoRoleName || ! ssoSession ) {
63
99
throw new CredentialsProviderError (
64
- 'Incomplete configuration. The fromSSO() argument hash must include "ssoStartUrl ",' +
65
- ' "ssoAccountId ", "ssoRegion ", "ssoRoleName" '
100
+ 'Incomplete configuration. The fromSSO() argument hash must include "ssoAccountId ",' +
101
+ ' "ssoRegion ", "ssoRoleName ", and one of "ssoStartUrl" or "ssoSession". '
66
102
) ;
67
103
} else {
68
- return resolveSSOCredentials ( { ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoClient } ) ;
104
+ return resolveSSOCredentials ( { ssoStartUrl, ssoSession , ssoAccountId, ssoRegion, ssoRoleName, ssoClient } ) ;
69
105
}
70
106
} ;
0 commit comments