Enforce maximum length on proxy hostname derivation

This commit is contained in:
Adam Harrison committed 2015-07-02 14:29:34 +01:00
1 parent 3bd5ae56f0
commit 3914c4c018
1 file changed
+9 -2
+9 -2
View File
@@ -13,6 +13,8 @@ import (
"github.com/weaveworks/weave/nameserver"
)
const MaxDockerHostname = 64
type createContainerInterceptor struct{ proxy *Proxy }
type createContainerRequestBody struct {
@@ -110,9 +112,14 @@ func (i *createContainerInterceptor) setWeaveDNS(container *createContainerReque
name := r.URL.Query().Get("name")
if container.Hostname == "" && name != "" {
container.Hostname = name
// Strip trailing period because it's unusual to see it used on the end of a host name
container.Domainname = strings.TrimSuffix(dnsDomain, ".")
trimmedDNSDomain := strings.TrimSuffix(dnsDomain, ".")
if len(name)+1+len(trimmedDNSDomain) > MaxDockerHostname {
Warning.Printf("Container name [%s] too long to be used as hostname", name)
} else {
container.Hostname = name
container.Domainname = trimmedDNSDomain
}
}
if len(container.HostConfig.DNSSearch) == 0 {