Honor AWS_CA_BUNDLE/ca_bundle for container credentials endpoint - #3789
Open
synfinatic wants to merge 1 commit into
Open
Honor AWS_CA_BUNDLE/ca_bundle for container credentials endpoint#3789synfinatic wants to merge 1 commit into
synfinatic wants to merge 1 commit into
Conversation
ContainerMetadataFetcher always built its default URLLib3Session with verify=True, so a custom CA bundle configured via AWS_CA_BUNDLE (or the ca_bundle profile setting) was silently ignored when fetching credentials from AWS_CONTAINER_CREDENTIALS_FULL_URI. This made it impossible to serve container credentials over HTTPS from a locally-trusted CA. Thread the ca_bundle config variable through create_credential_resolver, following the same pattern already used for other ContainerProvider settings, and add a verify parameter to ContainerMetadataFetcher that only affects the default session it builds (an injected session is used as-is, preserving the existing test injection point). Fixes aws/aws-sdk#9016 Generated by AI tools, and reviewed by Aaron Turner.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A custom CA bundle configured via
AWS_CA_BUNDLE(or theca_bundleprofilesetting) is silently ignored when botocore fetches credentials from
AWS_CONTAINER_CREDENTIALS_FULL_URI. This makes it impossible to servecontainer credentials over HTTPS from a locally-trusted (private/self-signed)
CA — the request fails TLS verification even though
AWS_CA_BUNDLEpoints ata bundle that includes the issuing CA.
Tracked upstream as aws/aws-sdk#9016 (cross-SDK, opened 2024-07-08, no
movement).
Root cause
create_credential_resolver(botocore/credentials.py) constructsContainerProvider()with no arguments, so it builds its ownContainerMetadataFetcher.ContainerMetadataFetcher.__init__(botocore/utils.py) defaults toURLLib3Session(timeout=self.TIMEOUT_SECONDS)with noverifyargument.URLLib3Sessiondefaultsverify=True, andget_cert_path(True)returnscertifi.where()— no environment variable or config setting is consulted.configprovider.pyalready maps'ca_bundle': ('ca_bundle', 'AWS_CA_BUNDLE', None, None), andcreate_credential_resolveralready hassessionin scope and alreadycalls
session.get_config_variable(...)for other settings (e.g.metadata_service_timeout) — this setting was just never read.Reproduction
With a local HTTPS server on
https://localhost:PORTpresenting a certificatesigned by a private CA, and:
fails today with
SSLError: SSL validation failed ... [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate, even thoughAWS_CA_BUNDLEnames a bundle that includesthe CA that signed the server's certificate. After this change the same code
succeeds.
Fix
create_credential_resolvernow readsca_bundle = session.get_config_variable('ca_bundle')and passes it to aContainerMetadataFetcher(verify=ca_bundle), following the same patternalready used for
InstanceMetadataProvider's fetcher.ContainerMetadataFetcher.__init__gains averify=Noneparameter. When nosessionis injected, the defaultURLLib3Sessionis built withverify=verify if verify is not None else True— so unconfigured behavior(
True→ certifi/default trust store) is unchanged, and a configuredca_bundlepath is passed straight through. If asessionis injected (theexisting test seam),
verifyhas no effect.Default behavior is unchanged; this only takes effect when
ca_bundle/AWS_CA_BUNDLEis explicitly configured.Testing
tests/unit/test_credentials.pycovering thatcreate_credential_resolverwires an unconfigured session toverify=True, and a configured one to the bundle path.tests/unit/test_utils.pycoveringContainerMetadataFetcher's newverifyparam directly: default sessionverification, custom bundle passthrough, and that an injected session
ignores
verify(preserving the existing injection point).private CA: fails with
CERTIFICATE_VERIFY_FAILEDbefore this change,succeeds via
session.get_credentials()withAWS_CA_BUNDLEset after.Fixes aws/aws-sdk#9016
Generated by AI tools, and reviewed by Aaron Turner.