From 8abe794178e23829f5d7f32dd994d5e3f59f7bce Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Wed, 2 Sep 2020 22:01:13 -0400 Subject: [PATCH] Use net.JoinHostPort to avoid IPV6 issues --- internal/ingress/controller/nginx.go | 3 ++- internal/ingress/controller/tcp.go | 3 ++- test/e2e/framework/framework.go | 3 ++- test/e2e/security/request_smuggling.go | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/ingress/controller/nginx.go b/internal/ingress/controller/nginx.go index 89a2853de..c4941f2d1 100644 --- a/internal/ingress/controller/nginx.go +++ b/internal/ingress/controller/nginx.go @@ -927,7 +927,8 @@ func updateStreamConfiguration(TCPEndpoints []ingress.L4Service, UDPEndpoints [] return err } - conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%v", nginx.StreamPort)) + hostPort := net.JoinHostPort("127.0.0.1", fmt.Sprintf("%v", nginx.StreamPort)) + conn, err := net.Dial("tcp", hostPort) if err != nil { return err } diff --git a/internal/ingress/controller/tcp.go b/internal/ingress/controller/tcp.go index da257dda7..76ae3431e 100644 --- a/internal/ingress/controller/tcp.go +++ b/internal/ingress/controller/tcp.go @@ -79,7 +79,8 @@ func (p *TCPProxy) Handle(conn net.Conn) { return } - clientConn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", proxy.IP, proxy.Port)) + hostPort := net.JoinHostPort(proxy.IP, fmt.Sprintf("%v", proxy.Port)) + clientConn, err := net.Dial("tcp", hostPort) if err != nil { return } diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 5dd590ed3..d53aa6897 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -485,7 +485,8 @@ func (f *Framework) WaitForNginxListening(port int) { podIP := f.GetNginxIP() err = wait.Poll(500*time.Millisecond, DefaultTimeout, func() (bool, error) { - conn, err := net.Dial("tcp", fmt.Sprintf("%v:%v", podIP, port)) + hostPort := net.JoinHostPort(podIP, fmt.Sprintf("%v", port)) + conn, err := net.Dial("tcp", hostPort) if err != nil { return false, nil } diff --git a/test/e2e/security/request_smuggling.go b/test/e2e/security/request_smuggling.go index a6188f77f..94ee53c64 100644 --- a/test/e2e/security/request_smuggling.go +++ b/test/e2e/security/request_smuggling.go @@ -68,7 +68,8 @@ server { }) func smugglingRequest(host, addr string, port int) (string, error) { - conn, err := net.Dial("tcp", fmt.Sprintf("%v:%v", addr, port)) + hostPort := net.JoinHostPort(addr, fmt.Sprintf("%v", port)) + conn, err := net.Dial("tcp", hostPort) if err != nil { return "", err }