Skip to content

eBPF-based security platform

testing: test the delivery path end to end

Daniel Borkmann6fbcbe36cf3e
diff --git a/Documentation/requirements.rst b/Documentation/requirements.rst
index ce6f360d..f73f2ae0 100644
--- a/Documentation/requirements.rst
+++ b/Documentation/requirements.rst
@@ -464,6 +464,8 @@ suites when validating a deployment.
Ubuntu). The prepared guest installs libtpms and the command TCTI
runtime. The guest uses the TPM-held NV writer and the kernel TPM
device, not a software signing replacement.
+* ``make -C testing end2end`` runs an OCI registry and an OpenTelemetry
+ Collector in Docker containers beside the VM, and needs ``curl``.
* ``make -C testing fuzz`` builds the parsers' libFuzzer targets with
``clang`` and needs its fuzzer and sanitizer runtime
(``libclang-rt-<version>-dev`` on Debian and Ubuntu).
diff --git a/Documentation/testing.rst b/Documentation/testing.rst
index 641ca70b..0295a6eb 100644
--- a/Documentation/testing.rst
+++ b/Documentation/testing.rst
@@ -158,7 +158,20 @@ signed fixture of the bundle that a test needs. A target test that skips
as a whole fails its family, since every one of them is required.
The end-to-end tests in ``end2end/`` run a shipped package against real
-kernel activity and follow it out through the export path.
+kernel activity and follow it out through the export path, and the last of
+them, ``t9105-delivery``, takes the whole delivery path. Around its VM,
+``end2end/host.sh`` plays the operator: it starts an OCI registry and an
+OpenTelemetry Collector in containers, pinned by digest, behind a
+throwaway CA; builds kernel-obs into a package with ``bpm build``, pushes
+it with ``bpm push`` and appends it to a signed upatch tree with ``bpm
+tree append``, all with the key the bundle's fixtures are signed with.
+The target activates the signed ``config-end2end`` image that points at
+the tree and the collector, and the units it ships pull, verify and load
+the package and export what it observes. The host then checks the TPM
+evidence the target produced with ``attest verify``, which must find the
+published payload loaded, and the collector's output, which must hold the
+package's records. The registry and the collector need Docker on the
+host; the guest reaches them through QEMU's address for the host.
6) The test VM
--------------
diff --git a/testing/Makefile b/testing/Makefile
index 0369a158..2830f48f 100644
--- a/testing/Makefile
+++ b/testing/Makefile
@@ -293,9 +293,13 @@ $(addprefix functional/,$(FAMILIES)): functional/%: build-operator
$(Q)$(ROOT)/testing/run-tests.sh functional/$*
+$(Q)$(call vm-tests,$(filter $*,$(VM_SUITES)))
+# The end-to-end VM runs between the operator's publication to a registry
+# and the host's checks of what the target attests and exports.
end2end: build-operator
$(Q)$(ROOT)/testing/run-tests.sh end2end
- +$(Q)$(call vm-tests,end2end)
+ +$(Q)$(if $(filter 0,$(VM)),:,$(MAKE) test-vm-bundle && \
+ TEST_VM_HOST_BUNDLE="$(abspath $(TEST_VM_BUNDLE_DIR))" \
+ $(ROOT)/testing/end2end/host.sh $(MAKE) -C $(ROOT)/testing vm-test-end2end)
vm-test-tpm: vm-test-register
@@ -361,4 +365,4 @@ clean:
mkdir -p "$$(dirname "$$bundle_dir")"; \
exec 9>"$$bundle_dir.lock"; \
flock 9; \
- rm -rf "$$bundle_dir"
+ rm -rf "$$bundle_dir" "$$bundle_dir.operator" $(ROOT)/build/test-vm/end2end
diff --git a/testing/end2end/host.sh b/testing/end2end/host.sh
new file mode 100755
index 00000000..9cd12eb6
--- /dev/null
+++ b/testing/end2end/host.sh
@@ -0,0 +1,175 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# testing/end2end/host.sh <command>... -- the operator's side of the
+# end-to-end test, around <command>, which boots the end2end VM. An OCI
+# registry and an OpenTelemetry Collector run in containers behind a
+# throwaway CA; the operator builds kernel-obs into a package, pushes it
+# and appends it to a signed upatch tree. After the VM, the TPM-signed
+# evidence the target left must verify and record the published operation
+# and payload, and the collector must hold what the package observed.
+
+set -eu
+
+cd "$(dirname "$0")/../.."
+REPO=$PWD
+: "${TEST_VM_HOST_BUNDLE:?the test VM bundle is required}"
+KEYS=$TEST_VM_HOST_BUNDLE.operator/keys
+W=$REPO/build/test-vm/end2end
+REGISTRY=127.0.0.1:15443
+COLLECTOR=127.0.0.1:14318
+# registry 3.1.2 and opentelemetry-collector-contrib 0.164.0, both built
+# with a Go that offers the hybrid ML-KEM group shirudo requires.
+REGISTRY_IMAGE=docker.io/library/registry@sha256:d4032d4cc323c1731c707931ecada07a53076eac38e3b61ae57533f170f2c6c3
+COLLECTOR_IMAGE=docker.io/otel/opentelemetry-collector-contrib@sha256:340c9ca6a36617084c6661bdc4f0fe92b7cda5a805d61673ec8db375fddc522b
+S=$REPO/shirudo
+export SHIRUDO_BUILD="$REPO/tools/shirudo-build/shirudo-build"
+export BPM_OCI_CA_FILE="$W/ca.pem"
+VM_NAME=${VM_NAME:-end2end-$$}
+export VM_NAME
+RESULT=$REPO/build/test-vm/vms/$VM_NAME-end2end/result/end2end
+
+say() { printf 'end2end: %s\n' "$*"; }
+die() { printf 'end2end: %s\n' "$*" >&2; exit 1; }
+
+down() {
+ docker logs shirudo-end2end-collector >"$W/collector.log" 2>&1 || true
+ docker rm -f shirudo-end2end-registry shirudo-end2end-collector \
+ >/dev/null 2>&1 || true
+}
+
+# Up to ten seconds for a TLS service to answer an HTTP request.
+wait_https() {
+ i=0
+ until curl -fsS --cacert "$W/ca.pem" "$@" >/dev/null 2>&1; do
+ i=$((i + 1))
+ [ "$i" -lt 50 ] || return 1
+ sleep 0.2
+ done
+}
+
+command -v docker >/dev/null 2>&1 || die "docker is required"
+[ -s "$KEYS/signing_key.pem" ] || die "no operator key beside the bundle: $KEYS"
+rm -rf "$W"
+mkdir -p "$W/out" "$W/pkg"
+chmod 0777 "$W/out"
+down
+trap down EXIT
+
+say "a CA, and a server certificate for the registry and the collector"
+openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
+ -keyout "$W/ca.key" -out "$W/ca.pem" -days 1 \
+ -subj /CN=shirudo-end2end-ca 2>/dev/null
+openssl req -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
+ -keyout "$W/server.key" -out "$W/server.csr" \
+ -subj /CN=shirudo-end2end 2>/dev/null
+printf 'subjectAltName=IP:127.0.0.1,IP:10.0.2.2\n' >"$W/server.ext"
+openssl x509 -req -in "$W/server.csr" -CA "$W/ca.pem" -CAkey "$W/ca.key" \
+ -CAcreateserial -out "$W/server.pem" -days 1 \
+ -extfile "$W/server.ext" 2>/dev/null
+chmod 0644 "$W/server.key"
+openssl rand -hex 16 >"$W/nonce"
+
+say "the registry and the collector"
+docker run -d --name shirudo-end2end-registry -p "$REGISTRY:5000" \
+ -v "$W:/certs:ro" -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/server.pem \
+ -e REGISTRY_HTTP_TLS_KEY=/certs/server.key "$REGISTRY_IMAGE" >/dev/null
+docker run -d --name shirudo-end2end-collector -p "$COLLECTOR:4318" \
+ -v "$W:/certs:ro" -v "$W/out:/out" \
+ -v "$REPO/testing/end2end/otelcol.yaml:/etc/otelcol-contrib/config.yaml:ro" \
+ "$COLLECTOR_IMAGE" >/dev/null
+wait_https "https://$REGISTRY/v2/" || die "the registry did not come up"
+wait_https -X POST -H 'Content-Type: application/json' -d '{}' \
+ "https://$COLLECTOR/v1/logs" || die "the collector did not come up"
+
+say "the operator builds, pushes and publishes kernel-obs"
+cp -R upatches/kernel-obs "$W/pkg/kernel-obs"
+ln -s "$REPO/vendor" "$W/pkg/kernel-obs/vendor"
+ln -s "$REPO/bpf" "$W/pkg/kernel-obs/bpf"
+sed -i '/^source = "kernel-obs.bpf.c"$/a\
+\
+[upatches.tree]\
+id = "kernel-obs"\
+\
+[upatches.tree.selector.labels]\
+role = ["end2end"]' "$W/pkg/kernel-obs/Beefile"
+(cd "$W/pkg" && "$S" bpm build kernel-obs --version 1.0.0 --keys-dir "$KEYS")
+BEE=$W/pkg/kernel-obs-1.0.0.bee
+"$S" bpm push "$BEE" "oci://$REGISTRY/shirudo/kernel-obs" --keys-dir "$KEYS"
+"$S" bpm tree append "$BEE" "oci://$REGISTRY/shirudo/end2end-tree" \
+ --keys-dir "$KEYS"
+tar -xzf "$BEE" -C "$W/pkg"
+"$S" upatch info --json "$W/pkg/kernel-obs-1.0.0/upatches/kernel-obs.upatch" |
+ python3 -c 'import json, sys; print(json.load(sys.stdin)["payload_sha256"])' \
+ >"$W/payload"
+
+say "the target, in $VM_NAME-end2end"
+"$@"
+
+say "the evidence verifies and records what was published"
+[ -s "$RESULT/evidence.json" ] || die "the target left no evidence in $RESULT"
+ak=$(python3 -c 'import json, sys; print(json.load(open(sys.argv[1]))["ak"]["name"])' \
+ "$RESULT/evidence.json")
+"$S" attest verify --evidence="$RESULT/evidence.json" --nonce="$(cat "$W/nonce")" \
+ --ak-name="$ak" --allow-runtime-events --require-initrd \
+ >"$W/verify.out" 2>&1 || {
+ cat "$W/verify.out" >&2
+ die "the evidence does not verify"
+}
+grep -qx 'verdict: ok' "$W/verify.out" || die "the evidence does not verify"
+# The records replay to the register the TPM certified, so the last load
+# and tree operation they name are the target's.
+python3 - "$RESULT/evidence.json" "$(cat "$W/payload")" "$W/ca.pem" \
+ "$REGISTRY" <<'PY' || die "the target did not load what was published"
+import json, ssl, sys, urllib.request
+
+evidence, payload, ca, registry = sys.argv[1:5]
+ctx = ssl.create_default_context(cafile=ca)
+
+
+def get(path, accept=None):
+ request = urllib.request.Request(f"https://{registry}/v2/{path}")
+ if accept:
+ request.add_header("Accept", accept)
+ return urllib.request.urlopen(request, context=ctx).read()
+
+
+repo = "shirudo/end2end-tree"
+manifest = json.loads(get(f"{repo}/manifests/stable",
+ "application/vnd.oci.image.manifest.v1+json"))
+published = None
+for layer in manifest["layers"]:
+ try:
+ document = json.loads(get(f"{repo}/blobs/{layer['digest']}"))
+ except ValueError:
+ continue
+ if isinstance(document, dict) and "operations" in document:
+ published = document["operations"][-1]
+assert published, "no publication in the tree"
+records = json.load(open(evidence))["eventlog"]
+loads = [r["upatch"] for r in records if r["type"] == "upatch_load"]
+assert loads[-1] == {"name": "kernel-obs", "payload_sha256": payload}, loads[-1]
+ops = [r["tree"] for r in records if r["type"] == "tree_op"]
+assert ops[-1] == {key: published[key] for key in
+ ("seq", "op", "id", "operation_digest")}, (ops[-1], published)
+PY
+
+say "the collector holds what kernel-obs observed"
+python3 - "$W/out/otlp.json" <<'PY' || die "the collector did not get the export"
+import json, sys
+
+upatches, text = set(), ""
+with open(sys.argv[1]) as f:
+ for line in f:
+ text += line
+ for rl in json.loads(line).get("resourceLogs", []):
+ for sl in rl.get("scopeLogs", []):
+ for record in sl.get("logRecords", []):
+ for kv in record.get("attributes", []):
+ if kv["key"] == "shirudo.upatch.name":
+ upatches.add(kv["value"].get("stringValue"))
+assert "kernel-obs" in upatches, upatches
+assert "end2end/exec-paths" in text, "no exec record of the test's program"
+PY
+say "ok"
diff --git a/testing/end2end/otelcol.yaml b/testing/end2end/otelcol.yaml
new file mode 100644
index 00000000..58acdf2c
--- /dev/null
+++ b/testing/end2end/otelcol.yaml
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# The collector of the end-to-end test: OTLP over HTTPS in, every request
+# written to a file the host then checks.
+receivers:
+ otlp:
+ protocols:
+ http:
+ endpoint: 0.0.0.0:4318
+ tls:
+ cert_file: /certs/server.pem
+ key_file: /certs/server.key
+exporters:
+ file:
+ path: /out/otlp.json
+service:
+ pipelines:
+ logs:
+ receivers: [otlp]
+ exporters: [file]
+ metrics:
+ receivers: [otlp]
+ exporters: [file]
diff --git a/testing/end2end/t9105-delivery.sh b/testing/end2end/t9105-delivery.sh
new file mode 100755
index 00000000..6fdc7c01
--- /dev/null
+++ b/testing/end2end/t9105-delivery.sh
@@ -0,0 +1,76 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# t9105 -- the delivery path end to end. The operator built kernel-obs into
+# a package, pushed it to an OCI registry and appended it to a signed
+# upatch tree, and an OpenTelemetry Collector listens (end2end/host.sh).
+# The target activates the signed config that points at both, and the
+# units it ships pull the tree, verify and load the package, and export
+# what it observes; the TPM-signed evidence goes back to the host, which
+# checks it and the collector against what it published.
+
+cd "$(dirname "$0")/.."
+. ./integration-lib.sh
+target_guard
+command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"
+
+E2E=$PWD/../build/test-vm/end2end
+CONFIG=/var/lib/shirudo/images/config-end2end
+PIN=/run/shirudo/bpffs/upatches/kernel-obs/link_0
+OUT=/mnt/shirudo-out/end2end
+[ -s "$E2E/ca.pem" ] && [ -s "$E2E/nonce" ] ||
+ test_skip_all "no registry and collector: run make -C testing end2end"
+[ -s "$CONFIG.img" ] || test_skip_all "missing config-end2end image"
+[ ! -e "$PIN" ] || test_skip_all "kernel-obs is loaded"
+mkdir -p "$OUT"
+W=$(mktemp -d)
+python3 end2end/tcp_forward.py 127.0.0.1:15443 10.0.2.2:15443 "$W/ready" &
+FORWARD=$!
+trap 'kill "$FORWARD" 2>/dev/null || true; rm -rf "$W"' EXIT
+i=0
+until [ -e "$W/ready" ]; do
+ i=$((i + 1))
+ [ "$i" -lt 50 ] || test_skip_all "the registry forwarder did not start"
+ sleep 0.1
+done
+
+# Start a unit and wait for it; its journal is what a failure needs.
+unit_ok() {
+ systemctl start "$1" && return 0
+ journalctl -u "$1" --no-pager | tail -n 30 >&2
+ return 1
+}
+
+test_expect_success 'the target trusts the CA of the registry and the collector' '
+ install -m 0644 "$E2E/ca.pem" /etc/shirudo/end2end-ca.pem &&
+ install -d /etc/shirudo/bpm &&
+ printf "BPM_OCI_CA_FILE=/etc/shirudo/end2end-ca.pem\n" \
+ >/etc/shirudo/bpm/environment &&
+ printf "OTEL_EXPORTER_OTLP_CERTIFICATE=/etc/shirudo/end2end-ca.pem\n" \
+ >/etc/shirudo/map-export.env
+'
+
+test_expect_success 'the signed end2end config activates live' '
+ "$SHIRUDO_BIN" image update "$CONFIG" >"$OUT/image-update.out" 2>&1 &&
+ "$SHIRUDO_BIN" image status >"$OUT/image-status.out" 2>&1
+'
+
+test_expect_success 'the tree sync unit pulls, verifies and loads the package' '
+ unit_ok shirudo-bpm-tree-sync.service &&
+ [ -e "$PIN" ] &&
+ "$SHIRUDO_BIN" status --json >"$OUT/status.json"
+'
+
+test_expect_success 'the map export unit ships what the package observed' '
+ python3 end2end/kernel_obs_events.py exec &&
+ unit_ok shirudo-map-export.service
+'
+
+test_expect_success 'the target attests what it runs' '
+ "$SHIRUDO_BIN" attest --nonce="$(cat "$E2E/nonce")" \
+ --out="$OUT/evidence.json" &&
+ [ -s "$OUT/evidence.json" ]
+'
+
+test_done
diff --git a/testing/end2end/tcp_forward.py b/testing/end2end/tcp_forward.py
new file mode 100755
index 00000000..6ee17263
--- /dev/null
+++ b/testing/end2end/tcp_forward.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+"""Forward a TCP port to another address, so the guest reaches the host's
+registry under the address the operator published the tree with."""
+
+import asyncio
+import sys
+
+
+async def pipe(reader, writer):
+ try:
+ while data := await reader.read(65536):
+ writer.write(data)
+ await writer.drain()
+ finally:
+ writer.close()
+
+
+async def main(listen, target, ready):
+ lhost, lport = listen.rsplit(":", 1)
+ thost, tport = target.rsplit(":", 1)
+
+ async def handle(reader, writer):
+ try:
+ treader, twriter = await asyncio.open_connection(thost, int(tport))
+ except OSError:
+ writer.close()
+ return
+ await asyncio.gather(pipe(reader, twriter), pipe(treader, writer),
+ return_exceptions=True)
+
+ server = await asyncio.start_server(handle, lhost, int(lport))
+ with open(ready, "w") as f:
+ f.write("ready\n")
+ async with server:
+ await server.serve_forever()
+
+
+asyncio.run(main(*sys.argv[1:4]))
diff --git a/testing/run-target-tests.sh b/testing/run-target-tests.sh
index ec90518f..51966667 100755
--- a/testing/run-target-tests.sh
+++ b/testing/run-target-tests.sh
@@ -30,7 +30,7 @@ esac
}
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-jsonl config-jsonl-bad config-interrupted; do
+ config-otel config-jsonl config-jsonl-bad config-interrupted config-end2end; do
for suffix in img verity roothash p7s; do
[ -s "$SHIRUDO_TEST_KEY_FIXTURES/$name.$suffix" ] &&
[ -s "/var/lib/shirudo/images/$name.$suffix" ] || {
diff --git a/testing/vm/build-bundle.sh b/testing/vm/build-bundle.sh
index 22d6b7c1..617e006a 100755
--- a/testing/vm/build-bundle.sh
+++ b/testing/vm/build-bundle.sh
@@ -773,6 +773,12 @@ printf 'vendored-tools\n' >"$TMP_DIR/dependency-mode"
printf 'shirudo-test-vm-bundle-stamp-v1\n' >"$TMP_DIR/.stamp"
printf '%s\n' "$RUNTIME_KEY" >"$TMP_DIR/runtime-image-key"
+# The end-to-end test publishes a package the target trusts, with the key
+# that signs the fixtures. It stays beside the bundle, out of the guest.
+rm -rf -- "$BUNDLE_DIR.operator"
+mkdir -m 0700 "$BUNDLE_DIR.operator"
+cp -a "$FIXTURE_WORK/trusted" "$BUNDLE_DIR.operator/keys"
+
rm -rf -- "$BUNDLE_DIR"
mv -- "$TMP_DIR" "$BUNDLE_DIR"
touch "$STAMP_FILE"
diff --git a/testing/vm/files/end2end-tree.conf b/testing/vm/files/end2end-tree.conf
new file mode 100644
index 00000000..f18e670a
--- /dev/null
+++ b/testing/vm/files/end2end-tree.conf
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+endpoint = oci://127.0.0.1:15443/shirudo/end2end-tree
+reference = stable
diff --git a/testing/vm/files/end2end.conf b/testing/vm/files/end2end.conf
new file mode 100644
index 00000000..5c6fcaf7
--- /dev/null
+++ b/testing/vm/files/end2end.conf
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+eventlog.max_bytes = 0
+map_export.tenant_id = tenant-end2end
+map_export.otel_endpoint = https://10.0.2.2:14318
+map_export.otel_retries = 2
diff --git a/testing/vm/image-fixtures.sh b/testing/vm/image-fixtures.sh
index c7f35942..888c328a 100755
--- a/testing/vm/image-fixtures.sh
+++ b/testing/vm/image-fixtures.sh
@@ -66,7 +66,8 @@ 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-jsonl config-jsonl-bad config-interrupted config-builtin; do
+ config-otel config-jsonl config-jsonl-bad config-interrupted config-end2end \
+ 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"
@@ -86,6 +87,13 @@ for name in config-boot-keys config-live-new-key config-a config-b config-bad co
config-jsonl|config-jsonl-bad)
cp "$templates/${name#config-}.conf" "$root/etc/shirudo/shirudo.conf"
;;
+ config-end2end)
+ mkdir -p "$root/etc/shirudo/bpm"
+ printf 'role=end2end\n' >"$root/etc/shirudo/node.labels"
+ cp "$templates/end2end-tree.conf" \
+ "$root/etc/shirudo/bpm/upatch-tree.conf"
+ cp "$templates/end2end.conf" "$root/etc/shirudo/shirudo.conf"
+ ;;
esac
cp "$output/public/boot.der" "$root/keys/trusted/$boot_fp.der"
"$builder" keys vouch "$output/public/boot.der" \