eBPF-based security platform
backend: hold an enrolled node against enrolled peers only
John Fastabend54875af71249
diff --git a/Documentation/operate/backend/status.rst b/Documentation/operate/backend/status.rstindex 6dd41265..bb592ec9 100644--- a/Documentation/operate/backend/status.rst+++ b/Documentation/operate/backend/status.rst@@ -80,7 +80,7 @@ A UI reads ``node_status`` as often as it likes, as :doc:`xtop` does:* - ``status``- ``stale``, ``unhealthy`` or ``healthy``, see below.* - ``trust``- - The node's ``trust`` from ``shirudo.nodes``: ``untrusted``, or ``enrolled`` once the operator has recorded its key as a TPM's (:doc:`maintain`). It is never part of ``status``: a healthy node is one whose records are consistent and match the tree, an enrolled one is one whose key is known to live in a TPM. Show both.+ - The node's ``trust`` from ``shirudo.nodes``: ``untrusted``, or ``enrolled`` once the operator has recorded its key as a TPM's (:doc:`maintain`). A node's own ``trust`` never decides its ``status``: a healthy node is one whose records are consistent and match the tree, an enrolled one is one whose key is known to live in a TPM. Show both. Check 7 reads it only to choose whom a node is compared with.* - ``failed_check``- The first check that failed: 2 for ``stale``, 3 to 7 for ``unhealthy``, 0 for ``healthy``.* - ``log``@@ -163,13 +163,20 @@ passed. Checks 3 to 6 have a section each below.- ``FAIL drift``* - 7- ``7 peers:``- - The node's ``base_root`` and its mask up to ``last_seq`` are the most common pair among the nodes with the same ``tree_id``, ``base_seq``, ``last_seq``, ``config_root`` and ``kernel_release``, or one of several equally common ones. Alone in its group it has ``no peers``.+ - The node's ``base_root`` and its mask up to ``last_seq`` are the most common pair among the nodes with the same ``tree_id``, ``base_seq``, ``last_seq``, ``config_root`` and ``kernel_release``, or one of several equally common ones. An enrolled node is compared with the enrolled nodes of that group only, an untrusted one with all of them. Alone in its group it has ``no peers``.- ``FAIL outlier``An outlier is a reason to attest a node, not an alarm by itself: a nodewhose labels changed partway through a tree differs from its peers fora good reason.+Whoever can post to the collector can make keys, as many as it takes to+be the most common pair of a group. Untrusted keys therefore have no+say about an enrolled node: they can neither make it an outlier nor+hide one among them. Among untrusted nodes they can do both, so enroll+the nodes whose check 7 you rely on (:doc:`maintain`). The line's count+is that of the nodes the node was compared with, itself included.+Three kinds of node are not held against the tree. Checks 4 to 7 passfor them and their lines say why:diff --git a/Documentation/operate/backend/tables/status.rst b/Documentation/operate/backend/tables/status.rstindex 41b55b41..c7396bf7 100644--- a/Documentation/operate/backend/tables/status.rst+++ b/Documentation/operate/backend/tables/status.rst@@ -193,6 +193,8 @@ shirudo.node_status- Checks: 1 signed, 2 fresh, 3 reported, 4 chain, 5 head, 6 set, 7 peers.Each only means something if the ones before it passed.+ - Check 7 compares an enrolled node with enrolled nodes only: untrusted+ keys cost nothing to make.- Checks 4–7 pass with a reason when the node cannot be held against atree: no tree, no mask, or publication unknown (ingest is behind).- A node behind the head is healthy until stuck_seconds after thediff --git a/tools/backend/sql/40-status.sql b/tools/backend/sql/40-status.sqlindex d3be2c56..4e7d3465 100644--- a/tools/backend/sql/40-status.sql+++ b/tools/backend/sql/40-status.sql@@ -368,8 +368,9 @@ WHERE (ak_name, tree_id) NOT IN (SELECT ak_name, tree_id FROM shirudo.history_co-- stale_seconds, whatever it says, else unhealthy when one of checks 3-- to 7 fails and healthy otherwise. failed_check is the first check that-- fails, 2 for stale and 0 for none, and log has one line per check, 1--- to 7. trust is not part of status. head_seq is the head of the newest--- publication known for the node's tree.+-- to 7. A node's trust does not decide its status; check 7 reads it to+-- choose the node's peers. head_seq is the head of the newest publication+-- known for the node's tree.CREATE TABLE IF NOT EXISTS shirudo.node_status(node_id String,@@ -563,19 +564,30 @@ WITH)GROUP BY ak_name),+ -- Anyone who can post to the collector can make keys, and as many+ -- of them as it takes to be the most common path of a group. An+ -- enrolled node is therefore held against the enrolled nodes of its+ -- group alone; an untrusted one against all of them.peers AS(- SELECT ak_name, n, same,- max(same) OVER (PARTITION BY p_tree, p_base, p_last, p_config, kernel_release) AS most+ SELECT ak_name,+ if(enrolled, n_enrolled, n_all) AS n,+ if(enrolled, same_enrolled, same_all) AS same,+ if(enrolled, max(same_enrolled) OVER grp, max(same_all) OVER grp) AS mostFROM(SELECT ak_name, p_tree, p_base, p_last, p_config, kernel_release,- count() OVER (PARTITION BY p_tree, p_base, p_last, p_config, kernel_release) AS n,- count() OVER (PARTITION BY p_tree, p_base, p_last, p_config, kernel_release, p_root, walked)- AS same+ trust = 'enrolled' AS enrolled,+ count() OVER grp AS n_all,+ countIf(enrolled) OVER grp AS n_enrolled,+ count() OVER path AS same_all,+ countIf(enrolled) OVER path AS same_enrolledFROM nodeWHERE skip = ''+ WINDOW grp AS (PARTITION BY p_tree, p_base, p_last, p_config, kernel_release),+ path AS (PARTITION BY p_tree, p_base, p_last, p_config, kernel_release, p_root, walked))+ WINDOW grp AS (PARTITION BY p_tree, p_base, p_last, p_config, kernel_release)),boot AS(diff --git a/tools/backend/test/status-peers.expected b/tools/backend/test/status-peers.expectedindex 45be45cf..09443168 100644--- a/tools/backend/test/status-peers.expected+++ b/tools/backend/test/status-peers.expected@@ -4,9 +4,21 @@ edge-02 edge-02 healthy untrusted 0 3 3 3 1edge-03 edge-03 healthy untrusted 0 3 3 3 1edge-04 edge-04 unhealthy untrusted 7 3 3 3 0edge-on-another-kernel edge-on-another-kernel healthy untrusted 0 3 3 3 1+enrolled-01 enrolled-01 healthy enrolled 0 3 3 3 1+enrolled-02 enrolled-02 healthy enrolled 0 3 3 3 1+enrolled-deviating enrolled-deviating unhealthy enrolled 7 3 3 3 0+made-up-01 made-up-01 healthy untrusted 0 3 3 3 0+made-up-02 made-up-02 healthy untrusted 0 3 3 3 0+made-up-03 made-up-03 healthy untrusted 0 3 3 3 0core-01 7 peers: no peers, 1 in groupedge-01 7 peers: pass, 4 in groupedge-02 7 peers: pass, 4 in groupedge-03 7 peers: pass, 4 in groupedge-04 7 peers: FAIL outlier, 4 in groupedge-on-another-kernel 7 peers: no peers, 1 in group+enrolled-01 7 peers: pass, 3 in group+enrolled-02 7 peers: pass, 3 in group+enrolled-deviating 7 peers: FAIL outlier, 3 in group+made-up-01 7 peers: pass, 6 in group+made-up-02 7 peers: pass, 6 in group+made-up-03 7 peers: pass, 6 in groupdiff --git a/tools/backend/test/status-peers.sql b/tools/backend/test/status-peers.sqlindex 188a7e43..2e27791e 100644--- a/tools/backend/test/status-peers.sql+++ b/tools/backend/test/status-peers.sql@@ -7,6 +7,12 @@-- every operation over. A node alone in its group has no peers and-- passes. Peers that have seen different heads have masks of different-- lengths for the same path, and are not outliers for that.+--+-- Keys cost nothing to make, so an untrusted one is no peer of an+-- enrolled node: on kernel 7.5.0 three untrusted keys on another path+-- neither turn the two enrolled nodes into outliers nor hide the+-- enrolled one that walks with them, and are themselves held against+-- the whole group.-- The publication of testing/fixtures/keepalive/tree-1.1.0.json, as the-- ingest job loads it: generation 3 with its three operations.@@ -25,6 +31,9 @@ INSERT INTO fixture VALUES('node-a-1.1.0', '{"schema":"shirudo.keepalive/1","boot_id":"168d20a1-5011-4e1b-9924-d8b73c85aa4e","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":3,"base_seq":0,"last_seq":3,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"154522480ff8884daa95589e80f26f20248bbf9c192dfbb3cee04e03b4f136a1","mask":"VA==","set_sha256":"74e5bd2c665109f6d8f926af5476c266ad70ab07293ff13b1a13d0b89aa5c1bf","count":1,"not_ok":0}'),('node-b-1.1.0', '{"schema":"shirudo.keepalive/1","boot_id":"9a6f14ea-0cc2-45e1-8e23-7b887120cf54","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":3,"base_seq":0,"last_seq":3,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"0000000000000000000000000000000000000000000000000000000000000000","mask":"qA==","set_sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","count":0,"not_ok":0}');+INSERT INTO shirudo.nodes (ak_name, trust) VALUES+('000benrolled-01', 'enrolled'), ('000benrolled-02', 'enrolled'), ('000benrolled-deviating', 'enrolled');+INSERT INTO shirudo.checked (host_name, body, ok, ak_name, ak_public, reset_count, clock)SELECT node.1, arrayFold((body, change) -> replaceOne(body, change.1, change.2), node.3, f.body),1, concat('000b', node.1), 'QUtB', 1, 1000@@ -36,7 +45,13 @@ FROM('edge-03', 'node-a-1.1.0', [('"mask":"VA=="', '"mask":"VAA="')]),('edge-04', 'node-b-1.1.0', [('"config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8"', '"config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807"')]),('core-01', 'node-b-1.1.0', [('"flags":0', '"flags":0')]),- ('edge-on-another-kernel', 'node-a-1.1.0', [('"kernel_release":"7.4.2"', '"kernel_release":"7.4.3"')])+ ('edge-on-another-kernel', 'node-a-1.1.0', [('"kernel_release":"7.4.2"', '"kernel_release":"7.4.3"')]),+ ('enrolled-01', 'node-a-1.1.0', [('"kernel_release":"7.4.2"', '"kernel_release":"7.5.0"')]),+ ('enrolled-02', 'node-a-1.1.0', [('"kernel_release":"7.4.2"', '"kernel_release":"7.5.0"')]),+ ('enrolled-deviating', 'node-b-1.1.0', [('"config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8"', '"config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807"'), ('"kernel_release":"7.4.2"', '"kernel_release":"7.5.0"')]),+ ('made-up-01', 'node-b-1.1.0', [('"config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8"', '"config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807"'), ('"kernel_release":"7.4.2"', '"kernel_release":"7.5.0"')]),+ ('made-up-02', 'node-b-1.1.0', [('"config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8"', '"config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807"'), ('"kernel_release":"7.4.2"', '"kernel_release":"7.5.0"')]),+ ('made-up-03', 'node-b-1.1.0', [('"config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8"', '"config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807"'), ('"kernel_release":"7.4.2"', '"kernel_release":"7.5.0"')])]) AS node) AS nINNER JOIN fixture AS f ON f.name = node.2;diff --git a/tools/backend/test/xtop-nodes.expected b/tools/backend/test/xtop-nodes.expectedindex 423e8a11..1b0decd0 100644--- a/tools/backend/test/xtop-nodes.expected+++ b/tools/backend/test/xtop-nodes.expected@@ -1,7 +1,7 @@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 enroll_ek_name enroll_source enrolled_ms 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 Map(String, String) Map(String, String) Array(Tuple(String, String, String, Array(Tuple(UInt8, String, String)))) String String Int64 Array(String) UInt8 UInt8node-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')])] 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 enrolled 0 3 3 4 0 7.4.2 d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f fleet-os 2026.11.1 0 1 1 1 0 {'role':'core'} {'role':'ak_name'} [] 000beeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee vm-host-1 1793527200000 ['1 signed: pass, enrolled, 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-b 000b9d72e08380a1 core-01 healthy enrolled 0 3 3 4 0 7.4.2 d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f fleet-os 2026.11.1 0 1 1 1 0 {'role':'core'} {'role':'ak_name'} [] 000beeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee vm-host-1 1793527200000 ['1 signed: pass, enrolled, 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: no peers, 1 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 {} {} [] 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: no tree','5 head: no tree','6 set: no tree','7 peers: no tree'] 1 1node-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')])] 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 1node-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 {} {} [] 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