From 78ede26c93cf95a6785d5329e3b90e802e7de91f Mon Sep 17 00:00:00 2001 From: divesh Date: Tue, 17 Nov 2026 15:40:23 -0800 Subject: [PATCH] fix(server): bracket IPv6 pod IPs in the gateway peer endpoint The chart renders OPENSHELL_PEER_ENDPOINT from an unbracketed pod IP, which is not a valid URI on IPv6 clusters. Closes #5673 Signed-off-by: divesh --- crates/openshell-server/src/lib.rs | 39 ++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/crates/openshell-server/src/lib.rs b/crates/openshell-server/src/lib.rs index 4f591f004f..3ce36b14bb 100644 --- a/crates/openshell-server/src/lib.rs +++ b/crates/openshell-server/src/lib.rs @@ -703,7 +703,7 @@ fn derive_peer_endpoint(config: &Config) -> Option { if let Ok(endpoint) = std::env::var("OPENSHELL_PEER_ENDPOINT") && !endpoint.trim().is_empty() { - return Some(endpoint.trim().to_string()); + return Some(bracket_ipv6_host(endpoint.trim())); } let pod_name = std::env::var("OPENSHELL_POD_NAME").ok()?; @@ -727,6 +727,22 @@ fn derive_peer_endpoint(config: &Config) -> Option { )) } +/// The chart renders `$(OPENSHELL_POD_IP)` into the endpoint without brackets. +fn bracket_ipv6_host(endpoint: &str) -> String { + let Some((scheme, rest)) = endpoint.split_once("://") else { + return endpoint.to_string(); + }; + let (authority, path) = rest.split_at(rest.find('/').unwrap_or(rest.len())); + match authority.rsplit_once(':') { + Some((host, port)) + if host.parse::().is_ok() && port.parse::().is_ok() => + { + format!("{scheme}://[{host}]:{port}{path}") + } + _ => endpoint.to_string(), + } +} + /// Reject a plaintext peer endpoint on a gateway that serves TLS. /// /// Peer relay traffic carries whole supervisor sessions between replicas. The @@ -2616,7 +2632,7 @@ mod tests { BoundGatewayListener, ConfiguredComputeDriver, ConnectionProtocol, ExtensionKind, MetricsTlsHandshakeLogLimiter, MetricsTlsHandshakeLogLimiters, MultiplexService, ServerState, TlsAcceptor, allow_plaintext_service_http, bind_gateway_listener, - classify_initial_bytes, configured_compute_driver, extension_token_ttl, + bracket_ipv6_host, classify_initial_bytes, configured_compute_driver, extension_token_ttl, is_benign_tls_handshake_failure, log_metrics_tls_handshake_rejection, log_metrics_tls_handshake_timeout, metrics_tls_acceptor_or_disable, mint_gateway_extension_credential, serve_gateway_listener, serve_tls_metrics_listener, @@ -2730,6 +2746,25 @@ mod tests { (cert_path, key_path) } + #[test] + fn peer_endpoint_brackets_only_unbracketed_ipv6_hosts() { + for (input, expected) in [ + ( + "http://fd00:10:244::16:8080", + "http://[fd00:10:244::16]:8080", + ), + ("https://[fd00::5]:8080", "https://[fd00::5]:8080"), + ("https://10.0.0.1:8080", "https://10.0.0.1:8080"), + ( + "https://gw-1.peers.ns.svc:8080", + "https://gw-1.peers.ns.svc:8080", + ), + ] { + assert_eq!(bracket_ipv6_host(input), expected); + assert!(expected.parse::().is_ok()); + } + } + #[test] fn plaintext_peer_endpoint_is_rejected_on_a_tls_gateway() { let error = validate_peer_endpoint_scheme(&tls_enabled_config(), "http://10.0.0.1:8080")