Skip to content

fix: use SDK middleware for User-Agent to support AWS_CA_BUNDLE#255

Open
gustavodiaz7722 wants to merge 1 commit into
aws-controllers-k8s:mainfrom
gustavodiaz7722:fix-aws-ca-bundle-compatibility
Open

fix: use SDK middleware for User-Agent to support AWS_CA_BUNDLE#255
gustavodiaz7722 wants to merge 1 commit into
aws-controllers-k8s:mainfrom
gustavodiaz7722:fix-aws-ca-bundle-compatibility

Conversation

@gustavodiaz7722

Copy link
Copy Markdown
Member

Description

Fixes aws-controllers-k8s/community#2915

When the AWS_CA_BUNDLE environment variable is set, all ACK controllers fail with:

unable to add custom RootCAs HTTPClient, has no WithTransportOptions, *runtime.clientWithUserAgent

Root Cause

The ACK runtime wraps the *awshttp.BuildableClient in a custom clientWithUserAgent struct to inject User-Agent headers. The AWS SDK's resolveCustomCABundle function type-asserts cfg.HTTPClient to *awshttp.BuildableClient in order to call WithTransportOptions and inject custom root CAs. Since the HTTPClient is *runtime.clientWithUserAgent (not *awshttp.BuildableClient), the assertion fails.

Fix

  • Remove the clientWithUserAgent wrapper struct
  • Pass *awshttp.BuildableClient directly as the HTTPClient so the SDK can modify its transport
  • Inject the custom User-Agent string via the SDK's built-in middleware (awsmiddleware.AddUserAgentKeyValue) through config.WithAPIOptions

This approach preserves the same User-Agent behavior while making the HTTPClient compatible with all SDK transport modifications (CA bundles, proxies, etc.).

Testing

  • All existing tests continue to pass
  • Added TestNewAWSConfig_HTTPClient_IsBuildableClient — verifies the HTTPClient remains type-assertable to *awshttp.BuildableClient
  • Added TestNewAWSConfig_WithAWSCABundle — directly reproduces the original bug by setting AWS_CA_BUNDLE and verifying LoadDefaultConfig succeeds

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ack-prow ack-prow Bot requested review from a-hilaly and knottnt June 16, 2026 20:51
@ack-prow

ack-prow Bot commented Jun 16, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: gustavodiaz7722
Once this PR has been reviewed and has the lgtm label, please assign michaelhtm for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@gustavodiaz7722 gustavodiaz7722 force-pushed the fix-aws-ca-bundle-compatibility branch from 181a627 to 44f7dda Compare June 16, 2026 21:01
Previously, the ACK runtime wrapped the *awshttp.BuildableClient in a
custom clientWithUserAgent struct to inject a User-Agent header. This
broke the AWS SDK's resolveCustomCABundle function, which type-asserts
the HTTPClient to *awshttp.BuildableClient to call WithTransportOptions.
When AWS_CA_BUNDLE was set, LoadDefaultConfig would fail with:
  "unable to add custom RootCAs HTTPClient, has no WithTransportOptions,
  *runtime.clientWithUserAgent"

This commit removes the clientWithUserAgent wrapper and instead uses a
custom smithy Build middleware to prepend the ACK User-Agent string to
outgoing HTTP requests. This approach:

1. Passes *awshttp.BuildableClient directly as the HTTPClient, allowing
   the SDK to properly modify transport options for CA bundles, proxies,
   and other features.
2. Preserves the exact User-Agent format (including slashes, parentheses,
   and semicolons) without character sanitization that the SDK's built-in
   AddUserAgentKeyValue middleware would apply.
3. Maintains backward compatibility — the User-Agent header seen by AWS
   APIs is identical to the previous format.

Fixes aws-controllers-k8s/community#2915
@gustavodiaz7722

Copy link
Copy Markdown
Member Author

/retest

@gustavodiaz7722

Copy link
Copy Markdown
Member Author

/restest

@gustavodiaz7722

Copy link
Copy Markdown
Member Author

/retest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to use environment variable AWS_CA_BUNDLE with IAM controller

1 participant