hostname: normalize before validation#2976
Conversation
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
|
|
||
| newHostname := strings.ToLower(hostInfo.Hostname) | ||
| if err := util.ValidateHostname(newHostname); err != nil { | ||
| newHostname, err := util.NormaliseHostname(hostInfo.Hostname) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
- 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?
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