@@ -1414,3 +1414,87 @@ function set_secret_build_args() {
14141414 _SECRET_BUILD_ARGS+=(" -DSECRET_DB_AWS_REGION=$SECRET_DB_AWS_REGION " )
14151415 fi
14161416}
1417+
1418+ #
1419+ # Secure boot variables and functions
1420+ #
1421+ # S3 bucket containing keys and certs
1422+ # ./db subdirectory contains the db key and various certs:
1423+ # .der is for signing modules like ZFS and connstat
1424+ # .crt is for signing vmlinuz
1425+ # signing_key.pem is the format expected by kernel build for signing its modules
1426+ #
1427+ # ./pub contains the auth files, secure boot enrollment certs.
1428+ #
1429+ S3_KEYS_URL=" s3://secure-boot-keys-prod/release"
1430+ #
1431+ # The kernel build expects the signing_key.pem in this directory, i.e.
1432+ # CONFIG_MODULE_SIG_KEY is set to /var/tmp/sbkeys/signing_key.pem in
1433+ # resources/delphix_kernel_annotations
1434+ #
1435+ SB_KEYS_DIR=" /var/tmp/sbkeys"
1436+ SBSIGN_KEY=" $SB_KEYS_DIR /db.key"
1437+ SBSIGN_DER=" $SB_KEYS_DIR /db.der"
1438+
1439+ function download_keys() {
1440+ logmust mkdir -p $SB_KEYS_DIR
1441+ logmust aws s3 cp --recursive " $S3_KEYS_URL /db/" $SB_KEYS_DIR
1442+ }
1443+
1444+ function delete_keys() {
1445+ logmust rm -r $SB_KEYS_DIR
1446+ }
1447+
1448+ # Update DEBIAN/md5sum for package directory after
1449+ # some files were updated, i.e. secure-boot signed.
1450+ #
1451+ function update_md5sums() {
1452+ pkg_dir=$1
1453+ echo_bold " Updating md5sums for $pkg_dir "
1454+
1455+ (
1456+ cd " $pkg_dir " || exit
1457+ : > DEBIAN/md5sums
1458+ # print paths relative to root of package
1459+ while IFS= read -r -d ' ' f; do
1460+ rel=" ${f# ./ } "
1461+ md5sum " $rel " >> DEBIAN/md5sums
1462+ done < <( find . -type f ! -path ' ./DEBIAN/*' ! -path ' ./etc/depmod*' -print0)
1463+ )
1464+ }
1465+
1466+ function repack_deb() {
1467+ deb_name=$1
1468+ deb_dir=$2
1469+ temp_deb=$( mktemp /tmp/deb.XXXXXX)
1470+
1471+ logmust fakeroot dpkg-deb -b " $deb_dir " " $temp_deb "
1472+ logmust mv " $temp_deb " " $deb_name "
1473+ }
1474+
1475+ #
1476+ # Sign .ko files in the module list
1477+ #
1478+ function sign_modules() {
1479+ deb_pkgs=" $1 "
1480+ echo_bold " Signing $deb_pkgs "
1481+ download_keys
1482+
1483+ while IFS= read -r pkg; do
1484+ echo_bold " Processing $pkg "
1485+ temp_dir=$( mktemp -d -p " /var/tmp/" )
1486+ logmust fakeroot dpkg-deb -R " $pkg " " $temp_dir "
1487+
1488+ # Find and sign all .ko files in package
1489+ find " $temp_dir " -type f -name " *.ko" -print0 |
1490+ while IFS= read -r -d ' ' kernel_mod; do
1491+ logmust kmodsign sha256 " $SBSIGN_KEY " " $SBSIGN_DER " " $kernel_mod " " $kernel_mod .signed"
1492+ logmust mv " $kernel_mod .signed" " $kernel_mod "
1493+ logmust modinfo -F signer " $kernel_mod "
1494+ done
1495+ # Repack the .deb"
1496+ update_md5sums " $temp_dir "
1497+ repack_deb " $pkg " " $temp_dir "
1498+ done <<< " $deb_pkgs"
1499+ delete_keys
1500+ }
0 commit comments