upatch tree#
A upatch tree is a signed, append-only list of add and delete
operations in one OCI repository, oci://<registry>/<repository>. The
operator publishes it with bpm tree append, one operation per
[upatches.tree] entry of a package. Every node reads it with bpm
tree sync, walks it in order and applies the operations whose selector
matches. The mask and projection_root of the keepalive
(Keepalive body) are a node’s account of that walk.
CBMC proves the target’s readers of the tree publication’s selectors and
operations, and the checks that keep a publication from taking a node
back, within the bounds Proof coverage lists.
Lean 4 proves that across any history of syncs, stops and reboots a
node’s generation, cursor and tree eventlog never go back and each
operation is applied at most once; CBMC shows that bpm tree sync
makes exactly the model’s writes.
Overview#
A tree lives in its own repository of a registry namespace, beside the
packages and the index of Package and index formats, as Figure 1 shows. Each
publication is one segment of operations, a signed document behind a
manifest. The tag <reference> names the current segment, and each
segment names the sealed one before it by digest. Each operation pins
the artifact manifest of its .upatch by digest. The sections below
define the objects and keys: Registry objects, Publication
document, Operation and Selector.
Figure 1. A tree and its namespace in the registry, with a node at seq 70 that is behind.#
Digests in the tree carry a sha256: prefix, as OCI does; the
keepalive leaves it out.
What is signed#
Object |
Protection |
Checked by |
|---|---|---|
Publication document |
Detached CMS signature over the exact document bytes. |
|
Artifact manifest and |
Not signed. Each signed operation pins them by
|
|
|
CMS signature, ML-DSA-87, over |
The kernel, at every load and unload. |
The detached signature uses the CMS profile of
Package and index formats: DER SignedData, no encapsulated content, no
certificates, ML-DSA-87, signer named by subject key identifier, checked
without a validity-time check against any active, enrolled BPF signer.
Names#
Name |
Source |
Rule |
|---|---|---|
|
|
A package name (Package and index formats). Fixed for the life of the
tree. Distinct from the operation |
Operation |
Beefile |
Must equal the upatch name of the artifact it publishes, so the
source file’s basename. |
Registry objects#
Object |
Content |
|---|---|
Publication manifest |
At |
Sealed segment |
A publication manifest that a later segment names in
|
Document layer |
The publication document, media type
|
Signature layer |
Detached CMS signature over the document layer’s bytes, media type
|
Artifact manifest |
One per operation, tagged |
Superseded generation |
A publication manifest that |
bpm tree append adds to the current segment or seals it and starts
the next, as Figure 2 shows; shirudo bpm gives the rule.
Figure 2. What an append of three operations does to a segment with room and to a full one.#
Publication document#
One JSON object per generation. Every append signs a new document that holds the segment’s operations so far.
{"schema": 1,
"tree_id": "<tree-id>",
"generation": <n>,
"parent_manifest_digest": "sha256:<hex>",
"base": {"seq": <b>,
"segment_manifest_digest": "sha256:<hex>",
"history_root": "<hex>"},
"operations": [<operation>, ...],
"head": {"seq": <n>}}
Key |
Value |
|---|---|
|
|
|
A package name. Required. |
|
Required. 1 for the first publication, one more for each append. From 0 to 263 - 2. |
|
Digest of the publication manifest this one replaces. Absent in the first publication. |
|
Required. 0 for the first segment of the tree, otherwise the
|
|
Required when |
|
Required when |
|
Required. At most 512. Each |
|
Required. The |
Unknown keys are ignored.
Operation#
One step of the tree: load or unload one upatch on the nodes its
selector matches. There is no replace: a new build of a loaded upatch is
a delete of the old one followed by an add of the new, since a
node cannot load a second upatch under a name already loaded.
{"seq": <n>, "op": "add", "id": "<upatch-name>",
"selector": {...},
"artifact": {"repository": "oci://<registry>/<repository>",
"manifest_digest": "sha256:<hex>",
"layer_digest": "sha256:<hex>",
"payload_sha256": "sha256:<hex>"},
"fixes": ["<advisory-id>", ...],
"operation_digest": "sha256:<hex>"}
Key |
Value |
|---|---|
|
Positive sequence number. |
|
|
|
The upatch name of the artifact. Must be a valid upatch name. |
|
Which nodes apply the operation, see Selector. |
|
|
|
Digest of the artifact manifest. |
|
Digest of the |
|
|
|
Optional, on an |
|
|
Selector#
Every key present must match. A list matches when one value matches.
Lists hold at least one value, and an option or label appears once in
kconfig and kernel_config together or in labels: the node
refuses a publication otherwise.
Key |
Type |
Matches when |
|---|---|---|
|
list of strings |
One value equals |
|
list of strings |
The kernel release starts with the value, followed by the end, a
|
|
list of strings |
One value equals the kernel’s GNU build ID from
|
|
object of lists |
For each option, its value in |
|
object of lists |
For each key, the node label’s value is in the list. Node labels
come from |
Lists hold 1 to 16 strings of fewer than 256 bytes. kconfig and
labels hold at most 64 keys each.
Operation digest#
operation_digest is the SHA-256 of the compact JSON of the operation
without operation_digest and fixes, in this form:
Keys in the order
seq,op,id,selector,artifact.selectorkeys in byte order:architecture,kconfig,kernel_build_id,kernel_release_prefix,labels. Empty lists are left out.kconfigandlabelskeys in byte order.List values in the published order.
bpm tree appendsorts them in byte order before it publishes.artifactkeys in the orderrepository,manifest_digest,layer_digest,payload_sha256.
The target recomputes the digest from the parsed operation and refuses the
publication when one differs. The digest of each applied operation enters
the measurement register as a tree_op event, see
Eventlog events.
From the Beefile#
Operations come from a package’s Beefile. Each [[upatches]] entry
with a [upatches.tree] table becomes one operation when bpm tree
append publishes the package: an add by default, a delete with
--op delete. Beefile gives the keys; the selector tables
become selector, with each list sorted in byte order.
[[upatches]]
source = "xfs-fix.bpf.c"
[upatches.tree]
id = "xfs-fix"
[upatches.tree.selector]
kernel_release_prefix = ["7.4"]
[upatches.tree.selector.kconfig]
CONFIG_XFS_FS = ["y", "m"] # published as ["m", "y"]
publishes an operation with this selector:
{"kconfig": {"CONFIG_XFS_FS": ["m", "y"]}, "kernel_release_prefix": ["7.4"]}
Target acceptance#
bpm tree sync applies a publication only when all of these hold:
The manifest has one document layer and one signature layer, each matching its descriptor’s digest and size.
The signature verifies against the active config’s non-revoked BPF signer set.
The document parses with the rules above,
tree_idis a package name, and every operation has a validid,opand digests and a correctoperation_digest.tree_idequals the one the node recorded.A publication other than the recorded one has a higher
generation. A direct successor that names aparent_manifest_digestnames the recorded manifest.head.seqis not below the node’s last appliedseq.When
base.seqlies past the node’s last appliedseq, 0 for a node without a state, the node walks back to it through the sealed segments, see Walk.Base check: the
history_rootof the node’soutcomesatbase.seq, 32 zero bytes at 0, equalsbase.history_root.Prefix check: the publication’s operation digests, folded from
base.history_rootup to the node’s last appliedseq, give the node’shistory_rootthere. This applies to every publication, so a registry that serves operations other than the ones a node already processed, inside a segment or at its base, is refused withEKEYREJECTED.
The node then records the publication, see Node records, and processes
the operations after its last applied seq.
For each new operation whose selector matches, the target then fetches the
artifact manifest by manifest_digest, takes the layer with
layer_digest and media type application/vnd.shirudo.upatch.v1,
checks its digest and size, and refuses the .upatch unless its header
payload_sha256 equals artifact.payload_sha256, its name equals
id and it is an unload directive exactly when op is delete.
Walk#
A node behind the segment that <reference> names walks back to the
segment its last applied seq lies in and then applies the segments
forwards, as Figure 1 shows. It keeps the manifest digest, base.seq,
head.seq and generation of each segment, not the documents.
While the oldest segment so far starts past the node’s last applied
seq, the node refuses the sync when the distance between the two exceeds the walk limit (E2BIG), see Limits, then fetchesmanifests/<base.segment_manifest_digest>. The sealed segment must pass checks 1 to 3 above, hash to that digest, have the sametree_id, end at its successor’sbase.seqand have a lowergeneration(ERANGE). A segment the registry does not serve refuses the sync; the node never skips ahead.Oldest first, the node fetches each sealed segment again by its digest and checks it as before, then runs checks 4 to 9 and applies it as above. The segment
<reference>names, which the walk holds, comes last.
An operation left in progress is completed against the oldest segment of
the walk alone: the node records a segment before it processes it, so the
operation lies in the segment its state names. state.json moves at
each applied operation and at each segment recorded, so a walk that stops
resumes with a shorter one. A reboot never walks: init reads
state.json alone.
Outcomes#
A node records one outcome for every operation it processes, in its
outcomes record (Node records). The keepalive reports the same
outcome as the operation’s two bits of mask.
|
|
Operation |
Loads or unloads |
Into the chain and register |
|---|---|---|---|---|
1 |
|
The selector matched and the operation was applied. |
yes |
yes |
2 |
|
The selector did not match: passed over for good. |
no |
no |
3 |
|
The selector matched, but an |
no |
yes |
none |
|
Not reached yet: past |
no |
no |
For outcomes 1 and 3, projection_root becomes the SHA-256 of the
previous root followed by the raw operation_digest, starting from 32
zero bytes, and the operation enters the measurement register as a
tree_op event.
Node records#
The target keeps these under /var/lib/shirudo/bpm/upatch-tree/. They are
not published. Each JSON object carries schema (1).
state.json#
The publication the node last accepted and how far it got.
Key |
Value |
|---|---|
|
Of the publication the node last accepted. |
|
The publication’s |
|
The last operation processed, applied or passed over because its selector does not match. |
|
The node’s projection root, see |
A sync records a publication, each segment of a walk in turn, once it
passes the checks above and an interrupted operation is completed, and
before it processes the first new operation of it. A sync that stops
among them leaves last_seq from segment_base_seq to head_seq,
and the node refuses an older generation from then on. A state without
one of tree_id, last_seq, the two roots, head_seq and
segment_base_seq is refused.
tree-eventlog#
One JSON object per line and applied operation, with seq, digest
(the operation_digest) and projection_root. projection_root
is the SHA-256 of the previous root followed by the raw operation
digest, starting from 32 zero bytes. A last line without its newline is
an append that did not finish: the replay skips it and the next append
drops it.
outcomes#
One JSON object per line and processed operation, in order from seq
1. Nothing rebuilds or prunes the file: the keepalive reads its last 512
operations from it whatever segments held them
(shirudo status).
Key |
Value |
|---|---|
|
The operation. |
|
1 applied, 2 selector did not match, 3 an |
|
The node’s projection root after the operation, which an unmatched one leaves where it was. |
|
The SHA-256 of |
A line at or below last_seq is never rewritten. A sync refuses a
state with last_seq above 0 whose outcomes is missing
(ENOENT), or has a gap or a malformed line or ends before
last_seq (EBADMSG).
pending.json#
seq, id and operation_digest of the operation in progress.
A sync removes it once state.json records the operation applied. When
a later sync passes the operation without applying it, as one the
selector no longer matches, the record stays until the next sync, whose
recovery removes a record at or below the cursor whatever the
publication holds.
Other files#
File |
Content |
|---|---|
|
Fetched artifacts, named by their layer digest. |
|
|
Order of the writes#
The order in which a sync writes is what makes it safe to stop at any
point. An operation whose selector does not match gets its outcomes
line, outcome 2, and moves last_seq. One that matches is applied in
this order:
pending.jsonis written.The artifact is fetched and checked, then loaded for an
addor unloaded for adelete.The measurement register is extended.
The
tree-eventlogline is appended.The
outcomesline is appended and synced to disk.state.jsonmoves to the operation.status/<id>is written for anaddwhose module is not loaded, and removed otherwise.pending.jsonis removed.
The next sync does this with what a stopped one left:
It drops
outcomeslines pastlast_seqand a last line without its newline before it appends.With a
pending.json, it completes the operation, without applying it again when the tree eventlog or this boot’s eventlog already records it, and applies it again otherwise. Anaddapplied again whose upatch the stopped sync already loaded with its payload counts as installed.Completing it writes the
outcomeslines the stopped sync did not commit: outcome 2 for each operation betweenlast_seqand the pending one, which that sync passed over, then the pending operation’s, 3 when it is anaddwhose upatch is not loaded, with itsstatus/<id>, and 1 otherwise.
Files, paths and xattrs lists every file shirudo keeps.
Limits#
Item |
Limit |
|---|---|
Operations per publication |
512 |
Values per selector list |
16, of fewer than 256 bytes |
|
64 each |
Walk of a node that has processed an operation,
|
65,536 operations from its last applied |
Walk of a node that has processed none, |
1,048,576 operations from |
JSON document |
8 MiB |
Detached signature |
64 KiB (writer) |
A walk past its limit refuses the sync with E2BIG before it fetches a
sealed segment, see Walk. The bound is on the distance from the node’s
last applied seq, not on the size of the tree. A node that has
applied nothing holds no upatch of the tree yet and is joining, so it
gets the higher limit; a running node walks holding the bpm lock, which
stops its keepalive, and gets the lower one. A higher limit only allows
more verified fetches and never makes a node accept what it would
otherwise refuse. Join time grows linearly with the tree: each segment
of a walk costs two fetches of its manifest, document and signature and
two signature checks, so a node that joins at the limit with the default
64 operations per segment walks 16,384 segments, about 100,000 registry
requests, besides fetching, loading and measuring each operation its
selectors match. Both limits are compile-time defines, settled for now
and to be revisited by experiment on live clusters; a node further
behind than its limit is refused every sync of the tree.
Example#
Generation 3 of a tree fleet-base: three packages published, then
kernel-obs replaced by a new build, a delete of the old one and
an add of the new. artifact objects and digests are left out.
{"schema": 1, "tree_id": "fleet-base", "generation": 3,
"parent_manifest_digest": "sha256:<hex>",
"base": {"seq": 0},
"operations": [
{"seq": 1, "op": "add", "id": "kernel-obs", "selector": {}, ...},
{"seq": 2, "op": "add", "id": "net-guard",
"selector": {"architecture": ["x86_64"], "labels": {"role": ["edge"]}}, ...},
{"seq": 3, "op": "add", "id": "xfs-fix",
"selector": {"kconfig": {"CONFIG_XFS_FS": ["m", "y"]},
"kernel_release_prefix": ["7.4"]}, ...},
{"seq": 4, "op": "delete", "id": "kernel-obs", "selector": {}, ...},
{"seq": 5, "op": "add", "id": "kernel-obs", "selector": {}, ...}],
"head": {"seq": 5}}
How three nodes walk it, with the outcome of each operation as its
mask bits:
Operation |
Node A: |
Node B: |
Node C: |
|---|---|---|---|
1 |
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
Loaded |
|
|
|
Chained |
1 to 5 |
1, 4, 5 |
1, 3, 4, 5 |
|
|
|
|
Each node’s keepalive reports last_seq 5, its mask and its
projection_root, folded from the digests of the operations it
chained.