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

wireguard: add generatePrivateKeyFile option + test #60138

Merged
merged 2 commits into from Apr 24, 2019

Conversation

grahamc
Copy link
Member

@grahamc grahamc commented Apr 24, 2019

Ideally, private keys never leave the host they're generated on - like
SSH. Setting generatePrivateKeyFile to true causes the PK to be
generate automatically.

Motivation for this change
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)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@grahamc grahamc requested a review from infinisil as a code owner April 24, 2019 02:31
@grahamc
Copy link
Member Author

grahamc commented Apr 24, 2019

@GrahamcOfBorg test wireguard
@GrahamcOfBorg test wireguard-generated

@@ -282,7 +333,12 @@ in
boot.extraModulePackages = [ kernel.wireguard ];
environment.systemPackages = [ pkgs.wireguard-tools ];

systemd.services = mapAttrs' generateUnit cfg.interfaces;
systemd.services = (x: builtins.trace x x) ((mapAttrs' generateSetupServiceUnit cfg.interfaces)
Copy link
Member Author

Choose a reason for hiding this comment

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

Errant trace.

@grahamc
Copy link
Member Author

grahamc commented Apr 24, 2019

Plus some nice assertion improvements based on feedback from @infinisil!

Ideally, private keys never leave the host they're generated on - like
SSH. Setting generatePrivateKeyFile to true causes the PK to be
generate automatically.
@grahamc
Copy link
Member Author

grahamc commented Apr 24, 2019

Seems this PR is good then, @Ma27 ?

@Ma27 Ma27 merged commit 28a95c4 into NixOS:master Apr 24, 2019
@Ma27
Copy link
Member

Ma27 commented Apr 24, 2019

@grahamc thanks!

@grahamc
Copy link
Member Author

grahamc commented Apr 24, 2019

Thank you!

@grahamc grahamc deleted the wireguard-generate-key branch April 24, 2019 14:03
mkdir --mode 0644 -p "${dirOf values.privateKeyFile}"
if [ ! -f "${values.privateKeyFile}" ]; then
touch "${values.privateKeyFile}"
chmod 0600 "${values.privateKeyFile}"
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not safe.

The private key can be read by an unprivileged user who opens the file between touch and chmod.

touch + chmod 600 + write are never safe. This is why install --mode (like mkdir --mode) and umask exist. See for example the key generation section in ArchWiki or NixOS's wiki.

Copy link
Contributor

Choose a reason for hiding this comment

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

Filed as #121288.

@nh2
Copy link
Contributor

nh2 commented May 16, 2021

So basically, the .path unit in this case is a NO-OP.

@arianvp It also makes it impossible to stop the service, see #123203.

puppe added a commit to puppe/secrets that referenced this pull request Oct 1, 2021
Apparently it is not safe to first create a file with touch and then set
permissions with chmod. An unprivileged user could open the file in
between. See
NixOS/nixpkgs#60138 (comment).
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