Centralize TLS config construction behind shared httputil helpers#7841
Merged
Conversation
Copilot
AI
changed the title
[WIP] Refactor TLS config struct initialization to eliminate duplicate code
Centralize TLS config construction behind shared httputil helpers
Jun 20, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR centralizes TLS tls.Config construction behind shared internal/httputil helpers to eliminate duplicated “min TLS version + certificate wiring” logic across the gateway server and proxy, reducing the risk of policy drift while preserving the existing TLS 1.2 minimum behavior.
Changes:
- Added
internal/httputil/tls_config.gowith a single TLS policy surface (MinTLSVersion) plusNewServerTLSConfig/NewClientTLSConfighelpers. - Updated gateway server TLS setup (
internal/server/gateway_tls.go) and proxy self-signed TLS generation (internal/proxy/tls.go) to usehttputil.NewServerTLSConfig. - Updated proxy outbound HTTP client TLS config (
internal/proxy/proxy.go) to usehttputil.NewClientTLSConfigand added focused helper tests ininternal/httputil/tls_config_test.go.
Show a summary per file
| File | Description |
|---|---|
| internal/server/gateway_tls.go | Replaces inline server tls.Config construction with httputil.NewServerTLSConfig while keeping existing mTLS augmentation logic intact. |
| internal/proxy/tls.go | Uses shared server TLS config helper for the generated self-signed localhost cert chain. |
| internal/proxy/proxy.go | Uses shared client TLS config helper for the proxy’s outbound http.Transport TLS policy. |
| internal/httputil/tls_config.go | Introduces centralized minimum TLS version constant and server/client TLS config constructors. |
| internal/httputil/tls_config_test.go | Adds unit tests validating the helper-produced tls.Config fields (min version and certificate wiring). |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 5/5 changed files
- Comments generated: 0
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.
TLS config initialization (
Certificates + MinVersion) was duplicated across server and proxy paths, with a separate inline client variant, creating policy drift risk if minimum TLS requirements change. This PR consolidates those constructions into shared helpers while preserving current TLS 1.2 behavior.Shared TLS policy surface
/internal/httputil/tls_config.gowith:MinTLSVersion(single source of truth for minimum TLS version)NewServerTLSConfig(cert tls.Certificate) *tls.ConfigNewClientTLSConfig() *tls.ConfigCall-site deduplication
/internal/server/gateway_tls.go/internal/proxy/tls.go/internal/proxy/proxy.goFocused helper coverage
/internal/httputil/tls_config_test.goto assert helper outputs (min version and certificate wiring).