eBPF-based security platform
testing: add the shared keepalive fixtures
John Fastabend543c2a765816
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex 5c2c6bc7..be76cac3 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -541,6 +541,9 @@ signed config image.- TLS 1.3 with ``X25519MLKEM768`` only* - ``t8006-otel-transport``- OTLP environment variables, headers and limits+ * - ``t8007-keepalive-fixtures``+ - Every digest, root, set hash, mask and tree key of the keepalive+ fixtures recomputes from their example tree* - ``t8101-map-export-all``- ``upatch map --all`` and JSON lines* - ``t8102-otel-backend``@@ -743,7 +746,7 @@ Coverage by areaUnauthorized policy-xattr changes: ``t6111``. Task and socketinheritance: ``t6141``, ``t6142``* - Telemetry- - ``t6139``, ``t8001`` to ``t8006``, ``t8101`` to ``t8105``,+ - ``t6139``, ``t8001`` to ``t8007``, ``t8101`` to ``t8105``,``t9101`` to ``t9105``. Fuzz: ``otel``, ``serializer``* - Decoders- ``t3002``, ``t8102``, ``t9101``. Fuzz: ``decoder``diff --git a/testing/fixtures/keepalive/node-a-1.0.0.json b/testing/fixtures/keepalive/node-a-1.0.0.jsonnew file mode 100644index 00000000..bcf64c38--- /dev/null+++ b/testing/fixtures/keepalive/node-a-1.0.0.json@@ -0,0 +1 @@+{"schema":"shirudo.keepalive/1","boot_id":"168d20a1-5011-4e1b-9924-d8b73c85aa4e","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":1,"base_seq":0,"last_seq":1,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"04f83540c1727aefcf3c53449a99594c8fd1cc15e1466dbdbf3168cc8f9dc136","mask":"QA==","set_sha256":"6c9e113d02cd14646f617d7bba4a092b91bc3802dfdaae50e2fef7a01e0580aa","count":1,"not_ok":0}\ No newline at end of filediff --git a/testing/fixtures/keepalive/node-a-1.1.0.json b/testing/fixtures/keepalive/node-a-1.1.0.jsonnew file mode 100644index 00000000..532e0a02--- /dev/null+++ b/testing/fixtures/keepalive/node-a-1.1.0.json@@ -0,0 +1 @@+{"schema":"shirudo.keepalive/1","boot_id":"168d20a1-5011-4e1b-9924-d8b73c85aa4e","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":3,"base_seq":0,"last_seq":3,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"154522480ff8884daa95589e80f26f20248bbf9c192dfbb3cee04e03b4f136a1","mask":"VA==","set_sha256":"74e5bd2c665109f6d8f926af5476c266ad70ab07293ff13b1a13d0b89aa5c1bf","count":1,"not_ok":0}\ No newline at end of filediff --git a/testing/fixtures/keepalive/node-b-1.0.0.json b/testing/fixtures/keepalive/node-b-1.0.0.jsonnew file mode 100644index 00000000..a3b65c1a--- /dev/null+++ b/testing/fixtures/keepalive/node-b-1.0.0.json@@ -0,0 +1 @@+{"schema":"shirudo.keepalive/1","boot_id":"9a6f14ea-0cc2-45e1-8e23-7b887120cf54","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":1,"base_seq":0,"last_seq":1,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"0000000000000000000000000000000000000000000000000000000000000000","mask":"gA==","set_sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","count":0,"not_ok":0}\ No newline at end of filediff --git a/testing/fixtures/keepalive/node-b-1.1.0.json b/testing/fixtures/keepalive/node-b-1.1.0.jsonnew file mode 100644index 00000000..48f186a6--- /dev/null+++ b/testing/fixtures/keepalive/node-b-1.1.0.json@@ -0,0 +1 @@+{"schema":"shirudo.keepalive/1","boot_id":"9a6f14ea-0cc2-45e1-8e23-7b887120cf54","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":3,"base_seq":0,"last_seq":3,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"0000000000000000000000000000000000000000000000000000000000000000","mask":"qA==","set_sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","count":0,"not_ok":0}\ No newline at end of filediff --git a/testing/fixtures/keepalive/ops-16.json b/testing/fixtures/keepalive/ops-16.jsonnew file mode 100644index 00000000..56bf1344--- /dev/null+++ b/testing/fixtures/keepalive/ops-16.json@@ -0,0 +1 @@+{"schema":"shirudo.keepalive/1","boot_id":"d5140906-4eab-4983-a62c-29e49d449ea3","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1fbdff17ad8d50404772901df54d5aa2c698eddbb413e286fc654f80931c688a","kernel_release":"7.4.0-shirudo","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":42,"base_seq":0,"last_seq":12,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"f59301708fc8e150c5d2abb1009b4f13fc0dcc1304b708f77dc14b1541679e28","mask":"WdlZAA==","set_sha256":"ac1af1d44b5c1fe3f616384db421138aa4d296595797b5864908a89276e17e6d","count":7,"not_ok":0}\ No newline at end of filediff --git a/testing/fixtures/keepalive/recompute.py b/testing/fixtures/keepalive/recompute.pynew file mode 100755index 00000000..3b94538d--- /dev/null+++ b/testing/fixtures/keepalive/recompute.py@@ -0,0 +1,304 @@+#!/usr/bin/env python3+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# recompute.py -- recompute the keepalive example values from the fixtures+# beside it: the operation digests, the projection_root chain, the set+# hashes and the masks of tree-1.1.0.json, and with them the tree keys of+# the four node bodies. Exits non-zero on any mismatch.++import base64+import hashlib+import json+import os+import sys++HERE = os.path.dirname(os.path.abspath(__file__))+ZEROS = "0" * 64+EMPTY_SET = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"++BODY_KEYS = [+ "schema", "boot_id", "version_id", "config_root", "kernel_release",+ "image_id", "image_version", "image_root", "verdict", "cond", "flags",+ "tamper", "tree_id", "generation", "base_seq", "last_seq", "base_root",+ "projection_root", "mask", "set_sha256", "count", "not_ok",+]+CANONICAL_KEYS = ["seq", "op", "id", "selector", "artifact"]+TAMPER_COUNTERS = 37+ALL_OK = 0x1555++OPERATION_DIGESTS = [+ "13b248d4a85d91150717e3e96dc9c2d7a8a43633e3b58f8f6168d408aed26c43",+ "5ce215313f29f87bfb87aa0cc65c237bf21bdc7702606e9cc29be187f950074b",+ "bd98b27dd5cfc9deeb0e4f49a7d4bd0f991762ec784be9ea838a59966d9dd0dc",+]+PROJECTION_ROOTS = [+ "04f83540c1727aefcf3c53449a99594c8fd1cc15e1466dbdbf3168cc8f9dc136",+ "a042a582b3a3d8c1b633b8ed0356e0b52f1f5aa25af85b06cc3f481562dcda93",+ "154522480ff8884daa95589e80f26f20248bbf9c192dfbb3cee04e03b4f136a1",+]+SET_1_0_0 = "6c9e113d02cd14646f617d7bba4a092b91bc3802dfdaae50e2fef7a01e0580aa"+SET_1_1_0 = "74e5bd2c665109f6d8f926af5476c266ad70ab07293ff13b1a13d0b89aa5c1bf"+FIXES = {1: ["EXAMPLE-0101"], 3: ["EXAMPLE-0101"]}++MASKS = [+ ("QA==", [1]),+ ("gA==", [2]),+ ("VA==", [1, 1, 1]),+ ("qA==", [2, 2, 2]),+ ("WdlZAA==", [1, 1, 2, 1, 3, 1, 2, 1, 1, 1, 2, 1, 0, 0, 0, 0]),+]++# The body the example pages print for node A after release 1.1.0: six+# conditions and no image keys.+PAGE_BODY_LEN = 732+PAGE_BODY_SHA256 = \+ "e863ee98defa29abe5c4367e3278ccb06a6b8b94702967afee949bcb9c7f0471"+PAGE_COND = 0x555++VERSION_ID = "d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f"+NODES = {+ "a": {+ "labels": {"role": "edge"},+ "identity": {+ "boot_id": "168d20a1-5011-4e1b-9924-d8b73c85aa4e",+ "version_id": VERSION_ID,+ "config_root": "1d8465c5b17838303fee92b3905420d2"+ "94d2c22c576a0bdef0f69f190ed22807",+ "kernel_release": "7.4.2",+ "image_id": "fleet-os",+ "image_version": "2026.11.1",+ "image_root": "a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c"+ "4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c",+ },+ },+ "b": {+ "labels": {"role": "core"},+ # The pages give only the ends of node B's config_root; the middle+ # is fixed here.+ "identity": {+ "boot_id": "9a6f14ea-0cc2-45e1-8e23-7b887120cf54",+ "version_id": VERSION_ID,+ "config_root": "ff2cbeff5d0e9c41a7b36f28d14ce09b"+ "73a5182e6fc40d97b5e2a1683c0f7ff8",+ "kernel_release": "7.4.2",+ "image_id": "fleet-os",+ "image_version": "2026.11.1",+ "image_root": None,+ },+ },+}+# Release, the generation its last append published and that+# publication's head.seq.+RELEASES = [("1.0.0", 1, 1), ("1.1.0", 3, 3)]++failures = 0+++def check(what, got, want):+ global failures++ if got == want:+ print(f"ok {what}")+ return+ failures += 1+ print(f"FAIL {what}\n got {got!r}\n want {want!r}")+++def compact(value):+ return json.dumps(value, separators=(",", ":"),+ ensure_ascii=False).encode()+++def sha256_hex(data):+ return hashlib.sha256(data).hexdigest()+++def load(name):+ """Parse a fixture and check that its bytes are the compact form."""+ with open(os.path.join(HERE, name), "rb") as f:+ raw = f.read()+ value = json.loads(raw)+ check(f"{name}: compact, no trailing newline", raw, compact(value))+ return value, raw+++def canonical(op):+ return compact({key: op[key] for key in CANONICAL_KEYS})+++def projection_step(prev, digest):+ return sha256_hex(bytes.fromhex(prev) + bytes.fromhex(digest))+++def selects(selector, labels):+ return all(labels.get(key) in values+ for key, values in selector.get("labels", {}).items())+++def mask_encode(codes):+ raw = bytearray((len(codes) + 3) // 4)+ for i, code in enumerate(codes):+ raw[i // 4] |= code << (6 - 2 * (i % 4))+ return base64.b64encode(bytes(raw)).decode()+++def set_sha256(loaded):+ lines = "".join(f"{payload} {name}\n"+ for name, payload in sorted(loaded.items()))+ return sha256_hex(lines.encode())+++def walk(operations, labels, head_seq):+ """The tree keys a node with these labels reports at head_seq."""+ root = ZEROS+ loaded = {}+ codes = []++ for op in operations[:head_seq]:+ if not selects(op["selector"], labels):+ codes.append(2)+ continue+ codes.append(1)+ root = projection_step(root, op["operation_digest"][len("sha256:"):])+ if op["op"] == "add":+ payload = op["artifact"]["payload_sha256"]+ loaded[op["id"]] = payload[len("sha256:"):]+ else:+ del loaded[op["id"]]+ return {+ "base_seq": 0,+ "last_seq": head_seq,+ "base_root": ZEROS,+ "projection_root": root,+ "mask": mask_encode(codes),+ "set_sha256": set_sha256(loaded),+ "count": len(loaded),+ "not_ok": 0,+ }+++def check_tree(tree):+ operations = tree["operations"]+ root = ZEROS++ check("tree: top-level keys", list(tree),+ ["schema", "tree_id", "generation", "parent_manifest_digest",+ "base", "operations", "head"])+ check("tree: generation", tree["generation"], 3)+ check("tree: base.seq", tree["base"], {"seq": 0})+ check("tree: head.seq", tree["head"], {"seq": len(OPERATION_DIGESTS)})+ check("tree: operation seqs", [op["seq"] for op in operations],+ list(range(1, len(OPERATION_DIGESTS) + 1)))+ for op, want in zip(operations, OPERATION_DIGESTS):+ seq = op["seq"]+ keys = CANONICAL_KEYS + ["fixes"] * (seq in FIXES) + \+ ["operation_digest"]+ check(f"operation {seq}: keys", list(op), keys)+ check(f"operation {seq}: fixes", op.get("fixes"), FIXES.get(seq))+ digest = sha256_hex(canonical(op))+ check(f"operation {seq}: digest of the canonical form", digest, want)+ check(f"operation {seq}: operation_digest", op["operation_digest"],+ "sha256:" + digest)+ root = projection_step(root, digest)+ check(f"projection_root after {seq}, all applied", root,+ PROJECTION_ROOTS[seq - 1])+++def check_sets(tree):+ payloads = [op["artifact"]["payload_sha256"][len("sha256:"):]+ for op in tree["operations"]]++ check("set_sha256 of the 1.0.0 set",+ set_sha256({"xfs-fix": payloads[0]}), SET_1_0_0)+ check("set_sha256 of the 1.1.0 set",+ set_sha256({"xfs-fix": payloads[2]}), SET_1_1_0)+ check("set_sha256 of the empty set", set_sha256({}), EMPTY_SET)+++def check_masks():+ for mask, codes in MASKS:+ check(f"mask {mask}", mask_encode(codes), mask)+++def check_health(name, body):+ check(f"{name}: keys", list(body), BODY_KEYS)+ check(f"{name}: schema", body["schema"], "shirudo.keepalive/1")+ check(f"{name}: verdict", body["verdict"], "ok")+ check(f"{name}: cond", body["cond"], ALL_OK)+ check(f"{name}: flags", body["flags"], 0)+ check(f"{name}: tamper", body["tamper"], [0] * TAMPER_COUNTERS)+++def check_node(tree, node, release, generation, head_seq):+ name = f"node-{node}-{release}.json"+ body, raw = load(name)+ want = dict(NODES[node]["identity"])++ want.update(tree_id=tree["tree_id"], generation=generation)+ want.update(walk(tree["operations"], NODES[node]["labels"], head_seq))+ check_health(name, body)+ for key, value in want.items():+ check(f"{name}: {key}", body[key], value)+ print(f" {name}: {len(raw)} bytes, sha256 {sha256_hex(raw)}")+ return body+++def check_final(bodies):+ a = bodies[("a", "1.1.0")]+ b = bodies[("b", "1.1.0")]++ check("node A after 1.1.0: mask, root, set, count",+ [a["mask"], a["projection_root"], a["set_sha256"], a["count"]],+ ["VA==", PROJECTION_ROOTS[2], SET_1_1_0, 1])+ check("node B after 1.1.0: mask, root, set, count",+ [b["mask"], b["projection_root"], b["set_sha256"], b["count"]],+ ["qA==", ZEROS, EMPTY_SET, 0])++ page = {key: value for key, value in a.items()+ if not key.startswith("image_")}+ page["cond"] = PAGE_COND+ raw = compact(page)+ check("page body of node A after 1.1.0: length", len(raw), PAGE_BODY_LEN)+ check("page body of node A after 1.1.0: sha256", sha256_hex(raw),+ PAGE_BODY_SHA256)+++def check_ops16():+ name = "ops-16.json"+ body, raw = load(name)+ codes = dict(MASKS)["WdlZAA=="]++ check_health(name, body)+ check(f"{name}: mask", body["mask"], mask_encode(codes))+ check(f"{name}: base_seq", body["base_seq"], 0)+ check(f"{name}: last_seq", body["last_seq"],+ sum(1 for code in codes if code))+ check(f"{name}: no operation reached after last_seq",+ any(codes[body["last_seq"]:]), False)+ check(f"{name}: base_root", body["base_root"], ZEROS)+ print(f" {name}: {len(raw)} bytes, sha256 {sha256_hex(raw)}")+++def main():+ tree, _ = load("tree-1.1.0.json")+ bodies = {}++ check_tree(tree)+ check_sets(tree)+ check_masks()+ for release, generation, head_seq in RELEASES:+ for node in NODES:+ bodies[(node, release)] = check_node(tree, node, release,+ generation, head_seq)+ check_final(bodies)+ check_ops16()+ if failures:+ print(f"recompute: {failures} mismatches")+ return 1+ print("recompute: every value recomputes")+ return 0+++if __name__ == "__main__":+ sys.exit(main())diff --git a/testing/fixtures/keepalive/tree-1.1.0.json b/testing/fixtures/keepalive/tree-1.1.0.jsonnew file mode 100644index 00000000..def56e74--- /dev/null+++ b/testing/fixtures/keepalive/tree-1.1.0.json@@ -0,0 +1 @@+{"schema":1,"tree_id":"fleet-base","generation":3,"parent_manifest_digest":"sha256:4ee49208ad87695d862c8cc976d1c910170a3de611cfcee2ce181efd8e0a2942","base":{"seq":0},"operations":[{"seq":1,"op":"add","id":"xfs-fix","selector":{"labels":{"role":["edge"]}},"artifact":{"repository":"oci://registry.example.com/shirudo/fleet-base","manifest_digest":"sha256:98f2c22f02ed3106f44cefae608868f529a38fada82d52a263f230cbda076144","layer_digest":"sha256:9ecc7c28f423abab4de35c3dbcb2af66dd44df59c0dcd52f465f7bc6338772e6","payload_sha256":"sha256:59f8ad56dfc63ce2b91d4b2edd89218694bee7287eaafe06a8624869210cf885"},"fixes":["EXAMPLE-0101"],"operation_digest":"sha256:13b248d4a85d91150717e3e96dc9c2d7a8a43633e3b58f8f6168d408aed26c43"},{"seq":2,"op":"delete","id":"xfs-fix","selector":{"labels":{"role":["edge"]}},"artifact":{"repository":"oci://registry.example.com/shirudo/fleet-base","manifest_digest":"sha256:4d4f3bf9f68bf0dcbd06bffe4aa9eaf83444430e60936b9b2d11ec6229130a1b","layer_digest":"sha256:e80b73d1bf9f8b4d50e5037f317e68bc4c8b15532187b1a3d73b5152a1596c55","payload_sha256":"sha256:f6a8fbb53b29691f47d8e9059a3796ecce2a48e693ec444da690209edef000f1"},"operation_digest":"sha256:5ce215313f29f87bfb87aa0cc65c237bf21bdc7702606e9cc29be187f950074b"},{"seq":3,"op":"add","id":"xfs-fix","selector":{"labels":{"role":["edge"]}},"artifact":{"repository":"oci://registry.example.com/shirudo/fleet-base","manifest_digest":"sha256:b25c835b353ba101d51c4473d602764c2f8746a6e60342bcf49d510a868cb62a","layer_digest":"sha256:653919e8cd88d08fc0d7d3bee8ac27323fadac7ec0a8b8eb6e9dc5a68c36bc97","payload_sha256":"sha256:82db4a710ddb53f6e3e245e01001242cfb2d628e542e9ffefbb343b01c48a7bf"},"fixes":["EXAMPLE-0101"],"operation_digest":"sha256:bd98b27dd5cfc9deeb0e4f49a7d4bd0f991762ec784be9ea838a59966d9dd0dc"}],"head":{"seq":3}}\ No newline at end of filediff --git a/testing/functional/otel/t8007-keepalive-fixtures.sh b/testing/functional/otel/t8007-keepalive-fixtures.shnew file mode 100644index 00000000..8291990f--- /dev/null+++ b/testing/functional/otel/t8007-keepalive-fixtures.sh@@ -0,0 +1,17 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# t8007 -- the keepalive fixtures agree with each other: every digest, root,+# set hash, mask and tree key of testing/fixtures/keepalive/ recomputes from+# the example tree.++cd "$(dirname "$0")/../.."+. ./test-lib.sh+command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"++test_expect_success 'every keepalive fixture value recomputes from the tree' '+ python3 fixtures/keepalive/recompute.py >&2+'++test_done