Skip to content

Commit 0046210

Browse files
committed
update for sed drives
1 parent edc67d5 commit 0046210

File tree

9 files changed

+207
-1
lines changed

9 files changed

+207
-1
lines changed

src/core-switch/scripts/collect.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ sudo tar czvf ~/install.bundle/configuration.tgz \
1919
etc/network/interfaces \
2020
etc/ssh/sshd_config.d/10-no-passwords.conf \
2121
etc/sysctl.d/10-disable-ipv6.conf \
22-
opt/nomad/docker.json
22+
opt/nomad/docker.json \
23+
lib/systemd/system/monitor-systemd-journal.service
2324

2425
sudo tar czvf ~/install.bundle/mok.tgz \
2526
var/lib/shim-signed/mok
@@ -32,6 +33,7 @@ tar czvf ~/install.bundle/$USER.tgz \
3233
.zshrc \
3334
.zshenv \
3435
.p10k.zsh \
36+
bin
3537

3638
cp -v ~{,/install.bundle}/secrets.tgz
3739
cp -v ~{,/install.bundle}/kernel.tgz

src/core-switch/scripts/orchestration/hashicorp/nomad-pack/deploy.sh

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ else
77
set -euo pipefail
88
fi
99

10+
sudo apt-get update
11+
sudo apt-get install -y build-essential
12+
1013
cd ~
1114
if [[ ! -d /usr/local/go ]] || [[ "${FETCH_GO:-0}" == "1" ]]
1215
then

src/core-switch/scripts/provision.sh

+8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ sudo systemctl stop networking
3434
cd /
3535
echo "deploying system configuration"
3636
sudo tar xzvf ~/install/configuration.tgz
37+
38+
echo "enabling journal monitor"
39+
sudo systemctl daemon-reload
40+
sudo systemctl enable monitor-systemd-journal.service
41+
3742
echo "deploying sev firmware"
3843
sudo tar xzvf ~/install/firmware.tgz
3944
echo "deploying existing MOK"
@@ -53,6 +58,9 @@ cp ~/install/secrets.tgz .
5358
echo "enabling clevis on demand"
5459
sudo systemctl enable clevis-luks-askpass.path
5560

61+
echo "creating src dir"
62+
mkdir -p ~/src
63+
5664
echo "cleaning up"
5765
sudo apt-get -y autoremove
5866

src/core-switch/scripts/security/aes256gcm/deploy.sh

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ else
77
set -euo pipefail
88
fi
99

