Skip to content

Disk Encryption (LUKS)

An encrypted host (LUKS2 volume declared in its disko configuration) protects its data in case of theft or disposal, but asks for a passphrase at every boot. DNF industrializes this point of friction with two guarantees:

  • several unlocking methods coexist at all times, so losing one method (forgotten passphrase, misplaced YubiKey) never locks you out;
  • the boot prompt is answered remotely, from the administration workstation, with no screen or keyboard attached to the host, and that from the very first boot that follows the installation.

Each method occupies its own keyslot in the LUKS2 header. All of them are valid at the same time, on every encrypted volume of the host.

MethodWhere it livesRole
Shared passphrasesops → luks-passphraseA single one for the whole fleet, it authorizes keyslot management. It is also what formats the disk
Per-host passphrasesops → luks/<hôte>/passphraseTo hand over to the machine’s user without exposing the fleet
FIDO2 YubiKeysDerived from the physical keyTouch the key at boot, nothing to type
Fenêtre de terminal
just luks <host> # provisions (or converges) encryption
just luks <host> pre # offline half, without touching the machine
just luks <host> passwd # rotates the per-host passphrase
just luks <host> show # audit: keyslot table + compliance
just luks <host> '' <ip> # targets an explicit IP (host not yet resolved)

The recipe is idempotent : each run converges and only asks for what is missing. It is called automatically at two moments, and it is rare to have to run it yourself :

Called byActionWhat it does
just install <host>preBefore the build, thus before installation
just install-here <host>pre, without a nix account (bootstrap-keys)First machine, from the ISO
just configure <host>(default)After the first boot

Without a LUKS volume in disko, it is a logged no-op.

The pre phase never touches the machine. It prepares what must exist before the system is built :

  1. the shared passphrase in sops if absent (asked only once for the whole fleet) ;
  2. the per-host passphrase in sops if absent, randomly generated and without asking anything (see the callout below) ;
  3. the initrd SSH host key, generated locally and stored in sops (luks/<host>/initrd-key, base64-encoded) ;
  4. registering the host in the public manifest usr/secrets/luks.json (versioned in the clear, it contains no secret) : it is this entry that activates the module.

The default phase adds what requires the machine :

  1. re-lays the initrd key from sops if it is missing on the target (it never regenerates a new one, that would invalidate the one placed by the installation) ;
  2. on a gateway, records its public address in the manifest (fallback of just unlock, see below). It is only a backup : the gateway reports its own address to the HCS. Behind a box, the WAN interface only carries a private IP : the public address is the one used to reach the machine, or is passed as an argument (just luks <host> '' auto <IP or DDNS name>) ;
  3. if no managed passphrase unlocks the volume (host installed before the switch to shared formatting), asks for its installation passphrase one last time and enrolls the shared one along with it.

Then commit and deploy :

Fenêtre de terminal
git add usr/secrets/luks.json
just commit "system(luks): <host>"
just apply <host>

At deployment, two idempotent services converge the LUKS header on each apply: luks-passphrase-sync (shared and per-host passphrases) and yubikey-luks-enroll (one FIDO2 entry per YubiKey enrolled on the fleet, see Strong authentication).

  • Per host: just luks <hôte> passwd, then commit and apply. The old keyslot is removed and replaced on the next deployment.
  • Shared: edit luks-passphrase via just sops, then apply across the whole fleet: each encrypted host rotates its keyslot in the process.
  • Isolated host: just luks <hôte> passwd, machine booted. Rotation happens on the spot, without apply (see Isolated encrypted host).

The synchronization service detects changes through a local ledger (/var/lib/luks-passphrase/ledger) : a modified sops value enrolls the new passphrase then kills the old slot. Slots missing from the ledger (FIDO2, manual enrollments) are never touched.

An isolated host holds no fleet secret, nor does its encryption :

