-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #36885 - Add Clevis/Tang disk encryption template
For disk encryption Clevis/Tang is often used. This commit introduces a Kickstart partition template taking care of disk encryption and a snippet responsible for binding the LUKS device via Clevis to a given Tang server. The default partition template encrypts the disk with a passphrase which can be provided via `disk_enc_passphrase` host parameter. If no host parameter is provided, the default passphrase is 'linux'. If, in addition, `disk_enc_tang_servers` host parameter is provided (can be one address as string or multiple addresses as array), the LUKS device will be bind to these Tang servers using Clevis. In this case, the passphrase will be removed. This commit targets mainly all operating systems of the Red Hat family, however the snippet can also be used for Ubuntu operating system.
- Loading branch information
Jan Löser
committed
Nov 6, 2023
1 parent
52d4a50
commit baeafe2
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
app/views/unattended/partition_tables_templates/kickstart_default_encrypted.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<%# | ||
kind: ptable | ||
name: Kickstart default encrypted | ||
model: Ptable | ||
oses: | ||
- AlmaLinux | ||
- RedHat | ||
- Rocky | ||
-%> | ||
<% if host_param('driverdisk_source') -%> | ||
driverdisk --source=<%= host_param('driverdisk_source') %> | ||
<% end -%> | ||
<% if host_param('ignoredisk_options') %> | ||
ignoredisk <%= host_param('ignoredisk_options') %> | ||
<% end %> | ||
zerombr | ||
clearpart --all --initlabel | ||
autopart --encrypted --passphrase="<%= host_param('disk_enc_passphrase') ? host_param('disk_enc_passphrase') : 'linux' %>" <%= host_param('autopart_options') %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
app/views/unattended/provisioning_templates/snippet/disk_enc_clevis_tang.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<%# | ||
kind: snippet | ||
name: disk_enc_clevis_tang | ||
model: ProvisioningTemplate | ||
snippet: true | ||
description: | | ||
Binds encrypted root directory ('/') utilizing Clevis to Tang server(s) for | ||
decryption. The first parent device containing a LUKS container will be used. | ||
The temporary passphrase will be removed afterwards. Currently, only Red Hat | ||
family and Ubuntu operating systems are supported. | ||
-%> | ||
<% | ||
passphrase = host_param('disk_enc_passphrase') || 'linux' | ||
tang_server_list = [] | ||
packages_redhat = "clevis clevis-luks clevis-systemd clevis-dracut" | ||
packages_ubuntu = "clevis clevis-luks clevis-systemd clevis-initramfs" | ||
|
||
unless host_param('disk_enc_tang_servers').blank? | ||
if host_param('disk_enc_tang_servers').is_a?(String) | ||
tang_server_list = [host_param('disk_enc_tang_servers')] | ||
else | ||
tang_server_list = host_param('disk_enc_tang_servers') | ||
end | ||
end | ||
-%> | ||
|
||
<% if (@host.operatingsystem.family == 'Redhat' or @host.operatingsystem.name == 'Ubuntu') and unless tang_server_list.blank? %> | ||
|
||
cat > /tmp/rootdir-luks-device.sh << "EOF" | ||
#!/bin/sh | ||
# | ||
# Author Jan Löser <[email protected]> | ||
# Published under the GNU Public Licence 3 | ||
# | ||
# This scripts tries to find the 1st LUKS device for / (root directory). | ||
# | ||
set -o pipefail | ||
|
||
rootdev=$(df / --output=source | tail -n1) | ||
targetdev=$(readlink -f $rootdev) | ||
slavedev=$targetdev | ||
|
||
while : ; do | ||
/sbin/cryptsetup luksDump $slavedev &>/dev/null && echo $slavedev && exit 0 | ||
set -e | ||
slave=$(find /sys/class/block/$(basename $slavedev)/slaves -type l | head -n1) | ||
slavedev=$(find /dev -name "$(basename $slave)" | head -n1) | ||
set +e | ||
done | ||
|
||
exit 1 | ||
EOF | ||
|
||
# needs bash here because Ubuntu's sh (dash) doesn't support `-o pipefail` option | ||
luksdev=$(bash /tmp/rootdir-luks-device.sh) | ||
|
||
if [[ -n "$luksdev" ]]; then | ||
echo "LUKS device found for '/': $luksdev" | ||
|
||
<% if @host.operatingsystem.family == 'Redhat' %> | ||
if [ -f /usr/bin/dnf ]; then | ||
dnf -y install <%= packages_redhat %> | ||
else | ||
yum -t -y install <%= packages_redhat %> | ||
fi | ||
<% elsif @host.operatingsystem.name == 'Ubuntu' %> | ||
apt -y install clevis clevis-luks clevis-initramfs clevis-systemd | ||
<% end %> | ||
|
||
<% for tang_server in tang_server_list %> | ||
echo '<%= passphrase %>' | clevis luks bind -y -k - -d $luksdev tang '{"url": "<%= tang_server %>"}' | ||
<% end %> | ||
echo '<%= passphrase %>' | cryptsetup luksRemoveKey $luksdev | ||
systemctl enable clevis-luks-askpass.path | ||
systemctl enable remote-cryptsetup.target | ||
|
||
<% if @host.operatingsystem.family == 'Redhat' %> | ||
dracut --verbose --force --hostonly-cmdline --regenerate-all | ||
<% elsif @host.operatingsystem.name == 'Ubuntu' %> | ||
update-initramfs -u -k 'all' | ||
<% end %> | ||
|
||
else | ||
echo "No LUKS device found!" | ||
fi | ||
|
||
<% end %> |