eBPF-based security platform
testing: enroll an end-to-end node through credential activation
John Fastabend6bc390d7a43b
diff --git a/.agents/skills/testing/SKILL.md b/.agents/skills/testing/SKILL.mdindex 49ab6000..dfe468af 100644--- a/.agents/skills/testing/SKILL.md+++ b/.agents/skills/testing/SKILL.md@@ -29,23 +29,27 @@ PATH=$PWD/build/afl/bin:$PATH make -C testing afl [AFL_SECONDS=600]make -C testing help```-The end2end tier runs t9107, and t9109 to t9111 on the host, against+The end2end tier runs t9107, and t9109 to t9112 on the host, againstthe keepalive backend of `tools/backend`, which `host.sh` starts forevery run. The tier boots two VMs at once, each with its ownswtpm: node A runs the tests, node B (`make -C testing vm-node-end2end`,node mode of `vm/run.sh`) takes `role=core` from `config-core` and waits.Node mode first runs `vm/tpm-builder.sh`, which creates the node's AK-and EK with tpm2-tools and writes their names to `tpm-names` in the VM's-state directory; host.sh verifies node B against them and t9109 enrolls-it in the backend, so node mode needs tpm2-tools and swtpm-tools on the-host.-With a backend, a fresh edge node (`END2END_NODE=edge`, `role=edge` from-`config-edge`) boots once node A has stopped, and `host.sh` runs t9109,-then t9110, which continues t9109's tree in segments, on the host against-it and node B. Then a second fresh pair boots in their place, as-`<name>-2-end2end-edge` and `-b`, the registry restarts empty, and+and EK with tpm2-tools, writes their names to `tpm-names` in the VM's+state directory, and stores an EK certificate from a throwaway CA whose+certificate it leaves in `ek-ca.pem` beside them; host.sh verifies node+B against the names and t9109 enrolls it in the backend, t9112 enrolls+the edge node through credential activation against its CA, so node mode+needs tpm2-tools, the swtpm TCTI of tpm2-tss (`libtss2-tcti-swtpm0t64`),+swtpm-tools and openssl on the host. The tier needs the quote checker,+which `make -C testing end2end` builds first. A fresh edge node+(`END2END_NODE=edge`, `role=edge` from `config-edge`) boots once node A+has stopped, and `host.sh` runs t9109,+then t9110, which continues t9109's tree in segments, and t9112, on the+host against it and node B. Then a second fresh pair boots in their+place, as `<name>-2-end2end-edge` and `-b`, the registry restarts empty, and`host.sh` runs t9111, the backward walk over sealed segments, against-them. Their output is `build/test-vm/end2end/t9109.log` to `t9111.log`.+them. Their output is `build/test-vm/end2end/t9109.log` to `t9112.log`.A test reaches the nodes with `node_sh b` or `node_sh edge` of`testing/end2end/node-lib.sh`, and does to them, the registry and thebackend what `testing/end2end/pipeline-lib.sh` offers. Their boot logsdiff --git a/.github/scripts/tests.sh b/.github/scripts/tests.shindex d7cab954..ea279b6e 100755--- a/.github/scripts/tests.sh+++ b/.github/scripts/tests.sh@@ -290,7 +290,7 @@ setup() {set -- "$@" autoconf autoconf-archive automake cloud-image-utils \dracut-core file isc-dhcp-client libguestfs-tools libltdl-dev \libtool libzstd-dev qemu-system-x86 qemu-utils swtpm \- swtpm-tools tpm2-tools+ swtpm-tools tpm2-tools libtss2-tcti-swtpm0t64fimkdir -p buildsudo BPF_VMLINUX_BTF="$PWD/$kernel/vmlinux.btf" \diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex 1e4d0479..52f8619d 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -781,6 +781,14 @@ signed config image.with the masks ``VQ==`` and ``mg==``, no walk once both are at thenew segment's base, keepalives over all three segments and bothnodes ``healthy``+ * - ``t9112-activation``+ - Enrollment through credential activation on a real vTPM, run by+ ``host.sh`` after ``t9110`` on the same nodes: an endorsement+ certificate from the edge node's own test CA chaining through+ ``attest challenge --ek-ca``, another node's CA refused, the+ challenge refused by another node, the answer verified with+ ``--expect-credential``, and the key moving from ``untrusted`` to+ ``enrolled`` in the backendUnit suites and fuzz targets~~~~~~~~~~~~~~~~~~~~~~~~~~~~@@ -933,7 +941,8 @@ Coverage by area``t6125``, ``t6128``, ``t6143``, ``t6144``. Unit: ``chain``* - Attestation- ``t2003``, ``t2005``, ``t4003``, ``t4004``, ``t4102``,- ``t4104``, ``t9105``, ``t9109``. Fuzz: ``attest``, ``tpm-wire``+ ``t4104``, ``t9105``, ``t9109``, ``t9112``. Fuzz: ``attest``,+ ``tpm-wire``* - Eventlog- ``t4002``, ``t4102``, ``t5007``, ``t6114``, ``t6128``. Fuzz:``eventlog``. Unit: ``eventlog``, ``io``@@ -1027,7 +1036,7 @@ The threats are those of :doc:`/security/threat-model`.* - T8 Quantum-capable adversaries- ``t2001``, ``t2002``, ``t5001``, ``t8005``* - T9 A target lying about its state- - ``t4001``, ``t4003``, ``t4004``, ``t4102``, ``t9105``+ - ``t4001``, ``t4003``, ``t4004``, ``t4102``, ``t9105``, ``t9112``* - T10 An attempt that leaves no trace- ``t6003``, ``t6108``, ``t6118``, ``t6119``, ``t6120``,``t6121``, ``t6124``, ``t6126``, ``t6135``, ``t6137``diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rstindex 1a9e4c6d..80784bf5 100644--- a/Documentation/contribute/testing/testing.rst+++ b/Documentation/contribute/testing/testing.rst@@ -35,8 +35,9 @@ Before you beginwhat ``make target`` needs. On Ubuntu,``.github/scripts/tests.sh setup`` installs ``cloud-image-utils``,``dracut-core``, ``file``, ``isc-dhcp-client``, ``libguestfs-tools``,- ``qemu-system-x86``, ``qemu-utils``, ``swtpm``, ``swtpm-tools`` and- ``tpm2-tools`` among others. :src:`testing/vm/run.sh` names the packages+ ``qemu-system-x86``, ``qemu-utils``, ``swtpm``, ``swtpm-tools``,+ ``tpm2-tools`` and the swtpm TCTI ``libtss2-tcti-swtpm0t64`` among+ others; ``tpm2-tss`` carries that TCTI on Fedora. :src:`testing/vm/run.sh` names the packagesit misses with an install command for ``apt-get`` or ``dnf``. Thebundle carries the TPM simulator helper, so:src:`testing/vm/build-bundle.sh` builds no bundle without@@ -188,10 +189,10 @@ a Python companion with the same stem, such asbefore ``init``. They skip on the build host and run in a separate VMthat the ``tpm`` family boots without the production initrd.-``t9109``, ``t9110`` and ``t9111`` carry target numbers but run on the-host: :src:`testing/end2end/host.sh` runs them after node A's suite, in-that order, against other nodes (see :ref:`testing-two-nodes`), and node-A's runner leaves them out.+``t9109`` to ``t9112`` carry target numbers but run on the host:+:src:`testing/end2end/host.sh` runs them after node A's suite, ``t9109``,+``t9110``, ``t9112`` and then ``t9111``, against other nodes (see+:ref:`testing-two-nodes`), and node A's runner leaves them out.Run the tests-------------@@ -741,10 +742,10 @@ Run the end-to-end tests``make -C testing end2end`` runs ``t9001`` on the host, then:src:`testing/end2end/host.sh` runs the test with an operator VM and thetarget 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.+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 builddependencies of the operator package added, which the runner prepares@@ -764,7 +765,7 @@ against the headers and ``vmlinux.h`` of the package, pushes it withoperator VM and node A name the registry ``registry.test``, at QEMU'saddress for the host, so the tree names it as node A reaches it. Thehost'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``,+for the keepalive backend's example tree and for ``t9109`` to ``t9112``,which run on the host.Node A and node B boot next. Node A activates a signed config that@@ -804,8 +805,11 @@ the host. ClickHouse is available to the collector on the test's Dockernetwork.``t9107`` runs the backend of :src:`tools/backend/`-(:doc:`/operate/integrations/backend`). ``host.sh`` starts a ClickHouse-of the backend's own on ``http://127.0.0.1:18125``, with the backend's schema+(:doc:`/operate/integrations/backend`), so the tier needs+``tools/quote-check/shirudo-quote-check``, which+``make -C testing end2end`` builds first; ``host.sh``, run without it,+stops before it starts anything. ``host.sh`` starts a ClickHouse of the+backend's own on ``http://127.0.0.1:18125``, with the backend's schemaand ``shirudo-quote-check`` as ``tpm_quote_check``, and a collector withthe backend's configuration on ``https://127.0.0.1:14320``. It publishesthe example tree of :src:`testing/fixtures/keepalive/` signed with the@@ -813,14 +817,16 @@ operator key and loads it with the backend's tree ingest job, which runs``bpm tree show``. In the guest, ``t9107`` sends the example keepaliveswith their recorded quotes through that collector and queriesClickHouse, both through QEMU's address for the host. After node A,-``host.sh`` runs ``t9109``, ``t9110`` and ``t9111`` against the same-backend, see :ref:`testing-pipeline`, :ref:`testing-history` and-:ref:`testing-walk`. ``host.sh`` writes the example tree's digest to-``build/test-vm/end2end/backend-tree.digest`` once the backend has loaded-it. Without that file, as in a run of the family without ``host.sh``,-:src:`testing/run-target-tests.sh` leaves ``t9107`` out with ``not run-without a keepalive backend`` rather than failing the family on its-skip.+``host.sh`` runs ``t9109`` to ``t9112`` against the same backend, see+:ref:`testing-pipeline`, :ref:`testing-history`,+:ref:`testing-activation` and :ref:`testing-walk`. ``host.sh`` writes+the example tree's digest to ``build/test-vm/end2end/backend-tree.digest``+when it publishes the tree, and removes it when the backend's tree+ingest job does not load the tree and when ``host.sh`` stops. Without+that file, as in a run of the family without ``host.sh``,+:src:`testing/run-target-tests.sh` leaves+``t9107`` out with ``not run without a keepalive backend`` rather than+failing the family on its skip... _testing-two-nodes:@@ -832,9 +838,9 @@ own software TPM and so its own attestation key. The operator VM runsbeside the first two, node A and node B, and stops before the othersboot. Node A is the family'sVM, 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-stopped, and ``t9109`` and then ``t9110`` run against it and node B.+Node B, ``<name>-end2end-b``, boots beside it. The fresh edge node,+``<name>-end2end-edge``, boots once node A has stopped, and ``t9109``,+``t9110`` and then ``t9112`` run against it and node B.Once both have stopped, a second fresh edge node and node B,``<name>-2-end2end-edge`` and ``<name>-2-end2end-b``, boot for``t9111``. All of them boot with ``make -C testing vm-node-end2end``, ``END2END_NODE=b`` or@@ -846,9 +852,13 @@ acts as the builder of :doc:`/operate/run/attest`::src:`testing/vm/tpm-builder.sh` creates the attestation key and theendorsement key in the node's fresh vTPM state, with the tpm2-toolscommands that page gives, and writes their names to ``tpm-names`` in the-VM's state directory. ``host.sh`` copies the file beside the node's SSH-key and verifies node B's evidence against those names, never against-the names the evidence carries, and checks that node A's key fails. Each takes its role from a signed+VM's state directory. As the vTPM's maker, it also writes an+endorsement certificate for the endorsement key to the ECC index of the+TCG profile, ``0x01C0000A``, signed by a CA of its own whose key it+throws away, and leaves the CA's certificate in ``ek-ca.pem`` beside the+names. ``host.sh`` copies both files beside the node's SSH key and+verifies node B's evidence against those names, never against the names+the evidence carries, and checks that node A's key fails. Each takes its role from a signedconfig image, as ``t9105`` configures node A:.. list-table::@@ -1034,6 +1044,34 @@ the kernel advisory ``shielded`` by ``xfs-fix`` at seq 3, below thewindow, on the edge node and ``unknown`` on node B, as threat U20 of:doc:`/security/threat-model` says.+.. _testing-activation:++The enrollment by activation+~~~~~~~~~~~~~~~~~~~~~~~~~~~~++``t9112`` enrolls the edge node the way the first method of+:doc:`/operate/run/attest` does, through credential activation, where+``t9109`` enrolls node B from its builder's records. ``host.sh`` runs it+after ``t9110``, against the same nodes and backend, and its output is+``build/test-vm/end2end/t9112.log``. It:++#. checks that the backend holds the edge node's key ``untrusted``;+#. collects evidence from the edge node with a fresh nonce, and checks+ that it names the attestation key of the node's keepalives and+ carries an ECC endorsement certificate;+#. makes a challenge with ``--ek-ca`` set to node B's ``ek-ca.pem``,+ which refuses with ``FAIL endorsement certificate: chains to``, and+ then with the edge node's own, which passes and prints the credential;+#. hands the challenge to node B, which refuses it as made for another+ attestation key;+#. has the edge node answer it with a second nonce, and verifies the+ answer with both names and ``--expect-credential``, which passes with+ the credential and fails with another;+#. inserts the key into ``shirudo.nodes`` as ``enrolled``, and checks+ that ``node_status`` then reads the edge node ``enrolled`` and node B,+ whose enrollment of ``t9109`` went with the schema ``t9110`` loaded+ again, still ``untrusted``.+.. _testing-walk:The backward walk@@ -1087,7 +1125,7 @@ holds the three segments, ``tree_ops`` the five operations and``node_ops`` each node from seq 1, with no contradiction marked, andboth nodes are ``healthy`` with ``4 chain: pass``, ``5 head: pass, seq 5of 5`` and ``6 set: pass``. :src:`testing/end2end/pipeline-lib.sh` holds-what ``t9109`` to ``t9111`` do to the nodes, the registry and+what ``t9109`` to ``t9112`` do to the nodes, the registry andClickHouse.Select test scriptsdiff --git a/testing/end2end/host.sh b/testing/end2end/host.shindex 5bf6d4c3..c3d25553 100755--- a/testing/end2end/host.sh+++ b/testing/end2end/host.sh@@ -7,10 +7,10 @@# 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.+# collector and node B. A fresh edge node boots in node A's place and t9109,+# t9110 and t9112 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@@ -65,6 +65,7 @@ down() {NODE_B_PID=stack_downrm -rf -- "$TLS_DIR" "$OPERATOR_PRIVATE_DIR"+ rm -f -- "$W/backend-tree.digest"}# A command in the operator VM, over SSH.@@ -80,7 +81,8 @@ node_run_dir() {# Boot node $1, b with the core role or edge with the edge role, prepared# like node A but without tests, and record in $NODES_DIR/node-$1 how to-# reach it and the key names its vTPM's builder recorded before it booted.+# reach it, the key names its vTPM's builder recorded before it booted and+# the CA of its vTPM's endorsement certificate.node_boot() {run=$(node_run_dir "$1")mkdir -p "$NODES_DIR/node-$1"@@ -90,6 +92,7 @@ node_boot() {>"$W/node-$1$NODE_ROUND.log" 2>&1 &&cp "$run/ssh.port" "$NODES_DIR/node-$1/port" &&cp "$run/tpm-names" "$NODES_DIR/node-$1/tpm-names" &&+ cp "$run/ek-ca.pem" "$NODES_DIR/node-$1/ek-ca.pem" &&install -m 0600 "$run/ssh/id_ed25519" "$NODES_DIR/node-$1/key"; then: >"$NODES_DIR/node-$1/ready"else@@ -274,6 +277,7 @@ fi[ $# -eq 0 ] || die "usage: $0"command -v docker >/dev/null 2>&1 || die "docker is required"+[ -x "$CHECKER" ] || die "no quote checker: $CHECKER; run make quote-check"private_dir="$(realpath -m "$HOST_PRIVATE_DIR")"repo_dir="$(realpath -m "$REPO")"[ "$private_dir" != "$repo_dir" ] &&@@ -295,7 +299,6 @@ stack_oci || die "the registry did not come up"stack_telemetry || die "the telemetry stack did not come up"say "the keepalive backend of tools/backend"-[ -x "$CHECKER" ] || die "no quote checker: $CHECKER"stack_backend "$BACKEND" "$CHECKER" ||die "the keepalive backend did not come up"@@ -309,11 +312,9 @@ TEST_VM_SERVE_COMMAND="$REPO/testing/end2end/host.sh" \# 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 $E2E_VM-end2end-edge"- node_boot edge &- NODE_EDGE_PID=$!-fi+say "the fresh edge node, in $E2E_VM-end2end-edge"+node_boot edge &+NODE_EDGE_PID=$!say "the collector holds what kernel-obs observed"python3 "$REPO/testing/end2end/check-otlp.py" "$RESULT/otel" \@@ -336,8 +337,8 @@ assert not [r for r in evidence["eventlog"] if r["type"] == "upatch_load"]' \"$W/node-b-evidence.json" ||die "node B loaded an upatch while it was prepared"# The names come from the builder, never from the node.-ak_b=$(sed -n 's/^ak-name //p' "$NODES_DIR/node-b/tpm-names")-ek_b=$(sed -n 's/^ek-name //p' "$NODES_DIR/node-b/tpm-names")+ak_b=$(node_builder_name b ak)+ek_b=$(node_builder_name b ek)"$S" attest verify --evidence="$W/node-b-evidence.json" \--nonce="$(cat "$W/nonce")" --ak-name="$ak_b" --ek-name="$ek_b" \--allow-runtime-events --require-initrd >"$W/node-b-verify.out" 2>&1 &&@@ -347,8 +348,11 @@ ek_b=$(sed -n 's/^ek-name //p' "$NODES_DIR/node-b/tpm-names")}! "$S" attest verify --evidence="$W/node-b-evidence.json" \--nonce="$(cat "$W/nonce")" --ak-name="$ak" --ek-name="$ek_b" \- --allow-runtime-events --require-initrd >"$W/node-b-wrong.out" 2>&1 ||- die "the evidence of node B verifies against node A's attestation key"+ --allow-runtime-events --require-initrd >"$W/node-b-wrong.out" 2>&1 &&+ grep -qx ' FAIL attestation key: the pinned key' "$W/node-b-wrong.out" || {+ cat "$W/node-b-wrong.out" >&2+ die "the evidence of node B is not refused for node A's attestation key"+}[ "$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"@@ -356,28 +360,27 @@ 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")"-if [ -n "$NODE_EDGE_PID" ]; then- wait "$NODE_EDGE_PID" || :- NODE_EDGE_PID=- node_wait edge 0 || {- tail -n 40 "$W/node-edge.log" >&2- die "the fresh edge node did not boot; see $W/node-edge.log"- }- [ "$(node_sh edge cat /run/shirudo/config/etc/shirudo/node.labels)" = role=edge ] ||- die "the fresh edge node is not labelled role=edge"- image_identity edge "$(node_run_dir edge)/result/keepalive.json" \- "$(cat "$TEST_VM_HOST_BUNDLE/verity/config-edge.root")"- host_test t9109-pipeline- host_test t9110-keepalive-history- node_down edge ""- node_clean edge- node_down b ""- node_clean b- second_pair- host_test t9111-pipeline-segments- node_down edge ""- node_clean edge-fi+wait "$NODE_EDGE_PID" || :+NODE_EDGE_PID=+node_wait edge 0 || {+ tail -n 40 "$W/node-edge.log" >&2+ die "the fresh edge node did not boot; see $W/node-edge.log"+}+[ "$(node_sh edge cat /run/shirudo/config/etc/shirudo/node.labels)" = role=edge ] ||+ die "the fresh edge node is not labelled role=edge"+image_identity edge "$(node_run_dir edge)/result/keepalive.json" \+ "$(cat "$TEST_VM_HOST_BUNDLE/verity/config-edge.root")"+host_test t9109-pipeline+host_test t9110-keepalive-history+host_test t9112-activation+node_down edge ""+node_clean edge+node_down b ""+node_clean b+second_pair+host_test t9111-pipeline-segments+node_down edge ""+node_clean edgenode_down b ""node_clean bdiff --git a/testing/end2end/node-lib.sh b/testing/end2end/node-lib.shindex bb576487..88ea9bf4 100644--- a/testing/end2end/node-lib.sh+++ b/testing/end2end/node-lib.sh@@ -9,8 +9,9 @@# set first.# Where host.sh records each node, in node-<name>/: port, the host port of-# its SSH server, key, the key of its root, and ready once it is-# prepared, else failed.+# its SSH server, key, the key of its root, tpm-names, the names of its+# keys its builder recorded, ek-ca.pem, the CA of its endorsement+# certificate, and ready once it is prepared, else failed.: "${NODES_DIR:=/mnt/shirudo-src/build/test-vm/end2end}"# Where the nodes' SSH ports are forwarded: QEMU's address for the host,# as node A sees it.@@ -38,3 +39,9 @@ node_sh() {-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \-p "$(cat "$node_dir/port")" "root@$NODES_HOST" "$@"}++# The name of the key $2, ak or ek, that node $1's builder recorded before+# the node booted.+node_builder_name() {+ sed -n "s/^$2-name //p" "$NODES_DIR/node-$1/tpm-names"+}diff --git a/testing/end2end/pipeline-lib.sh b/testing/end2end/pipeline-lib.shindex 2e85c538..73c6458c 100644--- a/testing/end2end/pipeline-lib.sh+++ b/testing/end2end/pipeline-lib.sh@@ -3,7 +3,7 @@# Copyright (c) 2026 Authors of shirudo## testing/end2end/pipeline-lib.sh -- what the host tests of the keepalive-# pipeline, t9109 to t9111, do to the nodes, the registry and the+# pipeline, t9109 to t9112, do to the nodes, the registry and the# backend's ClickHouse. A test sets W, CHECKS, STATE, RUNTIME, E2E and# STACK_NAME, and TREE_ID and WINDOW where it uses them, and sources# node-lib.sh and stack-lib.sh first.diff --git a/testing/end2end/t9109-pipeline.sh b/testing/end2end/t9109-pipeline.shindex 2695059e..6cda775a 100755--- a/testing/end2end/t9109-pipeline.sh+++ b/testing/end2end/t9109-pipeline.sh@@ -58,11 +58,6 @@ payload() {python3 -c 'import json, sys; print(json.load(sys.stdin)["payload_sha256"])'}-# The attestation key name node B's builder recorded before it booted.-builder_ak() {- sed -n "s/^ak-name //p" "$NODES_DIR/node-b/tpm-names"-}-# Print the rows of node_status, the age of the record aside.status_rows() {ch "SELECT ak_name, status, trust, failed_check,@@ -166,13 +161,13 @@ test_expect_success 'each node sends two quoted keepalives, a few seconds apart''test_expect_success 'node B keeps the attestation key its builder recorded' '- test -n "$(builder_ak)" &&- test "$(ak b)" = "$(builder_ak)"+ test -n "$(node_builder_name b ak)" &&+ test "$(ak b)" = "$(node_builder_name b ak)"'test_expect_success 'the operator enrolls node B from its builder'\''s records' 'ch "INSERT INTO shirudo.nodes (ak_name, trust)- VALUES ('\''$(builder_ak)'\'', '\''enrolled'\'')"+ VALUES ('\''$(node_builder_name b ak)'\'', '\''enrolled'\'')"'test_expect_success 'the backend keeps node B enrolled, the edge node untrusted, and every record' 'diff --git a/testing/end2end/t9112-activation.sh b/testing/end2end/t9112-activation.shnew file mode 100755index 00000000..6716982e--- /dev/null+++ b/testing/end2end/t9112-activation.sh@@ -0,0 +1,137 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# t9112 -- enroll the fresh edge node through credential activation, as+# "Enroll from a target activation" of the attest page does it. Its vTPM+# carries an endorsement certificate from its maker's CA, ek-ca.pem beside+# its records; the operator checks the certificate against that CA, makes a+# challenge, the edge node answers it with a second nonce, and the operator+# verifies the credential and marks the key enrolled in the backend. Node+# B's CA does not vouch for the edge node, and node B refuses the edge+# node's challenge.+#+# end2end/host.sh runs it on the host after t9110, which leaves both+# nodes untrusted and their keepalives in the backend.++cd "$(dirname "$0")/.."+. ./test-lib.sh++REPO=$(cd .. && pwd)+E2E=${E2E:-$REPO/build/test-vm/end2end}+S=$REPO/shirudo+STACK_NAME=${STACK_NAME:-shirudo-end2end}+RUNTIME=/usr/local/bin/shirudo-runtime+CLICKHOUSE_CLIENT="docker exec -i $STACK_NAME-backend-clickhouse clickhouse-client"+export CLICKHOUSE_CLIENT++[ -n "${END2END_BACKEND-}" ] ||+ test_skip_all "end2end/host.sh runs it after t9110, with a keepalive backend"+command -v docker >/dev/null 2>&1 || test_skip_all "no docker"+command -v jq >/dev/null 2>&1 || test_skip_all "no jq"+. ./vm/stack-lib.sh+. ./end2end/node-lib.sh+. ./end2end/pipeline-lib.sh+node_wait edge 0 && node_wait b 0 ||+ test_skip_all "the fresh edge node and node B are not up"+EDGE_CA=$NODES_DIR/node-edge/ek-ca.pem+B_CA=$NODES_DIR/node-b/ek-ca.pem+[ -s "$EDGE_CA" ] && [ -s "$B_CA" ] ||+ test_skip_all "the nodes' vTPMs carry no endorsement certificate"+W=$(mktemp -d)+trap 'rm -rf "$W"' EXIT++# The steps run the commands of "Enroll from a target activation" as the+# attest page gives them, the target's in node $1 over SSH.++# Copy the challenge $2 to node $1 and answer it there with the nonce $3,+# into $4.+answer() {+ node_sh "$1" "umask 077 && cat >/root/challenge.json" <"$2" &&+ on "$1" "$RUNTIME attest --nonce=$3 --challenge=/root/challenge.json \+ --output=/root/answer.json && cat /root/answer.json" >"$4"+}++test_expect_success 'the edge node is untrusted before it is enrolled' '+ ak_record edge &&+ test "$(ch "SELECT max(trust) FROM shirudo.nodes+ WHERE ak_name = '\''$(ak edge)'\''")" = untrusted+'++test_expect_success 'the edge node presents its attestation key and endorsement certificate' '+ openssl rand -hex 32 >"$W/nonce" &&+ on edge "$RUNTIME attest --nonce=$(cat "$W/nonce") --output=/root/enroll.json &&+ stat -c %a /root/enroll.json" >"$W/enroll.mode" &&+ test "$(cat "$W/enroll.mode")" = 600 &&+ on edge cat /root/enroll.json >"$W/enroll.json" &&+ jq -r .ak.name "$W/enroll.json" >"$W/ak" &&+ jq -r .ek.name "$W/enroll.json" >"$W/ek" &&+ test "$(cat "$W/ak")" = "$(ak edge)" &&+ test "$(jq -r .ek.type "$W/enroll.json")" = ecc &&+ test "$(jq -r ".ek_certificate | type" "$W/enroll.json")" = string+'++test_expect_success 'a challenge against node B'\''s CA is refused' '+ ! "$S" attest challenge --evidence="$W/enroll.json" \+ --ak-name="$(cat "$W/ak")" --ek-ca="$B_CA" \+ --output="$W/challenge-b.json" >"$W/challenge-b.out" &&+ grep -qF " FAIL endorsement certificate: chains to $B_CA: " \+ "$W/challenge-b.out" &&+ test ! -e "$W/challenge-b.json"+'++test_expect_success 'the operator makes a challenge the edge node'\''s CA vouches for' '+ "$S" attest challenge --evidence="$W/enroll.json" \+ --ak-name="$(cat "$W/ak")" --ek-ca="$EDGE_CA" \+ --output="$W/challenge.json" >"$W/challenge.out" &&+ grep -qx " OK endorsement certificate: describes the endorsement key" \+ "$W/challenge.out" &&+ grep -qx " OK endorsement certificate: chains to $EDGE_CA" \+ "$W/challenge.out" &&+ grep -qx "challenge: $W/challenge.json" "$W/challenge.out" &&+ sed -n "s/^credential: //p" "$W/challenge.out" >"$W/credential" &&+ test "$(wc -c <"$W/credential")" = 65+'++test_expect_success 'node B refuses the edge node'\''s challenge, made for another key' '+ openssl rand -hex 32 >"$W/nonce-b" &&+ ! answer b "$W/challenge.json" "$(cat "$W/nonce-b")" "$W/answer-b.json" \+ 2>"$W/answer-b.err" &&+ grep -q "the challenge was made for another attestation key" "$W/answer-b.err"+'++test_expect_success 'the edge node answers the challenge with a second nonce' '+ openssl rand -hex 32 >"$W/nonce-2" &&+ answer edge "$W/challenge.json" "$(cat "$W/nonce-2")" "$W/answer.json"+'++test_expect_success 'the answer carries the credential made for the edge node'\''s keys' '+ "$S" attest verify --evidence="$W/answer.json" --nonce="$(cat "$W/nonce-2")" \+ --ak-name="$(cat "$W/ak")" --ek-name="$(cat "$W/ek")" \+ --expect-credential="$(cat "$W/credential")" >"$W/verify.out" &&+ grep -qx " OK attestation key: activated the credential made for it under the endorsement key" \+ "$W/verify.out" &&+ grep -qx "verdict: ok" "$W/verify.out" &&+ ! "$S" attest verify --evidence="$W/answer.json" --nonce="$(cat "$W/nonce-2")" \+ --ak-name="$(cat "$W/ak")" --ek-name="$(cat "$W/ek")" \+ --expect-credential="$(printf "%064d" 0)" >"$W/verify-wrong.out"+'++test_expect_success 'the operator enrolls the edge node, and the backend trusts its key alone' '+ ch "INSERT INTO shirudo.nodes (ak_name, trust)+ VALUES ('\''$(cat "$W/ak")'\'', '\''enrolled'\'')" &&+ refresh node_status_mv &&+ ch "SELECT ak_name, trust FROM shirudo.node_status+ WHERE trust = '\''enrolled'\''" >"$W/enrolled" &&+ printf "%s\tenrolled\n" "$(ak edge)" | diff -u - "$W/enrolled"+'++# t9110 loaded the schema again, which dropped node B's enrollment of+# t9109.+test_expect_success 'node B, whose enrollment went with the schema, stays untrusted' '+ ak_record b &&+ test "$(ch "SELECT trust FROM shirudo.node_status+ WHERE ak_name = '\''$(ak b)'\''")" = untrusted+'++test_donediff --git a/testing/functional/build/t1007-test-vm-cli.sh b/testing/functional/build/t1007-test-vm-cli.shindex 90522e01..c2c2972b 100755--- a/testing/functional/build/t1007-test-vm-cli.sh+++ b/testing/functional/build/t1007-test-vm-cli.sh@@ -53,6 +53,7 @@ test_expect_success 'node mode boots only a core or edge node of the end2end suigrep -Fq "export TEST_VM_NODE_ROLE=" vm/run.sh &&grep -Fq "\"\$REPO_ROOT/testing/vm/tpm-builder.sh\" \"\$RUN_DIR/tpm\" \"\$RUN_DIR/tpm-names\"" \vm/run.sh &&+ grep -Fq "\"\$RUN_DIR/ek-ca.pem\"" vm/run.sh &&grep -Fq "tpm2_createprimary:tpm2-tools:tpm2-tools" vm/run.sh &&grep -Fq "if [[ \"\$VM_MODE\" == node ]]" vm/guest.sh &&grep -Fq "image update \"/var/lib/shirudo/images/config-\${TEST_VM_NODE_ROLE}\"" \@@ -1077,13 +1078,15 @@ test_expect_success 'the runners split the tests by number' 'test -e end2end/t9109-pipeline.sh &&test -e end2end/t9110-keepalive-history.sh &&test -e end2end/t9111-pipeline-segments.sh &&+ test -e end2end/t9112-activation.sh &&grep -Fqx " end2end/t9109-pipeline.sh | end2end/t9110-keepalive-history.sh) continue ;;" \run-target-tests.sh &&- grep -Fqx " end2end/t9111-pipeline-segments.sh) continue ;;" \+ grep -Fqx " end2end/t9111-pipeline-segments.sh | end2end/t9112-activation.sh) continue ;;" \run-target-tests.sh &&- grep -Fqx " host_test t9109-pipeline" end2end/host.sh &&- grep -Fqx " host_test t9110-keepalive-history" end2end/host.sh &&- grep -Fqx " host_test t9111-pipeline-segments" end2end/host.sh+ grep -Fqx "host_test t9109-pipeline" end2end/host.sh &&+ grep -Fqx "host_test t9110-keepalive-history" end2end/host.sh &&+ grep -Fqx "host_test t9111-pipeline-segments" end2end/host.sh &&+ grep -Fqx "host_test t9112-activation" end2end/host.sh'test_expect_success 'test-vm rejects unknown policy modes before boot' 'diff --git a/testing/run-target-tests.sh b/testing/run-target-tests.shindex 60ad61ef..456291d1 100755--- a/testing/run-target-tests.sh+++ b/testing/run-target-tests.sh@@ -72,14 +72,15 @@ for t in "$dir"/t[0-9]1[0-9][0-9]-*.sh; do[ -e "$t" ] || continuefound=1test_matches "$t" || continue- # end2end/host.sh runs t9109 to t9111 itself, on the host after node+ # end2end/host.sh runs t9109 to t9112 itself, on the host after node# A's suite, against fresh edge nodes and nodes B.case "$t" inend2end/t9109-pipeline.sh | end2end/t9110-keepalive-history.sh) continue ;;- end2end/t9111-pipeline-segments.sh) continue ;;+ end2end/t9111-pipeline-segments.sh | end2end/t9112-activation.sh) continue ;;end2end/t9107-keepalive-backend.sh)- # host.sh records the example tree only when it started a- # backend; without one it leaves t9107 out, as t9109 to t9111.+ # host.sh records the example tree when it publishes it to+ # its backend and removes the record when it stops, so a run+ # of the family without host.sh finds none.if [ ! -s ../build/test-vm/end2end/backend-tree.digest ]; thenprintf 'not run without a keepalive backend: %s\n' "$t"continuediff --git a/testing/vm/run.sh b/testing/vm/run.shindex 1b4a758c..70f23b10 100755--- a/testing/vm/run.sh+++ b/testing/vm/run.sh@@ -519,9 +519,11 @@ start_swtpm()chmod 0700 "$RUN_DIR/tpm"# An end2end node's TPM comes from a builder the operator trusts, which- # records the names of its keys before the guest boots.+ # records the names of its keys before the guest boots, and carries an+ # endorsement certificate from its maker's CA.if [[ "$VM_MODE" == node ]]; then"$REPO_ROOT/testing/vm/tpm-builder.sh" "$RUN_DIR/tpm" "$RUN_DIR/tpm-names" \+ "$RUN_DIR/ek-ca.pem" \>>"$RUN_DIR/swtpm.log" 2>&1 ||die "could not create the keys of the vTPM; see $RUN_DIR/swtpm.log"fi@@ -1565,9 +1567,23 @@ if [[ "$VM_INITRD" == 1 ]]; thenfiif [[ "$VM_MODE" == node ]]; thenHOST_DEPENDENCIES+=("tpm2_createprimary:tpm2-tools:tpm2-tools"- "swtpm_ioctl:swtpm-tools:swtpm-tools")+ "swtpm_ioctl:swtpm-tools:swtpm-tools" "openssl:openssl:openssl")ficheck_host_dependencies+# tpm2-tools load tpm2-tss's swtpm TCTI only when tpm-builder.sh runs. grep+# reads all of ldconfig's output, which pipefail would otherwise fail on+# SIGPIPE.+if [[ "$VM_MODE" == node ]] &&+ ! PATH="$PATH:/sbin:/usr/sbin" ldconfig -p |+ grep 'libtss2-tcti-swtpm\.so' >/dev/null; then+ log "error: missing the swtpm TCTI of tpm2-tss, libtss2-tcti-swtpm.so"+ log "Install it with:"+ print_dependency_install_command \+ "$(test_vm_pkg libtss2-tcti-swtpm0t64 tpm2-tss)" >&2+ [[ "$TEST_VM_HOST_PKG" == dnf ]] ||+ log "Before Ubuntu 24.04 and Debian 13 the package is libtss2-tcti-swtpm0."+ exit 1+fivalidate_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"diff --git a/testing/vm/tpm-builder.sh b/testing/vm/tpm-builder.shindex 2064ce41..392a8a16 100755--- a/testing/vm/tpm-builder.sh+++ b/testing/vm/tpm-builder.sh@@ -1,22 +1,38 @@#!/usr/bin/env bash# SPDX-License-Identifier: BSD-2-Clause# Copyright (c) 2026 Authors of shirudo-# testing/vm/tpm-builder.sh <state-dir> <names> -- act as the builder of-# "Enroll from a builder's records": create the attestation key and the-# endorsement key in the vTPM state before the guest boots, with the-# commands that page gives, and write their names to <names>.+# testing/vm/tpm-builder.sh <state-dir> <names> <ek-ca> -- act as the builder+# of "Enroll from a builder's records": create the attestation key and the+# endorsement key in the vTPM state before the guest boots, with the commands+# that page gives, and write their names to <names>. As the vTPM's maker, it+# also stores an endorsement certificate from a CA of its own, in <ek-ca>.set -euo pipefailstate=$1names=$2+ek_ca=$3work=$(mktemp -d)+# swtpm drops the lock on the state directory only when it exits, and the+# guest's swtpm opens that directory next.stop() {+ local pid++ pid=$(cat "$work/tpm.pid" 2>/dev/null) || pid=swtpm_ioctl --unix "$work/tpm.ctrl" -s >/dev/null 2>&1 || :rm -rf -- "$work"+ [[ -n "$pid" ]] || return 0+ for _ in {1..100}; do+ kill -0 "$pid" 2>/dev/null || return 0+ sleep 0.1+ done+ kill -KILL "$pid" 2>/dev/null || :+ echo "tpm-builder: swtpm $pid did not exit" >&2+ exit 1}trap stop EXIT+trap 'exit 1' INT TERM HUPname() {printf '000b%s\n' "$(tail -c +3 "$1" | sha256sum | cut -c1-64)"@@ -25,11 +41,16 @@ name() {swtpm socket --tpm2 --tpmstate "dir=$state,mode=0700" \--server "type=unixio,path=$work/tpm" \--ctrl "type=unixio,path=$work/tpm.ctrl" \+ --pid "file=$work/tpm.pid" \--flags not-need-init,startup-clear --daemonfor _ in {1..50}; do- [[ -S "$work/tpm" ]] && break+ [[ -S "$work/tpm" && -s "$work/tpm.pid" ]] && breaksleep 0.1done+[[ -S "$work/tpm" && -s "$work/tpm.pid" ]] || {+ echo "tpm-builder: swtpm did not open $work/tpm" >&2+ exit 1+}export TPM2TOOLS_TCTI="swtpm:path=$work/tpm"cd "$work"tpm2_createprimary -C e -g sha256 -G ecc256:ecdsa-sha256:null \@@ -39,4 +60,21 @@ tpm2_readpublic -c ak.ctx -o ak.pub >/dev/nulltpm2_flushcontext -ttpm2_createek -c - -G ecc -u ek.pub >/dev/nullprintf 'ak-name %s\nek-name %s\n' "$(name ak.pub)" "$(name ek.pub)" >"$names"-swtpm_ioctl --unix "$work/tpm.ctrl" -s++# The certificate goes where a TPM's maker puts it, the ECC index of the TCG+# EK credential profile, written under the platform hierarchy the firmware+# has not yet locked; the CA's key is thrown away with $work.+tpm2_print -t TPM2B_PUBLIC -f pem ek.pub >ek.pem+openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \+ -keyout ca.key -out ca.pem -days 3650 \+ -subj "/CN=shirudo test endorsement CA $(od -An -N8 -tx1 /dev/urandom | tr -d ' ')" \+ 2>/dev/null+openssl x509 -new -subj "/CN=shirudo test endorsement key" \+ -force_pubkey ek.pem -CA ca.pem -CAkey ca.key -days 3650 \+ -outform DER -out ek.der+tpm2_nvdefine -C p -s "$(stat -c %s ek.der)" \+ -a 'ppwrite|ppread|ownerread|authread|no_da|platformcreate' 0x01c0000a \+ >/dev/null+tpm2_nvwrite -C p -i ek.der 0x01c0000a+cp ca.pem "$ek_ca"+tpm2_shutdown