Skip to content

Commit c68d243

Browse files
committed
bake: Add signed verity format
This uses systemd-repart for image generation, but requires the unreleased v255 due to bugs and missing features in earlier versions. Signed-off-by: Jeremi Piotrowski <[email protected]>
1 parent 8e83b5b commit c68d243

File tree

5 files changed

+53
-5
lines changed

5 files changed

+53
-5
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,14 @@ In case you have an existing Torcx image you can convert it with the `convert_to
177177
```
178178

179179
Please make also sure that your don't have a `containerd.service` drop in file under `/etc` that uses Torcx paths.
180+
181+
182+
### Verity
183+
184+
To generate sysext protected by dm-verity with a signed root hash pass `FORMAT=verity` before invoking any of the scripts. This requires `systemd-repart` with a version >= v255. This also requires passing a path to a private key and certificate through `KEY` and `CERT`.
185+
186+
Here's an example:
187+
```
188+
openssl req -batch -new -x509 -sha256 -newkey rsa:2048 -nodes -out root_key.crt -keyout root_key.pem -days 3650
189+
FORMAT=verity KEY=root_key.pem CERT=root_key.crt ./create_kubernetes_sysext.sh v1.27.3 k8s
190+
```

bake.sh

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ FORMAT="${FORMAT:-squashfs}"
66
ARCH="${ARCH-}"
77
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH-0}"
88
export SOURCE_DATE_EPOCH
9+
KEY="${KEY-}"
10+
CERT="${CERT-}"
11+
12+
die() {
13+
echo >&2 "$@"
14+
exit 1
15+
}
916

1017
# This script is to be called as helper by other scripts but can also be used standalone
1118
if [ $# -lt 1 ]; then
@@ -22,12 +29,20 @@ elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
2229
exit 1
2330
fi
2431

32+
if [ "${FORMAT}" = "verity" ]; then
33+
[ -z "${KEY}" ] && die "\$KEY required for verity"
34+
[ -z "${CERT}" ] && die "\$CERT required for verity"
35+
fi
36+
2537
SYSEXTNAME="$1"
2638

27-
if [ "${FORMAT}" != "squashfs" ] && [ "${FORMAT}" != "btrfs" ] && [ "${FORMAT}" != "ext4" ] && [ "${FORMAT}" != "ext2" ]; then
28-
echo "Expected FORMAT=squashfs, FORMAT=btrfs, FORMAT=ext4, or FORMAT=ext2, got '${FORMAT}'" >&2
29-
exit 1
30-
fi
39+
case ${FORMAT} in
40+
squashfs) ;;
41+
btrfs) ;;
42+
ext4|ext2) ;;
43+
verity) ;;
44+
*) die "Unsupported format: '${FORMAT}'" ;;
45+
esac
3146

3247
# Map to valid values for https://www.freedesktop.org/software/systemd/man/os-release.html#ARCHITECTURE=
3348
if [ "${ARCH}" = "amd64" ] || [ "${ARCH}" = "x86_64" ]; then
@@ -57,7 +72,11 @@ elif [ "${FORMAT}" = "ext4" ] || [ "${FORMAT}" = "ext2" ]; then
5772
# Note: We didn't chown to root:root, meaning that the file ownership is left as is
5873
mkfs."${FORMAT}" -E root_owner=0:0 -d "${SYSEXTNAME}" "${SYSEXTNAME}".raw
5974
resize2fs -M "${SYSEXTNAME}".raw
60-
else
75+
elif [ "${FORMAT}" = "squashfs" ]; then
6176
mksquashfs "${SYSEXTNAME}" "${SYSEXTNAME}".raw -all-root
77+
elif [ "${FORMAT}" = "verity" ]; then
78+
systemd-repart --private-key="${KEY}" --certificate="${CERT}" --root="${SYSEXTNAME}" --no-pager --empty=create --size=auto --definitions=repart.d "${SYSEXTNAME}.raw"
79+
else
80+
die "Unsupported format: ${FORMAT}"
6281
fi
6382
echo "Created ${SYSEXTNAME}.raw"

repart.d/01-root.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[Partition]
2+
Type=root
3+
CopyFiles=/:/
4+
Format=squashfs
5+
Minimize=best
6+
Verity=data
7+
VerityMatchKey=sysext

repart.d/02-verity.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[Partition]
2+
Type=root-verity
3+
Verity=hash
4+
VerityMatchKey=sysext
5+
# Only works from v255
6+
Minimize=best
7+
SizeMinBytes=4K

repart.d/03-verity-sig.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[Partition]
2+
Type=root-verity-sig
3+
Verity=signature
4+
VerityMatchKey=sysext

0 commit comments

Comments
 (0)