juanfont/headscale · error
leading 0 not permitted in protocol number
Error message
leading 0 not permitted in protocol number
What it means
Returned by Protocol.validate (hscontrol/policy/v2/types.go:1770) when a numeric "proto" value starts with a zero — including the bare string "0" — mirroring Tailscale's strict parsing. Leading-zero forms like "006" or "017" are rejected even though they'd be numerically valid, to keep canonical representation.
Source
Thrown at hscontrol/policy/v2/types.go:132
ErrHostResolve = errors.New("error resolving host")
ErrInvalidPrefix = errors.New("invalid prefix")
ErrInvalidAutogroup = errors.New("invalid autogroup")
ErrUnknownAutogroup = errors.New("unknown autogroup")
ErrHostportMissingColon = errors.New("hostport must contain a colon")
ErrTypeNotSupported = errors.New("type not supported")
ErrInvalidAlias = errors.New("invalid alias format")
ErrInvalidAutoApprover = errors.New("invalid auto approver format")
ErrInvalidOwner = errors.New("invalid owner format")
ErrGroupNotDefined = errors.New("group not defined in policy")
ErrInvalidGroupMember = errors.New("invalid group member type")
ErrGroupValueNotArray = errors.New("group value must be an array of users")
ErrInvalidHostIP = errors.New("hostname contains invalid IP address")
ErrTagNotDefined = errors.New("tag not found")
ErrAutoApproverNotAlias = errors.New("auto approver is not an alias")
ErrInvalidACLAction = errors.New("invalid ACL action")
ErrInvalidSSHAction = errors.New("invalid SSH action")
ErrInvalidProtocolNumber = errors.New("invalid protocol number")
ErrProtocolLeadingZero = errors.New("leading 0 not permitted in protocol number")
ErrProtocolOutOfRange = errors.New("protocol number out of range (0-255)")
ErrAutogroupNotSupported = errors.New("autogroup not supported in headscale")
ErrAutogroupInternetSrc = errors.New("autogroup:internet can only be used in ACL destinations")
ErrAutogroupSelfSrc = errors.New("\"autogroup:self\" not valid on the src side of a rule")
ErrAutogroupNotSupportedACLSrc = errors.New("autogroup not supported for ACL sources")
ErrAutogroupNotSupportedACLDst = errors.New("autogroup not supported for ACL destinations")
ErrAutogroupDangerAllDst = errors.New("cannot use autogroup:danger-all as a dst")
ErrAutogroupNotSupportedSSHSrc = errors.New("autogroup not supported for SSH sources")
ErrAutogroupNotSupportedSSHDst = errors.New("autogroup not supported for SSH destinations")
ErrHostNotDefined = errors.New("host not defined in policy")
ErrSSHSourceAliasNotSupported = errors.New("alias not supported for SSH source")
ErrSSHDestAliasNotSupported = errors.New("alias not supported for SSH destination")
ErrUnknownField = errors.New("unknown field")
ErrProtocolNoSpecificPorts = errors.New("protocol does not support specific ports")
ErrTestEmptyAssertions = errors.New("test entry must have at least one of \"accept\" or \"deny\"")
ErrTestProtocolNotAllowed = errors.New("test protocol must be tcp, udp, sctp, or empty")
ErrTestDestinationMultiPort = errors.New("test destination port must be a single port")
ErrTestDestinationCIDR = errors.New("test destination must be a single host, not a CIDR range")View on GitHub (pinned to 565fd254d0)
Solutions
- Strip leading zeros: "06" → "6", "017" → "17"
- Prefer the protocol name (tcp, udp, ...) where one exists
- For protocol 0, omit "proto" from the rule instead of writing "0"
Example fix
// before
{"action": "accept", "proto": "017", "src": ["*"], "dst": ["tag:dns:53"]}
// after
{"action": "accept", "proto": "udp", "src": ["*"], "dst": ["tag:dns:53"]} Defensive patterns
Strategy: validation
Validate before calling
func canonicalProto(s string) bool {
if len(s) > 1 && s[0] == '0' {
return false // leading zero
}
return s != "0"
} Type guard
func isProtocolLeadingZero(err error) bool {
return errors.Is(err, policy.ErrProtocolLeadingZero)
} Try / catch
if err := json.Unmarshal(b, &acl); err != nil {
if errors.Is(err, policy.ErrProtocolLeadingZero) {
return fmt.Errorf("strip leading zeros from proto (and never write \"0\"; omit proto instead): %w", err)
}
return err
} Prevention
- Never zero-pad protocol numbers in generated policies
- For protocol 0 / all protocols, omit the proto field entirely
- Prefer names (tcp, udp) over numbers to sidestep formatting rules
When it happens
Trigger: Policy with "proto": "006", "proto": "017", or "proto": "0". Note that the bare "0" also triggers this even though 0 is in the valid numeric range; there is no way to write protocol 0 numerically.
Common situations: Zero-padding protocol numbers for alignment, copying fixed-width tables, or scripts generating policies with %03d formatting.
Related errors
- invalid protocol number
- protocol number out of range (0-255)
- protocol does not support specific ports
- proto name "*" not known; use protocol number 0-255 or proto
- test(s) failed
AI-assisted analysis of juanfont/headscale@565fd254d0 (2026-08-15).
Data as JSON: /api/errors/a5c0bdb067c48d14.
Report an issue: GitHub.