Skip to content

eBPF-based security platform

tools/xtop: list the shields available to append

John Fastabend1808e278f0ee
diff --git a/Documentation/operate/backend/xtop.rst b/Documentation/operate/backend/xtop.rst
index d605b250..783868fa 100644
--- a/Documentation/operate/backend/xtop.rst
+++ b/Documentation/operate/backend/xtop.rst
@@ -14,7 +14,9 @@ sends :src:`tools/xtop/sql/nodes.sql`, over ``shirudo.node_status``,
``shirudo.latest`` and ``shirudo.node_vulns``, and shows one row per
node, or one per image; Shields sends :src:`tools/xtop/sql/shields.sql`,
over the tree tables, ``shirudo.node_ops`` and ``shirudo.node_vulns``,
-and shows one row per upatch; SBOM sends :src:`tools/xtop/sql/sbom.sql`,
+and shows one row per upatch, or, with
+:src:`tools/xtop/sql/shields-available.sql` over
+``shirudo.shield_catalog``, one per shield available to append; SBOM sends :src:`tools/xtop/sql/sbom.sql`,
over ``shirudo.node_vulns``, and shows one row per finding, or, with
:src:`tools/xtop/sql/sbom-images.sql` over ``shirudo.sbom_images``, one
per image. It only reads: every query is sent with ``readonly=1``. It is a `Bun <https://bun.sh>`_ program built on
@@ -152,8 +154,17 @@ Detector hits are not shown: the collector of
Read the shields
----------------
-Shields has one row per upatch of every tree the tree ingest job loaded
-(:doc:`tree-ingest`), from its newest operation in ``shirudo.tree_ops``.
+Shields has two tabs: ``in trees``, the upatches the trees carry, and
+``available``, the shields published to a registry that a tree can take.
+``t`` switches between them, as does ``k`` past the header to the tabs,
+``h`` or ``l`` and Enter. The tab stays chosen while xtop runs.
+
+In trees
+~~~~~~~~
+
+``in trees`` has one row per upatch of every tree the tree ingest job
+loaded (:doc:`tree-ingest`), from its newest operation in
+``shirudo.tree_ops``.
.. list-table::
:header-rows: 1
@@ -197,6 +208,60 @@ The rollout counts the nodes whose newest record names the tree; a node
that moved to another tree leaves it. Detector hits are not shown,
because the backend takes in no metrics.
+Available
+~~~~~~~~~
+
+``available`` has one row per shield of ``shirudo.shield_catalog``, at
+the version put last, which :src:`tools/put-shields` writes and
+:src:`tools/backend/jobs/shields-put` loads. It lists the shields
+before any tree takes them, so that you can choose which to append.
+
+.. list-table::
+ :header-rows: 1
+
+ * - Column
+ - Value
+ * - ``SEVERITY``
+ - The worst severity of the advisories in the shield's ``fixes``,
+ as ``kernel_vulns`` or ``sbom_vulns`` give it; ``—`` when neither
+ knows them.
+ * - ``SHIELD``
+ - The id of its ``[upatches.tree]`` entry, which a tree operation
+ takes.
+ * - ``FIXES``
+ - The first advisory it fixes, and ``+N`` for the others.
+ * - ``TARGET``
+ - What those advisories are in: ``kernel``, or the packages of an
+ image's SBOM.
+ * - ``EXPOSED``
+ - The most nodes one of those advisories leaves exposed in
+ ``node_vulns`` now, whatever shields them later. A node exposed
+ to two of them counts once.
+ * - ``VERSION``
+ - The version of its package put last.
+ * - ``IN TREES``
+ - The trees whose newest operation of the shield is an ``add``;
+ ``—`` when no tree carries it.
+ * - ``PUT``
+ - How long ago that version was put.
+
+The table sorts by severity, then by the nodes exposed and the id. Enter
+on a shield shows its description, its package and version, the
+reference and manifest digest ``bpm tree append`` takes it by, its
+selector, when it was put and how many versions were, the trees that
+carry it, each advisory with its severity and the nodes it exposes, and
+the command that appends it, with the tree left to fill in:
+
+.. code-block:: none
+
+ shirudo bpm tree append oci://<registry>/<namespace>/<package>:<version> --package-digest sha256:<digest> oci://<registry>/<tree> --tree-id <tree-id>
+
+``/`` searches the id, package, version, reference, selector,
+description, advisories, severities, packages and trees. With no row in
+``shirudo.shield_catalog`` the tab says to run ``make shields`` on the
+local stack (:ref:`local-dev-stack`), or :src:`tools/put-shields` with
+``--catalog`` and then ``shields-put``.
+
Read the SBOM findings
----------------------
diff --git a/tools/xtop/src/App.tsx b/tools/xtop/src/App.tsx
index 177d52e7..9b3ef3a3 100644
--- a/tools/xtop/src/App.tsx
+++ b/tools/xtop/src/App.tsx
@@ -10,14 +10,14 @@ import { useMouse } from "./lib/useMouse.ts";
import { Panel } from "./components/Panel.tsx";
import { Sidebar, type MenuItem } from "./components/Sidebar.tsx";
import { NodesView, type NodesMode } from "./components/NodesView.tsx";
-import { ShieldsView } from "./components/ShieldsView.tsx";
+import { ShieldsView, type ShieldsMode } from "./components/ShieldsView.tsx";
import { SbomView, type SbomMode } from "./components/SbomView.tsx";
type ViewId = "nodes" | "shields" | "sbom";
const MENU: readonly (MenuItem & { id: ViewId; title: string })[] = [
{ id: "nodes", label: "Nodes", title: "nodes · status from shirudo.node_status" },
- { id: "shields", label: "Shields", title: "shields · upatches of the trees in shirudo.tree_ops" },
+ { id: "shields", label: "Shields", title: "shields · in the trees of shirudo.tree_ops, and available in shirudo.shield_catalog" },
{ id: "sbom", label: "SBOM", title: "sbom · findings from shirudo.node_vulns, images from shirudo.sbom_images" },
];
const SIDEBAR_WIDTH = 16;
@@ -28,7 +28,7 @@ const HINTS: Record<Focus, string> = {
menu: "j/k menu · l/enter open · 1 nodes · 2 shields · 3 sbom · q quit",
"menu-open": "j/k menu · l/enter open · tab back to view · esc close view · q quit",
nodes: "j/k scroll · k past top → sort, then tabs · / search · enter node checks, image → nodes · t by image · r refresh · tab menu · esc close · q quit",
- shields: "j/k scroll · k past top → sort · / search · enter details · r refresh · tab menu · esc close · q quit",
+ shields: "j/k scroll · k past top → sort, then tabs · / search · enter details · t trees/available · r refresh · tab menu · esc close · q quit",
sbom: "j/k scroll · k past top → sort, then tabs · / search · enter finding nodes, image → findings · t images · r refresh · tab menu · esc close · q quit",
detail: "esc back · q quit",
search: "regexes, all must match · !re drops matches · enter keep · esc clear",
@@ -45,6 +45,7 @@ export function App({ backend }: { backend: Backend }) {
// Kept while the app runs, so reopening Nodes keeps the toggle.
const [nodesMode, setNodesMode] = useState<NodesMode>("nodes");
const [sbomMode, setSbomMode] = useState<SbomMode>("findings");
+ const [shieldsMode, setShieldsMode] = useState<ShieldsMode>("trees");
const open = (view: ViewId) => {
setMenuCursor(MENU.findIndex((m) => m.id === view));
@@ -150,6 +151,8 @@ export function App({ backend }: { backend: Backend }) {
) : (
<ShieldsView
backend={backend}
+ mode={shieldsMode}
+ onModeChange={setShieldsMode}
height={viewLines}
active={!menuFocused}
onClose={close}
diff --git a/tools/xtop/src/components/AvailableDetail.tsx b/tools/xtop/src/components/AvailableDetail.tsx
new file mode 100644
index 00000000..210ab132
--- /dev/null
+++ b/tools/xtop/src/components/AvailableDetail.tsx
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier: BSD-2-Clause
+// Copyright (c) 2026 Authors of shirudo
+//
+// One shield available to append: where it is, what it fixes, which trees
+// carry it and the command that appends it.
+
+import type { ReactNode } from "react";
+import { Box, Text, useInput } from "ink";
+import { appendCommand, type AvailableShield } from "../lib/shields.ts";
+import { ago } from "../lib/format.ts";
+import { SeverityText } from "./style.tsx";
+
+type Props = {
+ /** null when the shield left shield_catalog since it was opened. */
+ shield: AvailableShield | null;
+ height: number;
+ active: boolean;
+ onClose: () => void;
+};
+
+function Field({ name, children }: { name: string; children: ReactNode }) {
+ return (
+ <Box>
+ <Box width={12} flexShrink={0}>
+ <Text dimColor>{name}</Text>
+ </Box>
+ <Text wrap="truncate-end">{children}</Text>
+ </Box>
+ );
+}
+
+export function AvailableDetail({ shield: s, height, active, onClose }: Props) {
+ useInput(
+ (input, key) => {
+ if (key.escape || key.return || input === "h" || key.leftArrow) onClose();
+ },
+ { isActive: active },
+ );
+
+ if (!s)
+ return (
+ <Box flexDirection="column" height={height}>
+ <Text color="yellow">the shield is no longer in shield_catalog</Text>
+ <Text dimColor>esc back</Text>
+ </Box>
+ );
+
+ return (
+ <Box flexDirection="column" height={height} overflow="hidden">
+ <Box flexDirection="column" flexShrink={0}>
+ <Text>
+ <Text bold>{s.id}</Text>
+ <Text dimColor>
+ {" "}
+ · {s.package} {s.version}
+ </Text>
+ </Text>
+ {s.description && <Text wrap="truncate-end">{s.description}</Text>}
+ <Field name="reference">{s.reference}</Field>
+ <Field name="manifest">sha256:{s.manifestDigest}</Field>
+ <Field name="selector">{s.selector}</Field>
+ <Field name="put">
+ {s.putAt ? `${s.putAt.toLocaleString()} (${ago(s.putAt)} ago)` : "—"}
+ {s.versions > 1 ? `, ${s.versions} versions in all` : ""}
+ </Field>
+ <Field name="in trees">{s.trees.length ? s.trees.join(", ") : <Text dimColor>none</Text>}</Field>
+ <Box marginTop={1} flexDirection="column">
+ <Text dimColor>fixes</Text>
+ {s.advisories.length === 0 && <Text dimColor>no advisory linked</Text>}
+ {s.advisories.map((a) => (
+ <Text key={a.id} wrap="truncate-end">
+ <Text bold>{a.id}</Text> <SeverityText severity={a.severity} />{" "}
+ <Text color={a.source === "kernel" ? "magenta" : "cyan"}>{a.source === "kernel" ? "kernel" : a.package || "?"}</Text>
+ <Text dimColor> · </Text>
+ <Text color={a.exposed ? "yellow" : undefined}>{a.exposed} nodes exposed</Text>
+ </Text>
+ ))}
+ </Box>
+ <Box marginTop={1} flexDirection="column">
+ <Text dimColor>append it with</Text>
+ <Text wrap="wrap">{appendCommand(s)}</Text>
+ </Box>
+ <Box marginTop={1}>
+ <Text dimColor>esc back</Text>
+ </Box>
+ </Box>
+ </Box>
+ );
+}
diff --git a/tools/xtop/src/components/ShieldsView.tsx b/tools/xtop/src/components/ShieldsView.tsx
index 99bd0b88..f00d5075 100644
--- a/tools/xtop/src/components/ShieldsView.tsx
+++ b/tools/xtop/src/components/ShieldsView.tsx
@@ -2,15 +2,19 @@
// Copyright (c) 2026 Authors of shirudo
//
// Every upatch of every tree the backend has loaded, with what it fixes
-// and how its newest operation rolled out. Enter shows one.
+// and how its newest operation rolled out, and every shield published and
+// available to append. Enter shows one.
import { useState } from "react";
import { Box, Text, useInput } from "ink";
import type { ReactNode } from "react";
import type { Backend } from "../lib/backend.ts";
+import { ago } from "../lib/format.ts";
import { useRefreshing } from "../lib/useRefreshing.ts";
import {
SHIELD_STATUS_RANK,
+ type AvailableReport,
+ type AvailableShield,
severityRank,
shieldTarget,
targeted,
@@ -19,14 +23,20 @@ import {
type ShieldStatus,
type ShieldsReport,
} from "../lib/shields.ts";
-import { DataTable, type Column } from "./DataTable.tsx";
+import { DataTable, Tabs, type Column } from "./DataTable.tsx";
import { ViewMessage } from "./ViewMessage.tsx";
import { MiniBar } from "./MiniBar.tsx";
import { ShieldDetail } from "./ShieldDetail.tsx";
+import { AvailableDetail } from "./AvailableDetail.tsx";
import { SHIELD_STATUS_COLOR, SeverityText } from "./style.tsx";
+/** The upatches of the trees, or the shields available to append. */
+export type ShieldsMode = "trees" | "available";
+
type Props = {
backend: Backend;
+ mode: ShieldsMode;
+ onModeChange: (mode: ShieldsMode) => void;
/** Lines available inside the panel. */
height: number;
active: boolean;
@@ -139,13 +149,112 @@ const shieldFields = (s: Shield) =>
// Ties: worst severity first, then name.
const tiebreak = (a: Shield, b: Shield) => severityRank(a.severity) - severityRank(b.severity) || a.id.localeCompare(b.id);
-export function ShieldsView({ backend, height, active, onClose, onSearchingChange, onDetailChange }: Props) {
+// ---- available shields ----------------------------------------------------
+
+const AVAILABLE_COLUMNS: readonly Column<AvailableShield>[] = [
+ {
+ id: "severity",
+ title: "SEVERITY",
+ width: 10,
+ defaultDir: "asc",
+ sortKey: (s) => severityRank(s.severity),
+ render: (s) => <SeverityText severity={s.severity} />,
+ },
+ {
+ id: "name",
+ title: "SHIELD",
+ defaultDir: "asc",
+ sortKey: (s) => s.id,
+ render: (s) => <Text bold>{s.id}</Text>,
+ },
+ {
+ id: "fixes",
+ title: "FIXES",
+ width: 18,
+ defaultDir: "asc",
+ sortKey: (s) => s.advisories.map((a) => a.id).join(" "),
+ render: (s) =>
+ s.advisories.length === 0 ? (
+ <Text dimColor>—</Text>
+ ) : (
+ <>
+ <Text>{s.advisories[0]!.id}</Text>
+ {s.advisories.length > 1 && <Text dimColor> +{s.advisories.length - 1}</Text>}
+ </>
+ ),
+ },
+ {
+ id: "target",
+ title: "TARGET",
+ width: 12,
+ defaultDir: "asc",
+ sortKey: (s) => shieldTarget(s.advisories),
+ render: (s) => {
+ const t = shieldTarget(s.advisories);
+ return t ? <Text color={t === "kernel" ? "magenta" : "cyan"}>{t}</Text> : <Text dimColor>—</Text>;
+ },
+ },
+ {
+ id: "exposed",
+ title: "EXPOSED",
+ width: 8,
+ align: "right",
+ defaultDir: "desc",
+ sortKey: (s) => s.exposed,
+ render: (s) => (s.exposed ? <Text color="yellow">{s.exposed}</Text> : <Text dimColor>0</Text>),
+ },
+ {
+ id: "version",
+ title: "VERSION",
+ width: 16,
+ defaultDir: "desc",
+ sortKey: (s) => s.version,
+ render: (s) => <Text dimColor>{s.version}</Text>,
+ },
+ {
+ id: "trees",
+ title: "IN TREES",
+ width: 16,
+ defaultDir: "desc",
+ sortKey: (s) => s.trees.length,
+ render: (s) => (s.trees.length ? <Text color="green">{s.trees.join(", ")}</Text> : <Text dimColor>—</Text>),
+ },
+ {
+ id: "put",
+ title: "PUT",
+ width: 6,
+ align: "right",
+ defaultDir: "desc",
+ sortKey: (s) => s.putAt?.getTime() ?? 0,
+ render: (s) => (s.putAt ? <Text>{ago(s.putAt)}</Text> : <Text dimColor>—</Text>),
+ },
+];
+
+const availableFields = (s: AvailableShield) =>
+ [
+ s.id,
+ s.package,
+ s.version,
+ s.reference,
+ s.selector,
+ s.description,
+ ...s.advisories.flatMap((a) => [a.id, a.severity, a.package, a.source]),
+ ...s.trees,
+ ];
+
+// Ties: most nodes exposed first, then name.
+const availableTiebreak = (a: AvailableShield, b: AvailableShield) => b.exposed - a.exposed || a.id.localeCompare(b.id);
+
+// ---- view ------------------------------------------------------------------
+
+export function ShieldsView({ backend, mode, onModeChange, height, active, onClose, onSearchingChange, onDetailChange }: Props) {
const [reload, setReload] = useState(0);
- const query = useRefreshing<ShieldsReport>(true, reload, () => backend.getShields());
+ const trees = useRefreshing<ShieldsReport>(mode === "trees", reload, () => backend.getShields());
+ const available = useRefreshing<AvailableReport>(mode === "available", reload, () => backend.getAvailableShields());
const [searching, setSearching] = useState(false);
+ const [onTabs, setOnTabs] = useState(false);
const [detail, setDetail] = useState<string | null>(null);
const keyOf = (s: Shield) => `${s.treeId}\0${s.id}`;
- const detailShield = detail ? (query.data?.shields.find((s) => keyOf(s) === detail) ?? null) : null;
const showDetail = (key: string | null) => {
setDetail(key);
@@ -155,26 +264,93 @@ export function ShieldsView({ backend, height, active, onClose, onSearchingChang
setSearching(s);
onSearchingChange(s);
};
+ const switchTo = (m: ShieldsMode, fromTabs = false) => {
+ setOnTabs(fromTabs);
+ showDetail(null);
+ onModeChange(m);
+ };
+ const modes: ShieldsMode[] = ["trees", "available"];
+ const tabs = {
+ labels: ["in trees", "available"],
+ selected: modes.indexOf(mode),
+ onSelect: (i: number) => switchTo(modes[i]!, true),
+ };
useInput(
(input) => {
+ if (input === "t") switchTo(mode === "trees" ? "available" : "trees");
if (input === "r") setReload((r) => r + 1);
},
{ isActive: active && !searching && !detail },
);
+ const query = mode === "trees" ? trees : available;
const message = (color: string | undefined, text: ReactNode) => (
- <ViewMessage active={active && !searching} onClose={onClose} color={color}>
- {text}
- </ViewMessage>
+ <Box flexDirection="column">
+ <Tabs labels={tabs.labels} selected={tabs.selected} />
+ <ViewMessage active={active && !searching} onClose={onClose} color={color}>
+ {text}
+ </ViewMessage>
+ </Box>
);
if (!query.data)
- return query.error ? message("red", `shields query failed: ${query.error}`) : message(undefined, "querying backend…");
- const report = query.data;
+ return query.error ? message("red", `${mode} query failed: ${query.error}`) : message(undefined, "querying backend…");
+ const tableHeight = Math.max(4, height);
+ const failed = query.error && <Text color="red">refresh failed: {query.error} · </Text>;
+ const status = (generatedAt: Date) => (
+ <>
+ <Text dimColor> · as of {generatedAt.toTimeString().slice(0, 8)}</Text>
+ {query.loading && <Text dimColor> · querying…</Text>}
+ </>
+ );
+
+ if (mode === "available") {
+ const report = available.data!;
+ if (report.shields.length === 0)
+ return message(
+ undefined,
+ "no shield in shirudo.shield_catalog: run make shields, or tools/put-shields --catalog and tools/backend/jobs/shields-put",
+ );
+ const detailShield = detail ? (report.shields.find((s) => s.id === detail) ?? null) : null;
+ return (
+ <Box flexDirection="column">
+ {detail && <AvailableDetail shield={detailShield} height={tableHeight} active={active} onClose={() => showDetail(null)} />}
+ <Box flexDirection="column" display={detail ? "none" : "flex"}>
+ <DataTable
+ tabs={tabs}
+ startOnTabs={onTabs}
+ footerHint="t in trees · r refresh"
+ rows={report.shields}
+ columns={AVAILABLE_COLUMNS}
+ rowKey={(s) => s.id}
+ height={tableHeight}
+ active={active && !detail}
+ initialSort={{ col: "severity", dir: "asc" }}
+ tiebreak={availableTiebreak}
+ searchFields={availableFields}
+ onSearchingChange={reportSearching}
+ onClose={onClose}
+ onOpen={(s) => showDetail(s.id)}
+ summary={(rows, sortedBy) => (
+ <>
+ {failed}
+ <Text bold>{rows.length}</Text> available · <Text color="green">{rows.filter((s) => s.trees.length).length} in a tree</Text> ·{" "}
+ <Text color="yellow">{rows.filter((s) => s.exposed).length} fix exposed nodes</Text>
+ <Text dimColor> · sorted by {sortedBy}</Text>
+ {status(report.generatedAt)}
+ </>
+ )}
+ />
+ </Box>
+ </Box>
+ );
+ }
+
+ const report = trees.data!;
if (report.shields.length === 0)
return message(undefined, "no upatch in shirudo.tree_ops: load a tree with jobs/tree-ingest");
- const tableHeight = Math.max(4, height);
- const trees = new Set(report.shields.map((s) => s.treeId));
+ const detailShield = detail ? (report.shields.find((s) => keyOf(s) === detail) ?? null) : null;
+ const treeIds = new Set(report.shields.map((s) => s.treeId));
return (
<Box flexDirection="column">
@@ -182,6 +358,8 @@ export function ShieldsView({ backend, height, active, onClose, onSearchingChang
{/* Hidden, not unmounted, so the table keeps its cursor, sort and search. */}
<Box flexDirection="column" display={detail ? "none" : "flex"}>
<DataTable
+ tabs={tabs}
+ startOnTabs={onTabs}
rows={report.shields}
columns={COLUMNS}
rowKey={keyOf}
@@ -190,7 +368,7 @@ export function ShieldsView({ backend, height, active, onClose, onSearchingChang
initialSort={{ col: "status", dir: "asc" }}
tiebreak={tiebreak}
searchFields={shieldFields}
- footerHint="r refresh"
+ footerHint="t available · r refresh"
onSearchingChange={reportSearching}
onClose={onClose}
onOpen={(s) => showDetail(keyOf(s))}
@@ -198,15 +376,14 @@ export function ShieldsView({ backend, height, active, onClose, onSearchingChang
const count = (st: ShieldStatus) => rows.filter((s) => s.status === st).length;
return (
<>
- {query.error && <Text color="red">refresh failed: {query.error} · </Text>}
+ {failed}
<Text bold>{rows.length}</Text> shields · <Text color="green">{count("deployed")} deployed</Text> ·{" "}
<Text color="yellow">{count("pending")} pending</Text> · <Text color="gray">{count("withdrawn")} withdrawn</Text>
<Text dimColor>
{" "}
- · {trees.size} tree{trees.size === 1 ? "" : "s"} · sorted by {sortedBy} · as of{" "}
- {report.generatedAt.toTimeString().slice(0, 8)}
+ · {treeIds.size} tree{treeIds.size === 1 ? "" : "s"} · sorted by {sortedBy}
</Text>
- {query.loading && <Text dimColor> · querying…</Text>}
+ {status(report.generatedAt)}
</>
);
}}
diff --git a/tools/xtop/src/lib/backend.ts b/tools/xtop/src/lib/backend.ts
index 8497a106..06798708 100644
--- a/tools/xtop/src/lib/backend.ts
+++ b/tools/xtop/src/lib/backend.ts
@@ -5,6 +5,7 @@
import NODES_SQL from "../../sql/nodes.sql" with { type: "text" };
import SHIELDS_SQL from "../../sql/shields.sql" with { type: "text" };
+import SHIELDS_AVAILABLE_SQL from "../../sql/shields-available.sql" with { type: "text" };
import SBOM_SQL from "../../sql/sbom.sql" with { type: "text" };
import SBOM_IMAGES_SQL from "../../sql/sbom-images.sql" with { type: "text" };
import { queryRows, type ClickHouseConfig } from "./clickhouse.ts";
@@ -19,7 +20,17 @@ import {
type NodeStatus,
type Trust,
} from "./fleet.ts";
-import { shieldStatus, worstSeverity, type Advisory, type Shield, type ShieldsReport } from "./shields.ts";
+import {
+ mostExposed,
+ shieldStatus,
+ worstSeverity,
+ type Advisory,
+ type AvailableAdvisory,
+ type AvailableReport,
+ type AvailableShield,
+ type Shield,
+ type ShieldsReport,
+} from "./shields.ts";
import {
EXPOSURES,
IMAGE_STATES,
@@ -37,6 +48,8 @@ export interface Backend {
getFleet(): Promise<FleetReport>;
/** Every upatch of every tree in shirudo.tree_ops. */
getShields(): Promise<ShieldsReport>;
+ /** The shields of shirudo.shield_catalog, each at the version put last. */
+ getAvailableShields(): Promise<AvailableReport>;
/** Every finding of shirudo.node_vulns, with the nodes it affects. */
getSbom(): Promise<SbomReport>;
/** Every image of shirudo.sbom_images, and those nodes run without an SBOM. */
@@ -188,6 +201,47 @@ export function toShield(r: ShieldRow): Shield {
};
}
+/** A row of sql/shields-available.sql. */
+export type AvailableRow = {
+ id: string;
+ package: string;
+ version: string;
+ reference: string;
+ manifest_digest: string;
+ selector: string;
+ description: string;
+ put_ms: number;
+ versions: number;
+ /** (advisory, severity, package, source, exposed) */
+ advisories: [string, string, string, string, number][];
+ trees: string[];
+};
+
+export function toAvailableShield(r: AvailableRow): AvailableShield {
+ const advisories: AvailableAdvisory[] = r.advisories.map(([id, severity, pkg, source, exposed]) => ({
+ id,
+ severity,
+ package: pkg,
+ source: oneOf<Advisory["source"]>(["kernel", "sbom", ""], source, "advisory source"),
+ exposed,
+ }));
+ return {
+ id: r.id,
+ package: r.package,
+ version: r.version,
+ reference: r.reference,
+ manifestDigest: r.manifest_digest,
+ selector: r.selector,
+ description: r.description,
+ putAt: r.put_ms ? new Date(r.put_ms) : null,
+ versions: r.versions,
+ advisories,
+ trees: r.trees,
+ severity: worstSeverity(advisories),
+ exposed: mostExposed(advisories),
+ };
+}
+
/** A row of sql/sbom.sql. */
export type FindingRow = {
vuln_id: string;
@@ -290,6 +344,11 @@ export class ClickHouseBackend implements Backend {
return { generatedAt: new Date(), shields: rows.map(toShield) };
}
+ async getAvailableShields(): Promise<AvailableReport> {
+ const rows = await queryRows<AvailableRow>(this.cfg, SHIELDS_AVAILABLE_SQL);
+ return { generatedAt: new Date(), shields: rows.map(toAvailableShield) };
+ }
+
async getSbom(): Promise<SbomReport> {
const rows = await queryRows<FindingRow>(this.cfg, SBOM_SQL);
return { generatedAt: new Date(), findings: rows.map(toFinding) };
diff --git a/tools/xtop/src/lib/shields.ts b/tools/xtop/src/lib/shields.ts
index 7f1014cd..847cec46 100644
--- a/tools/xtop/src/lib/shields.ts
+++ b/tools/xtop/src/lib/shields.ts
@@ -92,3 +92,41 @@ export function shieldTarget(advisories: readonly Pick<Advisory, "package" | "so
/** Nodes the newest operation can still apply on: all but those it left out. */
export const targeted = (r: Rollout) => r.nodes - r.notSelected;
+
+// ---- shields available to append -----------------------------------------
+
+/** An advisory an available shield fixes, and the nodes it leaves exposed now. */
+export type AvailableAdvisory = Pick<Advisory, "id" | "severity" | "package" | "source"> & { exposed: number };
+
+/** A shield of shirudo.shield_catalog, at the version put last. */
+export type AvailableShield = {
+ id: string;
+ package: string;
+ version: string;
+ /** oci://<registry>/<repository>:<version>, which bpm tree append takes. */
+ reference: string;
+ /** 64 hex digits, without "sha256:". */
+ manifestDigest: string;
+ selector: string;
+ description: string;
+ putAt: Date | null;
+ /** Versions put of it. */
+ versions: number;
+ advisories: AvailableAdvisory[];
+ /** Trees whose newest operation of it is an add. */
+ trees: string[];
+ /** The worst severity of its advisories, "" when none is known. */
+ severity: string;
+ /** The most nodes one of its advisories leaves exposed: a node exposed to two counts once. */
+ exposed: number;
+};
+
+export type AvailableReport = { generatedAt: Date; shields: AvailableShield[] };
+
+export const mostExposed = (advisories: readonly Pick<AvailableAdvisory, "exposed">[]) =>
+ advisories.reduce((most, a) => Math.max(most, a.exposed), 0);
+
+/** The bpm tree append that takes the shield, less the tree to fill in. */
+export const appendCommand = (s: Pick<AvailableShield, "reference" | "manifestDigest">) =>
+ `shirudo bpm tree append ${s.reference} --package-digest sha256:${s.manifestDigest} ` +
+ "oci://<registry>/<tree> --tree-id <tree-id>";
diff --git a/tools/xtop/test/shields.test.ts b/tools/xtop/test/shields.test.ts
index ddd7df5e..fa0411b9 100644
--- a/tools/xtop/test/shields.test.ts
+++ b/tools/xtop/test/shields.test.ts
@@ -5,8 +5,16 @@
// has them, turned into shields.
import { describe, expect, test } from "bun:test";
-import { toShield, type ShieldRow } from "../src/lib/backend.ts";
-import { severityRank, shieldStatus, shieldTarget, targeted, worstSeverity } from "../src/lib/shields.ts";
+import { toAvailableShield, toShield, type AvailableRow, type ShieldRow } from "../src/lib/backend.ts";
+import {
+ appendCommand,
+ mostExposed,
+ severityRank,
+ shieldStatus,
+ shieldTarget,
+ targeted,
+ worstSeverity,
+} from "../src/lib/shields.ts";
function row(over: Partial<ShieldRow>): ShieldRow {
return {
@@ -116,3 +124,70 @@ describe("helpers", () => {
expect(shieldStatus("delete", r)).toBe("withdrawn");
});
});
+
+function available(over: Partial<AvailableRow>): AvailableRow {
+ return {
+ id: "cve-2026-63984-rpl-detector",
+ package: "cve-2026-63984-rpl-detector",
+ version: "1.0.1795148004",
+ reference: "oci://127.0.0.1:15444/shields/cve-2026-63984-rpl-detector:1.0.1795148004",
+ manifest_digest: "23c4a6dcd8b4796af1e250257037dfbc65ecc6c8fb1dffe8b6491c4937add434",
+ selector: '{"architecture":["x86_64"],"kernel_release_prefix":["7.2"]}',
+ description: "Counts RPL source routing headers whose n + 1 exceeds 127, CVE-2026-63984",
+ put_ms: 1_795_148_004_000,
+ versions: 2,
+ advisories: [["CVE-2026-63984", "HIGH", "linux", "kernel", 3]],
+ trees: [],
+ ...over,
+ };
+}
+
+describe("toAvailableShield", () => {
+ test("keeps where the shield is and what it fixes", () => {
+ const s = toAvailableShield(available({}));
+ expect(s.reference).toBe("oci://127.0.0.1:15444/shields/cve-2026-63984-rpl-detector:1.0.1795148004");
+ expect(s.manifestDigest).toHaveLength(64);
+ expect(s.putAt).toEqual(new Date(1_795_148_004_000));
+ expect(s.versions).toBe(2);
+ expect(s.advisories).toEqual([
+ { id: "CVE-2026-63984", severity: "HIGH", package: "linux", source: "kernel", exposed: 3 },
+ ]);
+ expect(s.severity).toBe("HIGH");
+ expect(s.exposed).toBe(3);
+ expect(s.trees).toEqual([]);
+ });
+
+ test("an unknown advisory has no severity and exposes nobody", () => {
+ const s = toAvailableShield(available({ advisories: [["CVE-1", "", "", "", 0]], trees: ["fleet-base"] }));
+ expect(s.severity).toBe("");
+ expect(s.exposed).toBe(0);
+ expect(s.trees).toEqual(["fleet-base"]);
+ });
+
+ test("a put time that did not join reads as none", () => {
+ expect(toAvailableShield(available({ put_ms: 0 })).putAt).toBeNull();
+ });
+
+ test("refuses an advisory source it does not know", () => {
+ expect(() => toAvailableShield(available({ advisories: [["CVE-1", "HIGH", "x", "nvd", 0]] }))).toThrow(
+ 'unknown advisory source "nvd"',
+ );
+ });
+});
+
+describe("mostExposed", () => {
+ test("a node exposed to two advisories counts once", () => {
+ expect(mostExposed([{ exposed: 3 }, { exposed: 5 }, { exposed: 0 }])).toBe(5);
+ expect(mostExposed([])).toBe(0);
+ });
+});
+
+describe("appendCommand", () => {
+ test("names the package by reference and digest, the tree left to fill in", () => {
+ expect(appendCommand(toAvailableShield(available({})))).toBe(
+ "shirudo bpm tree append oci://127.0.0.1:15444/shields/cve-2026-63984-rpl-detector:1.0.1795148004 " +
+ "--package-digest sha256:23c4a6dcd8b4796af1e250257037dfbc65ecc6c8fb1dffe8b6491c4937add434 " +
+ "oci://<registry>/<tree> --tree-id <tree-id>",
+ );
+ });
+});