Skip to content

Commit e59dd4c

Browse files
committed
feat(credential-providers): add credentialScope field
1 parent e54099b commit e59dd4c

File tree

8 files changed

+50
-15
lines changed

8 files changed

+50
-15
lines changed

clients/client-sts/src/defaultStsRoleAssumers.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// smithy-typescript generated code
22
// Please do not touch this file. It's generated from template in:
33
// https://github.com/aws/aws-sdk-js-v3/blob/main/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultStsRoleAssumers.ts
4-
import { Credentials } from "@aws-sdk/types";
5-
import { Provider } from "@smithy/types";
4+
import { AwsCredentialIdentity, Provider } from "@smithy/types";
65

76
import { AssumeRoleCommand, AssumeRoleCommandInput } from "./commands/AssumeRoleCommand";
87
import {
@@ -14,7 +13,10 @@ import type { STSClient, STSClientConfig, STSClientResolvedConfig } from "./STSC
1413
/**
1514
* @internal
1615
*/
17-
export type RoleAssumer = (sourceCreds: Credentials, params: AssumeRoleCommandInput) => Promise<Credentials>;
16+
export type RoleAssumer = (
17+
sourceCreds: AwsCredentialIdentity,
18+
params: AssumeRoleCommandInput
19+
) => Promise<AwsCredentialIdentity>;
1820

1921
const ASSUME_ROLE_DEFAULT_REGION = "us-east-1";
2022

@@ -43,7 +45,7 @@ export const getDefaultRoleAssumer = (
4345
stsClientCtor: new (options: STSClientConfig) => STSClient
4446
): RoleAssumer => {
4547
let stsClient: STSClient;
46-
let closureSourceCreds: Credentials;
48+
let closureSourceCreds: AwsCredentialIdentity;
4749
return async (sourceCreds, params) => {
4850
closureSourceCreds = sourceCreds;
4951
if (!stsClient) {
@@ -65,14 +67,18 @@ export const getDefaultRoleAssumer = (
6567
secretAccessKey: Credentials.SecretAccessKey,
6668
sessionToken: Credentials.SessionToken,
6769
expiration: Credentials.Expiration,
70+
// TODO(credentialScope): access normally when shape is updated.
71+
credentialScope: (Credentials as any).CredentialScope,
6872
};
6973
};
7074
};
7175

7276
/**
7377
* @internal
7478
*/
75-
export type RoleAssumerWithWebIdentity = (params: AssumeRoleWithWebIdentityCommandInput) => Promise<Credentials>;
79+
export type RoleAssumerWithWebIdentity = (
80+
params: AssumeRoleWithWebIdentityCommandInput
81+
) => Promise<AwsCredentialIdentity>;
7682

7783
/**
7884
* The default role assumer that used by credential providers when sts:AssumeRoleWithWebIdentity API is needed.
@@ -101,14 +107,16 @@ export const getDefaultRoleAssumerWithWebIdentity = (
101107
secretAccessKey: Credentials.SecretAccessKey,
102108
sessionToken: Credentials.SessionToken,
103109
expiration: Credentials.Expiration,
110+
// TODO(credentialScope): access normally when shape is updated.
111+
credentialScope: (Credentials as any).CredentialScope,
104112
};
105113
};
106114
};
107115

108116
/**
109117
* @internal
110118
*/
111-
export type DefaultCredentialProvider = (input: any) => Provider<Credentials>;
119+
export type DefaultCredentialProvider = (input: any) => Provider<AwsCredentialIdentity>;
112120

113121
/**
114122
* The default credential providers depend STS client to assume role with desired API: sts:assumeRole,

codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultStsRoleAssumers.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Credentials } from "@aws-sdk/types";
2-
import { Provider } from "@smithy/types";
1+
import { AwsCredentialIdentity, Provider } from "@smithy/types";
32

43
import { AssumeRoleCommand, AssumeRoleCommandInput } from "./commands/AssumeRoleCommand";
54
import {
@@ -11,7 +10,10 @@ import type { STSClient, STSClientConfig, STSClientResolvedConfig } from "./STSC
1110
/**
1211
* @internal
1312
*/
14-
export type RoleAssumer = (sourceCreds: Credentials, params: AssumeRoleCommandInput) => Promise<Credentials>;
13+
export type RoleAssumer = (
14+
sourceCreds: AwsCredentialIdentity,
15+
params: AssumeRoleCommandInput
16+
) => Promise<AwsCredentialIdentity>;
1517

1618
const ASSUME_ROLE_DEFAULT_REGION = "us-east-1";
1719

@@ -40,7 +42,7 @@ export const getDefaultRoleAssumer = (
4042
stsClientCtor: new (options: STSClientConfig) => STSClient
4143
): RoleAssumer => {
4244
let stsClient: STSClient;
43-
let closureSourceCreds: Credentials;
45+
let closureSourceCreds: AwsCredentialIdentity;
4446
return async (sourceCreds, params) => {
4547
closureSourceCreds = sourceCreds;
4648
if (!stsClient) {
@@ -62,14 +64,18 @@ export const getDefaultRoleAssumer = (
6264
secretAccessKey: Credentials.SecretAccessKey,
6365
sessionToken: Credentials.SessionToken,
6466
expiration: Credentials.Expiration,
67+
// TODO(credentialScope): access normally when shape is updated.
68+
credentialScope: (Credentials as any).CredentialScope,
6569
};
6670
};
6771
};
6872

6973
/**
7074
* @internal
7175
*/
72-
export type RoleAssumerWithWebIdentity = (params: AssumeRoleWithWebIdentityCommandInput) => Promise<Credentials>;
76+
export type RoleAssumerWithWebIdentity = (
77+
params: AssumeRoleWithWebIdentityCommandInput
78+
) => Promise<AwsCredentialIdentity>;
7379

7480
/**
7581
* The default role assumer that used by credential providers when sts:AssumeRoleWithWebIdentity API is needed.
@@ -98,14 +104,16 @@ export const getDefaultRoleAssumerWithWebIdentity = (
98104
secretAccessKey: Credentials.SecretAccessKey,
99105
sessionToken: Credentials.SessionToken,
100106
expiration: Credentials.Expiration,
107+
// TODO(credentialScope): access normally when shape is updated.
108+
credentialScope: (Credentials as any).CredentialScope,
101109
};
102110
};
103111
};
104112

105113
/**
106114
* @internal
107115
*/
108-
export type DefaultCredentialProvider = (input: any) => Provider<Credentials>;
116+
export type DefaultCredentialProvider = (input: any) => Provider<AwsCredentialIdentity>;
109117

110118
/**
111119
* The default credential providers depend STS client to assume role with desired API: sts:assumeRole,
@@ -120,6 +128,9 @@ export const decorateDefaultCredentialProvider =
120128
(input: STSClientResolvedConfig) =>
121129
provider({
122130
roleAssumer: getDefaultRoleAssumer(input, input.stsClientCtor as new (options: STSClientConfig) => STSClient),
123-
roleAssumerWithWebIdentity: getDefaultRoleAssumerWithWebIdentity(input, input.stsClientCtor as new (options: STSClientConfig) => STSClient),
131+
roleAssumerWithWebIdentity: getDefaultRoleAssumerWithWebIdentity(
132+
input,
133+
input.stsClientCtor as new (options: STSClientConfig) => STSClient
134+
),
124135
...input,
125136
});

packages/credential-provider-env/src/fromEnv.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export const ENV_SESSION = "AWS_SESSION_TOKEN";
1717
* @internal
1818
*/
1919
export const ENV_EXPIRATION = "AWS_CREDENTIAL_EXPIRATION";
20+
/**
21+
* @internal
22+
*/
23+
export const ENV_CREDENTIAL_SCOPE = "AWS_CREDENTIAL_SCOPE";
2024

2125
/**
2226
* @internal
@@ -30,13 +34,15 @@ export const fromEnv = (): AwsCredentialIdentityProvider => async () => {
3034
const secretAccessKey: string | undefined = process.env[ENV_SECRET];
3135
const sessionToken: string | undefined = process.env[ENV_SESSION];
3236
const expiry: string | undefined = process.env[ENV_EXPIRATION];
37+
const credentialScope: string | undefined = process.env[ENV_CREDENTIAL_SCOPE];
3338

3439
if (accessKeyId && secretAccessKey) {
3540
return {
3641
accessKeyId,
3742
secretAccessKey,
3843
...(sessionToken && { sessionToken }),
3944
...(expiry && { expiration: new Date(expiry) }),
45+
...(credentialScope && { credentialScope }),
4046
};
4147
}
4248

packages/credential-provider-ini/src/resolveStaticCredentials.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface StaticCredsProfile extends Profile {
77
aws_access_key_id: string;
88
aws_secret_access_key: string;
99
aws_session_token?: string;
10+
aws_credential_scope?: string;
1011
}
1112

1213
/**
@@ -27,4 +28,5 @@ export const resolveStaticCredentials = (profile: StaticCredsProfile): Promise<A
2728
accessKeyId: profile.aws_access_key_id,
2829
secretAccessKey: profile.aws_secret_access_key,
2930
sessionToken: profile.aws_session_token,
31+
credentialScope: profile.aws_credential_scope,
3032
});

packages/credential-provider-process/src/ProcessCredentials.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export type ProcessCredentials = {
77
SecretAccessKey: string;
88
SessionToken?: string;
99
Expiration?: number;
10+
CredentialScope?: string;
1011
};

packages/credential-provider-process/src/getValidatedProcessCredentials.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ export const getValidatedProcessCredentials = (
3030
secretAccessKey: data.SecretAccessKey,
3131
...(data.SessionToken && { sessionToken: data.SessionToken }),
3232
...(data.Expiration && { expiration: new Date(data.Expiration) }),
33+
...(data.CredentialScope && { credentialScope: data.CredentialScope }),
3334
};
3435
};

packages/credential-provider-sso/src/resolveSSOCredentials.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { FromSSOInit, SsoCredentialsParameters } from "./fromSSO";
99
const SHOULD_FAIL_CREDENTIAL_CHAIN = false;
1010

1111
/**
12-
* @private
12+
* @internal
1313
*/
1414
export const resolveSSOCredentials = async ({
1515
ssoStartUrl,
@@ -67,9 +67,13 @@ export const resolveSSOCredentials = async ({
6767
}
6868

6969
const { roleCredentials: { accessKeyId, secretAccessKey, sessionToken, expiration } = {} } = ssoResp;
70+
// TODO(credentialScope): Extract from ssoResp object with other credential fields
71+
// TODO(credentialScope): when this field becomes defined on the shape.
72+
const credentialScope = (ssoResp?.roleCredentials as any)?.credentialScope;
73+
7074
if (!accessKeyId || !secretAccessKey || !sessionToken || !expiration) {
7175
throw new CredentialsProviderError("SSO returns an invalid temporary credential.", SHOULD_FAIL_CREDENTIAL_CHAIN);
7276
}
7377

74-
return { accessKeyId, secretAccessKey, sessionToken, expiration: new Date(expiration) };
78+
return { accessKeyId, secretAccessKey, sessionToken, expiration: new Date(expiration), credentialScope };
7579
};

packages/credential-providers/src/fromTemporaryCredentials.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ export const fromTemporaryCredentials = (options: FromTemporaryCredentialsOption
7878
secretAccessKey: Credentials.SecretAccessKey,
7979
sessionToken: Credentials.SessionToken,
8080
expiration: Credentials.Expiration,
81+
// TODO(credentialScope): access normally when shape is updated.
82+
credentialScope: (Credentials as any).CredentialScope,
8183
};
8284
};
8385
};

0 commit comments

Comments
 (0)