Skip to content

eBPF-based security platform

testing: Run end-to-end operator in separate VM

Martynas Pumputis2cc1448356d8
diff --git a/.agents/skills/testing/SKILL.md b/.agents/skills/testing/SKILL.md
index ff9dadde..7eaf8e2e 100644
--- a/.agents/skills/testing/SKILL.md
+++ b/.agents/skills/testing/SKILL.md
@@ -70,6 +70,11 @@ parser of input from outside the host gets a target in `testing/fuzz/`.
host, which appends their output to the same `guest.log`; there
`result/status` is only the guest's preparation, and `the SSH session
that ran the target tests failed` is the channel failing, not a test.
+- `end2end` runs an operator VM, `end2end-<pid>-operator`, around node
+ A and node B. A failure there reads `host.sh failed with status <n>`;
+ the `end2end operator:` lines say which step, the package build log
+ is its `result/operator-build.log`, and what it published and verified
+ is in its `result/end2end/`.
- A fuzz failure leaves its input in `testing/fuzz/crash-<target>-*`.
Run the target binary on that file to reproduce it. An `abort()` in
the harness is a property that failed, which can be the harness's own.
@@ -91,6 +96,10 @@ parser of input from outside the host gets a target in `testing/fuzz/`.
`Cannot select: ... AtomicStore`. Make does not rebuild the helper
when only that variable changes: remove
`tools/shirudo-build/compile.o` first.
+- `end2end` prepares the operator VM's image on first use, with network
+ access for clang 23 from apt.llvm.org, and caches it beside the
+ runtime image; every run then builds the operator package in that VM,
+ which takes minutes. Say so before starting.
## Run unconfined
@@ -146,6 +155,10 @@ checkout's source. Consider only VMs of the current checkout. Other QEMU
processes on the host, such as little-vm-helper guests, are not shirudo
targets.
+A VM named `<name>-operator` or `<name>-end2end` belongs to an
+end-to-end run, which stops it when it ends; `vm-ssh` reaches it while
+the run lasts, but never reuse, stop or clean it.
+
A VM under `build/test-vm/vms/<name>/` can be reused when all of these
hold:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index eed73a0a..36c82f89 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -97,7 +97,7 @@ jobs:
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: build/test-vm/cache
- key: test-vm-images-${{ hashFiles('testing/vm/runtime-packages', 'testing/vm/prepare-runtime.sh', 'testing/vm/build-bundle.sh', 'testing/vm/arch.sh') }}
+ key: test-vm-images-${{ hashFiles('testing/vm/runtime-packages', 'testing/vm/operator-packages', 'testing/vm/prepare-runtime.sh', 'testing/vm/build-bundle.sh', 'testing/vm/arch.sh', '.github/scripts/install-clang.sh') }}
- name: Prepare the test environment
id: setup
diff --git a/Documentation/contribute/code/developer-guide.rst b/Documentation/contribute/code/developer-guide.rst
index c4cc6af6..6486774d 100644
--- a/Documentation/contribute/code/developer-guide.rst
+++ b/Documentation/contribute/code/developer-guide.rst
@@ -242,8 +242,10 @@ path, which takes precedence over ``PATH``.
``bpm build`` compiles with the package directory as its working
directory. To build a package with a checkout's ``vmlinux.h`` and BPF
headers, give the package directory ``vendor`` and ``bpf`` symbolic
-links to the checkout's, as ``t7005`` and :src:`testing/end2end/host.sh`
-do.
+links to the checkout's, as ``t7005`` does. An installed operator package
+needs neither: ``shirudo-build`` falls back to the headers and
+``vmlinux.h`` it installs, as the operator VM of the end-to-end test
+builds ``kernel-obs``.
Build the target binary
-----------------------
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index 42b6abf0..60c6eb2d 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -97,7 +97,8 @@ signed config image.
* - ``t1007-test-vm-cli``
- Test VM scripts: kernel selection, host dependencies, arm64
boot settings, the bundle stamp, serve mode, node mode only for a
- core or edge node of the end-to-end tier
+ core or edge node of the end-to-end tier, the operator VM's role and
+ its signing key
* - ``t1008-kernel-ami-config``
- The slim kernel configuration for NitroTPM CRB, EC2, EFI and SSM
* - ``t1009-upatch-isa``
@@ -655,7 +656,10 @@ signed config image.
* - ``t9104-kernel-obs-dns-matrix``
- DNS over loopback in maps, OTLP and ClickHouse
* - ``t9105-delivery``
- - Registry, tree sync, load, export and attestation end to end
+ - The operator package built and installed in an operator VM
+ without a TPM, which publishes ``kernel-obs`` and verifies the
+ evidence; registry, tree sync, load, export and attestation on
+ the target
* - ``t9106-policy-exec-graph``
- A signed SHPL section labels five executables; its BPF policy
allows unlabeled tasks to exec unlabeled files and 0x1, allows
diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rst
index d89ab522..4d6e20f2 100644
--- a/Documentation/contribute/testing/testing.rst
+++ b/Documentation/contribute/testing/testing.rst
@@ -39,7 +39,9 @@ Before you begin
bundle carries the TPM simulator helper, so
:src:`testing/vm/build-bundle.sh` builds no bundle without
``libtpms-dev``.
-- For the end-to-end tests: Docker on the host.
+- For the end-to-end tests: Docker on the host, and network access the
+ first time, when the runner adds clang 23 from apt.llvm.org and the
+ operator's build dependencies to the image of the operator VM.
The ``CI suite`` workflow uses the x86-64 CI kernel package from
``shirudo-dev/kernel`` for every trigger. By default, it selects the
@@ -76,8 +78,8 @@ Test tiers
- ``make -C testing functional``
* - End-to-end
- :src:`testing/end2end/`
- - Around one VM, with a registry and a collector in containers on
- the host
+ - In an operator VM and a target VM, with a registry and a
+ collector in containers on the host
- ``make -C testing end2end``
* - Fuzz
- :src:`testing/fuzz/`
@@ -331,8 +333,10 @@ family runs, the end-to-end run and the interactive VM all boot it.
A family's VM runs its target tests itself and powers off. The
end-to-end VM prepares itself the same way and waits while the host runs
-its target tests over SSH, then powers off. The interactive VM stays up
-until you stop it.
+its target tests over SSH, then powers off. The operator VM of the
+end-to-end test has no TPM and no shirudo kernel arguments; it builds
+and installs the operator package and serves the end-to-end run. The
+interactive VM stays up until you stop it.
Build the test kernel
~~~~~~~~~~~~~~~~~~~~~
@@ -405,7 +409,9 @@ the signing key outside the checkout, which every guest can read, in
``TEST_VM_HOST_PRIVATE_DIR`` names another directory, which must lie
outside the repository. Every target that boots a VM rebuilds the bundle
when one of its inputs changed, or when that directory does not hold the
-key the bundle's fixtures are signed with. Build it alone with:
+key the bundle's fixtures are signed with. The end-to-end test builds it
+once, before its two VMs: the target must trust the key the operator
+signs with. Build it alone with:
.. code-block:: console
@@ -620,20 +626,43 @@ Run the end-to-end tests
------------------------
``make -C testing end2end`` runs ``t9001`` on the host, then
-:src:`testing/end2end/host.sh` plays the operator around node A, which
-runs the target tests, node B beside it, and with a keepalive backend a
-fresh edge node after node A (see :ref:`testing-two-nodes`). It starts
-an OCI registry, an OpenTelemetry Collector and ClickHouse in Docker
-containers pinned by digest. The registry and collector use a throwaway
-CA. It 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``. The target
-activates a signed config that points at the tree and the collector,
-and its units pull, verify, load and export. The VM's tests, ``t91??``,
-run over SSH from the host, which writes what they print to
-``result/guest.log`` as a family's VM does. The host then verifies the
-target's TPM evidence with ``attest verify`` and checks that the
-collector holds the package's records. The earlier ``kernel-obs`` tests
+:src:`testing/end2end/host.sh` runs the test with an operator VM and the
+target nodes: node A, which runs the target tests, node B beside it, and
+with a keepalive backend a fresh edge node after node A (see
+:ref:`testing-two-nodes`). It starts an OCI registry, an OpenTelemetry
+Collector and ClickHouse in Docker containers pinned by digest. The
+registry and collector use a throwaway CA.
+
+The operator VM boots from the runtime image with clang 23 and the build
+dependencies of the operator package added, which the runner prepares
+once and caches beside it. The VM has no TPM, boots without the shirudo
+kernel arguments, and is the only VM that sees the signing key. The host
+keeps the key it logs in to it with and the VM's disk, which holds the
+guest's own key, outside the checkout, in
+``/tmp/shirudo-test-vm-private-<uid>/end2end-operator/``: a VM's keys
+and disk lie in its state directory, which the target VMs read through
+their share of the checkout. The operator VM builds the operator package
+from the files git sees in the checkout and installs it. Once it is
+ready, the host has it run :src:`testing/end2end/operator.sh` over SSH:
+the operator builds ``kernel-obs`` into a package with ``bpm build``,
+against the headers and ``vmlinux.h`` of the package, pushes it with
+``bpm push``, appends it to a signed upatch tree with
+``bpm tree append`` and picks the nonce the targets attest with. The
+operator VM and node A name the registry ``registry.test``, at QEMU's
+address for the host, so the tree names it as node A reaches it. The
+host's own build and the operator key it keeps still play the operator
+for the keepalive backend's example tree and for ``t9109`` to ``t9111``,
+which run on the host.
+
+Node A and node B boot next. Node A activates a signed config that
+points at the tree and the collector, and its units pull, verify, load
+and export. Its tests, ``t91??``, run over SSH from the host, which
+writes what they print to ``result/guest.log`` as a family's VM does.
+The host hands node A's TPM evidence to the operator, which verifies it
+with ``attest verify`` and checks that its records name the package and
+the tree operation it published. Once the operator VM has stopped, the
+host checks that the collector holds the package's records. The earlier
+``kernel-obs`` tests
export each map snapshot as local JSON and OTLP from one read; the host
compares the snapshots with the collector's JSON output and queries the
ClickHouse log and sum metric tables to check that both collector exports
@@ -651,9 +680,15 @@ tests.
$ make -C testing end2end
-The host side writes to ``build/test-vm/end2end/``. The guest reaches
-the registry and collector through QEMU's address for the host. ClickHouse
-is available to the collector on the test's Docker network.
+The host side writes to ``build/test-vm/end2end/``. The VMs are named
+``end2end-<pid>-operator`` and ``end2end-<pid>-end2end``, or
+``<name>-operator`` and ``<name>-end2end`` with ``VM_NAME=<name>``; the
+operator's package build log is in its ``result/operator-build.log`` and
+what it published and verified in its ``result/end2end/``. While the run lasts,
+``make -C testing vm-ssh VM_NAME=<name>`` opens a shell on either VM.
+The guests reach the registry and collector through QEMU's address for
+the host. ClickHouse is available to the collector on the test's Docker
+network.
``t9107`` runs the reference keepalive backend, which lives in a
repository of its own, ``shirudo-dev/backend``. ``host.sh`` finds it
@@ -688,7 +723,9 @@ The nodes
~~~~~~~~~
The tier boots up to five targets, at most two at once, each with its
-own software TPM and so its own attestation key. Node A is the family's
+own software TPM and so its own attestation key. The operator VM runs
+beside the first two, node A and node B, and stops before the others
+boot. Node A is the family's
VM, named ``<name>-end2end``, and runs the target tests in number order.
Node B, ``<name>-end2end-b``, boots beside it. With a keepalive backend,
the fresh edge node, ``<name>-end2end-edge``, boots once node A has
@@ -780,8 +817,8 @@ directory and ``NODES_HOST`` is ``127.0.0.1``. The nodes reach the
registry and the collectors through QEMU's address for the host, as node
A does, and have the checkout at ``/workspace/shirudo`` too. A tree at
``127.0.0.1:15443`` names its packages there, so a test that syncs a node
-starts ``end2end/tcp_forward.py`` in it, as ``t9105`` does in node A,
-detached from the SSH session:
+starts ``end2end/tcp_forward.py`` in it, detached from the SSH
+session:
.. code-block:: sh
@@ -790,10 +827,10 @@ detached from the SSH session:
10.0.2.2:15443 /tmp/forward-ready </dev/null >/dev/null 2>&1"
The other nodes have 2 CPUs and ``TEST_VM_NODE_MEMORY``, ``2G`` by
-default; node A keeps ``TEST_VM_CPUS`` and ``TEST_VM_MEMORY``. With the
-defaults the guests take 6 GiB of host memory at most, while node A and
-node B run, and the registry, the two collectors and the two ClickHouse
-servers come on top. ``host.sh`` prints each node's memory use, and their
+default; node A and the operator VM keep ``TEST_VM_CPUS`` and
+``TEST_VM_MEMORY``. With the defaults the guests take 10 GiB of host
+memory at most, while the operator VM, node A and node B run, and the
+registry, the two collectors and the two ClickHouse servers come on top. ``host.sh`` prints each node's memory use, and their
boot logs are ``build/test-vm/end2end/node-b.log`` and
``node-edge.log``, and ``node-b-2.log`` and ``node-edge-2.log`` for the
second pair.
diff --git a/testing/Makefile b/testing/Makefile
index c3419021..b4582fb8 100644
--- a/testing/Makefile
+++ b/testing/Makefile
@@ -29,7 +29,8 @@ test-vm-arch = $(shell TEST_VM_ARCH='$(TEST_VM_ARCH)'; \
.DEFAULT_GOAL := all
.PHONY: all help clean unit ci-checks functional end2end build-operator build-unit \
test-helpers \
- fuzz bundle test-vm-bundle kernel bpf-next vm vm-console vm-ssh vm-stop vm-clean
+ fuzz bundle test-vm-bundle kernel bpf-next vm vm-console vm-ssh vm-stop vm-clean \
+ vm-operator-end2end
KERNEL_PATCHES ?= $(if $(wildcard $(ROOT)/kernel/*.patch),$(ROOT)/kernel/,)
override KERNEL_PATCHES := $(if $(strip $(KERNEL_PATCHES)),$(call root-path,$(KERNEL_PATCHES)),)
@@ -310,29 +311,51 @@ $(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.
+# The end-to-end test boots the operator VM, which builds the operator
+# package and alone gets the signing key on its own disk; while it serves,
+# host.sh has it publish kernel-obs, runs node A and has it verify what
+# node A attests. The host's own build plays the operator for the keepalive
+# backend and for the tests host.sh runs against the other nodes. The goals
+# host.sh boots the VMs with build nothing: all VMs boot this bundle, and a
+# rebuild between them, for an input changed meanwhile, would replace the
+# key the operator signs with and the targets trust.
end2end: build-operator
$(Q)$(ROOT)/testing/run-tests.sh end2end
+$(Q)$(if $(filter 0,$(VM)),:,$(MAKE) test-vm-bundle && \
TEST_VM_HOST_BUNDLE="$(abspath $(TEST_VM_BUNDLE_DIR))" \
TEST_VM_HOST_PRIVATE_DIR="$(abspath $(TEST_VM_HOST_PRIVATE_DIR))" \
- MAKE="$(MAKE)" \
- $(ROOT)/testing/end2end/host.sh $(MAKE) -C $(ROOT)/testing vm-test-end2end)
+ MAKE="$(MAKE)" $(ROOT)/testing/end2end/host.sh)
+
+vm-operator-end2end:
+ $(Q)VM_MODE=serve TEST_VM_ROLE=operator TEST_VM_INITRD=0 \
+ VM_VERBOSE="$(TEST_VM_VERBOSE)" VM_NAME="$(VM_NAME)" \
+ TEST_VM_SERVE_COMMAND="$(TEST_VM_SERVE_COMMAND)" \
+ TEST_VM_PRIVATE_DIR="$(TEST_VM_PRIVATE_DIR)" \
+ TEST_VM_OPERATOR_KEYS="$(abspath $(TEST_VM_HOST_PRIVATE_DIR))/operator-keys/keys" \
+ TEST_VM_KERNEL="$(abspath $(VM_KERNEL_IMAGE))" \
+ TEST_VM_WORK_DIR="$(TEST_VM_WORK_DIR)" \
+ TEST_VM_RUNTIME_CACHE_DIR="$(TEST_VM_RUNTIME_CACHE_DIR)" \
+ TEST_VM_MODE="$(TEST_VM_MODE)" \
+ TEST_VM_HOST_BUNDLE="$(abspath $(TEST_VM_BUNDLE_DIR))" \
+ $(ROOT)/testing/vm/run.sh
+
+vm-test-end2end:
+ $(Q)$(call run-target-vm,end2end,$(if $(VM_NAME),$(VM_NAME)-end2end),1)
# A node of the end-to-end run that end2end/host.sh boots and stops,
# prepared like the suite's VM, but it runs no tests and stays up until it
# is stopped. END2END_NODE=b is node B, with the core role, beside the
# suite's VM; edge is a fresh node with the edge role, after it.
END2END_NODE ?= b
-vm-node-end2end: $(VM_KERNEL_DEP) test-vm-bundle
+vm-node-end2end:
$(Q)$(if $(filter-out b edge,$(END2END_NODE)),$(error END2END_NODE must be b or edge))
$(Q)TEST_VM_NODE_ROLE=$(if $(filter edge,$(END2END_NODE)),edge,core) \
$(call run-target-vm,end2end,$(if $(VM_NAME),$(VM_NAME)-end2end-$(END2END_NODE)),1,node)
vm-test-tpm: vm-test-register
-$(addprefix vm-test-,register $(VM_SUITES)): vm-test-%: $(VM_KERNEL_DEP) test-vm-bundle
+$(addprefix vm-test-,register $(filter-out end2end,$(VM_SUITES))): \
+ vm-test-%: $(VM_KERNEL_DEP) test-vm-bundle
$(Q)$(call run-target-vm,$*,$(if $(VM_NAME),$(VM_NAME)-$*),$(if $(filter register,$*),0,1))
vm-stop:
diff --git a/testing/end2end/host.sh b/testing/end2end/host.sh
index d6e49012..39aff859 100755
--- a/testing/end2end/host.sh
+++ b/testing/end2end/host.sh
@@ -1,12 +1,16 @@
#!/bin/sh
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2026 Authors of shirudo
-# testing/end2end/host.sh -- run the operator side of the end-to-end VM test.
-# Its arguments are the command that runs the suite in node A; node B, a
-# second target with a TPM of its own, boots beside it. After node A, a
-# fresh edge node boots in its place and t9109 and t9110 run here against
-# it and node B. A second fresh edge node and node B then take their
-# place, on a registry that holds no tree, and t9111 runs against them.
+# testing/end2end/host.sh -- the runner of the end-to-end test. It starts the
+# registry, the collectors and the keepalive backend, and boots the operator
+# VM, which runs this script again with its name once it is ready; in that
+# run the operator publishes, node A runs its tests with node B, a second
+# target with a TPM of its own, booting beside it, and the operator verifies
+# what node A attests, each step over SSH. Then the runner checks the
+# collector and node B. A fresh edge node boots in node A's place and t9109
+# and t9110 run here against it and node B. A second fresh edge node and
+# node B then take their place, on a registry that holds no tree, and t9111
+# runs against them.
set -eu
@@ -17,6 +21,10 @@ HOST_PRIVATE_DIR="${TEST_VM_HOST_PRIVATE_DIR:-/tmp/shirudo-test-vm-private-$(id
KEYS=$HOST_PRIVATE_DIR/operator-keys/keys
W=$REPO/build/test-vm/end2end
TLS_DIR=$HOST_PRIVATE_DIR/end2end-tls
+# The operator's SSH key and disk, which holds its own key, stay out of the
+# checkout, which the target VMs mount, or a target could log in to the
+# operator and read the signing key.
+OPERATOR_PRIVATE_DIR=$HOST_PRIVATE_DIR/end2end-operator
REGISTRY=127.0.0.1:15443
COLLECTOR=127.0.0.1:14318
CLICKHOUSE=127.0.0.1:18123
@@ -28,10 +36,13 @@ STACK_PERSIST=0
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
-POLICY_FIXTURE=$TEST_VM_HOST_BUNDLE/fixtures/shirudo-test-policy-exec-graph.upatch
+MAKE=${MAKE:-make}
+E2E_VM=${E2E_VM:-${VM_NAME:-end2end-$$}}
+export E2E_VM
+RESULT=$REPO/build/test-vm/vms/$E2E_VM-end2end/result/end2end
+BEE=$W/pkg/kernel-obs-1.0.0.bee
+OPERATOR_SH=/workspace/shirudo/testing/end2end/operator.sh
+OPERATOR_OUT=/mnt/shirudo-out/end2end
CHECKER=$REPO/tools/quote-check/shirudo-quote-check
KEEPALIVE=$REPO/testing/fixtures/keepalive
NODES_DIR=$W
@@ -52,12 +63,17 @@ down() {
node_down b "$NODE_B_PID"
NODE_B_PID=
stack_down
- rm -rf -- "$TLS_DIR"
+ rm -rf -- "$TLS_DIR" "$OPERATOR_PRIVATE_DIR"
+}
+
+# A command in the operator VM, over SSH.
+operator() {
+ VM_NAME=$OPERATOR_VM VM_SSH_COMMAND="$*" "$REPO/testing/vm/run.sh" --ssh
}
# The state directory of node $1's VM.
node_run_dir() {
- printf '%s/build/test-vm/vms/%s%s-end2end-%s\n' "$REPO" "$VM_NAME" \
+ printf '%s/build/test-vm/vms/%s%s-end2end-%s\n' "$REPO" "$E2E_VM" \
"$NODE_ROUND" "$1"
}
@@ -68,7 +84,7 @@ node_boot() {
run=$(node_run_dir "$1")
mkdir -p "$NODES_DIR/node-$1"
if "${MAKE:-make}" -C "$REPO/testing" vm-node-end2end END2END_NODE="$1" \
- VM_NAME="$VM_NAME$NODE_ROUND" \
+ VM_NAME="$E2E_VM$NODE_ROUND" \
TEST_VM_CPUS=2 TEST_VM_MEMORY="${TEST_VM_NODE_MEMORY:-2G}" \
>"$W/node-$1$NODE_ROUND.log" 2>&1 &&
cp "$run/ssh.port" "$NODES_DIR/node-$1/port" &&
@@ -90,7 +106,7 @@ node_down() {
node_stop() {
[ ! -d "$(node_run_dir "$1")" ] ||
- VM_NAME=$VM_NAME$NODE_ROUND-end2end-$1 "$REPO/testing/vm/run.sh" --stop \
+ VM_NAME=$E2E_VM$NODE_ROUND-end2end-$1 "$REPO/testing/vm/run.sh" --stop \
>/dev/null 2>&1 || :
}
@@ -148,7 +164,7 @@ second_pair() {
rm -rf -- "$NODES_DIR/node-edge" "$NODES_DIR/node-b"
docker rm -fv "$STACK_NAME-registry" >/dev/null 2>&1 || :
stack_oci || die "the registry did not come up again"
- say "a second fresh edge node and node B, in $VM_NAME$NODE_ROUND-end2end-edge and -b"
+ say "a second fresh edge node and node B, in $E2E_VM$NODE_ROUND-end2end-edge and -b"
node_boot edge &
NODE_EDGE_PID=$!
node_boot b &
@@ -243,6 +259,41 @@ print("sha256:" + hashlib.sha256(raw).hexdigest())
PY
}
+# The operator VM serves this, with its own name as the argument.
+if [ $# -eq 1 ]; then
+ OPERATOR_VM=$1
+ say "the operator builds, pushes and publishes kernel-obs"
+ operator "$OPERATOR_SH" publish
+ operator cat "$OPERATOR_OUT/nonce" >"$W/nonce"
+ if [ -n "${BACKEND-}" ]; then
+ say "the keepalive backend of $BACKEND loads the example tree"
+ operator cat "$OPERATOR_OUT/pkg/kernel-obs-1.0.0.bee" >"$BEE"
+ publish_document shirudo/fleet-base >"$W/backend-tree.digest" ||
+ die "cannot publish the example tree"
+ CLICKHOUSE_CLIENT="docker exec -i $STACK_NAME-backend-clickhouse clickhouse-client" \
+ SHIRUDO="$S" "$BACKEND/jobs/tree-ingest" --cert "$KEYS/cert.der" \
+ "oci://$REGISTRY/shirudo/fleet-base" >"$W/tree-ingest.out" 2>&1 || {
+ cat "$W/tree-ingest.out" >&2
+ rm -f "$W/backend-tree.digest"
+ die "the tree ingest job did not load the example tree"
+ }
+ fi
+ # Node B outlives this run, which ends with its boot over, or with it
+ # stopped when the run fails.
+ trap '[ $? -eq 0 ] || node_down b "$NODE_B_PID"' EXIT
+ say "node A, in $E2E_VM-end2end, and node B, in $E2E_VM-end2end-b"
+ node_boot b &
+ NODE_B_PID=$!
+ "$MAKE" -C "$REPO/testing" vm-test-end2end VM_NAME="$E2E_VM"
+ say "the operator verifies the evidence and records node A returned"
+ [ -s "$RESULT/evidence.json" ] || die "node A left no evidence in $RESULT"
+ operator "cat >$OPERATOR_OUT/evidence.json" <"$RESULT/evidence.json"
+ operator "$OPERATOR_SH" verify
+ wait "$NODE_B_PID" || :
+ exit 0
+fi
+[ $# -eq 0 ] || die "usage: $0"
+
command -v docker >/dev/null 2>&1 || die "docker is required"
private_dir="$(realpath -m "$HOST_PRIVATE_DIR")"
repo_dir="$(realpath -m "$REPO")"
@@ -252,7 +303,6 @@ repo_dir="$(realpath -m "$REPO")"
install -d -m 0700 "$HOST_PRIVATE_DIR"
chmod 0700 "$HOST_PRIVATE_DIR"
[ -s "$KEYS/signing_key.pem" ] || die "no host-only operator key: $KEYS"
-[ -s "$POLICY_FIXTURE" ] || die "no policy exec graph fixture: $POLICY_FIXTURE"
rm -rf "$W"
mkdir -p "$W/out" "$W/pkg"
chmod 0777 "$W/out"
@@ -261,130 +311,49 @@ install -d -m 0755 "$TLS_DIR"
trap down EXIT
stack_prepare
-openssl rand -hex 16 >"$W/nonce"
say "the registry, collector and ClickHouse"
stack_oci || die "the registry did not come up"
stack_telemetry || die "the telemetry stack 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 = ["edge"]' "$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" \
- --new-index
-"$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"
-"$S" upatch info --json "$POLICY_FIXTURE" |
- python3 -c 'import json, sys; print(json.load(sys.stdin)["payload_sha256"])' \
- >"$W/policy-payload"
-
+BACKEND=
if backend_find; then
- say "the keepalive backend of $BACKEND loads the example tree"
+ say "the keepalive backend of $BACKEND"
[ -x "$CHECKER" ] || die "no quote checker: $CHECKER"
stack_backend "$BACKEND" "$CHECKER" ||
die "the keepalive backend did not come up"
- publish_document shirudo/fleet-base >"$W/backend-tree.digest" ||
- die "cannot publish the example tree"
- CLICKHOUSE_CLIENT="docker exec -i $STACK_NAME-backend-clickhouse clickhouse-client" \
- SHIRUDO="$S" "$BACKEND/jobs/tree-ingest" --cert "$KEYS/cert.der" \
- "oci://$REGISTRY/shirudo/fleet-base" >"$W/tree-ingest.out" 2>&1 || {
- cat "$W/tree-ingest.out" >&2
- rm -f "$W/backend-tree.digest"
- die "the tree ingest job did not load the example tree"
- }
else
say "no keepalive backend at ../backend and no BACKEND_DIR: t9107 and t9109 to t9111 do not run"
fi
-
-say "node A, in $VM_NAME-end2end, and node B, in $VM_NAME-end2end-b"
-node_boot b &
-NODE_B_PID=$!
-"$@"
-
-# The fresh edge node takes node A's place, so that two guests run at most.
+export BACKEND
+
+say "the operator, in $E2E_VM-operator"
+# Each VM's name goes on make's command line, where a VM_NAME the caller
+# gave make reaches every sub-make and overrides the environment.
+TEST_VM_SERVE_COMMAND="$REPO/testing/end2end/host.sh" \
+ TEST_VM_PRIVATE_DIR="$OPERATOR_PRIVATE_DIR" \
+ "$MAKE" -C "$REPO/testing" vm-operator-end2end \
+ VM_NAME="$E2E_VM-operator"
+
+# The fresh edge node takes the place of node A and the operator, so that
+# two guests run at most.
if [ -s "$W/backend-tree.digest" ]; then
- say "the fresh edge node, in $VM_NAME-end2end-edge"
+ say "the fresh edge node, in $E2E_VM-end2end-edge"
node_boot edge &
NODE_EDGE_PID=$!
fi
-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")" \
- "$(cat "$W/policy-payload")" "$W/ca.pem" "$REGISTRY" <<'PY' || \
- die "the target did not load what was published"
-import json, ssl, sys, urllib.request
-
-evidence, payload, policy_payload, ca, registry = sys.argv[1:6]
-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 {"name": "kernel-obs", "payload_sha256": payload} in loads, loads
-assert loads[-1] == {"name": "policy-exec-graph",
- "payload_sha256": policy_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 "$REPO/testing/end2end/check-otlp.py" \
- "$REPO/build/test-vm/vms/$VM_NAME-end2end/result/end2end/otel" \
+python3 "$REPO/testing/end2end/check-otlp.py" "$RESULT/otel" \
"$W/out/otlp.json" "http://$CLICKHOUSE/" || \
die "the collector or ClickHouse snapshots differ from the map exports"
say "node B booted with an attestation key and a role of its own"
-wait "$NODE_B_PID" || :
-NODE_B_PID=
node_wait b 0 || {
tail -n 40 "$W/node-b.log" >&2
die "node B did not boot; see $W/node-b.log"
}
+ak=$(python3 -c 'import json, sys; print(json.load(open(sys.argv[1]))["ak"]["name"])' \
+ "$RESULT/evidence.json")
node_sh b "/usr/local/bin/shirudo-runtime attest --nonce=$(cat "$W/nonce")" \
>"$W/node-b-evidence.json" || die "node B gave no evidence"
# Node B loads nothing of its own: a test gives it only what a tree holds.
@@ -403,7 +372,7 @@ print(evidence["ak"]["name"])' "$W/node-b-evidence.json") ||
[ "$ak_b" != "$ak" ] || die "node A and node B share an attestation key"
[ "$(node_sh b cat /run/shirudo/config/etc/shirudo/node.labels)" = role=core ] ||
die "node B is not labelled role=core"
-image_identity A "$REPO/build/test-vm/vms/$VM_NAME-end2end/result/keepalive.json"
+image_identity A "$REPO/build/test-vm/vms/$E2E_VM-end2end/result/keepalive.json"
image_identity B "$(node_run_dir b)/result/keepalive.json" \
"$(cat "$TEST_VM_HOST_BUNDLE/verity/config-core.root")"
diff --git a/testing/end2end/operator.sh b/testing/end2end/operator.sh
new file mode 100755
index 00000000..37df4a56
--- /dev/null
+++ b/testing/end2end/operator.sh
@@ -0,0 +1,115 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+# testing/end2end/operator.sh publish|verify -- the operator's side of the
+# end-to-end test, run over SSH in the operator VM with the operator package
+# and the signing key: publish what the target loads and the nonce it attests
+# with, then verify the evidence it returned against what was published.
+
+set -eu
+
+cd "$(dirname "$0")/../.."
+REPO=$PWD
+KEYS=/mnt/shirudo-operator-keys
+W=/mnt/shirudo-out/end2end
+REGISTRY=registry.test:15443
+POLICY_FIXTURE=/mnt/shirudo-bundle/fixtures/shirudo-test-policy-exec-graph.upatch
+export BPM_OCI_CA_FILE="$REPO/build/test-vm/end2end/ca.pem"
+
+say() { printf 'end2end operator: %s\n' "$*"; }
+die() { printf 'end2end operator: %s\n' "$*" >&2; exit 1; }
+
+payload() {
+ shirudo upatch info --json "$1" |
+ python3 -c 'import json, sys; print(json.load(sys.stdin)["payload_sha256"])'
+}
+
+publish() {
+ [ -s "$BPM_OCI_CA_FILE" ] || die "no CA of the registry: $BPM_OCI_CA_FILE"
+ [ -s "$POLICY_FIXTURE" ] || die "no policy exec graph fixture: $POLICY_FIXTURE"
+ rm -rf "$W"
+ mkdir -p "$W/pkg"
+ cp -R "$REPO/upatches/kernel-obs" "$W/pkg/kernel-obs"
+ sed -i '/^source = "kernel-obs.bpf.c"$/a\
+\
+[upatches.tree]\
+id = "kernel-obs"\
+\
+[upatches.tree.selector.labels]\
+role = ["edge"]' "$W/pkg/kernel-obs/Beefile"
+ say "build kernel-obs with the installed headers and vmlinux.h"
+ (cd "$W/pkg" && shirudo bpm build kernel-obs --version 1.0.0 --keys-dir "$KEYS")
+ bee=$W/pkg/kernel-obs-1.0.0.bee
+ say "push it to oci://$REGISTRY and append it to the upatch tree"
+ shirudo bpm push "$bee" "oci://$REGISTRY/shirudo/kernel-obs" \
+ --keys-dir "$KEYS" --new-index
+ shirudo bpm tree append "$bee" "oci://$REGISTRY/shirudo/end2end-tree" \
+ --keys-dir "$KEYS"
+ tar --no-same-owner -xzf "$bee" -C "$W/pkg"
+ payload "$W/pkg/kernel-obs-1.0.0/upatches/kernel-obs.upatch" >"$W/payload"
+ payload "$POLICY_FIXTURE" >"$W/policy-payload"
+ openssl rand -hex 16 >"$W/nonce"
+}
+
+verify() {
+ [ -s "$W/evidence.json" ] || die "no evidence to verify in $W"
+ ak=$(python3 -c 'import json, sys; print(json.load(open(sys.argv[1]))["ak"]["name"])' \
+ "$W/evidence.json")
+ say "verify the evidence"
+ shirudo attest verify --evidence="$W/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"
+ say "the target loaded what was published"
+ # The records replay to the register the TPM certified, so the last load
+ # and tree operation they name are the target's.
+ python3 - "$W/evidence.json" "$(cat "$W/payload")" \
+ "$(cat "$W/policy-payload")" "$BPM_OCI_CA_FILE" "$REGISTRY" <<'PY' ||
+import json, ssl, sys, urllib.request
+
+evidence, payload, policy_payload, ca, registry = sys.argv[1:6]
+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 {"name": "kernel-obs", "payload_sha256": payload} in loads, loads
+assert loads[-1] == {"name": "policy-exec-graph",
+ "payload_sha256": policy_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
+ die "the target did not load what was published"
+}
+
+case "${1:-}" in
+publish) publish ;;
+verify) verify ;;
+*)
+ printf 'usage: %s publish|verify\n' "$0" >&2
+ exit 2
+ ;;
+esac
diff --git a/testing/end2end/t9105-delivery.sh b/testing/end2end/t9105-delivery.sh
index b1cc9fcb..e6665bcf 100755
--- a/testing/end2end/t9105-delivery.sh
+++ b/testing/end2end/t9105-delivery.sh
@@ -2,13 +2,13 @@
# 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
+# t9105 -- the delivery path end to end. The operator VM 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.
+# what it observes; the TPM-signed evidence goes back to the operator,
+# which checks it against what it published.
cd "$(dirname "$0")/.."
. ./integration-lib.sh
@@ -24,16 +24,10 @@ OUT=/mnt/shirudo-out/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
+# The tree names the registry as the operator pushed to it, at QEMU's
+# address for the host.
+sed -E -i '/^[^#]*[[:space:]]registry\.test([[:space:]]|$)/d' /etc/hosts
+printf '10.0.2.2 registry.test\n' >>/etc/hosts
# Start a unit and wait for it; its journal is what a failure needs.
unit_ok() {
diff --git a/testing/functional/build/t1007-test-vm-cli.sh b/testing/functional/build/t1007-test-vm-cli.sh
index 7984561f..f89098ce 100755
--- a/testing/functional/build/t1007-test-vm-cli.sh
+++ b/testing/functional/build/t1007-test-vm-cli.sh
@@ -536,6 +536,59 @@ test_expect_success 'serve mode runs the end-to-end target tests over SSH' '
grep -Fq "while [ ! -e /mnt/shirudo-out/host-done ]" vm/run.sh &&
grep -Fq ": >\"\$RUN_DIR/result/host-done\"" vm/run.sh
'
+
+test_expect_success 'an operator VM serves without a TPM and alone gets the key' '
+ mkdir -p "$WORK/operator-keys" &&
+ ! TEST_VM_ROLE=other "$RUNNER" >"$WORK/role.out" 2>&1 &&
+ grep -q "TEST_VM_ROLE must be .target. or .operator." "$WORK/role.out" &&
+ ! TEST_VM_ROLE=operator VM_MODE=test TEST_VM_INITRD=0 \
+ "$RUNNER" >"$WORK/operator-mode.out" 2>&1 &&
+ grep -q "an operator VM runs in serve mode" "$WORK/operator-mode.out" &&
+ ! TEST_VM_ROLE=operator VM_MODE=serve TEST_VM_INITRD=0 \
+ TEST_VM_SERVE_COMMAND=/bin/true \
+ TEST_VM_OPERATOR_KEYS="$WORK/operator-keys" \
+ "$RUNNER" >"$WORK/operator-keys.out" 2>&1 &&
+ grep -q "TEST_VM_OPERATOR_KEYS must name" "$WORK/operator-keys.out" &&
+ ! VM_MODE=serve TEST_VM_OPERATOR_KEYS="$WORK/operator-keys" \
+ "$RUNNER" >"$WORK/target-keys.out" 2>&1 &&
+ grep -q "only an operator VM gets TEST_VM_OPERATOR_KEYS" \
+ "$WORK/target-keys.out" &&
+ ! VM_MODE=test TEST_VM_SERVE_COMMAND=/bin/true \
+ "$RUNNER" >"$WORK/serve-command.out" 2>&1 &&
+ grep -q "TEST_VM_SERVE_COMMAND must name a program, in serve mode" \
+ "$WORK/serve-command.out" &&
+ ! VM_MODE=serve TEST_VM_PRIVATE_DIR="$PWD/private" \
+ "$RUNNER" >"$WORK/private-repo.out" 2>&1 &&
+ grep -q "TEST_VM_PRIVATE_DIR must name a new directory outside" \
+ "$WORK/private-repo.out" &&
+ mkdir "$WORK/private" &&
+ ! VM_MODE=serve TEST_VM_PRIVATE_DIR="$WORK/private" \
+ "$RUNNER" >"$WORK/private-exists.out" 2>&1 &&
+ grep -q "TEST_VM_PRIVATE_DIR must name a new directory outside" \
+ "$WORK/private-exists.out" &&
+ grep -q -- "-u TEST_VM_PRIVATE_DIR" vm/run.sh &&
+ grep -Fq "SSH_KEY=\"\${PRIVATE_DIR:-\$SSH_DIR}/id_ed25519\"" vm/run.sh &&
+ grep -Fq "OVERLAY=\"\${PRIVATE_DIR:-\$RUN_DIR}/rootfs.qcow2\"" vm/run.sh &&
+ grep -Fq "OPERATOR_PRIVATE_DIR=\$HOST_PRIVATE_DIR/" end2end/host.sh &&
+ grep -Fq "TEST_VM_PRIVATE_DIR=\"\$OPERATOR_PRIVATE_DIR\"" end2end/host.sh &&
+ make -n -C .. -f testing/Makefile vm-operator-end2end VM_NAME=e2e-operator \
+ TEST_VM_SERVE_COMMAND=/bin/true TEST_VM_WORK_DIR="$WORK/operator-vm" \
+ TEST_VM_PRIVATE_DIR="$WORK/operator-private" \
+ >"$WORK/operator-make.out" 2>&1 &&
+ grep -q "TEST_VM_ROLE=operator" "$WORK/operator-make.out" &&
+ grep -q "TEST_VM_OPERATOR_KEYS=.*/operator-keys/keys" "$WORK/operator-make.out" &&
+ grep -Fq "TEST_VM_PRIVATE_DIR=\"$WORK/operator-private\"" \
+ "$WORK/operator-make.out" &&
+ make -n -C .. -f testing/Makefile vm-test-end2end VM_NAME=e2e \
+ TEST_VM_WORK_DIR="$WORK/target-vm" >"$WORK/target-make.out" 2>&1 &&
+ grep -q "VM_MODE=serve" "$WORK/target-make.out" &&
+ ! grep -q "TEST_VM_OPERATOR_KEYS\|TEST_VM_ROLE\|TEST_VM_PRIVATE_DIR" \
+ "$WORK/target-make.out" &&
+ grep -Fq "[[ \"\$VM_ROLE\" != target ]] || start_swtpm" vm/run.sh &&
+ grep -q "mount_tag=shirudo-operator-keys" vm/run.sh &&
+ grep -q "the operator VM has a TPM" vm/guest.sh &&
+ grep -q "bindeb-pkg PKG_ROLES=operator" vm/guest.sh
+'
test_expect_success 'make -C testing vm boots a release kernel at or above the floor' '
grep -q "VM_KERNEL_MIN := 7.4" ../testing/Makefile &&
grep -q "make -C testing vm KERNEL=7.4" ../testing/Makefile &&
diff --git a/testing/vm/build-bundle.sh b/testing/vm/build-bundle.sh
index 6198bf34..370f94a2 100755
--- a/testing/vm/build-bundle.sh
+++ b/testing/vm/build-bundle.sh
@@ -312,6 +312,12 @@ validate_host_private_dir
resolve_rootfs
prepare_runtime_image
+# run.sh prepares the operator VM's image with prepare-runtime.sh as well,
+# and needs the appliance kernel chosen above.
+mkdir -p "$WORK_DIR/cache/libguestfs"
+for name in SUPERMIN_KERNEL SUPERMIN_MODULES SUPERMIN_KERNEL_VERSION; do
+ [[ -z "${!name:-}" ]] || printf 'export %s=%q\n' "$name" "${!name}"
+done >"$WORK_DIR/cache/libguestfs/supermin.env"
if bundle_is_current; then
log "reusing current host bundle: $BUNDLE_DIR"
diff --git a/testing/vm/files/end2end-tree.conf b/testing/vm/files/end2end-tree.conf
index f18e670a..ec0994de 100644
--- a/testing/vm/files/end2end-tree.conf
+++ b/testing/vm/files/end2end-tree.conf
@@ -1,4 +1,4 @@
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2026 Authors of shirudo
-endpoint = oci://127.0.0.1:15443/shirudo/end2end-tree
+endpoint = oci://registry.test:15443/shirudo/end2end-tree
reference = stable
diff --git a/testing/vm/guest.sh b/testing/vm/guest.sh
index 725cb4a6..e4ed8f36 100755
--- a/testing/vm/guest.sh
+++ b/testing/vm/guest.sh
@@ -19,6 +19,7 @@ UPPER=/var/tmp/shirudo-upper
OVERLAY_WORK=/var/tmp/shirudo-overlay-work
WORKSPACE=/workspace/shirudo
VM_MODE="${VM_MODE:-test}"
+VM_ROLE="${TEST_VM_ROLE:-target}"
SHIRUDO_BIN=/usr/local/bin/shirudo
VM_INITRD="${TEST_VM_INITRD:-1}"
@@ -276,6 +277,52 @@ write_target_test_env()
} >/etc/shirudo-test-vm.env
}
+# The operator holds the signing key and is no target: it has no TPM, and its
+# shirudo is the operator package, built here for the distribution it runs
+# on, as that package must be, from the files git sees in the checkout,
+# which the host lists.
+prepare_operator()
+{
+ local src=/var/tmp/shirudo-operator-src
+ local build_log=/mnt/shirudo-out/operator-build.log
+ local files=/mnt/shirudo-out/source-files
+ local debs
+
+ if [[ -e /dev/tpm0 || -e /dev/tpmrm0 ]]; then
+ log "the operator VM has a TPM"
+ return 1
+ fi
+ [[ -s /mnt/shirudo-operator-keys/signing_key.pem ]] || {
+ log "the operator VM has no signing key"
+ return 1
+ }
+ [[ -s "$files" ]] || {
+ log "the host listed no files of the checkout"
+ return 1
+ }
+ sed -E -i '/^[^#]*[[:space:]]registry\.test([[:space:]]|$)/d' /etc/hosts
+ printf '%s\n' '10.0.2.2 registry.test' >>/etc/hosts
+
+ log "building the operator package"
+ rm -rf -- "$src"
+ mkdir -p "$src"
+ rsync -a --from0 --files-from="$files" --ignore-missing-args \
+ "$LOWER"/ "$src"/
+ if ! make -C "$src/packaging" -j"$(nproc)" bindeb-pkg PKG_ROLES=operator \
+ >"$build_log" 2>&1; then
+ tail -40 "$build_log"
+ log "the operator package did not build; see operator-build.log"
+ return 1
+ fi
+ debs=("$src"/shirudo-operator_*.deb)
+ [[ ${#debs[@]} -eq 1 && -s "${debs[0]}" ]] || {
+ log "expected one operator package in $src"
+ return 1
+ }
+ dpkg -i "${debs[0]}"
+ shirudo version
+}
+
configure_oci_ca
configure_bpm_oci_repository
configure_map_export
@@ -319,6 +366,12 @@ fi
cd "$WORKSPACE"
+if [[ "$VM_ROLE" == operator ]]; then
+ prepare_operator
+ log "operator prepared; the host runs its steps over SSH"
+ exit 0
+fi
+
log "installing networking modules from the booted kernel artifact"
install_kernel_modules
install_kernel_config
diff --git a/testing/vm/list-source.sh b/testing/vm/list-source.sh
new file mode 100755
index 00000000..c8f8c7c0
--- /dev/null
+++ b/testing/vm/list-source.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# testing/vm/list-source.sh <output> -- write the files git sees in the
+# checkout, tracked and untracked but not ignored, NUL-separated, for the
+# copies the build container and the operator VM make of it. Neither can ask
+# git itself: the .git of a linked worktree names a directory outside the
+# checkout, which they do not see.
+
+set -eu
+
+root=$(cd "$(dirname "$0")/../.." && pwd)
+[ $# -eq 1 ] || {
+ printf 'usage: %s <output>\n' "$0" >&2
+ exit 2
+}
+# Root without SUDO_UID, as under systemd-run, cannot prove the checkout
+# its own to git.
+git -c safe.directory='*' -C "$root" ls-files -z -co --exclude-standard \
+ >"$1" || {
+ printf '%s: cannot list the files of %s with git; the build container and the operator VM copy what git sees, and BUILD_CONTAINER=0 builds the bundle in place\n' \
+ "$0" "$root" >&2
+ exit 1
+}
diff --git a/testing/vm/operator-packages b/testing/vm/operator-packages
new file mode 100644
index 00000000..e45b49fe
--- /dev/null
+++ b/testing/vm/operator-packages
@@ -0,0 +1,20 @@
+build-essential
+cryptsetup-bin
+curl
+dpkg-dev
+e2fsprogs
+git
+gpg
+libcurl4-openssl-dev
+libelf-dev
+libjitterentropy3-dev
+libluajit-5.1-dev
+libssl-dev
+libtss2-dev
+libzstd-dev
+llvm
+openssl
+pkg-config
+python3
+rsync
+zlib1g-dev
diff --git a/testing/vm/run.sh b/testing/vm/run.sh
index bf2066d7..b59ac176 100755
--- a/testing/vm/run.sh
+++ b/testing/vm/run.sh
@@ -17,12 +17,25 @@
# atomically. VM_TENANT is used as the map-export tenant when OTEL export is
# enabled. VM_VERBOSE=1 streams the QEMU output of a VM that runs tests to
# the terminal as well as the console log.
+#
+# TEST_VM_SERVE_COMMAND names a program a serve-mode VM runs on the host,
+# with the VM's name as its argument, instead of the target tests.
+# TEST_VM_ROLE=operator boots the operator of the end-to-end test in serve
+# mode: no TPM, no initrd and no shirudo kernel arguments, the operator
+# package built in the guest, and alone the signing key in
+# TEST_VM_OPERATOR_KEYS.
+# TEST_VM_PRIVATE_DIR names a new directory outside the checkout for the
+# key the host logs in with and the VM's disk, which holds the guest's own
+# key, for a VM no other may log in to: by default both lie in the VM's
+# state directory, which every VM reads through its share of the checkout.
+# The caller removes the directory.
set -euo pipefail
# The guest boots with the host's own QEMU, swtpm and dracut; a library path
# a shirudo build needed for its OpenSSL would load the wrong libraries into
-# them.
+# them. A serve command gets it back.
+HOST_LD_LIBRARY_PATH="${LD_LIBRARY_PATH-}"
unset LD_LIBRARY_PATH
SECONDS=0
@@ -73,6 +86,10 @@ MEMORY="${TEST_VM_MEMORY:-4G}"
DISK_SIZE="${TEST_VM_DISK_SIZE:-30G}"
VM_TIMEOUT="${TEST_VM_TIMEOUT:-3600}"
VM_MODE="${VM_MODE:-test}"
+VM_ROLE="${TEST_VM_ROLE:-target}"
+SERVE_COMMAND="${TEST_VM_SERVE_COMMAND:-}"
+OPERATOR_KEYS="${TEST_VM_OPERATOR_KEYS:-}"
+OPERATOR_DISK_SIZE=16G
VM_SUITE="${TEST_VM_SUITE:-}"
NODE_ROLE="${TEST_VM_NODE_ROLE:-core}"
TEST_MODE="${TEST_VM_MODE:-verity}"
@@ -85,6 +102,7 @@ VM_NAME_REQUEST="${VM_NAME:-}"
VM_TENANT="${VM_TENANT:-}"
VM_SSH_COMMAND="${VM_SSH_COMMAND:-}"
SSH_PORT_REQUEST="${TEST_VM_SSH_PORT:-}"
+PRIVATE_DIR="${TEST_VM_PRIVATE_DIR:-}"
KERNEL_URL="${TEST_VM_KERNEL_URL:-}"
KERNEL_SHA256="${TEST_VM_KERNEL_SHA256:-}"
KERNEL_OVERRIDE="${TEST_VM_KERNEL:-}"
@@ -112,6 +130,7 @@ MAP_EXPORT_TENANT_ID=""
MAP_EXPORT_ENABLED=0
RUN_DIR=""
SSH_DIR=""
+SSH_KEY=""
SSH_PORT=""
SSH_PUBLIC_KEY=""
SSH_PORT_LOCK_FD=""
@@ -170,6 +189,24 @@ valid_vm_name()
validate_mode()
{
[[ "$TEST_MODE" == verity ]] || die "TEST_VM_MODE must be verity"
+ [[ -z "$SERVE_COMMAND" || ( "$VM_MODE" == serve && -x "$SERVE_COMMAND" ) ]] ||
+ die "TEST_VM_SERVE_COMMAND must name a program, in serve mode"
+ case "$VM_ROLE" in
+ target)
+ [[ -z "$OPERATOR_KEYS" ]] ||
+ die "only an operator VM gets TEST_VM_OPERATOR_KEYS"
+ ;;
+ operator)
+ [[ "$VM_MODE" == serve && -n "$SERVE_COMMAND" && "$VM_INITRD" == 0 ]] ||
+ die "an operator VM runs in serve mode with TEST_VM_SERVE_COMMAND and TEST_VM_INITRD=0"
+ [[ -s "$OPERATOR_KEYS/signing_key.pem" ]] ||
+ die "TEST_VM_OPERATOR_KEYS must name the directory of the operator's signing key"
+ return 0
+ ;;
+ *)
+ die "TEST_VM_ROLE must be 'target' or 'operator'"
+ ;;
+ esac
if [[ "$VM_SUITE" != register ]]; then
[[ "$VM_INITRD" == 1 && "$SKIP_SEAL" == 0 ]] ||
die "dm-verity requires TEST_VM_INITRD=1 and TEST_VM_SKIP_SEAL=0"
@@ -210,6 +247,18 @@ validate_mode()
esac
}
+validate_private_dir()
+{
+ local dir repo
+
+ [[ -n "$PRIVATE_DIR" ]] || return 0
+ dir="$(realpath -m "$PRIVATE_DIR")"
+ repo="$(realpath -m "$REPO_ROOT")"
+ [[ "$dir" != "$repo"/* && ! -e "$dir" ]] ||
+ die "TEST_VM_PRIVATE_DIR must name a new directory outside the repository"
+ PRIVATE_DIR="$dir"
+}
+
validate_map_export()
{
local configured=0
@@ -464,6 +513,37 @@ validate_host_bundle()
die "prepared runtime image is missing: $runtime_image; run 'make -C testing bundle'"
}
+start_swtpm()
+{
+ local _
+
+ chmod 0700 "$RUN_DIR/tpm"
+ if user_systemd_available; then
+ SWTPM_UNIT_FILE="${RUN_DIR}/swtpm.unit"
+ SWTPM_UNIT="shirudo-vm-${VM_NAME}-swtpm.service"
+ start_user_unit "$SWTPM_UNIT" "$RUN_DIR/swtpm.log" \
+ swtpm socket --tpmstate "dir=${RUN_DIR}/tpm,mode=0700" \
+ --ctrl "type=unixio,path=tpm/swtpm-sock" \
+ --tpm2 --log "file=${RUN_DIR}/swtpm.log,level=20"
+ printf '%s\n' "$SWTPM_UNIT" >"$SWTPM_UNIT_FILE"
+ SWTPM_PID="$(user_unit_pid "$SWTPM_UNIT")" || die "could not determine swtpm systemd PID"
+ printf '%s\n' "$SWTPM_PID" >"$SWTPM_PIDFILE"
+ else
+ # Ubuntu's AppArmor profile for swtpm closes an inherited terminal, and
+ # swtpm --daemon never returns when it starts without fds 0 to 2.
+ swtpm socket --tpmstate "dir=${RUN_DIR}/tpm,mode=0700" \
+ --ctrl "type=unixio,path=tpm/swtpm-sock" \
+ --tpm2 --log "file=${RUN_DIR}/swtpm.log,level=20" \
+ --pid "file=${SWTPM_PIDFILE}" --daemon </dev/null 2>&1 |
+ sed 's/^/[test-vm] swtpm: /' >&2
+ fi
+ for _ in {1..50}; do
+ [[ -S "$SWTPM_SOCKET" ]] && return 0
+ sleep 0.1
+ done
+ die "swtpm control socket did not appear"
+}
+
stop_swtpm()
{
local pid
@@ -671,7 +751,7 @@ ssh_options()
-o StrictHostKeyChecking=accept-new
-o GlobalKnownHostsFile=/dev/null
-o UserKnownHostsFile="${SSH_DIR}/known_hosts"
- -o IdentityFile="${SSH_DIR}/id_ed25519"
+ -o IdentityFile="$SSH_KEY"
-o ServerAliveInterval=15
-o ServerAliveCountMax=8
-p "$SSH_PORT"
@@ -684,7 +764,7 @@ wait_for_ssh()
for _ in {1..60}; do
ssh "${SSH_ARGS[@]}" -o BatchMode=yes [email protected] true \
- >/dev/null 2>&1 && return 0
+ </dev/null >/dev/null 2>&1 && return 0
sleep 1
done
return 1
@@ -719,6 +799,17 @@ run_target_tests_over_ssh()
return "$status"
}
+# The serve command runs with the caller's environment, less what made this
+# VM an operator and the file of its SSH key, since it boots other VMs.
+run_serve_command()
+{
+ log "running $(basename "$SERVE_COMMAND") for VM '$VM_NAME'"
+ env -u TEST_VM_ROLE -u TEST_VM_SERVE_COMMAND -u TEST_VM_OPERATOR_KEYS \
+ -u TEST_VM_PRIVATE_DIR \
+ ${HOST_LD_LIBRARY_PATH:+LD_LIBRARY_PATH="$HOST_LD_LIBRARY_PATH"} \
+ "$SERVE_COMMAND" "$VM_NAME" </dev/null
+}
+
# A serve-mode guest that prepared itself waits for the host-done marker in
# its result share, then powers itself off as a test-mode guest does.
serve_target_tests()
@@ -729,7 +820,11 @@ serve_target_tests()
guest_status="$(<"$RUN_DIR/result/status")"
fi
[[ "$guest_status" == 0 ]] || return 0
- run_target_tests_over_ssh
+ if [[ -n "$SERVE_COMMAND" ]]; then
+ run_serve_command
+ else
+ run_target_tests_over_ssh
+ fi
SERVE_STATUS=$?
: >"$RUN_DIR/result/host-done"
for _ in {1..1200}; do
@@ -748,7 +843,9 @@ run_ssh()
require_running_vm
check_access_dependency ssh
SSH_DIR="${RUN_DIR}/ssh"
- [[ -s "$RUN_DIR/ssh.port" && -r "$SSH_DIR/id_ed25519" ]] ||
+ SSH_KEY="$SSH_DIR/id_ed25519"
+ [[ ! -s "$RUN_DIR/ssh.key" ]] || SSH_KEY="$(<"$RUN_DIR/ssh.key")"
+ [[ -s "$RUN_DIR/ssh.port" && -r "$SSH_KEY" ]] ||
die "VM '$VM_NAME' has no SSH access metadata"
SSH_PORT="$(<"$RUN_DIR/ssh.port")"
[[ "$SSH_PORT" =~ ^[0-9]+$ ]] ||
@@ -1056,8 +1153,8 @@ cleanup()
print_test_summary
if [[ "$FINAL_STATUS" -eq 0 ]]; then
# A passed run keeps its logs, not the disks it booted.
- rm -f -- "$RUN_DIR/rootfs.qcow2" "$RUN_DIR/initrd.img" \
- "$RUN_DIR/seed.img"
+ rm -f -- "${PRIVATE_DIR:-$RUN_DIR}/rootfs.qcow2" \
+ "$RUN_DIR/initrd.img" "$RUN_DIR/seed.img"
rm -rf -- "$RUN_DIR/initrd-seed"
else
log "warning: the guest overlay contains an ephemeral signing key"
@@ -1191,6 +1288,34 @@ initrd_cache_key()
} | sha256sum | awk '{print $1}'
}
+# The operator's image: the runtime image with the toolchain that builds the
+# operator package, and clang 23 the way CI installs it. The key file beside
+# it marks it complete, as for the runtime image.
+prepare_operator_image()
+{
+ local packages="$REPO_ROOT/testing/vm/operator-packages"
+ local clang="$REPO_ROOT/.github/scripts/install-clang.sh"
+ local key
+
+ # The bundle builder chose the kernel of the libguestfs appliance, a
+ # downloaded one on a host without its own.
+ if [[ -s "$CACHE_DIR/libguestfs/supermin.env" ]]; then
+ # shellcheck source=/dev/null
+ . "$CACHE_DIR/libguestfs/supermin.env"
+ fi
+ key="operator-$({
+ printf '%s\n' "$RUNTIME_KEY" "$OPERATOR_DISK_SIZE"
+ sha256sum <"$packages"
+ sha256sum <"$clang"
+ } | sha256sum | cut -d' ' -f1)"
+ "$REPO_ROOT/testing/vm/prepare-runtime.sh" --rootfs "$ROOTFS" \
+ --cache-dir "$RUNTIME_CACHE_DIR" --package-file "$packages" \
+ --setup-script "$clang" --runtime-key "$key" \
+ --runtime-disk-size "$OPERATOR_DISK_SIZE" \
+ --key-output "$RUNTIME_CACHE_DIR/.$key.key"
+ ROOTFS="$RUNTIME_CACHE_DIR/$key.qcow2"
+}
+
prepare_initrd()
{
local key cache_dir build_dir lock_fd
@@ -1309,12 +1434,16 @@ allocate_ssh_access()
local port
SSH_DIR="${RUN_DIR}/ssh"
+ SSH_KEY="${PRIVATE_DIR:-$SSH_DIR}/id_ed25519"
mkdir -p "$SSH_DIR"
(
umask 077
- ssh-keygen -q -t ed25519 -N '' -f "$SSH_DIR/id_ed25519"
+ mkdir -p "$(dirname "$SSH_KEY")"
+ ssh-keygen -q -t ed25519 -N '' -f "$SSH_KEY"
)
- SSH_PUBLIC_KEY="$(<"$SSH_DIR/id_ed25519.pub")"
+ [[ -z "$PRIVATE_DIR" ]] ||
+ printf '%s\n' "$SSH_KEY" >"$RUN_DIR/ssh.key"
+ SSH_PUBLIC_KEY="$(<"$SSH_KEY.pub")"
exec {SSH_PORT_LOCK_FD}>"${VM_ROOT}/ssh-port.lock"
flock "$SSH_PORT_LOCK_FD"
@@ -1414,6 +1543,7 @@ while [[ "$#" -gt 0 ]]; do
done
validate_mode
+validate_private_dir
validate_kernel_selection
validate_kernel_artifact
validate_map_export
@@ -1430,6 +1560,8 @@ check_host_dependencies
validate_host_bundle
[[ "$CPUS" =~ ^[1-9][0-9]*$ ]] || die "TEST_VM_CPUS must be a positive integer"
[[ "$VM_TIMEOUT" =~ ^[1-9][0-9]*$ ]] || die "TEST_VM_TIMEOUT must be a positive integer"
+# The operator serves through the target VM's whole run.
+[[ "$VM_ROLE" != operator ]] || VM_TIMEOUT=$((VM_TIMEOUT * 2))
mkdir -p "$CACHE_DIR"
allocate_run_dir
@@ -1443,7 +1575,10 @@ KERNEL="$(resolve_kernel)"
RUNTIME_KEY="$(<"$TEST_VM_HOST_BUNDLE/runtime-image-key")"
ROOTFS="$RUNTIME_CACHE_DIR/$RUNTIME_KEY.qcow2"
-OVERLAY="${RUN_DIR}/rootfs.qcow2"
+[[ "$VM_ROLE" != operator ]] || prepare_operator_image
+[[ "$VM_ROLE" != operator ]] ||
+ "$REPO_ROOT/testing/vm/list-source.sh" "$RUN_DIR/result/source-files"
+OVERLAY="${PRIVATE_DIR:-$RUN_DIR}/rootfs.qcow2"
SEED="${RUN_DIR}/seed.img"
USER_DATA="${RUN_DIR}/user-data"
META_DATA="${RUN_DIR}/meta-data"
@@ -1572,6 +1707,7 @@ printf ' export TEST_VM_NODE_ROLE=%q\n' "$NODE_ROLE" >>"$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"
printf ' export TEST_VM_SSH_PUBLIC_KEY=%q\n' "$SSH_PUBLIC_KEY" >>"$USER_DATA"
+printf ' export TEST_VM_ROLE=%q\n' "$VM_ROLE" >>"$USER_DATA"
if [[ -n "$OCI_CA_DIR" ]]; then
printf ' export TEST_VM_OCI_CA=/mnt/shirudo-oci/ca.crt\n' >>"$USER_DATA"
fi
@@ -1622,6 +1758,10 @@ cat >>"$USER_DATA" <<'EOF'
fi
EOF
cat >>"$USER_DATA" <<'EOF'
+ if [ "$TEST_VM_ROLE" = operator ]; then
+ mkdir -p /mnt/shirudo-operator-keys
+ mount -t 9p -o trans=virtio,version=9p2000.L,msize=104857600,ro shirudo-operator-keys /mnt/shirudo-operator-keys || rc=$?
+ fi
mount -t 9p -o trans=virtio,version=9p2000.L,msize=104857600,ro shirudo-src /mnt/shirudo-src || rc=$?
if [ "$rc" -eq 0 ]; then
bash /mnt/shirudo-src/testing/vm/guest.sh || rc=$?
@@ -1645,38 +1785,17 @@ EOF
make_seed
cd "$RUN_DIR" || die "cannot enter $RUN_DIR"
-chmod 0700 "$RUN_DIR/tpm"
-if user_systemd_available; then
- SWTPM_UNIT_FILE="${RUN_DIR}/swtpm.unit"
- SWTPM_UNIT="shirudo-vm-${VM_NAME}-swtpm.service"
- start_user_unit "$SWTPM_UNIT" "$RUN_DIR/swtpm.log" \
- swtpm socket --tpmstate "dir=${RUN_DIR}/tpm,mode=0700" \
- --ctrl "type=unixio,path=tpm/swtpm-sock" \
- --tpm2 --log "file=${RUN_DIR}/swtpm.log,level=20"
- printf '%s\n' "$SWTPM_UNIT" >"$SWTPM_UNIT_FILE"
- SWTPM_PID="$(user_unit_pid "$SWTPM_UNIT")" || die "could not determine swtpm systemd PID"
- printf '%s\n' "$SWTPM_PID" >"$SWTPM_PIDFILE"
-else
- # Ubuntu's AppArmor profile for swtpm closes an inherited terminal, and
- # swtpm --daemon never returns when it starts without fds 0 to 2.
- swtpm socket --tpmstate "dir=${RUN_DIR}/tpm,mode=0700" \
- --ctrl "type=unixio,path=tpm/swtpm-sock" \
- --tpm2 --log "file=${RUN_DIR}/swtpm.log,level=20" \
- --pid "file=${SWTPM_PIDFILE}" --daemon </dev/null 2>&1 |
- sed 's/^/[test-vm] swtpm: /' >&2
-fi
-for _ in {1..50}; do
- [[ -S "$SWTPM_SOCKET" ]] && break
- sleep 0.1
-done
-[[ -S "$SWTPM_SOCKET" ]] || die "swtpm control socket did not appear"
+[[ "$VM_ROLE" != target ]] || start_swtpm
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"
-KERNEL_LSM_ARGS+=" dm_verity.keyring_unsealed=1 initcall_debug ignore_loglevel"
+KERNEL_LSM_ARGS=""
+if [[ "$VM_ROLE" == target ]]; then
+ # 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"
+ KERNEL_LSM_ARGS+=" dm_verity.keyring_unsealed=1 initcall_debug ignore_loglevel"
+fi
KERNEL_NET_DEVICE="virtio-net-pci,netdev=net0"
# The virt machine has no if=virtio mapping, so its disks are explicit PCI
@@ -1715,9 +1834,6 @@ QEMU_ARGS=(
-virtfs "local,id=shirudo-src,path=${REPO_ROOT},mount_tag=shirudo-src,security_model=none,readonly=on" \
-virtfs "local,id=shirudo-bundle,path=${TEST_VM_HOST_BUNDLE},mount_tag=shirudo-bundle,security_model=none,readonly=on" \
-virtfs "local,id=shirudo-out,path=${RUN_DIR}/result,mount_tag=shirudo-out,security_model=none" \
- -chardev "socket,id=chrtpm,path=tpm/swtpm-sock" \
- -tpmdev emulator,id=tpm0,chardev=chrtpm \
- -device "$TPM_DEVICE" \
-chardev "socket,id=console,path=console.sock,server=on,wait=off,logfile=${RUN_DIR}/console.log,logappend=on" \
-serial chardev:console \
-display none \
@@ -1731,6 +1847,18 @@ if [[ -n "$KERNEL_ARTIFACT_DIR" ]]; then
)
fi
+if [[ "$VM_ROLE" == target ]]; then
+ QEMU_ARGS+=(
+ -chardev "socket,id=chrtpm,path=tpm/swtpm-sock"
+ -tpmdev emulator,id=tpm0,chardev=chrtpm
+ -device "$TPM_DEVICE"
+ )
+else
+ QEMU_ARGS+=(
+ -virtfs "local,id=shirudo-operator-keys,path=${OPERATOR_KEYS},mount_tag=shirudo-operator-keys,security_model=none,readonly=on"
+ )
+fi
+
if [[ -n "$INITRD" ]]; then
QEMU_ARGS+=(-initrd "$INITRD")
fi
@@ -1883,6 +2011,8 @@ else
"$QEMU_BIN" "${QEMU_ARGS[@]}" \
>"$RUN_DIR/qemu.log" 2>&1 &
QEMU_PID=$!
+ # run.sh --ssh reaches a serve-mode VM by its PID file while it serves.
+ [[ "$VM_MODE" != serve ]] || printf '%s\n' "$QEMU_PID" >"$RUN_DIR/qemu.pid"
wait_for_ssh_listener
while :; do
show_progress
@@ -1894,6 +2024,7 @@ else
[[ "$VM_MODE" != serve ]] || serve_target_tests
wait "$QEMU_PID"
QEMU_STATUS=$?
+ rm -f -- "$RUN_DIR/qemu.pid"
for _ in {1..5}; do
show_progress
sleep 0.1
@@ -1907,11 +2038,13 @@ else
die "QEMU exited with status $QEMU_STATUS"
QEMU_PID=""
read_guest_status
- case "$SERVE_STATUS" in
- 0) ;;
- 255) die "the SSH session that ran the target tests failed" ;;
- *) die "target tests failed over SSH with status $SERVE_STATUS" ;;
- esac
+ if [[ "$SERVE_STATUS" -ne 0 ]]; then
+ [[ -z "$SERVE_COMMAND" ]] ||
+ die "$(basename "$SERVE_COMMAND") failed with status $SERVE_STATUS"
+ [[ "$SERVE_STATUS" -ne 255 ]] ||
+ die "the SSH session that ran the target tests failed"
+ die "target tests failed over SSH with status $SERVE_STATUS"
+ fi
FINAL_STATUS=0
fi
diff --git a/testing/vm/stack-lib.sh b/testing/vm/stack-lib.sh
index cc9dd0f1..39559d21 100644
--- a/testing/vm/stack-lib.sh
+++ b/testing/vm/stack-lib.sh
@@ -26,7 +26,11 @@ stack_prepare()
openssl req -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
-keyout "$TLS_DIR/server.key" -out "$TLS_DIR/server.csr" \
-subj /CN=shirudo-end2end 2>/dev/null
- printf 'subjectAltName=IP:127.0.0.1,IP:10.0.2.2\n' >"$TLS_DIR/server.ext"
+ # The end-to-end VMs name the registry registry.test; guests reach the
+ # collector, and other guests the registry, at QEMU's address for the
+ # host, and the host reaches both on its loopback.
+ printf 'subjectAltName=DNS:registry.test,IP:127.0.0.1,IP:10.0.2.2\n' \
+ >"$TLS_DIR/server.ext"
openssl x509 -req -in "$TLS_DIR/server.csr" -CA "$W/ca.pem" \
-CAkey "$TLS_DIR/ca.key" -CAcreateserial -out "$TLS_DIR/server.pem" \
-days 3650 -extfile "$TLS_DIR/server.ext" 2>/dev/null