Overly strict NAME_REGEX rejects valid hostnames

Bug #1916325 reported by Jonathan Hunter
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
curtin
Invalid
Undecided
Unassigned
curtin (Ubuntu)
Invalid
Undecided
Unassigned
subiquity (Ubuntu)
Fix Released
Undecided
Jonathan Hunter

Bug Description

All our servers' hostnames start with a location identifier, which is mostly numeric e.g. 123, 124 or sometimes 12A. A full hostname might be 12a-proxy-01.mydomain.co.uk, for example.

We are switching to Ubuntu but have hit this bug in the 20.04 curtin installer, which prevents us setting the hostname during installation. (Tested on plain 20.04 and on 20.04.02)

Our workaround has been to set a dummy hostname on installation, and then change it back once curtin has finished - but that gets messy especially as we are now looking into cloud-init and automation, where this won't work.

The NAME_REGEX quoted by curtin is "[a-z_][a-z0-9_-]*" which correctly prevents hostnames starting with a hyphen.. but it also prevents otherwise perfectly valid hostnames that start with a number. (Interestingly, an underscore is not defined as a valid hostname character, but is included as valid in the regex above)

I believe the correct NAME_REGEX would be "[a-z0-9_][a-z0-9_-]*" - i.e. adding 0-9 as valid characters at the start. (I've left the underscore character in, also)

Thanks

Jonathan

Ref:
https://man7.org/linux/man-pages/man7/hostname.7.html#:~:text=Valid%20characters%20for%20hostnames%20are,to%20an%20address%20for%20use.
       Each element of the hostname must be from 1 to 63 characters long
       and the entire hostname, including the dots, can be at most 253
       characters long. Valid characters for hostnames are ASCII(7)
       letters from a to z, the digits from 0 to 9, and the hyphen (-).
       A hostname may not start with a hyphen.

Revision history for this message
Ryan Harper (raharper) wrote :

Hi,

Thank you for filing a bug and helping make Ubuntu better. I believe the regex restriction is happening in the Ubuntu Server Live Installer (subiquity). I've added that package to this bug.

Here's the source code in question you're hitting.
https://github.com/canonical/subiquity/blob/a76581cd2b973b55e55c6ac05b5bf47168493140/subiquity/ui/views/identity.py#L110

Revision history for this message
Jonathan Hunter (jmhunter) wrote :

Thank you Ryan - much appreciated.

I have created a pull request against subiquity, it's my first one but hope it is OK :)

https://github.com/canonical/subiquity/pull/914

Changed in subiquity (Ubuntu):
assignee: nobody → Jonathan Hunter (jmhunter)
status: New → Fix Committed
Changed in curtin (Ubuntu):
status: New → Invalid
Changed in curtin:
status: New → Invalid
Changed in subiquity (Ubuntu):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.