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

nixos/networkmanager: remove networking.networkmanager.dynamicHosts #71337

Merged
merged 1 commit into from Oct 21, 2019

Conversation

flokli
Copy link
Contributor

@flokli flokli commented Oct 18, 2019

This option was removed because allowing (multiple) regular users to
override host entries affecting the whole system opens up a huge attack
vector. There seem to be very rare cases where this might be useful.
Consider setting system-wide host entries using networking.hosts,
provide them via the DNS server in your network, or use
networking.networkmanager.appendNameservers to point your system to
another (local) nameserver to set those entries.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • 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 nix-review --run "nix-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.
Notify maintainers

@rickynils
Copy link
Member

@flokli I commented on #71322 before seeing you opened this PR: #71322 (comment)

I like to hear a little bit more about why you think this particular option is such a security risk that it needs to be removed from nixpkgs.

I agree with you on the flaws in its implementation (possibly misusing /run/NetworkManager), but my comment linked above offers a solution for that.

But security-wise: The option is disabled by default, and a user has to explicitly enable it and make a decision on which uid should have write permissions to the hosts dirs. I don't see a big security risk here. The documentation could be clearer on the security implications of enabling the option, though.

@flokli
Copy link
Contributor Author

flokli commented Oct 18, 2019

Moved from @rickynils #71322 (comment):

@flokli The dynamicHosts config was merged to master in d80292d, no PR created.

I'm fine with removing the nm-setup-hostsdirs service and the use of /run/NetworkManager/hostsdirs, and instead adding an option for configuring which host dirs NetworkManager/dnsmasq should look at. I guess a more sensible name for the option would then be networking.networkmanager.extraHostsDirs. It would then be up to the user to configure the directories and their permissions.

@flokli
Copy link
Contributor Author

flokli commented Oct 18, 2019

I like to hear a little bit more about why you think this particular option is such a security risk that it needs to be removed from nixpkgs.

The option is disabled by default, still it's advertised in the NixOS options documentation, so people might enable it because they think "it's a good idea".

Assume there's two users for whom this was configured , and one of this users gets compromised. It's possible to do system-wide DNS redirection attacks of the whole traffic. There's a reason on why /etc/hosts is only writable by root on regular distros, and why you need to use sudo to change most system-wide things.

On top of that, it's a feature that was implemented solely inside nixpkgs. There's no upstream NM "best practices", explaining that this is the recommended way for users to change /etc/hosts records, and I'm not aware of other distros providing something similar.

@flokli
Copy link
Contributor Author

flokli commented Oct 18, 2019

I guess a more sensible name for the option would then be networking.networkmanager.extraHostsDirs. It would then be up to the user to configure the directories and their permissions.

I'd assume it's also sufficient to do something like this:

environments.etc = {
  target = "NetworkManager/dnsmasq.d/dyndns.conf";	
  text = ''
    hostsdir=/path/to/imperative-hostsdir
  '';
}

… and this is simply setting a setting documented in NetworkManager and dnsmasq.

I still consider imperatively adding entries in there as a regular user a hack, or what's the usecase?

@rickynils
Copy link
Member

My use case is for development/testing. It is a very simple way to dynamically update DNS entries to point to temporary VMs and containers.

I'm completely fine with removing it from nixpkgs, if it is not wanted there. It is simple enough for me to use a local NixOS module for this.

Maybe you should just mention the environment.etc = ... snippet in the release notes, instead of mentioning networking.networkmanager.appendNameservers, since piggy-backing the already running NM-controlled dnsmasq instance is much easier than configure an additional one.

@flokli flokli force-pushed the networkmanager-remove-dynamichosts branch 2 times, most recently from 16a3ce4 to fbe210c Compare October 18, 2019 15:37
@flokli
Copy link
Contributor Author

flokli commented Oct 18, 2019

You're right - just configuring the existing dnsmasq (if you happen to use the dnsmasq backend) is easier - I updated the PR and now point towards environment.etc. Does that look good to you now?

This might be a quick & dirty way around it, but at least for local containers this should be handled by NSS - and for anything remote I'd personally want HTTPS and a DNS record anyways.

This option was removed because allowing (multiple) regular users to
override host entries affecting the whole system opens up a huge attack
vector. There seem to be very rare cases where this might be useful.
Consider setting system-wide host entries using networking.hosts,
provide them via the DNS server in your network, or use
networking.networkmanager.appendNameservers to point your system to
another (local) nameserver to set those entries.
@flokli flokli force-pushed the networkmanager-remove-dynamichosts branch from fbe210c to ca6c91e Compare October 20, 2019 14:37
Copy link
Contributor

@worldofpeace worldofpeace left a comment

Choose a reason for hiding this comment

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

Fine with me 👍
I believe you supported your claim particularly well, the initial change could have used a PR. Changes to networkmanager in NixOS should have lots of review.

@flokli flokli merged commit f24b4fb into NixOS:master Oct 21, 2019
@flokli flokli deleted the networkmanager-remove-dynamichosts branch October 21, 2019 00:33
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

4 participants