Skip to content

Commit

Permalink
Merge pull request #3990 from hashicorp/b-gh-3854
Browse files Browse the repository at this point in the history
Warn when node name isnt a valid DNS label
  • Loading branch information
mkeeler authored Mar 29, 2018
2 parents 3086b3b + ebc6f41 commit ea6767d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
19 changes: 19 additions & 0 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -1555,6 +1566,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
Expand All @@ -1563,6 +1578,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)
}
}

Expand Down
2 changes: 2 additions & 0 deletions agent/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const (
staleCounterThreshold = 5 * time.Second

defaultMaxUDPSize = 512

MaxDNSLabelLength = 63
)

var InvalidDnsRe = regexp.MustCompile(`[^A-Za-z0-9\\-]+`)
Expand Down
14 changes: 7 additions & 7 deletions agent/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3079,14 +3079,14 @@ func checkDNSService(t *testing.T, generateNumNodes int, aRecordLimit int, qType
func TestDNS_ServiceLookup_ARecordLimits(t *testing.T) {
t.Parallel()
tests := []struct {
name string
aRecordLimit int
expectedAResults int
name string
aRecordLimit int
expectedAResults int
expectedAAAAResults int
expectedSRVResults int
numNodesTotal int
udpSize uint16
udpAnswerLimit int
expectedSRVResults int
numNodesTotal int
udpSize uint16
udpAnswerLimit int
}{
// UDP + EDNS
{"udp-edns-1", 1, 1, 1, 30, 30, 8192, 3},
Expand Down
3 changes: 2 additions & 1 deletion agent/http_oss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var extraTestEndpoints = map[string][]string{
}

// These endpoints are ignored in unit testing for response codes
var ignoredEndpoints = []string{"/v1/status/peers","/v1/agent/monitor", "/v1/agent/reload" }
var ignoredEndpoints = []string{"/v1/status/peers", "/v1/agent/monitor", "/v1/agent/reload"}

// These have custom logic
var customEndpoints = []string{"/v1/query", "/v1/query/"}

Expand Down

0 comments on commit ea6767d

Please sign in to comment.