Unattended reboots with encrypted disks

本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。

Unattended reboots with encrypted disks

Do you run a small home server or NAS holding your precious photos and sensitive documents? If so, I suppose the drives are encrypted, right? But then… can you reboot the machine without manually entering a passphrase before being able to access your files again?

你是否运行着一台小型家用服务器或 NAS 来存储珍贵的照片和敏感文档?如果是的话,我想你的硬盘应该是加密的,对吧?但问题是……你能在不手动输入密码的情况下重启机器并再次访问文件吗?

If you answered yes to the questions above—which is common for convenience—that implies the encryption keys live in the machine which… kinda defeats the purpose of disk encryption, doesn’t it? A thief can break into your house, lift the whole box (they are small these days, huh), plug it in elsewhere, and gain free rein over your files.

如果你对上述问题的回答是肯定的(为了方便起见,这很常见),那就意味着加密密钥存储在机器内部,这……在某种程度上违背了磁盘加密的初衷,不是吗?小偷可以闯入你的房子,把整个盒子搬走(现在的设备都很小,对吧),插到别处,然后随意访问你的文件。

So, which one is it? Simplicity and reliability by allowing automatic reboots or data protection by keeping the key in your head? With ZKeys—a little new project I’m launching today—you can have your cake and eat it too.

那么,你选哪一个呢?是通过允许自动重启来获得简单性和可靠性,还是通过将密钥记在脑子里来保护数据?有了 ZKeys——我今天推出的一个小型新项目——你就可以鱼与熊掌兼得。

A blog on operating systems, programming languages, testing, build systems, my own software projects and even personal productivity. Specifics include FreeBSD, Linux, Rust, Bazel and EndBASIC.

这是一个关于操作系统、编程语言、测试、构建系统、我个人软件项目甚至个人生产力的博客。具体内容包括 FreeBSD、Linux、Rust、Bazel 和 EndBASIC。

Subscribe 0 subscribers TL;DR ZKeys is a managed service that stores encryption passphrases off-site. Client machines fetch the encryption keys from the service and keep those keys alive (unlocked) via periodic keepalive messages.

订阅 0 位订阅者。简而言之:ZKeys 是一项在异地存储加密密码的托管服务。客户端机器从该服务获取加密密钥,并通过周期性的保活消息保持这些密钥处于激活(解锁)状态。

If the server stops receiving those messages for a long period of time (e.g. because it has been unplugged as part of theft), access to the key is automatically locked. You get automatic, passwordless reboots while keeping your data protected against real incidents.

如果服务器长时间停止接收这些消息(例如因为它被拔掉电源并被盗),对密钥的访问将自动锁定。你既能实现自动、无需密码的重启,又能确保数据在发生实际安全事件时得到保护。

Storytime About a year ago, I was reinstalling my FreeBSD home server to act as my NAS after a short stint with a Synology box. During that process, I decided to enable encryption for the ZFS data pool. But as I did that, I faced the question: how do I allow the machine to automatically serve my data after a reboot? I could put the key in a local file, which FreeBSD supports via the keylocation ZFS option, but that would render disk encryption pretty much useless.

故事时间:大约一年前,在短暂使用过群晖设备后,我重新安装了 FreeBSD 家用服务器作为 NAS。在此过程中,我决定为 ZFS 数据池启用加密。但当我这样做时,我面临一个问题:如何让机器在重启后自动提供数据服务?我可以把密钥放在本地文件中(FreeBSD 通过 ZFS 的 keylocation 选项支持这一点),但这会让磁盘加密变得毫无意义。

So I had an idea: what if I put the key on a different machine away from my house? I could then make the NAS fetch the key to mount the drives. And if someone stole the server, I could wipe the remote key and make the data unreadable before they could plug it back in. I did post this to Twitter and there was some interest in the idea:

于是我产生了一个想法:如果我把密钥放在家里以外的另一台机器上会怎样?我可以让 NAS 获取密钥来挂载驱动器。如果有人偷了服务器,我可以在他们重新接通电源之前擦除远程密钥,使数据无法读取。我把这个想法发到了 Twitter 上,并引起了一些关注:

Silly or smart? I wrote a startup rc.d script to automatically mount my encrypted ZFS pool by fetching the key from a remote server. What I want to protect against is the “drives stolen from home” case. If that happened, I could quickly remove the key. https://t.co/eZle2nJlXW— Julio Merino (@jmmv) September 7, 2025

愚蠢还是聪明?我写了一个启动 rc.d 脚本,通过从远程服务器获取密钥来自动挂载我的加密 ZFS 池。我想防范的是“硬盘在家中被盗”的情况。如果发生了这种情况,我可以迅速移除密钥。https://t.co/eZle2nJlXW— Julio Merino (@jmmv) 2025年9月7日

But… did you notice the problem with what I said above? Wiping the key by hand after noticing something is wrong is problematic because the gap between those two events may be large. What if I’m on a long vacation and I have no means of noticing that the machine has been stolen? Game over.

但是……你注意到我上面所说的问题了吗?在发现异常后手动擦除密钥是有问题的,因为这两个事件之间的时间间隔可能很长。如果我正在长假中,无法察觉机器被盗了怎么办?那就彻底完了。

