File tree Expand file tree Collapse file tree 6 files changed +67
-9
lines changed
credential-provider-env/src
credential-provider-web-identity/src Expand file tree Collapse file tree 6 files changed +67
-9
lines changed Original file line number Diff line number Diff line change 1- import type { AwsHandlerExecutionContext , AwsSdkFeatures } from "@aws-sdk/types" ;
1+ import type {
2+ AttributedAwsCredentialIdentity ,
3+ AwsHandlerExecutionContext ,
4+ AwsSdkCredentialsFeatures ,
5+ AwsSdkFeatures ,
6+ } from "@aws-sdk/types" ;
27
38/**
49 * @internal
@@ -24,3 +29,20 @@ export function setFeature<F extends keyof AwsSdkFeatures>(
2429 }
2530 context . __aws_sdk_context . features ! [ feature ] = value ;
2631}
32+
33+ /**
34+ * @internal
35+ *
36+ * sets feature attribution on the credential object.
37+ */
38+ export function setCredentialFeature < F extends keyof AwsSdkCredentialsFeatures > (
39+ credentials : AttributedAwsCredentialIdentity ,
40+ feature : F ,
41+ value : AwsSdkCredentialsFeatures [ F ]
42+ ) : AttributedAwsCredentialIdentity {
43+ if ( ! credentials . $source ) {
44+ credentials . $source = { } ;
45+ }
46+ credentials . $source ! [ feature ] = value ;
47+ return credentials ;
48+ }
Original file line number Diff line number Diff line change 1+ import { setCredentialFeature } from "@aws-sdk/core/client" ;
2+ import { AttributedAwsCredentialIdentity } from "@aws-sdk/types" ;
13import {
24 doesIdentityRequireRefresh ,
35 isIdentityExpired ,
@@ -102,9 +104,11 @@ export interface AwsSdkSigV4AuthResolvedConfig {
102104export const resolveAwsSdkSigV4Config = < T > (
103105 config : T & AwsSdkSigV4AuthInputConfig & AwsSdkSigV4PreviouslyResolved
104106) : T & AwsSdkSigV4AuthResolvedConfig => {
107+ let isUserSupplied = false ;
105108 // Normalize credentials
106109 let normalizedCreds : AwsCredentialIdentityProvider | undefined ;
107110 if ( config . credentials ) {
111+ isUserSupplied = true ;
108112 normalizedCreds = memoizeIdentityProvider ( config . credentials , isIdentityExpired , doesIdentityRequireRefresh ) ;
109113 }
110114 if ( ! normalizedCreds ) {
@@ -218,7 +222,12 @@ export const resolveAwsSdkSigV4Config = <T>(
218222 ...config ,
219223 systemClockOffset,
220224 signingEscapePath,
221- credentials : normalizedCreds ! ,
225+ credentials : isUserSupplied
226+ ? async ( ) =>
227+ normalizedCreds ! ( ) . then ( ( creds : AttributedAwsCredentialIdentity ) =>
228+ setCredentialFeature ( creds , "CREDENTIALS_CODE" , "e" )
229+ )
230+ : normalizedCreds ! ,
222231 signer,
223232 } ;
224233} ;
Original file line number Diff line number Diff line change 1- import type { CredentialProviderOptions } from "@aws-sdk/types" ;
1+ import { setCredentialFeature } from "@aws-sdk/core/client" ;
2+ import type { AttributedAwsCredentialIdentity , CredentialProviderOptions } from "@aws-sdk/types" ;
23import { CredentialsProviderError } from "@smithy/property-provider" ;
34import { AwsCredentialIdentityProvider } from "@smithy/types" ;
45
@@ -48,14 +49,19 @@ export const fromEnv =
4849 const accountId : string | undefined = process . env [ ENV_ACCOUNT_ID ] ;
4950
5051 if ( accessKeyId && secretAccessKey ) {
51- return {
52+ const credentials = {
5253 accessKeyId,
5354 secretAccessKey,
5455 ...( sessionToken && { sessionToken } ) ,
5556 ...( expiry && { expiration : new Date ( expiry ) } ) ,
5657 ...( credentialScope && { credentialScope } ) ,
5758 ...( accountId && { accountId } ) ,
58- } ;
59+ } as AttributedAwsCredentialIdentity ;
60+ setCredentialFeature ( credentials , "CREDENTIALS_ENV_VARS" , "g" ) ;
61+ if ( accountId ) {
62+ setCredentialFeature ( credentials , "RESOLVED_ACCOUNT_ID" , "T" ) ;
63+ }
64+ return credentials ;
5965 }
6066
6167 throw new CredentialsProviderError ( "Unable to find environment variable credentials." , { logger : init ?. logger } ) ;
Original file line number Diff line number Diff line change 1- import { CredentialProviderOptions } from "@aws-sdk/types" ;
1+ import { setCredentialFeature } from "@aws-sdk/core/client" ;
2+ import { AttributedAwsCredentialIdentity , CredentialProviderOptions } from "@aws-sdk/types" ;
23import { CredentialsProviderError } from "@smithy/property-provider" ;
34import type { AwsCredentialIdentityProvider } from "@smithy/types" ;
45import { readFileSync } from "fs" ;
@@ -40,10 +41,16 @@ export const fromTokenFile =
4041 } ) ;
4142 }
4243
43- return fromWebToken ( {
44+ const credentials : AttributedAwsCredentialIdentity = await fromWebToken ( {
4445 ...init ,
4546 webIdentityToken : readFileSync ( webIdentityTokenFile , { encoding : "ascii" } ) ,
4647 roleArn,
4748 roleSessionName,
4849 } ) ( ) ;
50+
51+ if ( process . env [ ENV_TOKEN_FILE ] ) {
52+ setCredentialFeature ( credentials , "CREDENTIALS_ENV_VARS_STS_WEB_ID_TOKEN" , "h" ) ;
53+ }
54+
55+ return credentials ;
4956 } ;
Original file line number Diff line number Diff line change @@ -21,7 +21,6 @@ export type AwsSdkFeatures = Partial<{
2121 ACCOUNT_ID_MODE_DISABLED : "Q" ;
2222 ACCOUNT_ID_MODE_REQUIRED : "R" ;
2323 SIGV4A_SIGNING : "S" ;
24- RESOLVED_ACCOUNT_ID : "T" ;
2524 FLEXIBLE_CHECKSUMS_REQ_CRC32 : "U" ;
2625 FLEXIBLE_CHECKSUMS_REQ_CRC32C : "V" ;
2726 FLEXIBLE_CHECKSUMS_REQ_CRC64 : "W" ;
@@ -32,8 +31,15 @@ export type AwsSdkFeatures = Partial<{
3231 FLEXIBLE_CHECKSUMS_RES_WHEN_SUPPORTED : "b" ;
3332 FLEXIBLE_CHECKSUMS_RES_WHEN_REQUIRED : "c" ;
3433 DDB_MAPPER : "d" ;
34+ } > &
35+ AwsSdkCredentialsFeatures ;
36+
37+ /**
38+ * @internal
39+ */
40+ export type AwsSdkCredentialsFeatures = Partial < {
41+ RESOLVED_ACCOUNT_ID : "T" ;
3542 CREDENTIALS_CODE : "e" ;
36- // CREDENTIALS_JVM_SYSTEM_PROPERTIES: "f"; // not applicable.
3743 CREDENTIALS_ENV_VARS : "g" ;
3844 CREDENTIALS_ENV_VARS_STS_WEB_ID_TOKEN : "h" ;
3945 CREDENTIALS_STS_ASSUME_ROLE : "i" ;
Original file line number Diff line number Diff line change 1+ import type { AwsCredentialIdentity } from "@smithy/types" ;
2+
3+ import type { AwsSdkCredentialsFeatures } from "../feature-ids" ;
4+
15export { AwsCredentialIdentity , AwsCredentialIdentityProvider } from "@smithy/types" ;
6+
7+ export type AttributedAwsCredentialIdentity = AwsCredentialIdentity & {
8+ $source ?: AwsSdkCredentialsFeatures ;
9+ } ;
You can’t perform that action at this time.
0 commit comments