From 8a7a548a6d0a6fc73b9b09cf3a5916da03026cab Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Tue, 4 Apr 2017 09:38:30 -0700 Subject: [PATCH] pkg/transport: remove port in Certificate.IPAddresses etcd passes 'url.URL.Host' to 'SelfCert' which contains client, peer port. 'net.ParseIP("127.0.0.1:2379")' returns 'nil', and the client on this self-cert will see errors of '127.0.0.1 because it doesn't contain any IP SANs' Signed-off-by: Gyu-Ho Lee --- pkg/transport/listener.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/transport/listener.go b/pkg/transport/listener.go index e760ffb1f..88c8923b8 100644 --- a/pkg/transport/listener.go +++ b/pkg/transport/listener.go @@ -27,7 +27,6 @@ import ( "net" "os" "path/filepath" - "strings" "time" "github.com/coreos/etcd/pkg/tlsutil" @@ -118,10 +117,11 @@ func SelfCert(dirpath string, hosts []string) (info TLSInfo, err error) { } for _, host := range hosts { - if ip := net.ParseIP(host); ip != nil { + h, _, _ := net.SplitHostPort(host) + if ip := net.ParseIP(h); ip != nil { tmpl.IPAddresses = append(tmpl.IPAddresses, ip) } else { - tmpl.DNSNames = append(tmpl.DNSNames, strings.Split(host, ":")[0]) + tmpl.DNSNames = append(tmpl.DNSNames, h) } }