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/luksroot: Add option to save passphrases. #64374

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ambrop72
Copy link
Contributor

@ambrop72 ambrop72 commented Jul 6, 2019

Motivation for this change

I needed that another LUKS device gets unlocked automatically using the same passphrase that was used to unlock the LUKS device containing the root file system. This adds an option to the initrd which if enabled will save passphrases to /run/initrd-saved-passphrases so that they can be used after the initrd to unlock other devices.

Maybe using /run/keys (which is already a thing and gets mounted automatically, but not in the initrd) would be more appropriate? Not sure where would be the right place to put the code for doing that, and if it could somehow conflict with the fstab entry.

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.

@rnhmjoj
Copy link
Contributor

rnhmjoj commented Jul 7, 2019

I thought #29441 did this already, or am I misunderstanding what this patch does?

@ambrop72
Copy link
Contributor Author

ambrop72 commented Jul 7, 2019

That one temporarily saves the passphrase and automatically tries to reuse it for the next LUKS device opened from the initrd. That allows opening multiple LUKS devices in the initrd while typing only one passphrase.

What I need is to open just one device in the initrd (where the root filesystem is), and open another device automatically during the systemd boot. That other device does not need to be opened in the initrd; configuring it to be opened in the initrd would prevent me from booting if the device does not work, would also increase the boot time a little (since it is not done in parallel).

This patch makes it possible for the initrd to save the passphrase so that it can be used later (after the initrd is done) to open another device. To do that I added a systemd service like this:

systemd.services.cryptsetup-crypt-disk = let
  name = "crypt-disk";
  device = "/dev/disk/by-uuid/xxx";
  keyFile = "/run/initrd-saved-passphrases/luks-crypt-ssd";
in {
  description = "Open LUKS volume ${name}";
  requires = [ "${utils.escapeSystemdPath device}.device" ];
  after = [ "${utils.escapeSystemdPath device}.device" ];
  # I use ZFS so this is a dependency of the service that imports the pool.
  # Otherwise it would be a dependency of mount units directly.
  before = [ "zfs-import-zfs-disk.service" ];
  requiredBy = [ "zfs-import-zfs-disk.service" ];
  unitConfig.DefaultDependencies = "no";
  serviceConfig = {
    Type = "oneshot";
    RemainAfterExit = true;
    ExecStart = "${pkgs.cryptsetup}/bin/cryptsetup luksOpen ${device} ${name} --key-file ${keyFile}";
  };
};

@cleverca22
Copy link
Contributor

another option would be to have a regular keyfile on the encrypted rootfs, and then always use that to open the 2nd luks device

@ambrop72
Copy link
Contributor Author

ambrop72 commented Jul 8, 2019

another option would be to have a regular keyfile on the encrypted rootfs, and then always use that to open the 2nd luks device

This is true but I'm not fond of keeping encryption keys on the disk and it's also manual work.

@stale
Copy link

stale bot commented Jun 1, 2020

Thank you for your contributions.
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the
    related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse. 3. Ask on the #nixos channel on
    irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 1, 2020
@LoveIsGrief
Copy link
Contributor

LoveIsGrief commented Dec 11, 2022

I know this is stale, but I find myself with a bit of time to try and work through the oldest, non-conflicting issues.

For clarity, why can't you mount this in the initrd phase? Won't putting the key in /run/initrd-saved-passphrases/ be the equivalent of putting the key on another encrypted drive that's been mounted in initrd? This turns the passphrase into a keyfile.

Is it just another way of doing things that doesn't require a benefit? / What's the benefit?

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Dec 11, 2022
@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants