From c7212b438dfabb2b28b8677bd07dfd01b92dc969 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Mon, 12 Sep 2016 19:49:22 -0700 Subject: [PATCH] embed: warn on domain name in listener --- embed/config.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/embed/config.go b/embed/config.go index 94e95902c1d..31a4ce987ef 100644 --- a/embed/config.go +++ b/embed/config.go @@ -17,6 +17,7 @@ package embed import ( "fmt" "io/ioutil" + "net" "net/http" "net/url" "strings" @@ -253,6 +254,13 @@ func (cfg *configYAML) configFromFile(path string) error { } func (cfg *Config) Validate() error { + if err := checkBindURLs(cfg.LPUrls); err != nil { + return err + } + if err := checkBindURLs(cfg.LCUrls); err != nil { + return err + } + // Check if conflicting flags are passed. nSet := 0 for _, v := range []bool{cfg.Durl != "", cfg.InitialCluster != "", cfg.DNSCluster != ""} { @@ -346,3 +354,27 @@ func (cfg Config) IsDefaultHost() (string, error) { } return "", defaultHostStatus } + +// checkBindURLs returns an error if any URL uses a domain name. +// TODO: return error in 3.2.0 +func checkBindURLs(urls []url.URL) error { + for _, url := range urls { + if url.Scheme == "unix" || url.Scheme == "unixs" { + continue + } + host, _, err := net.SplitHostPort(url.Host) + if err != nil { + return err + } + if host == "localhost" { + // special case for local address + // TODO: support /etc/hosts ? + continue + } + if net.ParseIP(host) == nil { + err := fmt.Errorf("expected IP in URL for binding (%s)", url.String()) + plog.Warning(err) + } + } + return nil +}