So I refined the idea: what if I had a service that stored the key remotely and required the consuming machine to send it frequent pings to keep the key unlocked? This way, if the machine were stolen, it’d likely be offline for more than a few minutes and the service could automatically determine that something is wrong and lock the key from future accesses. And that’s precisely what ZKeys does.

所以我改进了这个想法:如果我有一个服务,它在远程存储密钥,并要求消费机器频繁发送心跳包来保持密钥解锁状态,会怎样?这样一来,如果机器被盗,它很可能会离线超过几分钟,服务就能自动判断出异常并锁定密钥,防止后续访问。这正是 ZKeys 所做的事情。

Zero-knowledge protection Before getting into details, it’s important to get something out of the way early on: ZKeys is designed so that a compromise of the server is insufficient to retrieve or reconstruct your keys. This is done in two ways:

零知识保护:在进入细节之前,有一点必须先说明:ZKeys 的设计使得即使服务器被攻破,也无法检索或重构你的密钥。这是通过两种方式实现的:

Split keys: The ZKeys server only stores half of the passphrase used to unlock a volume. The other half remains on the client machine. The zkeys client program combines both halves to produce the whole passphrase.

密钥拆分:ZKeys 服务器仅存储用于解锁卷的密码的一半。另一半保留在客户端机器上。zkeys 客户端程序将两半合并以生成完整的密码。

Encryption at rest: The keys are encrypted at rest with a password that the zkeys client must supply for retrieval and which is securely transmitted over HTTPS. The password only lives in the server’s memory for a brief period of time.

静态加密:密钥在存储时使用密码进行加密,zkeys 客户端必须提供该密码才能进行检索,且该密码通过 HTTPS 安全传输。该密码仅在服务器内存中短暂存在。

The tradeoff is, simply, that you MUST back up the full encryption keys in a third location of your own (a paper in a safe, a password manager, you name it). If ZKeys goes down or you lose your remote key password, there is absolutely nothing I can do to help you. You have been warned. The setup instructions later on will instruct you how to back the key up.

简单的代价是,你必须在自己的第三个位置备份完整的加密密钥(保险箱里的纸条、密码管理器,随你选)。如果 ZKeys 宕机或者你丢失了远程密钥密码,我将无能为力。我已经提醒过你了。稍后的设置说明将指导你如何备份密钥。

Installation and setup The ZKeys service is available at https://zkeys.jmmv.dev/ and the open-source client—along with system integrations for FreeBSD and Fedora—is in my jmmv/zkeys repository.

安装与设置:ZKeys 服务位于 https://zkeys.jmmv.dev/,开源客户端以及针对 FreeBSD 和 Fedora 的系统集成位于我的 jmmv/zkeys 仓库中。

Disclaimer: ZKeys is offered to you for free. I make no promises about its reliability, availability, or anything else. I am giving you access because I expect that supporting a handful of extra users won’t be a big issue. But if support becomes a burden, or if load becomes unmanageable, I’ll have to re-evaluate my choices here. Which means that, for now, you have to use the limited LAUNCH50 code to get started!

免责声明:ZKeys 免费提供给你。我不对其可靠性、可用性或其他任何方面做出承诺。我向你开放访问权限是因为我预计支持少量额外用户不会成为大问题。但如果支持成为负担,或者负载变得无法管理,我将不得不重新评估我的选择。这意味着,目前你必须使用限量的 LAUNCH50 代码才能开始使用!

The basic idea to set ZKeys up is the following: Install the zkeys client CLI tool. Create a service account. Create a new key (or onboard an existing key). Configure the keep-alive service on the target machine. Change or add the filesystem encryption key to be the one stored in ZKeys. Configure the auto-mount service on the target machine. Reboot!

设置 ZKeys 的基本思路如下:安装 zkeys 客户端命令行工具。创建一个服务账户。创建一个新密钥(或导入现有密钥)。在目标机器上配置保活服务。将文件系统加密密钥更改或添加为存储在 ZKeys 中的密钥。在目标机器上配置自动挂载服务。重启!

That’s all it takes, but the steps are quite manual at the moment because no upstream OSes provide packages. The service documentation covers several scenarios in detail for FreeBSD and Fedora, so I’m not going to repeat them here. Demo of the integration between ZKeys and Fedora 44 with a fully encrypted root volume: the video starts by showing a fully unattended boot, followed by a manual lock of a key that causes Fedora to refuse to reboot on its own, and finishes with another automatic reboot after the key has been unlocked again.

这就是全部步骤,但目前这些步骤相当手动,因为没有上游操作系统提供软件包。服务文档详细介绍了 FreeBSD 和 Fedora 的几种场景,所以我在这里不再赘述。关于 ZKeys 与 Fedora 44(全加密根卷)集成的演示:视频开始展示了完全无人值守的启动,随后手动锁定密钥导致 Fedora 拒绝自动重启,最后在密钥再次解锁后展示了另一次自动重启。

Behind the scenes Now for the nerdy details, because that’s what you’re here for: The CLI is Rust, of course, but it has to come with a bunch of s

幕后花絮:现在进入极客细节,因为这正是你想要的:命令行工具当然是用 Rust 编写的,但它必须附带一堆 s