6 ms·
Remotely unlocking an encrypted hard disk
- mmh0000 8mo agoThis has been a "need" for a long time for home users with FDE. The go-to software solution for Linux has been: https://github.com/gsauthof/dracut-sshd https://github.com/gsauthof/dracut-sshd
- hnarn 8mo agoSure, if you're using dracut, which is not true for "Linux" in general.
- benttoothpaste 8mo agoMost Linux distros are not Arch either. It would be nice to have more support for this use case in general - like something one can configure easily during the initial OS setup. I use OpenSuse so I had to use the guide for Fedora, but there were some differences as far as I remember.
- mmh0000 8mo agoDracut is used by default on: Fedora, RHEL, CentOS, Rocky, Alma, Arch, and Gentoo Dracut is available on: Debian and Ubuntu That covers most common Linux distros. - Personally, I'm using this on Fedora.
- hnarn 8mo ago”Fedora, RHEL, CentOS, Rocky, Alma” are all the same distro group: Enterprise Linux (EL). That it's ”available” on other distros is irrelevant, almost anything is ”available” as a non standard choice for any distro.
- NobodyNada 8mo agoI have a setup based on this, but I modified it to encrypt the SSH host key using the TPM. That way, I can detect a MiTM from an attacker who has stolen the drive or modified the boot policy because host key verification will fail. /usr/lib/dracut/modules.d/46cryptssh: #!/bin/bash check() { require_binaries sshd || return 1 return 0 } depends() { return 0 } install() { if [ ! -e /etc/ssh/dracut ]; then mkdir /etc/ssh/dracut && tmp=$(mktemp -d) && head -c128 /dev/random > $tmp/passphrase && ssh-keygen -t ed25519 -f /etc/ssh/dracut/ssh_host_ed25519_key -N"$(base64 < $tmp/passphrase)" && tpm2_createprimary -C o -c $tmp/primary.ctx && tpm2_pcrread -o $tmp/pcr.bin sha256:0,7 tpm2_createpolicy --policy-pcr -l sha256:0,7 -f $tmp/pcr.bin -L $tmp/pcr.policy tpm2_create -C $tmp/primary.ctx -L $tmp/pcr.policy -i $tmp/passphrase -c $tmp/seal.ctx && tpm2_evictcontrol -C o -c $tmp/seal.ctx -o /etc/ssh/dracut/seal || { rm -r $tmp /etc/ssh/dracut exit 1 } rm -r $tmp fi for file in /etc/ssh/dracut/*; do inst_simple "$file" "/etc/ssh/${file#/etc/ssh/dracut/}" done mkdir -p -m 0700 "$initdir"/root/.ssh /usr/bin/install -m 600 /etc/ssh/dracut_authorized_keys "$initdir"/root/.ssh/authorized_keys inst_binary /usr/sbin/sshd inst_binary /usr/sbin/ssh-keygen inst_binary /usr/bin/tpm2_unseal inst_binary /usr/bin/base64 inst_simple /usr/lib/libtss2-tcti-device.so inst_simple "$moddir"/cryptsshd.service "$systemdsystemunitdir"/cryptsshd.service inst_simple "$moddir"/sshd_config /etc/ssh/sshd_config inst_binary /usr/lib/ssh/sshd-session inst_binary /usr/lib/ssh/sshd-auth mkdir -p -m 0755 "$initdir"/var/empty/sshd mkdir -p -m 0755 "$initdir"/usr/share/empty.sshd mkdir -p -m 0755 "$initdir"/var/log touch "$initdir"/var/log/lastlog systemctl -q --root "$initdir" enable cryptsshd } cryptsshd.service: [Unit] Description=OpenSSH Daemon for Disk Encryption Passphrase DefaultDependencies=no Before=cryptsetup.target After=network-online.target [Service] Type=notify-reload ExecStartPre=/bin/sh -c '/usr/bin/ssh-keygen -p -f /etc/ssh/ssh_host_ed25519_key \ -N "" -P "$(/usr/bin/tpm2_unseal -c /etc/ssh/seal -p pcr:sha256:0,7 | base64)"' ExecStart=/usr/bin/sshd -D KillMode=process Restart=always [Install] WantedBy=sysinit.target That encrypts the SSH host key using a password sealed with PCR7, which is invalidated if an attacker disables Secure Boot or tampers with the enrolled keys. Thus, an attacker can't extract the key from the drive or by modifying the kernel command line to boot to a shell (since that's not allowed without disabling secure boot). It's still probably vulnerable to a cold boot attack, since the key is decrypted CPU-side. It would be interesting to perform the actual key operations on the TPM itself to prevent this.
- kotaKat 8mo agoI'm vaguely reminded of some of the third party disk encryption/preboot management utilities that exist in the Windows space that leverage similar technology. Authentication is done against an online source, and only then is the key sent back to the local machine to unlock the disk. The Bitlocker key is kept nowhere near the local TPM. I've only seen it on some paranoid-level devices in industry (typically devices handling biometric identity verification services). IIRC this one is a Linux image that boots up, unlocks the normal Bitlocker partition via whatever mechanism you need, then hands control back to the Windows bootloader to continue onwards. https://winmagic.com/en/products/full-disk-encryption-for-windows/ https://winmagic.com/en/products/full-disk-encryption-for-wi...
- ycombinatrix 8mo agoFYI your decryption key can be MITMed during this process by anyone with physical access to the system, which defeats the purpose of encrypting the disk in the first place. Just use dm-verity for remote servers.
- izacus 8mo agoSecurity isn't a binary boolean though.
- embedding-shape 8mo agoIf only everyone shared the same use case :) Maybe I have a server at home, with a locked cabinet and vibration sensors, that houses a server or two and they all use full disk encryption, but I still want to be able to reboot them without having to connect a physical keyboard to them. So no one has physical access, not even me, but I still want to be able to reboot them. Or countless of other scenarios where it could be useful to be able to remotely unlock FDE.
- jiveturkey 8mo agoThat's not a counter-argument. You are protecting the physical access, and your threat model doesn't include someone willing to bypass your locks and sensors. (or it does and you just didn't go into those details.) The argument was that physical access gives up the FDE key.
- FabCH 8mo agoPolice show up and arrest you. Could be with reason, could be by accident. Maybe you did something wrong, maybe you didn’t. They also physically size your servers, and in doing so they unplug the system. If you have disk encryption, your data now requires the police to force you to produce a password, which may or may not be within their powers, depending on the jurisdiction. It’s strictly better to have full disk encryption and remote unlocking than no disk encryption at all, because it prevents such „system was switched off by accident“ attacks.
- 8mo ago
- wildzzz 8mo agoA long time ago, I built my own crashcart adapter with a raspberry pi and a teensy to do something similar. I would sometimes get weird mdadm errors that would hang the boot process and other times, a reboot or power loss wouldn't actually cause the PC to boot back up. The teensy did USB HID emulation for keyboard inputs. I added the ability to push the power button with a fet and some resistors. I had a cheap VGA to composite adapter going into a USB composite capture device so I could at least get screenshots for any weird boot messages. I built a small webpage using flask to display the screenshot, allow for text input, control inputs, and to push the power button. It was a lot of fun building but a basement flood completely wrecked it. Server was sitting on a 6in platform but the crashcart had fallen off the top of the case and was laying on the ground. Oops.
- deleted 8mo ago[deleted]
- hrtk 8mo agoI recently ported the WiFi hook to support systemd based initramfs so you could autoconnect via your WiFi to unlock your device. Give it a go: https://aur.archlinux.org/packages/mkinitcpio-wifi https://aur.archlinux.org/packages/mkinitcpio-wifi
- readytion 8mo ago[flagged]
- idorosen 8mo agoThere is an old but still reasonable solution with mkinitcpio hooks encrypt/sd-encrypt + ssh, which is very easy to set up with EFI or grub2 onward. Tailscale is probably overkill for this use case, given that you're already exposing pre-/early- boot to the network by setting up interfaces that early. This became much more hermetic with secureboot and TPMs, too.
- kro 8mo agoTPM definitely rises the effort by a lot to break it. But by default the communication with it is not encrypted, so especially for modules not built into the cpu wire/bus-tapping is a thing. https://news.ycombinator.com/item?id=46676919 https://news.ycombinator.com/item?id=46676919
- gruez 8mo agoJust use fTPM?
- Scramblejams 8mo agoI'd love to see this in the bootloader, along with a selection of binaries useful for recovery. Might sound silly but over the years I have had many a remote system get to the bootloader and then no further after an upgrade. Nowadays we've usually got a nicely sized EFI partition, why not stuff it all in there? Gimme a full Linux userspace from the bootloader, it would feel luxurious when I'm up at 3 am trying to recover a broken system halfway across the country. Or is there already a solution to this that I've been missing? (Yeah, KVM/IPMI/etc, I know, but not all hosters make it easy to get to that.)
- michaelt 8mo agoThe solution is "don't apply untested upgrades to critical servers at 3am" :) If you must do such upgrades, solutions include hot standby hardware, IPMI, an on-site tech with a screen and keyboard, or moving everything to the cloud.
- Scramblejams 8mo agoOf course, but all those things (including upgrading during business hours) require budget. So, back to my original question...
- Jnr 8mo agoIn new installs you do stuff everything in EFI partition and skip the old /boot partition as such. The better solution is to use tpm, unified kernel image and secure boot skipping the network unlock. The whole process is like this - 1. enable secure boot; 2. generate and install your own secure boot keys (using sbctl); 3. use clevis to enable automatic unlocking of the root fs only when secure boot check passes; 4. generate the unified kernel image (in EFI partition) that is signed by your secure boot key; 4. use efibootmgr to enable booting of said kernel image. (5.) If your CPU supports it, enable memory encryption in BIOS (to mitigate cold boot attacks). The unified kernel image doesn't accept additional kernel parameters, so only parameters that are set during generation of the initram are used. The secure boot makes sure no one else has tampered with the boot chain. And TPM stores the disk key securely. You can still add some additional network level check to make sure that your computer is in your expected location before unlocking. And you can also include some recovery tools + dropbear in your initram (within the unified kernel image), if you expect that you will have to do some recovery from the other side of the world.
- teddyh 8mo agoIf you want to be able to reboot remotely, and non-interactively (i.e. while you sleep), I (and one other person) created Mandos for this purpose: <https://www.recompile.se/mandos https://www.recompile.se/mandos>. It gets the password over the network. If this seems insecure to you, read the FAQ: <https://www.recompile.se/mandos/man/intro.8mandos https://www.recompile.se/mandos/man/intro.8mandos> Mandos works with initramfs images created by both initramfs-tools and Dracut, and is present in Debian since 2011, so no need to use a third-party package.
- kro 8mo agoGood FAQ, clearly stating the weak point of physical access. For a server that threatmodel can work, for a fleet of edge/iot devices in unsecured locations without permanent uptime there is no real solution to be expected without custom silicon logic (like in smartcards) on the soc.
- akdev1l 8mo agoHow does this compare to: https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/8/html/security_hardening/configuring-automated-unlocking-of-encrypted-volumes-using-policy-based-decryption_security-hardening https://docs.redhat.com/en/documentation/red_hat_enterprise_...
- belorn 8mo ago(I am the other Mandos developer) I think FOSDEM had a talk a few years ago about that solution and their tang server. It is very similar in concept. They use McCallum-Relyea exchange, and we use PGP encryption, but the basics are the same in that you need information stored at the server and information stored in the unencrypted initramfs in order to be combined and turned into the encryption key. If my understanding of the McCallum-Relyea exchange is correct, they also combine the key creation and perfect forward security of the transaction into a single protocol, while we use TLS and client keys for the perfect forward security aspect and PGP for data at rest. With tang you need to verify the hash of the tang server in order to prevent a MITM threat from extracting the server side part during the key creation process, while with Mandos you configure it manually with configuration files. Tang uses REST and JSON. Mandos sends a single protocol number and then sends the data. Both operate primarily through local LAN, through Mandos client also support as an option to use global reachable ip addresses. Outside of those design differences, there are some packaging aspects. Tang was designed for Redhat/Dracut, while Mandos was designed for Debian and initramfs-tools (Today Mandos also support Dracut, but it is not packaged for Redhat). Redhat packaging has been requested multiple times for Mandos, but neither of us two developer are Redhat users. To add some historical context, I recall a Debconf BoF by the developers of initramfs-tools about if they were going to continue developing initramfs-tools or giving up and port everything to Dracut, and the silence was fairly deafening. People did not want to give up on initramfs-tools, but everyone recognized the massive duplication that those two project are. Similarly, the reason why Redhat had chosen initially to develop Dracut rather than just port initramfs-tools is also fairly big mystery, and is generally considered a Not Invented Here syndrome. Today there are however some distinct difference in design between the two systems.
- Calzifer 8mo ago> Because initramfs is just a (mostly) normal Linux system, that means it has its own init PID 1. On Arch, that PID is in fact just systemd. Debian has (or had; at least my Devuan still has) a simple shell script as first init. Was an interesting read and helped me understand were to add my remote rootfs decryption. https://salsa.debian.org/kernel-team/initramfs-tools/-/blob/debian/latest/init https://salsa.debian.org/kernel-team/initramfs-tools/-/blob/...
- Foxboron 8mo ago`mkinitcpio` supports both. The `base` hook installs the shell PID 1, the `systemd` hook installs systemd as PID1. The default hook setup was changed with the latest'ish release to default too the `systemd` hook setup. Shell `init`; https://gitlab.archlinux.org/archlinux/mkinitcpio/mkinitcpio/-/blob/master/init?ref_type=heads https://gitlab.archlinux.org/archlinux/mkinitcpio/mkinitcpio...
- epistasis 8mo agoGlad to see another example of this! Remote unlocking of your personal server's encrypted hard drive is PITA. Other options that I've investigated that involve having a second server: * A second server with Tang, and Clevis in the initramfs OS * Keylime Putting tailscale in the initramfs, and then updating the certs on a frequent enough schedule, seems risky to me. I've already played around with limine enough that I know I don't want to install much in the initramfs...
- SchemaLoad 8mo agoTPM is probably the best solution here. The key can be automatically fetched on reboot unless the boot order is changed or the drive is put in another computer. Realistically for a home server what you are worried about is someone breaking in and selling your drives on Facebook marketplace rather than the FBI raiding your nextcloud server. So TPM automated unlock is perfectly sufficient.
- bogwog 8mo ago> Realistically for a home server what you are worried about is someone breaking in and selling your drives on Facebook marketplace If someone steals the entire machine, the drives will unlock themselves automatically. I don't think it's worth the risk to assume a hypothetical thief is too lazy to check if there's any valuable data on the disks. At the very least, they'll probably check for crypto wallets. With something like Clevis and Tang, you can set it up so it only auto unlocks while connected to your home network, or do something more complex as needed
- SchemaLoad 8mo agoThey will unlock in to a password protected system. Unless the junkie who stole your server has an unpatched debian login bug, this won't be much use to them. If they remove the drive or attempt to boot off a USB, the drive is unreadable.
- danparsonson 8mo ago
- convivialdingo 8mo agoMan, that's pretty excellent! I once built a demo-ish encrypted network boot system using similar initrd techniques. It's a fun hack working in the preboot environment.
- XorNot 8mo agoI currently have dropbear-ssh presenting the LUKS password prompt on my home server, but that has the very annoying quality that there's no way to do it from the console if you set that up too. It's not a huge problem but it certainly means some recovery scenarios would be painful.
- fc417fc802 8mo agoSeems like you should be able to launch the LUKS password prompt multiple times on different interfaces.
- bitbasher 8mo agoNot sure how relevant it is, but I use dropbear to remote unlock over ssh: https://www.cyberciti.biz/security/how-to-unlock-luks-using-dropbear-ssh-keys-remotely-in-linux/ https://www.cyberciti.biz/security/how-to-unlock-luks-using-...
- WorldPeas 8mo agoback before tailscale got good, I used to use tor to remote-unlock on my nixos tower. It worked quite well! https://nixos.wiki/wiki/Remote_disk_unlocking https://nixos.wiki/wiki/Remote_disk_unlocking
- abound 8mo agoI have a very similar setup to the author, but instead of running Tailscale in my initramfs, I have a Raspberry Pi sitting next to the home server (which is on my Tailscale network) and I use it like a bastion host. Process is something like: 1. SSH into the Pi 2. Issue the Wake-on-LAN packet to boot the server 3. Tunnel that server's SSH port to my laptop 4. SSH into the initramfs SSH server (I use TinySSH), enter the decryption key 5. Wait for server to come up, then access via Tailscale This is more complicated than the author's setup in that it requires another device (the Pi), but it's simpler in that you don't need to have the initramfs on your Tailnet.
- tocitadel 8mo ago[dead]
- hnarn 8mo agoIt's not only more complicated, it also does not sound to me like it would scale. What do you do when you have N servers? Do you buy N raspis, or do you keep using one bastion host? How do you automate it when you sooner or later must (re-)deploy? If you set this up once ("this" meaning adding networking, SSH and tailscale inside initramfs), you can just do the same thing for the next server you set up, and you don't have to worry about the failure of one node affecting the other(s).
- abound 8mo agoThe approach I've outlined scales fine to N servers, it just doesn't work if they're on different networks. But scaling also isn't really a parameter I (or the author) are optimizing for: we have a single beefy server we do all our work on, and a thin laptop client we want to access the server from, remotely and booting an encrypted root partition. I don't necessarily understand the deployment question. If it's about the Raspberry Pi, I just do my updates when I don't need to use it to boot the server.
- jcul 8mo agoI have something similar set up to unlock the drives on my home server. Just the SSH in initramfs though, tailscale is pretty cool. I've done stuff with mkinitcpio / initramfs on arch before, can't remember exactly what for. I still run arch on my main laptop. I'm running nixos on my home server though, and adding something like this is so easy by comparison.
- varispeed 8mo agoAnd me was thinking about having a monitor, camera pointed at monitor and robot arm that I could type password in controlling it remotely.
- teddyh 8mo agoAn equivalent, but simpler, solution would be to use a network-based KVM, like PiKVM. You connect a USB connector to the PiKVM so it can simulate a keyboard (and mouse), an HDMI connector so it can show you what’s on the server screen, and you also connect a special cable to the server motherboard power and reset pins, so the PiKVM can “press” those buttons remotely as well.
- emmelaich 8mo agoYou don't need a robot arm, just mimic a usb keyboard. https://pikvm.org/ https://pikvm.org/ and similar exist. This is maybe not as good as the article solution, because it requires you to secure the pi too.
- fennec-posix 8mo agoAside from enrolling a token with the TPM to unlock the LUKS volume, this is actually a pretty novel idea. Perfect for older hardware without TPM. I guess it depends on your use-case.
- nembal 8mo agois it just me, or feels scary that it is happening
- ApexGrab 8mo agoIt doesn't work if you use RAID 5 OR RAID 6 My friend have tried it
- 8fingerlouie 8mo agoMacOS recently solved this "issue". When rebooting a FileVault encrypted machine, where it normally "hangs" asking for a user to unlock it, you can now SSH into the machine, but instead of getting a prompt it interprets your SSH login as a user logging in, hangs up, and proceeds to booting up.
- embedding-shape 8mo agoHuuuh, is this true? Where is the Apple docs for this? Recently tried to setup a headless macos machine and all my searching led me to either having to do autologin or disabling FileVaukt fully.
- bertman 8mo agohttps://news.ycombinator.com/item?id=45294440 https://news.ycombinator.com/item?id=45294440
- mistersquid 8mo agoThe good news: macOS can unlock FDE over SSH. The bad news: `The capability to unlock the data volume over SSH appeared in macOS 26 Tahoe.`
- nozzlegear 8mo agoThe "bad news" about Tahoe is largely overblown unless you hang out in the control center (or whatever they call that notification area) all day, which is the only place you'll actually notice Liquid Glass on a Mac.
- krasikra 8mo ago[dead]
- Alan_Writer 8mo agoCan you also decrypt a PGP-encrypted hard disk now? I mean, nowadays...?
- fuckinpuppers 8mo agoThis was always a concern of mine, nowadays I deploy cheaper KVM over IP devices. Way cheaper than PiKVMs now: https://www.gl-inet.com/products/gl-rm1/ https://www.gl-inet.com/products/gl-rm1/