Skip to content

Commit 1ad2520

Browse files
committed
CP-12697 Enable SB for AWS on first boot (no shim)
PR URL: https://www.github.com/delphix/delphix-platform/pull/543
1 parent 9cd9047 commit 1ad2520

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

debian/postinst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ configure)
6969
systemctl enable delphix-rpool-upgrade.service
7070
systemctl enable delphix.target
7171

72+
systemctl unmask delphix-sb-enroll.service
73+
systemctl enable delphix-sb-enroll.service
74+
7275
if ! id -u postgres >/dev/null; then
7376
# When installing postgres, a postgres user is created unless it
7477
# already exists. To have a consistent UID accross installations
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[Unit]
2+
Description=Enroll Secure Boot variables (PK/KEK/db) from .auth files
3+
Documentation=man:efi-updatevar(1)
4+
DefaultDependencies=no
5+
Before=delphix-platform.service
6+
ConditionPathExists=/var/delphix/server/sb_certs/
7+
8+
[Service]
9+
Type=oneshot
10+
Environment=SB_AUTH_DIR=/var/delphix/server/sb_certs/
11+
ExecStart=/var/lib/delphix-sb-enroll/sb-enroll-efivars.sh
12+
# Prevent accidental re-runs the same boot unless you change the inputs
13+
RemainAfterExit=no
14+
15+
[Install]
16+
WantedBy=multi-user.target
17+
WantedBy=delphix-platform.service
18+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
AUTH_DIR="${SB_AUTH_DIR:-/var/delphix/server/sb_certs/}"
5+
6+
log() { printf '[sb-enroll] %s\n' "$*" >&2; }
7+
die() {
8+
log "ERROR: $*"
9+
exit 1
10+
}
11+
12+
# Do nothing if Secure Boot is already enabled.
13+
sb=$(od -An -t u1 /sys/firmware/efi/efivars/SecureBoot-* | awk '{print $NF}')
14+
[[ $sb -eq 1 ]] && exit 0
15+
16+
#
17+
# Run only on AWS.
18+
#
19+
# Expand this logic to support additional clouds.
20+
#
21+
if [[ $(get-appliance-platform) = "aws" ]]; then
22+
log "AWS detected"
23+
else
24+
log "Not AWS; skipping Secure Boot enrollment."
25+
exit 0
26+
fi
27+
28+
[[ -d /sys/firmware/efi/efivars ]] || die "Not booted in UEFI mode (/sys/firmware/efi/efivars missing)."
29+
30+
# Ensure efivars is mounted (usually is on Ubuntu)
31+
if ! mountpoint -q /sys/firmware/efi/efivars; then
32+
log "Mounting efivarfs..."
33+
sudo mount -t efivarfs efivarfs /sys/firmware/efi/efivars
34+
fi
35+
36+
[[ -d "$AUTH_DIR" ]] || die "Auth directory not found: $AUTH_DIR"
37+
38+
apply_auth() {
39+
local var="$1" # db, KEK, PK
40+
local file="$AUTH_DIR/${var}.auth"
41+
42+
sudo efi-updatevar -f "$file" "$var"
43+
log "${var}: update submitted"
44+
}
45+
46+
apply_auth db
47+
apply_auth KEK
48+
apply_auth PK
49+
50+
log "Rebooting..."
51+
init 6

0 commit comments

Comments
 (0)