Skip to content

eBPF-based security platform

tools: add put-shields, which publishes every shield to one namespace

John Fastabend6c19c951d2d7
diff --git a/Documentation/contribute/code/developer-guide.rst b/Documentation/contribute/code/developer-guide.rst
index 97e55e0c..350ce0a4 100644
--- a/Documentation/contribute/code/developer-guide.rst
+++ b/Documentation/contribute/code/developer-guide.rst
@@ -411,6 +411,10 @@ Project layout
- The ``vmlinux.h`` generator.
* - :src:`tools/bpf-deps/`
- The script that refreshes :src:`vendor/libbpf`.
+ * - :src:`tools/put-shields`
+ - Builds every shield package under :src:`upatches/` and pushes it
+ to one registry namespace and its index, see
+ :doc:`/upatches/publish/publishing`.
* - :src:`vendor/libbpf/`
- Vendored libbpf and BPF UAPI headers.
* - ``vendor/linux/``
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index f4e81eb1..ea8647d1 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -1280,7 +1280,8 @@ Commands and procedures
- ``status --include-eventlog`` and ``--show-full``.
- ``upatch rewrite-rodata`` in ``shirudo-build``, which
``kernel-obs`` uses to rewrite its watch lists.
-- The ``kernel-cve`` packages. A copy of an earlier Beefile of them is a
+- The ``kernel-cve`` packages, and :src:`tools/put-shields`, which
+ builds and pushes them. A copy of an earlier Beefile of them is a
seed of the ``beefile`` fuzz target.
- The recovery, upgrade and decommissioning procedures of
:doc:`/operate/maintain/backup-recovery` and :doc:`/operate/maintain/upgrade`.
diff --git a/Documentation/upatches/learn/examples.rst b/Documentation/upatches/learn/examples.rst
index 4424aa5f..cee8c8d7 100644
--- a/Documentation/upatches/learn/examples.rst
+++ b/Documentation/upatches/learn/examples.rst
@@ -76,7 +76,9 @@ Each Beefile builds a package named after its detector with one upatch
and one ``[upatches.tree]`` entry of the same name. The entry's
``fixes`` names the detector's CVE, and its selector the kernel of the
manifest: release prefix ``7.2``, its build ID, ``x86_64`` and the
-Kconfig option of the driver or protocol the detector watches.
+Kconfig option of the driver or protocol the detector watches. They are
+the shields :src:`tools/put-shields` publishes, as
+:doc:`/upatches/publish/publishing` shows.
.. list-table::
:header-rows: 1
diff --git a/Documentation/upatches/publish/publishing.rst b/Documentation/upatches/publish/publishing.rst
index 79cb093d..0752ad03 100644
--- a/Documentation/upatches/publish/publishing.rst
+++ b/Documentation/upatches/publish/publishing.rst
@@ -158,6 +158,57 @@ entries selectors that exclude each other, such as different values of
one label, or append the ``delete`` of the earlier upatch first.
:doc:`/reference/cli/bpm` has the exact rule.
+Publish every shield at once
+----------------------------
+
+A shield is a package whose Beefile has an ``[upatches.tree]`` entry,
+one that a tree can take. :src:`tools/put-shields` runs steps 1 and 3
+for every shield of the checkout, so that one namespace lists them all
+before you choose which to append:
+
+.. code-block:: console
+
+ operator$ tools/put-shields --version 1.0.0 --keys-dir <keys-dir> \
+ --new-index oci://<registry>/<namespace> >append.sh
+ put-shields: pushed oci://<registry>/<namespace>/cve-2025-71093-e1000-tbi-detector:1.0.0 sha256:b751…
+ put-shields: pushed oci://<registry>/<namespace>/cve-2026-31675-netem-detector:1.0.0 sha256:f369…
+ put-shields: pushed oci://<registry>/<namespace>/cve-2026-63984-rpl-detector:1.0.0 sha256:23c4…
+
+It builds every ``Beefile`` and ``*.bee`` under :src:`upatches/` that has
+an ``[upatches.tree]`` entry, or, when you name Beefiles and directories
+after the namespace, those Beefiles and the ones under those
+directories, each once, and pushes each package to
+``oci://<registry>/<namespace>/<package>``. Each entry of
+``<namespace>/bpm-index:stable`` then names a shield's repository,
+version and digests. Give ``--new-index`` for a namespace that has no
+index, and a new ``--version`` for every run after the first: ``bpm
+push`` refuses a version the index lists with other content, and a new
+build has other content. ``SHIRUDO`` names the ``shirudo`` binary, and
+the ``BPM_OCI_*`` variables reach the registry as they do for ``bpm
+push``.
+
+Keep the version short. A member path of a package,
+``<package>-<version>/upatches/<upatch>.unload.upatch``, holds at most 99
+bytes, which leaves the kernel-cve detectors 8 characters of version:
+past that, ``bpm build`` fails with ``File name too long``.
+
+It reports each push on standard error and writes to standard output,
+for each shield, the ``tree append`` command that takes it from the
+registry by its reference and manifest digest, with the tree left to
+fill in:
+
+.. code-block:: console
+
+ operator$ cat append.sh
+ shirudo bpm tree append oci://<registry>/<namespace>/cve-2025-71093-e1000-tbi-detector:1.0.0 --package-digest sha256:b751… oci://<registry>/<tree> --tree-id <tree-id>
+ shirudo bpm tree append oci://<registry>/<namespace>/cve-2026-31675-netem-detector:1.0.0 --package-digest sha256:f369… oci://<registry>/<tree> --tree-id <tree-id>
+ shirudo bpm tree append oci://<registry>/<namespace>/cve-2026-63984-rpl-detector:1.0.0 --package-digest sha256:23c4… oci://<registry>/<tree> --tree-id <tree-id>
+
+Run the lines of the shields you choose with your tree's repository and
+id, and ``--keys-dir``. The digest decides which package is appended:
+the registry can point the tag at another package your key signed, and
+``tree append`` refuses one whose manifest has another digest.
+
Segments and registry retention
-------------------------------
diff --git a/tools/put-shields b/tools/put-shields
new file mode 100755
index 00000000..1ece5bc2
--- /dev/null
+++ b/tools/put-shields
@@ -0,0 +1,143 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# tools/put-shields -- build every shield package and push it to one
+# registry namespace, whose signed bpm-index then lists them all: each
+# entry names the repository, version and manifest digest that
+# `shirudo bpm tree append` takes a package by.
+#
+# tools/put-shields --version <version> [--keys-dir <dir>] [--new-index]
+# oci://<registry>/<namespace> [<beefile>|<dir>...]
+#
+# A shield is a package whose Beefile has an [upatches.tree] entry. The
+# Beefiles are the ones given and, for each directory given, every
+# Beefile and *.bee under it that has one; without either, those under
+# upatches/. Each is built with `shirudo bpm build` at
+# <version> and pushed with `shirudo bpm push` to
+# oci://<registry>/<namespace>/<package>, which adds it to
+# <namespace>/bpm-index:stable, signed with the same keys. --new-index
+# starts that index with the first package, for a namespace that never
+# had one. The index lists a name and version once: push the next build
+# under a new version.
+#
+# Each push is reported on standard error, and standard output gets the
+# `shirudo bpm tree append` command that appends that shield by its
+# reference and manifest digest, less the tree to fill in.
+#
+# SHIRUDO the shirudo binary. Default: shirudo.
+# SHIRUDO_KEYS_DIR the keys directory when --keys-dir is not given.
+# BPM_OCI_* registry access, as for shirudo bpm push.
+#
+# Exit status: 0 when every package is pushed; 1 when a build or a push
+# fails, with the packages before it pushed; 2 for wrong usage.
+
+set -eu
+
+repo=$(cd "$(dirname "$0")/.." && pwd)
+shirudo=${SHIRUDO:-shirudo}
+keys=${SHIRUDO_KEYS_DIR:-}
+version=
+new_index=
+work=
+
+die()
+{
+ printf 'put-shields: %s\n' "$1" >&2
+ exit 1
+}
+
+usage()
+{
+ printf '%s\n' \
+ 'usage: put-shields --version <version> [--keys-dir <dir>] [--new-index]' \
+ ' oci://<registry>/<namespace> [<beefile>|<dir>...]' >&2
+ exit 2
+}
+
+cleanup()
+{
+ [ -z "$work" ] || rm -rf "$work"
+}
+
+is_shield()
+{
+ grep -q '^\[upatches\.tree\]' "$1"
+}
+
+# Every Beefile and *.bee under directory $1 with an [upatches.tree] entry.
+shields_under()
+{
+ found=$(find "$1" \( -name Beefile -o -name '*.bee' \) -type f | sort |
+ while read -r beefile; do
+ ! is_shield "$beefile" || realpath "$beefile"
+ done)
+ [ -n "$found" ] || die "no Beefile under $1 has an [upatches.tree] entry"
+ printf '%s\n' "$found"
+}
+
+while [ $# -gt 0 ]; do
+ case "$1" in
+ --version)
+ [ $# -ge 2 ] || usage
+ version=$2
+ shift 2
+ ;;
+ --keys-dir)
+ [ $# -ge 2 ] || usage
+ keys=$2
+ shift 2
+ ;;
+ --new-index)
+ new_index=--new-index
+ shift
+ ;;
+ -*) usage ;;
+ *) break ;;
+ esac
+done
+[ -n "$version" ] && [ $# -ge 1 ] || usage
+[ -n "$keys" ] || keys=/var/lib/shirudo/keys
+case "$1" in
+oci://*/?*) namespace=${1%/} ;;
+*) usage ;;
+esac
+shift
+
+trap cleanup EXIT
+trap 'exit 1' HUP INT TERM
+work=$(mktemp -d)
+[ $# -gt 0 ] || set -- "$repo/upatches"
+for shield; do
+ if [ -d "$shield" ]; then
+ shields_under "$shield"
+ elif [ -f "$shield" ]; then
+ is_shield "$shield" || die "$shield has no [upatches.tree] entry"
+ realpath "$shield"
+ else
+ die "$shield is neither a Beefile nor a directory"
+ fi
+done >"$work/given"
+# A Beefile given twice, or in two directories given, is built once.
+awk '!seen[$0]++' "$work/given" >"$work/beefiles"
+keys=$(realpath "$keys")
+
+mkdir "$work/out"
+while read -r beefile; do
+ built=$(cd "$work/out" && "$shirudo" bpm build "$(dirname "$beefile")" \
+ --file "$beefile" --version "$version" --keys-dir "$keys" </dev/null) ||
+ die "cannot build $beefile"
+ bee=$(basename "$(printf '%s\n' "$built" | tail -n 1)")
+ name=$(basename "$bee" "-$version.bee")
+ # shellcheck disable=SC2086 # --new-index or nothing
+ pushed=$("$shirudo" bpm push "$work/out/$bee" "$namespace/$name" \
+ --keys-dir "$keys" $new_index </dev/null) ||
+ die "cannot push $name $version to $namespace/$name"
+ new_index=
+ printf 'put-shields: pushed %s\n' "$pushed" >&2
+ # shellcheck disable=SC2086 # the reference and its digest, to be split
+ set -- $pushed
+ printf 'shirudo bpm tree append %s --package-digest %s oci://<registry>/<tree> --tree-id <tree-id>\n' \
+ "$1" "$2"
+ rm -f "$work/out/$bee"
+done <"$work/beefiles"