From 2e842ec6a3ff7a286d2ef168100dad3ebae21f1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Thu, 17 Aug 2023 15:05:00 +0200 Subject: [PATCH] fix: server name without port to generated certificate (#8053) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles-Edouard Brétéché --- pkg/tls/keypair.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pkg/tls/keypair.go b/pkg/tls/keypair.go index 7fa4c64951bb..c499ff12f8d5 100644 --- a/pkg/tls/keypair.go +++ b/pkg/tls/keypair.go @@ -60,21 +60,19 @@ func generateTLS(server string, caCert *x509.Certificate, caKey *rsa.PrivateKey, } var ips []net.IP if server != "" { - serverHost := "" - if strings.Contains(server, ":") { - host, _, err := net.SplitHostPort(server) + serverHost := server + if strings.Contains(serverHost, ":") { + host, _, err := net.SplitHostPort(serverHost) if err != nil { - logger.Error(err, "failed to split server host/port", "server", server) + logger.Error(err, "failed to split server host/port", "server", serverHost) } serverHost = host } - if serverHost != "" { - ip := net.ParseIP(serverHost) - if ip == nil || ip.IsUnspecified() { - dnsNames = append(dnsNames, serverHost) - } else { - ips = append(ips, ip) - } + ip := net.ParseIP(serverHost) + if ip == nil || ip.IsUnspecified() { + dnsNames = append(dnsNames, serverHost) + } else { + ips = append(ips, ip) } } templ := &x509.Certificate{