Skip to content

eBPF-based security platform

testing: add make shields, which publishes the shields to the local stack

John Fastabend8bcd82407981
diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rst
index 09fe7af6..8bf5804b 100644
--- a/Documentation/contribute/testing/testing.rst
+++ b/Documentation/contribute/testing/testing.rst
@@ -775,6 +775,48 @@ never updates: run ``trivy image --download-db-only`` first and whenever
you want newer advisories. Run it again to rescan; an image already
stored is left as it is. ``VM_NAME=<name>`` loads that VM's image alone.
+``make shields`` publishes every shield of :src:`upatches/`, the packages
+whose Beefile has an ``[upatches.tree]`` entry, to the stack's registry
+under ``oci://127.0.0.1:15444/shields``, so that xtop's shields view
+lists them as available. It runs :src:`tools/put-shields` with the VM
+bundle's operator key and the ``shirudo`` and ``shirudo-build`` of the
+checkout, then :doc:`/operate/backend/shields-put`, printing each
+command before it runs it:
+
+.. code-block:: console
+
+ $ make shields
+ $ tools/put-shields --version 1.0.1 --keys-dir /tmp/shirudo-test-vm-private-1000/operator-keys/keys --catalog build/test-vm/stack/shields.json --new-index oci://127.0.0.1:15444/shields
+ put-shields: pushed oci://127.0.0.1:15444/shields/cve-2025-71093-e1000-tbi-detector:1.0.1 sha256:1fdb…
+ shirudo bpm tree append oci://127.0.0.1:15444/shields/cve-2025-71093-e1000-tbi-detector:1.0.1 --package-digest sha256:1fdb… oci://<registry>/<tree> --tree-id <tree-id>
+ …
+ $ CLICKHOUSE_CLIENT='docker exec -i shirudo-dev-clickhouse clickhouse-client' tools/backend/jobs/shields-put build/test-vm/stack/shields.json
+ shields-put: oci://127.0.0.1:15444/shields/cve-2025-71093-e1000-tbi-detector:1.0.1 cve-2025-71093-e1000-tbi-detector (CVE-2025-71093)
+ …
+ shields-put: loaded shields: 3
+
+``SHIELDS`` publishes other shields instead: Beefiles, and directories
+in which every ``Beefile`` and ``*.bee`` with an ``[upatches.tree]``
+entry is one, relative to the checkout root unless absolute. Each is
+built where it is, with the ``vmlinux.h`` beside it:
+
+.. code-block:: console
+
+ $ make shields SHIELDS="upatches/kernel-cve/cve-2026-63984-rpl-detector.bee $HOME/my-shields"
+
+Each run pushes the next version, ``1.0.<n>``, counted in
+``build/test-vm/stack/shields-run``, since the index takes a version
+once and a new build is new content; the count goes with the registry at
+``make stack-down``. The first run starts the namespace's index. It needs
+what the other targets make and says which to run when one is missing:
+the operator key of a bundle from ``make vm``, the binaries from
+``make`` and ``make shirudo-build``, and the stack with its backend
+from ``make stack-up``. A stack started before
+``shirudo.shield_catalog`` was added lacks that table until ``make
+telemetry`` loads the schema again. Appending a shield
+to ``shirudo/local-tree`` with the command it prints and that key
+delivers it to the VMs.
+
Without the checker, ``make telemetry`` starts the telemetry stack alone and says so. A
stack started before the checker was built keeps its collector: run
``make stack-down``, which also removes the stack's data, before
diff --git a/Makefile b/Makefile
index 6b662c9a..21da15da 100644
--- a/Makefile
+++ b/Makefile
@@ -89,7 +89,7 @@ help:
'shirudo make targets:' \
' Build: make, make target, make target-deps, make bpf-deps, make install' \
' Operator tools: make shirudo-build, make quote-check' \
- ' Local stack: make stack-up, make oci, make telemetry, make vm, make vm-enroll, make vm-sbom, make xtop, make stack-down' \
+ ' Local stack: make stack-up, make oci, make telemetry, make vm, make vm-enroll, make vm-sbom, make shields, make xtop, make stack-down' \
' Checks: make sparse' \
' Source index: make tags (ctags), make cscope' \
' Install roles: make install-target, make install-operator' \
@@ -196,6 +196,6 @@ distclean: clean
$(Q)rm -rf build/quote-check-deps "$(QUOTE_CHECK_OPENSSL_PREFIX)"
$(Q)$(MAKE) -f Makefile.shirudo distclean
-.PHONY: vm vm-console vm-ssh vm-enroll vm-sbom vm-stop vm-clean oci telemetry stack-up stack-down xtop
-vm vm-console vm-ssh vm-enroll vm-sbom vm-stop vm-clean oci telemetry stack-up stack-down xtop:
+.PHONY: vm vm-console vm-ssh vm-enroll vm-sbom vm-stop vm-clean oci telemetry stack-up stack-down xtop shields
+vm vm-console vm-ssh vm-enroll vm-sbom vm-stop vm-clean oci telemetry stack-up stack-down xtop shields:
+$(Q)$(MAKE) -C testing $@
diff --git a/testing/Makefile b/testing/Makefile
index 2064766d..1f6a0d2a 100644
--- a/testing/Makefile
+++ b/testing/Makefile
@@ -223,6 +223,12 @@ xtop:
+$(Q)$(MAKE) -s -C $(ROOT)/tools/xtop
$(Q)$(ROOT)/testing/vm/stack.sh xtop
+# SHIELDS names Beefiles and directories of them, relative to the checkout
+# root unless absolute; without it, every shield under upatches/.
+shields:
+ $(Q)TEST_VM_HOST_PRIVATE_DIR="$(TEST_VM_HOST_PRIVATE_DIR)" $(ROOT)/testing/vm/stack.sh shields \
+ $(foreach shield,$(SHIELDS),'$(call root-path,$(shield))')
+
define run-target-vm
VM_MODE=$(or $(4),$(if $(filter $(1),$(VM_SERVE_SUITES)),serve,test)) \
TEST_VM_SUITE="$(1)" VM_VERBOSE="$(TEST_VM_VERBOSE)" VM_NAME="$(2)" VM_TENANT="$(VM_TENANT)" \
@@ -421,7 +427,7 @@ clean:
"$(abspath $(TEST_VM_HOST_PRIVATE_DIR))/operator-keys" \
$(ROOT)/build/test-vm/end2end
-.PHONY: oci telemetry stack-up stack-down xtop
+.PHONY: oci telemetry stack-up stack-down xtop shields
stack-up: oci telemetry
oci telemetry:
diff --git a/testing/vm/stack.sh b/testing/vm/stack.sh
index cffe0853..9da476ca 100755
--- a/testing/vm/stack.sh
+++ b/testing/vm/stack.sh
@@ -22,7 +22,7 @@ fi
exec 9>"$W/.lock"
flock 9
case "$TLS_DIR/" in "$REPO/"*) echo 'stack private keys must be outside the checkout' >&2; exit 1 ;; esac
-command=${1:?usage: stack.sh prepare|oci|telemetry|down|enroll|sbom|xtop|vm}
+command=${1:?usage: stack.sh prepare|oci|telemetry|down|enroll|sbom|shields|xtop|vm}
shift
prepare()
{
@@ -110,6 +110,59 @@ sbom)
printf "\$ %s --query '%s'\n" "$client" "$refresh"
$client --query "$refresh" </dev/null
;;
+shields)
+ # Shown before they run, as for enroll: every shield of upatches/
+ # pushed to the stack's registry, at a version of its own for each
+ # run, as bpm push takes a version once, then the catalog of what was
+ # pushed loaded into the backend, where xtop lists the shields as
+ # available. The index of the namespace is started on the first run.
+ # The arguments name Beefiles and directories of them, every shield
+ # under upatches/ when there are none.
+ keys=${TEST_VM_HOST_PRIVATE_DIR:?}/operator-keys/keys
+ [ -s "$keys/signing_key.pem" ] ||
+ { echo "no operator keys in $keys: run make vm first" >&2; exit 1; }
+ for name in registry clickhouse; do
+ [ "$(docker container inspect -f '{{.State.Running}}' "$STACK_NAME-$name" 2>/dev/null)" = true ] ||
+ { echo 'the local stack is not up: run make stack-up' >&2; exit 1; }
+ done
+ stack_clickhouse_client "$STACK_NAME-clickhouse" --query \
+ "SELECT name FROM system.databases WHERE name = 'shirudo'" </dev/null | grep -q . ||
+ { echo 'the stack has no backend: make quote-check, make stack-down, then make telemetry' >&2; exit 1; }
+ stack_clickhouse_client "$STACK_NAME-clickhouse" --query \
+ 'EXISTS TABLE shirudo.shield_catalog' </dev/null | grep -qx 1 ||
+ { echo 'the backend has no shirudo.shield_catalog: run make telemetry, which loads its schema' >&2; exit 1; }
+ for shield; do
+ [ -e "$shield" ] || { echo "no Beefile or directory $shield" >&2; exit 1; }
+ set -- "$@" "$(realpath "$shield")"
+ shift
+ done
+ export SHIRUDO="${SHIRUDO:-$REPO/shirudo}"
+ export SHIRUDO_BUILD="${SHIRUDO_BUILD:-$REPO/tools/shirudo-build/shirudo-build}"
+ [ -x "$SHIRUDO" ] && [ -x "$SHIRUDO_BUILD" ] ||
+ { echo "no $SHIRUDO or $SHIRUDO_BUILD: run make and make shirudo-build" >&2; exit 1; }
+ cd "$REPO"
+ export BPM_OCI_CA_FILE="$W/ca.pem"
+ client="docker exec -i $STACK_NAME-clickhouse clickhouse-client"
+ catalog=$(realpath --relative-to="$REPO" "$W/shields.json")
+ # A package's member paths must fit in 99 bytes, which a long version
+ # breaks, so the version counts the runs. The count is kept beside the
+ # registry and goes with it, and is taken before the push, so that a
+ # run that fails part way never reuses the version it pushed.
+ run=$(($(cat "$W/shields-run" 2>/dev/null || echo 0) + 1))
+ printf '%d\n' "$run" >"$W/shields-run"
+ new_index=
+ curl -sf --cacert "$W/ca.pem" -o /dev/null \
+ -H 'Accept: application/vnd.oci.image.manifest.v1+json' \
+ "https://$REGISTRY/v2/shields/bpm-index/manifests/stable" ||
+ new_index=--new-index
+ # shellcheck disable=SC2086 # --new-index or nothing
+ set -- --version "1.0.$run" --keys-dir "$keys" --catalog "$catalog" \
+ $new_index "oci://$REGISTRY/shields" "$@"
+ printf '$ tools/put-shields %s\n' "$*"
+ tools/put-shields "$@"
+ printf "\$ CLICKHOUSE_CLIENT='%s' tools/backend/jobs/shields-put %s\n" "$client" "$catalog"
+ CLICKHOUSE_CLIENT=$client tools/backend/jobs/shields-put "$catalog"
+ ;;
vm)
prepare
export TEST_VM_LOCAL_STACK=1