Skip to content

hostname: normalize before validation#2976

Closed
griffer wants to merge 1 commit into
juanfont:mainfrom
griffer:fix/hostname-normalization
Closed

hostname: normalize before validation#2976
griffer wants to merge 1 commit into
juanfont:mainfrom
griffer:fix/hostname-normalization

Conversation

@griffer
Copy link
Copy Markdown

@griffer griffer commented Dec 19, 2025

Apply NormaliseHostname() before ValidateHostname() in ApplyHostnameFromHostInfo() and EnsureHostname() to sanitize hostnames with minor invalid characters instead of replacing them with generic identifiers like "invalid-abc123".

This allows hostnames like "My-PC!" to become "my-pc" rather than being rejected.

Fixes #2926

  • have read the CONTRIBUTING.md file
  • raised a GitHub issue or discussed it on the projects chat beforehand
  • added unit tests
  • added integration tests
  • updated documentation if needed
  • updated CHANGELOG.md

Apply NormaliseHostname() before ValidateHostname() in ApplyHostnameFromHostInfo()
and EnsureHostname() to sanitize hostnames with minor invalid characters instead
of replacing them with generic identifiers like "invalid-abc123".

This allows hostnames like "My-PC!" to become "my-pc" rather than being rejected.

Fixes juanfont#2926
Comment thread hscontrol/types/node.go

newHostname := strings.ToLower(hostInfo.Hostname)
if err := util.ValidateHostname(newHostname); err != nil {
newHostname, err := util.NormaliseHostname(hostInfo.Hostname)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not oppose to relaxing this again, but I will be a lot more conservative.
The reason we made it very strict is to untangle the problems we had with invalid names sneaking in, and then also getting in all over the system without one place to control.

When we open up, we need to do :

  • Update/make a Normalise function that aligns with Tailscale SaaS behaviour
  • Make sure that the "chain" of normalising, validating and checking for collision is done in the correct order, aligning with upstream behaviour.

This means that we need to do the exercise of testing these variants against the SaaS control plane to get this right. We often get into the trap on patching things over and over and still getting different behaviour, which ultimately causes support burden.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kradalby Thanks for the explanation, it's very much appreciated. As i wrote in my initial bug report, i was not sure if this was a bug or by design. I thought there probably were a more complex reason why things were done like they are.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Update/make a Normalise function that aligns with Tailscale SaaS behaviour

Tailscale does not publish its server side normalization rules, so what would be the preferred way to achieve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Normalization of hostnames

3 participants