Skip to content

eBPF-based security platform

testing: check the keepalive backend's history over tree segments

John Fastabendddfc363e4515
diff --git a/.agents/skills/testing/SKILL.md b/.agents/skills/testing/SKILL.md
index 4333e9c2..2b357373 100644
--- a/.agents/skills/testing/SKILL.md
+++ b/.agents/skills/testing/SKILL.md
@@ -26,14 +26,15 @@ 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 does 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
-on the host against it and node B; its output is
-`build/test-vm/end2end/t9109.log`. A test reaches the nodes with
+without one t9107 skips and t9109 and t9110 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
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index 51ecd2fd..e5ec7664 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -679,6 +679,14 @@ signed config image.
and ``qA==``, each node's records against the backend's rows,
every SBOM state, ``node_vulns`` exposure and a body altered in
transit
+ * - ``t9110-keepalive-history``
+ - The backend's history of each node over a tree of segments, run by
+ ``host.sh`` after ``t9109`` on the same nodes: ``bpm tree append
+ --segment-ops 2`` past the lowered keepalive window, the ingest
+ job loading every segment through ``bpm tree show --walk``, a
+ 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``
Unit suites and fuzz targets
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -839,7 +847,8 @@ Coverage by area
* - upatch tree
- ``t3011``, ``t5004``, ``t7005``, ``t7007``, ``t7008``, ``t7009``,
``t7101``, ``t7102``, ``t7103``, ``t7104``, ``t7105``, ``t7106``,
- ``t7107``, ``t7108``, ``t7109``, ``t7110``, ``t9105``, ``t9109``.
+ ``t7107``, ``t7108``, ``t7109``, ``t7110``, ``t9105``, ``t9109``,
+ ``t9110``.
Fuzz: ``tree``,
``tree-state``, ``kconfig``. Unit: ``bpm_tree``,
``bpm_tree_overlap``, ``bpm_tree_state``, ``chain_history``,
@@ -851,7 +860,8 @@ Coverage by area
* - Telemetry
- ``t4006``, ``t4104``, ``t6139``, ``t7109``, ``t7110``, ``t8001`` to
``t8007``, ``t8101`` to ``t8106``, ``t9101`` to ``t9105``,
- ``t9107``, ``t9109``. Fuzz: ``otel``, ``quote-check``, ``serializer``.
+ ``t9107``, ``t9109``, ``t9110``. Fuzz: ``otel``, ``quote-check``,
+ ``serializer``.
Unit: ``keepalive``, ``keepalive_quote``, ``sysinfo``
* - Decoders
- ``t3002``, ``t8102``, ``t9101``. Fuzz: ``decoder``
diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rst
index 2ac3afb2..19526738 100644
--- a/Documentation/contribute/testing/testing.rst
+++ b/Documentation/contribute/testing/testing.rst
@@ -172,10 +172,10 @@ 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`` carries a target number but runs on the host:
-:src:`testing/end2end/host.sh` runs it after node A's suite, against two
-other nodes (see :ref:`testing-two-nodes`), and node A's runner leaves it
-out.
+``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
+A's runner leaves them out.
Run the tests
-------------
@@ -659,9 +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`` against the same backend, see
-:ref:`testing-pipeline`. Without ``BACKEND_DIR`` and without
-``../backend``, ``t9107`` skips and ``t9109`` does not run:
+``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:
.. code-block:: console
@@ -677,8 +678,9 @@ 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`` runs against it and node B. Both boot with ``make
--C testing vm-node-end2end``, ``END2END_NODE=b`` or ``edge``: the runner's
+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
+``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
until ``host.sh`` stops it at the end. Each takes its role from a signed
@@ -812,6 +814,45 @@ with one byte of its body changed lands in ``rejected`` as
the loaded set and each quote's qualifying data from the formats' own
definitions.
+.. _testing-history:
+
+The history over segments
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``t9110`` checks the backend's history of each node, ``node_ops`` and
+``node_sets``, on a tree longer than the keepalive window. The bundle
+builds every guest target with a window of 7 operations, a walk of 4 and
+a join of 6 (``TREE_LIMIT_CFLAGS``), so a tree of 11 operations is enough.
+``host.sh`` runs it after ``t9109``, against the same nodes and backend,
+and its output is ``build/test-vm/end2end/t9110.log``. It continues
+``t9109``'s tree, whose first segment holds operations 1 to 3, the add of
+``xfs-fix`` 1.1.0 at seq 3 with ``fixes`` included, and needs both nodes
+at seq 3 of it. It:
+
+#. empties the keepalive backend, loads its schema again and sets
+ ``window`` in ``shirudo.settings`` to 7;
+#. builds ``hist-pad``, a copy of ``xfs-fix`` that selects every node,
+ and appends add and delete of it in turn with ``--segment-ops 2``, as
+ operations 4 and 5, 6 and 7, then 8 to 11, which seal four segments;
+#. after each step loads the tree with the ingest job and syncs the
+ nodes. The edge node sends a keepalive each time, so the backend sees
+ it from seq 1. Node B syncs to seq 7, walking back one segment, and
+ sends nothing until seq 11, so the backend first sees it with a
+ window that starts at seq 4.
+
+It then checks that ``bpm tree show --walk`` and ``tree_pubs`` hold the
+five segments with their bases, ``segment-<k>`` tags and
+``history_root``, and ``tree_ops`` all 11 operations; that each node's
+newest record, its ``status --keepalive`` body and its ``outcomes`` agree
+on ``base_seq`` 4, ``base_root`` and the mask; that ``node_ops`` holds
+the edge node from seq 1 and node B from a gap row at seq 4, with the
+roots of their ``outcomes``; that both nodes are ``healthy``, the edge
+node's ``base_root`` verified and node B's log reading ``base unverified
+(gap)`` and ``set unverified (gap)``; and that ``node_vulns`` still reads
+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.
+
Select test scripts
~~~~~~~~~~~~~~~~~~~
diff --git a/testing/end2end/host.sh b/testing/end2end/host.sh
index 3b196ffe..e8d68d0b 100755
--- a/testing/end2end/host.sh
+++ b/testing/end2end/host.sh
@@ -4,8 +4,8 @@
# testing/end2end/host.sh -- run the operator side of the end-to-end VM test.
# Its arguments are the command that runs the suite in node A; node B, a
# second target with a TPM of its own, boots beside it. After node A, a
-# fresh edge node boots in its place and t9109 runs here against it and
-# node B.
+# fresh edge node boots in its place and t9109 and t9110 run here against
+# it and node B.
set -eu
@@ -118,6 +118,21 @@ PY
die "node $1 does not declare the image of the end-to-end nodes"
}
+# Run the test end2end/$1.sh on the host against the fresh edge node and
+# node B, with the keepalive backend, into $W/<number>.log. t9110 continues
+# what t9109 left in both nodes and the tree, so they run in that order.
+host_test() {
+ log=$W/${1%%-*}.log
+ say "${1%%-*}, on the host, against the fresh edge node and node B"
+ rc=0
+ (cd testing && E2E=$W END2END_BACKEND=$BACKEND END2END_KEYS=$KEYS \
+ NODES_DIR=$NODES_DIR NODES_HOST=$NODES_HOST \
+ sh "end2end/$1.sh") >"$log" 2>&1 || rc=$?
+ cat "$log"
+ [ "$rc" -eq 0 ] || die "${1%%-*} failed; see $log"
+ ! grep -q '^1\.\.0 # SKIP' "$log" || die "${1%%-*} was skipped"
+}
+
# 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
@@ -368,14 +383,8 @@ if [ -n "$NODE_EDGE_PID" ]; then
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")"
- say "t9109, on the host, against the fresh edge node and node B"
- rc=0
- (cd testing && E2E=$W END2END_BACKEND=$BACKEND END2END_KEYS=$KEYS \
- NODES_DIR=$NODES_DIR NODES_HOST=$NODES_HOST \
- sh end2end/t9109-pipeline.sh) >"$W/t9109.log" 2>&1 || rc=$?
- cat "$W/t9109.log"
- [ "$rc" -eq 0 ] || die "t9109 failed; see $W/t9109.log"
- ! grep -q '^1\.\.0 # SKIP' "$W/t9109.log" || die "t9109 was skipped"
+ host_test t9109-pipeline
+ host_test t9110-keepalive-history
node_down edge ""
node_clean edge
fi
diff --git a/testing/end2end/pipeline_checks.py b/testing/end2end/pipeline_checks.py
index fe623072..73b48eec 100644
--- a/testing/end2end/pipeline_checks.py
+++ b/testing/end2end/pipeline_checks.py
@@ -1,13 +1,16 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2026 Authors of shirudo
-"""What t9109 recomputes from a node's records and the backend's rows, each
-from the format's own definition, so that neither side is taken on trust."""
+"""What t9109 and t9110 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 ssl
import sys
+import urllib.request
ZERO = bytes(32)
HISTORY_TAG = b"shirudo-tree-history\0"
@@ -32,10 +35,10 @@ def roots(digests):
return projection.hex(), history.hex()
-def mask(outcomes, head_seq):
- """The keepalive mask of a node whose window starts at seq 1."""
+def mask(outcomes, head_seq, base_seq=0):
+ """The keepalive mask of a node over the window past base_seq."""
codes = {line["seq"]: line["outcome"] for line in outcomes}
- pairs = [codes.get(seq, 0) for seq in range(1, head_seq + 1)]
+ pairs = [codes.get(seq, 0) for seq in range(base_seq + 1, head_seq + 1)]
raw = bytearray((len(pairs) + 3) // 4)
for i, code in enumerate(pairs):
raw[i // 4] |= code << (6 - 2 * (i % 4))
@@ -63,31 +66,126 @@ def quote_extra(quote):
return attest[offset + 2:offset + 2 + size].hex()
-def node(state_path, outcomes_path, eventlog_path):
- """A node's view: its roots, its mask, and the digests it chained."""
+def node(state_path, outcomes_path, eventlog_path, window=None):
+ """A node's view: its roots, the window of its keepalive, which starts
+ at seq 1 without a window size, and the digests it chained."""
with open(state_path, encoding="utf-8") as f:
state = json.load(f)
outcomes = lines(outcomes_path)
seqs = [line["seq"] for line in outcomes]
assert seqs == list(range(1, state["last_seq"] + 1)), seqs
+ base = max(0, state["head_seq"] - int(window)) if window else 0
+ base_root = ZERO.hex()
+ if base:
+ base_root = hexdigest(outcomes[base - 1]["projection_root"])
return {
"last_seq": state["last_seq"],
+ "head_seq": state["head_seq"],
+ "segment_base_seq": state["segment_base_seq"],
"generation": state["generation"],
"projection_root": hexdigest(state["projection_root"]),
"outcomes": [line["outcome"] for line in outcomes],
"history_root": hexdigest(outcomes[-1]["history_root"]),
"outcome_root": hexdigest(outcomes[-1]["projection_root"]),
- "mask": mask(outcomes, state["head_seq"]),
+ "base_seq": base,
+ "base_root": base_root,
+ "mask": mask(outcomes, state["head_seq"], base),
"chained": [hexdigest(line["digest"]) for line in lines(eventlog_path)],
}
+def history(outcomes_path, gap):
+ """The rows of node_ops for a node's outcomes: from seq 1 with gap 0,
+ else from a gap row at seq gap that holds the root there."""
+ outcomes = lines(outcomes_path)
+ rows = []
+ if gap:
+ rows.append((gap, 0, outcomes[gap - 1]["projection_root"]))
+ rows += [(line["seq"], line["outcome"], line["projection_root"])
+ for line in outcomes if line["seq"] > gap]
+ return [f"{seq}\t{code}\t{hexdigest(root)}" for seq, code, root in rows]
+
+
+def walk(path):
+ """The objects `bpm tree show --walk` printed, each a JSON value that
+ may span lines."""
+ with open(path, encoding="utf-8") as f:
+ text = f.read()
+ decoder, at, objects = json.JSONDecoder(), 0, []
+ while True:
+ while at < len(text) and text[at].isspace():
+ at += 1
+ if at == len(text):
+ return objects
+ value, at = decoder.raw_decode(text, at)
+ objects.append(value)
+
+
+def segments(path):
+ """One line per segment of a walk, oldest first: base, head,
+ generation, manifest digest, the sealed segment it names (- for none)
+ and its history_root. Each segment continues the one before it, and
+ its history_root is the fold of every earlier operation."""
+ history_root = ZERO
+ previous, head, out = None, 0, []
+ for segment in walk(path):
+ document = segment["document"]
+ base = document["base"]
+ assert base["seq"] == head, (base, head)
+ if previous is None:
+ assert set(base) == {"seq"}, base
+ else:
+ assert hexdigest(base["segment_manifest_digest"]) == previous, base
+ assert base["history_root"] == history_root.hex(), base
+ for op in document["operations"]:
+ raw = bytes.fromhex(hexdigest(op["operation_digest"]))
+ history_root = hashlib.sha256(HISTORY_TAG + history_root + raw).digest()
+ head = document["head"]["seq"]
+ assert document["operations"][-1]["seq"] == head, document
+ manifest = hexdigest(segment["manifest_digest"])
+ sealed = hexdigest(base.get("segment_manifest_digest", "-"))
+ root = base.get("history_root", ZERO.hex())
+ out.append(f"{base['seq']}\t{head}\t{document['generation']}\t"
+ f"{manifest}\t{sealed}\t{root}")
+ previous = manifest
+ return out
+
+
+def operations(path):
+ """Every operation of a walk: seq, op, id and digest."""
+ return [f"{op['seq']}\t{op['op']}\t{op['id']}\t"
+ f"{hexdigest(op['operation_digest'])}"
+ for segment in walk(path)
+ for op in segment["document"]["operations"]]
+
+
+def tags(registry, ca, repository, count):
+ """The manifest digests of the tags segment-1 to segment-<count>."""
+ ctx = ssl.create_default_context(cafile=ca)
+ out = []
+ for k in range(1, count + 1):
+ request = urllib.request.Request(
+ f"https://{registry}/v2/{repository}/manifests/segment-{k}",
+ headers={"Accept": "application/vnd.oci.image.manifest.v1+json"})
+ with urllib.request.urlopen(request, context=ctx) as response:
+ out.append(hashlib.sha256(response.read()).hexdigest())
+ return out
+
+
def main():
command, args = sys.argv[1], sys.argv[2:]
if command == "roots":
print(*roots(args))
elif command == "node":
print(json.dumps(node(*args), sort_keys=True))
+ elif command == "history":
+ print(*history(args[0], int(args[1])), sep="\n")
+ elif command == "segments":
+ print(*segments(args[0]), sep="\n")
+ elif command == "operations":
+ print(*operations(args[0]), sep="\n")
+ elif command == "tags":
+ print(*tags(args[0], args[1], args[2], int(args[3])), sep="\n")
elif command == "set":
print(loaded_set(args[0]))
elif command == "quotes":
diff --git a/testing/end2end/t9110-keepalive-history.sh b/testing/end2end/t9110-keepalive-history.sh
new file mode 100644
index 00000000..68d6586a
--- /dev/null
+++ b/testing/end2end/t9110-keepalive-history.sh
@@ -0,0 +1,349 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# t9110 -- the keepalive backend keeps each node's history over a tree of
+# segments. The operator continues t9109's tree in segments of 2
+# operations up to seq 11, past the window of 7 operations the test VM
+# lowers the keepalive to. The ingest job loads every segment through bpm
+# tree show --walk. The fresh edge node reports from the start, so its
+# base_root is verified against node_ops, and xfs-fix, added at seq 3 below
+# its window, still shields it. Node B first reports at seq 11: a gap,
+# and still healthy.
+#
+# end2end/host.sh runs it on the host after t9109, as root, against the
+# same two nodes and backend.
+
+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}
+TREE=oci://$REGISTRY/shirudo/pipeline-tree
+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.
+WINDOW=7
+
+[ -n "${END2END_BACKEND-}" ] && [ -n "${END2END_KEYS-}" ] ||
+ test_skip_all "end2end/host.sh runs it after t9109, 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
+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() {
+ "$S" bpm tree append "$W/pkg/hist-pad-1.0.0.bee" "$TREE" \
+ --keys-dir "$KEYS" --tree-id pipeline --segment-ops 2 \
+ ${1:+--op "$1"} >&2
+}
+
+ingest() {
+ "$BACKEND/jobs/tree-ingest" --shirudo "$S" --cert "$KEYS/cert.der" \
+ "$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" &&
+ test "$(view "$n" last_seq) $(view "$n" head_seq)" = "3 3" &&
+ test "$(view "$n" segment_base_seq)" = 0 &&
+ on "$n" "[ ! -e $STATE/pending.json ]" || exit 1
+ done &&
+ "$S" bpm tree show "$TREE" --cert "$KEYS/cert.der" --walk >"$W/walk-3" &&
+ python3 "$CHECKS" segments "$W/walk-3" | cut -f 1-3 >"$W/segments-3" &&
+ test "$(cat "$W/segments-3")" = "$(printf "0\t3\t3")"
+'
+
+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)" &&
+ test "$(ch "SELECT stale_seconds, stuck_seconds, window
+ FROM shirudo.settings FINAL")" = "$(printf "600\t3600\t%s" "$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'\'', '\''t9110'\'')" &&
+ test "$(ch "SELECT count() FROM shirudo.keepalive")" = 0 &&
+ test "$(ch "SELECT count() FROM shirudo.node_ops")" = 0
+'
+
+# hist-pad selects no label, so that both nodes apply it, and stands for
+# the operations a tree gathers after a fix.
+test_expect_success 'the operator builds hist-pad 1.0.0' '
+ mkdir -p "$W/pkg/hist-pad" &&
+ sed "s/BPF_PROG(xfs_fix)/BPF_PROG(hist_pad)/" \
+ "$FIX/xfs-fix/xfs-fix.bpf.c" >"$W/pkg/hist-pad/hist-pad.bpf.c" &&
+ cat >"$W/pkg/hist-pad/Beefile" <<-\EOF &&
+ [package]
+ name = "hist-pad"
+ description = "An operation of the history end-to-end test"
+ license = "GPL-2.0 OR BSD-2-Clause"
+ authors = ["Authors of shirudo"]
+
+ [[upatches]]
+ source = "hist-pad.bpf.c"
+
+ [upatches.tree]
+ id = "hist-pad"
+ EOF
+ ln -s "$REPO/vendor" "$W/pkg/hist-pad/vendor" &&
+ ln -s "$REPO/bpf" "$W/pkg/hist-pad/bpf" &&
+ (cd "$W/pkg" && "$S" bpm build hist-pad --version 1.0.0 \
+ --keys-dir "$KEYS") >&2
+'
+
+test_expect_success 'seq 4 and 5 seal the first segment; the edge node reports' '
+ append && append delete &&
+ ingest &&
+ unit_ok edge shirudo-bpm-tree-sync.service &&
+ node_view edge &&
+ test "$(view edge last_seq) $(view edge segment_base_seq)" = "5 3" &&
+ unit_ok edge shirudo-keepalive.service &&
+ ch_wait "SELECT count() FROM shirudo.keepalive FINAL" 1 &&
+ ak_record edge &&
+ test "$(view edge base_seq)" = 0 &&
+ latest_cmp edge &&
+ refresh node_ops_mv &&
+ history_cmp edge 0
+'
+
+# Node B syncs without reporting: a walk of 2 operations back from seq 3,
+# within the 4 a running node of the test VM walks.
+test_expect_success 'seq 6 and 7: node B walks back a segment, unseen by the backend' '
+ append && append delete &&
+ ingest &&
+ unit_ok edge shirudo-bpm-tree-sync.service &&
+ unit_ok b shirudo-bpm-tree-sync.service &&
+ node_view edge && node_view b &&
+ test "$(view b last_seq) $(view b segment_base_seq)" = "7 5" &&
+ test "$(view b history_root)" = "$(view edge history_root)" &&
+ unit_ok edge shirudo-keepalive.service &&
+ ch_wait "SELECT count() FROM shirudo.keepalive FINAL" 2 &&
+ test "$(view edge base_seq)" = 0 &&
+ latest_cmp edge &&
+ refresh node_ops_mv &&
+ history_cmp edge 0 &&
+ test "$(ch "SELECT uniqExact(ak_name) FROM shirudo.keepalive")" = 1
+'
+
+test_expect_success 'seq 8 to 11: both nodes report a window past seq 0' '
+ append && append delete && append && append delete &&
+ ingest &&
+ for n in edge b; do
+ unit_ok "$n" shirudo-bpm-tree-sync.service &&
+ node_view "$n" &&
+ test "$(view "$n" last_seq) $(view "$n" segment_base_seq)" = "11 9" &&
+ test "$(view "$n" base_seq)" = 4 || exit 1
+ done &&
+ unit_ok edge shirudo-keepalive.service &&
+ unit_ok b shirudo-keepalive.service &&
+ ch_wait "SELECT count() FROM shirudo.keepalive FINAL" 4 &&
+ ak_record b &&
+ test "$(ak edge)" != "$(ak b)" &&
+ test "$(ch "SELECT count() FROM shirudo.rejected")" = 0 &&
+ for n in edge b; do
+ 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])
+ PY
+ done
+'
+
+test_expect_success 'bpm tree show --walk loads every segment into the backend' '
+ "$S" bpm tree show "$TREE" --cert "$KEYS/cert.der" --walk >"$W/walk" &&
+ python3 "$CHECKS" segments "$W/walk" >"$W/segments" &&
+ cut -f 1-3 "$W/segments" >"$W/bounds" &&
+ printf "%s\t%s\t%s\n" 0 3 3 3 5 5 5 7 7 7 9 9 9 11 11 >"$W/bounds.expected" &&
+ diff -u "$W/bounds.expected" "$W/bounds" >&2 &&
+ cut -f 4 "$W/segments" | head -n 4 >"$W/sealed" &&
+ python3 "$CHECKS" tags "$REGISTRY" "$E2E/ca.pem" shirudo/pipeline-tree 4 \
+ >"$W/tags" &&
+ diff -u "$W/sealed" "$W/tags" >&2 &&
+ 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 = '\''pipeline'\''
+ ORDER BY generation" "$W/pubs" &&
+ python3 "$CHECKS" operations "$W/walk" >"$W/ops" &&
+ test "$(wc -l <"$W/ops")" = 11 &&
+ ch_cmp "SELECT seq, op, id, operation_digest FROM shirudo.tree_ops FINAL
+ WHERE tree_id = '\''pipeline'\'' ORDER BY seq" "$W/ops" &&
+ cut -f 4 "$W/ops" >"$W/digests" &&
+ test "$(python3 "$CHECKS" roots $(cat "$W/digests") | cut -d " " -f 2)" = \
+ "$(view edge history_root)"
+'
+
+test_expect_success 'node_ops holds the edge node from seq 1 and node B from a gap at 4' '
+ refresh node_ops_mv &&
+ history_cmp edge 0 &&
+ history_cmp b 4 &&
+ printf "hist-pad\t11\tdelete\nxfs-fix\t3\tadd\n" >"$W/sets-edge" &&
+ ch_cmp "SELECT id, last_seq, last_op FROM shirudo.node_sets FINAL
+ WHERE ak_name = '\''$(ak edge)'\'' ORDER BY id" "$W/sets-edge"
+'
+
+test_expect_success 'base_root is verified on the edge node; node B shows a gap, healthy' '
+ refresh node_status_mv &&
+ 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
+ }
+ } &&
+ 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 11 of 11, generation 11" "$W/log-edge" &&
+ grep -qx "6 set: pass, 1 loaded" "$W/log-edge" &&
+ grep -qx "4 chain: pass, root $root_b, base unverified (gap)" "$W/log-b" &&
+ grep -qx "5 head: pass, seq 11 of 11, generation 11" "$W/log-b" &&
+ grep -qx "6 set: set unverified (gap), 0 loaded" "$W/log-b"
+'
+
+# xfs-fix 1.1.0 was added at seq 3 with fixes EXAMPLE-0101, below the
+# window of seq 5 to 11: only the history says what each node did there.
+test_expect_success 'the shield below the window still reads shielded on the edge node' '
+ stack_backend_client --query "INSERT INTO shirudo.kernel_vulns FORMAT JSONEachRow" \
+ <"$FIX/kernel-vulns.json" &&
+ refresh node_vulns_mv &&
+ cat >"$W/vulns" <<-EOF &&
+ b EXAMPLE-0101 unknown xfs-fix 3 add fixes
+ edge EXAMPLE-0101 shielded xfs-fix 3 add fixes
+ EOF
+ ch_cmp "SELECT if(ak_name = '\''$(ak edge)'\'', '\''edge'\'', '\''b'\'') AS node,
+ vuln_id, exposure, upatch_id, applied_seq, applied_op, shield_link
+ FROM shirudo.node_vulns WHERE source = '\''kernel'\''
+ ORDER BY node, vuln_id" "$W/vulns"
+'
+
+test_done
diff --git a/testing/functional/build/t1007-test-vm-cli.sh b/testing/functional/build/t1007-test-vm-cli.sh
index 87fbb913..03f6ecc6 100755
--- a/testing/functional/build/t1007-test-vm-cli.sh
+++ b/testing/functional/build/t1007-test-vm-cli.sh
@@ -965,9 +965,11 @@ test_expect_success 'the runners split the tests by number' '
! sh run-tests.sh nosuch >"$WORK/nosuch.out" 2>&1 &&
grep -q "no tests nosuch" "$WORK/nosuch.out" &&
test -e end2end/t9109-pipeline.sh &&
- grep -Fqx " [ \"\$t\" != end2end/t9109-pipeline.sh ] || continue" \
+ test -e end2end/t9110-keepalive-history.sh &&
+ grep -Fqx " end2end/t9109-pipeline.sh | end2end/t9110-keepalive-history.sh) continue ;;" \
run-target-tests.sh &&
- grep -Fq "sh end2end/t9109-pipeline.sh" end2end/host.sh
+ grep -Fqx " host_test t9109-pipeline" end2end/host.sh &&
+ grep -Fqx " host_test t9110-keepalive-history" 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 16cf67a1..aea68d0e 100755
--- a/testing/run-target-tests.sh
+++ b/testing/run-target-tests.sh
@@ -72,9 +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 itself, on the host after node A's suite,
- # against the fresh edge node and node B.
- [ "$t" != end2end/t9109-pipeline.sh ] || 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.
+ case "$t" in
+ end2end/t9109-pipeline.sh | end2end/t9110-keepalive-history.sh) continue ;;
+ esac
log="$SHIRUDO_TEST_RESULTS/$(basename "$t").log"
rc=0
sh "$t" >"$log" 2>&1 || rc=$?