{"record":{"id":"66fe05a1a1bdee76","repo":"hashicorp/nomad","slug":"service-name-must-be-valid-per-rfc-1123-and-can-co","errorCode":null,"errorMessage":"Service name must be valid per RFC 1123 and can contain only alphanumeric characters or dashes and must be no longer than 63 characters","messagePattern":"Service name must be valid per RFC 1123 and can contain only alphanumeric characters or dashes and must be no longer than 63 characters","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/services.go","lineNumber":954,"sourceCode":"\t\treturn fmt.Errorf(\"Service identity must provide at least one target aud value\")\n\t}\n\n\treturn nil\n}\n\n// ValidateName checks if the service Name is valid and should be called after\n// the name has been interpolated\nfunc (s *Service) ValidateName(name string) error {\n\t// Ensure the service name is valid per RFC-952 §1\n\t// (https://tools.ietf.org/html/rfc952), RFC-1123 §2.1\n\t// (https://tools.ietf.org/html/rfc1123), and RFC-2782\n\t// (https://tools.ietf.org/html/rfc2782).\n\t//  This validation is enforced on Nomad, but not on Consul, however if\n\t//  consul-template is being used, service names with dots in them wont be\n\t//  admissible.\n\tre := regexp.MustCompile(`^(?i:[a-z0-9]|[a-z0-9][a-z0-9\\-]{0,61}[a-z0-9])$`)\n\tif !re.MatchString(name) {\n\t\treturn fmt.Errorf(\"Service name must be valid per RFC 1123 and can contain only alphanumeric characters or dashes and must be no longer than 63 characters\")\n\t}\n\treturn nil\n}\n\n// LegacyAgentID is used only for generating the ID for services registered by a\n// pre-FIPS-compatible Nomad agent, so that if the agent was not shutdown\n// gracefully before upgrading, it can still deregister its old services.\n//\n// COMPAT: remove once upgrades from pre-FIPS-compatible agents are no longer\n// supported. Upgrading agents in-place to FIPS-enabled is unsupported.\nfunc (s *Service) LegacyAgentID(role string) string {\n\tif fips140.Enabled() {\n\t\treturn \"\"\n\t}\n\th := sha1.New()\n\tx := s.hashImpl(h, role, \"\", false)\n\treturn fmt.Sprintf(\"_nomad-%s-%s\", role, x)\n}","sourceCodeStart":936,"sourceCodeEnd":972,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/services.go#L936-L972","documentation":"ValidateName enforces RFC 1123 DNS-label rules on service names: only alphanumeric characters and dashes, 1-63 characters, must start and end with an alphanumeric. This is stricter than Consul to keep names compatible with consul-template (which disallows dots) and other DNS-based consumers.","triggerScenarios":"Naming a service \"my_service\" (underscore), \"MyService\" is fine per (?i) but \"my.service\", \"-web\", \"web-\", or a name longer than 63 chars.","commonSituations":"Using app names with underscores or dots in service stanzas; very long names from generated configs; copying Kubernetes-style names containing dots.","solutions":["Rename the service to use only letters, digits, and dashes (e.g. \"my-service\").","Shorten the name to at most 63 characters.","Strip leading/trailing dashes and any dots/underscores from generated names."],"exampleFix":"// before\nservice {\n  name = \"my_app.web\"\n}\n// after\nservice {\n  name = \"my-app-web\"\n}","handlingStrategy":"validation","validationCode":"var rfc1123 = regexp.MustCompile(`^(?i:[a-z0-9]|[a-z0-9][a-z0-9\\-]{0,61}[a-z0-9])$`)\nfunc validServiceName(name string) bool { return rfc1123.MatchString(name) }","typeGuard":"func isValidServiceName(name string) bool {\n  if len(name) == 0 || len(name) > 63 { return false }\n  for i, r := range name {\n    ok := (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '-'\n    if !ok || ((i == 0 || i == len(name)-1) && r == '-') { return false }\n  }\n  return true\n}","tryCatchPattern":null,"preventionTips":["Sanitize generated service names: replace dots/underscores with dashes","Truncate names to 63 chars and strip leading/trailing dashes","Test name generation with the RFC 1123 regex in unit tests"],"tags":["nomad","naming","rfc1123","validation"],"backgroundTag":"invalid-service-name","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}