@aws-sdk/credential-provider-sso 3.208.0 → 3.210.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/fromSSO.js +33 -7
- package/dist-cjs/isSsoProfile.js +1 -0
- package/dist-cjs/resolveSSOCredentials.js +20 -5
- package/dist-cjs/validateSsoProfile.js +2 -2
- package/dist-es/fromSSO.js +34 -8
- package/dist-es/isSsoProfile.js +1 -0
- package/dist-es/resolveSSOCredentials.js +20 -5
- package/dist-es/validateSsoProfile.js +2 -2
- package/dist-types/fromSSO.d.ts +30 -0
- package/dist-types/resolveSSOCredentials.d.ts +4 -1
- package/dist-types/ts3.4/fromSSO.d.ts +1 -0
- package/dist-types/ts3.4/resolveSSOCredentials.d.ts +2 -0
- package/dist-types/ts3.4/types.d.ts +1 -0
- package/dist-types/types.d.ts +1 -0
- package/package.json +4 -3
package/dist-cjs/fromSSO.js
CHANGED
|
@@ -7,29 +7,55 @@ const isSsoProfile_1 = require("./isSsoProfile");
|
|
|
7
7
|
const resolveSSOCredentials_1 = require("./resolveSSOCredentials");
|
|
8
8
|
const validateSsoProfile_1 = require("./validateSsoProfile");
|
|
9
9
|
const fromSSO = (init = {}) => async () => {
|
|
10
|
-
const { ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoClient } = init;
|
|
11
|
-
|
|
10
|
+
const { ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoClient, ssoSession } = init;
|
|
11
|
+
const profileName = (0, shared_ini_file_loader_1.getProfileName)(init);
|
|
12
|
+
if (!ssoStartUrl && !ssoAccountId && !ssoRegion && !ssoRoleName && !ssoSession) {
|
|
12
13
|
const profiles = await (0, shared_ini_file_loader_1.parseKnownFiles)(init);
|
|
13
|
-
const profileName = (0, shared_ini_file_loader_1.getProfileName)(init);
|
|
14
14
|
const profile = profiles[profileName];
|
|
15
|
+
if (!profile) {
|
|
16
|
+
throw new property_provider_1.CredentialsProviderError(`Profile ${profileName} was not found.`);
|
|
17
|
+
}
|
|
15
18
|
if (!(0, isSsoProfile_1.isSsoProfile)(profile)) {
|
|
16
19
|
throw new property_provider_1.CredentialsProviderError(`Profile ${profileName} is not configured with SSO credentials.`);
|
|
17
20
|
}
|
|
18
|
-
|
|
21
|
+
if (profile === null || profile === void 0 ? void 0 : profile.sso_session) {
|
|
22
|
+
const ssoSessions = await (0, shared_ini_file_loader_1.loadSsoSessionData)(init);
|
|
23
|
+
const session = ssoSessions[profile.sso_session];
|
|
24
|
+
const conflictMsg = ` configurations in profile ${profileName} and sso-session ${profile.sso_session}`;
|
|
25
|
+
if (ssoRegion && ssoRegion !== session.sso_region) {
|
|
26
|
+
throw new property_provider_1.CredentialsProviderError(`Conflicting SSO region` + conflictMsg, false);
|
|
27
|
+
}
|
|
28
|
+
if (ssoStartUrl && ssoStartUrl !== session.sso_start_url) {
|
|
29
|
+
throw new property_provider_1.CredentialsProviderError(`Conflicting SSO start_url` + conflictMsg, false);
|
|
30
|
+
}
|
|
31
|
+
profile.sso_region = session.sso_region;
|
|
32
|
+
profile.sso_start_url = session.sso_start_url;
|
|
33
|
+
}
|
|
34
|
+
const { sso_start_url, sso_account_id, sso_region, sso_role_name, sso_session } = (0, validateSsoProfile_1.validateSsoProfile)(profile);
|
|
19
35
|
return (0, resolveSSOCredentials_1.resolveSSOCredentials)({
|
|
20
36
|
ssoStartUrl: sso_start_url,
|
|
37
|
+
ssoSession: sso_session,
|
|
21
38
|
ssoAccountId: sso_account_id,
|
|
22
39
|
ssoRegion: sso_region,
|
|
23
40
|
ssoRoleName: sso_role_name,
|
|
24
41
|
ssoClient: ssoClient,
|
|
42
|
+
profile: profileName,
|
|
25
43
|
});
|
|
26
44
|
}
|
|
27
45
|
else if (!ssoStartUrl || !ssoAccountId || !ssoRegion || !ssoRoleName) {
|
|
28
|
-
throw new property_provider_1.CredentialsProviderError(
|
|
29
|
-
' "ssoAccountId", "ssoRegion", "ssoRoleName"');
|
|
46
|
+
throw new property_provider_1.CredentialsProviderError("Incomplete configuration. The fromSSO() argument hash must include " +
|
|
47
|
+
'"ssoStartUrl", "ssoAccountId", "ssoRegion", "ssoRoleName"');
|
|
30
48
|
}
|
|
31
49
|
else {
|
|
32
|
-
return (0, resolveSSOCredentials_1.resolveSSOCredentials)({
|
|
50
|
+
return (0, resolveSSOCredentials_1.resolveSSOCredentials)({
|
|
51
|
+
ssoStartUrl,
|
|
52
|
+
ssoSession,
|
|
53
|
+
ssoAccountId,
|
|
54
|
+
ssoRegion,
|
|
55
|
+
ssoRoleName,
|
|
56
|
+
ssoClient,
|
|
57
|
+
profile: profileName,
|
|
58
|
+
});
|
|
33
59
|
}
|
|
34
60
|
};
|
|
35
61
|
exports.fromSSO = fromSSO;
|
package/dist-cjs/isSsoProfile.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.isSsoProfile = void 0;
|
|
|
4
4
|
const isSsoProfile = (arg) => arg &&
|
|
5
5
|
(typeof arg.sso_start_url === "string" ||
|
|
6
6
|
typeof arg.sso_account_id === "string" ||
|
|
7
|
+
typeof arg.sso_session === "string" ||
|
|
7
8
|
typeof arg.sso_region === "string" ||
|
|
8
9
|
typeof arg.sso_role_name === "string");
|
|
9
10
|
exports.isSsoProfile = isSsoProfile;
|
|
@@ -4,16 +4,31 @@ exports.resolveSSOCredentials = void 0;
|
|
|
4
4
|
const client_sso_1 = require("@aws-sdk/client-sso");
|
|
5
5
|
const property_provider_1 = require("@aws-sdk/property-provider");
|
|
6
6
|
const shared_ini_file_loader_1 = require("@aws-sdk/shared-ini-file-loader");
|
|
7
|
+
const token_providers_1 = require("@aws-sdk/token-providers");
|
|
7
8
|
const EXPIRE_WINDOW_MS = 15 * 60 * 1000;
|
|
8
9
|
const SHOULD_FAIL_CREDENTIAL_CHAIN = false;
|
|
9
|
-
const resolveSSOCredentials = async ({ ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoClient, }) => {
|
|
10
|
+
const resolveSSOCredentials = async ({ ssoStartUrl, ssoSession, ssoAccountId, ssoRegion, ssoRoleName, ssoClient, profile, }) => {
|
|
10
11
|
let token;
|
|
11
12
|
const refreshMessage = `To refresh this SSO session run aws sso login with the corresponding profile.`;
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
if (ssoSession) {
|
|
14
|
+
try {
|
|
15
|
+
const _token = await (0, token_providers_1.fromSso)({ profile })();
|
|
16
|
+
token = {
|
|
17
|
+
accessToken: _token.token,
|
|
18
|
+
expiresAt: new Date(_token.expiration).toISOString(),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
throw new property_provider_1.CredentialsProviderError(e.message, SHOULD_FAIL_CREDENTIAL_CHAIN);
|
|
23
|
+
}
|
|
14
24
|
}
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
else {
|
|
26
|
+
try {
|
|
27
|
+
token = await (0, shared_ini_file_loader_1.getSSOTokenFromFile)(ssoStartUrl);
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
throw new property_provider_1.CredentialsProviderError(`The SSO session associated with this profile is invalid. ${refreshMessage}`, SHOULD_FAIL_CREDENTIAL_CHAIN);
|
|
31
|
+
}
|
|
17
32
|
}
|
|
18
33
|
if (new Date(token.expiresAt).getTime() - Date.now() <= EXPIRE_WINDOW_MS) {
|
|
19
34
|
throw new property_provider_1.CredentialsProviderError(`The SSO session associated with this profile has expired. ${refreshMessage}`, SHOULD_FAIL_CREDENTIAL_CHAIN);
|
|
@@ -5,8 +5,8 @@ const property_provider_1 = require("@aws-sdk/property-provider");
|
|
|
5
5
|
const validateSsoProfile = (profile) => {
|
|
6
6
|
const { sso_start_url, sso_account_id, sso_region, sso_role_name } = profile;
|
|
7
7
|
if (!sso_start_url || !sso_account_id || !sso_region || !sso_role_name) {
|
|
8
|
-
throw new property_provider_1.CredentialsProviderError(`Profile is configured with invalid SSO credentials. Required parameters "sso_account_id",
|
|
9
|
-
`"sso_role_name", "sso_start_url". Got ${Object.keys(profile).join(", ")}\nReference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html`, false);
|
|
8
|
+
throw new property_provider_1.CredentialsProviderError(`Profile is configured with invalid SSO credentials. Required parameters "sso_account_id", ` +
|
|
9
|
+
`"sso_region", "sso_role_name", "sso_start_url". Got ${Object.keys(profile).join(", ")}\nReference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html`, false);
|
|
10
10
|
}
|
|
11
11
|
return profile;
|
|
12
12
|
};
|
package/dist-es/fromSSO.js
CHANGED
|
@@ -1,31 +1,57 @@
|
|
|
1
1
|
import { CredentialsProviderError } from "@aws-sdk/property-provider";
|
|
2
|
-
import { getProfileName, parseKnownFiles } from "@aws-sdk/shared-ini-file-loader";
|
|
2
|
+
import { getProfileName, loadSsoSessionData, parseKnownFiles, } from "@aws-sdk/shared-ini-file-loader";
|
|
3
3
|
import { isSsoProfile } from "./isSsoProfile";
|
|
4
4
|
import { resolveSSOCredentials } from "./resolveSSOCredentials";
|
|
5
5
|
import { validateSsoProfile } from "./validateSsoProfile";
|
|
6
6
|
export const fromSSO = (init = {}) => async () => {
|
|
7
|
-
const { ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoClient } = init;
|
|
8
|
-
|
|
7
|
+
const { ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoClient, ssoSession } = init;
|
|
8
|
+
const profileName = getProfileName(init);
|
|
9
|
+
if (!ssoStartUrl && !ssoAccountId && !ssoRegion && !ssoRoleName && !ssoSession) {
|
|
9
10
|
const profiles = await parseKnownFiles(init);
|
|
10
|
-
const profileName = getProfileName(init);
|
|
11
11
|
const profile = profiles[profileName];
|
|
12
|
+
if (!profile) {
|
|
13
|
+
throw new CredentialsProviderError(`Profile ${profileName} was not found.`);
|
|
14
|
+
}
|
|
12
15
|
if (!isSsoProfile(profile)) {
|
|
13
16
|
throw new CredentialsProviderError(`Profile ${profileName} is not configured with SSO credentials.`);
|
|
14
17
|
}
|
|
15
|
-
|
|
18
|
+
if (profile?.sso_session) {
|
|
19
|
+
const ssoSessions = await loadSsoSessionData(init);
|
|
20
|
+
const session = ssoSessions[profile.sso_session];
|
|
21
|
+
const conflictMsg = ` configurations in profile ${profileName} and sso-session ${profile.sso_session}`;
|
|
22
|
+
if (ssoRegion && ssoRegion !== session.sso_region) {
|
|
23
|
+
throw new CredentialsProviderError(`Conflicting SSO region` + conflictMsg, false);
|
|
24
|
+
}
|
|
25
|
+
if (ssoStartUrl && ssoStartUrl !== session.sso_start_url) {
|
|
26
|
+
throw new CredentialsProviderError(`Conflicting SSO start_url` + conflictMsg, false);
|
|
27
|
+
}
|
|
28
|
+
profile.sso_region = session.sso_region;
|
|
29
|
+
profile.sso_start_url = session.sso_start_url;
|
|
30
|
+
}
|
|
31
|
+
const { sso_start_url, sso_account_id, sso_region, sso_role_name, sso_session } = validateSsoProfile(profile);
|
|
16
32
|
return resolveSSOCredentials({
|
|
17
33
|
ssoStartUrl: sso_start_url,
|
|
34
|
+
ssoSession: sso_session,
|
|
18
35
|
ssoAccountId: sso_account_id,
|
|
19
36
|
ssoRegion: sso_region,
|
|
20
37
|
ssoRoleName: sso_role_name,
|
|
21
38
|
ssoClient: ssoClient,
|
|
39
|
+
profile: profileName,
|
|
22
40
|
});
|
|
23
41
|
}
|
|
24
42
|
else if (!ssoStartUrl || !ssoAccountId || !ssoRegion || !ssoRoleName) {
|
|
25
|
-
throw new CredentialsProviderError(
|
|
26
|
-
' "ssoAccountId", "ssoRegion", "ssoRoleName"');
|
|
43
|
+
throw new CredentialsProviderError("Incomplete configuration. The fromSSO() argument hash must include " +
|
|
44
|
+
'"ssoStartUrl", "ssoAccountId", "ssoRegion", "ssoRoleName"');
|
|
27
45
|
}
|
|
28
46
|
else {
|
|
29
|
-
return resolveSSOCredentials({
|
|
47
|
+
return resolveSSOCredentials({
|
|
48
|
+
ssoStartUrl,
|
|
49
|
+
ssoSession,
|
|
50
|
+
ssoAccountId,
|
|
51
|
+
ssoRegion,
|
|
52
|
+
ssoRoleName,
|
|
53
|
+
ssoClient,
|
|
54
|
+
profile: profileName,
|
|
55
|
+
});
|
|
30
56
|
}
|
|
31
57
|
};
|
package/dist-es/isSsoProfile.js
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
import { GetRoleCredentialsCommand, SSOClient } from "@aws-sdk/client-sso";
|
|
2
2
|
import { CredentialsProviderError } from "@aws-sdk/property-provider";
|
|
3
3
|
import { getSSOTokenFromFile } from "@aws-sdk/shared-ini-file-loader";
|
|
4
|
+
import { fromSso as getSsoTokenProvider } from "@aws-sdk/token-providers";
|
|
4
5
|
const EXPIRE_WINDOW_MS = 15 * 60 * 1000;
|
|
5
6
|
const SHOULD_FAIL_CREDENTIAL_CHAIN = false;
|
|
6
|
-
export const resolveSSOCredentials = async ({ ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoClient, }) => {
|
|
7
|
+
export const resolveSSOCredentials = async ({ ssoStartUrl, ssoSession, ssoAccountId, ssoRegion, ssoRoleName, ssoClient, profile, }) => {
|
|
7
8
|
let token;
|
|
8
9
|
const refreshMessage = `To refresh this SSO session run aws sso login with the corresponding profile.`;
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
if (ssoSession) {
|
|
11
|
+
try {
|
|
12
|
+
const _token = await getSsoTokenProvider({ profile })();
|
|
13
|
+
token = {
|
|
14
|
+
accessToken: _token.token,
|
|
15
|
+
expiresAt: new Date(_token.expiration).toISOString(),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
throw new CredentialsProviderError(e.message, SHOULD_FAIL_CREDENTIAL_CHAIN);
|
|
20
|
+
}
|
|
11
21
|
}
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
else {
|
|
23
|
+
try {
|
|
24
|
+
token = await getSSOTokenFromFile(ssoStartUrl);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
throw new CredentialsProviderError(`The SSO session associated with this profile is invalid. ${refreshMessage}`, SHOULD_FAIL_CREDENTIAL_CHAIN);
|
|
28
|
+
}
|
|
14
29
|
}
|
|
15
30
|
if (new Date(token.expiresAt).getTime() - Date.now() <= EXPIRE_WINDOW_MS) {
|
|
16
31
|
throw new CredentialsProviderError(`The SSO session associated with this profile has expired. ${refreshMessage}`, SHOULD_FAIL_CREDENTIAL_CHAIN);
|
|
@@ -2,8 +2,8 @@ import { CredentialsProviderError } from "@aws-sdk/property-provider";
|
|
|
2
2
|
export const validateSsoProfile = (profile) => {
|
|
3
3
|
const { sso_start_url, sso_account_id, sso_region, sso_role_name } = profile;
|
|
4
4
|
if (!sso_start_url || !sso_account_id || !sso_region || !sso_role_name) {
|
|
5
|
-
throw new CredentialsProviderError(`Profile is configured with invalid SSO credentials. Required parameters "sso_account_id",
|
|
6
|
-
`"sso_role_name", "sso_start_url". Got ${Object.keys(profile).join(", ")}\nReference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html`, false);
|
|
5
|
+
throw new CredentialsProviderError(`Profile is configured with invalid SSO credentials. Required parameters "sso_account_id", ` +
|
|
6
|
+
`"sso_region", "sso_role_name", "sso_start_url". Got ${Object.keys(profile).join(", ")}\nReference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html`, false);
|
|
7
7
|
}
|
|
8
8
|
return profile;
|
|
9
9
|
};
|
package/dist-types/fromSSO.d.ts
CHANGED
|
@@ -6,6 +6,11 @@ export interface SsoCredentialsParameters {
|
|
|
6
6
|
* The URL to the AWS SSO service.
|
|
7
7
|
*/
|
|
8
8
|
ssoStartUrl: string;
|
|
9
|
+
/**
|
|
10
|
+
* SSO session identifier.
|
|
11
|
+
* Presence implies usage of the SSOTokenProvider.
|
|
12
|
+
*/
|
|
13
|
+
ssoSession?: string;
|
|
9
14
|
/**
|
|
10
15
|
* The ID of the AWS account to use for temporary credentials.
|
|
11
16
|
*/
|
|
@@ -25,5 +30,30 @@ export interface FromSSOInit extends SourceProfileInit {
|
|
|
25
30
|
/**
|
|
26
31
|
* Creates a credential provider that will read from a credential_process specified
|
|
27
32
|
* in ini files.
|
|
33
|
+
*
|
|
34
|
+
* The SSO credential provider must support both
|
|
35
|
+
*
|
|
36
|
+
* 1. the legacy profile format,
|
|
37
|
+
* @example
|
|
38
|
+
* ```
|
|
39
|
+
* [profile sample-profile]
|
|
40
|
+
* sso_account_id = 012345678901
|
|
41
|
+
* sso_region = us-east-1
|
|
42
|
+
* sso_role_name = SampleRole
|
|
43
|
+
* sso_start_url = https://www.....com/start
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* 2. and the profile format for SSO Token Providers.
|
|
47
|
+
* @example
|
|
48
|
+
* ```
|
|
49
|
+
* [profile sso-profile]
|
|
50
|
+
* sso_session = dev
|
|
51
|
+
* sso_account_id = 012345678901
|
|
52
|
+
* sso_role_name = SampleRole
|
|
53
|
+
*
|
|
54
|
+
* [sso-session dev]
|
|
55
|
+
* sso_region = us-east-1
|
|
56
|
+
* sso_start_url = https://www.....com/start
|
|
57
|
+
* ```
|
|
28
58
|
*/
|
|
29
59
|
export declare const fromSSO: (init?: FromSSOInit & Partial<SsoCredentialsParameters>) => CredentialProvider;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { Credentials } from "@aws-sdk/types";
|
|
2
2
|
import { FromSSOInit, SsoCredentialsParameters } from "./fromSSO";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @private
|
|
5
|
+
*/
|
|
6
|
+
export declare const resolveSSOCredentials: ({ ssoStartUrl, ssoSession, ssoAccountId, ssoRegion, ssoRoleName, ssoClient, profile, }: FromSSOInit & SsoCredentialsParameters) => Promise<Credentials>;
|
|
@@ -3,6 +3,7 @@ import { SourceProfileInit } from "@aws-sdk/shared-ini-file-loader";
|
|
|
3
3
|
import { CredentialProvider } from "@aws-sdk/types";
|
|
4
4
|
export interface SsoCredentialsParameters {
|
|
5
5
|
ssoStartUrl: string;
|
|
6
|
+
ssoSession?: string;
|
|
6
7
|
ssoAccountId: string;
|
|
7
8
|
ssoRegion: string;
|
|
8
9
|
ssoRoleName: string;
|
|
@@ -2,8 +2,10 @@ import { Credentials } from "@aws-sdk/types";
|
|
|
2
2
|
import { FromSSOInit, SsoCredentialsParameters } from "./fromSSO";
|
|
3
3
|
export declare const resolveSSOCredentials: ({
|
|
4
4
|
ssoStartUrl,
|
|
5
|
+
ssoSession,
|
|
5
6
|
ssoAccountId,
|
|
6
7
|
ssoRegion,
|
|
7
8
|
ssoRoleName,
|
|
8
9
|
ssoClient,
|
|
10
|
+
profile,
|
|
9
11
|
}: FromSSOInit & SsoCredentialsParameters) => Promise<Credentials>;
|
package/dist-types/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/credential-provider-sso",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.210.0",
|
|
4
4
|
"description": "AWS credential provider that exchanges a resolved SSO login token file for temporary AWS credentials",
|
|
5
5
|
"main": "./dist-cjs/index.js",
|
|
6
6
|
"module": "./dist-es/index.js",
|
|
@@ -24,9 +24,10 @@
|
|
|
24
24
|
},
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@aws-sdk/client-sso": "3.
|
|
27
|
+
"@aws-sdk/client-sso": "3.210.0",
|
|
28
28
|
"@aws-sdk/property-provider": "3.208.0",
|
|
29
|
-
"@aws-sdk/shared-ini-file-loader": "3.
|
|
29
|
+
"@aws-sdk/shared-ini-file-loader": "3.209.0",
|
|
30
|
+
"@aws-sdk/token-providers": "3.210.0",
|
|
30
31
|
"@aws-sdk/types": "3.208.0",
|
|
31
32
|
"tslib": "^2.3.1"
|
|
32
33
|
},
|