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/knot: add keyFiles option #79266

Merged
merged 3 commits into from Feb 15, 2020
Merged

nixos/knot: add keyFiles option #79266

merged 3 commits into from Feb 15, 2020

Conversation

Mic92
Copy link
Member

@Mic92 Mic92 commented Feb 5, 2020

Add an option to include configuration not in the nix store.
The use case for this are nixops like tools where the configuration
is not world-readable. Because of knot's DynamicUser we need to
install those files with the correct permission on startup into /var/lib/knot.

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
    • 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.

@Mic92
Copy link
Member Author

Mic92 commented Feb 5, 2020

Because of DynamicUser the permission management is not yet very straight forward:

services.knot = {
  enable = true;
  checkConfig = false;
  extraConfig = ''
    include: /var/lib/knot/knot-he-key.conf
  '';
};
systemd.services.knot = {
  serviceConfig.PermissionsStartOnly = true;
  preStart = ''
    install -m700 --owner $USER /var/src/secrets/knot-he-key.conf /var/lib/knot/knot-he-key.conf
  '';
};

Maybe rather than checkConfig I could also add an option to add custom secret files?

Copy link
Member

@mweinelt mweinelt left a comment

Choose a reason for hiding this comment

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

I understand your use case and the change is fine with me.

@vcunat
Copy link
Member

vcunat commented Feb 5, 2020

I haven't really thought about best practices for managing these secrets (for knot service).

@Mic92
Copy link
Member Author

Mic92 commented Feb 5, 2020

I though about adding an systemd.services.knot.keyFiles = [ "/path/to/tsig.conf" ];.
Those would be copied to /var/lib/knot/keys.d and than included in knot's default configuration.

@vcunat
Copy link
Member

vcunat commented Feb 5, 2020

I wonder if the risk of omitting the quotation marks is too high (leaking secrets by accident) 🤔

EDIT: I expect such mistakes can be detected in eval-time by some type-checking.

@Mic92
Copy link
Member Author

Mic92 commented Feb 5, 2020

I wonder if the risk of omitting the quotation marks is too high thinking

Usually when using nixops is using something like /run/keys, which is likely to fail on the developer machine. In theory all passwordFile options in nixos could be accidentally miss-used like that. However I see a fix for that outside of scope of this PR. This would be solved by a linter or custom nixos type option that check if the path is in the nix store.

@symphorien
Copy link
Member

About passwordFile like options: #78640

@Mic92
Copy link
Member Author

Mic92 commented Feb 8, 2020

With the latest commit knot now can do automatic DNSSEC signing.

@ofborg ofborg bot requested a review from vcunat February 8, 2020 08:34
@Mic92 Mic92 changed the title nixos/knot: make configuration check optional nixos/knot: add keyFiles option Feb 8, 2020
@@ -5,14 +5,16 @@ with lib;
let
cfg = config.services.knot;

configFile = pkgs.writeText "knot.conf" cfg.extraConfig;
socketFile = "/run/knot/knot.sock";
configFile = pkgs.writeTextFile {
Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to convert nix attrsets to yaml using remarshal. However the yaml subset chosen by knot is too restrictive for that (i.e. expect keys to appear in a certain order).

Copy link
Member

Choose a reason for hiding this comment

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

Have you seen this thread? If a few people tries this out in practice, I suppose we could make it available as another optional attribute.

Copy link
Member

@vcunat vcunat Feb 8, 2020

Choose a reason for hiding this comment

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

I'm not aware of keys being expected in particular order, though (perhaps I misunderstand). In any case the yaml is stricter than what I see usually (and new yaml is even a super-set of json IIRC).

Copy link
Member Author

Choose a reason for hiding this comment

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

I had an issue with an acl rule where the id key was not the first key, which lead to an error. This broke already in the nixos test. Anyway this PR should not interfere with migrating to a different contribute type...

Copy link
Member

Choose a reason for hiding this comment

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

Oh, that's a known restriction, though not by me until now.

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 I have an idea how to approach this; hopefully I can get it to work soon. I'll link from here when that happens.

Copy link
Member

Choose a reason for hiding this comment

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

It didn't really go the way I imagined, but let's continue on #81460

@Mic92
Copy link
Member Author

Mic92 commented Feb 8, 2020

Instead of adding an option to disable configuration checks I added a keyFiles option that implicitly disable configuration checks when used. This also gets permissions right in combination with knot's DynamicUser option.

@Mic92
Copy link
Member Author

Mic92 commented Feb 8, 2020

Here is a real-world example: https://github.com/Mic92/dotfiles/blob/34a97d3292b833fbad8f716f9c37a28eb4121eb1/nixos/eve/modules/knot/default.nix

Also the nixos test covers the new feature as well.

@Mic92 Mic92 mentioned this pull request Feb 12, 2020
10 tasks
Otherwise knot tries to write to non-writable directories.
This for example breaks dnssec signing.
While it's possible to overwrite these path in the configuration,
having a sane defaults is nicer.
This makes it hard to include secret files.
Also using tools like keymgr becomes harder.
This useful to include tsig keys using nixops without adding those
world-readable to the nix store.
@Mic92
Copy link
Member Author

Mic92 commented Feb 12, 2020

I dropped DynamicUser. Also because of #79928

@Mic92
Copy link
Member Author

Mic92 commented Feb 13, 2020

@ju1m If you would have a short look at it and give me a thumbs up, I would go forward and merge it!

@Mic92 Mic92 merged commit 466c1df into NixOS:master Feb 15, 2020
@Mic92 Mic92 deleted the knot branch February 15, 2020 11:15
dtzWill pushed a commit to dtzWill/nixpkgs that referenced this pull request Feb 15, 2020
nixos/knot: add keyFiles option

(cherry picked from commit 466c1df)
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