Skip to content

Commit 2c3856f

Browse files
author
Gareth Widlansky
committed
Fix systemd-boot signing on sealed image test
Signed-off-by: Gareth Widlansky <gareth.widlansky@proton.me>
1 parent f687add commit 2c3856f

File tree

3 files changed

+77
-20
lines changed

3 files changed

+77
-20
lines changed

Dockerfile.cfsuki

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
ARG base=localhost/bootc
33
# This is where we get the tools to build the UKI
44
ARG buildroot=quay.io/centos/centos:stream10
5+
56
FROM $base AS base
67

78
FROM $buildroot as buildroot-base
@@ -12,7 +13,7 @@ set -xeuo pipefail
1213
# is used by ukify as invoked with the `--measure` flag below. Not
1314
# strictly required, but nice to have the measured PCR values in the
1415
# output.
15-
dnf install -y systemd-ukify systemd-udev pesign openssl systemd-boot-unsigned
16+
dnf install -y systemd-ukify systemd-udev pesign openssl
1617
dnf clean all
1718
EORUN
1819

@@ -50,19 +51,9 @@ RUN --mount=type=secret,id=key \
5051
--measure \
5152
--json pretty \
5253
--output "/boot/$kver.efi"
53-
# Sign systemd-boot as well
54-
sdboot="/usr/lib/systemd/boot/efi/systemd-bootx64.efi"
55-
pesign \
56-
--certdir "pesign" \
57-
--certificate "${subject}" \
58-
--in "${sdboot}" \
59-
--out "${sdboot}.signed" \
60-
--sign
61-
mv "${sdboot}.signed" "${sdboot}"
6254
EOF
6355

6456
FROM base as final
65-
6657
RUN --mount=type=bind,from=kernel,target=/run/kernel <<EOF
6758
set -xeuo pipefail
6859
kver=$(cd /usr/lib/modules && echo *)
@@ -75,7 +66,7 @@ cp /run/kernel/boot/$kver.efi $target
7566
rm -v /usr/lib/modules/${kver}/{vmlinuz,initramfs.img}
7667
# Symlink into the /usr/lib/modules location
7768
ln -sr $target /usr/lib/modules/${kver}/$(basename $kver.efi)
78-
bootc container lint --fatal-warnings
69+
bootc container lint # --fatal-warnings no fatal warning
7970
EOF
8071

8172
FROM base as final-final

Dockerfile.sdboot

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Override via --build-arg=base=<image> to use a different base
2+
ARG base=localhost/bootc
3+
# Image to sign systemd-boot first, BEFORE, installing onto the image
4+
ARG buildroot=quay.io/centos/centos:stream10
5+
6+
FROM $base AS base-unsigned
7+
8+
FROM $buildroot as buildroot-base
9+
RUN <<EORUN
10+
set -xeuo pipefail
11+
dnf install -y pesign openssl
12+
dnf clean all
13+
EORUN
14+
15+
16+
FROM buildroot-base as kernel
17+
# Sign sdboot and put it on the target first
18+
RUN --mount=type=secret,id=key \
19+
--mount=type=secret,id=cert \
20+
--mount=type=bind,from=base-unsigned,target=/target \
21+
<<EORUN
22+
set -eux
23+
24+
# pesign uses NSS database so create it from input cert/key
25+
mkdir pesign
26+
certutil -N -d pesign --empty-password
27+
openssl pkcs12 -export -password 'pass:' -inkey /run/secrets/key -in /run/secrets/cert -out db.p12
28+
pk12util -i db.p12 -W '' -d pesign
29+
subject=$(openssl x509 -in /run/secrets/cert -subject | grep '^subject=CN=' | sed 's/^subject=CN=//')
30+
31+
# Sign systemd-boot as well
32+
sdboot="target/usr/lib/systemd/boot/efi/systemd-bootx64.efi"
33+
sdboot_out="/sdboot.efi"
34+
pesign \
35+
--certdir "pesign" \
36+
--certificate "${subject}" \
37+
--in "${sdboot}" \
38+
--out "${sdboot_out}" \
39+
--sign
40+
EORUN
41+
42+
43+
FROM base-unsigned as final
44+
RUN --mount=type=bind,from=kernel,target=/run/sdboot \
45+
<<EORUN
46+
set -eux
47+
sdboot=/usr/lib/systemd/boot/efi/systemd-bootx64.efi
48+
# copy signed sdboot from buildroot
49+
cp "/run/sdboot/sdboot.efi" ${sdboot}
50+
EORUN

tests/build-sealed

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ case $variant in
3434
esac
3535

3636

37-
graphroot=$(podman system info -f '{{.Store.GraphRoot}}')
38-
echo "Computing composefs digest..."
39-
cfs_digest=$(podman run --rm --privileged --read-only --security-opt=label=disable -v /sys:/sys:ro --net=none \
40-
-v ${graphroot}:/run/host-container-storage:ro --tmpfs /var "$input_image" bootc container compute-composefs-digest)
41-
4237
if test -z "${secureboot}"; then
4338
secureboot=$(pwd)/target/test-secureboot
4439
mkdir -p ${secureboot}
@@ -58,9 +53,30 @@ if test -z "${secureboot}"; then
5853
cd -
5954
fi
6055

61-
runv podman build -t $output_image \
62-
--build-arg=COMPOSEFS_FSVERITY=${cfs_digest} \
56+
# handle sdboot signing before building the sealed UKI
57+
# moves db, PK, and KEK test keys into /usr/lib/bootc/keys
58+
sdboot_signed="${input_image}_signed"
59+
runv podman build -t $sdboot_signed \
6360
--build-arg=base=${input_image} \
6461
--build-arg=buildroot=${BOOTC_buildroot_base} \
6562
--secret=id=key,src=${secureboot}/db.key \
66-
--secret=id=cert,src=${secureboot}/db.crt -f Dockerfile.cfsuki .
63+
--secret=id=cert,src=${secureboot}/db.crt \
64+
--secret=id=cert,src=${secureboot}/db.crt \
65+
--secret=id=pk_key,src=${secureboot}/PK.key \
66+
--secret=id=pk_cert,src=${secureboot}/PK.crt \
67+
--secret=id=kek_key,src=${secureboot}/KEK.key \
68+
--secret=id=kek_cert,src=${secureboot}/KEK.crt \
69+
--secret=id=guid,src=${secureboot}/GUID.txt \
70+
-f Dockerfile.sdboot .
71+
72+
graphroot=$(podman system info -f '{{.Store.GraphRoot}}')
73+
echo "Computing composefs digest..."
74+
cfs_digest=$(podman run --rm --privileged --read-only --security-opt=label=disable -v /sys:/sys:ro --net=none \
75+
-v ${graphroot}:/run/host-container-storage:ro --tmpfs /var "$sdboot_signed" bootc container compute-composefs-digest)
76+
77+
runv podman build -t $output_image \
78+
--build-arg=COMPOSEFS_FSVERITY=${cfs_digest} \
79+
--build-arg=base=${sdboot_signed} \
80+
--secret=id=key,src=${secureboot}/db.key \
81+
--secret=id=cert,src=${secureboot}/db.crt \
82+
-f Dockerfile.cfsuki .

0 commit comments

Comments
 (0)