Skip to content

eBPF-based security platform

testing: show a backward walk over sealed tree segments end to end

John Fastabend3966cef52f51
diff --git a/.agents/skills/testing/SKILL.md b/.agents/skills/testing/SKILL.md
index 2b357373..be4c2f5e 100644
--- a/.agents/skills/testing/SKILL.md
+++ b/.agents/skills/testing/SKILL.md
@@ -26,18 +26,23 @@ make -C testing help
The end2end tier runs t9107 against the keepalive backend that
`BACKEND_DIR` names, a checkout or a git URL, `../backend` by default;
-without one t9107 skips and t9109 and t9110 do not run, so say so when
+without one t9107 skips and t9109 to t9111 do not run, so say so when
reporting the tier. The tier boots two VMs at once, each with its own
swtpm: 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.
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; their output is `build/test-vm/end2end/t9109.log` and
-`t9110.log`. A test reaches the nodes with
-`node_sh b` or `node_sh edge` of `testing/end2end/node-lib.sh`. Their boot
-logs are `build/test-vm/end2end/node-b.log` and `node-edge.log`, their
-state `build/test-vm/vms/<name>-end2end-b/` and `-edge/`. Every node
+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`.
+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 the
+backend what `testing/end2end/pipeline-lib.sh` offers. Their boot logs
+are `build/test-vm/end2end/node-b.log` and `node-edge.log`, with `-2`
+for the second pair, their state `build/test-vm/vms/<name>-end2end-b/`
+and `-edge/`. Every node
declares the image of `testing/vm/files/end2end.os-release` without a
root hash, so the backend binds them `declared`.
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index e5ec7664..329e1595 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -687,6 +687,15 @@ signed config image.
running node's walk back, ``base_root`` verified against
``node_ops``, a node first seen past seq 0 reading ``gap`` and
``healthy``, and a shield below the window still ``shielded``
+ * - ``t9111-pipeline-segments``
+ - A backward walk on real data, run by ``host.sh`` after ``t9110`` on
+ a second fresh edge node and node B: ``bpm tree append
+ --segment-ops 2`` sealing three segments, a node without tree state
+ and a node behind inside a sealed segment both fetching it by its
+ digest, as the registry's access log shows, then applying forwards
+ with the masks ``VQ==`` and ``mg==``, no walk once both are at the
+ new segment's base, keepalives over all three segments and both
+ nodes ``healthy``
Unit suites and fuzz targets
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -848,7 +857,7 @@ Coverage by area
- ``t3011``, ``t5004``, ``t7005``, ``t7007``, ``t7008``, ``t7009``,
``t7101``, ``t7102``, ``t7103``, ``t7104``, ``t7105``, ``t7106``,
``t7107``, ``t7108``, ``t7109``, ``t7110``, ``t9105``, ``t9109``,
- ``t9110``.
+ ``t9110``, ``t9111``.
Fuzz: ``tree``,
``tree-state``, ``kconfig``. Unit: ``bpm_tree``,
``bpm_tree_overlap``, ``bpm_tree_state``, ``chain_history``,
@@ -860,7 +869,8 @@ Coverage by area
* - Telemetry
- ``t4006``, ``t4104``, ``t6139``, ``t7109``, ``t7110``, ``t8001`` to
``t8007``, ``t8101`` to ``t8106``, ``t9101`` to ``t9105``,
- ``t9107``, ``t9109``, ``t9110``. Fuzz: ``otel``, ``quote-check``,
+ ``t9107``, ``t9109``, ``t9110``, ``t9111``. Fuzz: ``otel``,
+ ``quote-check``,
``serializer``.
Unit: ``keepalive``, ``keepalive_quote``, ``sysinfo``
* - Decoders
diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rst
index 19526738..f0162aed 100644
--- a/Documentation/contribute/testing/testing.rst
+++ b/Documentation/contribute/testing/testing.rst
@@ -172,9 +172,9 @@ a Python companion with the same stem, such as
before ``init``. They skip on the build host and run in a separate VM
that the ``tpm`` family boots without the production initrd.
-``t9109`` and ``t9110`` carry target numbers but run on the host:
-:src:`testing/end2end/host.sh` runs them after node A's suite, in that
-order, against two other nodes (see :ref:`testing-two-nodes`), and node
+``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.
Run the tests
@@ -659,10 +659,10 @@ operator key and loads it with the backend's tree ingest job, which runs
``bpm tree show``. In the guest, ``t9107`` sends the example keepalives
with their recorded quotes through that collector and queries
ClickHouse, both through QEMU's address for the host. After node A,
-``host.sh`` runs ``t9109`` and ``t9110`` against the same backend, see
-:ref:`testing-pipeline` and :ref:`testing-history`. Without
-``BACKEND_DIR`` and without ``../backend``, ``t9107`` skips and
-``t9109`` and ``t9110`` do not run:
+``host.sh`` runs ``t9109``, ``t9110`` and ``t9111`` against the same
+backend, see :ref:`testing-pipeline`, :ref:`testing-history` and
+:ref:`testing-walk`. Without ``BACKEND_DIR`` and without ``../backend``,
+``t9107`` skips and ``t9109`` to ``t9111`` do not run:
.. code-block:: console
@@ -673,13 +673,15 @@ ClickHouse, both through QEMU's address for the host. After node A,
The nodes
~~~~~~~~~
-The tier boots up to three targets, at most two at once, each with its
+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
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
stopped, and ``t9109`` and then ``t9110`` run against it and node B.
-Both boot with ``make -C testing vm-node-end2end``, ``END2END_NODE=b`` or
+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
``edge``: the runner's
node mode prepares a node as it prepares node A, activates the config
image of its role, runs no tests, starts no timers and leaves it running
@@ -715,6 +717,16 @@ node has, and its register and eventlog keep all of it. So the fresh edge
node takes node A's place rather than node A moving to the pipeline
tree. Booting it after node A keeps two guests at most.
+``t9111`` needs nodes that have followed no tree, and both nodes of
+``t9109`` and ``t9110`` hold the eleven operations of
+``shirudo/pipeline-tree`` and their upatches by then. So ``host.sh``
+stops them and boots a second pair with the same config images, and it
+starts the registry again without a volume, so that it holds no tree
+and ``shirudo/pipeline-tree`` begins anew. The registry keeps nothing
+else that a later step needs, and the second pair needs no config image
+of its own. The pair boots once the first has stopped, so two guests
+still run at most; their boot costs the tier two more boots.
+
All nodes declare an image: :src:`testing/vm/files/end2end.os-release`,
``IMAGE_ID=fleet-os`` and ``IMAGE_VERSION=end2end-1``, is added to their
``/etc/os-release``. None binds the image as ``verified``. Their root is
@@ -730,10 +742,11 @@ attestation key differs from node A's and its labels are ``role=core``.
It checks that the fresh edge node is labelled ``role=edge``, and that
the keepalive body each node printed while it was prepared, in
``result/keepalive.json`` of its state directory, names the image above
-and no root.
+and no root. It checks the labels of the second pair the same way.
A test reaches node B and the fresh edge node as root over SSH through
-:src:`testing/end2end/node-lib.sh`, by the names ``b`` and ``edge``.
+:src:`testing/end2end/node-lib.sh`, by the names ``b`` and ``edge``,
+which name the second pair once it has booted.
``node_wait`` waits for a node to be prepared and fails when it did not
boot; ``node_sh`` runs a command line in its shell, with the test's
standard input and output:
@@ -768,7 +781,8 @@ 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
boot logs are ``build/test-vm/end2end/node-b.log`` and
-``node-edge.log``.
+``node-edge.log``, and ``node-b-2.log`` and ``node-edge-2.log`` for the
+second pair.
.. _testing-pipeline:
@@ -853,6 +867,62 @@ the kernel advisory ``shielded`` by ``xfs-fix`` at seq 3, below the
window, on the edge node and ``unknown`` on node B, as threat U20 of
:doc:`/security/threat-model` says.
+.. _testing-walk:
+
+The backward walk
+~~~~~~~~~~~~~~~~~
+
+``t9111`` shows a node's walk back over a sealed segment on real data:
+the publisher seals it, a node behind it follows its signed digest back
+and applies forwards, and the backend sees one tree. ``host.sh`` runs it
+after ``t9110``, against the second fresh edge node and node B and the
+same backend, and its output is ``build/test-vm/end2end/t9111.log``. The
+tree's five operations fit in the walk, join and keepalive window of the
+bundle's targets. It:
+
+#. checks that neither node has tree state and that the registry holds
+ no tree, empties the keepalive backend, loads its schema again and
+ sets ``window`` to 7;
+#. builds ``xfs-fix`` 1.0.0 and 1.1.0 and ``net-guard`` from
+ :src:`testing/fixtures/pipeline/net-guard/`, which selects no label,
+ so that node B applies something;
+#. appends, with ``--segment-ops 2`` and the tree id ``segments``, add
+ ``xfs-fix`` 1.0.0 for ``role=edge``, which node B alone syncs, then add
+ ``net-guard``, delete ``xfs-fix`` 1.0.0 and add ``xfs-fix`` 1.1.0,
+ which seal segment 1 at generation 2 as ``segment-1``;
+#. syncs the edge node, which has ``last_seq`` 0, and node B, at seq 1,
+ one after the other. Each fetches ``stable``, segment 2, then segment
+ 1 by its digest, and applies forwards to seq 4;
+#. loads the tree with the ingest job and sends a keepalive from each
+ node;
+#. appends delete ``net-guard``, which seals segment 2 as ``segment-2``,
+ syncs both nodes, which fetch ``stable`` and the manifest of the
+ ``net-guard`` package the delete names, which ``bpm tree append``
+ keeps in the tree's repository, but no sealed segment, and sends
+ keepalives again.
+
+The registry's access log (``stack_oci_log`` of
+:src:`testing/vm/stack-lib.sh`) is how it sees each fetch: the test
+writes a mark there before and after each sync, a request for a manifest
+that does not exist, and reads the requests for the tree's repository
+between them. It checks that each walk fetches segment 1 by its digest
+after ``stable`` and never by its ``segment-1`` tag, and that no sync
+after seq 5 fetches a sealed segment. It checks that each segment's
+``base`` names the manifest its tag names and the ``history_root`` the
+test folds from the published digests; that each node's ``outcomes``,
+``tree-eventlog`` and ``projection_root`` follow from the published
+operations and its role, with the masks ``VQ==`` and ``mg==`` at seq 4
+and ``VUA=`` and ``mkA=`` at seq 5, the same ``history_root`` on every
+line of both, ``segment_base_seq`` 2 and then 4, the ``tree_op`` events
+of its attested eventlog and its loaded upatches; that each keepalive
+covers all five operations from ``base_seq`` 0; and that ``tree_pubs``
+holds the three segments, ``tree_ops`` the five operations and
+``node_ops`` each node from seq 1, with no contradiction marked, and
+both nodes are ``healthy`` with ``4 chain: pass``, ``5 head: pass, seq 5
+of 5`` and ``6 set: pass``. :src:`testing/end2end/pipeline-lib.sh` holds
+what ``t9109`` to ``t9111`` do to the nodes, the registry and
+ClickHouse.
+
Select test scripts
~~~~~~~~~~~~~~~~~~~
diff --git a/testing/end2end/host.sh b/testing/end2end/host.sh
index e8d68d0b..5bc7d88b 100755
--- a/testing/end2end/host.sh
+++ b/testing/end2end/host.sh
@@ -5,7 +5,8 @@
# 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.
+# 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
@@ -37,6 +38,9 @@ NODES_DIR=$W
NODES_HOST=127.0.0.1
NODE_B_PID=
NODE_EDGE_PID=
+# The second pair of nodes adds NODE_ROUND to the VM name of the nodes
+# beside node A and to their boot logs.
+NODE_ROUND=
. "$REPO/testing/end2end/node-lib.sh"
say() { printf 'end2end: %s\n' "$*"; }
@@ -53,7 +57,8 @@ down() {
# The state directory of node $1's VM.
node_run_dir() {
- printf '%s/build/test-vm/vms/%s-end2end-%s\n' "$REPO" "$VM_NAME" "$1"
+ printf '%s/build/test-vm/vms/%s%s-end2end-%s\n' "$REPO" "$VM_NAME" \
+ "$NODE_ROUND" "$1"
}
# Boot node $1, b with the core role or edge with the edge role, prepared
@@ -63,8 +68,9 @@ 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" \
TEST_VM_CPUS=2 TEST_VM_MEMORY="${TEST_VM_NODE_MEMORY:-2G}" \
- >"$W/node-$1.log" 2>&1 &&
+ >"$W/node-$1$NODE_ROUND.log" 2>&1 &&
cp "$run/ssh.port" "$NODES_DIR/node-$1/port" &&
install -m 0600 "$run/ssh/id_ed25519" "$NODES_DIR/node-$1/key"; then
: >"$NODES_DIR/node-$1/ready"
@@ -84,7 +90,7 @@ node_down() {
node_stop() {
[ ! -d "$(node_run_dir "$1")" ] ||
- VM_NAME=$VM_NAME-end2end-$1 "$REPO/testing/vm/run.sh" --stop \
+ VM_NAME=$VM_NAME$NODE_ROUND-end2end-$1 "$REPO/testing/vm/run.sh" --stop \
>/dev/null 2>&1 || :
}
@@ -133,6 +139,35 @@ host_test() {
! grep -q '^1\.\.0 # SKIP' "$log" || die "${1%%-*} was skipped"
}
+# Boot the second pair of nodes for t9111, a fresh edge node and a fresh
+# node B with TPMs of their own, once the first pair has stopped, so that
+# two guests run at most. Their config images name the tree t9109 and
+# t9110 grew, so the registry starts again without it, and holds no tree.
+second_pair() {
+ NODE_ROUND=-2
+ 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"
+ node_boot edge &
+ NODE_EDGE_PID=$!
+ node_boot b &
+ NODE_B_PID=$!
+ wait "$NODE_EDGE_PID" || :
+ wait "$NODE_B_PID" || :
+ NODE_EDGE_PID=
+ NODE_B_PID=
+ for n in edge b; do
+ node_wait "$n" 0 || {
+ tail -n 40 "$W/node-$n$NODE_ROUND.log" >&2
+ die "node $n of the second pair did not boot; see $W/node-$n$NODE_ROUND.log"
+ }
+ done
+ [ "$(node_sh edge cat /run/shirudo/config/etc/shirudo/node.labels)" = role=edge ] &&
+ [ "$(node_sh b cat /run/shirudo/config/etc/shirudo/node.labels)" = role=core ] ||
+ die "the second pair is not labelled role=edge and role=core"
+}
+
# The keepalive backend t9107 runs against, in $BACKEND: BACKEND_DIR, a
# directory relative to the checkout or a git URL cloned into $W, by
# default ../backend. Without the variable and without that directory
@@ -387,6 +422,12 @@ if [ -n "$NODE_EDGE_PID" ]; then
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
node_down b ""
node_clean b
diff --git a/testing/end2end/pipeline-lib.sh b/testing/end2end/pipeline-lib.sh
new file mode 100644
index 00000000..2e85c538
--- /dev/null
+++ b/testing/end2end/pipeline-lib.sh
@@ -0,0 +1,162 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# 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
+# 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.
+
+# Run the query $1 on the backend's ClickHouse and print its result.
+ch() {
+ stack_backend_client --query "$1" </dev/null
+}
+
+# Wait up to 60 seconds for the query $1 to print $2.
+ch_wait() {
+ i=0
+ until [ "$(ch "$1")" = "$2" ]; do
+ i=$((i + 1))
+ [ "$i" -lt 120 ] || return 1
+ sleep 0.5
+ done
+}
+
+# Compare the query $1's result with file $2.
+ch_cmp() {
+ ch "$1" >"$2.out" && diff -u "$2" "$2.out" >&2
+}
+
+# Refresh the views $@ of shirudo, one after the other.
+refresh() {
+ for view in "$@"; do
+ ch "SYSTEM REFRESH VIEW shirudo.$view" &&
+ ch "SYSTEM WAIT VIEW shirudo.$view" || return 1
+ done
+}
+
+# Run the command line ${2...} as root in node $1, edge or b, with no
+# standard input.
+on() {
+ node_sh "$@" </dev/null
+}
+
+# Start the unit $2 in node $1 and wait for it; its journal is what a
+# failure needs.
+unit_ok() {
+ on "$1" "systemctl start $2 ||
+ { journalctl -u $2 --no-pager | tail -n 30 >&2; exit 1; }"
+}
+
+# Make node $1 trust the registry's and collectors' CA and reach the
+# registry at 127.0.0.1:15443, where the tree names its packages.
+node_reach() {
+ node_sh "$1" "cat >/etc/shirudo/end2end-ca.pem" <"$E2E/ca.pem" &&
+ on "$1" "install -d /etc/shirudo/bpm &&
+ echo BPM_OCI_CA_FILE=/etc/shirudo/end2end-ca.pem \
+ >/etc/shirudo/bpm/environment &&
+ echo OTEL_EXPORTER_OTLP_CERTIFICATE=/etc/shirudo/end2end-ca.pem \
+ >/etc/shirudo/map-export.env &&
+ cd /workspace/shirudo/testing && rm -f /tmp/forward-ready &&
+ setsid -f python3 end2end/tcp_forward.py 127.0.0.1:15443 \
+ 10.0.2.2:15443 /tmp/forward-ready \
+ </dev/null >/dev/null 2>&1 &&
+ i=0 && until [ -e /tmp/forward-ready ]; do
+ i=\$((i + 1)); [ \$i -lt 50 ] || exit 1; sleep 0.1
+ done"
+}
+
+# Copy node $1's tree records to $W/<name>-$1 and write its view of them,
+# with the keepalive window WINDOW when it is set, to $W/view-$1. A node
+# that applied nothing has no tree-eventlog.
+node_view() {
+ on "$1" cat "$STATE/state.json" >"$W/state.json-$1" &&
+ on "$1" cat "$STATE/outcomes" >"$W/outcomes-$1" &&
+ on "$1" "[ ! -e $STATE/tree-eventlog ] || cat $STATE/tree-eventlog" \
+ >"$W/tree-eventlog-$1" &&
+ python3 "$CHECKS" node "$W/state.json-$1" "$W/outcomes-$1" \
+ "$W/tree-eventlog-$1" ${WINDOW:+"$WINDOW"} >"$W/view-$1"
+}
+
+# Print the key $2 of node $1's view.
+view() {
+ python3 -c 'import json, sys; print(json.load(open(sys.argv[1]))[sys.argv[2]])' \
+ "$W/view-$1" "$2"
+}
+
+# Record in $W/ak-$1 the attestation key that node $1's records name.
+ak_record() {
+ boot=$(on "$1" cat /proc/sys/kernel/random/boot_id) &&
+ ch "SELECT DISTINCT ak_name FROM shirudo.keepalive
+ WHERE boot_id = '$boot'" >"$W/ak-$1" &&
+ test "$(wc -l <"$W/ak-$1")" = 1
+}
+
+# The attestation key name of node $1.
+ak() {
+ cat "$W/ak-$1"
+}
+
+# The newest record of node $1: base_seq, base_root, mask and
+# projection_root, as its view gives them.
+latest_cmp() {
+ printf '%s\t%s\t%s\t%s\n' "$(view "$1" base_seq)" "$(view "$1" base_root)" \
+ "$(view "$1" mask)" "$(view "$1" projection_root)" >"$W/latest-$1" &&
+ ch_cmp "SELECT base_seq, base_root, mask, projection_root
+ FROM shirudo.keepalive_latest FINAL
+ WHERE ak_name = '$(ak "$1")'" "$W/latest-$1"
+}
+
+# node_ops of node $1 in tree TREE_ID against its outcomes, from seq 1 or
+# from a gap row at seq $2.
+history_cmp() {
+ python3 "$CHECKS" history "$W/outcomes-$1" "$2" >"$W/history-$1" &&
+ ch_cmp "SELECT seq, code, lower(hex(root)) FROM shirudo.node_ops FINAL
+ WHERE ak_name = '$(ak "$1")' AND tree_id = '$TREE_ID'
+ ORDER BY seq" "$W/history-$1"
+}
+
+# The lines of node $1's log in node_status.
+status_log() {
+ ch "SELECT line FROM shirudo.node_status ARRAY JOIN log AS line
+ WHERE ak_name = '$(ak "$1")'"
+}
+
+# Compare ak_name, status and failed_check of node_status with file $1.
+# On a difference, print what the backend is torn down with: each node's
+# log, the last_seq and tamper array of each of its records, and the
+# tamper counters each node reads now.
+status_cmp() {
+ ch_cmp "SELECT ak_name, status, failed_check
+ FROM shirudo.node_status ORDER BY ak_name" "$1" && return 0
+ for n in edge b; do
+ status_log "$n" | sed "s/^/$n: /" >&2
+ ch "SELECT last_seq, tamper FROM shirudo.keepalive FINAL
+ WHERE ak_name = '$(ak "$n")' ORDER BY clock" |
+ sed "s/^/$n records: /" >&2
+ on "$n" "$RUNTIME status" | sed -n "/Tamper attempts/,/^\$/p" |
+ sed "s/^/$n status: /" >&2
+ done
+ return 1
+}
+
+# Write the mark $1 to the registry's access log, a GET of a manifest that
+# does not exist, and wait up to 10 seconds for it to appear there.
+registry_mark() {
+ curl -s -o /dev/null --cacert "$E2E/ca.pem" \
+ "https://$REGISTRY/v2/end2end-mark/manifests/$1" &&
+ i=0 &&
+ until stack_oci_log | grep -Fq "/v2/end2end-mark/manifests/$1 "; do
+ i=$((i + 1))
+ [ "$i" -lt 100 ] || return 1
+ sleep 0.1
+ done
+}
+
+# Print the requests for repository $3 that the registry logged between
+# the marks $1 and $2, one "<method> <path>" per line, the path after the
+# repository's.
+requests() {
+ stack_oci_log | python3 "$CHECKS" requests "$1" "$2" "$3"
+}
diff --git a/testing/end2end/pipeline_checks.py b/testing/end2end/pipeline_checks.py
index 73b48eec..86a9b4da 100644
--- a/testing/end2end/pipeline_checks.py
+++ b/testing/end2end/pipeline_checks.py
@@ -1,13 +1,14 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2026 Authors of shirudo
-"""What t9109 and t9110 recompute from a node's records, the publications
+"""What t9109 to t9111 recompute from a node's records, the publications
and the backend's rows, each from the format's own definition, so that
neither side is taken on trust."""
import base64
import hashlib
import json
+import re
import ssl
import sys
import urllib.request
@@ -86,6 +87,7 @@ def node(state_path, outcomes_path, eventlog_path, window=None):
"projection_root": hexdigest(state["projection_root"]),
"outcomes": [line["outcome"] for line in outcomes],
"history_root": hexdigest(outcomes[-1]["history_root"]),
+ "history_roots": [hexdigest(line["history_root"]) for line in outcomes],
"outcome_root": hexdigest(outcomes[-1]["projection_root"]),
"base_seq": base,
"base_root": base_root,
@@ -159,6 +161,87 @@ def operations(path):
for op in segment["document"]["operations"]]
+def artifacts(path, *seqs):
+ """The artifact manifest digests of the operations seqs of a walk, as
+ a node fetches them to apply each."""
+ wanted = {int(seq) for seq in seqs}
+ return [hexdigest(op["artifact"]["manifest_digest"])
+ for segment in walk(path)
+ for op in segment["document"]["operations"]
+ if op["seq"] in wanted]
+
+
+def selected(selector, labels):
+ """Whether a node with the labels selects an operation: every label
+ the selector names has one of its values."""
+ return all(labels.get(key) in values
+ for key, values in selector.get("labels", {}).items())
+
+
+def expect(view_path, walk_path, *labels):
+ """Hold a node's view against the operations of a walk and the node's
+ labels, key=value each: a node whose upatches all load applies every
+ operation it selects (01) and passes over the others (10), chains the
+ digests it applies into its projection_root and every digest into
+ the history_root of each line of its outcomes. Prints its mask."""
+ with open(view_path, encoding="utf-8") as f:
+ view = json.load(f)
+ labels = dict(label.split("=", 1) for label in labels)
+ ops = [op for segment in walk(walk_path)
+ for op in segment["document"]["operations"]]
+ ops = ops[:view["last_seq"]]
+ codes = [1 if selected(op.get("selector", {}), labels) else 2 for op in ops]
+ assert view["outcomes"] == codes, (view["outcomes"], codes)
+ digests = [hexdigest(op["operation_digest"]) for op in ops]
+ applied = [d for d, code in zip(digests, codes) if code == 1]
+ assert view["chained"] == applied, (view["chained"], applied)
+ assert view["projection_root"] == roots(applied)[0], view
+ assert view["outcome_root"] == view["projection_root"], view
+ assert view["history_roots"] == [roots(digests[:seq])[1]
+ for seq in range(1, len(digests) + 1)], view
+ return mask([{"seq": seq, "outcome": code}
+ for seq, code in enumerate(codes, 1)],
+ view["head_seq"], view["base_seq"])
+
+
+def loaded(upatch_list):
+ """The loaded upatches of `upatch list --json`, one "<name> <payload>"
+ per line, by name."""
+ with open(upatch_list, encoding="utf-8") as f:
+ upatches = json.load(f)["upatches"]
+ return sorted(f"{u['name']} {u['payload_sha256']}" for u in upatches
+ if u["loaded"] and u.get("type") == "load")
+
+
+def tree_events(evidence_path):
+ """The seq of every tree_op record of the eventlog in evidence."""
+ with open(evidence_path, encoding="utf-8") as f:
+ records = json.load(f)["eventlog"]
+ return [r["tree"]["seq"] for r in records if r["type"] == "tree_op"]
+
+
+ACCESS = re.compile(r'"([A-Z]+) /v2/(\S+) HTTP/[0-9.]+" ')
+
+
+def requests(log, start, end, repository):
+ """The requests for repository in the registry access log between the
+ GETs of the marks start and end, as "<method> <path>"."""
+ marks = {f"end2end-mark/manifests/{name}": name for name in (start, end)}
+ seen = None
+ for line in log:
+ found = ACCESS.search(line)
+ if not found:
+ continue
+ method, path = found.groups()
+ if marks.get(path) == start and seen is None:
+ seen = []
+ elif marks.get(path) == end and seen is not None:
+ return seen
+ elif seen is not None and path.startswith(repository + "/"):
+ seen.append(f"{method} {path[len(repository) + 1:]}")
+ raise SystemExit(f"pipeline_checks.py: no marks {start} and {end} in order")
+
+
def tags(registry, ca, repository, count):
"""The manifest digests of the tags segment-1 to segment-<count>."""
ctx = ssl.create_default_context(cafile=ca)
@@ -184,8 +267,18 @@ def main():
print(*segments(args[0]), sep="\n")
elif command == "operations":
print(*operations(args[0]), sep="\n")
+ elif command == "artifacts":
+ print(*artifacts(args[0], *args[1:]), sep="\n")
elif command == "tags":
print(*tags(args[0], args[1], args[2], int(args[3])), sep="\n")
+ elif command == "expect":
+ print(expect(*args))
+ elif command == "loaded":
+ sys.stdout.writelines(f"{line}\n" for line in loaded(args[0]))
+ elif command == "tree-events":
+ print(*tree_events(args[0]))
+ elif command == "requests":
+ sys.stdout.writelines(f"{line}\n" for line in requests(sys.stdin, *args))
elif command == "set":
print(loaded_set(args[0]))
elif command == "quotes":
diff --git a/testing/end2end/t9109-pipeline.sh b/testing/end2end/t9109-pipeline.sh
index 10150d88..8993db00 100755
--- a/testing/end2end/t9109-pipeline.sh
+++ b/testing/end2end/t9109-pipeline.sh
@@ -42,67 +42,12 @@ command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"
[ -s "$E2E/ca.pem" ] || test_skip_all "no registry and collector CA in $E2E"
. ./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"
W=$(mktemp -d)
trap 'rm -rf "$W"' EXIT
-# Run the query $1 on the backend's ClickHouse and print its result.
-ch() {
- stack_backend_client --query "$1" </dev/null
-}
-
-# Wait up to 60 seconds for the query $1 to print $2.
-ch_wait() {
- i=0
- until [ "$(ch "$1")" = "$2" ]; do
- i=$((i + 1))
- [ "$i" -lt 120 ] || return 1
- sleep 0.5
- done
-}
-
-# Compare the query $1's result with file $2.
-ch_cmp() {
- ch "$1" >"$2.out" && diff -u "$2" "$2.out" >&2
-}
-
-refresh() {
- for view in node_status_mv node_vulns_mv; do
- ch "SYSTEM REFRESH VIEW shirudo.$view" &&
- ch "SYSTEM WAIT VIEW shirudo.$view" || return 1
- done
-}
-
-# Run the command line ${2...} as root in node $1, edge or b, with no
-# standard input.
-on() {
- node_sh "$@" </dev/null
-}
-
-# Start the unit $2 in node $1 and wait for it; its journal is what a
-# failure needs.
-unit_ok() {
- on "$1" "systemctl start $2 ||
- { journalctl -u $2 --no-pager | tail -n 30 >&2; exit 1; }"
-}
-
-# Copy node $1's tree records to $W/<name>-$1, and print its view of them.
-# A node that applied nothing has no tree-eventlog.
-node_view() {
- on "$1" cat "$STATE/state.json" >"$W/state.json-$1" &&
- on "$1" cat "$STATE/outcomes" >"$W/outcomes-$1" &&
- on "$1" "[ ! -e $STATE/tree-eventlog ] || cat $STATE/tree-eventlog" \
- >"$W/tree-eventlog-$1" || return 1
- python3 "$CHECKS" node "$W/state.json-$1" "$W/outcomes-$1" \
- "$W/tree-eventlog-$1"
-}
-
-# The attestation key name of node $1, found by its boot_id in the records.
-ak() {
- cat "$W/ak-$1"
-}
-
# The payload_sha256 of the upatch xfs-fix in the package of release $1.
payload() {
tar -xzf "$W/pkg/$1/xfs-fix-$1.bee" -C "$W/pkg/$1" &&
@@ -180,28 +125,15 @@ print(\"\\n\".join(op[\"operation_digest\"].removeprefix(\"sha256:\") for op in
'
test_expect_success 'both nodes trust the CA and reach the registry' '
- for n in edge b; do
- node_sh "$n" "cat >/etc/shirudo/end2end-ca.pem" <"$E2E/ca.pem" &&
- on "$n" "install -d /etc/shirudo/bpm &&
- echo BPM_OCI_CA_FILE=/etc/shirudo/end2end-ca.pem \
- >/etc/shirudo/bpm/environment &&
- echo OTEL_EXPORTER_OTLP_CERTIFICATE=/etc/shirudo/end2end-ca.pem \
- >/etc/shirudo/map-export.env &&
- cd /workspace/shirudo/testing && rm -f /tmp/forward-ready &&
- setsid -f python3 end2end/tcp_forward.py 127.0.0.1:15443 \
- 10.0.2.2:15443 /tmp/forward-ready \
- </dev/null >/dev/null 2>&1 &&
- i=0 && until [ -e /tmp/forward-ready ]; do
- i=\$((i + 1)); [ \$i -lt 50 ] || exit 1; sleep 0.1
- done" || exit 1
- done
+ node_reach edge &&
+ node_reach b
'
test_expect_success 'the sync applies 01 01 01 on the edge node and 10 10 10 on node B' '
unit_ok edge shirudo-bpm-tree-sync.service &&
unit_ok b shirudo-bpm-tree-sync.service &&
- node_view edge >"$W/view-edge" &&
- node_view b >"$W/view-b" &&
+ node_view edge &&
+ node_view b &&
python3 - "$W/view-edge" "$W/view-b" <<-\PY
import json, sys
edge, b = (json.load(open(path)) for path in sys.argv[1:3])
@@ -220,12 +152,8 @@ test_expect_success 'each node sends two quoted keepalives, a few seconds apart'
unit_ok edge shirudo-keepalive.service &&
unit_ok b shirudo-keepalive.service &&
ch_wait "SELECT count() FROM shirudo.keepalive FINAL" 4 &&
- for n in edge b; do
- boot=$(on "$n" cat /proc/sys/kernel/random/boot_id) &&
- ch "SELECT DISTINCT ak_name FROM shirudo.keepalive
- WHERE boot_id = '\''$boot'\''" >"$W/ak-$n" &&
- test "$(wc -l <"$W/ak-$n")" = 1 || exit 1
- done &&
+ ak_record edge &&
+ ak_record b &&
test "$(ak edge)" != "$(ak b)"
'
@@ -249,14 +177,12 @@ test_expect_success 'node_status shows both nodes healthy with the masks VA== an
test "$version" = "$(on b "$RUNTIME version --version-id")" &&
ch "INSERT INTO shirudo.expected_builds (version_id, note)
VALUES ('\''$version'\'', '\''t9109'\'')" &&
- refresh &&
+ refresh node_status_mv node_vulns_mv &&
printf "%s\thealthy\tuntrusted\t0\n" "$(ak b)" "$(ak edge)" | sort >"$W/status" &&
ch_cmp "SELECT ak_name, status, trust, failed_check FROM shirudo.node_status
ORDER BY ak_name" "$W/status" &&
- ch "SELECT line FROM shirudo.node_status ARRAY JOIN log AS line
- WHERE ak_name = '\''$(ak edge)'\''" >"$W/log-edge" &&
- ch "SELECT line FROM shirudo.node_status ARRAY JOIN log AS line
- WHERE ak_name = '\''$(ak b)'\''" >"$W/log-b" &&
+ status_log edge >"$W/log-edge" &&
+ status_log b >"$W/log-b" &&
root=$(python3 -c "import json, sys; print(json.load(open(sys.argv[1]))[\"projection_root\"][:8])" \
"$W/view-edge") &&
grep -qx "4 chain: pass, root $root" "$W/log-edge" &&
@@ -366,7 +292,7 @@ test_expect_success 'node_vulns shields the edge node and excludes node B' '
<"$FIX/kernel-vulns.json" &&
test "$(ch "SELECT countIf(kver(kernel_release) >= [7, 0])
FROM shirudo.keepalive_latest FINAL")" = 2 &&
- refresh &&
+ refresh node_status_mv node_vulns_mv &&
cat >"$W/vulns" <<-EOF &&
b declared kernel EXAMPLE-0101 linux shield_excludes_node xfs-fix 3 add fixes
b declared sbom EXAMPLE-0202 openssl exposed_no_shield 0 none
@@ -391,7 +317,7 @@ test_expect_success 'a record replayed with one body byte changed is body_mismat
test "$(ch "SELECT reason, lower(hex(SHA256(body))) FROM shirudo.rejected")" = \
"$(printf "body_mismatch\t%s" "$(sha256sum "$W/altered" | cut -d " " -f 1)")" &&
test "$(ch "SELECT count() FROM shirudo.keepalive FINAL")" = 4 &&
- refresh &&
+ refresh node_status_mv node_vulns_mv &&
status_rows >"$W/status-after" &&
diff -u "$W/status-before" "$W/status-after" >&2
'
diff --git a/testing/end2end/t9110-keepalive-history.sh b/testing/end2end/t9110-keepalive-history.sh
index 68d6586a..10dcabdd 100644
--- a/testing/end2end/t9110-keepalive-history.sh
+++ b/testing/end2end/t9110-keepalive-history.sh
@@ -25,6 +25,7 @@ CHECKS=$PWD/end2end/pipeline_checks.py
REGISTRY=${REGISTRY:-127.0.0.1:15443}
STACK_NAME=${STACK_NAME:-shirudo-end2end}
TREE=oci://$REGISTRY/shirudo/pipeline-tree
+TREE_ID=pipeline
RUNTIME=/usr/local/bin/shirudo-runtime
STATE=/var/lib/shirudo/bpm/upatch-tree
CLICKHOUSE_CLIENT="docker exec -i $STACK_NAME-backend-clickhouse clickhouse-client"
@@ -41,66 +42,12 @@ command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"
[ -s "$E2E/ca.pem" ] || test_skip_all "no registry and collector CA in $E2E"
. ./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"
W=$(mktemp -d)
trap 'rm -rf "$W"' EXIT
-ch() {
- stack_backend_client --query "$1" </dev/null
-}
-
-# Wait up to 60 seconds for the query $1 to print $2.
-ch_wait() {
- i=0
- until [ "$(ch "$1")" = "$2" ]; do
- i=$((i + 1))
- [ "$i" -lt 120 ] || return 1
- sleep 0.5
- done
-}
-
-# Compare the query $1's result with file $2.
-ch_cmp() {
- ch "$1" >"$2.out" && diff -u "$2" "$2.out" >&2
-}
-
-# Refresh the views $@ of shirudo, one after the other.
-refresh() {
- for view in "$@"; do
- ch "SYSTEM REFRESH VIEW shirudo.$view" &&
- ch "SYSTEM WAIT VIEW shirudo.$view" || return 1
- done
-}
-
-on() {
- node_sh "$@" </dev/null
-}
-
-# Start the unit $2 in node $1 and wait for it; its journal is what a
-# failure needs.
-unit_ok() {
- on "$1" "systemctl start $2 ||
- { journalctl -u $2 --no-pager | tail -n 30 >&2; exit 1; }"
-}
-
-# Copy node $1's tree records to $W/<name>-$1 and write its view of them,
-# with the keepalive window, to $W/view-$1.
-node_view() {
- on "$1" cat "$STATE/state.json" >"$W/state.json-$1" &&
- on "$1" cat "$STATE/outcomes" >"$W/outcomes-$1" &&
- on "$1" "[ ! -e $STATE/tree-eventlog ] || cat $STATE/tree-eventlog" \
- >"$W/tree-eventlog-$1" &&
- python3 "$CHECKS" node "$W/state.json-$1" "$W/outcomes-$1" \
- "$W/tree-eventlog-$1" "$WINDOW" >"$W/view-$1"
-}
-
-# Print the key $2 of node $1's view.
-view() {
- python3 -c 'import json, sys; print(json.load(open(sys.argv[1]))[sys.argv[2]])' \
- "$W/view-$1" "$2"
-}
-
# Append hist-pad to the tree, as an add or with $1 as --op, in segments
# of 2 operations.
append() {
@@ -114,43 +61,6 @@ ingest() {
"$TREE" >&2
}
-# Record in $W/ak-$1 the attestation key that node $1's records name.
-ak_record() {
- boot=$(on "$1" cat /proc/sys/kernel/random/boot_id) &&
- ch "SELECT DISTINCT ak_name FROM shirudo.keepalive
- WHERE boot_id = '$boot'" >"$W/ak-$1" &&
- test "$(wc -l <"$W/ak-$1")" = 1
-}
-
-ak() {
- cat "$W/ak-$1"
-}
-
-# The newest record of node $1: base_seq, base_root, mask and
-# projection_root, as its view gives them.
-latest_cmp() {
- printf '%s\t%s\t%s\t%s\n' "$(view "$1" base_seq)" "$(view "$1" base_root)" \
- "$(view "$1" mask)" "$(view "$1" projection_root)" >"$W/latest-$1" &&
- ch_cmp "SELECT base_seq, base_root, mask, projection_root
- FROM shirudo.keepalive_latest FINAL
- WHERE ak_name = '$(ak "$1")'" "$W/latest-$1"
-}
-
-# node_ops of node $1 against its outcomes, from seq 1 or from a gap row
-# at seq $2.
-history_cmp() {
- python3 "$CHECKS" history "$W/outcomes-$1" "$2" >"$W/history-$1" &&
- ch_cmp "SELECT seq, code, lower(hex(root)) FROM shirudo.node_ops FINAL
- WHERE ak_name = '$(ak "$1")' AND tree_id = 'pipeline'
- ORDER BY seq" "$W/history-$1"
-}
-
-# The lines of node $1's log in node_status.
-status_log() {
- ch "SELECT line FROM shirudo.node_status ARRAY JOIN log AS line
- WHERE ak_name = '$(ak "$1")'"
-}
-
test_expect_success 'both nodes are where t9109 left them, at seq 3 of 3' '
for n in edge b; do
node_view "$n" &&
@@ -303,23 +213,7 @@ test_expect_success 'base_root is verified on the edge node; node B shows a gap,
printf "%s\thealthy\t0\n" "$(ak b)" "$(ak edge)" | sort >"$W/status" &&
status_log edge >"$W/log-edge" &&
status_log b >"$W/log-b" &&
- {
- ch_cmp "SELECT ak_name, status, failed_check
- FROM shirudo.node_status ORDER BY ak_name" "$W/status" ||
- {
- sed "s/^/edge: /" "$W/log-edge" >&2
- sed "s/^/b: /" "$W/log-b" >&2
- ch "SELECT last_seq, tamper FROM shirudo.keepalive FINAL
- WHERE ak_name = '\''$(ak edge)'\''
- ORDER BY clock" | sed "s/^/edge records: /" >&2
- for n in edge b; do
- on "$n" "$RUNTIME status" |
- sed -n "/Tamper attempts/,/^\$/p" |
- sed "s/^/$n status: /" >&2
- done
- false
- }
- } &&
+ status_cmp "$W/status" &&
root_edge=$(view edge projection_root | cut -c 1-8) &&
root_b=$(view b projection_root | cut -c 1-8) &&
grep -qx "4 chain: pass, root $root_edge" "$W/log-edge" &&
diff --git a/testing/end2end/t9111-pipeline-segments.sh b/testing/end2end/t9111-pipeline-segments.sh
new file mode 100755
index 00000000..acd9a984
--- /dev/null
+++ b/testing/end2end/t9111-pipeline-segments.sh
@@ -0,0 +1,327 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# t9111 -- a backward walk on real data. The operator appends five
+# operations to a new tree in segments of 2: xfs-fix 1.0.0 for role=edge,
+# net-guard for every node, the delete of xfs-fix 1.0.0, xfs-fix 1.1.0 and
+# the delete of net-guard. Node B (role=core) syncs once inside the first
+# segment. After seq 4 the edge node, which has followed no tree, and
+# node B both walk back to the sealed segment by its digest and apply
+# forwards; after seq 5 neither walks. The registry's access log shows
+# each fetch, and the backend sees one tree of three segments.
+#
+# end2end/host.sh runs it on the host after t9110, as root, against a
+# fresh edge node, a fresh node B and a registry that holds no tree.
+
+cd "$(dirname "$0")/.."
+. ./test-lib.sh
+
+REPO=$(cd .. && pwd)
+E2E=${E2E:-$REPO/build/test-vm/end2end}
+FIX=$PWD/fixtures/pipeline
+S=$REPO/shirudo
+CHECKS=$PWD/end2end/pipeline_checks.py
+REGISTRY=${REGISTRY:-127.0.0.1:15443}
+STACK_NAME=${STACK_NAME:-shirudo-end2end}
+REPOSITORY=shirudo/pipeline-tree
+TREE=oci://$REGISTRY/$REPOSITORY
+TREE_ID=segments
+RUNTIME=/usr/local/bin/shirudo-runtime
+STATE=/var/lib/shirudo/bpm/upatch-tree
+CLICKHOUSE_CLIENT="docker exec -i $STACK_NAME-backend-clickhouse clickhouse-client"
+export CLICKHOUSE_CLIENT
+# KEEPALIVE_WINDOW_OPS of the test VM bundle's target. The tree's five
+# operations fit in it, so every keepalive's window starts at seq 0.
+WINDOW=7
+
+[ -n "${END2END_BACKEND-}" ] && [ -n "${END2END_KEYS-}" ] ||
+ test_skip_all "end2end/host.sh runs it after t9110, with a keepalive backend"
+BACKEND=$END2END_BACKEND
+KEYS=$END2END_KEYS
+command -v docker >/dev/null 2>&1 || test_skip_all "no docker"
+command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"
+[ -s "$E2E/ca.pem" ] || test_skip_all "no registry and collector CA in $E2E"
+. ./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"
+W=$(mktemp -d)
+trap 'rm -rf "$W"' EXIT
+
+# Append the package $1, a path under $W/pkg without .bee, to the tree in
+# segments of 2 operations, as an add or with $2 as --op.
+append() {
+ "$S" bpm tree append "$W/pkg/$1.bee" "$TREE" --keys-dir "$KEYS" \
+ --tree-id "$TREE_ID" --segment-ops 2 ${2:+--op "$2"} >&2
+}
+
+# Write the walk of the tree back from its stable tag to $W/walk.
+walk() {
+ "$S" bpm tree show "$TREE" --cert "$KEYS/cert.der" --walk >"$W/walk"
+}
+
+ingest() {
+ "$BACKEND/jobs/tree-ingest" --shirudo "$S" --cert "$KEYS/cert.der" \
+ "$TREE" >&2
+}
+
+# The payload_sha256 of the upatch $2 in the package of release $1.
+payload() {
+ tar -xzf "$W/pkg/$1/$2-$1.bee" -C "$W/pkg/$1" &&
+ "$S" upatch info --json "$W/pkg/$1/$2-$1/upatches/$2.upatch" |
+ python3 -c 'import json, sys; print(json.load(sys.stdin)["payload_sha256"])'
+}
+
+# Sync node $1 in step $2 and print the manifests it fetched from the
+# tree's repository; $W/requests-$1 holds all it asked of that
+# repository. Marks in the registry's access log bound the sync.
+sync_node() {
+ registry_mark "$2-$1" &&
+ unit_ok "$1" shirudo-bpm-tree-sync.service &&
+ registry_mark "$2-$1-done" &&
+ requests "$2-$1" "$2-$1-done" "$REPOSITORY" >"$W/requests-$1" &&
+ sed -n "s|^GET manifests/||p" "$W/requests-$1"
+}
+
+# Check node $1 with labels $2 at seq $3 of the walk: its records against
+# the published operations, its mask $4, the seq of its tree_op events
+# $5 and its loaded upatches, file $6.
+node_check() {
+ node_view "$1" &&
+ test "$(view "$1" last_seq) $(view "$1" head_seq)" = "$3 $3" &&
+ on "$1" "[ ! -e $STATE/pending.json ]" &&
+ test "$(python3 "$CHECKS" expect "$W/view-$1" "$W/walk" "$2")" = "$4" &&
+ test "$(view "$1" mask)" = "$4" &&
+ on "$1" "$RUNTIME attest --nonce=$(openssl rand -hex 16)" \
+ >"$W/evidence-$1" &&
+ test "$(python3 "$CHECKS" tree-events "$W/evidence-$1")" = "$5" &&
+ on "$1" "$RUNTIME upatch list --json" >"$W/upatches-$1" &&
+ python3 "$CHECKS" loaded "$W/upatches-$1" >"$W/loaded-$1" &&
+ diff -u "$6" "$W/loaded-$1" >&2
+}
+
+# Send a keepalive from each node and wait for the backend to hold $1
+# records in all.
+report() {
+ unit_ok edge shirudo-keepalive.service &&
+ unit_ok b shirudo-keepalive.service &&
+ ch_wait "SELECT count() FROM shirudo.keepalive FINAL" "$1" &&
+ test "$(ch "SELECT count() FROM shirudo.rejected")" = 0
+}
+
+test_expect_success 'both nodes have followed no tree, and the registry holds none' '
+ for n in edge b; do
+ on "$n" "[ ! -e $STATE/state.json ] && [ ! -e $STATE/outcomes ]" &&
+ on "$n" "$RUNTIME upatch list --json" >"$W/upatches-$n" &&
+ test -z "$(python3 "$CHECKS" loaded "$W/upatches-$n")" || exit 1
+ done &&
+ test "$(curl -s -o /dev/null -w "%{http_code}" --cacert "$E2E/ca.pem" \
+ "https://$REGISTRY/v2/$REPOSITORY/manifests/stable")" = 404
+'
+
+test_expect_success 'the backend starts empty, with the window lowered to 7' '
+ ch "DROP DATABASE IF EXISTS shirudo SYNC" &&
+ ch "DROP DATABASE IF EXISTS otel SYNC" &&
+ stack_backend_schema "$BACKEND" &&
+ ch "INSERT INTO shirudo.settings (stale_seconds, stuck_seconds, window)
+ VALUES (600, 3600, $WINDOW)" &&
+ version=$(on edge "$RUNTIME version --version-id") &&
+ test "$version" = "$(on b "$RUNTIME version --version-id")" &&
+ ch "INSERT INTO shirudo.expected_builds (version_id, note)
+ VALUES ('\''$version'\'', '\''t9111'\'')" &&
+ test "$(ch "SELECT count() FROM shirudo.keepalive")" = 0
+'
+
+test_expect_success 'both nodes trust the CA and reach the registry' '
+ node_reach edge &&
+ node_reach b
+'
+
+# 1.1.0 differs from 1.0.0 in its program name, so that the two payloads
+# differ, as in t9109.
+test_expect_success 'the operator builds xfs-fix 1.0.0 and 1.1.0, and net-guard 1.0.0' '
+ for p in 1.0.0/xfs-fix 1.1.0/xfs-fix 1.0.0/net-guard; do
+ mkdir -p "$W/pkg/${p%/*}" &&
+ cp -R "$FIX/${p#*/}" "$W/pkg/$p" &&
+ ln -s "$REPO/vendor" "$W/pkg/$p/vendor" &&
+ ln -s "$REPO/bpf" "$W/pkg/$p/bpf" || exit 1
+ done &&
+ sed -i "s/BPF_PROG(xfs_fix)/BPF_PROG(xfs_fix_1_1)/" \
+ "$W/pkg/1.1.0/xfs-fix/xfs-fix.bpf.c" &&
+ for p in 1.0.0/xfs-fix 1.1.0/xfs-fix 1.0.0/net-guard; do
+ (cd "$W/pkg/${p%/*}" && "$S" bpm build "${p#*/}" \
+ --version "${p%/*}" --keys-dir "$KEYS") >&2 &&
+ payload "${p%/*}" "${p#*/}" >"$W/payload-${p#*/}-${p%/*}" || exit 1
+ done &&
+ ! cmp -s "$W/payload-xfs-fix-1.0.0" "$W/payload-xfs-fix-1.1.0"
+'
+
+test_expect_success 'append 1 starts segment 1; node B passes over seq 1' '
+ append 1.0.0/xfs-fix-1.0.0 &&
+ walk &&
+ python3 "$CHECKS" segments "$W/walk" | cut -f 1-3 >"$W/bounds" &&
+ test "$(cat "$W/bounds")" = "$(printf "0\t1\t1")" &&
+ sync_node b step-1 >"$W/fetched" &&
+ test "$(cat "$W/fetched")" = stable &&
+ : >"$W/loaded" &&
+ node_check b role=core 1 gA== "" "$W/loaded" &&
+ test "$(view b segment_base_seq)" = 0
+'
+
+test_expect_success 'appends 2 to 4 seal segment 1 at generation 2 as segment-1' '
+ append 1.0.0/net-guard-1.0.0 &&
+ append 1.0.0/xfs-fix-1.0.0 delete &&
+ append 1.1.0/xfs-fix-1.1.0 &&
+ walk &&
+ python3 "$CHECKS" segments "$W/walk" >"$W/segments-4" &&
+ printf "%s\t%s\t%s\n" 0 2 2 2 4 4 >"$W/bounds.expected" &&
+ cut -f 1-3 "$W/segments-4" | diff -u "$W/bounds.expected" - >&2 &&
+ sed -n 1p "$W/segments-4" | cut -f 4 >"$W/segment-1" &&
+ python3 "$CHECKS" tags "$REGISTRY" "$E2E/ca.pem" "$REPOSITORY" 1 |
+ diff -u "$W/segment-1" - >&2 &&
+ sed -n 2p "$W/segments-4" | cut -f 5 | diff -u "$W/segment-1" - >&2
+'
+
+# The edge node has last_seq 0: a walk of 2 operations back from segment
+# 2's base, within the 6 a joining node of the test VM walks.
+test_expect_success 'the edge node walks back to segment 1 by digest and applies 1 to 4' '
+ sync_node edge step-2 >"$W/fetched" &&
+ test "$(sed -n 1p "$W/fetched")" = stable &&
+ sed 1d "$W/fetched" | grep -qx "sha256:$(cat "$W/segment-1")" &&
+ ! grep -q "segment-" "$W/requests-edge" &&
+ printf "net-guard %s\nxfs-fix %s\n" "$(cat "$W/payload-net-guard-1.0.0")" \
+ "$(cat "$W/payload-xfs-fix-1.1.0")" >"$W/loaded" &&
+ node_check edge role=edge 4 VQ== "1 2 3 4" "$W/loaded" &&
+ test "$(view edge segment_base_seq)" = 2
+'
+
+# Node B is behind inside the sealed segment: a walk of 1 operation from
+# its last_seq 1, within the 4 a running node of the test VM walks.
+test_expect_success 'node B walks back into segment 1 from seq 1 and processes 2 to 4' '
+ sync_node b step-2 >"$W/fetched" &&
+ test "$(sed -n 1p "$W/fetched")" = stable &&
+ sed 1d "$W/fetched" | grep -qx "sha256:$(cat "$W/segment-1")" &&
+ ! grep -q "segment-" "$W/requests-b" &&
+ printf "net-guard %s\n" "$(cat "$W/payload-net-guard-1.0.0")" >"$W/loaded" &&
+ node_check b role=core 4 mg== 2 "$W/loaded" &&
+ test "$(view b segment_base_seq)" = 2 &&
+ test "$(view edge history_roots)" = "$(view b history_roots)"
+'
+
+test_expect_success 'both nodes report seq 4 of 4; the backend loads both segments' '
+ ingest &&
+ report 2 &&
+ ak_record edge &&
+ ak_record b &&
+ test "$(ak edge)" != "$(ak b)" &&
+ latest_cmp edge &&
+ latest_cmp b &&
+ refresh node_ops_mv node_status_mv &&
+ printf "%s\thealthy\t0\n" "$(ak b)" "$(ak edge)" | sort >"$W/status" &&
+ status_cmp "$W/status" &&
+ for n in edge b; do
+ status_log "$n" >"$W/log-$n" &&
+ grep -qx "5 head: pass, seq 4 of 4, generation 4" "$W/log-$n" || exit 1
+ done
+'
+
+# No walk: each node fetches the tag and, to apply the delete at seq 5,
+# its package's manifest, which bpm tree append stores in the tree's
+# repository; never a sealed segment, by digest or by tag.
+test_expect_success 'append 5 seals segment 2; neither node walks' '
+ append 1.0.0/net-guard-1.0.0 delete &&
+ walk &&
+ python3 "$CHECKS" segments "$W/walk" >"$W/segments" &&
+ printf "%s\t%s\t%s\n" 0 2 2 2 4 4 4 5 5 >"$W/bounds.expected" &&
+ cut -f 1-3 "$W/segments" | diff -u "$W/bounds.expected" - >&2 &&
+ head -n 2 "$W/segments" | diff -u "$W/segments-4" - >&2 &&
+ sync_node edge step-4 >"$W/fetched-edge" &&
+ sync_node b step-4 >"$W/fetched-b" &&
+ cut -f 4 "$W/segments" | head -n 2 >"$W/sealed" &&
+ {
+ echo stable &&
+ python3 "$CHECKS" artifacts "$W/walk" 5 | sed "s/^/sha256:/"
+ } | sort -u >"$W/fetched.expected" &&
+ {
+ sort -u "$W/fetched-edge" | diff -u "$W/fetched.expected" - >&2 &&
+ sort -u "$W/fetched-b" | diff -u "$W/fetched.expected" - >&2 &&
+ ! grep -q "segment-" "$W/requests-edge" "$W/requests-b" &&
+ ! grep -qFf "$W/sealed" "$W/requests-edge" "$W/requests-b" ||
+ {
+ sed "s/^/sealed: /" "$W/sealed" >&2
+ sed "s/^/edge: /" "$W/requests-edge" >&2
+ sed "s/^/b: /" "$W/requests-b" >&2
+ false
+ }
+ } &&
+ printf "xfs-fix %s\n" "$(cat "$W/payload-xfs-fix-1.1.0")" >"$W/loaded" &&
+ node_check edge role=edge 5 VUA= "1 2 3 4 5" "$W/loaded" &&
+ : >"$W/loaded" &&
+ node_check b role=core 5 mkA= "2 5" "$W/loaded" &&
+ for n in edge b; do
+ test "$(view "$n" segment_base_seq)" = 4 || exit 1
+ done
+'
+
+test_expect_success 'the publisher chains three segments by sealed digest and history_root' '
+ cut -f 4 "$W/segments" | head -n 2 >"$W/sealed" &&
+ python3 "$CHECKS" tags "$REGISTRY" "$E2E/ca.pem" "$REPOSITORY" 2 |
+ diff -u "$W/sealed" - >&2 &&
+ cut -f 5 "$W/segments" | tail -n 2 | diff -u "$W/sealed" - >&2 &&
+ python3 "$CHECKS" operations "$W/walk" | cut -f 4 >"$W/digests" &&
+ test "$(wc -l <"$W/digests")" = 5 &&
+ for at in 2 4; do
+ test "$(python3 "$CHECKS" roots $(head -n "$at" "$W/digests") |
+ cut -d " " -f 2)" = \
+ "$(awk -F "\t" -v at="$at" "\$1 == at { print \$6 }" "$W/segments")" ||
+ exit 1
+ done
+'
+
+test_expect_success 'each keepalive covers all five operations from base_seq 0' '
+ report 4 &&
+ for n in edge b; do
+ test "$(view "$n" base_seq)" = 0 &&
+ latest_cmp "$n" &&
+ on "$n" "$RUNTIME status --keepalive" >"$W/keepalive-$n" &&
+ python3 - "$W/keepalive-$n" "$W/view-$n" <<-\PY || exit 1
+ import json, sys
+ body, view = (json.load(open(p)) for p in sys.argv[1:3])
+ for key in "base_seq", "base_root", "mask", "last_seq", "projection_root":
+ assert body[key] == view[key], (key, body[key], view[key])
+ assert body["base_seq"] == 0 and body["last_seq"] == 5, body
+ PY
+ done
+'
+
+test_expect_success 'the backend holds one tree of three segments; both nodes healthy' '
+ ingest &&
+ sed "s/\t-\t/\t\t/" "$W/segments" >"$W/pubs" &&
+ ch_cmp "SELECT segment_base_seq, head_seq, generation, manifest_digest,
+ segment_manifest_digest, history_root
+ FROM shirudo.tree_pubs FINAL WHERE tree_id = '\''$TREE_ID'\''
+ ORDER BY generation" "$W/pubs" &&
+ python3 "$CHECKS" operations "$W/walk" >"$W/ops" &&
+ ch_cmp "SELECT seq, op, id, operation_digest FROM shirudo.tree_ops FINAL
+ WHERE tree_id = '\''$TREE_ID'\'' ORDER BY seq" "$W/ops" &&
+ refresh node_ops_mv history_contradictions_mv node_status_mv &&
+ history_cmp edge 0 &&
+ history_cmp b 0 &&
+ test "$(ch "SELECT count() FROM shirudo.history_contradictions")" = 0 &&
+ printf "%s\thealthy\t0\n" "$(ak b)" "$(ak edge)" | sort >"$W/status" &&
+ status_cmp "$W/status" &&
+ status_log edge >"$W/log-edge" &&
+ status_log b >"$W/log-b" &&
+ root_edge=$(view edge projection_root | cut -c 1-8) &&
+ root_b=$(view b projection_root | cut -c 1-8) &&
+ grep -qx "4 chain: pass, root $root_edge" "$W/log-edge" &&
+ grep -qx "5 head: pass, seq 5 of 5, generation 5" "$W/log-edge" &&
+ grep -qx "6 set: pass, 1 loaded" "$W/log-edge" &&
+ grep -qx "4 chain: pass, root $root_b" "$W/log-b" &&
+ grep -qx "5 head: pass, seq 5 of 5, generation 5" "$W/log-b" &&
+ grep -qx "6 set: pass, 0 loaded" "$W/log-b"
+'
+
+test_done
diff --git a/testing/fixtures/pipeline/net-guard/Beefile b/testing/fixtures/pipeline/net-guard/Beefile
new file mode 100644
index 00000000..201d2c99
--- /dev/null
+++ b/testing/fixtures/pipeline/net-guard/Beefile
@@ -0,0 +1,11 @@
+[package]
+name = "net-guard"
+description = "The upatch of the backward-walk end-to-end test that every node applies"
+license = "GPL-2.0 OR BSD-2-Clause"
+authors = ["Authors of shirudo"]
+
+[[upatches]]
+source = "net-guard.bpf.c"
+
+[upatches.tree]
+id = "net-guard"
diff --git a/testing/fixtures/pipeline/net-guard/net-guard.bpf.c b/testing/fixtures/pipeline/net-guard/net-guard.bpf.c
new file mode 100644
index 00000000..491ba5b6
--- /dev/null
+++ b/testing/fixtures/pipeline/net-guard/net-guard.bpf.c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * The upatch of the backward-walk end-to-end test that selects no label,
+ * so that every node applies it. It attaches to a function every test
+ * kernel has, so that it always loads.
+ */
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "Dual BSD/GPL";
+
+SEC("fentry/tcp_v4_connect")
+int BPF_PROG(net_guard)
+{
+ return 0;
+}
diff --git a/testing/functional/build/t1007-test-vm-cli.sh b/testing/functional/build/t1007-test-vm-cli.sh
index 03f6ecc6..9ccb5bc6 100755
--- a/testing/functional/build/t1007-test-vm-cli.sh
+++ b/testing/functional/build/t1007-test-vm-cli.sh
@@ -966,10 +966,14 @@ test_expect_success 'the runners split the tests by number' '
grep -q "no tests nosuch" "$WORK/nosuch.out" &&
test -e end2end/t9109-pipeline.sh &&
test -e end2end/t9110-keepalive-history.sh &&
+ test -e end2end/t9111-pipeline-segments.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 ;;" \
+ 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 t9110-keepalive-history" end2end/host.sh &&
+ grep -Fqx " host_test t9111-pipeline-segments" 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.sh
index aea68d0e..fbd54a67 100755
--- a/testing/run-target-tests.sh
+++ b/testing/run-target-tests.sh
@@ -72,10 +72,11 @@ for t in "$dir"/t[0-9]1[0-9][0-9]-*.sh; do
[ -e "$t" ] || continue
found=1
test_matches "$t" || continue
- # end2end/host.sh runs t9109 and t9110 itself, on the host after node
- # A's suite, against the fresh edge node and node B.
+ # end2end/host.sh runs t9109 to t9111 itself, on the host after node
+ # A's suite, against fresh edge nodes and nodes B.
case "$t" in
end2end/t9109-pipeline.sh | end2end/t9110-keepalive-history.sh) continue ;;
+ end2end/t9111-pipeline-segments.sh) continue ;;
esac
log="$SHIRUDO_TEST_RESULTS/$(basename "$t").log"
rc=0
diff --git a/testing/vm/stack-lib.sh b/testing/vm/stack-lib.sh
index 7c606331..cc9dd0f1 100644
--- a/testing/vm/stack-lib.sh
+++ b/testing/vm/stack-lib.sh
@@ -67,6 +67,14 @@ stack_oci()
stack_wait_https "https://$REGISTRY/v2/"
}
+# The registry's access log, oldest request first, one line per request
+# in the combined log format. The registry writes it to standard output
+# and the rest of its log to standard error.
+stack_oci_log()
+{
+ docker logs "$STACK_NAME-registry" 2>/dev/null
+}
+
stack_telemetry()
{
docker network inspect "$STACK_NAME" >/dev/null 2>&1 ||