eBPF-based security platform
tools/xtop: show where each label came from and its conflicts
John Fastabend0f9e05c2e329
diff --git a/Documentation/operate/backend/xtop.rst b/Documentation/operate/backend/xtop.rstindex 91c987b3..a44b69f3 100644--- a/Documentation/operate/backend/xtop.rst+++ b/Documentation/operate/backend/xtop.rst@@ -83,7 +83,9 @@ key the operator has recorded as a TPM's.* - ``LABELS``- The labels from ``shirudo.node_labels``, as ``key=value`` in keyorder: what :doc:`labels-put` loaded, not the node's own- ``node.labels``; ``—`` when none was put.+ ``node.labels``; ``—`` when none was put. ``!N`` before them+ counts the keys whose sets disagree, from+ ``shirudo.label_conflicts``.* - ``CHECK``- The first check that failed, as its line names it, for example``3 reported``; ``—`` when all passed.@@ -112,12 +114,14 @@ The summary line gives the health of the nodes shown: the percent ofthem ``healthy``, so 100% when every node is healthy and 0% when noneis. A stale node counts against it like an unhealthy one.-Enter on a node shows its host name, key, labels and the name they were-put under, ``ak_name``, ``node_id`` or ``config_root``, what its record-says it runs, and the seven lines of its ``log``, a failed one in red;-Esc returns. ``/`` searches the node, host and key names, status, trust,-image, kernel, build, the line of the failed check and each label as-``key=value``, so ``role=edge`` finds the nodes of that role.+Enter on a node shows its host name, key, labels with the name each was+put under, ``ak_name``, ``node_id`` or ``config_root``, a line per+conflict with the values it overrode, what its record says it runs, and+the seven lines of its ``log``, a failed one in red; Esc returns. ``/``+searches the node, host and key names, status, trust, image, kernel,+build, the line of the failed check and each label as ``key=value``, so+``role=edge`` finds the nodes of that role, and ``label conflict`` finds+the nodes with one.``t`` switches to one row per image id and version, with the ``role``labels of its members beside it, ``?`` for a member without one. Adiff --git a/tools/backend/test/xtop-nodes.expected b/tools/backend/test/xtop-nodes.expectedindex a379f749..9b4f3500 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 labels labels_by log seen updated-String String String String String UInt8 Nullable(UInt64) Nullable(UInt64) Nullable(UInt64) UInt64 LowCardinality(String) String Nullable(String) Nullable(String) UInt64 UInt64 UInt64 UInt64 UInt64 Map(String, String) String Array(String) UInt8 UInt8-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 {'role':'edge','site':'fra'} node_id ['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 {'role':'core'} ak_name ['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 1-node-c 000b0c lab-01 healthy untrusted 0 \N \N \N 0 7.5.1 d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f \N \N 0 0 0 0 1 {} none ['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 4 1 7.4.2 d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f fleet-os 2026.11.1 1 1 0 0 0 {'role':'edge','site':'ams'} node_id ['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 {} none ['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 1+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 labels label_sources label_conflicts log seen updated+String String String String String UInt8 Nullable(UInt64) Nullable(UInt64) Nullable(UInt64) UInt64 LowCardinality(String) String Nullable(String) Nullable(String) UInt64 UInt64 UInt64 UInt64 UInt64 Map(String, String) Map(String, String) Array(Tuple(String, String, String, Array(Tuple(UInt8, String, String)))) Array(String) UInt8 UInt8+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 {'image':'base','role':'edge','site':'fra'} {'image':'config_root','role':'node_id','site':'node_id'} [('role','edge','node_id',[(2,'node_id','edge'),(1,'config_root','lab')])] ['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 {'role':'core'} {'role':'ak_name'} [] ['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 1+node-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 4 1 7.4.2 d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f fleet-os 2026.11.1 1 1 0 0 0 {'image':'base','role':'edge','site':'ams'} {'image':'config_root','role':'node_id','site':'node_id'} [('role','edge','node_id',[(2,'node_id','edge'),(1,'config_root','lab')])] ['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 0cdf34cd..76fc3e31 100644--- a/tools/backend/test/xtop-nodes.setup.sql+++ b/tools/backend/test/xtop-nodes.setup.sql@@ -8,8 +8,9 @@-- 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 operator--- labels node A and node D by node_id and node B by its key, as--- jobs/labels-put loads them. The tests xtop-shields and xtop-sbom read+-- labels node A and node D by node_id, node B by its key and the config+-- image node A and node D booted by its root, as jobs/labels-put loads+-- them; that image's role=lab loses to their role=edge. The tests xtop-shields and xtop-sbom read-- the same rows.-- The publication of testing/fixtures/keepalive/tree-1.1.0.json, as the@@ -77,7 +78,8 @@ INSERT INTO shirudo.upatch_fixes (tree_id, seq, id, advisory, source) VALUESINSERT INTO shirudo.label_sets (by, node, labels) VALUES('node_id', 'node-a', {'role': 'edge', 'site': 'fra'}),('node_id', 'node-d', {'role': 'edge', 'site': 'ams'}),-('ak_name', '000b9d72e08380a1', {'role': 'core'});+('ak_name', '000b9d72e08380a1', {'role': 'core'}),+('config_root', '1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807', {'role': 'lab', 'image': 'base'});-- The operator's labels, as the page has them.INSERT INTO shirudo.nodes (ak_name, node_id)diff --git a/tools/xtop/sql/nodes.sql b/tools/xtop/sql/nodes.sqlindex 05c291e0..153dc0fd 100644--- a/tools/xtop/sql/nodes.sql+++ b/tools/xtop/sql/nodes.sql@@ -3,11 +3,19 @@---- One row per node for the nodes view of tools/xtop: the outcome of the-- checks from node_status, what the newest record says it runs from--- latest, the labels the operator gave it from node_labels, and per node--- the counts of node_vulns. Times are epoch milliseconds, so that no+-- latest, the labels the operator gave it from node_labels with the keys+-- whose sets disagree from label_conflicts, and per node the counts of+-- node_vulns. Times are epoch milliseconds, so that no-- client reads them in the server's time zone.-WITH vulns AS+WITH+conflicts AS+(+ SELECT c.ak_name AS ak_name, arraySort(groupArray(tuple(c.key, c.value, c.by, c.given))) AS conflicts+ FROM shirudo.label_conflicts AS c+ GROUP BY c.ak_name+),+vulns AS(SELECTak_name,@@ -43,9 +51,11 @@ SELECTv.exposed AS exposed,v.unknown AS unknown,lb.labels AS labels,- ifNull(lb.by, 'none') AS labels_by+ lb.sources AS label_sources,+ lc.conflicts AS label_conflictsFROM shirudo.node_status AS sLEFT JOIN shirudo.latest AS l ON l.ak_name = s.ak_nameLEFT JOIN vulns AS v ON v.ak_name = s.ak_nameLEFT JOIN shirudo.node_labels AS lb ON lb.ak_name = s.ak_name+LEFT JOIN conflicts AS lc ON lc.ak_name = s.ak_nameORDER BY node_id, ak_namediff --git a/tools/xtop/src/components/NodeDetail.tsx b/tools/xtop/src/components/NodeDetail.tsxindex 119c5362..938cd6af 100644--- a/tools/xtop/src/components/NodeDetail.tsx+++ b/tools/xtop/src/components/NodeDetail.tsx@@ -5,7 +5,7 @@import type { ReactNode } from "react";import { Box, Text, useInput } from "ink";-import { imageLabel, labelPairs, type FleetNode } from "../lib/fleet.ts";+import { imageLabel, type FleetNode } from "../lib/fleet.ts";import { STATUS_STYLE } from "./style.tsx";type Props = {@@ -62,9 +62,28 @@ export function NodeDetail({ node, height, active, onClose }: Props) {<Field name="host">{node.hostName}</Field><Field name="key">{node.akName}</Field><Field name="labels">- {labelPairs(node.labels).join(" ") || "none put"}- {node.labelsBy !== "none" && <Text dimColor> put by {node.labelsBy}</Text>}+ {Object.keys(node.labels).length === 0 && "none put"}+ {Object.keys(node.labels)+ .sort()+ .map((k, i) => (+ <Text key={k}>+ {i ? " " : ""}+ {k}={node.labels[k]}+ <Text dimColor> ({node.labelSources[k]})</Text>+ </Text>+ ))}</Field>+ {node.labelConflicts.map((c) => (+ <Field key={c.key} name="conflict">+ <Text color="yellow">+ {c.key}={c.value} from {c.by} over{" "}+ {c.given+ .filter((g) => g.value !== c.value)+ .map((g) => `${g.value} from ${g.by}`)+ .join(", ")}+ </Text>+ </Field>+ ))}<Field name="image">{imageLabel(node.imageId, node.imageVersion)}</Field><Field name="kernel">{node.kernel}</Field><Field name="build">{node.version}</Field>diff --git a/tools/xtop/src/components/NodesView.tsx b/tools/xtop/src/components/NodesView.tsxindex 3c4ff49f..e5034b22 100644--- a/tools/xtop/src/components/NodesView.tsx+++ b/tools/xtop/src/components/NodesView.tsx@@ -106,7 +106,12 @@ const NODE_COLUMNS: readonly Column<FleetNode>[] = [sortKey: (n) => labelPairs(n.labels).join(" ") || "~",render: (n) => {const pairs = labelPairs(n.labels);- return pairs.length ? <Text color="magenta">{pairs.join(" ")}</Text> : <Text dimColor>—</Text>;+ return (+ <>+ {n.labelConflicts.length > 0 && <Text color="yellow">!{n.labelConflicts.length} </Text>}+ {pairs.length ? <Text color="magenta">{pairs.join(" ")}</Text> : <Text dimColor>—</Text>}+ </>+ );},},{@@ -161,6 +166,7 @@ const nodeMatches = (n: FleetNode, q: string) =>n.version,n.failedCheck ? (n.log[n.failedCheck - 1] ?? "") : "",...labelPairs(n.labels),+ n.labelConflicts.length ? "label conflict" : "",].some((s) => s.toLowerCase().includes(q));// ---- per-image table -------------------------------------------------------@@ -345,6 +351,9 @@ export function NodesView({ backend, mode, onModeChange, height, active, onClose<Text color="green">{count("healthy")} healthy</Text> · <Text color="red">{count("unhealthy")} unhealthy</Text> ·{" "}<Text color="gray">{count("stale")} stale</Text> ·{" "}<Text color="yellow">{rows.filter((n) => n.trust === "untrusted").length} untrusted</Text>+ {rows.some((n) => n.labelConflicts.length) && (+ <Text color="yellow"> · {rows.filter((n) => n.labelConflicts.length).length} with label conflicts</Text>+ )}<Text dimColor> · sorted by {sortedBy}</Text>{asOf(report)}</>diff --git a/tools/xtop/src/lib/backend.ts b/tools/xtop/src/lib/backend.tsindex ff22ea00..43ea5445 100644--- a/tools/xtop/src/lib/backend.ts+++ b/tools/xtop/src/lib/backend.ts@@ -9,12 +9,13 @@ 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";import {- LABELS_BY,+ LABEL_SOURCES,STATUSES,TRUSTS,type FleetNode,type FleetReport,- type LabelsBy,+ type LabelConflict,+ type LabelSource,type NodeStatus,type Trust,} from "./fleet.ts";@@ -67,9 +68,22 @@ export type NodeRow = {exposed: number;unknown: number;labels: Record<string, string>;- labels_by: string;+ label_sources: Record<string, string>;+ /** (key, value, by, [(rank, by, value)]) */+ label_conflicts: [string, string, string, [number, string, string][]][];};+const labelSource = (by: string) => oneOf<LabelSource>(LABEL_SOURCES, by, "label source");++function toLabelConflict([key, value, by, given]: NodeRow["label_conflicts"][number]): LabelConflict {+ return {+ key,+ value,+ by: labelSource(by),+ given: given.map(([, from, v]) => ({ by: labelSource(from), value: v })),+ };+}+function oneOf<T extends string>(allowed: readonly T[], value: string, what: string): T {if (!(allowed as readonly string[]).includes(value)) throw new Error(`unknown ${what} "${value}"`);return value as T;@@ -96,7 +110,10 @@ export function toFleetNode(r: NodeRow): FleetNode {exposed: r.exposed,unknown: r.unknown,labels: r.labels,- labelsBy: oneOf<LabelsBy>(LABELS_BY, r.labels_by, "labels source"),+ labelSources: Object.fromEntries(+ Object.entries(r.label_sources).map(([key, by]) => [key, labelSource(by)]),+ ),+ labelConflicts: r.label_conflicts.map(toLabelConflict),};}diff --git a/tools/xtop/src/lib/fleet.ts b/tools/xtop/src/lib/fleet.tsindex 00a2c64f..84ecc159 100644--- a/tools/xtop/src/lib/fleet.ts+++ b/tools/xtop/src/lib/fleet.ts@@ -7,12 +7,22 @@/** node_status.status, worst first in STATUS_RANK. */export type NodeStatus = "unhealthy" | "stale" | "healthy";export type Trust = "untrusted" | "enrolled";-export type LabelsBy = "ak_name" | "node_id" | "config_root" | "none";+/** The name a label set was put under, most specific first. */+export type LabelSource = "ak_name" | "node_id" | "config_root";++/** A key whose sets give the node different values, and the value it took. */+export type LabelConflict = {+ key: string;+ value: string;+ by: LabelSource;+ /** Every value given, most specific name first. */+ given: { by: LabelSource; value: string }[];+};export const STATUS_RANK: Record<NodeStatus, number> = { unhealthy: 0, stale: 1, healthy: 2 };export const STATUSES = ["unhealthy", "stale", "healthy"] as const;export const TRUSTS = ["untrusted", "enrolled"] as const;-export const LABELS_BY = ["ak_name", "node_id", "config_root", "none"] as const;+export const LABEL_SOURCES = ["ak_name", "node_id", "config_root"] as const;export type Shields = {/** Upatches loaded that shield a finding of the node. */@@ -45,10 +55,14 @@ export type FleetNode = {exposed: number;/** Findings the backend cannot place: no image, no SBOM. */unknown: number;- /** What jobs/labels-put gave the node, not its own node.labels. */+ /**+ * What jobs/labels-put gave the node, not its own node.labels: the union+ * of its sets, the most specific name's value where they disagree.+ */labels: Record<string, string>;- /** The name the labels were put under. */- labelsBy: LabelsBy;+ /** Per key, the name its value was put under. */+ labelSources: Record<string, LabelSource>;+ labelConflicts: LabelConflict[];};export type FleetReport = {diff --git a/tools/xtop/test/fleet.test.ts b/tools/xtop/test/fleet.test.tsindex 066053e8..d4733d24 100644--- a/tools/xtop/test/fleet.test.ts+++ b/tools/xtop/test/fleet.test.ts@@ -46,7 +46,8 @@ function row(over: Partial<NodeRow>): NodeRow {exposed: 1,unknown: 0,labels: { role: "edge", site: "fra" },- labels_by: "node_id",+ label_sources: { role: "node_id", site: "node_id" },+ label_conflicts: [],...over,};}@@ -62,7 +63,7 @@ const ROWS: NodeRow[] = [shields_idle: 1,exposed: 2,labels: { role: "core" },- labels_by: "ak_name",+ label_sources: { role: "ak_name" },}),row({node_id: "node-c",@@ -79,7 +80,7 @@ const ROWS: NodeRow[] = [exposed: 0,unknown: 1,labels: {},- labels_by: "none",+ label_sources: {},}),row({node_id: "node-d",@@ -89,7 +90,7 @@ const ROWS: NodeRow[] = [failed_check: 3,log: LOG.map((l, i) => (i === 2 ? "3 reported: FAIL, verdict degraded, cond 0x1555, flags 0, tamper +0, build d6d918ad" : l)),}),- row({ labels: {}, labels_by: "none", node_id: "node-e", ak_name: "000b0e", host_name: "core-02", status: "stale", failed_check: 2, last_seq: 2, loaded: 0, shields_applied: 0, shields_idle: 1, exposed: 2 }),+ row({ labels: {}, label_sources: {}, node_id: "node-e", ak_name: "000b0e", host_name: "core-02", status: "stale", failed_check: 2, last_seq: 2, loaded: 0, shields_applied: 0, shields_idle: 1, exposed: 2 }),];describe("toFleetNode", () => {@@ -118,11 +119,40 @@ describe("toFleetNode", () => {test("keeps the labels the operator put", () => {expect(toFleetNode(ROWS[0]!).labels).toEqual({ role: "edge", site: "fra" });- expect(toFleetNode(ROWS[0]!).labelsBy).toBe("node_id");+ expect(toFleetNode(ROWS[0]!).labelSources).toEqual({ role: "node_id", site: "node_id" });expect(toFleetNode(ROWS[2]!).labels).toEqual({});- expect(toFleetNode(ROWS[2]!).labelsBy).toBe("none");- expect(toFleetNode(row({ labels_by: "config_root" })).labelsBy).toBe("config_root");- expect(() => toFleetNode(row({ labels_by: "host_name" }))).toThrow(/unknown labels source/);+ expect(() => toFleetNode(row({ label_sources: { role: "host_name" } }))).toThrow(/unknown label source/);+ });++ test("keeps the keys whose sets disagree", () => {+ const n = toFleetNode(+ row({+ labels: { image: "base", role: "edge", site: "fra" },+ label_sources: { image: "config_root", role: "node_id", site: "node_id" },+ label_conflicts: [+ [+ "role",+ "edge",+ "node_id",+ [+ [2, "node_id", "edge"],+ [1, "config_root", "lab"],+ ],+ ],+ ],+ }),+ );+ expect(n.labelConflicts).toEqual([+ {+ key: "role",+ value: "edge",+ by: "node_id",+ given: [+ { by: "node_id", value: "edge" },+ { by: "config_root", value: "lab" },+ ],+ },+ ]);});test("refuses a status the view does not know", () => {