10+
sudo apt-get update
11+
sudo apt-get install -y build-essential libssl-dev
12+
1013
mkdir -p ~/bin
1114
gcc -Wall -o ~/bin/aes256gcm ~/install/scripts/security/aes256gcm/aes256gcm.c -lcrypto
1215
gcc -Wall -o ~/bin/aes256gcm-decrypt ~/install/scripts/security/aes256gcm/aes256gcm-decrypt.c -lcrypto
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/bash
2+
3+
if [[ "$DEBUG" == "1" ]]
4+
then
5+
set -euxo pipefail
6+
else
7+
set -euo pipefail
8+
fi
9+
10+
sudo apt-get update
11+
sudo apt-get install -y argon2 parted
12+
13+
cd ~/src
14+
wget --content-disposition https://github.com/Drive-Trust-Alliance/exec/blob/master/sedutil_LINUX.tgz?raw=true
15+
tar xzvf sedutil_LINUX.tgz
16+
sudo cp sedutil/Release_x86_64/sedutil-cli /usr/sbin
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
# vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
3+
#
4+
# Copyright (c) 2016 Red Hat, Inc.
5+
# Author: Nathaniel McCallum <[email protected]>
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
21+
check() {
22+
return 0
23+
}
24+
25+
install() {
26+
inst_hook initqueue/online 60 "$moddir/unlock-sed.sh"
27+
inst_hook initqueue/settled 60 "$moddir/unlock-sed.sh"
28+
29+
inst_multiple \
30+
/etc/sedutil/nvme0.passphrase.enc \
31+
/etc/sedutil/nvme1.passphrase.enc \
32+
/usr/lib/x86_64-linux-gnu/libstdc++.so.6 \
33+
grep sed cut tr \
34+
argon2 \
35+
sedutil-cli \
36+
partprobe \
37+
clevis-decrypt \
38+
clevis
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/bash
2+
3+
if [[ "$DEBUG" == "1" ]]
4+
then
5+
set -euxo pipefail
6+
else
7+
set -euo pipefail
8+
fi
9+
10+
derive_hdd_passphrase() {
11+
local HDD_NAME=$1
12+
13+
echo -n "enter a passphrase for ${HDD_NAME}: "
14+
STTY_ORIG=$(stty -g)
15+
stty -echo
16+
IFS= read -r PASSPHRASE
17+
stty "${STTY_ORIG}"
18+
echo
19+
20+
echo -n "verify: "
21+
STTY_ORIG=$(stty -g)
22+
stty -echo
23+
IFS= read -r VERIFICATION
24+
stty "${STTY_ORIG}"
25+
echo
26+
27+
if [[ "${PASSPHRASE}" != "${VERIFICATION}" ]]; then
28+
echo "passphrases did not match!"
29+
exit 1
30+
fi
31+
unset VERIFICATION
32+
33+
echo "deriving key..."
34+
# we use a null salt so that we can recover the drive with only the passphrase, this is atypical salt usage
35+
export HDD_PASSPHRASE=$(echo -n "${PASSPHRASE}" | argon2 '\0\0\0\0\0\0\0\0' -id -e -t 10 -m 20 -p 8 | cut -d'$' -f6 | tr -d '\n')
36+
unset PASSPHRASE
37+
}
38+
39+
setup() {
40+
local HDD_NAME=$1
41+
42+
derive_hdd_passphrase "${HDD_NAME}"
43+
echo -n "${HDD_PASSPHRASE}" | sudo clevis encrypt tpm2 '{"pcr_bank":"sha256","pcr_ids":"0,2,3,4,6,7,8"}' | sudo dd of=/etc/sedutil/${HDD_NAME}.passphrase.enc
44+
45+
if [[ "${INITIALIZE_HDDS:-0}" == "1" ]]; then
46+
PASSPHRASE_LABEL=PSID_${HDD_NAME}
47+
CURRENT_PASSPHRASE="${!PASSPHRASE_LABEL}"
48+
49+
sudo sedutil-cli --PSIDrevert "${CURRENT_PASSPHRASE}" /dev/${HDD_NAME}
50+
sudo sedutil-cli --initialSetup "${HDD_PASSPHRASE}" /dev/${HDD_NAME}
51+
52+
sudo sedutil-cli --enableLockingRange 0 "${HDD_PASSPHRASE}" /dev/${HDD_NAME}
53+
sudo sedutil-cli --setMBREnable off "${HDD_PASSPHRASE}" /dev/${HDD_NAME}
54+
sudo sedutil-cli --setMBRDone off "${HDD_PASSPHRASE}" /dev/${HDD_NAME}
55+
fi
56+
unset HDD_PASSPHRASE
57+
}
58+
59+
sudo mkdir -p /etc/sedutil
60+
setup "nvme0"
61+
setup "nvme1"
62+
63+
sudo mkdir -p /usr/lib/dracut/modules.d/60unlock-sed
64+
sudo cp ~/install/scripts/security/sedutil/module-setup.sh /usr/lib/dracut/modules.d/60unlock-sed
65+
sudo cp ~/install/scripts/security/sedutil/unlock-sed.sh /usr/lib/dracut/modules.d/60unlock-sed
66+
67+
sudo dracut -f --regenerate-all -v
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Make sure to exit cleanly if SIGTERM is received.
6+
trap 'echo "Exiting due to SIGTERM" && exit 0' TERM
7+
8+
derive_hdd_passphrase() {
9+
local HDD_NAME=$1
10+
11+
# echo -n "enter the passphrase for ${HDD_NAME}: "
12+
# STTY_ORIG=$(stty -g)
13+
# stty -echo
14+
# IFS= read -r PASSPHRASE
15+
# stty "${STTY_ORIG}"
16+
# echo
17+
18+
PASSPHRASE=$(systemd-ask-password "enter the passphrase for ${HDD_NAME}: ")
19+
20+
echo "deriving key..."
21+
# we use a null salt so that we can recover the drive with only the passphrase, this is atypical salt usage
22+
export HDD_PASSPHRASE=$(echo -n "${PASSPHRASE}" | argon2 '\0\0\0\0\0\0\0\0' -id -e -t 10 -m 20 -p 8 | cut -d'$' -f6 | tr -d '\n')
23+
unset PASSPHRASE
24+
}
25+
26+
unlock() {
27+
local HDD_NAME=$1
28+
29+
LOCKED=$(sedutil-cli --query /dev/${HDD_NAME} | grep Locked | cut -d',' -f1 | cut -d'=' -f2 | sed 's/ //g')
30+
31+
if [[ "${LOCKED}" == "Y" ]]; then
32+
HDD_PASSPHRASE=$( (cat /etc/sedutil/${HDD_NAME}.passphrase.enc | clevis decrypt) || true )
33+
sedutil-cli --setLockingRange 0 rw "${HDD_PASSPHRASE}" /dev/${HDD_NAME} || true
34+
unset HDD_PASSPHRASE
35+
36+
LOCKED=$(sedutil-cli --query /dev/${HDD_NAME} | grep Locked | cut -d',' -f1 | cut -d'=' -f2 | sed 's/ //g')
37+
38+
if [[ "${LOCKED}" == "Y" ]]; then
39+
derive_hdd_passphrase "${HDD_NAME}"
40+
sedutil-cli --setLockingRange 0 rw "${HDD_PASSPHRASE}" /dev/${HDD_NAME}
41+
fi
42+
43+
echo "successfully unlocked /dev/${HDD_NAME}" >&2
44+
45+
partprobe /dev/${HDD_NAME}n1
46+
else
47+
echo "/dev/${HDD_NAME} is already unlocked. continuing." >&2
48+
fi
49+
}
50+
51+
echo "unlocking nvme drives" >&2
52+
unlock "nvme0"
53+
unlock "nvme1"
54+
55+
exit 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/bash
2+
3+
set -euo pipefail
4+
5+
install/scripts/security/sedutil/setup.sh
6+
7+
if [[ "${UNBIND:-0}" == "1" ]]; then
8+
sudo clevis luks unbind -d /dev/sda3 -s 1
9+
sudo clevis luks unbind -d /dev/sda4 -s 1
10+
fi
11+
12+
sudo clevis luks bind -d /dev/sda3 tpm2 '{"pcr_bank":"sha256","pcr_ids":"0,2,3,4,6,7,8"}'
13+
sudo clevis luks bind -d /dev/sda4 tpm2 '{"pcr_bank":"sha256","pcr_ids":"0,2,3,4,6,7,8"}'

0 commit comments

Comments
 (0)