Repository navigation
Conversation
Fixes aws#1545 The CLI only read a custom CA bundle from `--ca-bundle-path`/`caBundlePath` or `AWS_CA_BUNDLE`. The AWS CLI (botocore) also uses the `ca_bundle` setting of the active profile in the shared ini files and falls back to `REQUESTS_CA_BUNDLE`. Behind a TLS-intercepting proxy, a setup that works for `aws sso login` therefore failed in the CDK CLI with "self-signed certificate in certificate chain" on SSO.GetRoleCredentials. Resolve the bundle in botocore's order: explicit configuration, then `AWS_CA_BUNDLE`, then the profile's `ca_bundle` (credentials file over config file, read with `@smithy/shared-ini-file-loader`; profile from `--profile`, `AWS_PROFILE`, `AWS_DEFAULT_PROFILE`, `default`, as `AwsCliCompatible` already does), then `REQUESTS_CA_BUNDLE`. The chosen source is logged at debug level. The bundle already reaches the SSO and SSO-OIDC clients through the request handler's agent, so no other wiring changes are needed.
|
Automated review A maintainer will still review this — treat the notes below as a starting point. 📌 Commit This PR fixes a bug (#1545) where the CDK CLI ignored a custom CA bundle unless 🔴 0 blocking · 🟡 0 recommended · ⚪ 0 optional Generated automatically. React 👍 or 👎 to tell us whether this review helped, so we can improve these reviews. |
Fixes #1545
The CLI only picked up a custom CA bundle from
--ca-bundle-path/caBundlePathor theAWS_CA_BUNDLEenvironment variable. The AWS CLI (botocore) also uses theca_bundlesetting of the active profile and falls back toREQUESTS_CA_BUNDLE. Behind a TLS-intercepting proxy, a setup that works foraws sso loginfailed in the CDK CLI withself-signed certificate in certificate chainonSSO.GetRoleCredentials, and the user saw only "Unable to resolve AWS account to use".This change resolves the CA bundle in the same order as botocore (
Session.create_clientandEndpointCreator._get_verify_value):--ca-bundle-path/caBundlePathincdk.jsonAWS_CA_BUNDLE(the existing lowercaseaws_ca_bundlecheck stays)ca_bundlesetting of the profile in the shared credentials file, then the shared config file (botocore merges the credentials file over the config file). The profile is--profile, thenAWS_PROFILE, thenAWS_DEFAULT_PROFILE, thendefault. The files are read with@smithy/shared-ini-file-loader, which is already a dependency and honoursAWS_CONFIG_FILE/AWS_SHARED_CREDENTIALS_FILE.REQUESTS_CA_BUNDLEThe source that was used is logged at debug level, for example
Using CA bundle path from REQUESTS_CA_BUNDLE: /path/to/bundle.pem.No other wiring was needed. The resolved bundle goes into the
ProxyAgent, whichsdkRequestHandler()passes to the credential chain asclientConfig.requestHandler. The SDK'sSSOClient(GetRoleCredentials) andSSOOIDCClient(token refresh) are built from thatclientConfig, so the reporter's SSO path now uses the bundle. The detached telemetry sender gets the resolved path the same way it did before.I updated the
--ca-bundle-pathhelp text incli-config.tsand regeneratedparse-command-line-arguments.ts,user-input.tsandcli-type-registry.jsonwith the package'spre-compiletask.Decisions to flag:
AwsCliCompatiblein toolkit-lib already picks it (AWS_PROFILEbeforeAWS_DEFAULT_PROFILE). Botocore's own chain listsAWS_DEFAULT_PROFILEfirst; I followed the existing CDK convention so the bundle and the credentials come from the same profile.SSL_CERT_FILEis not used. Botocore ignores it too, and this PR aims for parity with the AWS CLI. A test pins this down.proxy-agent.tsthat only readsAWS_CA_BUNDLE. I left it alone to keep this PR to one concern.Testing: new unit tests in
packages/aws-cdk/test/cli/proxy-agent.test.tscover each precedence step using temporaryAWS_CONFIG_FILE/AWS_SHARED_CREDENTIALS_FILEfiles: explicit path,AWS_CA_BUNDLE, the profileca_bundlefrom--profile/AWS_PROFILE/AWS_DEFAULT_PROFILE/default, credentials file over config file,REQUESTS_CA_BUNDLE, no config file, andSSL_CERT_FILEbeing ignored. I didn't add an integration test because it would need a TLS-intercepting proxy.I used an AI coding assistant for parts of this change and reviewed and tested it myself.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license