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 <gyuhox@gmail.com>
This commit is contained in:
Gyu-Ho Lee 2017-04-04 09:38:30 -07:00
parent d6efc0b22b
commit 8a7a548a6d

View File

@ -27,7 +27,6 @@ import (
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"time" "time"
"github.com/coreos/etcd/pkg/tlsutil" "github.com/coreos/etcd/pkg/tlsutil"
@ -118,10 +117,11 @@ func SelfCert(dirpath string, hosts []string) (info TLSInfo, err error) {
} }
for _, host := range hosts { 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) tmpl.IPAddresses = append(tmpl.IPAddresses, ip)
} else { } else {
tmpl.DNSNames = append(tmpl.DNSNames, strings.Split(host, ":")[0]) tmpl.DNSNames = append(tmpl.DNSNames, h)
} }
} }