eBPF-based security platform
tools: add put-shirudo-build, which allows builds on the backend
John Fastabend96253e509e94
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex f843b8aa..863e3726 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -982,7 +982,8 @@ SBOM put job into a ``file://`` and an ``s3://`` store, again and withanother SBOM, and what it refuses (``test/sbom-put``), the label put joband the labels each node reads from it (``test/labels-put``), theenroll put job, a key bound once and what it refuses-(``test/enroll-put``), and the queries+(``test/enroll-put``), the helper that allows builds+(``test/put-shirudo-build``), and the queriesof :src:`tools/xtop/sql/`, with the names and types of their columns,over nodes healthy, unhealthy, stale and without a tree or an image, atree with one upatch deployed and one still rolling out, and thediff --git a/Documentation/operate/backend/index.rst b/Documentation/operate/backend/index.rstindex eb919e69..9197df00 100644--- a/Documentation/operate/backend/index.rst+++ b/Documentation/operate/backend/index.rst@@ -81,6 +81,9 @@ Files* - :src:`tools/backend/jobs/labels-put`- Loads the labels the operator gives the nodes, out of band(:doc:`labels-put`).+ * - :src:`tools/put-shirudo-build`+ - Allows builds of shirudo, by ``version_id`` or binary, in+ ``shirudo.expected_builds`` (:doc:`maintain`).* - :src:`tools/backend/jobs/enroll-put`- Enrolls the attestation keys a builder created in TPMs, from itsrecords (:doc:`enroll-put`).diff --git a/Documentation/operate/backend/maintain.rst b/Documentation/operate/backend/maintain.rstindex d2c77f5d..246c6da7 100644--- a/Documentation/operate/backend/maintain.rst+++ b/Documentation/operate/backend/maintain.rst@@ -30,6 +30,19 @@ Check 3 fails a node whose ``version_id`` is not listed:INSERT INTO shirudo.expected_builds (version_id, note) VALUES ('<version_id>', 'shirudo 2026.11');+:src:`tools/put-shirudo-build` does the same from the shell, for a+``version_id`` or for the binary itself, whose ``shirudo version+--version-id`` it reads, and leaves a build already allowed as it is:++.. code-block:: console++ $ tools/put-shirudo-build --note 'shirudo 2026.11' /usr/bin/shirudo+ put-shirudo-build: 6e52d48ecbe8cf7e7d54e74460b3c54b3087c3d5e9eceea22644f584b34f73cb: allowed++It runs ``clickhouse-client``, or the command ``CLICKHOUSE_CLIENT``+names, as the jobs do, and exits 1 when an argument is not a build or+the load fails, with nothing loaded, and 2 for wrong usage.+Enroll a node-------------diff --git a/Documentation/operate/backend/tables/reference.rst b/Documentation/operate/backend/tables/reference.rstindex fb530668..144e6a81 100644--- a/Documentation/operate/backend/tables/reference.rst+++ b/Documentation/operate/backend/tables/reference.rst@@ -82,7 +82,7 @@ shirudo.expected_builds.. clickhouse-table:: shirudo.expected_builds:kind: ref- :written-by: the operator+ :written-by: the operator, or tools/put-shirudo-build:row-size: ~100 B (estimate).:scale: Builds you allow.:reference: tens of rows, negligiblediff --git a/tools/backend/test/put-shirudo-build.expected b/tools/backend/test/put-shirudo-build.expectednew file mode 100644index 00000000..b89b153f--- /dev/null+++ b/tools/backend/test/put-shirudo-build.expected@@ -0,0 +1,21 @@+put-shirudo-build: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: allowed+put-shirudo-build: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: allowed+first put: status 0+put-shirudo-build: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: already allowed+put-shirudo-build: cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc: allowed+again: status 0+put-shirudo-build: 000000000000000000000000000000000000000000000000000000000000000 is neither a version_id nor a shirudo binary, nothing loaded+neither: status 1+put-shirudo-build: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA is neither a version_id nor a shirudo binary, nothing loaded+upper: status 1+put-shirudo-build: ./broken does not give a version_id, nothing loaded+no build from it: status 1+put-shirudo-build: the note has a control character, nothing loaded+note with a tab: status 1+usage: put-shirudo-build [--note <text>] <version_id>|<shirudo>...+no build: status 2+usage: put-shirudo-build [--note <text>] <version_id>|<shirudo>...+no argument: status 2+aaaa test-vm build+bbbb test-vm build+ccccdiff --git a/tools/backend/test/put-shirudo-build.sh b/tools/backend/test/put-shirudo-build.shnew file mode 100644index 00000000..cbba288d--- /dev/null+++ b/tools/backend/test/put-shirudo-build.sh@@ -0,0 +1,45 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# tools/put-shirudo-build: allows builds given by version_id and by a+# binary that prints its own, once each; a build already allowed is left+# as it is. Then what it refuses, each with a message and nothing loaded:+# an argument that is neither, a binary that gives no version_id, a note+# with a control character and wrong usage.++set -eu++test=$(cd "$(dirname "$0")" && pwd)+helper=$test/../../put-shirudo-build++work=$(mktemp -d)+trap 'rm -rf "$work"' EXIT++a=$(printf '%064d' 0 | tr 0 a)+b=$(printf '%064d' 0 | tr 0 b)+c=$(printf '%064d' 0 | tr 0 c)++# run <what> <command>...: run a command, then name its status.+run()+{+ what=$1+ shift+ status=0+ "$@" 2>&1 || status=$?+ printf '%s: status %d\n' "$what" "$status"+}++# A shirudo that knows only version --version-id.+printf '#!/bin/sh\n[ "$*" = "version --version-id" ] && echo %s\n' "$b" >"$work/shirudo"+printf '#!/bin/sh\necho not-a-build\n' >"$work/broken"+chmod +x "$work/shirudo" "$work/broken"++run 'first put' "$helper" --note 'test-vm build' "$a" "$work/shirudo" "$a"+run 'again' "$helper" "$a" "$c"+run 'neither' "$helper" "$(printf '%063d' 0)"+run 'upper' "$helper" "$(printf '%064d' 0 | tr 0 A)"+(cd "$work" && run 'no build from it' "$helper" ./broken)+run 'note with a tab' "$helper" --note "$(printf 'a\tb')" "$c"+run 'no build' "$helper" --note x+run 'no argument' "$helper"diff --git a/tools/backend/test/put-shirudo-build.sql b/tools/backend/test/put-shirudo-build.sqlnew file mode 100644index 00000000..955d8bc4--- /dev/null+++ b/tools/backend/test/put-shirudo-build.sql@@ -0,0 +1,8 @@+-- SPDX-License-Identifier: BSD-2-Clause+-- Copyright (c) 2026 Authors of shirudo+--+-- The builds after test/put-shirudo-build.sh: the one given by version_id+-- and the one the binary gave, with the first put's note, and the third+-- from the second put, without one. The refused calls loaded nothing.++SELECT left(version_id, 4), note FROM shirudo.expected_builds FINAL ORDER BY version_id;diff --git a/tools/put-shirudo-build b/tools/put-shirudo-buildnew file mode 100755index 00000000..e6764a9b--- /dev/null+++ b/tools/put-shirudo-build@@ -0,0 +1,113 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# tools/put-shirudo-build -- allow builds of shirudo on the backend: add+# their version_id to shirudo.expected_builds, which check 3 of+# node_status reads.+#+# tools/put-shirudo-build [--note <text>] <version_id>|<shirudo>...+#+# Each argument is a version_id, 64 lowercase hex digits, or a shirudo+# binary, whose shirudo version --version-id gives it. A build already+# allowed is left as it is. --note says what the build is, such as the+# release it came from.+#+# CLICKHOUSE_CLIENT the client command and its options, split at+# spaces. Default: clickhouse-client, which reads+# CLICKHOUSE_HOST, CLICKHOUSE_USER and+# CLICKHOUSE_PASSWORD itself.+#+# Exit status: 0 when every build is allowed; 1 when an argument is not a+# build or the load fails, with nothing loaded; 2 for wrong usage.++set -eu++note=+work=++die()+{+ printf 'put-shirudo-build: %s\n' "$1" >&2+ exit 1+}++usage()+{+ printf '%s\n' 'usage: put-shirudo-build [--note <text>] <version_id>|<shirudo>...' >&2+ exit 2+}++cleanup()+{+ [ -z "$work" ] || rm -rf "$work"+}++client()+{+ # shellcheck disable=SC2086 # a command with its options, to be split+ ${CLICKHOUSE_CLIENT:-clickhouse-client} "$@"+}++is_version_id()+{+ case "$1" in+ *[!0-9a-f]*) return 1 ;;+ esac+ [ "${#1}" -eq 64 ]+}++version_id_of()+{+ if is_version_id "$1"; then+ printf '%s\n' "$1"+ elif [ -f "$1" ] && [ -x "$1" ]; then+ id=$("$1" version --version-id 2>/dev/null) && is_version_id "$id" ||+ die "$1 does not give a version_id, nothing loaded"+ printf '%s\n' "$id"+ else+ die "$1 is neither a version_id nor a shirudo binary, nothing loaded"+ fi+}++if [ "${1:-}" = --note ]; then+ [ $# -ge 2 ] || usage+ note=$2+ shift 2+fi+[ $# -ge 1 ] || usage+case "$1" in+-*) usage ;;+esac+case "$note" in+*[[:cntrl:]]*) die 'the note has a control character, nothing loaded' ;;+esac++trap cleanup EXIT+trap 'exit 1' HUP INT TERM+work=$(mktemp -d)+for build; do+ version_id_of "$build" >>"$work/given"+done+sort -u "$work/given" >"$work/builds"++client --query 'SELECT version_id FROM shirudo.expected_builds FINAL FORMAT TSVRaw' \+ </dev/null >"$work/read" ||+ die 'cannot read shirudo.expected_builds, nothing loaded'+sort -u "$work/read" | comm -23 "$work/builds" - >"$work/new"+# A TSV field takes a backslash as an escape.+escaped=$(printf '%s' "$note" | sed 's/\\/\\\\/g')+while read -r id; do+ printf '%s\t%s\n' "$id" "$escaped"+done <"$work/new" >"$work/rows"+if [ -s "$work/rows" ]; then+ client --query 'INSERT INTO shirudo.expected_builds (version_id, note) FORMAT TSV' \+ <"$work/rows" || die 'cannot insert into shirudo.expected_builds, nothing loaded'+fi+while read -r id; do+ if grep -qx "$id" "$work/new"; then+ printf 'put-shirudo-build: %s: allowed\n' "$id"+ else+ printf 'put-shirudo-build: %s: already allowed\n' "$id"+ fi+done <"$work/builds"