ItemIsolated host
KeyslotsIts passphrase, its YubiKeys, no shared one
FormattingWith its passphrase
luks/<hôte>/*usr/secrets/hosts/<hôte>.yaml
YubiKeysAt the host’s salt, once captured
just unlockSends only its passphrase
Rotationjust luks <hôte> passwd, immediate

Without a synchronization service, passwd acts on the machine itself : new slot, sops, then removal of the old one. At every step, the value stored in sops opens the volume.

Each key there is enrolled to a salt specific to the host, authorized by its passphrase : see Isolated encrypted hosts and YubiKey, salts and isolated hosts.

A host that becomes isolated is reinstalled (just install) : its old luks/<hôte> entries remain in secrets.yaml, flagged by just luks, to be deleted with just sops.

Every encrypted host follows the same sequence, with nothing to configure:

  1. YubiKey — an enrolled and plugged-in key makes its LED blink: touching it opens the volume, nothing to type. No key plugged in, the step lasts ~6 s ; a key that nobody touches, ~30 s (firmware limit).
  2. Passphrase — a prompt is then presented, with no time limit. It accepts the per-host passphrase, the shared one or the installation one.

The prompt of step 2 is one and the same request, served in parallel on the physical console (/dev/tty1) and over ssh on port 2222. Nothing to choose, no window to miss: the first one to answer opens the volume.

Remotely, the initrd starts a dedicated sshd on port 2222, with its own persistent host key, accessible only with the deployment key nix. just unlock answers it there :

Fenêtre de terminal
just unlock <host> # passphrase read from sops, otherwise asked at the terminal

just unlock waits for port 2222 to appear (a dot per attempt), reads the shared passphrase from sops and pushes it into the initrd, then verifies that the machine has indeed left its initrd before announcing success. If it is refused, it retries with the per-host passphrase. This is what just full-install calls on its own after the first reboot. On a non-encrypted host, it is a logged no-op.

Before any sending, just unlock verifies that the initrd host key is the one stored in sops, then enforces it on each connection. Key absent from sops or different → stop, nothing is sent : an impostor could listen on 2222.

No stored passphrase accepted, or no infrastructure key on the workstation : from a terminal, just unlock presents the LUKS prompt via systemd-tty-ask-password-agent. It probes port 2222 on the explicit IP (if provided), the host name, the WAN IP reported to the HCS, then that of the manifest. In both cases, once the passphrase is accepted, the boot continues and port 22 comes back.

A gateway that reboots may come back on a different public address, awaiting its passphrase and without VPN. It therefore reports its address to the HCS, over SSH, and just unlock tries it first, before the manifest one.

MomentWho reportsFrequency
Waiting in initrddnf-wan-report (initrd)Every 15 min
System booteddnf-wan-report.timerAt boot, then every hour

On the HCS side, the dnf-wan-report account accepts only one key per gateway (its initrd key, tied to a forced command). The retained address is the one seen by sshd, stored in /var/lib/dnf-wan-report/<host>.

Bringing it into service, in this order :

  1. just luks <gateway> copies the initrd public key into usr/secrets/luks.json (nothing activates before) ;
  2. git add usr/secrets/luks.json, then just apply <hcs> ;
  3. just apply <gateway>, then just luks <gateway> show confirms the first report.

Each change of address or phase (initrd, system) is logged on the HCS : journalctl -t dnf-wan-report retraces the reboots of each gateway there.

just luks <host> show writes nothing : it queries the machine and reports. It exits with an error as soon as a check fails, so it can also be used in a script.

Fenêtre de terminal
just luks <host> show

A first block draws up the keyslot table of each volume. Nothing is assumed there : each managed passphrase is really tried against the header, so the “Check” column says what the volume accepts today, not what a registry has remembered.

/dev/disk/by-partlabel/disk-main-luks
Slot Content Source Check
---- ------------------- --------------------------- -----------------
0 Shared passphrase sops luks-passphrase opens the volume
1 Host passphrase sops luks/poste/passphrase opens the volume
2 YubiKey alice/main systemd-fido2 token enrolled
7 Unknown - not managed by DNF
Slots in use: 4/32

A second block audits remote unlocking, point by point :

CheckWhat it catches
Host present in luks.jsonThe module would stay inert
Initrd key on the target (+ fingerprint)Next apply without remote unlocking
sops backup of the same fingerprintA reinstallation would lose remote access
initrd sshd enabled in the configurationnix.pub missing, or host outside the manifest
Bootloader newer than the keyThe trap : key absent from the initrd that boots
Drivers of the wired cards present in the initrdNo network in stage 1 : nothing answers on 2222
Booted system = audited configurationA pending apply would make the audit misleading
WAN address reported to the HCS (gateways)Report missing or older than 2 h
Public address collected (gateways)Unreachable in initrd once the VPN is down
LocationContentStatus
usr/secrets/luks.jsonProvisioned hosts, WAN IP, initrd public keysPublic, versioned
secrets.yaml → luks-passphraseShared passphrase of the fleetsops encrypted
secrets.yaml → luks/<host>/passphrasePer-host passphrasesops encrypted
secrets.yaml → luks/<host>/initrd-keyinitrd SSH host key (base64)sops encrypted
secrets.yaml → luks/<host>/initrd-key-pubIts public key, pinned by just unlocksops encrypted
/var/lib/luks-initrd/ (target)Working copy of the initrd keyPersistent, outside the repo
/var/lib/luks-passphrase/ledger (target)Registry of managed keyslots (rotation detection)Persistent, outside the repo
/var/lib/dnf-wan-report/<host> (HCS)Last reported WAN addressPersistent, outside the repo

The module exposes three options: darkone.system.luks.enable (default true), darkone.system.luks.sshPort (default 2222) and darkone.system.luks.wanReport.enable (default true).

The initrd takes a DHCP lease for port 2222. Kept at boot, NetworkManager sees the interface as connected (externally): no DHCP, no DNS, resolv.conf empty. The initrd now returns its lease on a NetworkManager host: effective at the first reboot after deployment.