-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Unlock encrypted root filesystem via SSH #10027
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10027 +/- ##
========================================
- Coverage 79% 79% -<1%
========================================
Files 386 386
Lines 122431 122431
========================================
- Hits 97023 96892 -131
- Misses 25408 25539 +131
Continue to review full report at Codecov.
|
Just as an idea: if the target is debian, why not use the |
Unfortunately this is not a normal login, its an SSH session, hence tty misses graphical features. Also, zfs script already uses systemd-ask-password utility for non-SSH unlock features, hence I'ce decided to reuse it to minimize changes to initramfs hooks. |
Tiny update on Dropbear detection mechanism. As per advices given, some Debian derivatives do not have /var/run folder present inside initramfs, so I've changed dropbear process detection to classic ps | grep approach. |
I feel like this over-complicates the process. You are installing the client script ( Other setups (ArchLinux's mkinitcpio hook for unlocking zfs remotely, for example) simply wait for the user to ssh in and manually unlock the rootfs. That seems easier, since it allows for any client with the appropriate key to login and unlock the filesystem. Your setup requires the client to install the zfsunlock script, since you use specially created FIFOs in order to send the data. I think a simpler solution would be to support a method of configuring the initramfs such that it confirms there is an ssh daemon running and then simply waits for a client to login and unlock any drives that it doesn't have keys for. |
This approach assumes user is prompted with password login with option to cancel it, it needed. |
You're right, I misunderstood. The It's also not robust to the situation where multiple filesystems need to be unlocked (i.e. when I think it's safe to assume that if users can understand how to install zfs on root, configure the initramfs tools, and ssh into a system running from its initramfs, then they can also learn to run the |
Thanks for the error noted, I will move /run/zfsunlockcomplete after the cycle for unlocking all the pools has been completed. As for the unlocking multiple pools, so far the script assumes only the root pool requires decryption. I'll extend the script so it will ask in cycle for several keys if there is more than one encrypted pool requiring key present. |
New commit version now can recognize and prompt for several encrypted pools password. |
in new version of the commit zfsunlock now will work even if the user cancel the prompt, go to shell and run zfsunlock again, so even if the profile has been accidentally overwritten by some package, the user can run zfsunlock manually. |
What does this mean?
Using systemd-ask-password for the actual prompting isn't necessarily a problem. But it's unclear to me if you've addressed the point about simultaneously prompting on the console and via dropbear. If this requires someone to SSH into the machine, that's bad. If the network is broken, for example, they will have a mess. |
You're right, it has to be addressed too. I'll come back with extended version of the script, covering the scenario with simultaneous prompts appearing on boot console and SSH session. |
Updated version now simultaneously prompting on the console and via dropbear. Installing dropbear-initramfs now is optional. |
I think, my point didn't come across really well, so I'll try again. The askpass utility (from Debian's
Yes that's exactly the point of this askpass utility. With the The whole askpass program seems to be much more exact and clean than writing program name substrings into files and hoping that no other process line from ps will match. Maybe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but I haven't had a chance to try it yet. looking forward to this addition!
If anyone wants to test SSH unlock using Debian 10 live image and VirtualBox you can use test install script I've made for this purpose.
|
Hi @Andrey42 are you certain your repo contains this patch #10027? I installed ubuntu 20.04 and dropbear-initramfs, but entering "zfsunlock" did nothing when I logged into dropbear. I couldn't find "zfsunlock" on the system either.[edit: @Andrey42 I've re-updated from your repo and this patch is now included. Thank you.] |
This file is listed as being in Markdown format, but it didn't really use much Markdown. I have added a fair amount of formatting. I have reordered and reworded things to improve the flow of the text. Reviewed-By: Andrey Prokopenko <[email protected]> Reviewed-By: Brian Behlendorf <[email protected]> Reviewed-By: Tom Caputi <[email protected]> Signed-off-by: Richard Laager <[email protected]> Closes #10027
This commit add a new feature for Debian-based distributions to unlock encrypted root partition over SSH. This feature is very handy on headless NAS or VPS cloud servers. To use this feature, you will need to install the dropbear-initramfs package. Reviewed-By: Brian Behlendorf <[email protected]> Reviewed-By: Tom Caputi <[email protected]> Signed-off-by: Andrey Prokopenko <[email protected]> Signed-off-by: Richard Laager <[email protected]> Closes #10027
@Andrey42 I just tried installing this on my Ubuntu 20.04 personal server. I got this error:
The error comes from this line in
It appears that busybox's ps does not have take an Any thoughts about a good way to fix this? EDIT: I ran the remaining commands manually after getting the PID myself and the rest seems to work well, which is good news. :) |
So this is interesting. On Ubuntu, if you have the
Debian, at least on Buster, does not have a @tcaputi / @Andrey42 Does this work: |
Testing right now.... |
@rlaager It looks like cut isn't working the way you'd like it...
|
awk exists (at least in my busybox). So this seems to work:
|
If you have awk, then this should work: |
I'm not sure what the point of the last |
It was supposed to replace the |
I'm not sure if that will work with normal
We might need to try to detect what kind of ps we're running. |
It's not meant to work with normal |
|
@rlaager Right. I'm just saying that if anyone (for whatever reason) has a real version of |
Thanks for noting it. Better to cover all possible angles. |
The initramfs hook scripts depend on Makefile. This way, if the substitution code is changed, they should update. This brings it in line with etc/init.d (which was modified to match the example in the automake docs). The initramfs hook script cleaning now matches etc/init.d. There was a mix of SUBDIRS recursion and custom install rules for files in subdirectories. This was duplicated for the "hooks" and "scripts" subdirectories. Now everything uses SUBDIRS. I fixed the substitution of DEFAULT_INITCONF_DIR for hooks/zfs. Reviewed-By: Andrey Prokopenko <[email protected]> Reviewed-By: Brian Behlendorf <[email protected]> Reviewed-By: Tom Caputi <[email protected]> Signed-off-by: Richard Laager <[email protected]> Closes openzfs#10027 (cherry picked from commit 4cfd339)
This file is listed as being in Markdown format, but it didn't really use much Markdown. I have added a fair amount of formatting. I have reordered and reworded things to improve the flow of the text. Reviewed-By: Andrey Prokopenko <[email protected]> Reviewed-By: Brian Behlendorf <[email protected]> Reviewed-By: Tom Caputi <[email protected]> Signed-off-by: Richard Laager <[email protected]> Closes openzfs#10027 (cherry picked from commit 746d22e)
Hi, as the documentation is still todo, could somebody give me a hint on how to use this with Debian Buster? Thanks a lot! |
The code has been merged in master repo, so you can cherrypick then add patch from this PR to the source code, then compile the ZFS package, for example latest version 0.8.5. The actual code will be part of 2.0 package or earlier as per users request.
Then on every encrypted system boot, the system will open SSH connection and wait for keys to entered via the SSH by human user or via script, by calling zfsunlock command on SSH prompt. At the same time, if you enter ZFS password into console, SSH server is quitetly shut down, and boot resumes in usual manner, i.e. entering ZFS encryption password via SSH and console can safely coexists. This solution is extremely usable in cases where you cannot trust credentials storage of your datacenter vendor (AWS, Azure, Google etc.) and need to rotate ZFS root filesystem encryption keys without any hosting vendor involvement, automatically excluding machines from the distributed pool in case the system is compromised, or there is a threat it might be. |
@terem42 I'm not sure how you'd like to receive user requests, but I would very much like to see this in a current version vs waiting for 2.0. Not as much as raidz expansion, but it's up there on my list to replace my current mdadm workflow. |
Well, I'm not using official distributions anyway. Normally I take master and apply my own set of patches and PRs. |
ZFS 2.0 is also already available in Debian 10 backports. |
The initramfs hook scripts depend on Makefile. This way, if the substitution code is changed, they should update. This brings it in line with etc/init.d (which was modified to match the example in the automake docs). The initramfs hook script cleaning now matches etc/init.d. There was a mix of SUBDIRS recursion and custom install rules for files in subdirectories. This was duplicated for the "hooks" and "scripts" subdirectories. Now everything uses SUBDIRS. I fixed the substitution of DEFAULT_INITCONF_DIR for hooks/zfs. Reviewed-By: Andrey Prokopenko <[email protected]> Reviewed-By: Brian Behlendorf <[email protected]> Reviewed-By: Tom Caputi <[email protected]> Signed-off-by: Richard Laager <[email protected]> Closes openzfs#10027
This file is listed as being in Markdown format, but it didn't really use much Markdown. I have added a fair amount of formatting. I have reordered and reworded things to improve the flow of the text. Reviewed-By: Andrey Prokopenko <[email protected]> Reviewed-By: Brian Behlendorf <[email protected]> Reviewed-By: Tom Caputi <[email protected]> Signed-off-by: Richard Laager <[email protected]> Closes openzfs#10027
This commit add a new feature for Debian-based distributions to unlock encrypted root partition over SSH. This feature is very handy on headless NAS or VPS cloud servers. To use this feature, you will need to install the dropbear-initramfs package. Reviewed-By: Brian Behlendorf <[email protected]> Reviewed-By: Tom Caputi <[email protected]> Signed-off-by: Andrey Prokopenko <[email protected]> Signed-off-by: Richard Laager <[email protected]> Closes openzfs#10027
This commit add new feature for Debian-based distributions to
unlock encrypted root partition over SSH This feature is very handy on any
headless NAS or VPS cloud servers. To use this feature, you will need to
install dropbear-initramfs package during the system setup.
Signed-off-by: Andrey Prokopenko [email protected]
Motivation and Context
Many NAS and cloud-based servers requiring encrypted root filesystem do not have displays or keyboard connected, hence the usage of encrypted partitions is limited to servers with physical access to keyboard or the usage of rather ugly and insecure schemas where key is saved along with the initramfs image, making it easily prone for breaking into. Proposed pull request removes this vulnerability for Debian based systems and makes usage of encrypted root filesystems on headless systems, requiring encryption, much more convenient.
Description
New section inside initramfs zfs setup script checks for the presense of working dropbear SSH process ( to be installed via dropbear-initramfs package) and if it's present, opens two in and out named pipes, then waits for the password input and sends the pool decryption result back.
On the login via SSH, if dropbear module is present and running, the user is presented with password prompt. Once the password is accepted, dropbear initramfs process will be killed and user is requested to reconnect via normal user credentials.
How Has This Been Tested?
The standard set of zfs-linux debian packages was built via Github Actions free tier build based on my workflow, see more details here: https://github.com/andrey42/zfs-debian/blob/master/.github/workflows/debian-packages-build.yml
Two VM with encrypted partitions were created using aforementioned packages to test booting process with and without encrypted root filesystem. Test scripts for hosting provider are available here: https://github.com/andrey42/zfs-hetzner-vm
Two complete scripts for creating barebone installation using deboostrap, experimental version of ZFS packages and dropbear-initramfs with SSH keys config on Debian 10 and Ubuntu 18.04 are located here: https://github.com/andrey42/zfs-hetzner-vm/tree/vmtest
Types of changes
Checklist:
Signed-off-by
.