eBPF-based security platform
backend: bind a node to the newest build that has an SBOM
John Fastabend8f67baf96eee
diff --git a/Documentation/operate/backend/exposure.rst b/Documentation/operate/backend/exposure.rstindex f9de61a6..c995979b 100644--- a/Documentation/operate/backend/exposure.rst+++ b/Documentation/operate/backend/exposure.rst@@ -173,9 +173,9 @@ from "no data".* - ``declared``- Matched on ``image_id`` and ``image_version`` only, because the node or the image has no root. Root on the node can edit ``os-release``.* - ``root_mismatch``- - Same id and version, another root: a rebuild that kept its version, or a modified image. The rows are those of the newest build; flag them.+ - Same id and version, another root: a rebuild that kept its version, or a modified image. The rows are those of the newest build that has an SBOM; flag them.* - ``no_sbom``- - The node names an image that has no row in ``sbom_images``, or one whose ``state`` is not ``ok``. Kernel rows still appear.+ - The node names an image that has no row in ``sbom_images``, or one whose ``state`` is not ``ok``: the build with the node's own root, or without such a build every build of that id and version. Kernel rows still appear.* - ``no_image``- The node reports no image. Kernel rows still appear.diff --git a/Documentation/operate/backend/tables/vulns.rst b/Documentation/operate/backend/tables/vulns.rstindex d1688569..1a8af158 100644--- a/Documentation/operate/backend/tables/vulns.rst+++ b/Documentation/operate/backend/tables/vulns.rst@@ -54,7 +54,7 @@ shirudo.sbom_images- Only an image with state ok has findings in sbom_vulns.- A node's SBOM is the one with the node's own image_root if present,- else the newest build of that id and version.+ else the newest build of that id and version that has one.:image_id: Image name, e.g. fleet-os.:image_version: e.g. 2026.11.1.diff --git a/tools/backend/sql/50-vulns.sql b/tools/backend/sql/50-vulns.sqlindex f0dd1cdd..1d7d6e1d 100644--- a/tools/backend/sql/50-vulns.sql+++ b/tools/backend/sql/50-vulns.sql@@ -175,7 +175,9 @@ WITHFROM shirudo.latest),-- The SBOM of each node's image: the one with the node's own root- -- when there is one, else the newest build of that id and version.+ -- when there is one, else the newest build of that id and version+ -- that has one: a build whose scan failed does not hide an older+ -- build's findings.img AS(SELECT n.ak_name AS ak_name, i.sbom_sha256 AS sbom_sha256, i.scanned_at AS scanned_at,@@ -189,7 +191,8 @@ WITHFROM node AS nLEFT JOIN shirudo.sbom_images AS i FINALON i.image_id = n.image_id AND i.image_version = n.image_version- ORDER BY n.ak_name, i.image_root = n.image_root DESC, i.built_at DESC, i.image_root+ ORDER BY n.ak_name, i.image_root = n.image_root DESC,+ i.state = 'ok' AND i.sbom_sha256 != '' DESC, i.built_at DESC, i.image_rootLIMIT 1 BY n.ak_name),kmatch ASdiff --git a/tools/backend/test/vulns-cases.expected b/tools/backend/test/vulns-cases.expectedindex 03853c00..91fd5564 100644--- a/tools/backend/test/vulns-cases.expected+++ b/tools/backend/test/vulns-cases.expected@@ -34,6 +34,7 @@ binding-root-mismatch root_mismatch kernel EXAMPLE-0606 linux 7.4.2 exposed_no_build-no-root declared sbom EXAMPLE-0808 curl 8.1-2 exposed_no_shield 0 0 false nonebuild-other-root root_mismatch sbom EXAMPLE-0808 curl 8.1-2 exposed_no_shield 0 0 false nonebuild-own-root verified sbom EXAMPLE-0707 curl 8.1-1 exposed_no_shield 0 0 false none+build-scan-failed no_sbom none unknown 0 0 false nonekernel-fixed verified kernel EXAMPLE-0303 linux 7.4.5 shielded xfs-fix 3 add 3 add true manualkernel-fixed verified kernel EXAMPLE-0606 linux 7.4.5 exposed_no_shield 0 0 false nonekernel-unreadable verified none none 0 0 false none@@ -67,7 +68,7 @@ shield-live-before-withdrawn verified kernel EXAMPLE-0606 linux 7.4.2 exposed_nshield-no-tree verified kernel EXAMPLE-0101 linux 7.4.2 7.4.5 exposed_no_shield 0 0 false noneshield-no-tree verified kernel EXAMPLE-0303 linux 7.4.2 exposed_no_shield 0 0 false noneshield-no-tree verified kernel EXAMPLE-0606 linux 7.4.2 exposed_no_shield 0 0 false none-nodes 29 29+nodes 30 30shielded now, delete comingold-at-1 EXAMPLE-0101 old-fix 1 2shielded now, add comingdiff --git a/tools/backend/test/vulns-cases.sql b/tools/backend/test/vulns-cases.sqlindex b0036857..49884d96 100644--- a/tools/backend/test/vulns-cases.sql+++ b/tools/backend/test/vulns-cases.sql@@ -6,7 +6,9 @@-- binding: a root other than the SBOM's is root_mismatch and keeps its-- rows; an image whose state is not ok, or that has no row, is no_sbom,-- which keeps the kernel rows and is unknown without any. Of two builds--- of one version a node gets its own root's, else the newest one's.+-- of one version a node gets its own root's, else the newest one's that+-- has an SBOM: a newer build whose scan failed is no_sbom only for the+-- node that booted it.-- A package of the kernel and the findings of an older scan are left-- out, and an image without findings gives none.--@@ -105,7 +107,8 @@ SELECT 'fleet-os', '2026.11.4', 'a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3SELECT 'fleet-os', '2026.11.5', 'a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c', 'spdx-json', '', 'unsupported_format', '2026-11-06 08:00:00', '2', at FROM scan UNION ALLSELECT 'fleet-os', '2026.11.6', '6666666666666666666666666666666666666666666666666666666666666666', 'cyclonedx-json', '6666666666666666666666666666666666666666666666666666666666666666', 'ok', '2026-11-07 08:00:00', '2', at FROM scan UNION ALLSELECT 'fleet-os', '2026.11.7', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'cyclonedx-json', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'ok', '2026-11-08 08:00:00', '2', at FROM scan UNION ALL-SELECT 'fleet-os', '2026.11.7', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'cyclonedx-json', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'ok', '2026-11-09 08:00:00', '2', at FROM scan;+SELECT 'fleet-os', '2026.11.7', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'cyclonedx-json', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'ok', '2026-11-09 08:00:00', '2', at FROM scan UNION ALL+SELECT 'fleet-os', '2026.11.7', 'dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', 'cyclonedx-json', '', 'missing', '2026-11-10 08:00:00', '2', at FROM scan;INSERT INTO shirudo.sbom_vulns (sbom_sha256, vuln_id, package, installed, fixed, severity, scanned_at)SELECT '5b0e2c8a4f6d1e3b7a9c0d2e4f6a8b1c3d5e7f9a0b2c4d6e8f1a3b5c7d9e91d4', 'EXAMPLE-0202', 'openssl', '3.5.1-1', '3.5.1-2', 'HIGH', at FROM scan UNION ALLSELECT '5b0e2c8a4f6d1e3b7a9c0d2e4f6a8b1c3d5e7f9a0b2c4d6e8f1a3b5c7d9e91d4', 'EXAMPLE-0101', 'linux-image-7.4.2', '7.4.2-1', '7.4.5-1', 'CRITICAL', at FROM scan UNION ALL@@ -130,6 +133,7 @@ FROM('build-own-root', [('"image_version":"2026.11.1"', '"image_version":"2026.11.7"'), ('"image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c"', '"image_root":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"'), ('"kernel_release":"7.4.2"', '"kernel_release":"6.18.9"')]),('build-other-root', [('"image_version":"2026.11.1"', '"image_version":"2026.11.7"'), ('"image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c"', '"image_root":"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"'), ('"kernel_release":"7.4.2"', '"kernel_release":"6.18.9"')]),('build-no-root', [('"image_version":"2026.11.1"', '"image_version":"2026.11.7"'), ('"image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c"', '"image_root":null'), ('"kernel_release":"7.4.2"', '"kernel_release":"6.18.9"')]),+ ('build-scan-failed', [('"image_version":"2026.11.1"', '"image_version":"2026.11.7"'), ('"image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c"', '"image_root":"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"'), ('"kernel_release":"7.4.2"', '"kernel_release":"6.18.9"')]),('kernel-fixed', [('"image_version":"2026.11.1"', '"image_version":"2026.11.6"'), ('"image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c"', '"image_root":"6666666666666666666666666666666666666666666666666666666666666666"'), ('"kernel_release":"7.4.2"', '"kernel_release":"7.4.5"')]),('kernel-unreadable', [('"image_version":"2026.11.1"', '"image_version":"2026.11.6"'), ('"image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c"', '"image_root":"6666666666666666666666666666666666666666666666666666666666666666"'), ('"kernel_release":"7.4.2"', '"kernel_release":"next-20261111"')]),('old-at-0', [('"image_version":"2026.11.1"', '"image_version":"2026.11.6"'), ('"image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c"', '"image_root":"6666666666666666666666666666666666666666666666666666666666666666"'), ('"tree_id":"fleet-base"', '"tree_id":"fleet-old"'), ('"last_seq":3', '"last_seq":0'), ('"mask":"VA=="', '"mask":"AA=="')]),