Skip to content

Commit 01fec04

Browse files
committed
fix(cli): getting credentials via SSO fails when the region is set in the profile (#32520)
We were reading the region from the config file and passing it to the credential providers. However, in the case of SSO, this makes the credential provider use that region to do the SSO flow, which is incorrect. The region that should be used for that is the one set in the `sso_session` section of the config file. The long term solution is for all the logic for handling regions in the SDK itself, without forcing consumers to know all the intricacies of all the use cases. As a mitigation for now, we are using the non-public `parentClientConfig` while we wait for an SDK update. Fixes #32510. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b5c2189 commit 01fec04

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

packages/aws-cdk/lib/api/aws-auth/awscli-compatible.ts

+15
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ export class AwsCliCompatible {
3434
requestHandler: AwsCliCompatible.requestHandlerBuilder(options.httpOptions),
3535
customUserAgent: 'aws-cdk',
3636
logger: options.logger,
37+
};
38+
39+
// Super hacky solution to https://github.com/aws/aws-cdk/issues/32510, proposed by the SDK team.
40+
//
41+
// Summary of the problem: we were reading the region from the config file and passing it to
42+
// the credential providers. However, in the case of SSO, this makes the credential provider
43+
// use that region to do the SSO flow, which is incorrect. The region that should be used for
44+
// that is the one set in the sso_session section of the config file.
45+
//
46+
// The idea here: the "clientConfig" is for configuring the inner auth client directly,
47+
// and has the highest priority, whereas "parentClientConfig" is the upper data client
48+
// and has lower priority than the sso_region but still higher priority than STS global region.
49+
const parentClientConfig = {
3750
region: await this.region(options.profile),
3851
};
3952
/**
@@ -51,6 +64,7 @@ export class AwsCliCompatible {
5164
ignoreCache: true,
5265
mfaCodeProvider: tokenCodeFn,
5366
clientConfig,
67+
parentClientConfig,
5468
logger: options.logger,
5569
}));
5670
}
@@ -83,6 +97,7 @@ export class AwsCliCompatible {
8397
const nodeProviderChain = fromNodeProviderChain({
8498
profile: envProfile,
8599
clientConfig,
100+
parentClientConfig,
86101
logger: options.logger,
87102
mfaCodeProvider: tokenCodeFn,
88103
ignoreCache: true,

0 commit comments

Comments
 (0)