Skip to content

Set resolveconf to localhost only when the user does not specify any …#122843

Closed
gwitmond wants to merge 3 commits intoNixOS:masterfrom
gwitmond:default-resolver
Closed

Set resolveconf to localhost only when the user does not specify any …#122843
gwitmond wants to merge 3 commits intoNixOS:masterfrom
gwitmond:default-resolver

Conversation

@gwitmond
Copy link
Copy Markdown
Contributor

…nameservers.

The problem was that when the user defines networking.nameservers and then enables services.bind
the user's name servers are ignored. This violates the principle of least surprise.

This change sets the default only when the user does not specify any name servers.

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • NixOps
    • 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.

…nameservers.

The problem was that when the user defines networking.nameservers and then enables services.bind
the user's nameservers are ignored. This violates the principle of least surprise.

This change sets the default only when the user does not specify any nameservers.
@gwitmond gwitmond requested a review from peti as a code owner May 13, 2021 15:09
@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels May 13, 2021
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels May 13, 2021
@gwitmond
Copy link
Copy Markdown
Contributor Author

Ignore this one, it's better solved at resolvconf.nix.

I'll make an update.

gwitmond added 2 commits May 13, 2021 17:44
Bug: when the user specifies `networking.nameserver` and enables
services `bind` `unbound` or `dnsmasq`, the resolver would assume
these are client resolvers and set resolvconf to 127.0.0.1. This
ignores the user specified name servers and violates the principle
of least surprise.

This change tests for explicit specified name servers before applying
the default.
@gwitmond
Copy link
Copy Markdown
Contributor Author

I think, this is the correct solution. Please review.

@aanderse aanderse requested a review from vcunat May 15, 2021 12:51
@vcunat
Copy link
Copy Markdown
Member

vcunat commented May 15, 2021

I'm not sure. In case of nameservers != [] && useLocalResolver, I might prefer to throw an error, because to me it seems unclear what was meant. As it is now, both options are exposed and can be set explicitly by the user.

@vcunat
Copy link
Copy Markdown
Member

vcunat commented May 15, 2021

In other words, assuming we keep this automagic, in cases like yours I'd expect the configuration explicitly sets useLocalResolver to false.

Your approach would make sense perhaps if we additionally made the option internal, or some such "larger" change of what's being done here.

@gwitmond
Copy link
Copy Markdown
Contributor Author

The problem I'm trying to solve is this one.

I have static configured networking, so I've set networking.nameservers to my upstream servers.

I also run a Bind named service as master for a few domains. As that thing manages the private keys for DNSSEC, I don't want it to do client resolving.

However, without my proposed patch, enabling Bind will override my explicit defined name server configuration and set 127.0.0.1. That's what I mean with principle of least surprise: an explicit configuration should not be ignored by a default setting.

As there is no documentation in either networking.nameservers, nor at bind, unbound and dnsmasq that it sets the resolver config, it is hard for a Nixos user to discover this behaviour. Only by reading the module source of Bind, I learned about the existence of useLocalResolver.

I hope this clears things up.

@vcunat
Copy link
Copy Markdown
Member

vcunat commented May 15, 2021

Aah, I didn't realize there's this common issue due to named being a dual-purpose service in principle (authoritative and not).

@gwitmond
Copy link
Copy Markdown
Contributor Author

I can add some documentation at bind, unbound and dnsmasq to tell about the useLocalResolver existence.

@gwitmond
Copy link
Copy Markdown
Contributor Author

I guess, this could be added to options.services.{bind,unbound,dnsmasq}.enable.description:

   Notice: enabling this also sets the resolver in `/etc/resolv.conf`
   to `127.0.0.1`. To specify `networking.nameservers` yourself, set
   `networking.resolvconf.useLocalResolver = false`.

Please let me know if you think that would be helpful to the user.

Personally, I think my patch does exactly that, let the default be 127.0.0.1 unless the user specifies nameservers themselves.

Cheers.

@stale
Copy link
Copy Markdown

stale bot commented Nov 16, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 16, 2021
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 5, 2023
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 19, 2024
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 8, 2024
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 10, 2024
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 1, 2025
@gwitmond gwitmond closed this by deleting the head repository Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants