Skip to content

Commit a5aa695

Browse files
committed
Moved dracut directory up to top-level to decouple it with systemd.
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]>
1 parent c6fc63f commit a5aa695

File tree

14 files changed

+90
-7
lines changed

14 files changed

+90
-7
lines changed

src/dracut/clevis/clevis-hook.sh.in

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
@libexecdir@/clevis-luks-generic-unlocker -l
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
set -eu
3+
# vim: set ts=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
4+
#
5+
# Copyright (c) 2020-2021 Red Hat, Inc.
6+
# Author: Sergio Correia <[email protected]>
7+
#
8+
# This program is free software: you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation, either version 3 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
#
21+
22+
. clevis-luks-common-functions
23+
24+
# Make sure to exit cleanly if SIGTERM is received.
25+
trap 'echo "Exiting due to SIGTERM" && exit 0' TERM
26+
27+
loop=
28+
while getopts ":l" o; do
29+
case "${o}" in
30+
l) loop=true;;
31+
*) ;;
32+
esac
33+
done
34+
35+
to_unlock() {
36+
local _devices='' _d _uuid
37+
for _d in $(lsblk -o PATH,FSTYPE,RM \
38+
| awk '$2 == "crypto_LUKS" && $3 == "0" { print $1 }' | sort -u);
39+
do
40+
if ! bindings="$(clevis luks list -d "${_d}" 2>/dev/null)" \
41+
|| [ -z "${bindings}" ]; then
42+
continue
43+
fi
44+
_uuid="$(cryptsetup luksUUID "${_d}")"
45+
if clevis_is_luks_device_by_uuid_open "${_uuid}"; then
46+
continue
47+
fi
48+
_devices="$(printf '%s\n%s' "${_devices}" "${_d}")"
49+
done
50+
echo "${_devices}" | sed -e 's/^\n$//'
51+
}
52+
53+
while true; do
54+
for d in $(to_unlock); do
55+
uuid="$(cryptsetup luksUUID "${d}")"
56+
if ! clevis luks unlock -d "${d}"; then
57+
echo "Unable to unlock ${d} (UUID=${uuid})" >&2
58+
continue
59+
fi
60+
echo "Unlocked ${d} (UUID=${uuid}) successfully" >&2
61+
done
62+
63+
[ "${loop}" != true ] && break
64+
# Checking for pending devices to be unlocked.
65+
if remaining=$(to_unlock) && [ -z "${remaining}" ]; then
66+
break;
67+
fi
68+
69+
sleep 0.5
70+
done

src/luks/systemd/dracut/clevis/meson.build src/dracut/clevis/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ if dracut.found()
1616
install_dir: dracutdir,
1717
configuration: data,
1818
)
19+
install_data('clevis-luks-generic-unlocker', install_dir: libexecdir)
1920
else
2021
warning('Will not install dracut module due to missing dependencies!')
2122
endif

src/luks/systemd/dracut/clevis/module-setup.sh.in src/dracut/clevis/module-setup.sh.in

+15-4
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,36 @@
1919
#
2020

2121
depends() {
22-
echo crypt systemd
22+
local __depends=crypt
23+
if dracut_module_included "systemd"; then
24+
__depends=$(printf '%s systemd' "${_depends}")
25+
fi
26+
echo "${__depends}"
2327
return 255
2428
}
2529

2630
install() {
2731
if dracut_module_included "systemd"; then
2832
inst_multiple \
2933
$systemdsystemunitdir/clevis-luks-askpass.service \
30-
$systemdsystemunitdir/clevis-luks-askpass.path
34+
$systemdsystemunitdir/clevis-luks-askpass.path \
35+
@SYSTEMD_REPLY_PASS@ \
36+
@libexecdir@/clevis-luks-askpass
3137
systemctl -q --root "$initdir" add-wants cryptsetup.target clevis-luks-askpass.path
3238
else
3339
inst_hook initqueue/online 60 "$moddir/clevis-hook.sh"
3440
inst_hook initqueue/settled 60 "$moddir/clevis-hook.sh"
41+
42+
inst_multiple \
43+
@libexecdir@/clevis-luks-generic-unlocker \
44+
clevis-luks-unlock \
45+
lsblk \
46+
sort \
47+
awk
3548
fi
3649

3750
inst_multiple \
3851
/etc/services \
39-
@SYSTEMD_REPLY_PASS@ \
40-
@libexecdir@/clevis-luks-askpass \
4152
clevis-luks-common-functions \
4253
grep sed cut \
4354
clevis-decrypt \
File renamed without changes.

src/luks/systemd/dracut/clevis/clevis-hook.sh.in

-2
This file was deleted.

src/luks/systemd/meson.build

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ sd_reply_pass = find_program(
1010

1111
if systemd.found() and sd_reply_pass.found()
1212
data.set('SYSTEMD_REPLY_PASS', sd_reply_pass.path())
13-
subdir('dracut')
1413

1514
unitdir = systemd.get_pkgconfig_variable('systemdsystemunitdir')
1615

src/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
subdir('bash')
22
subdir('luks')
33
subdir('pins')
4+
subdir('dracut')
45
subdir('initramfs-tools')
56

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

0 commit comments

Comments
 (0)