-
Notifications
You must be signed in to change notification settings - Fork 1k
Fixes #37857 - Tang support multiple phys. volumes #10334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sbernhard
merged 1 commit into
theforeman:develop
from
ATIX-AG:clevis-tang-multiple-disks
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ 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. | ||
| decryption. All parent devices 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. | ||
| -%> | ||
|
|
@@ -27,52 +27,66 @@ description: | | |
| <% if (@host.operatingsystem.family == 'Redhat' || @host.operatingsystem.name == 'Ubuntu') && tang_server_list.present? -%> | ||
|
|
||
| cat > /tmp/rootdir-luks-device.sh << "EOF" | ||
| #!/bin/sh | ||
| #!/bin/bash | ||
| # | ||
| # Author Jan Löser <[email protected]> | ||
| # Published under the GNU Public Licence 3 | ||
| # SPDX-FileCopyrightText: 2024 Jan Löser <[email protected]> | ||
| # SPDX-FileCopyrightText: 2024 Martin Spiessl <[email protected]> | ||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||
| # | ||
| # This scripts tries to find the 1st LUKS device for / (root directory). | ||
| # This script tries to find all LUKS devices mounted in /etc/crypttab. | ||
| # | ||
| 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 | ||
| mapfile -t maybe_luks_devices < <( | ||
| awk '{print $1}' /etc/crypttab | \ | ||
sbernhard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| xargs -rn1 find /dev -name | \ | ||
| xargs -rn1 readlink -f | ||
| ) | ||
| luks_devices=() | ||
| while [[ ${#maybe_luks_devices[@]} -gt 0 ]] ; do | ||
| # classify maybe_luks_devices into luks_devices and non_luks_devices | ||
| non_luks_devices=() | ||
| for dev in "${maybe_luks_devices[@]}" ; do | ||
| /sbin/cryptsetup luksDump "$dev" &>/dev/null && luks_devices+=("$dev") || non_luks_devices+=("$dev") | ||
| done | ||
| # resolve non_luks_devices to discover new maybe_luks_devices | ||
| set -e | ||
| slave=$(find /sys/class/block/$(basename $slavedev)/slaves -type l | head -n1) | ||
| slavedev=$(find /dev -name "$(basename $slave)" | head -n1) | ||
| maybe_luks_devices=() | ||
| for dev in "${non_luks_devices[@]}" ; do | ||
| mapfile -t slaves < <(find "/sys/class/block/$(basename "$dev")/slaves" -type l) | ||
| for slave in "${slaves[@]}" ; do | ||
| slavedev=$(find /dev -name "$(basename "$slave")" | head -n1) | ||
| maybe_luks_devices+=("$slavedev") | ||
| done | ||
| done | ||
| set +e | ||
| done | ||
|
|
||
| exit 1 | ||
| printf "%s\n" "${luks_devices[@]}" | ||
| 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" | ||
| luksdevs=$(bash /tmp/rootdir-luks-device.sh) | ||
| if [ -n "$luksdevs" ]; then | ||
| echo "LUKS devices found for '/': $luksdevs" | ||
|
|
||
| <% if @host.operatingsystem.family == 'Redhat' -%> | ||
| $PKG_MANAGER_INSTALL <%= packages_redhat %> | ||
| <% elsif @host.operatingsystem.name == 'Ubuntu' -%> | ||
| $PKG_MANAGER_INSTALL <%= packages_ubuntu %> | ||
| <% end -%> | ||
|
|
||
| <% for tang_server in tang_server_list -%> | ||
| echo '<%= passphrase %>' | clevis luks bind -y -k - -d $luksdev tang '{"url": "<%= tang_server %>"}' | ||
| if [[ $? -ne 0 ]]; then | ||
| echo "---" | ||
| echo "There was an error during Clevis LUKS bind of '$luksdev' to Tang server '<%= tang_server %>'." | ||
| echo "System halted." | ||
| sleep infinity | ||
| fi | ||
| <% end -%> | ||
| echo '<%= passphrase %>' | cryptsetup luksRemoveKey $luksdev | ||
| for luksdev in $luksdevs; do | ||
| <% for tang_server in tang_server_list -%> | ||
| echo '<%= passphrase %>' | clevis luks bind -y -k - -d $luksdev tang '{"url": "<%= tang_server %>"}' | ||
| if [ $? -ne 0 ]; then | ||
| echo "---" | ||
| echo "There was an error during Clevis LUKS bind of '$luksdev' to Tang server '<%= tang_server %>'." | ||
| echo "System halted." | ||
| sleep infinity | ||
| fi | ||
| <% end -%> | ||
| echo '<%= passphrase %>' | cryptsetup luksRemoveKey $luksdev | ||
| done | ||
| systemctl enable clevis-luks-askpass.path | ||
| systemctl enable remote-cryptsetup.target | ||
|
|
||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.