proxy: select TLS certificates from the matched listener #1725
(Automatic review) Reviewed head ff5f2b2a230dc0b0f126cdc134554f54286a696b. The overall architecture (InternalListener.Certificates / CertificateIDs, ValidateCertificate setting cert.Leaf, excluding TLSModePassthrough, and keeping the flat certificate map for the follow-up cleanup) looks good. Please address these items before approval:
1. Single-pod DataPlaneHTTPSPort (8443) shadows more-specific listeners on other ports (pkg/proxy/proxy.go:877-900): In matchTLSListeners, when localPort == state.DataPlaneHTTPSPort and portMatched is non-empty, returning as soon as state.MatchListeners(portMatched, sni) finds any match lets a catch-all or shorter-wildcard listener on port 8443 shadow an exact or longer-wildcard listener on port 443. When localPort == state.DataPlaneHTTPSPort, also match against all listeners and prefer the strictly more specific match (by MatchType, then longer wildcard Hostname), keeping portMatched on ties so port 8443 still wins when both ports share the same hostname. Add a regression test in pkg/proxy/certificate_selection_test.go with a catch-all (or wildcard) listener on DataPlaneHTTPSPort and an exact listener on port 443.
2. Check all tied listeners in matched (pkg/proxy/proxy.go:993-996): In single-pod mode, two listeners on different ports with the same hostname (for example, two *.example.com or two catch-all listeners on ports 443 and 8444 with different SAN certificates) both appear in matched. Inspecting only matched[0] misses certificates on matched[1]. Try SupportsCertificate across all matched listeners (in their deterministic sorted order) before applying the CatchAllMatch fallback to the first listener's first certificate.
3. AGENTS.md hygiene in new production code (pkg/proxy/proxy.go:820-943):
- Spell out abbreviated identifiers: l -> listener (isTLSTerminatingListener, updateTLSListenersLocked, matchTLSListeners), portStr -> portString (clientHelloLocalPort), cert -> certificate and lastErr -> lastError or certificateErr (selectListenerCertificate).
- Tighten the Beyond the Gateway API specification: comment (pkg/proxy/proxy.go:921-926) to state what the specification leaves unsaid and use active voice.
(Automatic review)
justinsb
codebot-robot
Fixes #1722