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

Add stubby resolver daemon service module #38667

Merged
merged 9 commits into from May 16, 2018

Conversation

baroncharlus
Copy link
Contributor

@baroncharlus baroncharlus commented Apr 10, 2018

This change implements stubby, the DNS-over-TLS stub resolver daemon.
The package itself is maintained by @leenaars.

The motivation for this change was the desire to use stubby's
DNS-over-TLS functionality in tandem with unbound, which requires
passing certain configuration parameters. This module implements those
config parameters by exposing them for use in configuration.nix.

This is a reopening of PR #38586, which was based on the incorrect branch.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-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 nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

baroncharlus added 2 commits April 9, 2018 20:45
This change implements stubby, the DNS-over-TLS stub resolver daemon.
The motivation for this change was the desire to use stubby's
DNS-over-TLS funcitonality in tandem with unbound, which requires
passing certain configuration parameters. This module implements those
config parameters by exposing them for use in configuration.nix.
re-merging the module list to remove unecessary changes.
'';
};

enableNetBindService = mkOption {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

instead of trying to parse the listenAddresses, which required the very inefficient splitString, I have simply provided the option to disable this capability if the user knows they are going to bind to ports > 1024.


serviceConfig = {
AmbientCapabilities = "${optionalString cfg.enableNetBindService "CAP_NET_BIND_SERVICE"}";
CapabilitiesBoundingSet = "${optionalString cfg.enableNetBindService "CAP_NET_BIND_SERVICE"}";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this part I'm not 100% sure about and would welcome input. obviously, having AmbientCapabilities= set to nothing (instead of just being altogether absent in the false case) isn't the prettiest. however, it does seem to achieve the desired effect (for now, anyway).

Copy link
Member

@infinisil infinisil Apr 10, 2018

Choose a reason for hiding this comment

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

Eh, I think providing an option for this is a bit too much. Should be fine to just set the values by default, if the user wants to override it he can still do it with something like systemd.services.stubby.serviceConfig.AmbientCapabilities = mkForce "";. I mean it's a DNS module after all, it should be expected to be able to bind to privileged ports.

baroncharlus added 2 commits April 10, 2018 07:26
This change removes the unecessary flag for toggling the capabilities
which allows the daemon to bind to low ports.
Adding the option to turn on debug logging.
@wizeman
Copy link
Member

wizeman commented Apr 13, 2018

Shouldn't this service be ordered before nss-lookup.target, like the unbound and dnscrypt-proxy services?

@wizeman
Copy link
Member

wizeman commented Apr 13, 2018

Also, it would be useful to mention that the idleTimeout option is in ms units.

BTW, thanks for contributing this service, I am already using it successfully (with unbound as a caching layer)!

@baroncharlus
Copy link
Contributor Author

@wizeman both good points. very pleased to hear someone found it useful!

Improving docs to note that idleTimeout is expressed in ms. Adding the
nss-lookup `before' target to the systemd service definition.
fallbacks = concatMapStringsSep "\n " (x: "- ${x}") cfg.fallbackProtocols;
listeners = concatMapStringsSep "\n " (x: "- ${x}") cfg.listenAddresses;
# By default, the recursive resolvers maintained by the getdns
# project itself are enabled. More information about both getdns's servers, # as well as third party options for upstream resolvers, can be found here:
Copy link
Member

Choose a reason for hiding this comment

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

Missed a line break here


fallbackProtocols = mkOption {
default = [ "GETDNS_TRANSPORT_TLS" ];
type = types.listOf 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.

You could use types.enum [ "GETDNS_TRANSPORT_TLS" "GETDNS_TRANSPORT_TCP" "GETDNS_TRANSPORT_UDP" ] here

};

authenticationMode = mkOption {
default = "GETDNS_AUTHENTICATION_REQUIRED";
Copy link
Member

Choose a reason for hiding this comment

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

You could change this to a boolean option authenticationRequired when there's only the values required/none. But only if you're sure that other options won't be added in the future (i suspect that won't be the case).

Copy link
Member

Choose a reason for hiding this comment

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

And if you don't want to make it a boolean, it can be an enum like above instead.

@wizeman
Copy link
Member

wizeman commented Apr 20, 2018

BTW, I forgot to mention that I'm getting the following message in the systemd journal:

Apr 20 15:26:09 wizylap systemd[1]: /nix/store/dh0mk6yh4nhnmh9j3yqimvwcch5h9sp4-unit-stubby.service/stubby.service:15: Unknown lvalue 'CapabilitiesBoundingSet' in section 'Service'

@baroncharlus
Copy link
Contributor Author

@wizeman whups! You're right. that should be CapabilityBindingSet, not Capabilities. Thanks!

baroncharlus added 2 commits April 21, 2018 16:15
This change restricts fallbackProtocol and authenticationMode to accept
only valid options instead of any list or str types (respectively). This
change also fixes typo in the CapabilityBoundingSet systemd setting.
Cleaning up docs, adding literal tags to settings, and removing
whitespace.
listeners = concatMapStringsSep "\n " (x: "- ${x}") cfg.listenAddresses;

# By default, the recursive resolvers maintained by the getdns
# project itself are enabled. More information about both getdns's servers, # as well as third party options for upstream resolvers, can be found here:
Copy link
Member

@infinisil infinisil Apr 21, 2018

Choose a reason for hiding this comment

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

I meant a line break in this comment line, there's a # in the middle of it.


# By default, the recursive resolvers maintained by the getdns
# project itself are enabled. More information about both getdns's servers,
# # as well as third party options for upstream resolvers, can be found here:
Copy link
Member

@infinisil infinisil Apr 22, 2018

Choose a reason for hiding this comment

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

Now there's two # here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh dear... what are we going to do with me

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

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

Looks perfect to me now, well done! I have also tested this locally and it worked without problems.

@baroncharlus
Copy link
Contributor Author

🎉🎉! thanks for your help, @infinisil and @wizeman.

@jfrankenau
Copy link
Member

jfrankenau commented May 14, 2018

I've been running this since a few days together with systemd-resolved and it works fine. I guess you'll just have to squash the commits to have this PR merged.

@baroncharlus, have you had a look at the upstream systemd service? I wonder if we should set the working directory as well. This seems to be of interest for zero configuration DNSSEC. (See also appdata_dir in Stubby's config.)

@xeji xeji merged commit 380cdd8 into NixOS:master May 16, 2018
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

6 participants