Skip to content

Commit

Permalink
decrypt-root: add service to decrypt the ROOT partition
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Campion committed Mar 24, 2024
1 parent 8d5495e commit b9f3b12
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
22 changes: 22 additions & 0 deletions dracut/31decrypt-root/decrypt-root
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Check if there is a partition labeled ROOT and, if so, determine its UUID.
match=$(lsblk -o UUID,PARTLABEL | grep -w ROOT)
if [[ $? -ne 0 ]]; then
exit 0
fi
uuid="${match%% *}"

# Check if the partition labeled ROOT is a LUKS device.
IFS= read -r -n "4" header < /dev/disk/by-uuid/$uuid
if [[ "$header" != "LUKS" ]]; then
exit 0
fi

# Generate a systemd-cryptsetup unit to decrypt the root partition.
# We call the LUKS device `rootencrypted`, no matter what it was called in the Ignition configuration.
echo "rootencrypted UUID=$uuid none luks" > /tmp/crypttab
SYSTEMD_CRYPTTAB=/tmp/crypttab /usr/lib/systemd/system-generators/systemd-cryptsetup-generator /etc/systemd/system/

# Start the generated systemd service to decrypt the root partition.
systemctl start systemd-cryptsetup@rootencrypted
16 changes: 16 additions & 0 deletions dracut/31decrypt-root/decrypt-root.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Generate and execute a systemd-cryptsetup service to decrypt the ROOT partition

DefaultDependencies=no
# If systemd-networkd.service is used in the initramfs, then we should run after it, since the ROOT partition
# might use network-bound encryption.
After=systemd-networkd.service dev-disk-by\x2dpartlabel-ROOT.device
Wants=dev-disk-by\x2dpartlabel-ROOT.device
Before=dracut-initqueue.service

[Service]
Type=oneshot
ExecStart=/usr/sbin/decrypt-root

[Install]
WantedBy=ignition-subsequent.target
9 changes: 9 additions & 0 deletions dracut/31decrypt-root/module-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
install() {
inst_script "$moddir/decrypt-root" \
"/usr/sbin/decrypt-root"

inst_simple "$moddir/decrypt-root.service" \
"$systemdsystemunitdir/decrypt-root.service"

systemctl --root "$initdir" enable decrypt-root.service
}

0 comments on commit b9f3b12

Please sign in to comment.