Hardening URL Construction and IPv6 Support#1198
Conversation
erain
left a comment
There was a problem hiding this comment.
This fixes raw IPv6 literals, but it regresses the bracketed IPv6 form that users would have needed as the existing workaround, for example --kubelet-host=[2001:db8::1]. Passing that value to net.JoinHostPort double-brackets the host, producing an invalid URL. Since this flag is user-provided and the old implementation accepted bracketed IPv6, the hardening should normalize that input before joining.
Please strip one surrounding IPv6 bracket pair before calling net.JoinHostPort or add a small host-normalization helper used by both clients. Add tests for bracketed IPv6 hosts in both monitor/controller and monitor/kubelet so this does not regress again.
PROMPT for coding agent: Fix PR #1198 by adding shared host normalization for NewClient URL construction. It should accept raw IPv6, already-bracketed IPv6, IPv4, and hostnames, then call net.JoinHostPort with the normalized host. Update controller and kubelet client tests to cover bracketed IPv6 in addition to the existing raw IPv6 cases.
…for IPv6 - Implement NormalizeHost to strip brackets from IPv6 addresses. - Use NormalizeHost in controller and kubelet clients. - Add unit tests for normalization and regression tests for clients. #gkepathfinder PROD_RISK=low
…for IPv6 - Implement NormalizeHost to strip brackets from IPv6 addresses. - Use NormalizeHost in controller and kubelet clients. - Add unit tests for normalization and regression tests for clients.
594ea24 to
a911912
Compare
erain
left a comment
There was a problem hiding this comment.
Re-reviewed the updated URL construction change. NormalizeHost now handles already-bracketed IPv6 before net.JoinHostPort, and the controller/kubelet tests cover raw and bracketed IPv6 cases. Ran go test ./monitor/controller ./monitor/kubelet ./monitor/util from kubelet-to-gcm on the PR head. Looks good.
a911912 to
5a0f739
Compare
7b7e7a6 to
2cef1d1
Compare
Hardens URL construction for Kubelet and Controller manager metrics endpoints by replacing string interpolation with
net.JoinHostPort. This ensures correct handling of IPv6 addresses (bracketing) and improves overall robustness.Changes:
net.JoinHostPortfor robust/metricsendpoint construction.net.JoinHostPortfor robust/stats/summaryendpoint construction.NewClient(v4, v6, hostname).NewClient(HTTP/S, v4/v6).Testing: