Skip to content

Commit

Permalink
etcdmain: reject binding listeners to domain names
Browse files Browse the repository at this point in the history
Fixes #6336
  • Loading branch information
heyitsanthony authored and gyuho committed Sep 6, 2016
1 parent 5c44cdf commit 6e83ec0
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions etcdmain/config.go
Expand Up @@ -20,6 +20,7 @@ import (
"flag"
"fmt"
"io/ioutil"
"net"
"net/url"
"os"
"runtime"
Expand Down Expand Up @@ -410,6 +411,13 @@ func (cfg *config) configFromFile() error {
}

func (cfg *config) validateConfig(isSet func(field string) bool) error {
if err := checkBindURLs(cfg.lpurls); err != nil {
return err
}
if err := checkBindURLs(cfg.lcurls); err != nil {
return err
}

// when etcd runs in member mode user needs to set --advertise-client-urls if --listen-client-urls is set.
// TODO(yichengq): check this for joining through discovery service case
mayFallbackToProxy := isSet("discovery") && cfg.fallback.String() == fallbackFlagProxy
Expand Down Expand Up @@ -456,3 +464,22 @@ func (cfg config) isReadonlyProxy() bool { return cfg.proxy.String() == pr
func (cfg config) shouldFallbackToProxy() bool { return cfg.fallback.String() == fallbackFlagProxy }

func (cfg config) electionTicks() int { return int(cfg.ElectionMs / cfg.TickMs) }

// checkBindURLs returns an error if any URL uses a domain name.
func checkBindURLs(urls []url.URL) error {
for _, url := range urls {
if url.Scheme == "unix" || url.Scheme == "unixs" {
continue
}
host := strings.Split(url.Host, ":")[0]
if host == "localhost" {
// special case for local address
// TODO: support /etc/hosts ?
continue
}
if net.ParseIP(host) == nil {
return fmt.Errorf("expected IP in URL for binding (%s)", url.String())
}
}
return nil
}

0 comments on commit 6e83ec0

Please sign in to comment.