Skip to content

eBPF-based security platform

tools/xtop: show the labels of the nodes

John Fastabendae4a2670c31e
diff --git a/Documentation/operate/backend/xtop.rst b/Documentation/operate/backend/xtop.rst
index 5a01abac..72813b95 100644
--- a/Documentation/operate/backend/xtop.rst
+++ b/Documentation/operate/backend/xtop.rst
@@ -80,6 +80,10 @@ key the operator has recorded as a TPM's.
- ``untrusted`` or ``enrolled``.
* - ``NODE``
- ``node_id``.
+ * - ``LABELS``
+ - The labels from ``shirudo.node_labels``, as ``key=value`` in key
+ order: what :doc:`labels-put` loaded, not the node's own
+ ``node.labels``; ``—`` when none was put.
* - ``CHECK``
- The first check that failed, as its line names it, for example
``3 reported``; ``—`` when all passed.
@@ -108,21 +112,22 @@ The summary line gives the health of the nodes shown: the percent of
them ``healthy``, so 100% when every node is healthy and 0% when none
is. A stale node counts against it like an unhealthy one.
-Enter on a node shows its host name, key, 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 and the line of the failed check.
-
-``t`` switches to one row per image id and version. A group's status is
-its worst member's, its health the percent of its members ``healthy``,
-its kernel ``mixed`` when its members differ, its tree the member
-furthest behind, its shields the sums over its members, and its
-exposure that of its most exposed member. Enter on an image shows its
-nodes.
-
-Labels and detector hits are not shown: the keepalive carries no labels,
-and the collector of :src:`tools/backend/otelcol.yaml` takes in no map
-snapshot metrics.
+Enter on a node shows its host name, key, labels, 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.
+
+``t`` switches to one row per image id and version, with the ``role``
+labels of its members beside it, ``?`` for a member without one. A
+group's status is its worst member's, its health the percent of its
+members ``healthy``, its kernel ``mixed`` when its members differ, its
+tree the member furthest behind, its shields the sums over its members,
+and its exposure that of its most exposed member. Enter on an image
+shows its nodes.
+
+Detector hits are not shown: the collector of
+:src:`tools/backend/otelcol.yaml` takes in no map snapshot metrics.
Read the shields
----------------
diff --git a/tools/backend/test/xtop-nodes.expected b/tools/backend/test/xtop-nodes.expected
index 5d6ec1a0..be3aef20 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 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 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 ['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 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 ['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 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 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) 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'} ['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'} ['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 {'role':'edge','site':'ams'} ['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 1
nodes 5
diff --git a/tools/backend/test/xtop-nodes.setup.sql b/tools/backend/test/xtop-nodes.setup.sql
index 90139cfa..0cdf34cd 100644
--- a/tools/backend/test/xtop-nodes.setup.sql
+++ b/tools/backend/test/xtop-nodes.setup.sql
@@ -7,8 +7,10 @@
-- 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. 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.
+-- 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
+-- 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.
@@ -72,6 +74,11 @@ INSERT INTO shirudo.tree_ops (tree_id, seq, op, id, selector, repository, manife
INSERT INTO shirudo.upatch_fixes (tree_id, seq, id, advisory, source) VALUES
('fleet-base', 4, 'ssl-fix', 'EXAMPLE-0202', 'fixes');
+INSERT 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'});
+
-- 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))
diff --git a/tools/xtop/sql/nodes.sql b/tools/xtop/sql/nodes.sql
index b4e866f7..cafa52c3 100644
--- a/tools/xtop/sql/nodes.sql
+++ b/tools/xtop/sql/nodes.sql
@@ -3,8 +3,9 @@
--
-- 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, and per node the counts of node_vulns. Times are epoch
--- milliseconds, so that no client reads them in the server's time zone.
+-- 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
+-- client reads them in the server's time zone.
WITH vulns AS
(
@@ -40,8 +41,10 @@ SELECT
v.shields_pending AS shields_pending,
v.shields_idle AS shields_idle,
v.exposed AS exposed,
- v.unknown AS unknown
+ v.unknown AS unknown,
+ lb.labels AS labels
FROM shirudo.node_status AS s
LEFT JOIN shirudo.latest AS l ON l.ak_name = s.ak_name
LEFT JOIN vulns AS v ON v.ak_name = s.ak_name
+LEFT JOIN shirudo.node_labels AS lb ON lb.ak_name = s.ak_name
ORDER BY node_id, ak_name
diff --git a/tools/xtop/src/components/NodeDetail.tsx b/tools/xtop/src/components/NodeDetail.tsx
index 1dd60b7d..f4e3690c 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, type FleetNode } from "../lib/fleet.ts";
+import { imageLabel, labelPairs, type FleetNode } from "../lib/fleet.ts";
import { STATUS_STYLE } from "./style.tsx";
type Props = {
@@ -61,6 +61,7 @@ export function NodeDetail({ node, height, active, onClose }: Props) {
</Text>
<Field name="host">{node.hostName}</Field>
<Field name="key">{node.akName}</Field>
+ <Field name="labels">{labelPairs(node.labels).join(" ") || "none put"}</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.tsx
index 33f61a75..3c4ff49f 100644
--- a/tools/xtop/src/components/NodesView.tsx
+++ b/tools/xtop/src/components/NodesView.tsx
@@ -14,6 +14,7 @@ import {
groupByImage,
healthPercent,
imageLabel,
+ labelPairs,
type FleetNode,
type FleetReport,
type ImageGroup,
@@ -97,7 +98,17 @@ const NODE_COLUMNS: readonly Column<FleetNode>[] = [
sortKey: (n) => n.trust,
render: (n) => <Text color={n.trust === "enrolled" ? "green" : "yellow"}>{n.trust}</Text>,
},
- { id: "name", title: "NODE", defaultDir: "asc", sortKey: (n) => n.name, render: (n) => <Text bold>{n.name}</Text> },
+ { id: "name", title: "NODE", width: 16, defaultDir: "asc", sortKey: (n) => n.name, render: (n) => <Text bold>{n.name}</Text> },
+ {
+ id: "labels",
+ title: "LABELS",
+ defaultDir: "asc",
+ 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>;
+ },
+ },
{
id: "check",
title: "CHECK",
@@ -149,13 +160,25 @@ const nodeMatches = (n: FleetNode, q: string) =>
n.kernel,
n.version,
n.failedCheck ? (n.log[n.failedCheck - 1] ?? "") : "",
+ ...labelPairs(n.labels),
].some((s) => s.toLowerCase().includes(q));
// ---- per-image table -------------------------------------------------------
const IMAGE_COLUMNS: readonly Column<ImageGroup>[] = [
{ id: "status", title: "STATUS", width: 12, defaultDir: "asc", sortKey: (g) => STATUS_RANK[g.status], render: (g) => <StatusCell status={g.status} /> },
- { id: "image", title: "IMAGE", defaultDir: "asc", sortKey: (g) => g.key, render: (g) => imageCell(g.imageId, g.imageVersion) },
+ {
+ id: "image",
+ title: "IMAGE",
+ defaultDir: "asc",
+ sortKey: (g) => g.key,
+ render: (g) => (
+ <>
+ {imageCell(g.imageId, g.imageVersion)}
+ <Text dimColor> {g.roles.join(",")}</Text>
+ </>
+ ),
+ },
{
id: "nodes",
title: "NODES",
@@ -214,7 +237,7 @@ const IMAGE_COLUMNS: readonly Column<ImageGroup>[] = [
];
const imageMatches = (g: ImageGroup, q: string) =>
- [g.key, g.status, g.kernel ?? "mixed"].some((s) => s.toLowerCase().includes(q));
+ [g.key, g.status, g.kernel ?? "mixed", ...g.roles].some((s) => s.toLowerCase().includes(q));
// ---- view ------------------------------------------------------------------
diff --git a/tools/xtop/src/lib/backend.ts b/tools/xtop/src/lib/backend.ts
index 095ccac3..11221972 100644
--- a/tools/xtop/src/lib/backend.ts
+++ b/tools/xtop/src/lib/backend.ts
@@ -57,6 +57,7 @@ export type NodeRow = {
shields_idle: number;
exposed: number;
unknown: number;
+ labels: Record<string, string>;
};
function oneOf<T extends string>(allowed: readonly T[], value: string, what: string): T {
@@ -84,6 +85,7 @@ export function toFleetNode(r: NodeRow): FleetNode {
shields: { applied: r.shields_applied, pending: r.shields_pending, idle: r.shields_idle },
exposed: r.exposed,
unknown: r.unknown,
+ labels: r.labels,
};
}
diff --git a/tools/xtop/src/lib/fleet.ts b/tools/xtop/src/lib/fleet.ts
index 57fad3eb..abcbd7f9 100644
--- a/tools/xtop/src/lib/fleet.ts
+++ b/tools/xtop/src/lib/fleet.ts
@@ -43,6 +43,8 @@ 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. */
+ labels: Record<string, string>;
};
export type FleetReport = {
@@ -68,11 +70,19 @@ export type ImageGroup = {
/** Exposed findings of the worst member. */
exposed: number;
unknown: number;
+ /** The members' role labels, each once; "?" for a member without one. */
+ roles: string[];
lastSeen: Date;
};
export const NO_IMAGE = "—";
+/** key=value, in key order: how the labels show and are searched. */
+export const labelPairs = (labels: Record<string, string>) =>
+ Object.keys(labels)
+ .sort()
+ .map((k) => `${k}=${labels[k]}`);
+
export const imageLabel = (id: string | null, version: string | null) =>
id === null ? NO_IMAGE : version ? `${id} ${version}` : id;
@@ -128,6 +138,7 @@ export function groupByImage(nodes: readonly FleetNode[]): ImageGroup[] {
shields: { applied: sum("applied"), pending: sum("pending"), idle: sum("idle") },
exposed: Math.max(...members.map((m) => m.exposed)),
unknown: members.reduce((t, m) => t + m.unknown, 0),
+ roles: [...new Set(members.map((m) => m.labels.role ?? "?"))].sort(),
lastSeen: new Date(Math.max(...members.map((m) => m.lastSeen.getTime()))),
};
});
diff --git a/tools/xtop/test/fleet.test.ts b/tools/xtop/test/fleet.test.ts
index 822c8bfa..aea97b47 100644
--- a/tools/xtop/test/fleet.test.ts
+++ b/tools/xtop/test/fleet.test.ts
@@ -8,7 +8,7 @@
import { describe, expect, test } from "bun:test";
import { toFleetNode, toFleetReport, type NodeRow } from "../src/lib/backend.ts";
import { configFromEnv, queryRows } from "../src/lib/clickhouse.ts";
-import { failedCheckName, groupByImage, healthPercent, imageLabel } from "../src/lib/fleet.ts";
+import { failedCheckName, groupByImage, healthPercent, imageLabel, labelPairs } from "../src/lib/fleet.ts";
const BUILD = "d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f";
const LOG = [
@@ -45,13 +45,23 @@ function row(over: Partial<NodeRow>): NodeRow {
shields_idle: 0,
exposed: 1,
unknown: 0,
+ labels: { role: "edge", site: "fra" },
...over,
};
}
const ROWS: NodeRow[] = [
row({}),
- row({ node_id: "node-b", ak_name: "000b9d72e08380a1", host_name: "core-01", loaded: 0, shields_applied: 0, shields_idle: 1, exposed: 2 }),
+ row({
+ node_id: "node-b",
+ ak_name: "000b9d72e08380a1",
+ host_name: "core-01",
+ loaded: 0,
+ shields_applied: 0,
+ shields_idle: 1,
+ exposed: 2,
+ labels: { role: "core" },
+ }),
row({
node_id: "node-c",
ak_name: "000b0c",
@@ -66,6 +76,7 @@ const ROWS: NodeRow[] = [
shields_applied: 0,
exposed: 0,
unknown: 1,
+ labels: {},
}),
row({
node_id: "node-d",
@@ -75,7 +86,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({ 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: {}, 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", () => {
@@ -102,6 +113,11 @@ describe("toFleetNode", () => {
expect(toFleetNode(row({ image_id: "", image_version: "" })).imageId).toBeNull();
});
+ test("keeps the labels the operator put", () => {
+ expect(toFleetNode(ROWS[0]!).labels).toEqual({ role: "edge", site: "fra" });
+ expect(toFleetNode(ROWS[2]!).labels).toEqual({});
+ });
+
test("refuses a status the view does not know", () => {
expect(() => toFleetNode(row({ status: "degraded" }))).toThrow(/unknown status/);
expect(() => toFleetNode(row({ trust: "maybe" }))).toThrow(/unknown trust/);
@@ -152,6 +168,11 @@ describe("groupByImage", () => {
expect(none.unknown).toBe(1);
});
+ test("rolls up the role labels, ? for a member without one", () => {
+ expect(fleetOs.roles).toEqual(["?", "core", "edge"]);
+ expect(none.roles).toEqual(["?"]);
+ });
+
test("reports a mixed kernel as null", () => {
const mixed = groupByImage([toFleetNode(ROWS[0]!), toFleetNode(row({ ak_name: "x", kernel_release: "7.5.0" }))]);
expect(mixed[0]!.kernel).toBeNull();
@@ -192,3 +213,10 @@ describe("clickhouse", () => {
await expect(queryRows(configFromEnv({}), "SELECT 1", fake)).rejects.toThrow("404 Code: 60. DB::Exception: Unknown table");
});
});
+
+describe("labelPairs", () => {
+ test("key=value in key order", () => {
+ expect(labelPairs({ site: "fra", role: "edge" })).toEqual(["role=edge", "site=fra"]);
+ expect(labelPairs({})).toEqual([]);
+ });
+});