eBPF-based security platform
testing: check image-mode boot and command restrictions
KP Singh72fd83ee2588
diff --git a/Makefile.shirudo b/Makefile.shirudoindex c7878d6e..8f2b6d94 100644--- a/Makefile.shirudo+++ b/Makefile.shirudo@@ -556,6 +556,10 @@ verity-test-helpers: $(VERITY_TEST_HELPERS)# Compiled test helpers (also usable as fuzz entry points).TEST_HELPERS := $(VERITY_TEST_HELPERS) \+ testing/helper/test-image-cli \+ testing/helper/test-image-config \+ testing/helper/test-config-image \+ testing/helper/test-image-keys \testing/helper/test-json-parser \testing/helper/test-string \testing/helper/test-conditions \@@ -740,7 +744,25 @@ testing/helper/test-config-image: testing/helper/test-config-image.c \+testing/helper/test-image-keys: testing/helper/test-image-keys.c \+ util/image_keys.o util/keys.o $(REGISTER_OBJS)+ @printf ' CC $@\n'+ $(Q)$(CC) $(CFLAGS) -o $@ $^ $(REGISTER_LIBS)++testing/helper/test-image-config: testing/helper/test-image-config.c \+ util/config.o util/image_config.o util/io.o util/log.o util/malloc.o util/hex.o \+ util/string.o+ @printf ' CC $@\n'+ $(Q)$(CC) $(CFLAGS) -o $@ $^+testing/helper/test-image-cli: testing/helper/test-image-cli.c builtin-bpm.c \+ $(filter-out $(call obj,builtin-bpm.o),$(BUILTIN_OBJS)) \+ $(UTIL_OBJS) $(VERSION_OBJ) $(LIBBPF_A)+ @printf ' CC $@\n'+ $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(RPATH_LDFLAGS) -o $@ \+ $(filter-out builtin-bpm.c,$^) \+ -Wl,--wrap=bpm_tree_fetch_publication \+ $(STATIC_LIBS) $(DYNAMIC_LIBS)test-helpers: $(TEST_HELPERS)diff --git a/contrib/build-test-vm-bundle.sh b/contrib/build-test-vm-bundle.shindex ddda8032..2accd985 100755--- a/contrib/build-test-vm-bundle.sh+++ b/contrib/build-test-vm-bundle.sh@@ -26,6 +26,7 @@ STAMP_FILE="${TEST_VM_BUNDLE_STAMP:-${BUNDLE_DIR}/.stamp}"STAMP_INPUTS="${TEST_VM_BUNDLE_INPUTS:-}"PACKAGE_CERT="${TEST_VM_PACKAGE_CERT:-}"RUNTIME_PREP_VERSION=4+TEST_VM_MODE=${TEST_VM_MODE:-legacy}RUNTIME_DISK_SIZE="${TEST_VM_RUNTIME_DISK_SIZE:-8G}"log()@@ -204,6 +205,10 @@ done# which Ubuntu 24.04 no longer installs; without it apt in the appliance# reaches nothing.[[ "$TEST_VM_HOST_PKG" != apt ]] || require_command dhclient isc-dhcp-client+if [[ "$TEST_VM_MODE" == verity ]]; then+ require_command veritysetup cryptsetup-bin cryptsetup+ require_command mkfs.ext4 e2fsprogs e2fsprogs+ficheck_libguestfs_hostresolve_rootfs()@@ -263,6 +268,9 @@ bundle_is_current(){local input+ [[ -s "$BUNDLE_DIR/test-mode" &&+ "$(cat "$BUNDLE_DIR/test-mode")" == "$TEST_VM_MODE" ]] || return 1+[[ -f "$STAMP_FILE" && -n "$STAMP_INPUTS" ]] || return 1[[ -x "$BUNDLE_DIR/root/usr/local/bin/shirudo" ]] || return 1[[ -s "$BUNDLE_DIR/runtime-image-key" ]] || return 1@@ -278,6 +286,7 @@ bundle_is_current()command -v flock >/dev/null 2>&1 ||die "flock is required; install it with: $(test_vm_install_cmd util-linux)"+case "$TEST_VM_MODE" in legacy|verity) ;; *) die "invalid TEST_VM_MODE" ;; esacvalidate_package_certmkdir -p "$(dirname "$BUNDLE_DIR")"@@ -305,6 +314,10 @@ cleanup()trap cleanup EXITmake -C "$REPO_ROOT" DESTDIR="$TMP_DIR/root" install-target+if [[ "$TEST_VM_MODE" == verity ]]; then+ make -C "$REPO_ROOT" -j"$(nproc)" -f Makefile.shirudo \+ PROFILE=target CONFIG_MK=config-target.mk verity-test-helpers+fiinstall -d "$TMP_DIR/test-helpers/testing/helper" \"$TMP_DIR/test-helpers/testing/upatch/kernel-obs/exec"@@ -330,6 +343,7 @@ testing/helper/otel-mock.pytesting/helper/test-oci-registry.pyEOF+build_fixture(){local source="$1"@@ -720,6 +734,12 @@ fithird.vouch package-cert.der > manifest)+if [[ "$TEST_VM_MODE" == verity ]]; then+ "$REPO_ROOT/contrib/verity-vm-bundle.sh" "$TMP_DIR" "$FIXTURE_WORK" \+ "$FIXTURE_WORK/trusted" "$FIXTURE_WORK/own"+fi+printf '%s\n' "$TEST_VM_MODE" >"$TMP_DIR/test-mode"+printf 'shirudo-test-vm-bundle-v1\n' >"$TMP_DIR/format"printf 'vendored-tools\n' >"$TMP_DIR/dependency-mode"printf 'shirudo-test-vm-bundle-stamp-v1\n' >"$TMP_DIR/.stamp"diff --git a/contrib/test-vm-guest.sh b/contrib/test-vm-guest.shindex c8b55679..13a4f624 100755--- a/contrib/test-vm-guest.sh+++ b/contrib/test-vm-guest.sh@@ -19,6 +19,8 @@ UPPER=/var/tmp/shirudo-upperOVERLAY_WORK=/var/tmp/shirudo-overlay-workWORKSPACE=/workspace/shirudoVM_MODE="${VM_MODE:-test}"+TEST_MODE="${TEST_VM_MODE:-legacy}"+SHIRUDO_BIN=/usr/local/bin/shirudoSKIP_SEAL="${TEST_VM_SKIP_SEAL:-0}"VM_INITRD="${TEST_VM_INITRD:-0}"@@ -71,7 +73,14 @@ install_kernel_modules()modprobe "$module"donefor module in veth bridge 8021q nf_flow_table nf_flow_table_inet; do- lsmod | awk -v module="$module" '$1 == module { found = 1 } END { exit !found }'+ if [[ -d "/sys/module/$module" ]]; then+ continue+ fi+ # Built-in modules without parameters need not appear in sysfs.+ grep -Eq "(^|/)$module\.ko$" "$target/modules.builtin" || {+ log "required networking module is unavailable: $module"+ return 1+ }done# nf_flow_table_procfs (CONFIG_NF_FLOW_TABLE_PROCFS) is built into# nf_flow_table.ko when enabled; it therefore does not have a separate@@ -322,6 +331,23 @@ test -c /dev/tpm0test -c /dev/tpmrm0tpm2_getrandom 8 >/dev/null+if [[ "$TEST_MODE" == verity ]]; then+ (cd "$BUNDLE/verity" && sha256sum -c manifest)+ mountpoint -q /run/shirudo/runtime+ mountpoint -q /run/shirudo/config+ install -m 0755 "$BUNDLE/verity/shirudo-runtime" /usr/local/bin/shirudo-runtime+ SHIRUDO_BIN=/usr/local/bin/shirudo-runtime+ for unit in "${TARGET_UNITS[@]}"; do+ case "$unit" in *.service) ;; *) continue ;; esac+ mkdir -p "/etc/systemd/system/$unit.d"+ {+ printf '[Service]\nExecStart=\n'+ sed -n 's|^ExecStart=/usr/local/bin/shirudo |ExecStart=/usr/local/bin/shirudo-runtime |p' \+ "/usr/lib/systemd/system/$unit"+ } >"/etc/systemd/system/$unit.d/runtime.conf"+ done+ systemctl daemon-reload+elselog "importing operator certificate and attaching the measured Shirudo LSM"install -d -m 0700 /var/lib/shirudo/keys@@ -358,11 +384,15 @@ if [[ "$SKIP_SEAL" == 1 ]]; thenficonfigure_bpm_tree/usr/local/bin/shirudo init "${init_args[@]}"+fi+if [[ "$TEST_MODE" == verity ]]; then+ "$SHIRUDO_BIN" init+fitest -e /run/shirudo/bpffs/lsm_linkif [[ "$VM_INITRD" == 1 ]]; thenlog "checking that the initrd brought enforcement up"journalctl -b -u shirudo-initrd.service --no-pager | tail -20 || true- /usr/local/bin/shirudo status --json | python3 -c '+ "$SHIRUDO_BIN" status --json | python3 -c 'import json, sysd = json.load(sys.stdin)assert d["mode"] == "production", d["mode"]@@ -370,7 +400,7 @@ assert d["tpm"]["bound_in"] == "initrd", d["tpm"]'test ! -e /run/shirudo/eventlog.pendingfi-/usr/local/bin/shirudo status --json >/tmp/shirudo-status.json+"$SHIRUDO_BIN" status --json >/tmp/shirudo-status.jsonpython3 - /tmp/shirudo-status.json <<'PY'import jsonimport sys@@ -424,20 +454,24 @@ log "running target test suite: ${TEST_VM_SUITE:-all}": >/mnt/shirudo-out/failed-suites(cd testing+ export SHIRUDO_BIN+ export SHIRUDO_TEST_MODE="$TEST_MODE"+ export SHIRUDO_TEST_KEY_FIXTURES="$BUNDLE/verity"+ export SHIRUDO_TEST_RESULTS=/mnt/shirudo-out/verityif [[ "${TEST_VM_SUITE:-all}" == obs ]]; then- SHIRUDO_BIN=/usr/local/bin/shirudo \+ SHIRUDO_BIN="$SHIRUDO_BIN" \SHIRUDO_TEST_FIXTURES_DIR="$BUNDLE/fixtures" \SHIRUDO_TEST_FAILURES_FILE=/mnt/shirudo-out/failed-tests \SHIRUDO_TEST_SUITE_FAILURES_FILE=/mnt/shirudo-out/failed-suites \./run-target-obs-tests.shelif [[ "${TEST_VM_SUITE:-all}" == tree ]]; then- SHIRUDO_BIN=/usr/local/bin/shirudo \+ SHIRUDO_BIN="$SHIRUDO_BIN" \SHIRUDO_TEST_FIXTURES_DIR="$BUNDLE/fixtures" \SHIRUDO_TEST_FAILURES_FILE=/mnt/shirudo-out/failed-tests \SHIRUDO_TEST_SUITE_FAILURES_FILE=/mnt/shirudo-out/failed-suites \./run-target-tree-tests.shelse- SHIRUDO_BIN=/usr/local/bin/shirudo \+ SHIRUDO_BIN="$SHIRUDO_BIN" \SHIRUDO_TEST_FIXTURES_DIR="$BUNDLE/fixtures" \SHIRUDO_TEST_FAILURES_FILE=/mnt/shirudo-out/failed-tests \SHIRUDO_TEST_SUITE_FAILURES_FILE=/mnt/shirudo-out/failed-suites \diff --git a/contrib/test-vm-runtime-packages b/contrib/test-vm-runtime-packagesindex d99f4548..3aea1387 100644--- a/contrib/test-vm-runtime-packages+++ b/contrib/test-vm-runtime-packages@@ -1,4 +1,5 @@ca-certificates+e2fsprogskeyutilslibelf1t64libjson-c5diff --git a/contrib/test-vm.sh b/contrib/test-vm.shindex b927c4e4..79d7d23b 100755--- a/contrib/test-vm.sh+++ b/contrib/test-vm.sh@@ -63,6 +63,7 @@ DISK_SIZE="${TEST_VM_DISK_SIZE:-30G}"VM_TIMEOUT="${TEST_VM_TIMEOUT:-3600}"VM_MODE="${VM_MODE:-test}"VM_SUITE="${TEST_VM_SUITE:-all}"+TEST_MODE="${TEST_VM_MODE:-legacy}"SKIP_SEAL="${TEST_VM_SKIP_SEAL:-0}"VM_INITRD="${TEST_VM_INITRD:-0}"VM_INITRD_MODULES="${TEST_VM_INITRD_MODULES:-base systemd systemd-initrd dracut-systemd rootfs-block fs-lib udev-rules terminfo shirudo}"@@ -154,6 +155,16 @@ valid_vm_name()validate_mode(){+ case "$TEST_MODE" in+ legacy) ;;+ verity)+ [[ "$VM_INITRD" == 1 && "$SKIP_SEAL" == 0 ]] ||+ die "verity mode requires TEST_VM_INITRD=1 and TEST_VM_SKIP_SEAL=0"+ [[ "$VM_SUITE" == all && "$VM_MODE" == test ]] ||+ die "verity mode requires the complete test suite"+ ;;+ *) die "TEST_VM_MODE must be legacy or verity" ;;+ esaccase "$VM_MODE" ininteractive|test) ;;*) die "VM_MODE must be 'interactive' or 'test'" ;;@@ -949,7 +960,7 @@ kernel_release_of()# identity and the cloud-init stage later finds the files in place.build_initrd(){- local kver gen unit seed trusted fp+ local kver gen unit seed trusted fp certlocal -a argskver="$(kernel_release_of "$KERNEL")" ||@@ -983,12 +994,31 @@ EOFdie "cannot fingerprint the bundle's own certificate"cp "$TEST_VM_HOST_BUNDLE/fixtures/own.der" "$trusted/$fp.der"cp "$TEST_VM_HOST_BUNDLE/fixtures/own.vouch" "$trusted/$fp.vouch"+ if [[ "$TEST_MODE" == verity ]]; then+ [[ -s "$TEST_VM_HOST_BUNDLE/verity/manifest" ]] ||+ die "verity fixtures missing from the host bundle"+ (cd "$TEST_VM_HOST_BUNDLE/verity" && sha256sum -c manifest) ||+ die "verity fixture checksum mismatch"+ mkdir -p "$seed/shirudo-test-images"+ cp "$TEST_VM_HOST_BUNDLE/verity/"*.{img,verity,roothash,p7s} \+ "$seed/shirudo-test-images/"+ cp "$TEST_VM_HOST_BUNDLE/verity/bootstrap.conf" \+ "$seed/shirudo-test-images/bootstrap.conf"+ cat >>"$seed/usr/lib/systemd/system/shirudo-test-seed.service" <<'EOF'+ExecStart=/bin/sh -c 'mkdir -p /sysroot/var/lib/shirudo/images /sysroot/etc/shirudo && cp /shirudo-test-images/*.img /shirudo-test-images/*.verity /shirudo-test-images/*.roothash /shirudo-test-images/*.p7s /sysroot/var/lib/shirudo/images/ && cp /shirudo-test-images/bootstrap.conf /sysroot/etc/shirudo/shirudo.conf'+EOF+ fi+ cert="$RUN_DIR/cert.der"+ cp "$TEST_VM_HOST_BUNDLE/fixtures/cert.der" "$cert"args=(--kver "$kver" --output "$RUN_DIR/initrd.img"--binary "$TEST_VM_HOST_BUNDLE/root/usr/local/bin/shirudo"--binary-path /usr/local/bin/shirudo- --cert "$TEST_VM_HOST_BUNDLE/fixtures/cert.der"+ --cert "$cert"--trusted-dir "$trusted"--unit "$unit" --module-dir "$REPO_ROOT/tools/gen-initrd")+ if [[ "$TEST_MODE" == verity ]]; then+ args+=(--bootstrap-conf "$seed/shirudo-test-images/bootstrap.conf")+ fiif [[ -n "$KERNEL_ARTIFACT_DIR" ]]; thenargs+=(--kmoddir "$KERNEL_ARTIFACT_DIR/lib/modules")else@@ -1356,6 +1386,7 @@ if [[ -n "$KERNEL_ARTIFACT_DIR" ]]; thenEOFfiprintf ' export VM_MODE=%q\n' "$VM_MODE" >>"$USER_DATA"+printf ' export TEST_VM_MODE=%q\n' "$TEST_MODE" >>"$USER_DATA"printf ' export TEST_VM_SUITE=%q\n' "$VM_SUITE" >>"$USER_DATA"printf ' export TEST_VM_SKIP_SEAL=%q\n' "$SKIP_SEAL" >>"$USER_DATA"printf ' export TEST_VM_INITRD=%q\n' "$VM_INITRD" >>"$USER_DATA"@@ -1456,6 +1487,9 @@ log "booting $(basename "$KERNEL") with ${CPUS} CPUs and ${MEMORY} memory"# The bpf keyring is left open for init to enrol the certificate and# seal it, as a production initrd does.KERNEL_LSM_ARGS="lsm=bpf bpf.keyring_unsealed=1"+if [ "$TEST_MODE" = verity ]; then+ KERNEL_LSM_ARGS+=" dm_verity.keyring_unsealed=1"+fiKERNEL_NET_DEVICE="virtio-net-pci,netdev=net0"# The virt machine has no if=virtio mapping, so its disks are explicit PCIdiff --git a/contrib/verity-vm-bundle.sh b/contrib/verity-vm-bundle.shnew file mode 100755index 00000000..e5b23134--- /dev/null+++ b/contrib/verity-vm-bundle.sh@@ -0,0 +1,38 @@+#!/bin/bash+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++set -euo pipefail+source_dir=$(cd "$(dirname "$0")/.." && pwd)+[ "$#" -eq 4 ] || exit 2+bundle=$1+work=$2+keys=$3+boot_keys=$4+"$source_dir/contrib/verity-vm-config-fixtures.sh" --keys-dir "$keys" \+ --boot-keys-dir "$boot_keys" --output "$work/verity"+mkdir "$bundle/verity"+cp -a "$work/verity/public/." "$bundle/verity/"+cat >"$work/runtime.conf" <<'EOF'+config.image = /var/lib/shirudo/images/config-boot-keys+config.verification_key = /run/shirudo/runtime/etc/shirudo/config-cert.der+config.pcr = 14+tpm.tcti = device:/dev/tpmrm0+EOF+"$source_dir/tools/gen-image/shirudo-gen-runtime" \+ --binary "$bundle/root/usr/local/bin/shirudo" \+ --bootstrap-conf "$work/runtime.conf" --cert "$keys/cert.der" \+ --config-cert "$keys/cert.der" --output "$bundle/verity/runtime" \+ --keys-dir "$keys" --builder "$source_dir/tools/shirudo-build/shirudo-build" \+ --extra-binary "$source_dir/build/verity-tests/shirudo-policy-probe" \+ --unit-output "$bundle/verity/runtime-service.conf" \+ >"$bundle/verity/runtime.root"+printf 'runtime.image = /var/lib/shirudo/images/runtime\nruntime.root_hash = %s\n' \+ "$(cat "$bundle/verity/runtime.root")" >"$bundle/verity/bootstrap.conf"+command=$(sed -n 's/^ExecStart=\(.*\) init$/\1/p' \+ "$bundle/verity/runtime-service.conf")+[ -n "$command" ]+printf '#!/bin/sh\nexec %s "$@"\n' "$command" >"$bundle/verity/shirudo-runtime"+chmod 0755 "$bundle/verity/shirudo-runtime"+(cd "$bundle/verity" && sha256sum -- *.img *.verity *.roothash *.p7s *.der \+ *.fingerprint *.upatch bootstrap.conf runtime-service.conf shirudo-runtime >manifest)diff --git a/contrib/verity-vm-config-fixtures.sh b/contrib/verity-vm-config-fixtures.shnew file mode 100755index 00000000..320e6943--- /dev/null+++ b/contrib/verity-vm-config-fixtures.sh@@ -0,0 +1,158 @@+#!/bin/bash+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++set -euo pipefail+umask 077++source_dir=$(cd "$(dirname "$0")/.." && pwd)+keys_dir=+boot_keys_dir=+output=+builtin_key=${TEST_VM_BUILTIN_SIGNING_KEY:-}+builtin_cert=${TEST_VM_BUILTIN_SIGNING_CERT:-}+while [ $# -gt 0 ]; do+ case "$1" in+ --boot-keys-dir) boot_keys_dir=${2:?}; shift 2 ;;+ --keys-dir) keys_dir=${2:?}; shift 2 ;;+ --output) output=${2:?}; shift 2 ;;+ *)+ printf 'usage: %s --keys-dir <operator-keys> [--boot-keys-dir <operator-keys>] --output <new-directory>\n' \+ "$0" >&2+ exit 2+ ;;+ esac+done+[ -n "$keys_dir" ] && [ -n "$output" ] || exit 2+keys_dir=$(realpath "$keys_dir")+[ -s "$keys_dir/cert.der" ] && [ -s "$keys_dir/signing_key.pem" ]+[ ! -e "$output" ] && [ ! -L "$output" ] || {+ printf 'Refusing existing output: %s\n' "$output" >&2+ exit 1+}+if [ -n "$builtin_key$builtin_cert" ]; then+ [ -r "$builtin_key" ] && [ -r "$builtin_cert" ] || {+ printf 'both built-in signing key and certificate are required\n' >&2+ exit 1+ }+fi+operator="$source_dir/shirudo"+builder="$source_dir/tools/shirudo-build/shirudo-build"+validator="$source_dir/testing/helper/test-image-keys"+[ -x "$operator" ] && [ -x "$builder" ] && [ -x "$validator" ]+mkdir -m 0700 "$output"+output=$(realpath "$output")+mkdir "$output/private" "$output/public" "$output/source"++for name in boot live; do+ if [ "$name" = boot ] && [ -n "$boot_keys_dir" ]; then+ mkdir "$output/private/boot"+ cp "$boot_keys_dir/cert.der" "$boot_keys_dir/signing_key.pem" \+ "$output/private/boot/"+ else+ "$operator" genkey --keys-dir "$output/private/$name" \+ >"$output/$name-genkey.log" 2>&1+ fi+ "$operator" bpm key fingerprint "$output/private/$name/cert.der" \+ >"$output/public/$name.fingerprint"+ cp "$output/private/$name/cert.der" "$output/public/$name.der"+done+boot_fp=$(cat "$output/public/boot.fingerprint")+live_fp=$(cat "$output/public/live.fingerprint")+[[ "$boot_fp" =~ ^[a-f0-9]{64}$ ]] && [[ "$live_fp" =~ ^[a-f0-9]{64}$ ]]+[ "$boot_fp" != "$live_fp" ]+cp "$keys_dir/cert.der" "$output/public/primary.der"++for name in config-boot-keys config-live-new-key config-a config-b config-bad config-revoke \+ config-tree-stable config-tree-updated config-tree-deleted config-tree-restored \+ config-otel config-interrupted config-builtin; do+ [ "$name" != config-builtin ] || [ -n "$builtin_key" ] || continue+ root="$output/source/$name"+ mkdir -p "$root/etc/shirudo" "$root/keys/trusted" "$root/keys/revoked"+ printf 'eventlog.max_bytes = 0\nmap_export.tenant_id = %s\n' "$name" \+ >"$root/etc/shirudo/shirudo.conf"+ case "$name" in+ config-tree-*)+ mkdir -p "$root/etc/shirudo/bpm"+ printf 'env=tree-test\n' >"$root/etc/shirudo/node.labels"+ printf 'endpoint = oci://127.0.0.1:5443/shirudo/upatch-tree\nreference = %s\n' \+ "${name#config-tree-}" >"$root/etc/shirudo/bpm/upatch-tree.conf"+ ;;+ config-otel)+ cat >"$root/etc/shirudo/shirudo.conf" <<'EOF'+eventlog.max_bytes = 0+map_export.tenant_id = tenant-config-0000+map_export.otel_endpoint = http://127.0.0.1:5444+map_export.otel_insecure = true+map_export.otel_retries = 0+EOF+ ;;+ esac+ cp "$output/public/boot.der" "$root/keys/trusted/$boot_fp.der"+ "$builder" keys vouch "$output/public/boot.der" \+ -o "$root/keys/trusted/$boot_fp.vouch" --keys-dir "$keys_dir" \+ >"$output/$name-boot-vouch.log" 2>&1+ if [ "$name" = config-live-new-key ]; then+ cp "$output/public/live.der" "$root/keys/trusted/$live_fp.der"+ "$builder" keys vouch "$output/public/live.der" \+ -o "$root/keys/trusted/$live_fp.vouch" \+ --keys-dir "$output/private/boot" \+ >"$output/$name-live-vouch.log" 2>&1+ fi+ if [[ "$name" == config-revoke || "$name" == config-interrupted ]]; then+ cp "$output/public/boot.der" "$root/keys/revoked/$boot_fp.der"+ elif [ "$name" = config-bad ]; then+ printf 'invalid certificate\n' >"$root/keys/revoked/$boot_fp.der"+ fi+ if [ "$name" != config-bad ]; then+ "$validator" "$keys_dir/cert.der" "$root" >"$output/$name-validation.log"+ expected=2+ [[ "$name" != config-revoke && "$name" != config-interrupted ]] || expected=1+ [ "$name" != config-live-new-key ] || expected=3+ grep -q "signers=$expected" "$output/$name-validation.log"+ fi+ verify_cert="$keys_dir/cert.der"+ if [ "$name" = config-builtin ]; then+ truncate -s 8M "$output/private/builtin.img"+ mkfs.ext4 -q -F -b 4096 -O '^has_journal' -E root_owner=0:0 \+ -d "$root" "$output/private/builtin.img"+ "$builder" image build "$output/private/builtin.img" \+ -o "$output/public/$name" --key "$builtin_key" \+ --cert "$builtin_cert" >"$output/$name-build.log" 2>&1+ verify_cert="$builtin_cert"+ cp "$builtin_cert" "$output/public/builtin.der"+ else+ "$source_dir/tools/gen-image/shirudo-gen-image" --source "$root" \+ --output "$output/public/$name" --keys-dir "$keys_dir" --size 8 \+ --builder "$builder" >"$output/$name-build.log" 2>&1+ fi+ SHIRUDO_BUILD="$builder" "$operator" image verify "$output/public/$name" \+ --cert "$verify_cert" >"$output/public/$name.root"++done++"$builder" "$source_dir/testing/fixtures/basic.bpf.c" \+ -o "$output/public/shirudo-test-revoked-key.upatch" \+ --name shirudo-test-revoked-key \+ --vmlinux "$source_dir/vendor/linux/vmlinux.h" \+ --key "$output/private/boot/signing_key.pem" \+ --cert "$output/public/boot.der"++# These host checks validate the fixture graph before the real target test.+mkdir "$output/check-live" "$output/check-boot"+"$validator" "$keys_dir/cert.der" "$output/source/config-boot-keys" \+ "$output/check-boot" "$keys_dir/cert.der" "$output/public/boot.der" \+ >"$output/check-boot.log"+grep -qx 'extends=1 activations=1' "$output/check-boot.log"+grep -qx 'rc=0 mutations=0 signers=2' "$output/check-boot.log"+if "$validator" "$keys_dir/cert.der" "$output/source/config-live-new-key" \+ "$output/check-live" "$keys_dir/cert.der" "$output/public/boot.der" \+ >"$output/check-live.log"; then+ printf 'Unexpected acceptance of missing live signer\n' >&2+ exit 1+fi+grep -qx 'extends=0 activations=0' "$output/check-live.log"+grep -qx 'rc=-126 mutations=0 signers=3' "$output/check-live.log"+printf 'Target artifacts only: %s/public\n' "$output"+printf 'Private operator keys remain in: %s/private\n' \+ "$output"diff --git a/contrib/verity-vm-install.sh b/contrib/verity-vm-install.shnew file mode 100755index 00000000..045ad9a7--- /dev/null+++ b/contrib/verity-vm-install.sh@@ -0,0 +1,117 @@+#!/bin/bash+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++set -euo pipefail++source_dir=$(cd "$(dirname "$0")/.." && pwd)+state=${SHIRUDO_VERITY_VM_STATE:-$HOME/.linux-kernel-vscode/shirudo-verity}+kernel=+keys_dir=+probes=()+while [ $# -gt 0 ]; do+ case "$1" in+ --kernel) kernel=${2:?}; shift 2 ;;+ --keys-dir) keys_dir=${2:?}; shift 2 ;;+ --probe) probes+=("${2:?}"); shift 2 ;;+ *) printf 'usage: %s --kernel <built-kernel-tree> --keys-dir <operator-keys> [--probe <trusted-ELF>]\n' "$0" >&2; exit 2 ;;+ esac+done+[ -n "$kernel" ] && [ -n "$keys_dir" ] || exit 2+[ -f "$kernel/arch/x86/boot/bzImage" ] && [ -f "$kernel/include/config/kernel.release" ] || exit 1+[ -x "$source_dir/shirudo-target" ] && [ -x "$source_dir/tools/shirudo-build/shirudo-build" ] || exit 1+vm="$source_dir/contrib/verity-vm.sh"+"$vm" ssh 'test ! -e /run/shirudo/bpffs/lsm_link && test -w /var/lib/shirudo'+mkdir -p "$state/fixtures"+work=$(mktemp -d "$state/fixtures/build.XXXXXX")+install -m 0755 "$source_dir/shirudo-target" "$work/shirudo-target"+release=$(cat "$kernel/include/config/kernel.release")++for name in config-a config-b config-bad; do+ mkdir -p "$work/$name/etc/shirudo" "$work/$name/keys/trusted" "$work/$name/keys/revoked"+ printf 'eventlog.max_bytes = 0\nmap_export.tenant_id = %s\n' "$name" \+ >"$work/$name/etc/shirudo/shirudo.conf"+ if [ "$name" = config-bad ]; then+ printf 'invalid certificate\n' >"$work/$name/keys/revoked/0000000000000000000000000000000000000000000000000000000000000000.der"+ fi+ "$source_dir/tools/gen-image/shirudo-gen-image" --source "$work/$name" \+ --output "$work/$name" --keys-dir "$keys_dir" --size 8 \+ --builder "$source_dir/tools/shirudo-build/shirudo-build"+done+cat >"$work/runtime.conf" <<'EOF'+config.image = /var/lib/shirudo/images/config-a+config.verification_key = /run/shirudo/runtime/etc/shirudo/config-cert.der+config.pcr = 14+tpm.tcti = device:/dev/tpmrm0+EOF+extra=()+for probe in "${probes[@]}"; do+ extra+=(--extra-binary "$probe")+done+"$source_dir/tools/gen-image/shirudo-gen-runtime" --binary "$work/shirudo-target" \+ --bootstrap-conf "$work/runtime.conf" --cert "$keys_dir/cert.der" \+ --config-cert "$keys_dir/cert.der" --output "$work/runtime" \+ --keys-dir "$keys_dir" --builder "$source_dir/tools/shirudo-build/shirudo-build" \+ --unit-output "$work/runtime-service.conf" "${extra[@]}" >"$work/runtime-root"+runtime_command=$(sed -n 's/^ExecStart=\(.*\) init$/\1/p' "$work/runtime-service.conf")+[ -n "$runtime_command" ]+printf '#!/bin/sh\nexec %s "$@"\n' "$runtime_command" >"$work/shirudo-runtime"+printf 'runtime.image = /var/lib/shirudo/images/runtime\nruntime.root_hash = %s\n' \+ "$(cat "$work/runtime-root")" >"$work/bootstrap.conf"++make -C "$kernel" -j"$(nproc)" LLVM=1 INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH="$work/modules" modules_install++tar -C "$work/modules" -cf - "lib/modules/$release" | "$vm" ssh tar -xf - -C /+"$vm" push "$kernel/arch/x86/boot/bzImage" /boot/vmlinuz-shirudo-verity+"$vm" push "$work/shirudo-target" /usr/local/bin/shirudo+"$vm" push "$work/shirudo-runtime" /usr/local/bin/shirudo-runtime+"$vm" ssh 'mkdir -p /var/lib/shirudo/images /etc/shirudo /usr/lib/dracut/modules.d/90shirudo /etc/systemd/system/shirudo.service.d /root/test-results/verity'+for name in config-a config-b config-bad runtime; do+ for suffix in img verity roothash p7s; do+ "$vm" push "$work/$name.$suffix" "/var/lib/shirudo/images/$name.$suffix"+ done+done+"$vm" push "$work/bootstrap.conf" /etc/shirudo/shirudo.conf+"$vm" push "$work/runtime-service.conf" /etc/systemd/system/shirudo.service.d/verity.conf+"$vm" push "$source_dir/tools/gen-initrd/module-setup.sh" /usr/lib/dracut/modules.d/90shirudo/module-setup.sh+"$vm" push "$source_dir/tools/gen-initrd/shirudo-gen-initrd" /usr/local/bin/shirudo-gen-initrd+"$vm" push "$keys_dir/cert.der" /var/lib/shirudo/keys/cert.der+sed 's|@bindir@|/usr/local/bin|g' "$source_dir/systemd/shirudo-initrd.service.in" >"$work/shirudo-initrd.service"+"$vm" push "$work/shirudo-initrd.service" /usr/lib/systemd/system/shirudo-initrd.service++"$vm" ssh bash -s -- "$release" <<'GUEST'+set -euo pipefail+chmod 0755 /usr/local/bin/shirudo /usr/local/bin/shirudo-runtime /usr/local/bin/shirudo-gen-initrd /usr/lib/dracut/modules.d/90shirudo/module-setup.sh+mkdir -p /root/prototype-backup+if [ -d /var/lib/shirudo/upatches ] && [ ! -e /root/prototype-backup/upatches ]; then+ mv /var/lib/shirudo/upatches /root/prototype-backup/upatches+fi+mkdir -p /var/lib/shirudo/upatches+printf 'console=ttyS0,115200 root=/dev/vda rw nokaslr lsm=bpf bpf.keyring_unsealed=1 dm_verity.keyring_unsealed=1\n' >/etc/kernel/cmdline+/usr/local/bin/shirudo-gen-initrd --kver "$1" --output /boot/initrd-shirudo-verity.img \+ --binary /usr/local/bin/shirudo --binary-path /usr/local/bin/shirudo \+ --cert /var/lib/shirudo/keys/cert.der --bootstrap-conf /etc/shirudo/shirudo.conf \+ --unit /usr/lib/systemd/system/shirudo-initrd.service \+ -- --no-hostonly --no-hostonly-cmdline --add-drivers 'efivarfs dm_mod dm_verity loop ext4' \+ --modules 'base systemd systemd-initrd dracut-systemd rootfs-block fs-lib udev-rules terminfo shirudo' \+ >/root/test-results/verity/initrd-build.log 2>&1+ukify build --linux /boot/vmlinuz-shirudo-verity --initrd /boot/initrd-shirudo-verity.img \+ --cmdline @/etc/kernel/cmdline --os-release @/etc/os-release \+ --output /boot/shirudo-verity.efi >/root/test-results/verity/uki-build.log 2>&1+GUEST+"$vm" pull /boot/shirudo-verity.efi "$state/shirudo-verity.efi"+"$vm" pull /boot/initrd-shirudo-verity.img "$state/initrd-verity.img"+image_file=$(mktemp "$state/esp.img.XXXXXX")+trap 'rm -f "$image_file"' EXIT+truncate -s 256M "$image_file"+printf 'label: gpt\nstart=2048, type=U\n' | sfdisk "$image_file" >/dev/null+mformat -i "$image_file@@1048576" -F -v SHIRUDOV ::+mmd -i "$image_file@@1048576" ::/EFI ::/EFI/BOOT+mcopy -i "$image_file@@1048576" "$state/shirudo-verity.efi" ::/EFI/BOOT/BOOTX64.EFI+if [ ! -e "$state/esp.legacy.img" ]; then+ cp --reflink=auto --sparse=always "$state/esp.img" "$state/esp.legacy.img"+fi+mv "$image_file" "$state/esp.img"+trap - EXIT+touch "$state/verity-ready"+printf 'Fixtures: %s\nPrototype UKI ready. Stop the installation VM, then start the prototype VM.\n' "$work"diff --git a/contrib/verity-vm.sh b/contrib/verity-vm.shnew file mode 100755index 00000000..2973cac4--- /dev/null+++ b/contrib/verity-vm.sh@@ -0,0 +1,79 @@+#!/bin/bash+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++set -euo pipefail++state=${SHIRUDO_VERITY_VM_STATE:-$HOME/.linux-kernel-vscode/shirudo-verity}+key=${SHIRUDO_VERITY_VM_SSH_KEY:-$HOME/.ssh/linux-kernel-vscode-rsa}+port=${SHIRUDO_VERITY_VM_PORT:-5557}+gdb_port=${SHIRUDO_VERITY_VM_GDB_PORT:-1236}+command=${1:-help}+shift || true+ssh_args=(-p "$port" -i "$key" -o IdentitiesOnly=yes -o BatchMode=yes+ -o ConnectTimeout=5 -o StrictHostKeyChecking=accept-new+ -o UserKnownHostsFile="$state/known_hosts")++case "$command" in+ssh)+ exec ssh "${ssh_args[@]}" [email protected] "$@"+ ;;+push)+ [ $# -eq 2 ] || exit 2+ exec scp -O -P "$port" -i "$key" -o IdentitiesOnly=yes \+ -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile="$state/known_hosts" \+ "$1" "[email protected]:$2"+ ;;+pull)+ [ $# -eq 2 ] || exit 2+ exec scp -O -P "$port" -i "$key" -o IdentitiesOnly=yes \+ -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile="$state/known_hosts" \+ "[email protected]:$1" "$2"+ ;;+stop)+ exec ssh -n "${ssh_args[@]}" [email protected] poweroff+ ;;+start|start-install)+ [ -f "$state/debian-x86_64.img" ] || { echo "missing cloned rootfs in $state" >&2; exit 1; }+ ;;+*)+ printf 'usage: %s start-install|start|stop|ssh|push|pull [arguments]\n' "$0"+ exit 2+ ;;+esac++exec 9>"$state/vm.lock"+flock -n 9 || { echo 'prototype VM is already running' >&2; exit 1; }+mkdir -p "$state/tpm"+rm -f "$state/tpm.sock"+swtpm socket --tpm2 --tpmstate dir="$state/tpm" \+ --ctrl type=unixio,path="$state/tpm.sock" \+ --flags not-need-init,startup-clear &+tpm_pid=$!+trap 'kill "$tpm_pid" 2>/dev/null || true; wait "$tpm_pid" 2>/dev/null || true' EXIT+for ((attempt = 0; attempt < 50; attempt++)); do+ [[ -S "$state/tpm.sock" ]] && break+ kill -0 "$tpm_pid"+ sleep 0.1+done+[[ -S "$state/tpm.sock" ]]++if [[ "$command" == start-install ]]; then+ boot=(-kernel "$state/vmlinuz-bootstrap" -initrd "$state/initrd-bootstrap.img"+ -append 'console=ttyS0,115200 root=/dev/vda rw nokaslr lsm=bpf bpf.keyring_unsealed=1 rd.systemd.mask=shirudo-initrd.service systemd.mask=shirudo.service')+else+ [ -f "$state/verity-ready" ] || { echo 'install and verify the prototype UKI first' >&2; exit 1; }+ boot=(-drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.fd+ -drive if=pflash,format=raw,file="$state/OVMF_VARS_4M.fd"+ -drive if=virtio,format=raw,readonly=on,file="$state/esp.img")+fi+qemu-system-x86_64 -enable-kvm -cpu host -machine q35 -name shirudo-verity \+ -smp 4 -m 4G -display none -monitor none -serial stdio \+ -gdb tcp:127.0.0.1:"$gdb_port" \+ -qmp unix:"$state/qmp.sock",server=on,wait=off \+ -netdev user,id=net0,hostfwd=tcp:127.0.0.1:"$port"-:22 \+ -device virtio-net-pci,netdev=net0 \+ -drive file="$state/debian-x86_64.img",format=raw,if=virtio \+ -chardev socket,id=chrtpm,path="$state/tpm.sock" \+ -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis,tpmdev=tpm0 \+ "${boot[@]}" "$@"diff --git a/testing/Makefile b/testing/Makefileindex 3e491fc2..c0bf7376 100644--- a/testing/Makefile+++ b/testing/Makefile@@ -27,9 +27,14 @@ KERNEL_PATCHES ?= $(if $(wildcard $(ROOT)/kernel/*.patch),$(ROOT)/kernel/,)override KERNEL_PATCHES := $(if $(strip $(KERNEL_PATCHES)),$(call root-path,$(KERNEL_PATCHES)),)PACKAGE_FORMAT ?= $(call test-vm-arch,TEST_VM_HOST_PKG_FORMAT)+TEST_VM_MODE ?= legacy+ifneq ($(filter $(TEST_VM_MODE),legacy verity),$(TEST_VM_MODE))+ $(error TEST_VM_MODE must be legacy or verity)+endif+TEST_VM_INITRD ?= $(if $(filter verity,$(TEST_VM_MODE)),1,0)TEST_VM_WORK_DIR ?= build/test-vmoverride TEST_VM_WORK_DIR := $(call root-path,$(TEST_VM_WORK_DIR))-TEST_VM_BUNDLE_DIR ?= $(TEST_VM_WORK_DIR)/host-bundle-$(VM_KERNEL_TAG)$(KERNEL_COMMIT_SUFFIX)+TEST_VM_BUNDLE_DIR ?= $(TEST_VM_WORK_DIR)/host-bundle-$(VM_KERNEL_TAG)$(KERNEL_COMMIT_SUFFIX)-$(TEST_VM_MODE)TEST_VM_RUNTIME_CACHE_DIR ?= $(TEST_VM_WORK_DIR)/cache/runtimeoverride TEST_VM_RUNTIME_CACHE_DIR := $(call root-path,$(TEST_VM_RUNTIME_CACHE_DIR))TEST_VM_MAP_EXPORT_CA ?=@@ -111,7 +116,9 @@ TEST_VM_BUNDLE_SOURCES := $(sort $(wildcard \$(ROOT)/vendor/libbpf/include/linux/*.h \$(ROOT)/vendor/libbpf/include/uapi/linux/*.h \$(ROOT)/vendor/libbpf/include/asm/*.h \- $(ROOT)/testing/helper/*.c $(ROOT)/testing/helper/*.py \+ $(ROOT)/testing/helper/*.c $(ROOT)/testing/helper/*.h $(ROOT)/testing/helper/*.py \+ $(ROOT)/testing/tamperproof/*.c $(ROOT)/contrib/verity-*.sh \+ $(ROOT)/tools/gen-image/shirudo-gen-* \$(ROOT)/testing/upatch/kernel-obs/exec/*.c $(ROOT)/completion/* $(ROOT)/systemd/*.in \$(ROOT)/systemd/*.timer $(ROOT)/testing/fixtures/*.c $(ROOT)/testing/fixtures/*.lua \$(ROOT)/testing/fixtures/decoders/* \@@ -138,7 +145,8 @@ $(ROOT)/config.mk: $(ROOT)/Makefile.configtest-vm-bundle: $(VM_KERNEL_DEP) $(TEST_VM_BUNDLE_STAMP)$(TEST_VM_BUNDLE_STAMP): $(TEST_VM_BUNDLE_INPUTS)- $(Q)TEST_VM_HOST_BUNDLE="$(abspath $(TEST_VM_BUNDLE_DIR))" \+ $(Q)TEST_VM_MODE="$(TEST_VM_MODE)" TEST_VM_INITRD="$(TEST_VM_INITRD)" \+ TEST_VM_HOST_BUNDLE="$(abspath $(TEST_VM_BUNDLE_DIR))" \TEST_VM_WORK_DIR="$(abspath $(TEST_VM_WORK_DIR))" \TEST_VM_RUNTIME_CACHE_DIR="$(abspath $(TEST_VM_RUNTIME_CACHE_DIR))" \TEST_VM_UBUNTU_CODENAME="$(TEST_VM_UBUNTU_CODENAME)" \@@ -199,6 +207,7 @@ vm: $(VM_KERNEL_DEP) test-vm-bundleTEST_VM_PACKAGE_CERT="$(TEST_VM_PACKAGE_CERT)" \TEST_VM_BPM_OCI_REPOSITORY="$(TEST_VM_BPM_OCI_REPOSITORY)" \TEST_VM_BPM_OCI_INDEX_CERT="$(TEST_VM_BPM_OCI_INDEX_CERT)" \+ TEST_VM_MODE="$(TEST_VM_MODE)" TEST_VM_INITRD="$(TEST_VM_INITRD)" \TEST_VM_HOST_BUNDLE="$(abspath $(TEST_VM_BUNDLE_DIR))" \$(ROOT)/contrib/test-vm.shvm-console:@@ -222,6 +231,7 @@ test-tgt: $(VM_KERNEL_DEP) test-vm-bundleTEST_VM_OCI_CA="$(TEST_VM_OCI_CA)" \TEST_VM_BPM_OCI_REPOSITORY="$(TEST_VM_BPM_OCI_REPOSITORY)" \TEST_VM_BPM_OCI_INDEX_CERT="$(TEST_VM_BPM_OCI_INDEX_CERT)" \+ TEST_VM_MODE="$(TEST_VM_MODE)" TEST_VM_INITRD="$(TEST_VM_INITRD)" \TEST_VM_HOST_BUNDLE="$(abspath $(TEST_VM_BUNDLE_DIR))" \$(ROOT)/contrib/test-vm.sh@@ -238,6 +248,7 @@ test-tgt-obs: $(VM_KERNEL_DEP) test-vm-bundleTEST_VM_OCI_CA="$(TEST_VM_OCI_CA)" \TEST_VM_BPM_OCI_REPOSITORY="$(TEST_VM_BPM_OCI_REPOSITORY)" \TEST_VM_BPM_OCI_INDEX_CERT="$(TEST_VM_BPM_OCI_INDEX_CERT)" \+ TEST_VM_MODE="$(TEST_VM_MODE)" TEST_VM_INITRD="$(TEST_VM_INITRD)" \TEST_VM_HOST_BUNDLE="$(abspath $(TEST_VM_BUNDLE_DIR))" \$(ROOT)/contrib/test-vm.sh@@ -292,7 +303,8 @@ help:' make -C testing test-op' \' make -C testing test-helpers' \' make -C testing fuzz [FUZZ_SECONDS=60]' \- ' make -C testing test-tgt [TEST_VM_INITRD=1]' \+ ' make -C testing test-tgt TEST_VM_MODE=legacy [TEST_VM_INITRD=1]' \+ ' make -C testing test-tgt TEST_VM_MODE=verity (dracut initrd, root required)' \' make -C testing test-tgt-obs' \' make -C testing test-installer' \' make -C testing vm, vm-console, vm-ssh, vm-stop, or vm-clean' \diff --git a/testing/bpm/t1118-bpm-tree.sh b/testing/bpm/t1118-bpm-tree.shindex 0bee6718..858060a3 100755--- a/testing/bpm/t1118-bpm-tree.sh+++ b/testing/bpm/t1118-bpm-tree.sh@@ -26,15 +26,15 @@ do[ -s "$fixture" ] || test_skip_all "missing tree fixture: $fixture"done-[ ! -e "$TREE_CONFIG" ] || test_skip_all "tree config already exists"+[ "${SHIRUDO_TEST_MODE:-legacy}" = verity ] || [ ! -e "$TREE_CONFIG" ] || test_skip_all "tree config already exists"[ ! -e /var/lib/shirudo/bpm/upatch-tree ] ||test_skip_all "tree state already exists"-[ ! -e "$TREE_LABELS" ] || test_skip_all "node labels already exist"+[ "${SHIRUDO_TEST_MODE:-legacy}" = verity ] || [ ! -e "$TREE_LABELS" ] || test_skip_all "node labels already exist"cleanup(){tree_registry_stop- rm -f "$TREE_CONFIG" "$TREE_LABELS"+ tree_cleanup_configrm -rf "$WORK"}trap cleanup EXITdiff --git a/testing/bpm/t1119-bpm-tree-sequential.sh b/testing/bpm/t1119-bpm-tree-sequential.shindex 941c0995..90cbc455 100755--- a/testing/bpm/t1119-bpm-tree-sequential.sh+++ b/testing/bpm/t1119-bpm-tree-sequential.sh@@ -28,8 +28,8 @@ do[ -s "$fixture" ] || test_skip_all "missing tree fixture: $fixture"done-[ ! -e "$TREE_CONFIG" ] || test_skip_all "tree config already exists"-[ ! -e "$TREE_LABELS" ] || test_skip_all "node labels already exist"+[ "${SHIRUDO_TEST_MODE:-legacy}" = verity ] || [ ! -e "$TREE_CONFIG" ] || test_skip_all "tree config already exists"+[ "${SHIRUDO_TEST_MODE:-legacy}" = verity ] || [ ! -e "$TREE_LABELS" ] || test_skip_all "node labels already exist"[ "$(tree_state_field tree_id)" = shirudo-test-tree ] &&[ "$(tree_state_field last_seq)" = 2 ] ||test_skip_all "tree state is not where t1118 leaves it"@@ -42,7 +42,7 @@ cleanup()"$FIXTURES/shirudo-test-tree-skip.unload.upatch" \--no-precheck >/dev/null 2>&1 || truefi- rm -f "$TREE_CONFIG" "$TREE_LABELS"+ tree_cleanup_configrm -rf "$WORK"}trap cleanup EXITdiff --git a/testing/bpm/t1120-bpm-tree-delete.sh b/testing/bpm/t1120-bpm-tree-delete.shindex 7a69d9ea..e718b659 100755--- a/testing/bpm/t1120-bpm-tree-delete.sh+++ b/testing/bpm/t1120-bpm-tree-delete.sh@@ -27,8 +27,8 @@ do[ -s "$fixture" ] || test_skip_all "missing tree fixture: $fixture"done-[ ! -e "$TREE_CONFIG" ] || test_skip_all "tree config already exists"-[ ! -e "$TREE_LABELS" ] || test_skip_all "node labels already exist"+[ "${SHIRUDO_TEST_MODE:-legacy}" = verity ] || [ ! -e "$TREE_CONFIG" ] || test_skip_all "tree config already exists"+[ "${SHIRUDO_TEST_MODE:-legacy}" = verity ] || [ ! -e "$TREE_LABELS" ] || test_skip_all "node labels already exist"[ "$(tree_state_field tree_id)" = shirudo-test-tree ] &&[ "$(tree_state_field last_seq)" = 3 ] &&[ -e "$MATCH_PIN" ] ||@@ -42,7 +42,7 @@ cleanup()"$FIXTURES/shirudo-test-tree-match.unload.upatch" \--no-precheck >/dev/null 2>&1 || truefi- rm -f "$TREE_CONFIG" "$TREE_LABELS"+ tree_cleanup_configrm -rf "$WORK"}trap cleanup EXITdiff --git a/testing/helper/image-shirudo b/testing/helper/image-shirudonew file mode 100755index 00000000..3fbc4921--- /dev/null+++ b/testing/helper/image-shirudo@@ -0,0 +1,19 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++runtime=/run/shirudo/runtime+library_path=$runtime/lib:$runtime/lib64:$runtime/usr/lib:$runtime/usr/lib64+for directory in "$runtime"/lib/*-linux-gnu "$runtime"/usr/lib/*-linux-gnu; do+ [ -d "$directory" ] && library_path=$library_path:$directory+done+for loader in "$runtime"/lib64/ld-linux-x86-64.so.2 \+ "$runtime"/lib/ld-linux-aarch64.so.1 \+ "$runtime"/lib/ld-linux-riscv64-lp64d.so.1; do+ if [ -x "$loader" ]; then+ exec "$loader" --inhibit-cache --library-path "$library_path" \+ "$runtime/usr/bin/shirudo" "$@"+ fi+done+printf "image-shirudo: runtime ELF interpreter not found\n" >&2+exit 1diff --git a/testing/helper/otel-mock.py b/testing/helper/otel-mock.pyindex bd355962..a59197f5 100644--- a/testing/helper/otel-mock.py+++ b/testing/helper/otel-mock.py@@ -24,6 +24,7 @@ certificate and key the sink speaks HTTPS.import gzipimport http.serverimport json+import osimport pathlibimport sslimport sys@@ -122,7 +123,7 @@ class Handler(http.server.BaseHTTPRequestHandler):self.server.done = True-server = http.server.HTTPServer(("127.0.0.1", 0), Handler)+server = http.server.HTTPServer(("127.0.0.1", int(os.environ.get("SHIRUDO_TEST_OTEL_PORT", "0"))), Handler)server.done = Falseif tls:context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)diff --git a/testing/helper/test-image-cli.c b/testing/helper/test-image-cli.cnew file mode 100644index 00000000..44ecf8f7--- /dev/null+++ b/testing/helper/test-image-cli.c@@ -0,0 +1,91 @@+// SPDX-License-Identifier: BSD-2-Clause+/* Copyright (c) 2026 Authors of shirudo */++#include "../../builtin-bpm.c"+#include "util/config.h"++int __wrap_bpm_tree_fetch_publication(struct bpm_oci_client *client,+ const char *repository,+ const char *reference,+ const char *certificate,+ struct shirudo_tree_publication *pub,+ char *digest, size_t capacity);++int __wrap_bpm_tree_fetch_publication(struct bpm_oci_client *client,+ const char *repository,+ const char *reference,+ const char *certificate,+ struct shirudo_tree_publication *pub,+ char *digest, size_t capacity)+{+ (void)client;+ (void)repository;+ (void)reference;+ (void)pub;+ (void)digest;+ (void)capacity;+ puts(certificate);+ return 0;+}++int main(int argc, const char **argv)+{+ struct shirudo_config bootstrap;+ int fd, rc;++ if (argc < 3)+ return 2;+ fd = open(argv[1], O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);+ if (fd < 0)+ return 1;+ rc = config_load_path(&bootstrap, "/dev/null");+ if (!rc) {+ memcpy(bootstrap.tpm_owner_auth, "bootstrap-owner", 15);+ bootstrap.tpm_owner_auth_len = 15;+ snprintf(bootstrap.tpm_tcti, sizeof(bootstrap.tpm_tcti),+ "bootstrap-tcti");+ rc = shirudo_image_config_set(&bootstrap, fd);+ }+ close(fd);+ if (rc)+ return 1;+ if (!strcmp(argv[2], "bpm")) {+ rc = cmd_bpm(argc - 2, argv + 2);+ } else if (!strcmp(argv[2], "keys")) {+ rc = cmd_keys(argc - 2, argv + 2);+ } else if (!strcmp(argv[2], "config")) {+ rc = cmd_config(argc - 2, argv + 2);+ } else if (!strcmp(argv[2], "source") && argc == 4) {+ struct bpm_source source;++ rc = load_source(argv[3], &source);+ if (!rc) {+ char content[64];+ FILE *file = fopen(source.key_file, "r");++ if (!file) {+ rc = -errno;+ } else {+ if (!fgets(content, sizeof(content), file))+ rc = -EIO;+ else+ fputs(content, stdout);+ fclose(file);+ }+ }+ } else if (!strcmp(argv[2], "tree")) {+ struct shirudo_tree_publication publication = {};+ struct bpm_tree_config config = {};+ char digest[BPM_MAX_DIGEST];++ snprintf(config.endpoint, sizeof(config.endpoint),+ "oci://example.invalid/tree");+ snprintf(config.reference, sizeof(config.reference), "latest");+ rc = tree_fetch_publication(&config, &publication, digest,+ sizeof(digest));+ } else {+ rc = 2;+ }+ shirudo_image_config_clear();+ return rc ? 1 : 0;+}diff --git a/testing/helper/test-image-config.c b/testing/helper/test-image-config.cnew file mode 100644index 00000000..9db18397--- /dev/null+++ b/testing/helper/test-image-config.c@@ -0,0 +1,61 @@+// SPDX-License-Identifier: BSD-2-Clause+/* Copyright (c) 2026 Authors of shirudo */++#include <errno.h>+#include <fcntl.h>+#include <stdio.h>+#include <string.h>+#include <unistd.h>++#include "util/config.h"+#include "util/image_config.h"++int main(int argc, char **argv)+{+ struct shirudo_config bootstrap, effective;+ char resolved[4096];+ int fd, rc;++ if (argc < 3 || argc > 4)+ return 2;+ fd = open(argv[2], O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);+ if (fd < 0)+ return 1;+ rc = config_load_path(&bootstrap, "/dev/null");+ if (rc)+ goto out;+ memcpy(bootstrap.tpm_owner_auth, "bootstrap-owner", 15);+ bootstrap.tpm_owner_auth_len = 15;+ snprintf(bootstrap.tpm_tcti, sizeof(bootstrap.tpm_tcti),+ "bootstrap-tcti");+ if (!strcmp(argv[1], "validate")) {+ rc = shirudo_image_config_validate(fd);+ } else if (!strcmp(argv[1], "effective")) {+ rc = shirudo_image_config_set(&bootstrap, fd);+ if (!rc && !shirudo_image_config_get(&effective))+ rc = -EIO;+ if (!rc) {+ printf("owner=%.*s\ntcti=%s\nlimit=%llu\n",+ (int)effective.tpm_owner_auth_len,+ effective.tpm_owner_auth, effective.tpm_tcti,+ effective.eventlog_max_bytes);+ printf("registries=%s\n",+ shirudo_image_path(SHIRUDO_IMAGE_REGISTRIES));+ }+ } else if (!strcmp(argv[1], "relative") && argc == 4) {+ rc = shirudo_image_config_set(&bootstrap, fd);+ if (!rc)+ rc = shirudo_image_path_relative(resolved,+ sizeof(resolved),+ argv[3]);+ if (!rc)+ printf("resolved=%s\n", resolved);+ } else {+ rc = -EINVAL;+ }+out:+ shirudo_image_config_clear();+ close(fd);+ printf("rc=%d\n", rc);+ return rc ? 1 : 0;+}diff --git a/testing/helper/test-image-keys.c b/testing/helper/test-image-keys.cnew file mode 100644index 00000000..073f4a86--- /dev/null+++ b/testing/helper/test-image-keys.c@@ -0,0 +1,72 @@+// SPDX-License-Identifier: BSD-2-Clause+/* Copyright (c) 2026 Authors of shirudo */++#include <shirudo/misc.h>++#include <errno.h>+#include <fcntl.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <unistd.h>++#include "image_keys.h"+#include "malloc.h"+#include "keyring.h"+#include "keys.h"++static __u32 mutations;+static char **held;+static int held_count;++key_serial_t keyring_bpf_serial(void)+{+ return 42;+}++int keyring_holds_cert(key_serial_t ring, const __u8 *der,+ size_t size)+{+ int i;++ (void)ring;+ for (i = 0; i < held_count; i++) {+ __u8 *candidate = NULL;+ size_t length = 0;+ int rc;++ rc = keys_read_der(held[i], &candidate, &length);+ if (rc)+ return rc;+ rc = size == length && !memcmp(der, candidate, size);+ xfree(candidate, length);+ if (rc)+ return 1;+ }+ return 0;+}++int shirudo_keys_revoke_image(const __u8 *der, size_t size, bool boot)+{+ (void)der;+ (void)size;+ (void)boot;+ mutations++;+ return -EPERM;+}++int main(int argc, char **argv)+{+ struct shirudo_trusted_set set = {};+ int fd, rc;++ if (argc != 3)+ return 2;+ fd = open(argv[2], O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);+ if (fd < 0)+ return 2;+ rc = shirudo_keys_validate_image_set(argv[1], fd, &set);+ close(fd);+ printf("rc=%d mutations=%u signers=%zu\n", rc, mutations, set.n);+ return rc || mutations ? 1 : 0;+}diff --git a/testing/helper/test-keys.c b/testing/helper/test-keys.cindex bdca412b..afa34192 100644--- a/testing/helper/test-keys.c+++ b/testing/helper/test-keys.c@@ -59,15 +59,24 @@ int main(int argc, char **argv)printf("%s\n", rc == 1 ? "yes" : rc == 0 ? "no" : "error");return rc < 0 ? 1 : 0;}- rc = keys_load(argv[2], NULL,- argc < 4 || strcmp(argv[3], "primary"), &set);+ if (!strcmp(argv[1], "image")) {+ char primary[PATH_MAX];++ snprintf(primary, sizeof(primary), "%s/cert.der", argv[2]);+ rc = shirudo_keys_load_image(primary, argv[2], NULL, true,+ &set);+ } else {+ rc = keys_load(argv[2], NULL,+ argc < 4 || strcmp(argv[3], "primary"),+ &set);+ }if (!strcmp(argv[1], "reject"))return rc == -EINVAL ? 0 : 1;if (rc) {printf("rc=%d\n", rc);return 1;}- if (strcmp(argv[1], "load") == 0) {+ if (!strcmp(argv[1], "load") || !strcmp(argv[1], "image")) {printf("n=%zu revoked=%zu unvouched=%zu\n", set.n,set.n_revoked, set.n_unvouched);for (i = 0; i < set.n; i++) {diff --git a/testing/integration-lib.sh b/testing/integration-lib.shindex 98ffe695..810e09d8 100644--- a/testing/integration-lib.sh+++ b/testing/integration-lib.sh@@ -72,6 +72,11 @@ tree_state_field() {# Point the target at the fixture tree at the given reference.tree_configure() {+ if [ "${SHIRUDO_TEST_MODE:-legacy}" = verity ]; then+ "$SHIRUDO_BIN" image update \+ "$SHIRUDO_TEST_KEY_FIXTURES/config-tree-$1"+ return+ fimkdir -p /etc/shirudo/bpmprintf 'env=tree-test\n' >"$TREE_LABELS"printf '%s\n' \@@ -79,6 +84,11 @@ tree_configure() {"reference = $1" >"$TREE_CONFIG"}+tree_cleanup_config() {+ [ "${SHIRUDO_TEST_MODE:-legacy}" != verity ] || return 0+ rm -f "$TREE_CONFIG" "$TREE_LABELS"+}+# Serve the fixture registry $1 on 127.0.0.1:5443, logging requests to# $2/requests.log, and wait for it; tree_registry_stop ends it.tree_registry_start() {diff --git a/testing/otel/t1115-map-export-all.sh b/testing/otel/t1115-map-export-all.shindex 03b52a85..de69d7a0 100644--- a/testing/otel/t1115-map-export-all.sh+++ b/testing/otel/t1115-map-export-all.sh@@ -15,12 +15,19 @@ CONFIG=/etc/shirudo/shirudo.confWORK=$(mktemp -d)SERVER=""CONFIG_EXISTED=0-if [ -e "$CONFIG" ]; then cp "$CONFIG" "$WORK/config"; CONFIG_EXISTED=1; fi+if [ "${SHIRUDO_TEST_MODE:-legacy}" = verity ]; then+ export SHIRUDO_TEST_OTEL_PORT=5444+elif [ -e "$CONFIG" ]; then+ cp "$CONFIG" "$WORK/config"+ CONFIG_EXISTED=1+firestore() {[ -n "$SERVER" ] && kill "$SERVER" >/dev/null 2>&1 || true[ -n "$SERVER" ] && wait "$SERVER" 2>/dev/null || trueif [ -e "$PIN" ]; then "$SHIRUDO_BIN" upatch unload "$UNLOAD" --no-precheck >/dev/null 2>&1 || true; fi- if [ "$CONFIG_EXISTED" -eq 1 ]; then cp "$WORK/config" "$CONFIG"; else rm -f "$CONFIG"; fi+ if [ "${SHIRUDO_TEST_MODE:-legacy}" != verity ]; then+ if [ "$CONFIG_EXISTED" -eq 1 ]; then cp "$WORK/config" "$CONFIG"; else rm -f "$CONFIG"; fi+ firm -rf "$WORK"}trap restore EXIT@@ -38,7 +45,7 @@ assert isinstance(log["data"], dict)assert metric[0]["name"] == "shirudo.map_export.second"PYcat >"$WORK/otel.py" <<'PY'-import http.server, json, pathlib, sys+import http.server, json, os, pathlib, sysport_file, meta_file = map(pathlib.Path, sys.argv[1:3])paths, tenants = [], []class Handler(http.server.BaseHTTPRequestHandler):@@ -50,7 +57,7 @@ class Handler(http.server.BaseHTTPRequestHandler):self.send_header("Content-Length", str(len(body))); self.end_headers()self.wfile.write(body); self.server.done = len(paths) >= 4def log_message(self, *args): pass-server = http.server.HTTPServer(("127.0.0.1", 0), Handler)+server = http.server.HTTPServer(("127.0.0.1", int(os.environ.get("SHIRUDO_TEST_OTEL_PORT", "0"))), Handler)server.done = False; server.timeout = 5; port_file.write_text(str(server.server_port))while not server.done: server.handle_request()PY@@ -94,8 +101,12 @@ test_expect_success '--all auto exports mixed metric and log maps' 'i=0; while test ! -s "$WORK/otel.port" && test "$i" -lt 100; do i=$((i+1)); sleep .02; done;test -s "$WORK/otel.port" &&port=$(cat "$WORK/otel.port") &&- printf "%s\n" "map_export.tenant_id = tenant-config-0000" \- "map_export.otel_endpoint = http://127.0.0.1:1/ignored" >"$CONFIG" &&+ if [ "${SHIRUDO_TEST_MODE:-legacy}" = verity ]; then+ "$SHIRUDO_BIN" image update "$SHIRUDO_TEST_KEY_FIXTURES/config-otel"+ else+ printf "%s\n" "map_export.tenant_id = tenant-config-0000" \+ "map_export.otel_endpoint = http://127.0.0.1:1/ignored" >"$CONFIG"+ fi &&"$SHIRUDO_BIN" upatch map --all --otel --otel-endpoint="http://127.0.0.1:$port/base" &&"$SHIRUDO_BIN" upatch map --all --otel --tenant-id=tenant-uuid-1234 --otel-endpoint="http://127.0.0.1:$port/base";kill "$SERVER" >/dev/null 2>&1 || true; wait "$SERVER" 2>/dev/null || true; SERVER="";diff --git a/testing/otel/t1116-otel-backend.sh b/testing/otel/t1116-otel-backend.shindex c15e9f0a..d6f76599 100644--- a/testing/otel/t1116-otel-backend.sh+++ b/testing/otel/t1116-otel-backend.sh@@ -23,7 +23,13 @@ TIMER_WAS_ACTIVE=0[ -s "$UNLOAD" ] || test_skip_all "missing OTEL backend unload fixture"systemctl cat shirudo-map-export.service >/dev/null 2>&1 || test_skip_all "map-export service is not installed"systemctl cat shirudo-map-export.timer >/dev/null 2>&1 || test_skip_all "map-export timer is not installed"-if [ -e "$CONFIG" ]; then cp "$CONFIG" "$WORK/config"; CONFIG_EXISTED=1; fi+if [ "${SHIRUDO_TEST_MODE:-legacy}" = verity ]; then+ "$SHIRUDO_BIN" image update "$SHIRUDO_TEST_KEY_FIXTURES/config-otel"+ export SHIRUDO_TEST_OTEL_PORT=5444+elif [ -e "$CONFIG" ]; then+ cp "$CONFIG" "$WORK/config"+ CONFIG_EXISTED=1+fiif systemctl is-active --quiet shirudo-map-export.timer; then TIMER_WAS_ACTIVE=1; firestore() {systemctl stop shirudo-map-export.timer >/dev/null 2>&1 || true@@ -31,7 +37,9 @@ restore() {[ -n "$SERVER" ] && kill "$SERVER" >/dev/null 2>&1 || true[ -n "$SERVER" ] && wait "$SERVER" 2>/dev/null || trueif [ -e "$PIN" ]; then "$SHIRUDO_BIN" upatch unload "$UNLOAD" --no-precheck >/dev/null 2>&1 || true; fi- if [ "$CONFIG_EXISTED" -eq 1 ]; then cp "$WORK/config" "$CONFIG"; else rm -f "$CONFIG"; fi+ if [ "${SHIRUDO_TEST_MODE:-legacy}" != verity ]; then+ if [ "$CONFIG_EXISTED" -eq 1 ]; then cp "$WORK/config" "$CONFIG"; else rm -f "$CONFIG"; fi+ fi[ "$TIMER_WAS_ACTIVE" -eq 1 ] && systemctl start shirudo-map-export.timer >/dev/null 2>&1 || truerm -rf "$WORK"}@@ -39,7 +47,7 @@ trap restore EXITsystemctl stop shirudo-map-export.timer >/dev/null 2>&1 || truesystemctl stop shirudo-map-export.service >/dev/null 2>&1 || truecat >"$WORK/otel.py" <<'PY'-import http.server, json, pathlib, sys+import http.server, json, os, pathlib, sysport_file, meta_file = map(pathlib.Path, sys.argv[1:3])paths = []class Handler(http.server.BaseHTTPRequestHandler):@@ -50,7 +58,7 @@ class Handler(http.server.BaseHTTPRequestHandler):self.send_header("Content-Length", str(len(body))); self.end_headers()self.wfile.write(body)def log_message(self, *args): pass-server = http.server.HTTPServer(("127.0.0.1", 0), Handler)+server = http.server.HTTPServer(("127.0.0.1", int(os.environ.get("SHIRUDO_TEST_OTEL_PORT", "0"))), Handler)server.timeout = 1; port_file.write_text(str(server.server_port))while len(paths) < 4: server.handle_request()PY@@ -68,7 +76,8 @@ test_expect_success 'map-export service delivers both decoder-backed maps' 'i=0; while { test ! -s "$WORK/otel.port" || test ! -s "$WORK/otel.meta"; } && test "$i" -lt 100; do i=$((i+1)); sleep .1; done;test -s "$WORK/otel.port" &&port=$(cat "$WORK/otel.port") &&- printf "%s\n" "map_export.otel_endpoint = http://127.0.0.1:$port" "map_export.otel_insecure = true" "map_export.otel_retries = 0" >"$CONFIG" &&+ { [ "${SHIRUDO_TEST_MODE:-legacy}" = verity ] ||+ printf "%s\n" "map_export.otel_endpoint = http://127.0.0.1:$port" "map_export.otel_insecure = true" "map_export.otel_retries = 0" >"$CONFIG"; } &&"$SHIRUDO_BIN" upatch load "$LOAD" --no-precheck >/dev/null 2>&1 &&systemctl start shirudo-map-export.service &&systemctl start shirudo-map-export.timer;@@ -114,7 +123,8 @@ PYpython3 "$WORK/slow-otel.py" "$WORK/slow.port" "$WORK/slow.meta" & SERVER=$!;i=0; while test ! -s "$WORK/slow.port" && test "$i" -lt 100; do i=$((i+1)); sleep .1; done;port=$(cat "$WORK/slow.port") && test -n "$port" &&- printf "%s\n" "map_export.otel_endpoint = http://127.0.0.1:$port" "map_export.otel_insecure = true" "map_export.otel_retries = 0" >"$CONFIG" || return 1;+ { [ "${SHIRUDO_TEST_MODE:-legacy}" = verity ] ||+ printf "%s\n" "map_export.otel_endpoint = http://127.0.0.1:$port" "map_export.otel_insecure = true" "map_export.otel_retries = 0" >"$CONFIG"; } || return 1;(systemctl start shirudo-map-export.service >/dev/null 2>&1) & service_start=$!;systemctl start shirudo-map-export.timer && wait "$service_start";i=0; while { test ! -s "$WORK/slow.meta" || test "$(python3 -c "import json,sys; print(json.load(open(sys.argv[1]))['completed'])" "$WORK/slow.meta" 2>/dev/null || echo 0)" -lt 4; } && test "$i" -lt 300; do i=$((i+1)); sleep .1; done;diff --git a/testing/otel/t1117-otel-serialized-metric.sh b/testing/otel/t1117-otel-serialized-metric.shindex 0513aec1..7b131dd8 100644--- a/testing/otel/t1117-otel-serialized-metric.sh+++ b/testing/otel/t1117-otel-serialized-metric.sh@@ -22,7 +22,13 @@ TIMER_WAS_ACTIVE=0[ -s "$LOAD" ] || test_skip_all "missing serialized metric fixture"[ -s "$UNLOAD" ] || test_skip_all "missing serialized metric unload fixture"systemctl cat shirudo-map-export.service >/dev/null 2>&1 || test_skip_all "map-export service is not installed"-if [ -e "$CONFIG" ]; then cp "$CONFIG" "$WORK/config"; CONFIG_EXISTED=1; fi+if [ "${SHIRUDO_TEST_MODE:-legacy}" = verity ]; then+ "$SHIRUDO_BIN" image update "$SHIRUDO_TEST_KEY_FIXTURES/config-otel"+ export SHIRUDO_TEST_OTEL_PORT=5444+elif [ -e "$CONFIG" ]; then+ cp "$CONFIG" "$WORK/config"+ CONFIG_EXISTED=1+fiif systemctl is-active --quiet shirudo-map-export.timer; then TIMER_WAS_ACTIVE=1; firestore() {systemctl stop shirudo-map-export.timer >/dev/null 2>&1 || true@@ -30,7 +36,9 @@ restore() {[ -n "$SERVER" ] && kill "$SERVER" >/dev/null 2>&1 || true[ -n "$SERVER" ] && wait "$SERVER" 2>/dev/null || trueif [ -e "$SERIALIZER_PIN" ]; then "$SHIRUDO_BIN" upatch unload "$UNLOAD" --no-precheck >/dev/null 2>&1 || true; fi- if [ "$CONFIG_EXISTED" -eq 1 ]; then cp "$WORK/config" "$CONFIG"; else rm -f "$CONFIG"; fi+ if [ "${SHIRUDO_TEST_MODE:-legacy}" != verity ]; then+ if [ "$CONFIG_EXISTED" -eq 1 ]; then cp "$WORK/config" "$CONFIG"; else rm -f "$CONFIG"; fi+ fi[ "$TIMER_WAS_ACTIVE" -eq 1 ] && systemctl start shirudo-map-export.timer >/dev/null 2>&1 || truerm -rf "$WORK"}@@ -70,7 +78,7 @@ while len(bodies) < 4:PYcat >"$WORK/service.py" <<'PY'-import http.server, json, pathlib, sys, time+import http.server, json, os, pathlib, sys, timeport_file, body_file = map(pathlib.Path, sys.argv[1:3])requests = []class Handler(http.server.BaseHTTPRequestHandler):@@ -84,7 +92,7 @@ class Handler(http.server.BaseHTTPRequestHandler):self.end_headers()self.wfile.write(payload)def log_message(self, *args): pass-server = http.server.HTTPServer(("127.0.0.1", 0), Handler)+server = http.server.HTTPServer(("127.0.0.1", int(os.environ.get("SHIRUDO_TEST_OTEL_PORT", "0"))), Handler)server.timeout = 1port_file.write_text(str(server.server_port))deadline = time.monotonic() + 30@@ -125,7 +133,8 @@ test_expect_success 'serialized multi-page metrics preserve peek and drain interi=0; while test ! -s "$WORK/service.port" && test "$i" -lt 100; do i=$((i+1)); sleep .1; done;test -s "$WORK/service.port" &&port=$(cat "$WORK/service.port") &&- printf "%s\n" "map_export.otel_endpoint = http://127.0.0.1:$port" "map_export.otel_insecure = true" "map_export.otel_retries = 0" >"$CONFIG" &&+ { [ "${SHIRUDO_TEST_MODE:-legacy}" = verity ] ||+ printf "%s\n" "map_export.otel_endpoint = http://127.0.0.1:$port" "map_export.otel_insecure = true" "map_export.otel_retries = 0" >"$CONFIG"; } &&if ! systemctl start shirudo-map-export.service; thensystemctl status shirudo-map-export.service --no-pager >&2 || truejournalctl -u shirudo-map-export.service --no-pager -n 100 >&2 || truediff --git a/testing/run-target-tests.sh b/testing/run-target-tests.shindex e388a018..24f29c82 100755--- a/testing/run-target-tests.sh+++ b/testing/run-target-tests.sh@@ -9,6 +9,17 @@ set -eucd "$(dirname "$0")"+case "${SHIRUDO_TEST_MODE:-legacy}" in+legacy)+ if mountpoint -q /run/shirudo/runtime; then+ printf 'legacy suite refuses an active image runtime\n' >&2+ exit 1+ fi+ ;;+verity) exec sh ./run-target-verity-tests.sh ;;+*) printf 'SHIRUDO_TEST_MODE must be legacy or verity\n' >&2; exit 2 ;;+esac+# The keyring substitution test deliberately destroys the trust anchor.# It runs last.fail=0diff --git a/testing/run-target-verity-tests.sh b/testing/run-target-verity-tests.shnew file mode 100755index 00000000..33fd1608--- /dev/null+++ b/testing/run-target-verity-tests.sh@@ -0,0 +1,79 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++set -eu+cd "$(dirname "$0")"+export SHIRUDO_TEST_MODE=verity+: "${SHIRUDO_BIN:?runtime command is required}"+: "${SHIRUDO_TEST_FIXTURES_DIR:?signed upatch fixtures are required}"+: "${SHIRUDO_TEST_KEY_FIXTURES:?signed image fixtures are required}"+: "${SHIRUDO_TEST_RESULTS:=/tmp/shirudo-verity-results}"+: "${SHIRUDO_TEST_SUITE_FAILURES_FILE:=}"+[ "$(id -u)" = 0 ] && [ -x "$SHIRUDO_BIN" ] &&+ [ -e /run/shirudo/bpffs/task_authority ] &&+ mountpoint -q /run/shirudo/runtime && mountpoint -q /run/shirudo/config || {+ printf 'image suite requires an initialized image-mode target\n' >&2+ exit 1+}+for name in config-boot-keys config-live-new-key config-a config-b config-bad config-revoke \+ config-tree-stable config-tree-updated config-tree-deleted config-tree-restored \+ config-otel config-interrupted; do+ for suffix in img verity roothash p7s; do+ [ -s "$SHIRUDO_TEST_KEY_FIXTURES/$name.$suffix" ] &&+ [ -s "/var/lib/shirudo/images/$name.$suffix" ] || {+ printf 'missing required image fixture: %s.%s\n' "$name" "$suffix" >&2+ exit 1+ }+ done+done+mkdir -p "$SHIRUDO_TEST_RESULTS"+export SHIRUDO_BIN SHIRUDO_TEST_KEY_FIXTURES+export SHIRUDO_TEST_CONFIG_RESULTS="$SHIRUDO_TEST_RESULTS/config"+export SHIRUDO_TEST_SIGNER_RESULTS="$SHIRUDO_TEST_RESULTS/signers"+export SHIRUDO_TEST_INTERRUPTION_RESULTS="$SHIRUDO_TEST_RESULTS/interruption"+export SHIRUDO_TEST_CLI_RESULTS="$SHIRUDO_TEST_RESULTS/cli"+export SHIRUDO_TEST_REVOKE_RESULTS="$SHIRUDO_TEST_RESULTS/revocation"+fail=0+# Boot assertions precede updates; the interruption leaves state pending.+for t in \+ tamperproof/t1155-verity-boot-signers.sh \+ t1200-target-fixtures.sh \+ t1103-version-gate.sh \+ t1104-payload-mismatch.sh \+ t1107-load-unload.sh \+ t1108-tpm-chain.sh \+ t1111-upatch-get.sh \+ t1114-uprobe-multi.sh \+ tamperproof/t1110-lsm-deny.sh \+ tamperproof/t1112-prog-load-keyring-gate.sh \+ tamperproof/t1113-mount-lockdown.sh \+ tamperproof/t1135-pin-rename.sh \+ tamperproof/t1137-bpf-cmd-deny.sh \+ tamperproof/t1136-tamper-counters.sh \+ tamperproof/t1130-map-lockdown.sh \+ tamperproof/t1131-pr-set-mm-identity.sh \+ tamperproof/t1132-seal-scratch.sh \+ tamperproof/t1125-key-permission.sh \+ tamperproof/t1140-verity-authority.sh \+ tamperproof/t1150-verity-devices.sh \+ tamperproof/t1151-verity-process.sh \+ tamperproof/t1153-verity-hidden.sh \+ tamperproof/t1157-verity-cli.sh+do+ log="$SHIRUDO_TEST_RESULTS/$(basename "$t").log"+ rc=0+ sh "$t" >"$log" 2>&1 || rc=$?+ cat "$log"+ if grep -q '^1\.\.0 # SKIP' "$log"; then+ printf 'required image suite was skipped: %s\n' "$t" >&2+ rc=1+ fi+ if [ "$rc" -ne 0 ]; then+ fail=$((fail + 1))+ if [ -n "$SHIRUDO_TEST_SUITE_FAILURES_FILE" ]; then+ printf '%s\n' "$t" >>"$SHIRUDO_TEST_SUITE_FAILURES_FILE"+ fi+ fi+done+[ "$fail" -eq 0 ]diff --git a/testing/t0015-test-vm-cli.sh b/testing/t0015-test-vm-cli.shindex e6ca022b..a9875290 100755--- a/testing/t0015-test-vm-cli.sh+++ b/testing/t0015-test-vm-cli.sh@@ -280,7 +280,7 @@ test_expect_success 'the runtime image gives the appliance the host resolvers in! grep -qx -- "--install" "$WORK/dns-args" &&grep -q "cat /root/shirudo-nameservers >>/etc/resolv.conf" "$WORK/dns-args" &&grep -q "apt-get \$apt_opts update" "$WORK/dns-args" &&- grep -q "apt-get \$apt_opts install ca-certificates keyutils" "$WORK/dns-args" &&+ grep -q "apt-get \$apt_opts install ca-certificates e2fsprogs keyutils" "$WORK/dns-args" &&grep -q "ripgrep rsync" "$WORK/dns-args" &&run_dns "$WORK/no-such-resolv.conf" &&! test -s "$WORK/dns-ns" &&@@ -940,4 +940,37 @@ test_expect_success 'operator and target runners have disjoint explicit scopes'! grep -R -q "$forbidden" ../testing/Makefile ../contrib ../testing'+test_expect_success 'test-vm rejects unknown policy modes before boot' '+ ! TEST_VM_MODE=typo "$RUNNER" >"$WORK/policy-mode.out" 2>&1 &&+ grep -q "TEST_VM_MODE must be legacy or verity" "$WORK/policy-mode.out"+'++test_expect_success 'image VM requires initrd enrollment and complete guards' '+ ! TEST_VM_MODE=verity TEST_VM_INITRD=0 "$RUNNER" \+ >"$WORK/image-initrd.out" 2>&1 &&+ grep -q "verity mode requires TEST_VM_INITRD=1" "$WORK/image-initrd.out" &&+ ! TEST_VM_MODE=verity TEST_VM_INITRD=1 TEST_VM_SKIP_SEAL=1 "$RUNNER" \+ >"$WORK/image-seal.out" 2>&1 &&+ grep -q "TEST_VM_SKIP_SEAL=0" "$WORK/image-seal.out"+'++test_expect_success 'image VM refuses an incompatible partial suite' '+ ! TEST_VM_MODE=verity TEST_VM_INITRD=1 TEST_VM_SUITE=tree "$RUNNER" \+ >"$WORK/image-suite.out" 2>&1 &&+ grep -q "verity mode requires the complete test suite" "$WORK/image-suite.out"+'++test_expect_success 'target runner refuses an unknown policy mode' '+ ! SHIRUDO_TEST_MODE=typo sh ./run-target-tests.sh \+ >"$WORK/target-mode.out" 2>&1 &&+ grep -q "SHIRUDO_TEST_MODE must be legacy or verity" "$WORK/target-mode.out"+'++test_expect_success 'image target runner refuses missing fixture configuration' '+ ! SHIRUDO_TEST_MODE=verity SHIRUDO_BIN=/bin/true \+ SHIRUDO_TEST_FIXTURES_DIR= SHIRUDO_TEST_KEY_FIXTURES= \+ sh ./run-target-tests.sh >"$WORK/target-fixtures.out" 2>&1 &&+ grep -q "signed upatch fixtures are required" "$WORK/target-fixtures.out"+'+test_donediff --git a/testing/t0036-gen-initrd-cli.sh b/testing/t0036-gen-initrd-cli.shindex 5a490c4d..11bf78fc 100755--- a/testing/t0036-gen-initrd-cli.sh+++ b/testing/t0036-gen-initrd-cli.sh@@ -14,9 +14,15 @@ W=$(mktemp -d)trap 'rm -rf "$W"' EXITprintf 'not a certificate\n' >"$W/cert.der": >"$W/shirudo-target_0_amd64.deb"+printf "eventlog.max_bytes = 1048576\n" >"$W/ordinary.conf"+printf "runtime.image = /var/lib/shirudo/images/runtime\nruntime.root_hash = %064d\n" 0 >"$W/image.conf"test_expect_success 'the generator prints the kernel parameter the initrd needs' '- [ "$(bash $G --print-cmdline)" = "bpf.keyring_unsealed=1" ]+ [ "$(bash $G --bootstrap-conf "$W/ordinary.conf" --print-cmdline)" = "bpf.keyring_unsealed=1" ]+'++test_expect_success 'image bootstrap also enables boot enrollment in the dm-verity keyring' '+ [ "$(bash $G --bootstrap-conf "$W/image.conf" --print-cmdline)" = "bpf.keyring_unsealed=1 dm_verity.keyring_unsealed=1" ]'test_expect_success 'the generator refuses an unknown option' 'diff --git a/testing/t0037-keys-set.sh b/testing/t0037-keys-set.shindex b24d3753..2185986d 100755--- a/testing/t0037-keys-set.sh+++ b/testing/t0037-keys-set.sh@@ -73,4 +73,19 @@ test_expect_success 'malformed trusted certificates are rejected before or after./$H reject "$W/malformed"'+test_expect_success 'image revocation preserves historical vouches while excluding revoked signing keys' '+ rm "$W/keys/revoked/$fp_c.der" &&+ $SHB keys vouch "$W/c/cert.der" -o "$W/keys/trusted/$fp_c.vouch" \+ --keys-dir "$W/b" >/dev/null 2>&1 &&+ fp_a=$(../shirudo bpm key fingerprint "$W/a/cert.der" 2>/dev/null) &&+ cp "$W/a/cert.der" "$W/keys/revoked/$fp_a.der" &&+ cp "$W/b/cert.der" "$W/keys/revoked/$fp_b.der" &&+ ./$H image "$W/keys" >"$W/image-set" &&+ grep -qx "n=1 revoked=2 unvouched=0" "$W/image-set" &&+ grep -q "^$(sha "$W/c/cert.der") $fp_c trusted " "$W/image-set" &&+ ! grep -q "^$(sha "$W/a/cert.der") " "$W/image-set" &&+ ! grep -q "^$(sha "$W/b/cert.der") " "$W/image-set"+'++test_donediff --git a/testing/t0047-image-config.sh b/testing/t0047-image-config.shnew file mode 100755index 00000000..fbc1bcf4--- /dev/null+++ b/testing/t0047-image-config.sh@@ -0,0 +1,104 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++cd "$(dirname "$0")"+. ./test-lib.sh++H=${SHIRUDO_TEST_IMAGE_CONFIG_HELPER:-./helper/test-image-config}+[ -x "$H" ] || test_skip_all "test-image-config helper not built"+WORK=$(mktemp -d)+trap 'rm -rf "$WORK"' EXIT HUP INT TERM++source_tree() {+ mkdir -p "$WORK/$1/etc/shirudo/bpm/registries.d" \+ "$WORK/$1/etc/shirudo/bpm/keys" \+ "$WORK/$1/keys/trusted" "$WORK/$1/keys/revoked" &&+ printf "eventlog.max_bytes = 12345\n" >"$WORK/$1/etc/shirudo/shirudo.conf"+}++test_expect_success 'allowed settings are accepted while TPM bootstrap settings survive' '+ source_tree good &&+ "$H" effective "$WORK/good" >"$WORK/effective" &&+ grep -qx "limit=12345" "$WORK/effective" &&+ grep -qx "owner=bootstrap-owner" "$WORK/effective" &&+ grep -qx "tcti=bootstrap-tcti" "$WORK/effective"+'++test_expect_success 'config cannot override runtime, verification key, PCR or TPM bootstrap settings' '+ for key in config.verification_key config.pcr config.image runtime.image runtime.root_hash tpm.owner_auth tpm.tcti; do+ source_tree "$key" &&+ printf "%s = attacker\n" "$key" >>"$WORK/$key/etc/shirudo/shirudo.conf" &&+ ! "$H" validate "$WORK/$key" || exit 1+ done+'++test_expect_success 'malformed and oversized config lines are refused' '+ source_tree malformed && printf "not a setting\n" >>"$WORK/malformed/etc/shirudo/shirudo.conf" &&+ ! "$H" validate "$WORK/malformed" &&+ source_tree oversized &&+ python3 - "$WORK/oversized/etc/shirudo/shirudo.conf" <<"PY" &&+from pathlib import Path+import sys+Path(sys.argv[1]).write_text("#" + "x" * 2048 + "\n")+PY+ ! "$H" validate "$WORK/oversized"+'++test_expect_success 'the main settings file cannot be a symlink outside the verified filesystem' '+ source_tree linked-file &&+ mv "$WORK/linked-file/etc/shirudo/shirudo.conf" "$WORK/outside.conf" &&+ ln -s "$WORK/outside.conf" "$WORK/linked-file/etc/shirudo/shirudo.conf" &&+ ! "$H" validate "$WORK/linked-file"+'++test_expect_success 'intermediate directory symlinks cannot escape the verified image' '+ source_tree linked-dir &&+ mv "$WORK/linked-dir/etc" "$WORK/outside-etc" &&+ ln -s "$WORK/outside-etc" "$WORK/linked-dir/etc" &&+ ! "$H" validate "$WORK/linked-dir"+'++test_expect_success 'repository and trusted-key symlinks cannot supply mutable outside assets' '+ source_tree linked-assets &&+ printf mutable >"$WORK/outside.der" &&+ ln -s "$WORK/outside.der" "$WORK/linked-assets/etc/shirudo/bpm/keys/repository.der" &&+ ! "$H" validate "$WORK/linked-assets" &&+ source_tree linked-trusted &&+ ln -s "$WORK" "$WORK/linked-trusted/keys/trusted/outside" &&+ ! "$H" validate "$WORK/linked-trusted"+'++test_expect_success 'special files in config are refused without opening or blocking on them' '+ source_tree fifo && mkfifo "$WORK/fifo/etc/shirudo/bpm/keys/blocked" &&+ ! "$H" validate "$WORK/fifo"+'++test_expect_success 'relative lookup refuses absolute paths and parent traversal' '+ "$H" relative "$WORK/good" etc/shirudo/bpm/upatch-tree.conf >"$WORK/relative" &&+ grep -q "^resolved=/proc/self/fd/" "$WORK/relative" &&+ for path in /etc/shirudo/shirudo.conf ../outside.conf etc/../../outside.conf; do+ ! "$H" relative "$WORK/good" "$path" || exit 1+ done+'++test_expect_success 'caller environment cannot override authenticated effective TPM settings' '+ SHIRUDO_TPM_OWNER_AUTH=attacker SHIRUDO_TPM_TCTI=attacker \+ "$H" effective "$WORK/good" >"$WORK/env" &&+ grep -qx "owner=bootstrap-owner" "$WORK/env" &&+ grep -qx "tcti=bootstrap-tcti" "$WORK/env"+'++test_expect_success 'invalid export settings fail preparation before activation' '+ for setting in "map_export.otel_insecure = invalid" \+ "map_export.unknown = value" \+ "map_export.otel_retries = -1" \+ "map_export.s3_uri = s3://bucket/key" \+ "map_export.otlp_max_bytes = 1"; do+ source_tree bad-export &&+ printf "%s\n" "$setting" >>"$WORK/bad-export/etc/shirudo/shirudo.conf" &&+ ! "$H" validate "$WORK/bad-export" || exit 1+ done+'++test_donediff --git a/testing/t0050-image-keys.sh b/testing/t0050-image-keys.shnew file mode 100755index 00000000..5471e143--- /dev/null+++ b/testing/t0050-image-keys.sh@@ -0,0 +1,131 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++cd "$(dirname "$0")"+. ./test-lib.sh+H=${SHIRUDO_TEST_IMAGE_KEYS_HELPER:-$(pwd)/helper/test-image-keys}+SHB=../tools/shirudo-build/shirudo-build+[ -x "$H" ] || test_skip_all "test-image-keys helper not built"+[ -x "$SHB" ] || test_skip_all "shirudo-build not built"+W=$(mktemp -d)+trap 'rm -rf "$W"' EXIT HUP INT TERM++for key in a b c; do+ ../shirudo genkey --keys-dir "$W/$key" >/dev/null 2>&1 || {+ test_expect_success "image key fixture generation" false+ test_done+ }+ eval "fp_$key=$(../shirudo bpm key fingerprint "$W/$key/cert.der" 2>/dev/null)"+done++fresh() {+ mkdir -p "$W/$1/etc/shirudo" "$W/$1/keys/trusted" "$W/$1/keys/revoked" &&+ printf "eventlog.max_bytes = 0\n" >"$W/$1/etc/shirudo/shirudo.conf"+}++valid() {+ "$H" "$W/a/cert.der" "$W/$1" >"$W/result" &&+ grep -q "rc=0 mutations=0" "$W/result"+}++invalid() {+ ! "$H" "$W/a/cert.der" "$W/$1" >"$W/result" &&+ grep -q "mutations=0" "$W/result"+}++vouch() {+ cp "$W/$2/cert.der" "$W/$1/keys/trusted/$3.der" &&+ "$SHB" keys vouch "$W/$2/cert.der" \+ -o "$W/$1/keys/trusted/$3.vouch" --keys-dir "$W/$4" >/dev/null 2>&1+}++test_expect_success 'a config with only the authenticated initial signer passes without mutation' '+ fresh initial && valid initial && grep -q "signers=1" "$W/result"+'++test_expect_success 'a vouched boot signer and canonical revocation pass validation' '+ fresh replacement && vouch replacement b "$fp_b" a &&+ cp "$W/a/cert.der" "$W/replacement/keys/revoked/$fp_a.der" &&+ valid replacement && grep -q "signers=1" "$W/result"+'++test_expect_success 'revoked historical signers still validate earlier vouches' '+ fresh historical && vouch historical b "$fp_b" a &&+ vouch historical c "$fp_c" b &&+ cp "$W/a/cert.der" "$W/historical/keys/revoked/$fp_a.der" &&+ cp "$W/b/cert.der" "$W/historical/keys/revoked/$fp_b.der" &&+ valid historical && grep -q "signers=1" "$W/result"+'++test_expect_success 'revoking every admitted signer fails preflight' '+ fresh all-revoked &&+ cp "$W/a/cert.der" "$W/all-revoked/keys/revoked/$fp_a.der" &&+ invalid all-revoked+'++test_expect_success 'an uppercase revocation cannot bypass the last-signer check' '+ fresh uppercase && upper=$(printf %s "$fp_a" | tr a-f A-F) &&+ cp "$W/a/cert.der" "$W/uppercase/keys/revoked/$upper.der" &&+ invalid uppercase+'++test_expect_success 'a canonical filename with the wrong certificate fails preflight' '+ fresh mismatch &&+ cp "$W/b/cert.der" "$W/mismatch/keys/revoked/$fp_a.der" &&+ invalid mismatch+'++test_expect_success 'malformed DER fails even when another signer remains' '+ fresh malformed && vouch malformed b "$fp_b" a &&+ printf "not a certificate" >"$W/malformed/keys/revoked/$fp_a.der" &&+ invalid malformed+'++test_expect_success 'empty and oversized revocation records fail preflight' '+ fresh empty && : >"$W/empty/keys/revoked/$fp_a.der" && invalid empty &&+ fresh oversized && truncate -s 1048577 "$W/oversized/keys/revoked/$fp_a.der" &&+ invalid oversized+'++test_expect_success 'unknown revocation files and malformed names fail preflight' '+ for name in README bad.der abc.DE R.der; do+ fresh "unknown-$name" &&+ cp "$W/a/cert.der" "$W/unknown-$name/keys/revoked/$name" &&+ invalid "unknown-$name" || exit 1+ done+'++test_expect_success 'revocation symlinks cannot read mutable outside certificates' '+ fresh symlink &&+ ln -s "$W/a/cert.der" "$W/symlink/keys/revoked/$fp_a.der" &&+ invalid symlink+'++test_expect_success 'revocation FIFOs and directories fail without blocking' '+ fresh fifo && mkfifo "$W/fifo/keys/revoked/$fp_a.der" && invalid fifo &&+ fresh directory && mkdir "$W/directory/keys/revoked/$fp_a.der" &&+ invalid directory+'++test_expect_success 'a symlinked keys directory cannot escape the image' '+ fresh keys-link && rm -r "$W/keys-link/keys" &&+ ln -s "$W/replacement/keys" "$W/keys-link/keys" && invalid keys-link+'++test_expect_success 'an unvouched additional signer is refused before mutation' '+ fresh unvouched && cp "$W/b/cert.der" "$W/unvouched/keys/trusted/$fp_b.der" &&+ invalid unvouched+'++test_expect_success 'a corrupt vouch is refused before mutation' '+ fresh bad-vouch && vouch bad-vouch b "$fp_b" a &&+ printf "bad vouch" >"$W/bad-vouch/keys/trusted/$fp_b.vouch" && invalid bad-vouch+'++test_expect_success 'malformed additional certificates fail before mutation' '+ fresh bad-trusted && printf "invalid DER" >"$W/bad-trusted/keys/trusted/$fp_b.der" &&+ invalid bad-trusted+'++test_donediff --git a/testing/t0051-image-cli.sh b/testing/t0051-image-cli.shnew file mode 100755index 00000000..1a49471a--- /dev/null+++ b/testing/t0051-image-cli.sh@@ -0,0 +1,96 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++cd "$(dirname "$0")"+. ./test-lib.sh++H=${SHIRUDO_TEST_IMAGE_CLI_HELPER:-./helper/test-image-cli}+if [ ! -x "$H" ]; then+ printf "not ok 1 - test-image-cli helper is required\n1..1\n"+ exit 1+fi+WORK=$(mktemp -d)+trap 'rm -rf "$WORK"' EXIT HUP INT TERM+ROOT="$WORK/config"+REG="$ROOT/etc/shirudo/bpm/registries.d"+mkdir -p "$REG" "$ROOT/etc/shirudo/bpm/keys"+printf "eventlog.max_bytes = 12345\n" >"$ROOT/etc/shirudo/shirudo.conf"+printf "authenticated-key\n" >"$ROOT/etc/shirudo/bpm/keys/repo.der"+printf "host-key\n" >"$WORK/host.der"+FP=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef++source_file() {+ printf "endpoint = oci://example.invalid\nkey_file = %s\n" "$2" >"$REG/$1.conf"+}++refused() {+ if "$H" "$ROOT" "$@" >"$WORK/output" 2>"$WORK/error"; then+ return 1+ fi+ grep -q "image mode:" "$WORK/error" &&+ grep -q "signed.*config" "$WORK/error"+}++test_expect_success 'local repository mutations fail before changing config or keys' '+ source_file keep "$WORK/host.der" &&+ cp "$REG/keep.conf" "$WORK/before.conf" &&+ refused bpm config register add new oci://example.invalid --key-file "$WORK/host.der" &&+ refused bpm config register remove keep &&+ refused bpm config register rm keep &&+ cmp "$REG/keep.conf" "$WORK/before.conf" &&+ grep -qx host-key "$WORK/host.der" &&+ test ! -e "$REG/new.conf"+'++test_expect_success 'local key changes explain signed revocation and reboot enrollment' '+ refused keys add missing.der --vouch missing.vouch &&+ grep -q reboot "$WORK/error" &&+ refused keys revoke "$FP" &&+ grep -q "shirudo image update" "$WORK/error" &&+ refused bpm key add oci://example.invalid/package:latest &&+ grep -q reboot "$WORK/error" &&+ refused bpm key ad missing.der+'++test_expect_success 'read-only repository listing and command help remain available' '+ "$H" "$ROOT" bpm config register list >"$WORK/list" &&+ grep -qx keep "$WORK/list" &&+ "$H" "$ROOT" keys add --help &&+ "$H" "$ROOT" keys revoke --help &&+ "$H" "$ROOT" bpm key add --help &&+ "$H" "$ROOT" bpm key --list-cmds+'++test_expect_success 'config output identifies image settings and authenticated TPM origins' '+ SHIRUDO_TPM_TCTI=attacker SHIRUDO_TPM_OWNER_AUTH=attacker \+ "$H" "$ROOT" config >"$WORK/effective" &&+ grep -q "authenticated config image" "$WORK/effective" &&+ grep -qx "eventlog.max_bytes = 12345" "$WORK/effective" &&+ grep -qx "tpm.tcti = bootstrap-tcti # from runtime image" "$WORK/effective" &&+ grep -q "15 bytes; redacted; from runtime image" "$WORK/effective" &&+ ! grep -q attacker "$WORK/effective"+'++test_expect_success 'repository certificates resolve inside the held config image' '+ source_file relative etc/shirudo/bpm/keys/repo.der &&+ source_file conventional /etc/shirudo/bpm/keys/repo.der &&+ "$H" "$ROOT" source relative >"$WORK/key" &&+ grep -qx authenticated-key "$WORK/key" &&+ "$H" "$ROOT" source conventional >"$WORK/key" &&+ grep -qx authenticated-key "$WORK/key"+'++test_expect_success 'repository certificate references cannot escape to host files' '+ for path in "$WORK/host.der" ../host.der etc/../../host.der; do+ source_file escape "$path" &&+ ! "$H" "$ROOT" source escape || exit 1+ done+'++test_expect_success 'tree publications verify against the runtime trust anchor' '+ "$H" "$ROOT" tree >"$WORK/certificate" &&+ grep -qx /run/shirudo/runtime/keys/cert.der "$WORK/certificate"+'++test_donediff --git a/testing/tamperproof/t1131-pr-set-mm-identity.py b/testing/tamperproof/t1131-pr-set-mm-identity.pyindex fcb853e5..b7d42324 100644--- a/testing/tamperproof/t1131-pr-set-mm-identity.py+++ b/testing/tamperproof/t1131-pr-set-mm-identity.py@@ -10,12 +10,8 @@ import sysPR_SET_MM = 35PR_SET_MM_EXE_FILE = 13PR_SET_MM_MAP = 14-SHIRUDO = os.path.abspath(sys.argv[1])-SHIRUDO_ID = os.stat(SHIRUDO).st_dev, os.stat(SHIRUDO).st_ino-OTHER = next(os.path.realpath(path) for path in- ("/bin/true", "/usr/bin/true", sys.executable)- if os.path.isfile(path) and os.access(path, os.X_OK) and- (os.stat(path).st_dev, os.stat(path).st_ino) != SHIRUDO_ID)+SHIRUDO_COMMAND = os.path.abspath(sys.argv[1])+RUNTIME = "/run/shirudo/runtime"libc = ctypes.CDLL(None, use_errno=True)libc.prctl.argtypes = [ctypes.c_int, ctypes.c_ulong, ctypes.c_ulong,@@ -23,9 +19,25 @@ libc.prctl.argtypes = [ctypes.c_int, ctypes.c_ulong, ctypes.c_ulong,libc.prctl.restype = ctypes.c_intlibc.syscall.restype = ctypes.c_long+ctypes.set_errno(0)+mode_result = libc.prctl(0x53520001, 0, 0, 0, 0)+mode_errno = ctypes.get_errno()+assert mode_result == -1 and mode_errno in (errno.EINVAL, 1001, 1002), \+ ("Shirudo mode query", mode_result, mode_errno)+IMAGE_MODE = mode_errno == 1002+SHIRUDO = os.path.abspath(os.environ.get("SHIRUDO_TEST_RUNTIME_BIN",+ RUNTIME + "/usr/bin/shirudo")) \+ if IMAGE_MODE else SHIRUDO_COMMAND+SHIRUDO_ID = os.stat(SHIRUDO).st_dev, os.stat(SHIRUDO).st_ino+OTHER = next(os.path.realpath(path) for path in+ ("/bin/true", "/usr/bin/true", sys.executable)+ if os.path.isfile(path) and os.access(path, os.X_OK) and+ (os.stat(path).st_dev, os.stat(path).st_ino) != SHIRUDO_ID)+BPF_SYSCALL = {"x86_64": 321, "aarch64": 280,"riscv64": 280}[platform.machine()]BPF_OBJ_GET = 7+BPF_OBJ_GET_INFO_BY_FD = 15BPF_MAP_LOOKUP_ELEM = 1BPF_F_RDONLY = 1 << 3@@ -44,6 +56,21 @@ class MapElemAttr(ctypes.Structure):("flags", ctypes.c_uint64)]+class ObjInfoAttr(ctypes.Structure):+ _fields_ = [("bpf_fd", ctypes.c_uint32),+ ("info_len", ctypes.c_uint32),+ ("info", ctypes.c_uint64)]+++class MapInfoPrefix(ctypes.Structure):+ _fields_ = [("type", ctypes.c_uint32),+ ("id", ctypes.c_uint32),+ ("key_size", ctypes.c_uint32),+ ("value_size", ctypes.c_uint32),+ ("max_entries", ctypes.c_uint32),+ ("map_flags", ctypes.c_uint32)]++class ShirudoIdentity(ctypes.Structure):_fields_ = [("sb_dev", ctypes.c_uint32),("exe_dev", ctypes.c_uint32),@@ -58,6 +85,12 @@ class ShirudoIdentity(ctypes.Structure):("key_serials", ctypes.c_int32 * 16)]+class ShirudoImageIdentity(ShirudoIdentity):+ _fields_ = [("runtime_mode", ctypes.c_uint32),+ ("run_dev", ctypes.c_uint32),+ ("runtime_root", ctypes.c_uint8 * 32)]++def assert_frozen_executable_identity():path = b"/run/shirudo/bpffs/identity\0"name = ctypes.create_string_buffer(path)@@ -66,16 +99,40 @@ def assert_frozen_executable_identity():ctypes.sizeof(get_attr))assert fd >= 0, ("open identity map", ctypes.get_errno())try:+ info = MapInfoPrefix()+ info_attr = ObjInfoAttr(fd, ctypes.sizeof(info), ctypes.addressof(info))+ result = libc.syscall(BPF_SYSCALL, BPF_OBJ_GET_INFO_BY_FD,+ ctypes.byref(info_attr), ctypes.sizeof(info_attr))+ assert result == 0, ("identity map metadata", ctypes.get_errno())+ assert info.type == 2 and info.key_size == 4 and info.max_entries == 1, \+ ("identity map shape", info.type, info.key_size, info.max_entries)+ assert ctypes.sizeof(ShirudoIdentity) <= info.value_size <= 1024 * 1024, \+ ("identity map value size", info.value_size)key = ctypes.c_uint32(0)- value = ShirudoIdentity()+ buffer = ctypes.create_string_buffer(info.value_size)lookup_attr = MapElemAttr(fd, 0, ctypes.addressof(key),- ctypes.addressof(value), 0)+ ctypes.addressof(buffer), 0)result = libc.syscall(BPF_SYSCALL, BPF_MAP_LOOKUP_ELEM,ctypes.byref(lookup_attr),ctypes.sizeof(lookup_attr))assert result == 0, ("read identity map", ctypes.get_errno())finally:os.close(fd)+ value = ShirudoIdentity.from_buffer_copy(buffer.raw)+ if IMAGE_MODE:+ assert info.value_size >= ctypes.sizeof(ShirudoImageIdentity), \+ ("image identity extension missing", info.value_size)+ image = ShirudoImageIdentity.from_buffer_copy(buffer.raw)+ assert image.runtime_mode == 1 and any(image.runtime_root), \+ ("frozen image trust mode", image.runtime_mode)+ executable = os.path.realpath(SHIRUDO)+ runtime = os.path.realpath(RUNTIME)+ assert os.path.commonpath((executable, runtime)) == runtime, executable+ assert os.stat(executable).st_dev == os.stat(runtime).st_dev, executable+ return+ if info.value_size >= ctypes.sizeof(ShirudoImageIdentity):+ image = ShirudoImageIdentity.from_buffer_copy(buffer.raw)+ assert image.runtime_mode == 0, ("legacy trust mode", image.runtime_mode)st = os.stat(SHIRUDO)expected_dev = (os.major(st.st_dev) << 20) | os.minor(st.st_dev)assert (value.exe_dev, value.exe_ino) == (expected_dev, st.st_ino), \@@ -185,7 +242,8 @@ assert child_succeeds(lambda: mm_map_result(OTHER)), \def invalid_fd_then_exec():result, err = call_prctl(PR_SET_MM, PR_SET_MM_EXE_FILE, 1 << 30)assert result == -1 and err == errno.EPERM, (result, err)- os.execve(SHIRUDO, [SHIRUDO, "status", "--json"], os.environ.copy())+ os.execve(SHIRUDO_COMMAND, [SHIRUDO_COMMAND, "status", "--json"],+ os.environ.copy())assert child_succeeds(invalid_fd_then_exec), \diff --git a/testing/tamperproof/t1132-seal-scratch.sh b/testing/tamperproof/t1132-seal-scratch.shindex f6ea711c..21f40c53 100644--- a/testing/tamperproof/t1132-seal-scratch.sh+++ b/testing/tamperproof/t1132-seal-scratch.sh@@ -16,7 +16,10 @@ for c in python3 mkfs.ext4 debugfs; docommand -v "$c" >/dev/null 2>&1 || test_skip_all "no $c"done-STATE=/var/lib/shirudo/keys/cert.der+case "${SHIRUDO_TEST_MODE:-legacy}" in+verity) STATE=/var/lib/shirudo/eventlog ;;+*) STATE=/var/lib/shirudo/keys/cert.der ;;+esac[ -e "$STATE" ] || test_skip_all "no labelled state at $STATE"WORK=$(mktemp -d) || test_skip_all "cannot make a scratch directory"MNT=$WORK/mnt@@ -86,6 +89,7 @@ PYEOFtest_expect_success 'control: an unlabelled copy of a shell cannot open a labelled file for write' 'cp "$SH" "$WORK/ctl" &&+ "$WORK/ctl" -c ":" &&! "$WORK/ctl" -c ": >> $STATE" 2>/dev/null'@@ -97,6 +101,7 @@ os.setxattr(sys.argv[1], \"security.bpf.shirudo\", open(sys.argv[2], \"rb\").rea'test_expect_success 'a binary its file system labels cannot open a labelled file for write' '+ "$MNT/sh" -c ":" &&! "$MNT/sh" -c ": >> $STATE" 2>/dev/null'diff --git a/testing/tamperproof/t1155-verity-boot-signers.py b/testing/tamperproof/t1155-verity-boot-signers.pynew file mode 100644index 00000000..13cbeae3--- /dev/null+++ b/testing/tamperproof/t1155-verity-boot-signers.py@@ -0,0 +1,137 @@+#!/usr/bin/env python3+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++import ctypes+import hashlib+import importlib.util+import json+import os+from pathlib import Path+import platform+import secrets+import struct+import sys+++spec = importlib.util.spec_from_file_location(+ "config_test", Path(__file__).with_name("t1154-verity-config.py"))+config = importlib.util.module_from_spec(spec)+spec.loader.exec_module(config)+require = config.require+FIXTURES = Path(os.environ["SHIRUDO_TEST_KEY_FIXTURES"])+BOOT = FIXTURES / "config-boot-keys"+CANDIDATE = FIXTURES / "config-live-new-key"+ROOT = BOOT.with_suffix(".roothash").read_text()+LIBC = ctypes.CDLL(None, use_errno=True)+LIBC.syscall.restype = ctypes.c_long+ADD_KEY, KEYCTL = {"x86_64": (248, 250), "aarch64": (217, 219),+ "riscv64": (217, 219)}[platform.machine()]+++def syscall(number, *arguments):+ result = LIBC.syscall(ctypes.c_long(number),+ *(ctypes.c_long(value) for value in arguments))+ if result < 0:+ error = ctypes.get_errno()+ raise OSError(error, os.strerror(error))+ return result+++def describe(serial):+ buffer = ctypes.create_string_buffer(4096)+ length = syscall(KEYCTL, 6, serial, ctypes.addressof(buffer), len(buffer), 0)+ require(0 < length <= len(buffer), "key description overflow")+ fields = buffer.value.decode().split(";", 4)+ require(len(fields) == 5, "invalid key description")+ return fields+++def certificate_description(path):+ # A private thread-keyring probe gets the kernel's canonical certificate ID.+ der = path.read_bytes()+ payload = ctypes.create_string_buffer(der)+ key_type = ctypes.create_string_buffer(b"asymmetric")+ serial = syscall(ADD_KEY, ctypes.addressof(key_type), 0,+ ctypes.addressof(payload), len(der), -1)+ try:+ fields = describe(serial)+ require(fields[0] == "asymmetric", "unexpected probe key type")+ return fields[4]+ finally:+ syscall(KEYCTL, 9, serial, -1, 0, 0)+++def keyring(expected=2):+ # GET_KEYRING_ID requests unpossessed SEARCH; direct READ needs no search.+ serial = -9+ identity = describe(serial)+ require(identity[0] == "keyring" and identity[4] == ".bpf", identity)+ buffer = ctypes.create_string_buffer(4096)+ length = syscall(KEYCTL, 11, serial, ctypes.addressof(buffer), len(buffer), 0)+ require(0 < length <= len(buffer) and length % 4 == 0, "bad keyring read")+ keys = {str(key): describe(key)+ for (key,) in struct.iter_unpack("=i", buffer.raw[:length])}+ require(len(keys) == expected, f"expected {expected} boot-enrolled keys: {keys}")+ require(all(value[0] == "asymmetric" for value in keys.values()), keys)+ return {"serial": serial, "identity": identity, "keys": keys}+++def check_members(ring):+ descriptions = {fields[4] for fields in ring["keys"].values()}+ expected = {certificate_description(FIXTURES / name)+ for name in ("primary.der", "boot.der")}+ require(len(expected) == 2 and descriptions == expected,+ "the live .bpf keyring does not hold exactly primary and boot keys")+ require(certificate_description(FIXTURES / "live.der") not in descriptions,+ "the new live signer was already enrolled")+ for name in ("boot", "live"):+ fingerprint = (FIXTURES / (name + ".fingerprint")).read_text().strip()+ actual = config.run(name + "-fingerprint", "bpm", "key", "fingerprint",+ FIXTURES / (name + ".der")).strip()+ require(actual == fingerprint and len(fingerprint) == 64,+ f"wrong fixture fingerprint: {name}")+ if name == "boot":+ trusted = config.CONFIG / "keys/trusted"+ require((trusted / (fingerprint + ".der")).read_bytes() ==+ (FIXTURES / "boot.der").read_bytes(), "wrong mounted boot key")+ require((trusted / (fingerprint + ".vouch")).stat().st_size > 0,+ "boot signer has no vouch")+++def snapshot(label):+ effects = config.snapshot(label)+ effects["keyring"] = keyring()+ require(effects["status"]["root_hash"] == ROOT, "wrong boot root")+ require("map_export.tenant_id = config-boot-keys\n" in effects["settings"],+ "wrong boot configuration")+ config.save(label, effects)+ return effects+++def main():+ require(len(ROOT) == 64, "wrong boot root size")+ mode = sys.argv[1]+ if mode == "initial":+ (config.RESULTS / "anchor.json").unlink(missing_ok=True)+ check_members(keyring())+ snapshot("initial")+ elif mode in ("new-signer", "repeat"):+ before = snapshot(mode + "-before")+ config.run(mode + "-update", "image", "update",+ CANDIDATE if mode == "new-signer" else BOOT,+ success=mode == "repeat")+ if mode == "new-signer":+ error = (config.RESULTS / (mode + "-update.stderr")).read_text()+ require("BPF signer was not enrolled at boot" in error and+ "reboot with the new trusted key set required" in error,+ "update failed for a reason other than boot-only enrollment")+ after = snapshot(mode + "-after")+ differences = [key for key in before if before[key] != after[key]]+ require(not differences, f"{mode} changed state: {differences}")+ else:+ raise ValueError(mode)+++if __name__ == "__main__":+ main()diff --git a/testing/tamperproof/t1155-verity-boot-signers.sh b/testing/tamperproof/t1155-verity-boot-signers.shnew file mode 100755index 00000000..7602e353--- /dev/null+++ b/testing/tamperproof/t1155-verity-boot-signers.sh@@ -0,0 +1,45 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++cd "$(dirname "$0")/.."+. ./integration-lib.sh+verity_required() {+ printf 'Bail out! %s\n' "$*" >&2+ exit 1+}+target_guard++mountpoint -q /run/shirudo/runtime && mountpoint -q /run/shirudo/config ||+ verity_required "dm-verity image mode is not active"+command -v python3 >/dev/null 2>&1 || verity_required "no python3"+case "$(uname -m)" in+x86_64|aarch64|riscv64) ;;+*) verity_required "no keyctl syscall numbers for this architecture" ;;+esac+: "${SHIRUDO_TEST_KEY_FIXTURES:=/root/verity-key-fixtures}"+for name in config-boot-keys config-live-new-key; do+ for suffix in img verity roothash p7s; do+ [ -r "$SHIRUDO_TEST_KEY_FIXTURES/$name.$suffix" ] ||+ verity_required "missing signed key fixture: $name.$suffix"+ done+done+for name in primary.der boot.der live.der boot.fingerprint live.fingerprint; do+ [ -r "$SHIRUDO_TEST_KEY_FIXTURES/$name" ] ||+ verity_required "missing public key fixture: $name"+done++if [ -n "${SHIRUDO_TEST_SIGNER_RESULTS:-}" ]; then+ work=$SHIRUDO_TEST_SIGNER_RESULTS+ mkdir -p "$work"+else+ work=$(mktemp -d)+ trap 'rm -rf "$work"' EXIT HUP INT TERM+fi+export SHIRUDO_BIN SHIRUDO_TEST_KEY_FIXTURES++test_expect_success 'boot enrolls the vouched signer and measures its signed CONFIG' '+ python3 tamperproof/t1155-verity-boot-signers.py initial "$work"+'++test_donediff --git a/testing/tamperproof/t1157-verity-cli.py b/testing/tamperproof/t1157-verity-cli.pynew file mode 100644index 00000000..4f6a7350--- /dev/null+++ b/testing/tamperproof/t1157-verity-cli.py@@ -0,0 +1,43 @@+#!/usr/bin/env python3+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++import importlib.util+from pathlib import Path+import sys++spec = importlib.util.spec_from_file_location(+ "config_test", Path(__file__).with_name("t1154-verity-config.py"))+config = importlib.util.module_from_spec(spec)+spec.loader.exec_module(config)+++def main():+ mode = sys.argv[1]+ commands = {+ "enrollment": [("keys", "add", "missing.der", "--vouch", "missing.vouch"),+ ("bpm", "key", "add", "oci://example.invalid/package:latest")],+ "mutation": [("keys", "revoke", "a" * 64),+ ("bpm", "config", "register", "add", "new",+ "oci://example.invalid", "--key-file", "missing.der"),+ ("bpm", "config", "register", "remove", "new"),+ ("bpm", "config", "register", "rm", "new")],+ "help": [("keys", "add", "--help"), ("keys", "revoke", "--help"),+ ("bpm", "key", "add", "--help")],+ }+ before = config.snapshot(mode + "-before")+ for index, arguments in enumerate(commands[mode]):+ label = mode + str(index)+ config.run(label, *arguments, success=mode == "help")+ if mode != "help":+ error = (config.RESULTS / (label + ".stderr")).read_text()+ config.require("image mode:" in error and "signed" in error,+ "missing image-mode guidance: " + error)+ wanted = "reboot" if mode == "enrollment" else "shirudo image update"+ config.require(wanted in error, "missing recovery action: " + error)+ after = config.snapshot(mode + "-after")+ config.require(before == after, "CLI refusal/help changed measured state")+++if __name__ == "__main__":+ main()diff --git a/testing/tamperproof/t1157-verity-cli.sh b/testing/tamperproof/t1157-verity-cli.shnew file mode 100644index 00000000..50934008--- /dev/null+++ b/testing/tamperproof/t1157-verity-cli.sh@@ -0,0 +1,21 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++cd "$(dirname "$0")/.."+. ./integration-lib.sh+target_guard+work=${SHIRUDO_TEST_CLI_RESULTS:-$(mktemp -d)}+mkdir -p "$work"+export SHIRUDO_BIN++test_expect_success 'image key enrollment requires a signed config and reboot' '+ python3 tamperproof/t1157-verity-cli.py enrollment "$work"+'+test_expect_success 'image revocation and repository changes require signed config activation' '+ python3 tamperproof/t1157-verity-cli.py mutation "$work"+'+test_expect_success 'image mode keeps command help available' '+ python3 tamperproof/t1157-verity-cli.py help "$work"+'+test_done