Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial revert of #76542's strict hostname checks #94022

Closed
wants to merge 3 commits into from

Conversation

grahamc
Copy link
Member

@grahamc grahamc commented Jul 27, 2020

Motivation for this change

See #94011 for context, but in general this check is a bit too strict.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Some networks depend on the hostname being a FQDN, and migrating is
not a trivial task. See the tracking issue in NixOS#94011, and the PR
containing the reverted commit: NixOS#76542

This reverts commit 993baa5.
@grahamc grahamc requested a review from tfc as a code owner July 27, 2020 18:32
@@ -216,7 +216,7 @@ def __init__(self, args: Dict[str, Any]) -> None:
if cmd:
match = re.search("run-(.+)-vm$", cmd)
if match:
self.name = match.group(1)
self.name = match.group(1).replace(".", "_")
Copy link
Member Author

Choose a reason for hiding this comment

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

This file is named after the hostname, but later on this Python code uses the machine.name value as a Python variable name.

Copy link
Member

Choose a reason for hiding this comment

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

I guess the problem doesn't just apply to .'s but all kinds of allowed characters? e.g. -?

Copy link
Member Author

Choose a reason for hiding this comment

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

True, though I wasn't sure just how far I should go. I could add - too. Should I do more?

Copy link
Member

@andir andir left a comment

Choose a reason for hiding this comment

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

IMHO this looks fine. I'd like to hear from @zimbatm (and other involved) parties what their thought on this is. As I outlined in the related issue I kinda gave up on the split of what a hostname is long ago for various reasons.

Copy link
Member

@primeos primeos left a comment

Choose a reason for hiding this comment

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

Before we merge this we also need to update the release notes in nixos/doc/manual/release-notes/rl-2009.xml.

Other than that I'm fine if we don't enforce the recommendations / best practices anymore (enforcing a recommended syntax was always critical and for that reason I guess I'd actually even prefer only documenting the recommendation in the option instead of enforcing it - but personally I'm fine with it either way and I'd prefer the current implementation if it where only enforced by Linux/systemd).

# reasons (as undocumented feature):
type = types.strMatching
"^$|^[[:alpha:]]([[:alnum:]_-]{0,61}[[:alnum:]])?$";
type = types.str;
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be best if we'd still limit the maximum length to 63 characters as that is actually a strict limit.

contain the domain part. This means that the hostname must start with a
letter, end with a letter or digit, and have as interior characters only
letters, digits, and hyphen. The maximum length is 63 characters.
Additionally it is recommended to only use lower-case characters.
Copy link
Member

Choose a reason for hiding this comment

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

I would still keep that part or a similar version as a recommendation (or at least refer to hostname(5)).

Copy link
Member

@vcunat vcunat left a comment

Choose a reason for hiding this comment

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

I don't really have an opinion on this. If it's not rare to break the previous strict check in practice, this PR's approach sounds right.

Docs in Linux and POSIX don't seem clear, with man hostname.5 just "recommending" it to be a single label. I agree with this PR still "enforcing" that

fqdn = hostName + (optionalString (domain != null) ".${domain}");

Copy link
Contributor

@flokli flokli left a comment

Choose a reason for hiding this comment

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

I still think most of the logic on why simply using the FQDN as hostname from systemd/systemd#15894 (comment) applies to us as well. Doing this is a bad idea, and works in some usecases "mostly by accident".

IMHO we should follow that logic, and keep the NixOS module code simple. Previously, we had some error-prone "if hostname is a fqdn, do this, else do that" logic in multiple places (and hadn't it in some others).
I was also guilty of using the FQDN as hostname, and it broke in other places (and required quirky workarounds).

Generally, I think people who still need to stick with the old behaviour, and can't switch, can maintain a revert of that functionality in a fork, as suggested by @primeos in #94011.

If that really is not an option, and for some reasons these "large corporate users" need some time to switch, I wouldn't object too much about adding a "footgun" with a heavy warning sign for one release to opt-out from the assertion failure (and without any additional logic inside the rest of the module system).

People should really fix their broken setups, instead of nixpkgs carrying workarounds.

@blitz
Copy link
Contributor

blitz commented Jul 28, 2020

I agree with @flokli. Having a warning for an extended period seems like a good middle ground between breaking users and having subtly b0rken setups.

@andir
Copy link
Member

andir commented Jul 28, 2020 via email

@flokli
Copy link
Contributor

flokli commented Jul 29, 2020

Avahi for example fails to run with an error message if config.networking.hostName is a FQDN (and services.avahi.hostName and services.avahi.domainName need to be set to prevent this).

In general, supporting both things increases complexity, having the FQDN is discouraged, and I don't see much reason to just revert this.

@arianvp
Copy link
Member

arianvp commented Jul 29, 2020

Another place where this might be a problem is in nixos-rebuild --flake

nixos-rebuild will use /proc/sys/kernel/hostname as the default flake attribute name; but that might be formatted as an FQDN .

However since recently nix-instantiate silently ignores attributes with dots in their name NixOS/nix#3798 (comment) this will lead to issues

@aanderse
Copy link
Member

Depending on the outcome of this conversation nixops may need to be updated:

    deployment.targetHost = mkDefault config.networking.hostName;

This default value should be updated to include the domain now as well.

@arianvp
Copy link
Member

arianvp commented Aug 15, 2020

This breaks at least digitalocean and Packet.net too by the way; which include . in hostnames by default

@primeos primeos added this to To Do in 20.09 Blockers via automation Aug 15, 2020
@primeos primeos added this to the 20.09 milestone Aug 15, 2020
@flokli
Copy link
Contributor

flokli commented Aug 16, 2020

@arianvp can you elaborate how this breaks these machines? If we're just talking about hostnames being sent over DHCP, that should still work (hostnamectl set-hostname --transient foo.bar.baz)

@flokli
Copy link
Contributor

flokli commented Aug 17, 2020

Also note the packet hostnames are only suggested, and probably are not intended to be used as FQDNs anyways: fra2-x1.small.x86-01. I doubt small.x86-01 is meant as the domain part.

@primeos
Copy link
Member

primeos commented Sep 5, 2020

I'll go ahead and close this as we also have #94011 which seems more appropriate for the current discussion. We can of course re-open this PR if necessary.

@primeos primeos closed this Sep 5, 2020
20.09 Blockers automation moved this from To Do to Done Sep 5, 2020
@primeos primeos removed this from Done in 20.09 Blockers Sep 5, 2020
@primeos primeos removed this from the 20.09 milestone Sep 5, 2020
primeos added a commit to primeos/nixpkgs that referenced this pull request Oct 10, 2020
Since NixOS#76542 this workaround is required to use a FQDN as hostname. See
NixOS#94011 and NixOS#94022 for the related discussion. Due to some
potential/unresolved issues (legacy software, backward compatibility,
etc.) we're documenting this workaround [0].

[0]: NixOS#94011 (comment)
jonringer pushed a commit that referenced this pull request Oct 10, 2020
Since #76542 this workaround is required to use a FQDN as hostname. See
#94011 and #94022 for the related discussion. Due to some
potential/unresolved issues (legacy software, backward compatibility,
etc.) we're documenting this workaround [0].

[0]: #94011 (comment)
jonringer pushed a commit to jonringer/nixpkgs that referenced this pull request Oct 10, 2020
Since NixOS#76542 this workaround is required to use a FQDN as hostname. See
NixOS#94011 and NixOS#94022 for the related discussion. Due to some
potential/unresolved issues (legacy software, backward compatibility,
etc.) we're documenting this workaround [0].

[0]: NixOS#94011 (comment)

(cherry picked from commit 4a600af)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants