client: do not modify user-provided HTTP client#51817
Merged
thaJeztah merged 1 commit intomoby:masterfrom Jan 7, 2026
Merged
Conversation
Member
|
Heh. Nice find! Looks like it has been like this since .. forever. Validate is failing; looks like you need to run |
197b591 to
a6334d2
Compare
Member
|
🙈 sigh.. GOSEC linting failure now (sorry!) 🫶 |
The http.Client passed into client.WithHTTPClient() is modified by the constructor in-place: the value of its Transport field is mutated and wrapped in an OpenTelemetry decorator. This can lead to very surprising behaviour when a second client is constructed reusing the same http.Client value. If the http.Client is configured for TLS, the second client will fail to detect that and will incorrectly dial the Engine API socket as cleartext HTTP. Copy the provided http.Client so our modifications don't leak out to unexpected places. Signed-off-by: Cory Snider <csnider@mirantis.com>
a6334d2 to
9ebbf65
Compare
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.
- What I did
Fixed constructing two Engine API clients from the same http.Client so that the second behaves the same as the first.
- How I did it
The
http.Clientpassed intoclient.WithHTTPClient()is modified by the constructor in-place: the value of itsTransportfield is mutated and wrapped in an OpenTelemetry decorator. This can lead to very surprising behaviour when a second client is constructed reusing the samehttp.Clientvalue. If thehttp.Clientis configured for TLS, the second client will fail to detect that and will incorrectly dial the Engine API socket as cleartext HTTP. Copy the providedhttp.Clientso our modifications don't leak out to unexpected places.- How to verify it
New unit test.
- Human readable description for the release notes
- The http.Client value passed to client.WithHTTPClient() is now copied rather than mutated in-place.- A picture of a cute animal (not mandatory but encouraged)