eBPF-based security platform
backend: add the shields query a UI reads
John Fastabend7d3f73cf83cd
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex 689bd4b6..e65b0ce7 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -978,9 +978,11 @@ history it reads, ``node_vulns`` and its inputs, theretention script and the views that keep boot baselines, the treeingest job on a single publication and on a walk over sealed segments,the SBOM scan job on a store that holds an image in every state, and-the query of :src:`tools/xtop/sql/nodes.sql`, with the names and types-of its columns, over nodes healthy, unhealthy, stale and without a tree-or an image (``test/xtop-nodes``).+the queries of :src:`tools/xtop/sql/nodes.sql` and+:src:`tools/xtop/sql/shields.sql`, with the names and types of their+columns, over nodes healthy, unhealthy, stale and without a tree or an+image, and a tree with one upatch deployed and one still rolling out+(``test/xtop-nodes``, ``test/xtop-shields``).The unit tests of :src:`tools/xtop/test/` cover how xtop turns the rowsof that query into nodes, the health percent, the roll-up by image anddiff --git a/tools/backend/test/xtop-nodes.expected b/tools/backend/test/xtop-nodes.expectedindex 87496bd9..5d6ec1a0 100644--- a/tools/backend/test/xtop-nodes.expected+++ b/tools/backend/test/xtop-nodes.expected@@ -1,8 +1,8 @@node_id ak_name host_name status trust failed_check generation last_seq head_seq loaded kernel_release version_id image_id image_version shields_applied shields_pending shields_idle exposed unknown log seen updatedString String String String String UInt8 Nullable(UInt64) Nullable(UInt64) Nullable(UInt64) UInt64 LowCardinality(String) String Nullable(String) Nullable(String) UInt64 UInt64 UInt64 UInt64 UInt64 Array(String) UInt8 UInt8-node-a 000b23602ab98bfb edge-01 healthy untrusted 0 3 3 3 1 7.4.2 d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f fleet-os 2026.11.1 1 0 0 1 0 ['1 signed: pass, untrusted, 0 rejected in the last hour','2 fresh: pass, last record N s ago','3 reported: pass, verdict ok, cond 0x1555, flags 0, tamper +0, build d6d918ad','4 chain: pass, root 15452248','5 head: pass, seq 3 of 3, generation 3','6 set: pass, 1 loaded','7 peers: pass, 2 in group'] 1 1-node-b 000b9d72e08380a1 core-01 healthy untrusted 0 3 3 3 0 7.4.2 d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f fleet-os 2026.11.1 0 0 1 2 0 ['1 signed: pass, untrusted, 0 rejected in the last hour','2 fresh: pass, last record N s ago','3 reported: pass, verdict ok, cond 0x1555, flags 0, tamper +0, build d6d918ad','4 chain: pass, root 00000000','5 head: pass, seq 3 of 3, generation 3','6 set: pass, 0 loaded','7 peers: pass, 2 in group'] 1 1+node-a 000b23602ab98bfb edge-01 healthy untrusted 0 3 3 4 1 7.4.2 d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f fleet-os 2026.11.1 1 1 0 0 0 ['1 signed: pass, untrusted, 0 rejected in the last hour','2 fresh: pass, last record N s ago','3 reported: pass, verdict ok, cond 0x1555, flags 0, tamper +0, build d6d918ad','4 chain: pass, root 15452248','5 head: behind, seq 3 of 4, generation 3','6 set: pass, 1 loaded','7 peers: pass, 2 in group'] 1 1+node-b 000b9d72e08380a1 core-01 healthy untrusted 0 3 3 4 0 7.4.2 d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f fleet-os 2026.11.1 0 1 1 1 0 ['1 signed: pass, untrusted, 0 rejected in the last hour','2 fresh: pass, last record N s ago','3 reported: pass, verdict ok, cond 0x1555, flags 0, tamper +0, build d6d918ad','4 chain: pass, root 00000000','5 head: behind, seq 3 of 4, generation 3','6 set: pass, 0 loaded','7 peers: pass, 2 in group'] 1 1node-c 000b0c lab-01 healthy untrusted 0 \N \N \N 0 7.5.1 d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f \N \N 0 0 0 0 1 ['1 signed: pass, untrusted, 0 rejected in the last hour','2 fresh: pass, last record N s ago','3 reported: pass, verdict ok, cond 0x1555, flags 0, tamper +0, build d6d918ad','4 chain: no tree','5 head: no tree','6 set: no tree','7 peers: no tree'] 1 1-node-d 000b0d edge-02 unhealthy untrusted 3 3 3 3 1 7.4.2 d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f fleet-os 2026.11.1 1 0 0 1 0 ['1 signed: pass, untrusted, 0 rejected in the last hour','2 fresh: pass, last record N s ago','3 reported: FAIL, verdict degraded, cond 0x1555, flags 0, tamper +0, build d6d918ad','4 chain: pass, root 15452248','5 head: pass, seq 3 of 3, generation 3','6 set: pass, 1 loaded','7 peers: pass, 2 in group'] 1 1-node-e 000b0e core-02 stale untrusted 2 3 3 3 0 7.4.2 d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f fleet-os 2026.11.1 0 0 1 2 0 ['1 signed: pass, untrusted, 0 rejected in the last hour','2 fresh: FAIL, last record N s ago','3 reported: pass, verdict ok, cond 0x1555, flags 0, tamper +0, build d6d918ad','4 chain: pass, root 00000000','5 head: pass, seq 3 of 3, generation 3','6 set: pass, 0 loaded','7 peers: pass, 2 in group'] 1 1+node-d 000b0d edge-02 unhealthy untrusted 3 3 3 4 1 7.4.2 d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f fleet-os 2026.11.1 1 1 0 0 0 ['1 signed: pass, untrusted, 0 rejected in the last hour','2 fresh: pass, last record N s ago','3 reported: FAIL, verdict degraded, cond 0x1555, flags 0, tamper +0, build d6d918ad','4 chain: pass, root 15452248','5 head: behind, seq 3 of 4, generation 3','6 set: pass, 1 loaded','7 peers: pass, 2 in group'] 1 1+node-e 000b0e core-02 stale untrusted 2 3 3 4 0 7.4.2 d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f fleet-os 2026.11.1 0 1 1 1 0 ['1 signed: pass, untrusted, 0 rejected in the last hour','2 fresh: FAIL, last record N s ago','3 reported: pass, verdict ok, cond 0x1555, flags 0, tamper +0, build d6d918ad','4 chain: pass, root 00000000','5 head: behind, seq 3 of 4, generation 3','6 set: pass, 0 loaded','7 peers: pass, 2 in group'] 1 1nodes 5diff --git a/tools/backend/test/xtop-nodes.setup.sql b/tools/backend/test/xtop-nodes.setup.sqlindex 003e86c9..90139cfa 100644--- a/tools/backend/test/xtop-nodes.setup.sql+++ b/tools/backend/test/xtop-nodes.setup.sql@@ -5,7 +5,10 @@-- the selector and node C with no image, and two more for the states the-- nodes view of tools/xtop tells apart: node D sends node A's record with-- a verdict that is not ok, so check 3 fails it, and node E sent node--- B's record an hour ago and turns stale.+-- B's record an hour ago and turns stale. Generation 4 of the tree adds+-- ssl-fix for the openssl finding at operation 4, which no node has+-- reached yet: a rollout under way, for the shields view. The test+-- xtop-shields reads the same rows.-- The publication of testing/fixtures/keepalive/tree-1.1.0.json, as the-- ingest job loads it: generation 3 with its three operations.@@ -60,12 +63,23 @@ INSERT INTO shirudo.checked (received, host_name, body, ok, ak_name, ak_public,SELECT now64(3) - INTERVAL 1 HOUR, 'core-02', body, 1, '000b0e', 'QUtF', 3, 3000FROM fixture WHERE name = 'node-b-1.1.0';+-- Generation 4: operation 4 adds ssl-fix for the openssl finding. Its+-- digests are made up; no node reaches it.+INSERT INTO shirudo.tree_pubs (tree_id, generation, manifest_digest, parent_manifest_digest, head_seq, published_at) VALUES+('fleet-base', 4, '7d1e0f2a9b8c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e', '1f327364233e3f2dcebcd13c0af8d84f886201531b135294bd7356a2f7ed680b', 4, now64(3) - INTERVAL 1 MINUTE);+INSERT INTO shirudo.tree_ops (tree_id, seq, op, id, selector, repository, manifest_digest, layer_digest, payload_sha256, operation_digest) VALUES+('fleet-base', 4, 'add', 'ssl-fix', '{}', 'oci://registry.example.com/shirudo/fleet-base', 'c0ffee00c0ffee00c0ffee00c0ffee00c0ffee00c0ffee00c0ffee00c0ffee00', 'c0ffee01c0ffee01c0ffee01c0ffee01c0ffee01c0ffee01c0ffee01c0ffee01', 'c0ffee02c0ffee02c0ffee02c0ffee02c0ffee02c0ffee02c0ffee02c0ffee02', 'c0ffee03c0ffee03c0ffee03c0ffee03c0ffee03c0ffee03c0ffee03c0ffee03');+INSERT INTO shirudo.upatch_fixes (tree_id, seq, id, advisory, source) VALUES+('fleet-base', 4, 'ssl-fix', 'EXAMPLE-0202', 'fixes');+-- The operator's labels, as the page has them.INSERT INTO shirudo.nodes (ak_name, node_id)SELECT record.1, argMinState(record.2, toDateTime64(0, 3))FROM (SELECT arrayJoin([('000b23602ab98bfb', 'node-a'), ('000b9d72e08380a1', 'node-b'), ('000b0c', 'node-c'), ('000b0d', 'node-d'), ('000b0e', 'node-e')]) AS record)GROUP BY record.1;+SYSTEM REFRESH VIEW shirudo.node_ops_mv;+SYSTEM WAIT VIEW shirudo.node_ops_mv;SYSTEM REFRESH VIEW shirudo.node_status_mv;SYSTEM WAIT VIEW shirudo.node_status_mv;SYSTEM REFRESH VIEW shirudo.node_vulns_mv;diff --git a/tools/backend/test/xtop-shields.expected b/tools/backend/test/xtop-shields.expectednew file mode 100644index 00000000..8e24f32e--- /dev/null+++ b/tools/backend/test/xtop-shields.expected@@ -0,0 +1,5 @@+tree_id id seq op add_seq ops manifest_digest repository selector advisories images nodes applied not_selected no_target pending published+String String UInt64 String UInt64 UInt64 String String String Array(Tuple(String, String, String, String, UInt64, UInt64)) Array(String) UInt64 UInt64 UInt64 UInt64 UInt64 UInt8+fleet-base ssl-fix 4 add 4 1 c0ffee00c0ffee00c0ffee00c0ffee00c0ffee00c0ffee00c0ffee00c0ffee00 oci://registry.example.com/shirudo/fleet-base {} [('EXAMPLE-0202','HIGH','openssl','sbom',0,4)] ['fleet-os 2026.11.1'] 4 0 0 0 4 1+fleet-base xfs-fix 3 add 3 3 b25c835b353ba101d51c4473d602764c2f8746a6e60342bcf49d510a868cb62a oci://registry.example.com/shirudo/fleet-base {"labels":{"role":["edge"]}} [('EXAMPLE-0101','CRITICAL','linux','kernel',2,2)] ['fleet-os 2026.11.1'] 4 2 2 0 0 1+shields 2diff --git a/tools/backend/test/xtop-shields.setup.sql b/tools/backend/test/xtop-shields.setup.sqlnew file mode 120000index 00000000..49c04991--- /dev/null+++ b/tools/backend/test/xtop-shields.setup.sql@@ -0,0 +1 @@+xtop-nodes.setup.sql\ No newline at end of filediff --git a/tools/backend/test/xtop-shields.sh b/tools/backend/test/xtop-shields.shnew file mode 100644index 00000000..fa94d1e9--- /dev/null+++ b/tools/backend/test/xtop-shields.sh@@ -0,0 +1,17 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# The query the shields view of tools/xtop sends, over the rows of+# xtop-nodes.setup.sql, with the names and types of its columns, which+# the view reads by name. The publication time changes from run to run+# and is left out.++query=$(dirname "$0")/../../xtop/sql/shields.sql++{+ printf '%s\n' "SELECT * EXCEPT (published_ms), published_ms > 0 AS published"+ printf '%s\n' "FROM ("+ sed '/^--/d' "$query"+ printf '%s\n' ") ORDER BY tree_id, id FORMAT TSVWithNamesAndTypes"+} | $CLICKHOUSE_CLIENTdiff --git a/tools/backend/test/xtop-shields.sql b/tools/backend/test/xtop-shields.sqlnew file mode 100644index 00000000..c0c4e5f7--- /dev/null+++ b/tools/backend/test/xtop-shields.sql@@ -0,0 +1,7 @@+-- SPDX-License-Identifier: BSD-2-Clause+-- Copyright (c) 2026 Authors of shirudo+--+-- Every upatch of every tree is a row of the shields view;+-- xtop-shields.sh prints the rows.++SELECT 'shields', uniqExact(tree_id, id) FROM shirudo.tree_ops FINAL;diff --git a/tools/xtop/sql/shields.sql b/tools/xtop/sql/shields.sqlnew file mode 100644index 00000000..5f8c6edc--- /dev/null+++ b/tools/xtop/sql/shields.sql@@ -0,0 +1,120 @@+-- SPDX-License-Identifier: BSD-2-Clause+-- Copyright (c) 2026 Authors of shirudo+--+-- One row per upatch of every tree for the shields view of tools/xtop:+-- its newest operation, the advisories the newest add of it fixes with+-- their severity and package, the images that carry them, and how the+-- nodes following the tree came out of the newest operation, from their+-- history in node_ops. A node whose record has not reached that+-- operation is pending. Times are epoch milliseconds.++WITH+shields AS+(+ SELECT+ tree_id,+ id,+ max(o.seq) AS newest_seq,+ argMax(o.op, o.seq) AS newest_op,+ maxIf(o.seq, o.op = 'add') AS add_seq,+ count() AS ops,+ argMax(o.manifest_digest, o.seq) AS newest_manifest,+ argMax(o.repository, o.seq) AS newest_repository,+ argMax(o.selector, o.seq) AS newest_selector+ FROM shirudo.tree_ops AS o FINAL+ GROUP BY tree_id, id+),+published AS+(+ SELECT s.tree_id AS tree_id, s.id AS id, min(p.published_at) AS published_at+ FROM shields AS s+ INNER JOIN shirudo.tree_pubs AS p FINAL ON p.tree_id = s.tree_id+ WHERE p.head_seq >= s.newest_seq+ GROUP BY tree_id, id+),+fixes AS+(+ SELECT DISTINCT s.tree_id AS tree_id, s.id AS id, f.advisory AS advisory+ FROM shields AS s+ INNER JOIN shirudo.upatch_fixes AS f FINAL+ ON f.tree_id = s.tree_id AND f.id = s.id AND f.seq = s.add_seq+),+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+ upatch_id,+ vuln_id,+ uniqIf(ak_name, exposure = 'shielded') AS shielded,+ uniqIf(ak_name, exposure NOT IN ('shielded', 'none', 'unknown')) AS exposed,+ arraySort(groupUniqArrayIf(concat(image_id, ' ', image_version), image_id != '')) AS images+ FROM shirudo.node_vulns+ WHERE vuln_id != ''+ GROUP BY upatch_id, vuln_id+),+advisories AS+(+ SELECT+ fx.tree_id AS tree_id,+ fx.id AS id,+ arraySort(groupArray(tuple(fx.advisory, ifNull(k.severity, ''), ifNull(k.package, ''),+ ifNull(k.source, ''), e.shielded, e.exposed))) AS advisories,+ arraySort(arrayDistinct(arrayFlatten(groupArray(e.images)))) AS images+ FROM fixes AS fx+ LEFT JOIN known AS k ON k.vuln_id = fx.advisory+ LEFT JOIN exposure AS e ON e.upatch_id = fx.id AND e.vuln_id = fx.advisory+ GROUP BY tree_id, id+),+history AS+(+ SELECT ak_name, tree_id, seq, code+ FROM shirudo.node_ops FINAL+),+rollout AS+(+ SELECT+ s.tree_id AS tree_id,+ s.id AS id,+ uniq(l.ak_name) AS nodes,+ uniqIf(l.ak_name, h.code = 1) AS applied,+ uniqIf(l.ak_name, h.code = 2) AS not_selected,+ uniqIf(l.ak_name, h.code = 3) AS no_target,+ uniqIf(l.ak_name, ifNull(l.last_seq, 0) < s.newest_seq) AS pending+ FROM shields AS s+ INNER JOIN (SELECT ak_name, assumeNotNull(tree_id) AS tree_id, last_seq+ FROM shirudo.latest WHERE tree_id IS NOT NULL) AS l ON l.tree_id = s.tree_id+ LEFT JOIN history AS h ON h.ak_name = l.ak_name AND h.tree_id = s.tree_id AND h.seq = s.newest_seq+ GROUP BY tree_id, id+)+SELECT+ s.tree_id AS tree_id,+ s.id AS id,+ s.newest_seq AS seq,+ toString(s.newest_op) AS op,+ s.add_seq AS add_seq,+ s.ops AS ops,+ s.newest_manifest AS manifest_digest,+ s.newest_repository AS repository,+ s.newest_selector AS selector,+ toUnixTimestamp64Milli(p.published_at) AS published_ms,+ a.advisories AS advisories,+ a.images AS images,+ r.nodes AS nodes,+ r.applied AS applied,+ r.not_selected AS not_selected,+ r.no_target AS no_target,+ r.pending AS pending+FROM shields AS s+LEFT JOIN published AS p ON p.tree_id = s.tree_id AND p.id = s.id+LEFT JOIN advisories AS a ON a.tree_id = s.tree_id AND a.id = s.id+LEFT JOIN rollout AS r ON r.tree_id = s.tree_id AND r.id = s.id+ORDER BY tree_id, iddiff --git a/tools/xtop/src/components/style.tsx b/tools/xtop/src/components/style.tsxnew file mode 100644index 00000000..6ae872b2--- /dev/null+++ b/tools/xtop/src/components/style.tsx@@ -0,0 +1,34 @@+// SPDX-License-Identifier: BSD-2-Clause+// Copyright (c) 2026 Authors of shirudo++import { Text } from "ink";+import type { NodeStatus } from "../lib/fleet.ts";+import type { ShieldStatus } from "../lib/shields.ts";++export const STATUS_STYLE: Record<NodeStatus, { icon: string; color: string }> = {+ unhealthy: { icon: "✗", color: "red" },+ stale: { icon: "○", color: "gray" },+ healthy: { icon: "●", color: "green" },+};++export const SHIELD_STATUS_COLOR: Record<ShieldStatus, string> = {+ pending: "yellow",+ deployed: "green",+ withdrawn: "gray",+};++export const SEVERITY_COLOR: Record<string, string> = {+ CRITICAL: "red",+ HIGH: "red",+ MEDIUM: "yellow",+ LOW: "gray",+};++export function SeverityText({ severity }: { severity: string }) {+ if (!severity) return <Text dimColor>—</Text>;+ return (+ <Text color={SEVERITY_COLOR[severity.toUpperCase()]} bold={severity.toUpperCase() === "CRITICAL"}>+ {severity.toLowerCase()}+ </Text>+ );+}