Node status#
Once a minute the backend decides, for every node, whether it is
healthy, from the node’s newest record, its history and the tree it
follows. The objects that do it are in tools/backend/sql/40-status.sql, and
Status gives their columns and cost:
Object |
Kind |
Holds |
|---|---|---|
|
function |
The outcome pair of the operation at index |
|
view |
The newest record of every node, from |
|
view |
Every label of every node, one row per set it comes from, see Label the nodes. |
|
view |
The labels of every node: the union of its sets, the most specific name’s value where they disagree. |
|
view |
Per node, each key its sets give different values, and those values. |
|
ReplacingMergeTree, |
The history of every node: what it did at each operation of its tree the backend has seen it reach, see History. |
|
refreshable materialized view, every minute, appending |
Adds the operations each node’s newest record reaches past its stored history, unless the record contradicts that history or the node is marked. |
|
view |
Per node whose newest record contradicts its stored history, whether at |
|
MergeTree, |
The marks: one row per node and tree whose record once contradicted its history, with |
|
refreshable materialized view, every minute, appending |
Marks every node in |
|
ReplacingMergeTree by |
Per node, the newest operation of every upatch it applied, from |
|
materialized view |
Writes a row of |
|
MergeTree, |
One row per node: the outcome of the checks. |
|
refreshable materialized view, every minute |
Runs the checks for all nodes and replaces the rows of |
A UI reads node_status as often as it likes, as Watch nodes, shields and SBOMs with xtop does:
SELECT node_id, host_name, status, trust, failed_check, log, last_seen, updated_at
FROM shirudo.node_status
ORDER BY status = 'healthy', node_id;
Column |
Value |
|---|---|
|
The node’s label, its key and the host name its newest record claimed. |
|
|
|
The node’s |
|
The first check that failed: 2 for |
|
Seven lines, one per check in order. |
|
When the newest record was first received. |
|
From the newest record; |
|
The head of the newest publication loaded for the node’s tree, |
|
|
|
When the row was computed. |
Checks#
status is:
stalewhen the newest record was first received more thanstale_secondsago, 10 minutes by default. It wins over everything else, because the other lines then describe old data; thelogstill shows what that record said. A node whose records are all refused gets no new record and turns stale.A record received again counts from when it came first. Its quote still checks, so whoever holds a node’s last record, a collector or a reader of
shirudo.keepalive, can send it again, but a node that sends nothing new turns stale all the same: only a quote with a laterclockorreset_countis news, and only the node’s TPM signs one.shirudo.boot_firstkeeps that first time for the newest record of each boot.A node sends a record a minute, but not while it syncs its tree: every shirudo command on a target holds the config operation lock for its whole run, and
bpm tree syncholds it until its last operation is applied. A keepalive that cannot take the lock within 30 seconds sends nothing, so a sync that runs for minutes leaves a gap of that length. The default allows for syncs of a few minutes; it is a first guess, to be tuned against the sync durations seen on real clusters.unhealthywhen the record is fresh and one of checks 3 to 7 fails.healthyotherwise. A node behind the head of its tree is healthy untilstuck_secondshave passed since the oldest publication it has not finished was loaded: that is a rollout, and line 5 saysbehind.
The checks, in order. Each only means something if those before it passed. Checks 3 to 6 have a section each below.
# |
Line starts |
Passes when |
Fails as |
|---|---|---|---|
1 |
|
Always, here: a record whose quote fails never becomes a node’s newest. The line gives the node’s trust and how many records under its key were refused in the last hour. |
Never fails |
2 |
|
The newest record, by the quote’s |
|
3 |
|
The record reports a healthy target of an expected build, see Check 3. |
|
4 |
|
The mask folds to |
|
5 |
|
The node is at the head of its tree, or |
|
6 |
|
The loaded set is the one the mask leads to, see Check 6. |
|
7 |
|
The node’s |
|
An outlier is a reason to attest a node, not an alarm by itself: a node whose labels changed partway through a tree differs from its peers for a 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 (Maintain the backend). 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 pass for them and their lines say why:
Line reads |
When |
|---|---|
|
The record’s |
|
The node follows a tree but its record has no |
|
The record names a generation newer than the newest in |
The two nodes of the example in testing/fixtures/keepalive/, after release 1.1.0 of the upatch
their tree carries, with tools/backend/test/status-fixtures.sql showing the same:
node_id: edge-01
status: healthy
trust: untrusted
failed_check: 0
log: 1 signed: pass, untrusted, 0 rejected in the last hour
2 fresh: pass, last record 21 s ago
3 reported: pass, verdict ok, cond 0x1555, flags 0, tamper +0, build d6d918ad
4 chain: pass, root 15452248
5 head: pass, seq 3 of 3, generation 3
6 set: pass, 1 loaded
7 peers: no peers, 1 in group
node_id: core-01
status: healthy
trust: untrusted
failed_check: 0
log: 1 signed: pass, untrusted, 0 rejected in the last hour
2 fresh: pass, last record 21 s ago
3 reported: pass, verdict ok, cond 0x1555, flags 0, tamper +0, build d6d918ad
4 chain: pass, root 00000000
5 head: pass, seq 3 of 3, generation 3
6 set: pass, 0 loaded
7 peers: no peers, 1 in group
Check 3#
Check 3 passes when all of these hold:
verdictisok;each of the seven condition pairs of
condis OK,0x1555; pairs above the seventh are not read;bits 0 to 3 of
flagsare clear;the total of
tamperis what it was in the first record of this boot that could read the counters;version_idis inshirudo.expected_builds.
It fails as FAIL, with every item on the line; an unexpected build
is marked (not expected). Bits 4 and 5 of flags say a node is
busy, not broken, and do not fail it, see Check 6.
The baseline of check 3 is a boot’s first readable total. A record
whose tamper is null could not read the counters: it says so in
flags bit 3 and fails the check for that, its line reads tamper +0,
and it neither sets the baseline nor is compared with it. The next
record that reads them is held against the first one that did, so a
boot that begins with an unreadable record does not fail later for
counters it had from the start.
Check 4#
Check 4 folds the published operation digests that the mask marks 1 or
3, from base_root, each step SHA-256 of the previous root and the
digest. It passes when all of these hold:
the fold gives
projection_root;no operation up to
last_seqis marked 0;every operation from
base_seq + 1tolast_seqis intree_ops;base_seq,last_seq,base_rootandprojection_rootare present and well formed;when
base_seqis 0,base_rootis the zero root every tree starts from: the history is folded from it, so a window that starts anywhere else at seq 0 would pass with nothing stored for it;when
base_seqis above 0,base_rootis the root the node’s history has atbase_seq, see Gaps;at every operation of the window the history reaches, the code and the root folded from
base_rootare the stored ones, see Contradictions;the node has no mark.
Where the history has no row at base_seq, or only the gap row with
the same root, the line adds base unverified (gap) and the check
does not fail on that account. When the history is why it fails, the
line adds base differs from history, window differs from history
at seq <seq> or marked: contradicted history at seq <seq>. A
marked node fails even when its record cannot be held against the tree.
Check 5#
Check 5 passes when last_seq is at the head of the newest
publication of the tree, or when the oldest publication the node has
not finished was loaded at most stuck_seconds ago, and the line then
reads behind. It fails as FAIL stuck.
The stuck clock of check 5 belongs to the node, not to the tree. It
starts at the published_at of the earliest-loaded publication of the
node’s tree whose head_seq is beyond the node’s last_seq, so a
publication that follows does not start it again: an operator who
publishes more often than stuck_seconds still sees a node that never
moves, stuck_seconds after the first publication it failed to finish.
A node that moves, but never as far as the head, starts a new clock
with every publication it finishes. tools/backend/test/status-stuck.sql shows both.
Check 6#
Check 6 folds the operations the mask marks 1 into the set they leave
loaded, an add loading its payload under its id and a delete
removing it, and hashes one line <payload_sha256> <id> per upatch,
sorted by id. When base_seq is above 0 the fold starts from what
the node’s history leaves loaded at base_seq, from node_sets. The
line reads the first of these that applies:
Line reads |
When |
Check 6 |
|---|---|---|
|
|
Fails |
|
|
Passes, the set not compared |
|
|
Passes, the set not compared |
|
|
Passes, the set not compared |
|
The hash is |
Passes |
|
Otherwise. |
Fails |
The check is exact. A node sends a record of one point in time or flags
it, and neither flag hides a node for long. An operation in flight has a
seq above last_seq, so bit 4 on a node at the head is a
contradiction; a node that stays behind the head fails check 5 as stuck,
with or without the bits. A gap is what the backend cannot know: what
the node applied in it would be in its set.
What the checks cost#
Checks 4 and 6 depend on the tree and the mask, not on the node, so the
refresh folds each distinct path, the combination of tree_id,
base_seq, last_seq, base_root and
mask, once and joins the result to the nodes on it. It reads
keepalive_latest and boot_first, one row per node and per boot,
and never shirudo.keepalive. Of the history it reads, per node, the
projection that says how far it reaches, the rows of node_ops from
base_seq to where the window or the history ends, whichever comes
first, at most 513 per node, and, for a node whose window starts past
seq 0, its rows of node_sets, one per upatch it ever applied. The
rows of the window are read through history_conflicts, which
node_ops_mv and history_contradictions_mv read too, so each refresh
reads them once per node. tools/backend/test/status-cost.sql asserts what the
refresh reads.
History#
A keepalive’s mask covers a window of the last 512 operations of the
node’s tree, from base_seq + 1, and base_root is the node’s root
before it. Below the window a record says nothing, so the backend keeps
what each node’s records said while it could: shirudo.node_ops has a
row for every node, tree and operation the backend has seen the node
reach, and shirudo.node_sets what that leaves loaded. Check 4 holds
every record against them, check 6 a record whose base_seq is above
0, and node_vulns a upatch whose newest operation is below the
window.
shirudo.node_ops:
Column |
Value |
|---|---|
|
The node, its tree and the operation. |
|
What the node did there, as its mask said: 1 applied, 2 selector did not match, 3 attach module not loaded. 0 marks a gap, see below. |
|
The node’s |
shirudo.node_sets has, per node, tree and upatch id, the newest
operation the node applied: last_seq, last_op (add or delete)
and the last_payload of that operation.
Once a minute the backend holds each node’s newest record against its
stored history, node_ops_mv to add rows and
history_contradictions_mv to mark the node. Figure 1 shows the three
outcomes: the record extends the history, its window starts past it and
leaves a gap, or it contradicts it.
Figure 1. What a node’s newest record does to its stored history, for a tree whose head is 700 and a window of the last 512 operations.#
A record extends the history by the operations it reaches past the
last stored row, up to last_seq, with their codes from the mask and
their roots folded from the last stored root. They are added only when
every one of them is in tree_ops, none is marked 0 and the fold ends
at the record’s projection_root: a record that does not extend the
history consistently adds nothing, nor does one that contradicts it,
see Contradictions, or any record of a marked node. The rows of an
operation never change once added.
node_sets_mv follows every row with code 1. The fold runs once per
distinct path and starting point, not per node.
Gaps#
A record whose window starts past the stored history, because the node
is new to the backend or was not heard from while its tree moved on by
more than the window, leaves a gap: the operations in between are in no
record the node will send. The history starts again at the record’s
base_seq with a gap row, code 0, which holds the record’s
base_root, as the middle row of Figure 1 shows. Rows are only ever
added past the last one, so the history up to a seq is whole when it
reaches that seq and has no gap at or below it. For a record whose
base_seq is above 0:
check 4 reads
base unverified (gap)where the history has no row atbase_seqor only the gap row, which nothing verified, with the same root; another root, a gap row’s included, fails asbase differs from history, see Check 4;check 6 reads
set unverified (gap)where the history does not reachbase_seqwhole, see Check 6; otherwise the expected set is that ofnode_setsat or belowbase_seq, with the operations the window marks 1 on top;node_vulnsreads an operation below the window from the history, and isunknownwhen the history has no row for it, see Exposure.
tools/backend/test/history-base.sql shows nodes followed from seq 0 through four
windows, tools/backend/test/history-gap.sql nodes first seen, or seen again, past
their history, and tools/backend/test/vulns-history.sql a shield older than the
window.
The order of the refreshes does not matter: check 6 reads the history
at or below base_seq, which an earlier record put there, and check 4
also the rows of the window, which match the record they were folded
from. Check 4 and node_ops_mv find a contradiction from
history_conflicts themselves and do not wait for the mark.
A keepalive reports a node’s outcomes for the last 512
operations of its tree only (U20 of Threat model). A node first
heard from after its tree has grown past that window never tells the
backend which earlier operations it applied. Check 4 anchors its
history at that first record’s base_root and verifies the records
after it; comparing it with its peers (check 7) works from the start;
but check 6 stays set unverified (gap) for as long as the node
follows that tree, and node_vulns is unknown for shields added
before the window. Every node that joins a tree of more than 512
operations is in that case, and so is one that the backend did not
hear from while its tree moved on by more than 512 operations. Attest such a node with shirudo attest when its
loaded set matters.
Contradictions#
A record that does not extend a node’s history adds no rows. Two rules decide when it fails:
Where a record’s window overlaps the node’s stored history, it has to match the stored rows at every seq they share, as the top row of Figure 1 compares them:
base_rootthe root atbase_seq, and up to the lower oflast_seqand the end of the history the mask’s code and the folded root the stored ones. A gap row has no code, so only its root is compared. This holds for a window from seq 0 too. A mismatch fails check 4 asbase differs from historyorwindow differs from history at seq <seq>, naming the first seq that differs. The code is compared because the roots alone would miss an operation the node calls applied (1) in one record and attach module not loaded (3) in another: both chain the operation.shirudo.history_conflictsfinds these records.A node whose record once contradicted its history keeps failing until an operator clears its mark, so that a later gap cannot launder it: without the mark, a node whose window has moved past its stored history would start a gap like one not heard from, and pass. Once a minute
history_contradictions_mvadds a row toshirudo.history_contradictionsfor every node and tree inhistory_conflictsthat has none. While a node has a mark, check 4 fails asmarked: contradicted history at seq <seq>, unless its record contradicts its history now, which the line names instead, andnode_ops_mvadds nothing to its history, gap rows included.
The mark is stricter than the record that set it in three ways: it
holds for the node whatever tree its newest record follows and whatever
boot it comes from, and it fails check 4 even for a node whose record
check 4 otherwise skips (no tree, no mask, publication unknown).
A new boot does not clear it, since a node that lies once can reboot,
and nor does a gap.
Clear a mark once the node has been looked at, for example attested
with shirudo attest:
DELETE FROM shirudo.history_contradictions WHERE ak_name = '<ak_name>';
Its history then grows again from where it stopped. A record that
still contradicts it is marked again at the next refresh; one whose
window has moved past it starts a gap, as for a node not heard from.
To hold the node’s next records against nothing it said before, delete
its history with the mark, as for a node that is gone, see Maintain the backend.
tools/backend/test/history-base.sql shows both rules with edge-liar, which lies
about its base, and edge-swap, which lies inside its window. Watch
for gaps on nodes the backend heard from all along.
Size#
node_ops gains a row per node for every
operation the node processes, whatever its outcome, about 34 bytes on
disk, mostly the root: a publication of one operation to 10,000 nodes
adds 10,000 rows, and 10,000 nodes that each go through a tree of
65,000 operations hold about 650 million rows, some 22 GB. node_sets
holds a row per node and upatch the node ever applied, about 70 bytes.
Neither has a TTL, and nothing removes their rows but the operator:
trimming them would reopen the gaps they close, turning the base of
check 4, the set of check 6 and older shields in node_vulns back into
gap and unknown. A refresh reads one row of the projection per node
to find where its history ends, and the rows it needs at base_seq,
not the whole table.
No retention is chosen for node_ops and node_sets. It needs
measurements on real clusters, together with stale_seconds, which
decides how long a node may be silent, and the two grow as above.
window of shirudo.settings is not read: a node chooses its window
and says where it starts in base_seq, and the checks read what the
record has.