Skip to content

eBPF-based security platform

backend: read a record's age from when it first arrived

John Fastabend241fcb186365
diff --git a/Documentation/operate/backend/boot-baselines.rst b/Documentation/operate/backend/boot-baselines.rst
index 92d30b53..83002459 100644
--- a/Documentation/operate/backend/boot-baselines.rst
+++ b/Documentation/operate/backend/boot-baselines.rst
@@ -41,7 +41,9 @@ How a row is written and read
- ``shirudo.boot_first_mv`` writes a row for every accepted record as it
is ingested, keyed by the record's ``ak_name`` and ``boot_id``. The table
is an AggregatingMergeTree: the rows of one boot merge into one, which
- keeps the total of the earliest record.
+ keeps the total of the earliest record. The same row keeps when the
+ boot's newest record was first received, which check 2 reads for the
+ record's age (:doc:`status`).
- The refresh of ``node_status`` joins a node's newest record to the row
with the same ``ak_name`` and ``boot_id``, and check 3 compares the
record's total with that baseline. A rise fails the check.
diff --git a/Documentation/operate/backend/status.rst b/Documentation/operate/backend/status.rst
index 262a56c5..6dd41265 100644
--- a/Documentation/operate/backend/status.rst
+++ b/Documentation/operate/backend/status.rst
@@ -86,7 +86,7 @@ A UI reads ``node_status`` as often as it likes, as :doc:`xtop` does:
* - ``log``
- Seven lines, one per check in order.
* - ``last_seen``
- - When the newest record was received.
+ - When the newest record was first received.
* - ``generation``, ``last_seq``
- From the newest record; ``NULL`` for a node that follows no tree.
* - ``head_seq``
@@ -101,11 +101,19 @@ Checks
``status`` is:
-- ``stale`` when the newest record was received more than ``stale_seconds``
- ago, 10 minutes by default. It wins over everything else, because the
- other lines then describe old data; the ``log`` still shows what that
- record said. A node whose records are all refused gets no new record
- and turns stale.
+- ``stale`` when the newest record was first received more than
+ ``stale_seconds`` ago, 10 minutes by default. It wins over everything
+ else, because the other lines then describe old data; the ``log`` still
+ 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 later
+ ``clock`` or ``reset_count`` is news, and only the node's TPM signs
+ one. ``shirudo.boot_first`` keeps 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
@@ -135,7 +143,7 @@ passed. Checks 3 to 6 have a section each below.
- Never fails
* - 2
- ``2 fresh:``
- - The newest record, by the quote's ``reset_count`` and ``clock``, was received at most ``stale_seconds`` ago.
+ - The newest record, by the quote's ``reset_count`` and ``clock``, was first received at most ``stale_seconds`` ago.
- ``FAIL``
* - 3
- ``3 reported:``
diff --git a/Documentation/operate/backend/tables/latest.rst b/Documentation/operate/backend/tables/latest.rst
index e03b4f1e..7930abb9 100644
--- a/Documentation/operate/backend/tables/latest.rst
+++ b/Documentation/operate/backend/tables/latest.rst
@@ -9,7 +9,8 @@ Latest state
============
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.
+store: each node's newest record, and each boot's first tamper total and when its
+newest record came first.
Schema: :src:`tools/backend/sql/30-latest.sql`
@@ -44,16 +45,18 @@ shirudo.keepalive_latest
:reference: ≈ 15 MB
:bytes: 1.5e+07
- The newest record of each node by the TPM's own counters. A late or
- repeated record never replaces a newer one.
+ 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.
:ak_name: Node identity; the sort key.
:order_key: reset_count << 40 \| clock. Highest wins.
- :received: When the backend received the record. Freshness (check 2) and
- retention count from it.
+ :received: 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: The OTLP Timestamp the target put on the log record. Not trusted for
ordering.
:host_name: host.name resource attribute: what the node claims to be called. Not
@@ -127,5 +130,8 @@ shirudo.boot_first
:first_order_key: order_key of the boot's first record.
:tamper_first: arraySum(tamper) at the lowest order_key with readable counters. Read
with argMinMerge.
+ :newest_received: 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: Last record received for the boot, or last time the hourly job found
it to be the node's current boot.
diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rst
index 8ee20dc5..1d1a792b 100644
--- a/Documentation/security/threat-model.rst
+++ b/Documentation/security/threat-model.rst
@@ -1785,7 +1785,10 @@ R17 Telemetry has no proof of origin
``attest``, created for each keepalive, over no PCR, and
``shirudo-quote-check`` verifies it without a TPM. A quote that
checks proves that the body is unchanged since that key signed it,
- and its clock orders the keepalives of one key. It does not prove
+ and its clock orders the keepalives of one key. A keepalive sent
+ again checks as it did the first time: a backend has to take a
+ record's age from when its clock first arrived, as the example
+ backend's check 2 does, or a silent node reads as alive. It does not prove
that the key lives in a genuine TPM: only ``attest challenge`` ties
the key to an endorsement key, and a backend treats every node as
``untrusted`` until a future workflow does that. Nor does it vouch
diff --git a/tools/backend/sql/30-latest.sql b/tools/backend/sql/30-latest.sql
index 475024fb..1f15287c 100644
--- a/tools/backend/sql/30-latest.sql
+++ b/tools/backend/sql/30-latest.sql
@@ -6,8 +6,10 @@
-- kept up to date as records arrive.
-- The record with the highest order_key of each node, which is its
--- newest by the TPM's own counters. A record that arrives late or again
--- does not replace a newer one.
+-- newest by the TPM's own counters. A record that arrives late does not
+-- replace a newer one. The newest record sent again does replace itself,
+-- received included, which is why no check reads received here for the
+-- age of a record: boot_first has when it came first.
CREATE TABLE IF NOT EXISTS shirudo.keepalive_latest
(
ak_name String,
@@ -55,6 +57,12 @@ WHERE reject = '';
-- whose tamper is null has no total and does not set the baseline; it
-- reads as an empty array here.
--
+-- newest_received is when the boot's newest record, by order_key, was
+-- received first. Check 2 reads its age and not the age of the row in
+-- keepalive_latest, which a record sent again replaces with the time of
+-- the copy: whoever holds a node's last record could keep a node that
+-- sends no more from turning stale.
+--
-- last_used is when a record of the boot was last received, or when
-- boot_first_keep_mv last found the boot to be its node's current one,
-- and a row leaves that long after it as the TTL says. The TTL here is
@@ -66,6 +74,7 @@ CREATE TABLE IF NOT EXISTS shirudo.boot_first
boot_id String,
first_order_key SimpleAggregateFunction(min, UInt64),
tamper_first AggregateFunction(argMin, UInt64, UInt64),
+ newest_received AggregateFunction(argMax, DateTime64(3), Tuple(UInt64, Int64)),
last_used SimpleAggregateFunction(max, DateTime)
)
ENGINE = AggregatingMergeTree
@@ -78,6 +87,7 @@ SELECT
boot_id,
min(order_key) AS first_order_key,
argMinStateIf(arraySum(tamper), order_key, notEmpty(tamper)) AS tamper_first,
+ argMaxState(received, (order_key, -toUnixTimestamp64Milli(received))) AS newest_received,
max(toDateTime(received)) AS last_used
FROM shirudo.checked
WHERE reject = ''
@@ -98,6 +108,7 @@ SELECT
b.boot_id AS boot_id,
min(b.first_order_key) AS first_order_key,
argMinMergeState(b.tamper_first) AS tamper_first,
+ argMaxMergeState(b.newest_received) AS newest_received,
now() AS last_used
FROM shirudo.boot_first AS b
INNER JOIN shirudo.keepalive_latest AS k FINAL ON k.ak_name = b.ak_name AND k.boot_id = b.boot_id
diff --git a/tools/backend/sql/40-status.sql b/tools/backend/sql/40-status.sql
index a6fdd5e5..d3be2c56 100644
--- a/tools/backend/sql/40-status.sql
+++ b/tools/backend/sql/40-status.sql
@@ -579,7 +579,8 @@ WITH
),
boot AS
(
- SELECT ak_name, boot_id, argMinMerge(tamper_first) AS tamper_first
+ SELECT ak_name, boot_id, argMinMerge(tamper_first) AS tamper_first,
+ argMaxMerge(newest_received) AS newest_received
FROM shirudo.boot_first
GROUP BY ak_name, boot_id
),
@@ -604,13 +605,16 @@ WITH
result AS
(
SELECT k.node_id AS node_id, k.ak_name AS ak_name, k.host_name AS host_name, k.trust AS trust,
- k.received AS received, k.generation AS generation, k.last_seq AS last_seq,
+ -- A copy of the newest record has a later received and
+ -- the same order_key; the boot knows the first.
+ if(b.ak_name = '', k.received, least(k.received, b.newest_received)) AS received,
+ k.generation AS generation, k.last_seq AS last_seq,
k.count AS count, k.set_sha256 AS set_sha256, k.verdict AS verdict, k.cond AS cond,
k.flags AS flags, k.version_id AS version_id, k.projection_root AS projection_root,
k.skip AS skip, k.newest AS newest, k.head AS head, k.p_last AS p_last,
p.n AS n,
r.rejected AS rejected,
- dateDiff('second', k.received, now64(3)) AS age_s,
+ dateDiff('second', received, now64(3)) AS age_s,
age_s > stale_after AS stale,
-- A record that could not read its counters has no total
-- to compare; flags bit 3 says so and fails the check.
diff --git a/tools/backend/test/status-stale.expected b/tools/backend/test/status-stale.expected
index 987504b9..024d5ba7 100644
--- a/tools/backend/test/status-stale.expected
+++ b/tools/backend/test/status-stale.expected
@@ -1,7 +1,10 @@
+received again 1
fresh healthy 0 1 3 reported: pass, verdict ok, cond 0x1555, flags 0, tamper +0, build d6d918ad
+replayed stale 2 0 3 reported: pass, verdict ok, cond 0x1555, flags 0, tamper +0, build d6d918ad
silent stale 2 0 3 reported: pass, verdict ok, cond 0x1555, flags 0, tamper +0, build d6d918ad
silent-and-degraded stale 2 0 3 reported: FAIL, verdict degraded, cond 0x1555, flags 0, tamper +0, build d6d918ad
fresh fresh stale untrusted 2 3 3 3 1
+replayed replayed stale untrusted 2 3 3 3 1
silent silent stale untrusted 2 3 3 3 1
silent-and-degraded silent-and-degraded stale untrusted 2 3 3 3 1
fresh 1 signed: pass, untrusted, 0 rejected in the last hour
@@ -10,4 +13,4 @@ fresh 3 reported: pass, verdict ok, cond 0x1555, flags 0, tamper +0, build d6d91
fresh 4 chain: pass, root 15452248
fresh 5 head: pass, seq 3 of 3, generation 3
fresh 6 set: pass, 1 loaded
-fresh 7 peers: pass, 3 in group
+fresh 7 peers: pass, 4 in group
diff --git a/tools/backend/test/status-stale.sql b/tools/backend/test/status-stale.sql
index eaa40700..89fc74f3 100644
--- a/tools/backend/test/status-stale.sql
+++ b/tools/backend/test/status-stale.sql
@@ -4,7 +4,9 @@
-- A node whose newest record is older than stale_seconds is stale with
-- failed_check 2, whatever that record says, and its log still shows what
-- it said. The threshold comes from shirudo.settings, lowered here to four
--- seconds: a node turns stale while the test waits six.
+-- seconds: a node turns stale while the test waits six. A record sent
+-- again is no newer than it was: the node "replayed" sent its only record
+-- a minute ago, and the copy that arrives now leaves it stale.
-- The publication of testing/fixtures/keepalive/tree-1.1.0.json, as the
-- ingest job loads it: generation 3 with its three operations.
@@ -44,10 +46,18 @@ FROM
(
SELECT arrayJoin([
('silent', 'node-a-1.1.0', [('"flags":0', '"flags":0')]),
+ ('replayed', 'node-a-1.1.0', [('"flags":0', '"flags":0')]),
('silent-and-degraded', 'node-a-1.1.0', [('"verdict":"ok"', '"verdict":"degraded"')])
]) AS node
) AS n
INNER JOIN fixture AS f ON f.name = node.2;
+
+INSERT INTO shirudo.checked (host_name, body, ok, ak_name, ak_public, reset_count, clock)
+SELECT 'replayed', body, 1, '000breplayed', 'QUtB', 1, 1000
+FROM fixture WHERE name = 'node-a-1.1.0';
+SELECT 'received again', dateDiff('second', received, now64(3)) < 30
+FROM shirudo.keepalive_latest FINAL WHERE ak_name = '000breplayed';
+
SYSTEM REFRESH VIEW shirudo.node_status_mv;
SYSTEM WAIT VIEW shirudo.node_status_mv;