Skip to content

eBPF-based security platform

tools/xtop: count a node on a build the SBOM store does not have

John Fastabend4ffff465183b
diff --git a/Documentation/operate/backend/xtop.rst b/Documentation/operate/backend/xtop.rst
index b5786ea1..b9cc4c4b 100644
--- a/Documentation/operate/backend/xtop.rst
+++ b/Documentation/operate/backend/xtop.rst
@@ -347,4 +347,7 @@ is older than ``sbom_stale_seconds``, the nodes that run it, its
findings with how many are critical and high, how long ago it was
scanned and the version of the matcher's database. An image a node runs
that has no SBOM in the store reads ``no_sbom``: store one with
-:doc:`sbom-put`. Enter on an image shows its findings.
+:doc:`sbom-put`. So does a build a node runs whose root the store does
+not have for that id and version, on a row of its own with that root:
+``node_vulns`` binds such a node ``root_mismatch``. Enter on an image
+shows its findings.
diff --git a/tools/backend/test/xtop-sbom.expected b/tools/backend/test/xtop-sbom.expected
index 407ac3de..c886da1a 100644
--- a/tools/backend/test/xtop-sbom.expected
+++ b/tools/backend/test/xtop-sbom.expected
@@ -5,4 +5,8 @@ EXAMPLE-0202 openssl HIGH sbom 3.5.1-2 ['3.5.1-1'] 4 5 ssl-fix 0 4 0 0 0 false [
image_id image_version image_root state sbom_format sbom_sha256 built_ms db_version stale vulns critical high nodes scanned
String String String String String String Int64 String UInt8 UInt64 UInt64 UInt64 UInt64 UInt8
fleet-os 2026.11.1 a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c ok cyclonedx-json 5b0e2c8a4f6d1e3b7a9c0d2e4f6a8b1c3d5e7f9a0b2c4d6e8f1a3b5c7d9e91d4 1793606400000 2 0 1 0 1 4 1
+image_id image_version image_root state nodes
+String String String String UInt64
+fleet-os 2026.11.1 a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c ok 4
+fleet-os 2026.11.1 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb no_sbom 1
findings 2
diff --git a/tools/backend/test/xtop-sbom.sh b/tools/backend/test/xtop-sbom.sh
index d8626aef..ec8c486a 100644
--- a/tools/backend/test/xtop-sbom.sh
+++ b/tools/backend/test/xtop-sbom.sh
@@ -10,16 +10,28 @@
xtop=$(dirname "$0")/../../xtop/sql
-# query <file> <outer select>: run a query of the view inside a select
-# that leaves out what changes.
+# query <file> <outer select> [<order>]: run a query of the view inside a
+# select that leaves out what changes.
query()
{
{
printf '%s\n' "$2 FROM ("
sed '/^--/d' "$xtop/$1"
- printf '%s\n' ") FORMAT TSVWithNamesAndTypes"
+ printf '%s\n' ") ${3:-} FORMAT TSVWithNamesAndTypes"
} | $CLICKHOUSE_CLIENT
}
query sbom.sql 'SELECT *'
query sbom-images.sql 'SELECT * EXCEPT (scanned_ms), scanned_ms > 0 AS scanned'
+
+# A node on a build of that image whose root the store does not have is
+# counted on a no_sbom row of its own, not on the stored build's.
+$CLICKHOUSE_CLIENT --query "INSERT INTO shirudo.checked
+ (host_name, body, ok, ak_name, ak_public, reset_count, clock)
+ SELECT 'edge-03', replaceOne(body,
+ 'a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c',
+ 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'),
+ 1, '000b0f', 'QUtG', 1, 1000
+ FROM shirudo.keepalive FINAL WHERE ak_name = '000b23602ab98bfb'"
+query sbom-images.sql 'SELECT image_id, image_version, image_root, state, nodes' \
+ 'ORDER BY image_root'
diff --git a/tools/xtop/sql/sbom-images.sql b/tools/xtop/sql/sbom-images.sql
index f5470abc..b321049c 100644
--- a/tools/xtop/sql/sbom-images.sql
+++ b/tools/xtop/sql/sbom-images.sql
@@ -5,8 +5,10 @@
-- every image in sbom_images, its findings and the nodes that run it,
-- and, as no_sbom, every image a node runs that sbom_images does not
-- have. A node that reports no image root runs an image of its id and
--- version, as node_vulns reads it. Times are epoch milliseconds; a
--- no_sbom row has 0 for them.
+-- version, as node_vulns reads it; one that reports a root sbom_images
+-- has not for that id and version runs a build of its own, a no_sbom row
+-- with that root, so that every node is counted on a row. Times are
+-- epoch milliseconds; a no_sbom row has 0 for them.
WITH
running AS
@@ -82,6 +84,8 @@ SELECT
toUInt64(0),
uniq(r.ak_name)
FROM running AS r
-LEFT ANTI JOIN images AS i ON i.image_id = r.image_id AND i.image_version = r.image_version
+WHERE (r.image_id, r.image_version, r.image_root) NOT IN (SELECT image_id, image_version, image_root FROM images)
+ AND (r.image_root != ''
+ OR (r.image_id, r.image_version) NOT IN (SELECT image_id, image_version FROM images))
GROUP BY r.image_id, r.image_version, r.image_root
ORDER BY image_id, image_version, image_root