From 3facce6bfaf4a1472fb0a40421c80ce3acf42c0b Mon Sep 17 00:00:00 2001 From: Matt Keeler Date: Tue, 27 Mar 2018 15:00:33 -0400 Subject: [PATCH] GH-3854: Warn when node name isnt a valid DNS label --- agent/agent.go | 19 +++++++++++++++++++ agent/dns.go | 2 ++ 2 files changed, 21 insertions(+) diff --git a/agent/agent.go b/agent/agent.go index abce307c35..e65d45f514 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -269,6 +269,17 @@ func (a *Agent) Start() error { return fmt.Errorf("Failed to setup node ID: %v", err) } + // Warn if the node name is incompatible with DNS + if InvalidDnsRe.MatchString(a.config.NodeName) { + a.logger.Printf("[WARN] agent: Node name %q will not be discoverable "+ + "via DNS due to invalid characters. Valid characters include "+ + "all alpha-numerics and dashes.", a.config.NodeName) + } else if ( len(a.config.NodeName) > MaxDNSLabelLength ) { + a.logger.Printf("[WARN] agent: Node name %q will not be discoverable "+ + "via DNS due to it being too long. Valid lengths are between "+ + "1 and 63 bytes.", a.config.NodeName) + } + // create the local state a.State = local.NewState(LocalConfig(c), a.logger, a.tokens) @@ -1549,6 +1560,10 @@ func (a *Agent) AddService(service *structs.NodeService, chkTypes []*structs.Che a.logger.Printf("[WARN] agent: Service name %q will not be discoverable "+ "via DNS due to invalid characters. Valid characters include "+ "all alpha-numerics and dashes.", service.Service) + } else if ( len(service.Service) > MaxDNSLabelLength ) { + a.logger.Printf("[WARN] agent: Service name %q will not be discoverable "+ + "via DNS due to it being too long. Valid lengths are between "+ + "1 and 63 bytes.", service.Service) } // Warn if any tags are incompatible with DNS @@ -1557,6 +1572,10 @@ func (a *Agent) AddService(service *structs.NodeService, chkTypes []*structs.Che a.logger.Printf("[DEBUG] agent: Service tag %q will not be discoverable "+ "via DNS due to invalid characters. Valid characters include "+ "all alpha-numerics and dashes.", tag) + } else if ( len(tag) > MaxDNSLabelLength ) { + a.logger.Printf("[DEBUG] agent: Service tag %q will not be discoverable "+ + "via DNS due to it being too long. Valid lengths are between "+ + "1 and 63 bytes.", tag) } } diff --git a/agent/dns.go b/agent/dns.go index eb59961e63..c9ba4e8107 100644 --- a/agent/dns.go +++ b/agent/dns.go @@ -31,6 +31,8 @@ const ( staleCounterThreshold = 5 * time.Second defaultMaxUDPSize = 512 + + MaxDNSLabelLength = 63 ) var InvalidDnsRe = regexp.MustCompile(`[^A-Za-z0-9\\-]+`)