Skip to content

Commit

Permalink
Moved dracut directory up to top-level to decouple it with systemd.
Browse files Browse the repository at this point in the history
Adds a clevis-luks-generic-unlocker for alternative use without systemd.

Based on patch by Sergio Correia <[email protected]>

Closes: #346

Signed-off-by: Jonathan Davies <[email protected]>
  • Loading branch information
jpds committed Nov 5, 2021
1 parent c6fc63f commit d304771
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 7 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src/dracut/clevis/clevis-hook.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

@libexecdir@/clevis-luks-generic-unlocker -l
70 changes: 70 additions & 0 deletions src/dracut/clevis/clevis-luks-generic-unlocker
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash
set -eu
# vim: set ts=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
#
# Copyright (c) 2020 Red Hat, Inc.
# Author: Sergio Correia <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

. clevis-luks-common-functions

# Make sure to exit cleanly if SIGTERM is received.
trap 'echo "Exiting due to SIGTERM" && exit 0' TERM

loop=
while getopts ":l" o; do
case "${o}" in
l) loop=true;;
*) ;;
esac
done

to_unlock() {
local _devices='' _d _uuid
for _d in $(lsblk -o PATH,FSTYPE,RM \
| awk '$2 == "crypto_LUKS" && $3 == "0" { print $1 }' | sort -u);
do
if ! bindings="$(clevis luks list -d "${_d}" 2>/dev/null)" \
|| [ -z "${bindings}" ]; then
continue
fi
_uuid="$(cryptsetup luksUUID "${_d}")"
if clevis_is_luks_device_by_uuid_open "${_uuid}"; then
continue
fi
_devices="$(printf '%s\n%s' "${_devices}" "${_d}")"
done
echo "${_devices}" | sed -e 's/^\n$//'
}

while true; do
for d in $(to_unlock); do
uuid="$(cryptsetup luksUUID "${d}")"
if ! clevis luks unlock -d "${d}"; then
echo "Unable to unlock ${d} (UUID=${uuid})" >&2
continue
fi
echo "Unlocked ${d} (UUID=${uuid}) successfully" >&2
done

[ "${loop}" != true ] && break
# Checking for pending devices to be unlocked.
if remaining=$(to_unlock) && [ -z "${remaining}" ]; then
break;
fi

sleep 0.5
done
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ if dracut.found()
install_dir: dracutdir,
configuration: data,
)
install_data('clevis-luks-generic-unlocker', install_dir: libexecdir)
else
warning('Will not install dracut module due to missing dependencies!')
endif
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,36 @@
#

depends() {
echo crypt systemd
local __depends=crypt
if dracut_module_included "systemd"; then
__depends=$(printf '%s systemd' "${_depends}")
fi
echo "${__depends}"
return 255
}

install() {
if dracut_module_included "systemd"; then
inst_multiple \
$systemdsystemunitdir/clevis-luks-askpass.service \
$systemdsystemunitdir/clevis-luks-askpass.path
$systemdsystemunitdir/clevis-luks-askpass.path \
@SYSTEMD_REPLY_PASS@ \
@libexecdir@/clevis-luks-askpass
systemctl -q --root "$initdir" add-wants cryptsetup.target clevis-luks-askpass.path
else
inst_hook initqueue/online 60 "$moddir/clevis-hook.sh"
inst_hook initqueue/settled 60 "$moddir/clevis-hook.sh"

inst_multiple \
@libexecdir@/clevis-luks-generic-unlocker \
clevis-luks-unlock \
lsblk \
sort \
awk
fi

inst_multiple \
/etc/services \
@SYSTEMD_REPLY_PASS@ \
@libexecdir@/clevis-luks-askpass \
clevis-luks-common-functions \
grep sed cut \
clevis-decrypt \
Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions src/luks/systemd/dracut/clevis/clevis-hook.sh.in

This file was deleted.

1 change: 0 additions & 1 deletion src/luks/systemd/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ sd_reply_pass = find_program(

if systemd.found() and sd_reply_pass.found()
data.set('SYSTEMD_REPLY_PASS', sd_reply_pass.path())
subdir('dracut')

unitdir = systemd.get_pkgconfig_variable('systemdsystemunitdir')

Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
subdir('bash')
subdir('luks')
subdir('pins')
subdir('dracut')
subdir('initramfs-tools')

bins += join_paths(meson.current_source_dir(), 'clevis-decrypt')
Expand Down

0 comments on commit d304771

Please sign in to comment.