Skip to content

eBPF-based security platform

backend: list the shields pushed as available to append

John Fastabendefb0b01d4675
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index ea8647d1..628853c0 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -985,12 +985,14 @@ another SBOM, and what it refuses (``test/sbom-put``), the label put job
and the labels each node reads from it (``test/labels-put``), the
enroll put job, a key bound once and what it refuses
(``test/enroll-put``), the helper that allows builds
-(``test/put-shirudo-build``), and the queries
+(``test/put-shirudo-build``), the shield put job, a second version of
+a shield and what it refuses (``test/shields-put``), and the queries
of :src:`tools/xtop/sql/`, with the names and types of their columns,
over nodes healthy, unhealthy, stale and without a tree or an image, a
-tree with one upatch deployed and one still rolling out, and the
-findings and images of their SBOMs (``test/xtop-nodes``,
-``test/xtop-shields``, ``test/xtop-sbom``).
+tree with one upatch deployed and one still rolling out, the shields
+available to append beside those trees, and the findings and images of
+their SBOMs (``test/xtop-nodes``, ``test/xtop-shields``,
+``test/shields-put``, ``test/xtop-sbom``).
The unit tests of :src:`tools/xtop/test/` cover how xtop turns the rows
of those queries into nodes, shields, findings and images, the health
diff --git a/Documentation/operate/backend/index.rst b/Documentation/operate/backend/index.rst
index 9197df00..3e764ea2 100644
--- a/Documentation/operate/backend/index.rst
+++ b/Documentation/operate/backend/index.rst
@@ -87,6 +87,9 @@ Files
* - :src:`tools/backend/jobs/enroll-put`
- Enrolls the attestation keys a builder created in TPMs, from its
records (:doc:`enroll-put`).
+ * - :src:`tools/backend/jobs/shields-put`
+ - Loads the shields that :src:`tools/put-shields` pushed, as
+ available to append to a tree (:doc:`shields-put`).
* - :src:`tools/backend/jobs/sbom-put`
- Stores the CycloneDX SBOM of an image in the SBOM store, for an
image pipeline to call (:doc:`sbom-put`).
@@ -113,6 +116,7 @@ Files
sbom-put
labels-put
enroll-put
+ shields-put
maintain
boot-baselines
xtop
diff --git a/Documentation/operate/backend/shields-put.rst b/Documentation/operate/backend/shields-put.rst
new file mode 100644
index 00000000..c782a816
--- /dev/null
+++ b/Documentation/operate/backend/shields-put.rst
@@ -0,0 +1,102 @@
+..
+ SPDX-License-Identifier: BSD-2-Clause
+ Copyright (c) 2026 Authors of shirudo
+
+:page-type: How-to
+:audience: Operators
+
+List the shields available to append
+====================================
+
+The backend learns which upatches a tree carries from the tree itself
+(:doc:`tree-ingest`), but not which shields you have published and could
+append. :src:`tools/backend/jobs/shields-put` loads them into
+``shirudo.shield_catalog`` (:doc:`tables/reference`), where
+:doc:`xtop` lists them as available, with the advisories they fix and the
+nodes those leave exposed. It is POSIX shell around
+``clickhouse-client``, with :src:`tools/backend/jobs/shields-rows.py` to
+read the file, so the host that runs it needs ``python3`` and
+``clickhouse-client``.
+
+1. Push the shields and write their catalog with
+ :src:`tools/put-shields` (:doc:`/upatches/publish/publishing`):
+
+ .. code-block:: console
+
+ operator$ tools/put-shields --version 1.0.0 --keys-dir <keys-dir> \
+ --catalog shields.json oci://<registry>/<namespace>
+
+ The catalog has one entry per ``[upatches.tree]`` entry of a pushed
+ package:
+
+ .. code-block:: json
+
+ {"shields": [
+ {"id": "cve-2026-63984-rpl-detector",
+ "package": "cve-2026-63984-rpl-detector", "version": "1.0.0",
+ "reference": "oci://registry.example.com/shields/cve-2026-63984-rpl-detector:1.0.0",
+ "manifest_digest": "sha256:65fc…",
+ "fixes": ["CVE-2026-63984"],
+ "selector": {"architecture": ["x86_64"], "kernel_release_prefix": ["7.2"]},
+ "description": "Counts RPL source routing headers whose n + 1 exceeds 127, CVE-2026-63984"}
+ ]}
+
+2. Check it, which loads nothing:
+
+ .. code-block:: console
+
+ $ jobs/shields-put --check shields.json
+
+3. Load it:
+
+ .. code-block:: console
+
+ $ jobs/shields-put shields.json
+ shields-put: oci://registry.example.com/shields/cve-2026-63984-rpl-detector:1.0.0 cve-2026-63984-rpl-detector (CVE-2026-63984)
+ shields-put: loaded shields: 1
+
+``-`` in place of the file reads standard input.
+
+What a put does
+---------------
+
+A shield is named by its reference and its ``id``. A put of the same pair
+replaces its row, and every other row stays, so each version you push is
+kept: xtop shows the newest put of each ``id``, and how many versions it
+has. The file is loaded in one insert, whole or not at all.
+
+The job refuses a file, and loads nothing, when it is not the form
+above, or when a value is one ``bpm build`` or ``bpm push`` would not
+have made: an ``id`` that is not an upatch name, a package name or
+version out of their rules (:doc:`/reference/formats/bpm-formats`), a
+digest that is not ``sha256:`` and 64 lowercase hex digits, a reference
+that is not ``oci://<registry>/<repository>:<version>`` of that package
+and version, more than 16 advisories or one out of the ``fixes`` rule
+(:doc:`/reference/formats/beefile`), a selector that is not an object, a
+description of more than 1024 bytes or with a control character, or one
+shield twice.
+
+The catalog is what you say you pushed. The job does not read the
+registry: ``bpm tree append`` verifies the package by its digest when you
+append it, and the target verifies every upatch it loads.
+
+Exit status
+-----------
+
+.. list-table::
+ :header-rows: 1
+ :widths: 15 85
+
+ * - Status
+ - Meaning
+ * - 0
+ - Every shield is loaded, or checked with ``--check``.
+ * - 1
+ - The file is refused or cannot be read, or the load fails.
+ Nothing is loaded.
+ * - 2
+ - Wrong usage.
+
+``CLICKHOUSE_CLIENT`` names the client and its options, split at spaces,
+``clickhouse-client`` by default, which reads ``CLICKHOUSE_HOST``,
+``CLICKHOUSE_USER`` and ``CLICKHOUSE_PASSWORD`` itself.
diff --git a/Documentation/operate/backend/tables/reference.rst b/Documentation/operate/backend/tables/reference.rst
index 144e6a81..91f37519 100644
--- a/Documentation/operate/backend/tables/reference.rst
+++ b/Documentation/operate/backend/tables/reference.rst
@@ -241,6 +241,34 @@ shirudo.label_sets
:labels: The whole set, key to value.
:put_at: When labels-put loaded it; the version ReplacingMergeTree keeps the newest of.
+shirudo.shield_catalog
+----------------------
+
+.. clickhouse-table:: shirudo.shield_catalog
+ :kind: ref
+ :written-by: jobs/shields-put, from what tools/put-shields --catalog wrote
+ :row-size: ~500 B (estimate: a reference, a 64-hex digest, selector JSON).
+ :scale: Every version of every shield pushed. Not per node.
+ :reference: thousands of rows, negligible
+ :bytes: 1000000
+
+ The shields published to a registry, available to append to a tree:
+ one row per [upatches.tree] entry of a pushed package. xtop's shields
+ view lists the newest of each id as available.
+
+ - Read with FINAL: a put of the same reference and id replaces the row.
+ - selector is copied as JSON text and never evaluated, as in tree_ops.
+
+ :reference: The package, oci://<registry>/<repository>:<version>.
+ :id: The upatch, the id of its tree entry.
+ :package: Package name.
+ :version: Package version.
+ :manifest_digest: The package's manifest, 64 lowercase hex digits without sha256:; bpm tree append takes the package by the reference and this digest.
+ :fixes: The advisories of the entry's fixes, in byte order.
+ :selector: The entry's selector as compact JSON.
+ :description: The package's description.
+ :put_at: When shields-put loaded it; the version ReplacingMergeTree keeps the newest of.
+
shirudo.enrollments
-------------------
diff --git a/Documentation/upatches/publish/publishing.rst b/Documentation/upatches/publish/publishing.rst
index 0752ad03..80e5b729 100644
--- a/Documentation/upatches/publish/publishing.rst
+++ b/Documentation/upatches/publish/publishing.rst
@@ -209,6 +209,10 @@ 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.
+``--catalog <file>`` also writes the shields it pushed, with their fixes
+and selectors, for the keepalive backend to list as available
+(:doc:`/operate/backend/shields-put`).
+
Segments and registry retention
-------------------------------
diff --git a/tools/backend/jobs/shields-put b/tools/backend/jobs/shields-put
new file mode 100755
index 00000000..99f9488b
--- /dev/null
+++ b/tools/backend/jobs/shields-put
@@ -0,0 +1,90 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# jobs/shields-put -- load the shields published to a registry into
+# shirudo.shield_catalog, where they show as available to append to a
+# tree.
+#
+# jobs/shields-put [--check] <catalog.json>|-
+#
+# The catalog is what tools/put-shields --catalog writes: one entry per
+# [upatches.tree] entry of a pushed package, with the reference and
+# manifest digest bpm tree append takes the package by. A shield put
+# again under the same reference and id replaces its row; the others
+# stay. The file is loaded whole or not at all. --check reads and checks
+# it, and loads nothing.
+#
+# 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 shield is loaded, or checked with --check; 1
+# when the file is refused or the load fails, with nothing loaded; 2 for
+# wrong usage.
+
+set -eu
+
+here=$(cd "$(dirname "$0")" && pwd)
+check=0
+work=
+
+die()
+{
+ printf 'shields-put: %s\n' "$1" >&2
+ exit 1
+}
+
+usage()
+{
+ printf '%s\n' 'usage: shields-put [--check] <catalog.json>|-' >&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} "$@"
+}
+
+[ "${1:-}" = --check ] && { check=1; shift; }
+[ $# -eq 1 ] || usage
+case "$1" in
+-) ;;
+-*) usage ;;
+esac
+
+trap cleanup EXIT
+trap 'exit 1' HUP INT TERM
+work=$(mktemp -d)
+if [ "$1" = - ]; then
+ cat >"$work/catalog.json"
+else
+ cp "$1" "$work/catalog.json" 2>/dev/null || die "cannot read $1, nothing loaded"
+fi
+
+if [ "$check" -eq 1 ]; then
+ python3 "$here/shields-rows.py" "$work/catalog.json" "$work/rows.jsonl" 0
+ exit
+fi
+
+# Every put gets a time of its own, after every put before it, so that
+# the newest row of a shield is the one ReplacingMergeTree keeps.
+put_at=$(client --query 'SELECT toUnixTimestamp64Milli(greatest(now64(3),
+ (SELECT max(put_at) FROM shirudo.shield_catalog) + toIntervalMillisecond(1)))' \
+ </dev/null) || die 'cannot read shirudo.shield_catalog, nothing loaded'
+python3 "$here/shields-rows.py" "$work/catalog.json" "$work/rows.jsonl" \
+ "$put_at" >"$work/summary" || exit 1
+# One insert, one block: the shields land together or not at all.
+if [ -s "$work/rows.jsonl" ]; then
+ client --query 'INSERT INTO shirudo.shield_catalog FORMAT JSONEachRow' \
+ <"$work/rows.jsonl" || die 'cannot insert into shirudo.shield_catalog, nothing loaded'
+fi
+cat "$work/summary"
+printf 'shields-put: loaded shields: %d\n' "$(wc -l <"$work/rows.jsonl")"
diff --git a/tools/backend/jobs/shields-rows.py b/tools/backend/jobs/shields-rows.py
new file mode 100644
index 00000000..b11a306f
--- /dev/null
+++ b/tools/backend/jobs/shields-rows.py
@@ -0,0 +1,191 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# jobs/shields-rows.py -- the part of jobs/shields-put that shell does not
+# reach: reading and checking the catalog of shields.
+#
+# shields-rows.py <catalog.json> <rows.jsonl> <put_at>
+#
+# Reads {"shields": [{"id": <upatch>, "package": <name>, "version":
+# <version>, "reference": "oci://<registry>/<repository>:<version>",
+# "manifest_digest": "sha256:<hex>", "fixes": [<advisory>, ...],
+# "selector": {...}, "description": <text>}, ...]}, as tools/put-shields
+# --catalog writes it, and writes one row of shirudo.shield_catalog per
+# shield in ClickHouse's JSONEachRow format, with put_at, milliseconds
+# since the epoch, on every row. Prints a line per shield. Each value
+# follows the rule bpm build and bpm push hold it to, so that a row names
+# a package bpm tree append can take.
+#
+# Exit status: 0; 1 when the file is refused, named on standard error,
+# with nothing written; 2 for wrong usage.
+
+import json
+import re
+import sys
+
+PROG = "shields-put"
+# As BPM_BUILD_MAX_FIXES, TREE_STRING_MAX and BPM_FIX_ID_CHARS of
+# tools/shirudo-build/bpm.h, and the name rules of bpm-formats.rst.
+MAX_FIXES = 16
+MAX_TEXT = 255
+MAX_DESCRIPTION = 1024
+UPATCH = re.compile(r"[A-Za-z0-9_-][A-Za-z0-9._-]{0,254}")
+PACKAGE = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]{0,126}")
+VERSION = re.compile(r"[A-Za-z0-9][A-Za-z0-9._+-]{0,126}")
+FIX = re.compile(r"[A-Za-z0-9._:-]{1,255}")
+DIGEST = re.compile(r"sha256:([0-9a-f]{64})")
+REFERENCE = re.compile(r"oci://([A-Za-z0-9.-]+(?::[0-9]{1,5})?)/"
+ r"((?:[A-Za-z0-9._-]+/)*([A-Za-z0-9._-]+)):([^:/]+)")
+CONTROL = re.compile(r"[\x00-\x1f\x7f]")
+KEYS = {"id", "package", "version", "reference", "manifest_digest", "fixes",
+ "selector", "description"}
+
+
+class Refused(Exception):
+ pass
+
+
+def unique_keys(pairs):
+ seen = {}
+ for key, value in pairs:
+ if key in seen:
+ raise Refused('the key "%s" is given twice in one object'
+ % printable(key))
+ seen[key] = value
+ return seen
+
+
+def not_a_number(name):
+ raise Refused("%s is not a JSON number" % name)
+
+
+def printable(text):
+ return "".join(c if c.isprintable() else "?" for c in str(text))
+
+
+def parse(data):
+ try:
+ text = data.decode("utf-8")
+ except UnicodeDecodeError:
+ raise Refused("the file is not UTF-8")
+ decoder = json.JSONDecoder(object_pairs_hook=unique_keys,
+ parse_constant=not_a_number)
+ try:
+ return decoder.decode(text)
+ except (ValueError, RecursionError):
+ raise Refused("the file is not a JSON value")
+
+
+def string(n, entry, key, pattern, form):
+ value = entry.get(key)
+ if type(value) is not str or not pattern.fullmatch(value):
+ raise Refused("shield %d: %s is not %s" % (n, key, form))
+ return value
+
+
+def fixes_of(where, value):
+ if type(value) is not list or len(value) > MAX_FIXES:
+ raise Refused("%s: fixes is not an array of at most %d advisories"
+ % (where, MAX_FIXES))
+ for fix in value:
+ if type(fix) is not str or not FIX.fullmatch(fix):
+ raise Refused("%s: the advisory %s is not 1 to %d bytes of"
+ " letters, digits, ., _, : and -"
+ % (where, printable(fix), MAX_TEXT))
+ if len(set(value)) != len(value):
+ raise Refused("%s: fixes names an advisory twice" % where)
+ return sorted(value)
+
+
+def shield_of(n, entry):
+ if type(entry) is not dict:
+ raise Refused("shield %d is not an object" % n)
+ if set(entry) != KEYS:
+ extra = sorted(set(entry) - KEYS)
+ if extra:
+ raise Refused('shield %d has the key "%s", which a shield does'
+ " not have" % (n, printable(extra[0])))
+ raise Refused("shield %d does not have %s"
+ % (n, ", ".join(sorted(KEYS - set(entry)))))
+ upatch = string(n, entry, "id", UPATCH,
+ "an upatch name: 1 to 255 of letters, digits, ., _"
+ " and -, not starting with .")
+ where = "shield %s" % upatch
+ package = string(n, entry, "package", PACKAGE, "a package name")
+ version = string(n, entry, "version", VERSION, "a package version")
+ digest = string(n, entry, "manifest_digest", DIGEST,
+ "sha256:<64 lowercase hex>")
+ reference = entry["reference"]
+ match = REFERENCE.fullmatch(reference) if type(reference) is str else None
+ if not match or match.group(3) != package or match.group(4) != version:
+ raise Refused("%s: reference is not oci://<registry>/<repository>:"
+ "<version> of package %s at %s"
+ % (where, package, printable(version)))
+ if type(entry["selector"]) is not dict:
+ raise Refused("%s: selector is not an object" % where)
+ description = entry["description"]
+ if (type(description) is not str or CONTROL.search(description)
+ or len(description.encode("utf-8")) > MAX_DESCRIPTION):
+ raise Refused("%s: description is not at most %d bytes of text"
+ " without a control character"
+ % (where, MAX_DESCRIPTION))
+ return {
+ "reference": reference,
+ "id": upatch,
+ "package": package,
+ "version": version,
+ "manifest_digest": DIGEST.fullmatch(digest).group(1),
+ "fixes": fixes_of(where, entry["fixes"]),
+ "selector": json.dumps(entry["selector"], sort_keys=True,
+ ensure_ascii=False, separators=(",", ":")),
+ "description": description,
+ }
+
+
+def shields_of(doc):
+ if type(doc) is not dict or set(doc) != {"shields"}:
+ raise Refused('the file is not an object whose one key is "shields"')
+ if type(doc["shields"]) is not list:
+ raise Refused("shields is not an array")
+ out, seen = [], set()
+ for n, entry in enumerate(doc["shields"], 1):
+ row = shield_of(n, entry)
+ key = (row["reference"], row["id"])
+ if key in seen:
+ raise Refused("shield %s of %s is given twice"
+ % (row["id"], row["reference"]))
+ seen.add(key)
+ out.append(row)
+ return out
+
+
+def main():
+ if len(sys.argv) != 4 or not sys.argv[3].isdigit():
+ print("usage: shields-rows.py <catalog.json> <rows.jsonl> <put_at>",
+ file=sys.stderr)
+ return 2
+ path, rows, put_at = sys.argv[1], sys.argv[2], int(sys.argv[3])
+ try:
+ with open(path, "rb") as f:
+ shields = shields_of(parse(f.read()))
+ except Refused as reason:
+ print("%s: %s, nothing loaded" % (PROG, reason), file=sys.stderr)
+ return 1
+ except OSError as error:
+ print("%s: cannot read %s, nothing loaded"
+ % (PROG, printable(error.filename or path)), file=sys.stderr)
+ return 1
+ with open(rows, "w", encoding="utf-8") as f:
+ for row in shields:
+ f.write(json.dumps(dict(row, put_at=put_at / 1000),
+ ensure_ascii=False, separators=(",", ":")))
+ f.write("\n")
+ for row in shields:
+ fixes = ", ".join(row["fixes"]) or "no advisory"
+ print("%s: %s %s (%s)" % (PROG, row["reference"], row["id"], fixes))
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/tools/backend/sql/20-reference.sql b/tools/backend/sql/20-reference.sql
index c330fd10..e8017537 100644
--- a/tools/backend/sql/20-reference.sql
+++ b/tools/backend/sql/20-reference.sql
@@ -117,6 +117,29 @@ CREATE TABLE IF NOT EXISTS shirudo.label_sets
ENGINE = ReplacingMergeTree(put_at)
ORDER BY (by, node);
+-- The shields published to a registry and available to append to a tree:
+-- one row per [upatches.tree] entry of a pushed package, as jobs/shields-put
+-- loads what tools/put-shields wrote. reference is the package's
+-- oci://<registry>/<repository>:<version> and manifest_digest its manifest,
+-- 64 lowercase hex digits without "sha256:", as tree_ops has them: bpm
+-- tree append takes the package by the two. selector is the entry's
+-- selector as JSON text, copied and never evaluated. A put of the same
+-- reference and id replaces the row. Read it with FINAL.
+CREATE TABLE IF NOT EXISTS shirudo.shield_catalog
+(
+ reference String,
+ id String,
+ package String,
+ version String,
+ manifest_digest String,
+ fixes Array(String),
+ selector String,
+ description String,
+ put_at DateTime64(3) DEFAULT now64(3)
+)
+ENGINE = ReplacingMergeTree(put_at)
+ORDER BY (reference, id);
+
-- The thresholds of the checks, the retention of shirudo.keepalive and
-- shirudo.boot_first and the age at which an SBOM's scan is stale, in one
-- row. Read it with FINAL; to change a value, insert the whole row again
diff --git a/tools/backend/test/schema.expected b/tools/backend/test/schema.expected
index 28b2d091..35d32be2 100644
--- a/tools/backend/test/schema.expected
+++ b/tools/backend/test/schema.expected
@@ -34,6 +34,7 @@ shirudo rejected_mv MaterializedView
shirudo sbom_images ReplacingMergeTree image_id, image_version, image_root
shirudo sbom_vulns MergeTree sbom_sha256, vuln_id, package
shirudo settings ReplacingMergeTree id
+shirudo shield_catalog ReplacingMergeTree reference, id
shirudo tree_ops ReplacingMergeTree tree_id, seq
shirudo tree_pubs ReplacingMergeTree tree_id, generation
shirudo upatch_fixes ReplacingMergeTree tree_id, seq, advisory, source
diff --git a/tools/backend/test/shields-put.expected b/tools/backend/test/shields-put.expected
new file mode 100644
index 00000000..cfed3377
--- /dev/null
+++ b/tools/backend/test/shields-put.expected
@@ -0,0 +1,55 @@
+shields-put: oci://registry.example.com/shields/xfs-fix:1.0.0 xfs-fix (EXAMPLE-0101)
+shields-put: oci://registry.example.com/shields/ssl-fix:1.0.0 ssl-fix (EXAMPLE-0202)
+shields-put: oci://registry.example.com/shields/probe:0.1.0 probe (no advisory)
+shields-put: loaded shields: 3
+first put: status 0
+shields-put: oci://registry.example.com/shields/ssl-fix:1.1.0 ssl-fix (EXAMPLE-0202, EXAMPLE-0303)
+shields-put: loaded shields: 1
+second put: status 0
+shields-put: oci://registry.example.com/shields/xfs-fix:1.0.0 xfs-fix (EXAMPLE-0101)
+shields-put: oci://registry.example.com/shields/ssl-fix:1.0.0 ssl-fix (EXAMPLE-0202)
+shields-put: oci://registry.example.com/shields/probe:0.1.0 probe (no advisory)
+check: status 0
+shields-put: the file is not a JSON value, nothing loaded
+not json: status 1
+shields-put: the file is not an object whose one key is "shields", nothing loaded
+not the form: status 1
+shields-put: shield 1 has the key "extra", which a shield does not have, nothing loaded
+key too many: status 1
+shields-put: shield 1 does not have description, fixes, manifest_digest, package, reference, selector, version, nothing loaded
+key too few: status 1
+shields-put: shield 1: id is not an upatch name: 1 to 255 of letters, digits, ., _ and -, not starting with ., nothing loaded
+dot first: status 1
+shields-put: shield 1: package is not a package name, nothing loaded
+bad package: status 1
+shields-put: shield 1: version is not a package version, nothing loaded
+bad version: status 1
+shields-put: shield 1: manifest_digest is not sha256:<64 lowercase hex>, nothing loaded
+bad digest: status 1
+shields-put: shield a: the advisory A B is not 1 to 255 bytes of letters, digits, ., _, : and -, nothing loaded
+bad advisory: status 1
+shields-put: shield a: fixes names an advisory twice, nothing loaded
+advisory twice: status 1
+shields-put: shield a: reference is not oci://<registry>/<repository>:<version> of package a at 1.0.0, nothing loaded
+other package: status 1
+shields-put: shield a: reference is not oci://<registry>/<repository>:<version> of package a at 1.0.0, nothing loaded
+other version: status 1
+shields-put: shield a: selector is not an object, nothing loaded
+selector not object: status 1
+shields-put: shield a: description is not at most 1024 bytes of text without a control character, nothing loaded
+control in description: status 1
+shields-put: shield a of oci://registry.example.com/shields/a:1.0.0 is given twice, nothing loaded
+twice: status 1
+shields-put: cannot read none.json, nothing loaded
+no file: status 1
+usage: shields-put [--check] <catalog.json>|-
+no argument: status 2
+id package version reference manifest_digest selector description versions advisories trees
+String String String String String String String UInt64 Array(Tuple(String, String, String, String, UInt64)) Array(String)
+probe probe 0.1.0 oci://registry.example.com/shields/probe:0.1.0 0000000000000000000000000000000000000000000000000000000000000003 {} probe at 0.1.0 1 [] []
+ssl-fix ssl-fix 1.1.0 oci://registry.example.com/shields/ssl-fix:1.1.0 0000000000000000000000000000000000000000000000000000000000000004 {} ssl-fix at 1.1.0 2 [('EXAMPLE-0202','HIGH','openssl','sbom',4),('EXAMPLE-0303','','','',0)] ['fleet-base']
+xfs-fix xfs-fix 1.0.0 oci://registry.example.com/shields/xfs-fix:1.0.0 0000000000000000000000000000000000000000000000000000000000000001 {"labels":{"role":["edge"]}} xfs-fix at 1.0.0 1 [('EXAMPLE-0101','CRITICAL','linux','kernel',2)] ['fleet-base']
+oci://registry.example.com/shields/probe:0.1.0 probe probe 0.1.0 0000000000000000000000000000000000000000000000000000000000000003 [] {} probe at 0.1.0
+oci://registry.example.com/shields/ssl-fix:1.0.0 ssl-fix ssl-fix 1.0.0 0000000000000000000000000000000000000000000000000000000000000002 ['EXAMPLE-0202'] {} ssl-fix at 1.0.0
+oci://registry.example.com/shields/ssl-fix:1.1.0 ssl-fix ssl-fix 1.1.0 0000000000000000000000000000000000000000000000000000000000000004 ['EXAMPLE-0202','EXAMPLE-0303'] {} ssl-fix at 1.1.0
+oci://registry.example.com/shields/xfs-fix:1.0.0 xfs-fix xfs-fix 1.0.0 0000000000000000000000000000000000000000000000000000000000000001 ['EXAMPLE-0101'] {"labels":{"role":["edge"]}} xfs-fix at 1.0.0
diff --git a/tools/backend/test/shields-put.setup.sql b/tools/backend/test/shields-put.setup.sql
new file mode 120000
index 00000000..49c04991
--- /dev/null
+++ b/tools/backend/test/shields-put.setup.sql
@@ -0,0 +1 @@
+xtop-nodes.setup.sql
\ No newline at end of file
diff --git a/tools/backend/test/shields-put.sh b/tools/backend/test/shields-put.sh
new file mode 100644
index 00000000..466c1bd1
--- /dev/null
+++ b/tools/backend/test/shields-put.sh
@@ -0,0 +1,91 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# jobs/shields-put over the rows of xtop-nodes.setup.sql: a catalog of
+# three shields loads whole, xfs-fix, which the tree fleet-base carries,
+# ssl-fix and probe, which fixes nothing; a second put from standard
+# input adds ssl-fix at 1.1.0 beside its 1.0.0; --check loads nothing.
+# Then what it refuses, each with a message and nothing loaded: a file
+# that is not JSON or not of the form, a shield with a key too many or
+# too few, a name, version, digest or advisory bpm build or bpm push
+# would refuse, a reference of another package or version, a selector
+# that is not an object, a description with a control character, one
+# shield twice, a missing file and wrong usage. Last, the query the
+# shields view of tools/xtop sends for the available shields, with the
+# names and types of its columns, which the view reads by name, and
+# without the time of the put, which changes from run to run.
+
+set -eu
+
+test=$(cd "$(dirname "$0")" && pwd)
+job=$test/../jobs/shields-put
+query=$test/../../xtop/sql/shields-available.sql
+
+work=$(mktemp -d)
+trap 'rm -rf "$work"' EXIT
+
+# 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"
+}
+
+reg=oci://registry.example.com/shields
+d1=sha256:$(printf '%064d' 1)
+d2=sha256:$(printf '%064d' 2)
+d3=sha256:$(printf '%064d' 3)
+d4=sha256:$(printf '%064d' 4)
+
+# shield <id> <package> <version> <digest> <fixes> [<selector>]
+shield()
+{
+ printf '{"id": "%s", "package": "%s", "version": "%s", "reference": "%s/%s:%s", "manifest_digest": "%s", "fixes": %s, "selector": %s, "description": "%s at %s"}' \
+ "$1" "$2" "$3" "$reg" "$2" "$3" "$4" "$5" "${6:-{\}}" "$1" "$3"
+}
+
+# refused <what> <file content>: the job on that file.
+refused()
+{
+ printf '%s\n' "$2" >"$work/bad.json"
+ run "$1" "$job" "$work/bad.json"
+}
+
+printf '{"shields": [%s, %s, %s]}\n' \
+ "$(shield xfs-fix xfs-fix 1.0.0 "$d1" '["EXAMPLE-0101"]' '{"labels": {"role": ["edge"]}}')" \
+ "$(shield ssl-fix ssl-fix 1.0.0 "$d2" '["EXAMPLE-0202"]')" \
+ "$(shield probe probe 0.1.0 "$d3" '[]')" >"$work/first.json"
+run 'first put' "$job" "$work/first.json"
+printf '{"shields": [%s]}\n' \
+ "$(shield ssl-fix ssl-fix 1.1.0 "$d4" '["EXAMPLE-0202", "EXAMPLE-0303"]')" >"$work/second.json"
+run 'second put' "$job" - <"$work/second.json"
+run 'check' "$job" --check "$work/first.json"
+
+ok=$(shield a a 1.0.0 "$d1" '[]')
+refused 'not json' '{"shields": ['
+refused 'not the form' '{"nodes": []}'
+refused 'key too many' "{\"shields\": [${ok%\}}, \"extra\": 1}]}"
+refused 'key too few' '{"shields": [{"id": "a"}]}'
+refused 'dot first' "{\"shields\": [$(shield .a a 1.0.0 "$d1" '[]')]}"
+refused 'bad package' "{\"shields\": [$(shield a -a 1.0.0 "$d1" '[]')]}"
+refused 'bad version' "{\"shields\": [$(shield a a '1.0 0' "$d1" '[]')]}"
+refused 'bad digest' "{\"shields\": [$(shield a a 1.0.0 sha256:ABC '[]')]}"
+refused 'bad advisory' "{\"shields\": [$(shield a a 1.0.0 "$d1" '["A B"]')]}"
+refused 'advisory twice' "{\"shields\": [$(shield a a 1.0.0 "$d1" '["A", "A"]')]}"
+refused 'other package' "{\"shields\": [$(printf '%s' "$ok" | sed 's|shields/a:|shields/b:|')]}"
+refused 'other version' "{\"shields\": [$(printf '%s' "$ok" | sed 's|a:1.0.0|a:2.0.0|')]}"
+refused 'selector not object' "{\"shields\": [$(shield a a 1.0.0 "$d1" '[]' '[]')]}"
+refused 'control in description' "{\"shields\": [$(printf '%s' "$ok" | sed 's|a at 1.0.0|a\\u0007|')]}"
+refused 'twice' "{\"shields\": [$ok, $ok]}"
+(cd "$work" && run 'no file' "$job" none.json)
+run 'no argument' "$job"
+
+{
+ printf '%s\n' "SELECT * EXCEPT (put_ms) FROM ("
+ sed '/^--/d' "$query"
+ printf '%s\n' ") ORDER BY id FORMAT TSVWithNamesAndTypes"
+} | $CLICKHOUSE_CLIENT
diff --git a/tools/backend/test/shields-put.sql b/tools/backend/test/shields-put.sql
new file mode 100644
index 00000000..b0f5ede9
--- /dev/null
+++ b/tools/backend/test/shields-put.sql
@@ -0,0 +1,11 @@
+-- SPDX-License-Identifier: BSD-2-Clause
+-- Copyright (c) 2026 Authors of shirudo
+--
+-- The catalog after test/shields-put.sh: four rows, ssl-fix at 1.0.0 and
+-- at 1.1.0 beside xfs-fix and probe, with the digests without "sha256:",
+-- the fixes in byte order and the selectors as compact JSON. The refused
+-- files loaded nothing.
+
+SELECT reference, id, package, version, manifest_digest, fixes, selector, description
+FROM shirudo.shield_catalog FINAL
+ORDER BY reference, id;
diff --git a/tools/put-shields b/tools/put-shields
index 1ece5bc2..faddcf76 100755
--- a/tools/put-shields
+++ b/tools/put-shields
@@ -8,7 +8,8 @@
# `shirudo bpm tree append` takes a package by.
#
# tools/put-shields --version <version> [--keys-dir <dir>] [--new-index]
-# oci://<registry>/<namespace> [<beefile>|<dir>...]
+# [--catalog <file>] 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
@@ -23,7 +24,10 @@
#
# 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.
+# reference and manifest digest, less the tree to fill in. --catalog
+# writes the shields pushed, with their fixes and selectors, as
+# jobs/shields-put of tools/backend loads them, so that the backend lists
+# them as available.
#
# SHIRUDO the shirudo binary. Default: shirudo.
# SHIRUDO_KEYS_DIR the keys directory when --keys-dir is not given.
@@ -39,6 +43,7 @@ shirudo=${SHIRUDO:-shirudo}
keys=${SHIRUDO_KEYS_DIR:-}
version=
new_index=
+catalog=
work=
die()
@@ -51,7 +56,7 @@ usage()
{
printf '%s\n' \
'usage: put-shields --version <version> [--keys-dir <dir>] [--new-index]' \
- ' oci://<registry>/<namespace> [<beefile>|<dir>...]' >&2
+ ' [--catalog <file>] oci://<registry>/<namespace> [<beefile>|<dir>...]' >&2
exit 2
}
@@ -92,6 +97,11 @@ while [ $# -gt 0 ]; do
new_index=--new-index
shift
;;
+ --catalog)
+ [ $# -ge 2 ] || usage
+ catalog=$2
+ shift 2
+ ;;
-*) usage ;;
*) break ;;
esac
@@ -139,5 +149,14 @@ while read -r beefile; do
set -- $pushed
printf 'shirudo bpm tree append %s --package-digest %s oci://<registry>/<tree> --tree-id <tree-id>\n' \
"$1" "$2"
+ python3 "$repo/tools/shield-entries.py" "$beefile" "$1" "$2" "$version" \
+ >>"$work/entries" || die "cannot read the tree entries of $beefile"
rm -f "$work/out/$bee"
done <"$work/beefiles"
+if [ -n "$catalog" ]; then
+ {
+ printf '{"shields": [\n'
+ paste -sd, "$work/entries"
+ printf ']}\n'
+ } >"$catalog" || die "cannot write $catalog"
+fi
diff --git a/tools/shield-entries.py b/tools/shield-entries.py
new file mode 100644
index 00000000..d8b9798f
--- /dev/null
+++ b/tools/shield-entries.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# tools/shield-entries.py -- the catalog entries of a pushed package, for
+# tools/put-shields --catalog: one JSON object per line for each
+# [upatches.tree] entry of its Beefile, as jobs/shields-put reads them.
+#
+# shield-entries.py <beefile> <reference> <manifest_digest> <version>
+
+import json
+import sys
+import tomllib
+
+
+def selector_of(table):
+ """The entry's selector as a publication spells it: lists sorted."""
+ out = {}
+ for key, value in table.items():
+ if isinstance(value, dict):
+ out[key] = {k: sorted(v) for k, v in value.items()}
+ else:
+ out[key] = sorted(value)
+ return out
+
+
+def main():
+ if len(sys.argv) != 5:
+ print("usage: shield-entries.py <beefile> <reference>"
+ " <manifest_digest> <version>", file=sys.stderr)
+ return 2
+ path, reference, digest, version = sys.argv[1:]
+ try:
+ with open(path, "rb") as f:
+ beefile = tomllib.load(f)
+ except (OSError, tomllib.TOMLDecodeError) as error:
+ print("put-shields: cannot read %s: %s" % (path, error),
+ file=sys.stderr)
+ return 1
+ package = beefile["package"]
+ for upatch in beefile.get("upatches", []):
+ tree = upatch.get("tree")
+ if not tree:
+ continue
+ print(json.dumps({
+ "id": tree["id"],
+ "package": package["name"],
+ "version": version,
+ "reference": reference,
+ "manifest_digest": digest,
+ "fixes": sorted(tree.get("fixes", [])),
+ "selector": selector_of(tree.get("selector", {})),
+ "description": package.get("description", ""),
+ }, ensure_ascii=False, separators=(",", ":"), sort_keys=True))
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/tools/xtop/sql/shields-available.sql b/tools/xtop/sql/shields-available.sql
new file mode 100644
index 00000000..46bf083f
--- /dev/null
+++ b/tools/xtop/sql/shields-available.sql
@@ -0,0 +1,86 @@
+-- SPDX-License-Identifier: BSD-2-Clause
+-- Copyright (c) 2026 Authors of shirudo
+--
+-- One row per shield of shirudo.shield_catalog for the shields view of
+-- tools/xtop, at the version put last: the reference and manifest digest
+-- bpm tree append takes it by, its selector, the advisories it fixes with
+-- their severity and the nodes they leave exposed, and the trees whose
+-- newest operation of it is an add. Times are epoch milliseconds.
+
+WITH
+newest AS
+(
+ SELECT
+ id,
+ argMax(reference, put_at) AS reference,
+ argMax(package, put_at) AS package,
+ argMax(version, put_at) AS version,
+ argMax(manifest_digest, put_at) AS manifest_digest,
+ argMax(fixes, put_at) AS fixes,
+ argMax(selector, put_at) AS selector,
+ argMax(description, put_at) AS description,
+ max(put_at) AS last_put,
+ count() AS versions
+ FROM shirudo.shield_catalog FINAL
+ GROUP BY id
+),
+in_trees AS
+(
+ SELECT id, arraySort(groupArray(tree_id)) AS trees
+ FROM
+ (
+ SELECT tree_id, id, argMax(op, seq) AS newest_op
+ FROM shirudo.tree_ops FINAL
+ GROUP BY tree_id, id
+ )
+ WHERE newest_op = 'add'
+ GROUP BY id
+),
+known AS
+(
+ SELECT vuln_id, any(severity) AS severity, 'linux' AS package, 'kernel' AS source
+ FROM shirudo.kernel_vulns FINAL
+ GROUP BY vuln_id
+ UNION ALL
+ SELECT vuln_id, any(severity) AS severity, any(package) AS package, 'sbom' AS source
+ FROM shirudo.sbom_vulns
+ GROUP BY vuln_id
+),
+exposure AS
+(
+ SELECT vuln_id, uniqIf(ak_name, exposure NOT IN ('shielded', 'none', 'unknown')) AS exposed
+ FROM shirudo.node_vulns
+ WHERE vuln_id != ''
+ GROUP BY vuln_id
+),
+fixes AS
+(
+ SELECT id, advisory FROM newest ARRAY JOIN fixes AS advisory
+),
+advisories AS
+(
+ SELECT
+ fx.id AS id,
+ arraySort(groupArray(tuple(fx.advisory, ifNull(k.severity, ''), ifNull(k.package, ''),
+ ifNull(k.source, ''), ifNull(e.exposed, 0)))) AS advisories
+ FROM fixes AS fx
+ LEFT JOIN known AS k ON k.vuln_id = fx.advisory
+ LEFT JOIN exposure AS e ON e.vuln_id = fx.advisory
+ GROUP BY id
+)
+SELECT
+ n.id AS id,
+ n.package AS package,
+ n.version AS version,
+ n.reference AS reference,
+ n.manifest_digest AS manifest_digest,
+ n.selector AS selector,
+ n.description AS description,
+ toUnixTimestamp64Milli(n.last_put) AS put_ms,
+ n.versions AS versions,
+ a.advisories AS advisories,
+ t.trees AS trees
+FROM newest AS n
+LEFT JOIN advisories AS a ON a.id = n.id
+LEFT JOIN in_trees AS t ON t.id = n.id
+ORDER BY id