Latest state#

Reference · Operators

Small tables kept current on every insert so the checks never scan the audit store: each node’s newest record, and each boot’s first tamper total and when its newest record came first.

Schema: tools/backend/sql/30-latest.sql

Views, functions and jobs#

shirudo.keepalive_latest_mv

materialized view, on insert.

checked → keepalive_latest for accepted rows.

shirudo.boot_first_mv

materialized view, on insert.

checked → boot_first, aggregating per (ak_name, boot_id).

shirudo.boot_first_keep_mv

refreshable MV, every 1 hour, APPEND.

Rewrites the baseline of every node’s current boot with last_used = now(), so the TTL only removes boots a node has left.

shirudo.keepalive_latest#

Stored

The newest record of each node by the TPM’s own counters. A late record never replaces a newer one; the newest one received again replaces itself, with the time of the copy.

  • Read with FINAL.

  • Same columns as keepalive, minus quote, plus order_key.

Engine:

ReplacingMergeTree(order_key)

Order by:

ak_name

Defined in:

tools/backend/sql/30-latest.sql

Written by:

keepalive_latest_mv on insert into checked

Fires on insert:

nothing

Queried by:

boot_first_keep_mv into boot_first; latest (view); node_label_items (view); history_conflicts (view); node_ops_mv into node_ops

Row size:

~1.5 KB per node (estimate: body plus its parsed columns; one row per node, so little cross-row compression).

Scale:

Nodes after a merge. Before one, up to one row per record received since the last merge.

Reference fleet:

≈ 15 MB

Columns (30)

Column

Type

Meaning

ak_name

String

Node identity; the sort key.

order_key

UInt64

reset_count << 40 | clock. Highest wins.

received

DateTime64(3)

When the backend received the record, or a copy of it. Retention counts from it. Freshness (check 2) does not: it reads newest_received of boot_first.

time

DateTime64(9)

The OTLP Timestamp the target put on the log record. Not trusted for ordering.

host_name

String

host.name resource attribute: what the node claims to be called. Not an identity.

body

String CODEC(ZSTD(1))

The newest record’s signed body.

reset_count

UInt32

TPM reset counter of the newest record.

clock

UInt64

TPM clock of the newest record.

schema

LowCardinality(String)

Body schema. Must be shirudo.keepalive/1 or 1.x, else the record is rejected as schema.

boot_id

String

Identifies the boot that sent the record. Tamper baselines in boot_first are per boot.

version_id

String

Build identifier of the shirudo binary: SHA-256 over its git commit (with -dirty), config.mk and Makefile.shirudo. Printed by shirudo version –version-id. Check 3 requires it to be in expected_builds.

config_root

Nullable(String)

Digest of the node’s configuration. One of the keys that groups peers for check 7.

kernel_release

LowCardinality(String)

Running kernel, e.g. 7.4.2. Groups peers (check 7) and is matched against kernel_vulns via kver().

image_id

Nullable(String)

OS image the node says it booted. Joins to sbom_images.

image_version

Nullable(String)

Version of that image.

image_root

Nullable(String)

Verity root of the image. When it matches the SBOM’s root the binding is verified.

verdict

LowCardinality(String)

The node’s own overall verdict. Check 3 requires ok.

cond

UInt64

Condition pairs, two bits each. Check 3 requires the low seven pairs to read 0x1555 (all OK).

flags

UInt64

Bits 0–3 are faults and fail check 3 (bit 2: outcomes file damaged, bit 3: tamper counters unreadable). Bit 4: sync in progress. Bit 5: snapshot unsettled.

tamper

Array(UInt64)

Tamper counters. Their sum must not rise within a boot (check 3). Empty when unreadable.

tree_id

Nullable(String)

The upatch tree the node follows. NULL means no tree, and checks 4–7 are skipped.

generation

Nullable(UInt64)

Publication generation of the tree the node has seen.

base_seq

Nullable(UInt64)

The record’s window starts after this operation seq (exclusive).

last_seq

Nullable(UInt64)

Last operation the node has applied (inclusive end of the window).

base_root

Nullable(String)

Hash-chain root at base_seq, 64 hex digits.

projection_root

Nullable(String)

Hash-chain root after last_seq. Check 4 refolds the tree to reproduce it.

mask

Nullable(String)

Base64, two bits per operation in the window: 1 applied, 2 selector did not match, 3 attach module not loaded, 0 not reached. Decoded by mask_code().

set_sha256

String

Hash of the upatch set the node has loaded. Check 6 recomputes it.

count

UInt64

Number of upatches loaded. Shown as loaded in node_status.

not_ok

UInt64

Reported by the node and stored. No check reads it.

shirudo.boot_first#

Stored

Per node and boot, the tamper total of the first record that could read the counters. Check 3 fails if the current total is higher.

  • A record with empty tamper does not set the baseline (argMinStateIf … notEmpty(tamper)).

  • A TTL drops a row from its part regardless of newer parts. Without the hourly rewrite, a boot longer than the retention would lose its oldest row and its baseline would move later, hiding a rise. docs/boot-baselines.md explains it.

Engine:

AggregatingMergeTree

Order by:

(ak_name, boot_id)

TTL:

last_used + INTERVAL 2592000 SECOND. The default of boot_first_retention_seconds in settings, set by tools/backend/sql/apply-retention.sh

Defined in:

tools/backend/sql/30-latest.sql

Written by:

boot_first_mv on insert into checked; boot_first_keep_mv (refresh every 1 hour, append)

Fires on insert:

nothing

Queried by:

boot_first_keep_mv into boot_first; node_status_mv into node_status

Row size:

~150 B (estimate).

Scale:

Nodes × boots with a record in the last 30 days, plus each node’s current boot, which is kept indefinitely.

Reference fleet:

~3 boots each: 30k rows ≈ 5 MB

Columns (6)

Column

Type

Meaning

ak_name

String

Node.

boot_id

String

Boot.

first_order_key

SimpleAggregateFunction(min, UInt64)

order_key of the boot’s first record.

tamper_first

AggregateFunction(argMin, UInt64, UInt64)

arraySum(tamper) at the lowest order_key with readable counters. Read with argMinMerge.

newest_received

AggregateFunction(argMax, DateTime64(3), Tuple(UInt64, Int64))

When the boot’s record with the highest order_key was first received. Check 2 reads the age of a node’s newest record here, so that a copy of it sent again does not make it fresh. Read with argMaxMerge.

last_used

SimpleAggregateFunction(max, DateTime)

Last record received for the boot, or last time the hourly job found it to be the node’s current boot.