Skip to content

eBPF-based security platform

docs: pull in keepalive, beefile, otlp, etc references

John Fastabend3e58f2b14691
diff --git a/.agents/skills/docs/SKILL.md b/.agents/skills/docs/SKILL.md
index cc247d71..30b82a80 100644
--- a/.agents/skills/docs/SKILL.md
+++ b/.agents/skills/docs/SKILL.md
@@ -31,9 +31,10 @@ Then go through the pages each kind of change has:
| File or directory | `reference/files.rst` |
| systemd unit | `reference/systemd-units.rst` |
| Environment variable | `reference/environment.rst` |
-| Setting | `reference/formats/configuration.rst` |
-| `.upatch`, bpm, eventlog, OTLP or status JSON format | `reference/formats/<format>.rst` |
-| Beefile key | `upatches/publish/beefile.rst` |
+| Setting | `reference/configuration.rst` |
+| Eventlog event | `reference/eventlog.rst` |
+| `.upatch`, Beefile, upatch tree, package and index, status JSON, OTLP, keepalive or map export format | `reference/formats/<format>.rst` |
+| Beefile key | `reference/formats/beefile.rst` |
| Threat closed or opened, residual risk | `security/threat-model.rst` |
| Test or fuzz target | `contribute/testing/test-coverage.rst` |
| Carried kernel patch | `internals/kernel-patches.rst` |
diff --git a/.agents/skills/upatch/SKILL.md b/.agents/skills/upatch/SKILL.md
index e47debf4..85ce43b9 100644
--- a/.agents/skills/upatch/SKILL.md
+++ b/.agents/skills/upatch/SKILL.md
@@ -113,7 +113,7 @@ shirudo build --unload <name> --keys-dir <keys> -o <name>.unload.upatch \
## Build a package
-The Beefile (`publish/beefile.rst`) names the package and its upatches,
+The Beefile (`reference/formats/beefile.rst`) names the package and its upatches,
and optionally generated `.rodata` (`[[upatches.rodata]]`), tree
metadata (`[upatches.tree]`) and extra files. A `README.md` beside it
is what `bpm info` prints.
diff --git a/Documentation/concepts/background/opentelemetry.rst b/Documentation/concepts/background/opentelemetry.rst
index fab7379d..f39a0163 100644
--- a/Documentation/concepts/background/opentelemetry.rst
+++ b/Documentation/concepts/background/opentelemetry.rst
@@ -162,7 +162,7 @@ settings in ``etc/shirudo/shirudo.conf`` of the signed config image. Both
units also read ``/etc/shirudo/map-export.env``, which carries the
``OTEL_EXPORTER_OTLP_*`` headers, CA certificate, client certificate and
key, compression and timeout, and the ``AWS_*`` credentials for S3.
-:doc:`/reference/formats/configuration` lists the settings, and
+:doc:`/reference/configuration` lists the settings, and
:doc:`/reference/formats/otlp` the documents on the wire.
The connection uses TLS 1.3 with a hybrid ML-KEM key exchange, the same
diff --git a/Documentation/concepts/background/pqc.rst b/Documentation/concepts/background/pqc.rst
index f40e6fb6..40ff22e3 100644
--- a/Documentation/concepts/background/pqc.rst
+++ b/Documentation/concepts/background/pqc.rst
@@ -234,4 +234,4 @@ Related
- :doc:`tpm`
- :doc:`oci`
- :doc:`/operate/maintain/keys`
-- :doc:`/reference/formats/configuration`
+- :doc:`/reference/configuration`
diff --git a/Documentation/concepts/glossary.rst b/Documentation/concepts/glossary.rst
index c89e9889..d9ca5923 100644
--- a/Documentation/concepts/glossary.rst
+++ b/Documentation/concepts/glossary.rst
@@ -56,7 +56,7 @@ it.
package directory, that names the package and lists its upatch
sources, read-only data generators, extra files and tree selectors.
``shirudo bpm build`` reads ``Beefile`` in the package directory, or
- the file that ``--file`` names. See :doc:`/upatches/publish/beefile`.
+ the file that ``--file`` names. See :doc:`/reference/formats/beefile`.
BPF keyring
The kernel's ``.bpf`` keyring, which the kernel uses for a signed
@@ -140,7 +140,7 @@ it.
boot ID and the fields the digest covers. shirudo only appends to it
and keeps the records of every boot. A verifier trusts it only as
far as this boot's records replay to the value the TPM certifies.
- See :doc:`/reference/formats/eventlog`.
+ See :doc:`/reference/eventlog`.
evidence
The JSON document, of kind ``shirudo-attestation``, that ``shirudo
diff --git a/Documentation/concepts/measurement-register.rst b/Documentation/concepts/measurement-register.rst
index 4f88e93d..462307d7 100644
--- a/Documentation/concepts/measurement-register.rst
+++ b/Documentation/concepts/measurement-register.rst
@@ -132,7 +132,7 @@ reports it under the ``UpatchesMeasured`` condition, the next load or
unload undoes it before it acts, and ``init`` at the next boot restores
no archive whose load the eventlog does not record. An unload is
measured before the pins go, so an interrupted unload leaves a register
-that records more than happened. :doc:`/reference/formats/eventlog`
+that records more than happened. :doc:`/reference/eventlog`
lists the fields of each event.
Eventlog
diff --git a/Documentation/concepts/upatches-and-packages.rst b/Documentation/concepts/upatches-and-packages.rst
index 8c635a20..0fa4ca98 100644
--- a/Documentation/concepts/upatches-and-packages.rst
+++ b/Documentation/concepts/upatches-and-packages.rst
@@ -119,7 +119,7 @@ Its definition is a Beefile, a file in a subset of TOML in the package
directory. The Beefile names the package and lists its upatch sources,
optional generators for read-only data, extra files to ship and, per
upatch, the selector it gets when published to an upatch tree.
-:doc:`/upatches/publish/beefile` describes every key.
+:doc:`/reference/formats/beefile` describes every key.
``shirudo bpm build`` builds and signs every upatch the Beefile lists,
together with its unload directive, and writes ``<name>-<version>.bee``.
@@ -188,7 +188,7 @@ The target keeps a projection root, a hash chain over the operations it
applied, and the next boot's init event includes it. The register value
an operator predicts therefore covers the tree as well as the archived
upatches. :doc:`/upatches/publish/publishing` shows how to publish to a tree,
-and :doc:`/reference/formats/bpm-formats` gives the document formats.
+and :doc:`/reference/formats/upatch-tree` gives the document formats.
How the objects relate
----------------------
diff --git a/Documentation/contribute/code/develop-locally.rst b/Documentation/contribute/code/develop-locally.rst
index cfe1cb41..c4ae776b 100644
--- a/Documentation/contribute/code/develop-locally.rst
+++ b/Documentation/contribute/code/develop-locally.rst
@@ -412,7 +412,7 @@ Watch the data
The body is what the decoder returned, shortened here. It counts
every execution on the guest, the target's own timers included, so
your counts differ. The attributes name the upatch, its attach point
- and the map, see :doc:`/reference/formats/otlp`.
+ and the map, see :doc:`/reference/formats/map-export`.
3. While you work on a decoder, run it by hand against the live map:
diff --git a/Documentation/index.rst b/Documentation/index.rst
index edb8629c..66fe9410 100644
--- a/Documentation/index.rst
+++ b/Documentation/index.rst
@@ -113,6 +113,17 @@ By role
:doc:`/security/threat-model`
- Contributors: :doc:`/contribute/code/develop-locally`
+Specifications
+--------------
+
+- :doc:`/reference/formats/beefile`: the Beefile that describes a package
+- :doc:`/reference/formats/upatch-format`: the signed ``.upatch``
+ container
+- :doc:`/reference/formats/upatch-tree`: the operations, segments and
+ publication document of an upatch tree
+- :doc:`/reference/formats/keepalive`: the record a target sends its
+ collector, its :ref:`body <keepalive-body-format>` and its TPM quote
+
Documentation
-------------
diff --git a/Documentation/internals/config-images.rst b/Documentation/internals/config-images.rst
index 61d1250a..a7db1b40 100644
--- a/Documentation/internals/config-images.rst
+++ b/Documentation/internals/config-images.rst
@@ -90,7 +90,7 @@ initrd's file, and later commands use the runtime image's. The initrd's
file must then not be readable by group or others. The initial BPF
certificate is not a setting: it is ``keys/cert.der`` on the runtime
image.
-:doc:`/reference/formats/configuration` lists every key.
+:doc:`/reference/configuration` lists every key.
Image files
-----------
@@ -354,4 +354,4 @@ Related
- :doc:`/operate/deploy/boot-integration` for building the images and the
initrd
- :doc:`/reference/cli/image` for the ``shirudo image`` commands
-- :doc:`/reference/formats/configuration` for the settings
+- :doc:`/reference/configuration` for the settings
diff --git a/Documentation/internals/measurement-register.rst b/Documentation/internals/measurement-register.rst
index 5ed7c2d3..1a14bc2f 100644
--- a/Documentation/internals/measurement-register.rst
+++ b/Documentation/internals/measurement-register.rst
@@ -261,7 +261,7 @@ followed by ``fsync``. A partial append is truncated away, and one that
was killed before it could be is skipped by every reader and dropped by
the next append, so that it cannot join the next record on its line.
The file is sealed like the rest of the state tree.
-:doc:`/reference/formats/eventlog` gives the format.
+:doc:`/reference/eventlog` gives the format.
The ``init`` run in the initrd writes its record to
``/run/shirudo/eventlog.pending``, which crosses the switch to the root
@@ -571,4 +571,4 @@ Related
sessions
- :doc:`/concepts/measurement-register` for the concept
- :doc:`/operate/run/attest` for attesting a target
-- :doc:`/reference/formats/eventlog` for the eventlog format
+- :doc:`/reference/eventlog` for the eventlog format
diff --git a/Documentation/operate/deploy/boot-integration.rst b/Documentation/operate/deploy/boot-integration.rst
index 5ca7d8e3..42296332 100644
--- a/Documentation/operate/deploy/boot-integration.rst
+++ b/Documentation/operate/deploy/boot-integration.rst
@@ -78,7 +78,7 @@ A target reads two different bootstrap files. Both are called
You write the runtime bootstrap file first, because it goes into the
runtime image. The UKI bootstrap file names the root hash of that image,
so you can write it only after the runtime image exists.
-:doc:`/reference/formats/configuration` describes every key.
+:doc:`/reference/configuration` describes every key.
When the TPM owner hierarchy has a password, set ``tpm.owner_auth`` in
both files. Init reads it from the UKI file when it creates the TPM
diff --git a/Documentation/operate/plan/overhead.rst b/Documentation/operate/plan/overhead.rst
index 416bcd91..fa8faa72 100644
--- a/Documentation/operate/plan/overhead.rst
+++ b/Documentation/operate/plan/overhead.rst
@@ -99,7 +99,7 @@ Files and images
* - Eventlog growth
- 1.9 KiB per boot, 350 B per upatch load or unload
- shirudo never shortens the eventlog. See the size limits in
- :doc:`/reference/formats/eventlog`.
+ :doc:`/reference/eventlog`.
.. figure:: /images/operate-runtime-image.svg
:alt: Of the 15 MiB runtime image, the stripped target binary takes
@@ -551,6 +551,6 @@ Related
- :doc:`/operate/plan/scalability`
- :doc:`/reference/systemd-units`
- :doc:`/reference/files`
-- :doc:`/reference/formats/eventlog`
+- :doc:`/reference/eventlog`
- :doc:`/internals/enforcement`
- :doc:`/concepts/background/tpm`
diff --git a/Documentation/operate/plan/system-requirements.rst b/Documentation/operate/plan/system-requirements.rst
index e910220c..6f273aa4 100644
--- a/Documentation/operate/plan/system-requirements.rst
+++ b/Documentation/operate/plan/system-requirements.rst
@@ -303,7 +303,7 @@ TPM
empty authorization.
* - Owner hierarchy authorization, if set, in ``tpm.owner_auth``
- shirudo defines the NV index and the writer key under the owner
- hierarchy. See :doc:`/reference/formats/configuration`.
+ hierarchy. See :doc:`/reference/configuration`.
Target userspace
----------------
diff --git a/Documentation/operate/run/deliver-packages.rst b/Documentation/operate/run/deliver-packages.rst
index 8e123745..030abd37 100644
--- a/Documentation/operate/run/deliver-packages.rst
+++ b/Documentation/operate/run/deliver-packages.rst
@@ -451,5 +451,7 @@ Next steps
operator side
- :doc:`/operate/run/telemetry` to export what the installed upatches collect
- :doc:`/reference/cli/bpm` for every ``bpm`` option
-- :doc:`/reference/formats/bpm-formats` for the index, package and tree
+- :doc:`/reference/formats/bpm-formats` for the index and package
+ formats
+- :doc:`/reference/formats/upatch-tree` for the tree format
formats
diff --git a/Documentation/operate/run/read-status.rst b/Documentation/operate/run/read-status.rst
index 0663e2f0..ad810cb4 100644
--- a/Documentation/operate/run/read-status.rst
+++ b/Documentation/operate/run/read-status.rst
@@ -451,7 +451,7 @@ unload:
...
The ``init`` record comes from the initrd run. Every later record is a
-state change that extended the register. :doc:`/reference/formats/eventlog`
+state change that extended the register. :doc:`/reference/eventlog`
describes the records.
.. _status-verdicts:
diff --git a/Documentation/operate/run/telemetry.rst b/Documentation/operate/run/telemetry.rst
index a76cfde8..71818a34 100644
--- a/Documentation/operate/run/telemetry.rst
+++ b/Documentation/operate/run/telemetry.rst
@@ -181,7 +181,7 @@ The config image accepts these keys:
Default: 4194304.
The only other key the config image's ``shirudo.conf`` accepts is
-``eventlog.max_bytes``. :doc:`/reference/formats/configuration` lists
+``eventlog.max_bytes``. :doc:`/reference/configuration` lists
every key, including those of the runtime image.
Set credentials and TLS material
diff --git a/Documentation/operate/troubleshoot/troubleshooting.rst b/Documentation/operate/troubleshoot/troubleshooting.rst
index 12f145a3..2c3253e9 100644
--- a/Documentation/operate/troubleshoot/troubleshooting.rst
+++ b/Documentation/operate/troubleshoot/troubleshooting.rst
@@ -459,7 +459,7 @@ Causes
Action
Raise ``eventlog.max_bytes`` in a signed config and activate it, see
- :doc:`/reference/formats/configuration`. Keep the cap below 8 MiB:
+ :doc:`/reference/configuration`. Keep the cap below 8 MiB:
every reader of the eventlog fails on a larger log.
:doc:`/operate/maintain/backup-recovery` covers the eventlog's lifetime.
diff --git a/Documentation/reference/cli/attest-predict.rst b/Documentation/reference/cli/attest-predict.rst
index 374fd7b1..38b82802 100644
--- a/Documentation/reference/cli/attest-predict.rst
+++ b/Documentation/reference/cli/attest-predict.rst
@@ -71,7 +71,7 @@ Events
- a key revocation. ``<certificate-sha256>`` is the SHA-256 of the
revoked certificate. ``<label>`` is required and not used.
-The eventlog entry of each event (:doc:`/reference/formats/eventlog`)
+The eventlog entry of each event (:doc:`/reference/eventlog`)
carries the values.
Output
@@ -190,4 +190,4 @@ Related
- :doc:`attest-verify`
- :doc:`upatch-load`
- :doc:`/internals/measurement-register`
-- :doc:`/reference/formats/eventlog`
+- :doc:`/reference/eventlog`
diff --git a/Documentation/reference/cli/bpm.rst b/Documentation/reference/cli/bpm.rst
index 6fc35d5e..402fe64f 100644
--- a/Documentation/reference/cli/bpm.rst
+++ b/Documentation/reference/cli/bpm.rst
@@ -210,7 +210,7 @@ reading its options.
A failure names its phase as :doc:`/reference/failure-categories`
lists them, and the sync applies nothing past it. The walk, its limits
and the time a joining node takes, which grows linearly with the tree,
-are in :doc:`/reference/formats/bpm-formats`; both limits are to be
+are in :doc:`/reference/formats/upatch-tree`; both limits are to be
revisited on live clusters.
With ``--dry-run``, it reports which operations would apply and applies
@@ -273,7 +273,7 @@ append: the publication at <repository>:<reference> does not verify``
and nothing is published.
A tree is a chain of segments, each one publication document of at most
-512 operations; :doc:`/reference/formats/bpm-formats` has the ``base``
+512 operations; :doc:`/reference/formats/upatch-tree` has the ``base``
keys that link them. An append never splits its operations
across segments. Before it adds its ``n`` operations to the current
segment, which holds ``c``, it seals that segment when ``c`` is at least
@@ -478,7 +478,7 @@ build
-----
``build`` builds and signs a package from a Beefile
-(:doc:`/upatches/publish/beefile`):
+(:doc:`/reference/formats/beefile`):
- The Beefile is ``--file``, else ``<context>/Beefile``, with
``<context>`` defaulting to the current directory.
@@ -634,6 +634,6 @@ Related
- :doc:`/operate/run/deliver-packages`
- :doc:`/upatches/publish/publishing`
-- :doc:`/upatches/publish/beefile`
+- :doc:`/reference/formats/beefile`
- :doc:`/reference/formats/bpm-formats`
- :doc:`/reference/systemd-units`
diff --git a/Documentation/reference/cli/config.rst b/Documentation/reference/cli/config.rst
index 9b2ca4bf..cac4d20a 100644
--- a/Documentation/reference/cli/config.rst
+++ b/Documentation/reference/cli/config.rst
@@ -57,7 +57,7 @@ The comments in the output are not a reference. The ``map_export``
comment is wrong: it says that empty destinations leave the export timer
idle, while the timer runs ``upatch map --all``, which reads every map
and prints it (see :doc:`upatch-map`).
-:doc:`/reference/formats/configuration` describes every setting.
+:doc:`/reference/configuration` describes every setting.
Options
-------
@@ -150,6 +150,6 @@ The command prints:
Related
-------
-- :doc:`/reference/formats/configuration`
+- :doc:`/reference/configuration`
- :doc:`/internals/config-images`
- :doc:`image`
diff --git a/Documentation/reference/cli/gen-tools.rst b/Documentation/reference/cli/gen-tools.rst
index f72f1b5e..3a3beddd 100644
--- a/Documentation/reference/cli/gen-tools.rst
+++ b/Documentation/reference/cli/gen-tools.rst
@@ -136,7 +136,7 @@ trusted binaries. Requires ``readelf``, ``ldd`` and ``llvm-strip``.
* - ``--bootstrap-conf``
- required
- The bootstrap ``shirudo.conf``
- (:doc:`/reference/formats/configuration`).
+ (:doc:`/reference/configuration`).
* - ``--cert``
- required
- The initial BPF signing certificate.
@@ -327,7 +327,7 @@ needs:
bpf.keyring_unsealed=1 dm_verity.keyring_unsealed=1
``<bootstrap-conf>`` is the bootstrap ``shirudo.conf`` that names the
-runtime image (:doc:`/reference/formats/configuration`).
+runtime image (:doc:`/reference/configuration`).
Related
-------
@@ -336,4 +336,4 @@ Related
- :doc:`/operate/deploy/boot-integration`
- :doc:`/internals/boot-flow`
- :doc:`/internals/config-images`
-- :doc:`/reference/formats/configuration`
+- :doc:`/reference/configuration`
diff --git a/Documentation/reference/cli/image.rst b/Documentation/reference/cli/image.rst
index 64379010..1f73d634 100644
--- a/Documentation/reference/cli/image.rst
+++ b/Documentation/reference/cli/image.rst
@@ -271,5 +271,5 @@ Related
- :doc:`/internals/config-images`
- :doc:`/concepts/background/dm-verity`
- :doc:`gen-tools`
-- :doc:`/reference/formats/configuration`
+- :doc:`/reference/configuration`
- :doc:`/operate/maintain/keys`
diff --git a/Documentation/reference/cli/status.rst b/Documentation/reference/cli/status.rst
index 37fa6b5a..04938068 100644
--- a/Documentation/reference/cli/status.rst
+++ b/Documentation/reference/cli/status.rst
@@ -86,7 +86,7 @@ is configured: ``map_export.otel_endpoint``, else
below, has the TPM's attestation key quote the SHA-256 of the body, and
sends one OTLP log record named ``shirudo.keepalive`` with the body as a
string and the quote as its one attribute, ``shirudo.quote``
-(:doc:`/reference/formats/otlp`). The attestation key is the one
+(:doc:`/reference/formats/keepalive`). The attestation key is the one
:doc:`attest` uses, created for the quote and flushed after it. When no
TPM answers or the quote fails, ``status`` sends nothing, says why on
standard error and exits 1: a keepalive without a quote is worth nothing
@@ -100,90 +100,25 @@ the full document, not the keepalive body, and ``--include-system`` and
With ``--keepalive``, ``status`` prints the keepalive body, the compact
status record a node's TPM quotes, as one line on standard output. It
neither quotes nor sends it and needs no TPM, so an operator can see
-what a node reports. The body has 23 keys in a fixed order: ``schema``
-(``shirudo.keepalive/1``), ``boot_id``, ``version_id``, ``config_root``,
-``kernel_release``, ``image_id``, ``image_version``, ``image_root``,
-``verdict``, ``cond``, ``flags``, ``tamper``, ``integrity``,
-``tree_id``, ``generation``, ``base_seq``, ``last_seq``, ``base_root``,
-``projection_root``, ``mask``, ``set_sha256``, ``count`` and ``not_ok``.
-A key that does not apply is ``null``:
-
-- ``config_root`` unless the selected config is active;
-- the seven tree keys, ``tree_id`` to ``mask``, when the node follows no
- tree or its tree state cannot be read.
-
-``cond`` holds two bits per condition, condition *i* of the order above
-at bits ``2i`` and ``2i+1``, ``LsmAttached`` first and ``XdpCovered``
-last: ``00`` not evaluated, ``01`` ``OK``, ``10`` ``WARN``, ``11``
-``ALERT``. All seven ``OK`` is ``5461``. ``tamper`` lists every counter
-of :doc:`/security/tamper-counters`, zeros included, in the order of
-that page, and ``integrity`` every counter of
-:doc:`/security/integrity-counters` the same way. A collector reads a
-counter by its place: a new one is appended, never put between two.
-
-The tree keys report a window of the last 512 operations up to the head
-of the recorded publication, whatever segments hold them: ``base_seq``
-is the head less 512, or 0 for a tree of 512 operations or fewer, and
-``base_root`` the node's projection root after ``base_seq``, 64 zeros
-at 0. ``mask`` holds two bits per operation from ``base_seq + 1`` to the
-head: ``01`` applied, ``10`` passed over, ``11`` module absent, ``00``
-not reached. Both come from the outcomes record of
-:doc:`/reference/formats/bpm-formats`, which keeps every operation the
-node processed, those of sealed segments included. ``set_sha256`` is
-SHA-256 over a ``<payload_sha256> <name>`` line for every loaded upatch,
-sorted by name, the ``set_digest`` form of the ``init`` event.
-``not_ok`` counts the loaded upatches the tree holds a status file for.
-The bits of ``flags``:
-
-.. list-table::
- :header-rows: 1
- :widths: 8 24 68
-
- * - Bit
- - Name
- - Set when
- * - 0
- - ``register_rebound``
- - The register was bound more than once for this TPM reset.
- * - 1
- - ``bound_late``
- - This boot's ``init`` record says the register was bound from the
- root file system, not from the initrd.
- * - 2
- - ``tree_log_mismatch``
- - The tree eventlog does not replay to the ``projection_root`` of
- ``state.json``, or the outcomes record lacks a line the window
- needs; ``base_root`` and ``mask`` are then ``null``.
- * - 3
- - ``tamper_unavailable``
- - The tamper counters cannot be read; ``tamper`` is ``null``.
- * - 4
- - ``tree_op_pending``
- - A tree operation was left in flight: ``pending.json`` existed
- before or after the read, after a sync stopped mid-operation.
- * - 5
- - ``snapshot_unsettled``
- - ``state.json`` kept changing while the body was read, which the
- config operation lock leaves to a writer outside it.
- * - 6
- - ``integrity_unavailable``
- - The integrity counters cannot be read; ``integrity`` is ``null``.
+what a node reports. Its keys, their order and their encoding are in
+:ref:`keepalive-body-format`.
``status`` holds the config operation lock for its whole run, as every
target command does, a ``bpm tree sync`` included. It therefore never
reads a tree a sync is changing: while one runs, ``status`` waits up to
-30 seconds for the lock and then fails, and no body is printed or sent. A sync
-writes ``pending.json`` before it loads or unloads anything and removes
-it only after ``state.json`` has the new ``last_seq``, so bit 4 says a
-sync stopped in the middle of an operation and the next sync completes
-it. ``status`` still reads ``state.json``, looks for ``pending.json``,
-reads the outcomes up to that ``last_seq`` and the loaded upatches, then
-looks for ``pending.json`` and reads ``state.json`` again, and starts
-over when the second ``state.json`` differs from the first, three times
-in all, printing the last read with bit 5 set; under the lock that
-happens only if something writes the tree without it. With bits 4 and 5
-clear the tree keys and the loaded set describe one point. The two bits
-say the node is busy, not that it is unhealthy.
+30 seconds for the lock and then fails, and no body is printed or
+sent. A sync writes ``pending.json`` before it loads or unloads anything
+and removes it only after ``state.json`` has the new ``last_seq``, so
+``tree_op_pending`` says a sync stopped in the middle of an operation
+and the next sync completes it. ``status`` still reads ``state.json``,
+looks for ``pending.json``, reads the outcomes up to that ``last_seq``
+and the loaded upatches, then looks for ``pending.json`` and reads
+``state.json`` again, and starts over when the second ``state.json``
+differs from the first, three times in all, printing the last read with
+``snapshot_unsettled`` set; under the lock that happens only if
+something writes the tree without it. With both flags clear the tree
+keys and the loaded set describe one point. The two flags say the node
+is busy, not that it is unhealthy.
Options
-------
diff --git a/Documentation/reference/cli/upatch-map.rst b/Documentation/reference/cli/upatch-map.rst
index aa69d18b..f258519c 100644
--- a/Documentation/reference/cli/upatch-map.rst
+++ b/Documentation/reference/cli/upatch-map.rst
@@ -61,13 +61,13 @@ With ``<upatch> <map>``, ``map`` reads the map:
- ``--otel`` sends the map to an OTLP collector. A map with a signed Lua
decoder is sent as the log or metric the decoder declares. A map
without one is classified by shirudo (see
- :doc:`/reference/formats/otlp`).
+ :doc:`/reference/formats/map-export`).
Every map
~~~~~~~~~
``--all`` handles every map of every loaded upatch as above and loads the
-``map_export`` settings (:doc:`/reference/formats/configuration`):
+``map_export`` settings (:doc:`/reference/configuration`):
``map_export.json_path`` turns on JSON output to that file and
``map_export.otel_endpoint`` turns on OTLP, together with the tenant,
TLS, retry, size and S3 settings. Options on the command line take
@@ -198,6 +198,7 @@ Related
- :doc:`/operate/run/telemetry`
- :doc:`/reference/formats/otlp`
+- :doc:`/reference/formats/map-export`
- :doc:`/upatches/write/maps-arenas-serializers`
- :doc:`/upatches/write/decoders`
- :doc:`upatch-get`
diff --git a/Documentation/reference/formats/configuration.rst b/Documentation/reference/configuration.rst
similarity index 99%
rename from Documentation/reference/formats/configuration.rst
rename to Documentation/reference/configuration.rst
index 5cf84d12..e020c7f4 100644
--- a/Documentation/reference/formats/configuration.rst
+++ b/Documentation/reference/configuration.rst
@@ -253,7 +253,7 @@ On a target, the effective settings combine the files as follows:
``SHIRUDO_TPM_OWNER_AUTH`` override the file. A target refuses both,
see :doc:`/reference/environment`.
-See :doc:`/reference/formats/otlp` for what the ``map_export.*``
+See :doc:`/reference/formats/map-export` for what the ``map_export.*``
destinations receive.
Syntax and validation
@@ -488,7 +488,7 @@ file, ``bpm tree sync`` does nothing.
Either value may be enclosed in double quotes. An opening quote without
a closing one is refused with ``EINVAL``. Lines without ``=`` and other
-keys are ignored. See :doc:`/reference/formats/bpm-formats` for the
+keys are ignored. See :doc:`/reference/formats/upatch-tree` for the
publication.
Node labels
diff --git a/Documentation/reference/environment.rst b/Documentation/reference/environment.rst
index b8921dba..78d9b629 100644
--- a/Documentation/reference/environment.rst
+++ b/Documentation/reference/environment.rst
@@ -296,7 +296,7 @@ Related
- :doc:`/reference/systemd-units` for the units that read the
environment files
-- :doc:`/reference/formats/configuration` for the settings these
+- :doc:`/reference/configuration` for the settings these
variables complement
- :doc:`/operate/run/telemetry` and :doc:`/operate/run/deliver-packages` for
setting up export and registry access
diff --git a/Documentation/reference/formats/eventlog.rst b/Documentation/reference/eventlog.rst
similarity index 98%
rename from Documentation/reference/formats/eventlog.rst
rename to Documentation/reference/eventlog.rst
index 05f76d0e..e63bdba4 100644
--- a/Documentation/reference/formats/eventlog.rst
+++ b/Documentation/reference/eventlog.rst
@@ -44,7 +44,7 @@ refuses both, see :doc:`/reference/environment`.
The upatch tree keeps its own projection log in
``/var/lib/shirudo/bpm/upatch-tree/tree-eventlog``, described in
-:doc:`bpm-formats`. Config image activations extend the config PCR
+:doc:`formats/upatch-tree`. Config image activations extend the config PCR
instead of the register and keep their records under
``/var/lib/shirudo/config-update``, see :doc:`/internals/config-images`.
Neither is part of the eventlog.
@@ -287,7 +287,7 @@ record whose ``set`` lists it, with that payload.
``status`` compares the replay with the live register (condition
``ChainIntact``, field ``tpm.chain_matches_eventlog`` in
-:doc:`status-json`). It also reports a mismatch when the register's
+:doc:`formats/status-json`). It also reports a mismatch when the register's
name differs from the recorded ``nv_name``, when the recorded PCR values
and writer key do not give that name, and when two ``init`` records
name the same TPM reset count. ``shirudo attest`` puts the selected
@@ -401,5 +401,5 @@ Related
- :doc:`/internals/measurement-register`
- :doc:`/operate/run/attest`
-- :doc:`status-json`
+- :doc:`formats/status-json`
- :doc:`/reference/cli/status`
diff --git a/Documentation/reference/failure-categories.rst b/Documentation/reference/failure-categories.rst
index 5ebe94b4..5554b350 100644
--- a/Documentation/reference/failure-categories.rst
+++ b/Documentation/reference/failure-categories.rst
@@ -127,7 +127,7 @@ Categories
- The eventlog would exceed ``eventlog.max_bytes``. Nothing was
loaded or measured.
- Raise ``eventlog.max_bytes`` in the signed config, see
- :doc:`/reference/formats/configuration`. The eventlog is sealed
+ :doc:`/reference/configuration`. The eventlog is sealed
and cannot be rotated.
* - ``parser_rejected``
- ``parse``, ``target_verify``
diff --git a/Documentation/reference/files.rst b/Documentation/reference/files.rst
index be3d0240..f431d540 100644
--- a/Documentation/reference/files.rst
+++ b/Documentation/reference/files.rst
@@ -80,7 +80,7 @@ Operator host
- administrator
- none
- Operator settings, such as ``tls.classical_hosts``. See
- :doc:`/reference/formats/configuration`.
+ :doc:`/reference/configuration`.
Output files the caller names: ``.upatch`` artifacts and ``.vouch``
files with mode ``0644``, ``.bee`` packages with mode ``0600``.
@@ -132,7 +132,7 @@ the label as foreign. In the initrd, ``init`` binds
- measuring commands
- ``0600``
- Append-only eventlog, one JSON record per line. See
- :doc:`/reference/formats/eventlog`.
+ :doc:`/reference/eventlog`.
* - ``eventlog.lock``
- measuring commands
- ``0600``
@@ -314,7 +314,7 @@ name under ``/etc/shirudo``.
* - ``keys/revoked/``
- Revoked certificates.
-See :doc:`/reference/formats/configuration` for the keys of each file.
+See :doc:`/reference/configuration` for the keys of each file.
Private bpffs pins
------------------
@@ -456,7 +456,7 @@ Host configuration
* - ``/etc/shirudo/shirudo.conf``
- On the root file system: the source of the initrd's bootstrap
file and the settings of a host without images. In the initrd:
- the bootstrap file. See :doc:`/reference/formats/configuration`.
+ the bootstrap file. See :doc:`/reference/configuration`.
* - ``/etc/shirudo/keys/cert.der``, ``/etc/shirudo/keys/trusted/``
- In the initrd only: the certificates the dracut module copies in.
* - ``/etc/shirudo/bpm/registries.d/<source>.conf``
diff --git a/Documentation/reference/formats/beefile.rst b/Documentation/reference/formats/beefile.rst
new file mode 100644
index 00000000..484f6a8d
--- /dev/null
+++ b/Documentation/reference/formats/beefile.rst
@@ -0,0 +1,660 @@
+..
+ SPDX-License-Identifier: BSD-2-Clause
+ Copyright (c) 2026 Authors of shirudo
+
+:page-type: Reference
+:audience: upatch authors
+
+Beefile
+=======
+
+A Beefile describes a package: its name, the files it ships, the upatches
+``shirudo bpm build`` compiles and signs into it, and the entries
+``shirudo bpm tree append`` publishes to an upatch tree. ``bpm build``
+reads ``<context>/Beefile``, or the file given with ``--file``, and treats
+the directory that holds it as the package directory. Every path in the
+Beefile is relative to that directory. The package archives the Beefile
+unchanged as its ``Beefile`` member. :doc:`/reference/cli/bpm` lists the
+command options and :doc:`bpm-formats` the archive format.
+
+Overview
+--------
+
+Every table a Beefile may hold, the keys each takes and how many of it
+a package may have:
+
+.. code-block:: none
+
+ [package] once
+ name package name
+ description, license, authors read and ignored
+ [[files]] up to 128
+ source, target a file shipped as it is
+ [[upatches]] up to 128
+ source the BPF program, names the upatch
+ type bpf
+ load_target, unload_target where the artifacts go
+ [[upatches.rodata]] up to 16 per upatch
+ symbol, input, generator, generated .rodata
+ update
+ [[upatches.policy]] up to 64 per upatch
+ id, bit, paths signed policy labels
+ [upatches.tree] once per upatch
+ id the operation's identity
+ load_artifact, unload_artifact what add and delete publish
+ fixes advisories the upatch fixes
+ [upatches.tree.selector] once per upatch
+ kernel_release_prefix, kernel and machine
+ kernel_build_id, architecture
+ [upatches.tree.selector.kconfig] Kconfig option values
+ [upatches.tree.selector.labels] node labels
+
+Syntax
+------
+
+A Beefile is a small subset of TOML, read line by line. ``bpm build``
+reports every error in the file, of syntax or of content, as ``bpm
+build: <file> is not a valid Beefile``, without a line number. For a
+``fixes`` it refuses, a ``Beefile: fixes ...`` line before that one says
+what is wrong with the list.
+
+File
+~~~~
+
+.. list-table::
+ :header-rows: 1
+ :widths: 20 80
+
+ * - Element
+ - Rule
+ * - Line
+ - One table header, one ``key = value`` pair, a comment or nothing.
+ * - String
+ - ``"..."`` takes the escapes ``\n``, ``\r``, ``\t``, ``\\`` and
+ ``\"``; ``'...'`` takes none.
+ * - Array
+ - Of quoted strings, on the same line.
+ * - Number
+ - Only for a policy ``bit``, read as hexadecimal.
+ * - Comment
+ - ``#`` outside a string, to the end of the line.
+ * - Not supported
+ - Booleans, inline tables and values that span lines.
+
+A tree id or selector value holding a control character, as the first
+three escapes spell, is refused by ``bpm tree append``, as no node could
+read the publication.
+
+.. code-block:: toml
+
+ [package]
+ name = "xfs-fix" # a comment
+ authors = ['Ops team', "On-call \"A\""]
+
+Nesting
+~~~~~~~
+
+``[[upatches.rodata]]``, ``[[upatches.policy]]`` and the
+``[upatches.tree]`` tables belong to the ``[[upatches]]`` entry above
+them. Write an entry's own keys before its first sub-table: a key after
+``[upatches.tree]`` belongs to that table.
+
+.. code-block:: toml
+
+ [[upatches]]
+ source = "a.bpf.c" # entry key: before any sub-table
+
+ [upatches.tree]
+ id = "a" # belongs to the tree table of a
+
+ [[upatches]] # a new entry starts here
+ source = "b.bpf.c"
+
+Keys
+----
+
+``[package]``
+~~~~~~~~~~~~~
+
+Once per Beefile.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 18 14 10 58
+
+ * - Key
+ - Type
+ - Required
+ - Rules
+ * - ``name``
+ - string
+ - yes
+ - The package name: 1 to 127 characters of letters, digits, ``.``,
+ ``_`` and ``-``, starting with a letter or a digit. The archive is
+ ``<name>-<version>.bee``.
+ * - ``description``
+ - string
+ - no
+ - Read and ignored.
+ * - ``license``
+ - string
+ - no
+ - Read and ignored.
+ * - ``authors``
+ - array of strings
+ - no
+ - Read and ignored.
+
+A ``README.md`` in the package directory is added to the package, and
+``shirudo bpm info`` prints it.
+
+.. code-block:: toml
+
+ [package]
+ name = "kernel-obs"
+ description = "shirudo kernel observability"
+ license = "GPL-2.0 OR BSD-2-Clause"
+ authors = ["Authors of shirudo"]
+
+``[[files]]``
+~~~~~~~~~~~~~
+
+One table per file to ship as it is: headers, generator programs, lists,
+reproducers.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 18 14 10 58
+
+ * - Key
+ - Type
+ - Required
+ - Rules
+ * - ``source``
+ - string
+ - yes
+ - A regular file inside the package directory. Not absolute, no
+ ``..`` component, and its real path must not leave the directory.
+ * - ``target``
+ - string
+ - no
+ - The member path in the package. Default: ``source``. Not absolute,
+ no empty, ``.`` or ``..`` component.
+
+.. code-block:: toml
+
+ [[files]]
+ source = "watch.list"
+ target = "watch.list"
+
+``[[upatches]]``
+~~~~~~~~~~~~~~~~
+
+One table per upatch to build. ``bpm build`` compiles a ``.bpf.c``,
+signs the object into a load artifact and generates its unload directive
+from the artifact's payload digest, so a package always ships both.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 18 14 10 58
+
+ * - Key
+ - Type
+ - Required
+ - Rules
+ * - ``source``
+ - string
+ - yes
+ - A ``.bpf.c``, ``.bpf.o`` or ``.o`` file inside the package
+ directory, under the same rules as a file ``source``. The upatch
+ name is its base name without ``.bpf.c``, ``.bpf.o`` or ``.o``.
+ There is no key to set another name.
+ * - ``type``
+ - string
+ - no
+ - ``bpf``, the default and the only value, in any case.
+ * - ``load_target``
+ - string
+ - no
+ - The member path of the load artifact. Default:
+ ``upatches/<base>.upatch``, with ``<base>`` the source's base name
+ without ``.bpf.c`` or ``.bpf.o``, or without its last extension.
+ * - ``unload_target``
+ - string
+ - no
+ - The member path of the unload directive. Default:
+ ``upatches/<base>.unload.upatch``.
+
+.. code-block:: toml
+
+ [[upatches]]
+ source = "kernel-obs.bpf.c" # upatch name: kernel-obs
+
+Keep both targets directly under ``upatches/``. On a target, ``bpm
+install`` loads every file in the package's ``upatches/`` directory whose
+name contains ``.upatch`` but not ``.unload.upatch``, in name order, and
+``bpm uninstall`` applies every ``upatches/*.unload.upatch`` in reverse
+name order. ``bpm upgrade`` applies the old version's unload directives
+before it loads the new version, and pairs ``<x>.unload.upatch`` with
+``<x>.upatch`` to restore the old version when the new one fails. An
+artifact elsewhere is shipped but never loaded.
+
+``bpm build`` compiles a ``.bpf.c`` as ``shirudo build`` does, see
+:doc:`/reference/cli/build`, but in the package directory. It finds
+libbpf's headers in ``./vendor/libbpf`` there, or in the operator
+package's ``/usr/share/shirudo/bpf/include``, and ``vmlinux.h`` at
+``--vmlinux``, then at ``./vmlinux.h`` and ``./vendor/linux/vmlinux.h``
+of the directory ``bpm build`` runs in, then of the package directory,
+then at the installed path. ``bpm build`` passes no extra compiler
+flags.
+
+``[[upatches.rodata]]``
+~~~~~~~~~~~~~~~~~~~~~~~
+
+Generated data for one ``const`` variable in the upatch's ``.rodata``. A
+generator program produces the variable's bytes from an input file at
+``bpm build``, and an updater program does the same at ``bpm config
+update``, which re-signs the upatch without compiling it again.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 18 14 10 58
+
+ * - Key
+ - Type
+ - Required
+ - Rules
+ * - ``symbol``
+ - string
+ - yes
+ - The variable's name in the object's BTF, at most 127 characters.
+ * - ``input``
+ - string
+ - yes
+ - The default input, a regular file inside the package directory,
+ not absolute, without ``..``.
+ * - ``generator``
+ - array of strings
+ - yes
+ - The command for ``bpm build``, 1 to 16 arguments.
+ * - ``update``
+ - array of strings
+ - yes
+ - The command for ``bpm config update``, 1 to 16 arguments.
+
+.. code-block:: toml
+
+ [[upatches.rodata]]
+ symbol = "obs_watch_v4"
+ input = "watch.list"
+ generator = ["python3", "gen_watch_rodata.py"]
+ update = ["python3", "gen_watch_rodata.py"]
+
+The first argument of a command that contains a ``/``, or else the
+second, must be a regular file inside the package directory, such as
+``gen_watch_rodata.py`` above. shirudo runs the command without a shell,
+with ``execvp``, in the package directory, and appends ``--input <path>
+--symbol <symbol> --output <path>``. The program writes the variable's
+raw bytes to the output file. A result whose length differs from the
+variable's size fails the build.
+
+An input is named by its file name up to the first dot: ``watch.list``
+is ``watch``. ``--rodata-input <name>=<path>`` replaces the input of every
+entry with that name for one build. An override for a name that no entry
+has fails. Entries that share a name must name the same input.
+
+The generator and the updater run on the operator host with the
+operator's rights. The target receives only the signed result. Without
+``--file``, ``bpm config update`` takes the Beefile and the updater from
+the base package and runs them. It also trusts the base package's
+unsigned header to locate ``.rodata`` before it re-signs, so run it only
+on a base package you built or verified yourself.
+
+``[[upatches.policy]]``
+~~~~~~~~~~~~~~~~~~~~~~~
+
+A named policy bit and the absolute paths whose
+``security.bpf.shirudo.policy`` xattrs this upatch labels. The builder
+embeds the entries in the signed ``SHPL`` section.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 18 14 10 58
+
+ * - Key
+ - Type
+ - Required
+ - Rules
+ * - ``id``
+ - string
+ - yes
+ - The policy's name, mapped to one one-hot 64-bit mask. Repeating
+ the same ID and mask in other upatches extends that policy; an ID
+ cannot change masks.
+ * - ``bit``
+ - number
+ - yes
+ - The one-hot mask, read as hexadecimal, with or without ``0x``, so
+ ``bit = 10`` is ``0x10``. Two different IDs cannot use the same
+ mask in one package.
+ * - ``paths``
+ - array of strings
+ - yes
+ - 1 to 16 absolute paths. A path may name a non-executable file.
+
+.. code-block:: toml
+
+ [[upatches.policy]]
+ id = "apache"
+ bit = 0x1
+ paths = ["/usr/local/apache", "/usr/bin/apache"]
+
+A policy table opts the upatch into shirudo's shared task
+``shirudo_task_policy`` and socket ``shirudo_sock_policy`` maps. The
+generated loader reuses both pinned maps rather than creating private
+copies. The BPF source must declare the map ABI, normally by including
+``policy.h`` after ``vmlinux.h`` and the libbpf headers. It also brings
+``XATTR_POLICY``, the name of the xattr, for a program that reads it.
+The header is installed beside the shirudo BPF headers. Declaring the
+maps without policy tables leaves them as ordinary upatch-owned maps.
+
+Signed BPF programs can write the maps, so enforcement programs must
+treat them as read-only by contract. Root can give its own processes
+any bit, through a file system it mounts whose executables carry the
+xattr, so let a bit restrict what a task may do, never exempt it from a
+rule.
+
+``[upatches.tree]``
+~~~~~~~~~~~~~~~~~~~
+
+Optional, once per upatch. Present when ``bpm tree append`` is to
+publish the upatch as a tree operation.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 18 14 10 58
+
+ * - Key
+ - Type
+ - Required
+ - Rules
+ * - ``id``
+ - string
+ - yes
+ - The operation's identity across generations. A valid upatch name,
+ and equal to the upatch's name, the source's base name:
+ ``bpm tree append`` refuses an artifact whose name differs, and so
+ does the target.
+ * - ``load_artifact``
+ - string
+ - no
+ - The member that an ``add`` publishes. Default: ``load_target``.
+ * - ``unload_artifact``
+ - string
+ - no
+ - The member that a ``delete`` publishes. Default:
+ ``unload_target``.
+ * - ``fixes``
+ - array of strings
+ - no
+ - The IDs of the advisories the upatch fixes: 1 to 16 IDs, each
+ once and of 1 to 255 bytes of letters, digits, ``.``, ``_``,
+ ``:`` and ``-``. The key may appear once.
+
+.. code-block:: toml
+
+ [upatches.tree]
+ id = "xfs-fix" # source = "xfs-fix.bpf.c"
+ fixes = ["EXAMPLE-0101"]
+
+``fixes`` is a convention of the keepalive backend, which reads it to say
+which nodes are exposed to an advisory. Nodes ignore it: it selects
+nothing, and no target reads, checks or measures it. ``bpm build``
+checks the form of each ID, not that the advisory exists, and refuses a
+list that breaks the rules above, an empty list and a value that is not
+an array of strings. It keeps the Beefile as written; the order of the
+IDs does not matter, because the list is published in byte order.
+``bpm tree append`` writes it on the operation it publishes as an
+``add``, outside the operation digest, and never on a ``delete``
+(:doc:`/upatches/publish/publishing`).
+
+``[upatches.tree.selector]``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Optional, once per upatch. Says where the operation applies. Every key
+holds an array of 1 to 16 accepted values, and each key may appear once.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 25 75
+
+ * - Key
+ - Matches when
+ * - ``kernel_release_prefix``
+ - ``uname -r`` starts with a value and continues with ``.``, ``-`` or
+ nothing: ``7.2`` matches ``7.2.0`` and ``7.2-rc1``, not ``7.20``.
+ * - ``kernel_build_id``
+ - the running kernel's GNU build ID from ``/sys/kernel/notes``, in
+ lowercase hex, equals a value. A kernel without one never matches.
+ * - ``architecture``
+ - ``uname -m`` equals a value, such as ``x86_64``, ``aarch64`` or
+ ``riscv64``.
+
+.. code-block:: toml
+
+ [upatches.tree.selector]
+ kernel_release_prefix = ["7.4"]
+ architecture = ["x86_64", "aarch64"]
+
+A target matches a selector when it matches every key given, including
+the keys of its ``kconfig`` and ``labels`` tables, and a key when it
+matches one of its values. An entry without a selector applies
+everywhere. A target that does not match an operation passes over it and
+never comes back to it, also after a kernel upgrade or a label change.
+
+``[upatches.tree.selector.kconfig]``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Up to 64 keys, each a Kconfig option, once, with its accepted values. An
+option that is not set matches ``"n"``. The target reads
+``/proc/config.gz`` and, when that is missing, is not one whole gzip
+stream or names none of the options, ``/boot/config-<release>``, each of
+at most 4 MiB. A target with neither does not match, and one whose
+configuration cannot be read stops the sync at the operation. A line of
+1024 bytes or more is skipped whole, so its option reads as not set.
+
+.. code-block:: toml
+
+ [upatches.tree.selector.kconfig]
+ CONFIG_XFS_FS = ["y", "m"]
+
+``[upatches.tree.selector.labels]``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Up to 64 keys, each a node label, once, with its accepted values. The
+target reads its labels from the signed config image's
+``etc/shirudo/node.labels``. A target without labels does not match.
+
+.. code-block:: toml
+
+ [upatches.tree.selector.labels]
+ role = ["edge"]
+
+Checks
+------
+
+Unknown keys and tables
+~~~~~~~~~~~~~~~~~~~~~~~
+
+.. list-table::
+ :header-rows: 1
+ :widths: 50 50
+
+ * - Where
+ - Result
+ * - an unknown key in ``[package]``, ``[[files]]``, ``[[upatches]]``,
+ ``[[upatches.rodata]]``, ``[[upatches.policy]]`` or
+ ``[upatches.tree.selector]``
+ - refused
+ * - an unknown array of tables, ``[[name]]``
+ - refused
+ * - an unknown table under ``upatches.tree``
+ - refused, because a selector the builder cannot read would widen
+ the rollout
+ * - a table name with quotes, or blanks around its dots, such as
+ ``[upatches ."tree".selector]``
+ - refused, for the same reason
+ * - an unknown key in ``[upatches.tree]``
+ - ignored, as metadata for newer publishers, unless it is
+ ``selector``, quoted or dotted, such as
+ ``selector.architecture = ["aarch64"]``, which is refused
+ * - a key before the first table, or in a table with any other name
+ - ignored
+
+Limits and reserved names
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. list-table::
+ :header-rows: 1
+ :widths: 50 50
+
+ * - Limit
+ - Value
+ * - ``[[files]]`` tables
+ - 128
+ * - ``[[upatches]]`` tables
+ - 128
+ * - ``[[upatches.rodata]]`` tables per upatch
+ - 16
+ * - arguments per ``generator`` or ``update`` command
+ - 16
+ * - ``[[upatches.policy]]`` tables per upatch
+ - 64
+ * - ``paths`` per policy table
+ - 16
+ * - values per selector key
+ - 16
+ * - IDs in ``fixes``
+ - 16, of 255 bytes each
+ * - keys in each of ``kconfig`` and ``labels``
+ - 64
+ * - length of a string in a selector or command
+ - 255 bytes
+ * - package version, ``--version``
+ - A SemVer 2.0.0 version of at most 127 characters, such as
+ ``1.2.0``, ``1.2.0-rc.1`` or ``1.2.0+build.5``
+ * - member path including ``<name>-<version>/``
+ - 99 bytes, the limit of a ustar name
+ * - ``.bee`` file
+ - 256 MiB for all member files together
+
+Every member path must be unique, and none may lie below another: a
+name is a file or a directory, not both, so ``a`` and ``a/b`` do not go
+into one package. ``Beefile``, ``README.md``, ``cert.der`` and
+``build-environment.json`` are reserved for the members ``bpm build``
+writes itself, and no member path lies below one of them either. A
+member path longer than the ustar limit fails the build with ``bpm
+build: File name too long``, and members of more than 256 MiB together,
+or one of that size alone, with ``bpm build: the members of the package
+are more than 256 MiB together, the most a target installs``: a target
+unpacks no more.
+
+Output
+------
+
+``bpm build`` writes ``<name>-<version>.bee``, a gzip-compressed ustar
+archive with one top-level directory ``<name>-<version>/``.
+:doc:`bpm-formats` gives the archive's rules.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 40 60
+
+ * - Member
+ - From
+ * - ``Beefile``
+ - This file, unchanged.
+ * - ``<target>``
+ - Each ``[[files]]`` entry.
+ * - ``upatches/<base>.upatch``
+ - Each ``[[upatches]]`` load artifact, signed, at its
+ ``load_target``.
+ * - ``upatches/<base>.unload.upatch``
+ - Its unload directive, signed, at its ``unload_target``.
+ * - ``README.md``
+ - The package directory's, when it has one.
+ * - ``cert.der``
+ - The signing certificate.
+ * - ``build-environment.json``
+ - The build record.
+
+Examples
+--------
+
+Generated data
+~~~~~~~~~~~~~~
+
+:src:`upatches/kernel-obs/Beefile` declares two upatches, one with two
+generated ``.rodata`` variables, and ships the generators and their
+input beside them. It has no tree entry: it is installed with ``bpm
+install``.
+
+.. literalinclude:: ../../../upatches/kernel-obs/Beefile
+ :language: toml
+
+.. code-block:: console
+
+ operator$ shirudo bpm build upatches/kernel-obs --version 1.0.0 --keys-dir keys
+
+The package holds ``Beefile``, ``README.md``, ``build-environment.json``,
+``cert.der``, the four ``[[files]]`` members and, under ``upatches/``,
+``kernel-obs.upatch``, ``kernel-obs.unload.upatch``,
+``userns-unshare-counter.upatch`` and
+``userns-unshare-counter.unload.upatch``.
+
+Policy labels
+~~~~~~~~~~~~~
+
+:src:`testing/fixtures/policy-exec-graph/Beefile` declares five policy
+bits, each labeling one path, which its upatch reads to decide which
+executables a task may start and which sockets it may use.
+
+.. literalinclude:: ../../../testing/fixtures/policy-exec-graph/Beefile
+ :language: toml
+
+A tree entry
+~~~~~~~~~~~~
+
+:src:`testing/fixtures/pipeline/xfs-fix/Beefile` publishes its upatch
+to a tree as an operation that only nodes labeled ``role=edge`` apply,
+and names the advisory it fixes.
+
+.. literalinclude:: ../../../testing/fixtures/pipeline/xfs-fix/Beefile
+ :language: toml
+
+.. code-block:: console
+
+ operator$ shirudo bpm build ./xfs-fix --version 1.1.0 --keys-dir keys
+ operator$ shirudo bpm tree append ./xfs-fix-1.1.0.bee \
+ oci://registry.example.com/shirudo/fleet-base --keys-dir keys
+
+Not a model
+~~~~~~~~~~~
+
+:src:`upatches/kernel-cve/kernel-cve.bee` breaks these rules. Two of its
+load targets make member paths longer than 99 bytes with any version, so
+``bpm build`` fails. Its tree ids name the CVE directories while its
+upatch names are the detectors' base names, so ``bpm tree append`` would
+refuse every entry. And its ``unload_artifact`` paths name members the
+package does not have.
+
+Related
+-------
+
+- :doc:`/upatches/publish/publishing` for building, pushing and appending
+ a package
+- :doc:`/reference/cli/bpm` for ``bpm build``, ``bpm tree append`` and
+ ``bpm config update``
+- :doc:`bpm-formats` for the archive and the index
+- :doc:`upatch-tree` for the tree the ``[upatches.tree]`` entries
+ publish to
diff --git a/Documentation/reference/formats/bpm-formats.rst b/Documentation/reference/formats/bpm-formats.rst
index c32b25cc..c968ba80 100644
--- a/Documentation/reference/formats/bpm-formats.rst
+++ b/Documentation/reference/formats/bpm-formats.rst
@@ -5,28 +5,24 @@
:page-type: Reference
:audience: upatch authors
-Package, index and tree formats
-===============================
+Package and index formats
+=========================
-shirudo publishes three kinds of objects to an OCI registry: packages
-(``.bee`` files), the signed repository index that lists them, and upatch
-trees. The operator writes them with ``bpm build``, ``bpm push`` and
-``bpm tree append`` (see :doc:`/reference/cli/bpm`). The target reads them
-with ``bpm repo update``, ``bpm install``, ``bpm upgrade`` and
-``bpm tree sync``. The ``.upatch`` files inside are specified in
-:doc:`upatch-format`.
+shirudo publishes packages (``.bee`` files) to an OCI registry and lists
+them in a signed repository index. The operator writes them with ``bpm
+build`` and ``bpm push`` (see :doc:`/reference/cli/bpm`). The target reads
+them with ``bpm repo update``, ``bpm install`` and ``bpm upgrade``. The
+Beefile a package is built from is in :doc:`beefile`, the ``.upatch``
+files inside in :doc:`upatch-format`, and the upatch tree, which
+publishes single upatches of a package, in :doc:`upatch-tree`.
CBMC proves the target's readers of these formats within the bounds
:doc:`/contribute/testing/proof-coverage` lists: the tar headers and
member names, the registry's challenges, tokens, headers and
-descriptors, the package names and versions, the tree publication's
-selectors and operations, and the checks that keep a publication from
-taking a node back. Lean 4 proves the version order total for versions
-of every length, that every member name the archive check takes, of any
-length, extracts strictly below the package's directory, and 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.
+descriptors, and the package names and versions. Lean 4 proves the
+version order total for versions of every length, and that every member
+name the archive check takes, of any length, extracts strictly below the
+package's directory.
What is signed
--------------
@@ -60,18 +56,12 @@ What is signed
* - ``Beefile``, ``README.md``, ``build-environment.json``, files
- Not signed. Covered by the archive digest when the index pins it.
- None beyond the archive digest.
- * - Tree publication document
- - Detached CMS signature over the exact document bytes.
- - ``bpm tree sync``, against the active config's non-revoked BPF signer set.
- * - Tree artifact manifest and ``.upatch`` layer
- - Not signed. Each signed operation pins them by
- ``manifest_digest``, ``layer_digest`` and ``payload_sha256``.
- - ``bpm tree sync``.
* - Certificate referrer manifest
- Not signed.
- Not read by shirudo.
-The detached signatures use the same CMS profile as the ``.upatch``
+The detached signatures, of an index here and of a tree publication
+(:doc:`upatch-tree`), use the same CMS profile as the ``.upatch``
signature: DER ``SignedData``, no encapsulated content, no certificates,
ML-DSA-87, signer named by subject key identifier. The verifier checks it
without a validity-time check: against the repository certificate for
@@ -105,14 +95,6 @@ Names
- The Beefile cannot override it. 1 to 255 characters of
``[A-Za-z0-9._-]``, each ``.`` counting as two, not starting with
``.``.
- * - Tree operation ``id``
- - Beefile ``[upatches.tree] id``
- - Must equal the upatch name of the artifact it publishes, so the
- source file's basename. ``bpm tree append`` and ``bpm tree sync``
- both refuse a mismatch.
- * - Tree ``tree_id``
- - ``--tree-id``, else the package name of the first append
- - Fixed for the life of the tree. Distinct from the operation ``id``.
Package archive
---------------
@@ -147,7 +129,7 @@ uid and gid 0 and mtime 0.
``Beefile``, ``README.md``, ``cert.der`` and ``build-environment.json`` are
reserved and cannot be ``[[files]]`` or upatch targets.
-:doc:`/upatches/publish/beefile` describes the Beefile.
+:doc:`/reference/formats/beefile` describes the Beefile.
On install the target loads every regular file in :src:`upatches/` whose name
ends in ``.upatch`` but not in ``.unload.upatch``, in name order. Uninstall
@@ -316,368 +298,6 @@ version again with a different ``manifest_digest`` or ``package_digest``.
The target keeps the verified document as
``/var/lib/shirudo/bpm/repos/<source>/index.json``.
-upatch tree
------------
-
-A tree is an append-only sequence of ``add`` and ``delete`` operations in
-one repository, ``oci://<registry>/<repository>``. ``bpm tree append``
-publishes one operation per ``[upatches.tree]`` entry of a package.
-
-Tree objects in the registry
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-.. list-table::
- :header-rows: 1
- :widths: 26 74
-
- * - Object
- - Content
- * - Publication manifest
- - At ``<repository>:<reference>``, ``stable`` unless
- ``--reference`` names another tag. OCI image manifest,
- ``schemaVersion`` 2, ``artifactType``
- ``application/vnd.shirudo.upatch.tree.v1``, the empty config, and
- exactly one document layer and one signature layer, in that order.
- Its bytes are exactly those ``bpm tree append`` writes: compact
- JSON with the keys ``schemaVersion``, ``mediaType``,
- ``artifactType``, ``config`` and ``layers`` in this order, and each
- descriptor's ``mediaType``, ``digest`` and ``size``. A target and
- ``bpm tree append`` refuse a manifest in any other form, so that the
- manifest digest a target records and a successor names as its
- parent or segment follows from the two signed layers.
- * - Sealed segment
- - A publication manifest that a later segment names in
- ``base.segment_manifest_digest``, unchanged since it was the
- current one. Tagged ``segment-<k>``, ``k`` counting the sealed
- segments from 1, only so that registry garbage collection keeps
- it; targets fetch it by digest and never read the tag.
- * - Document layer
- - The publication document, media type
- ``application/vnd.shirudo.upatch.tree.v1+json``.
- * - Signature layer
- - Detached CMS signature over the document layer's bytes, media type
- ``application/vnd.shirudo.upatch.tree.signature.v1``.
- * - Artifact manifest
- - One per operation, tagged ``upatch-<id>-<payload16>``, where
- ``<payload16>`` is the first 16 hex digits of the artifact's
- ``payload_sha256``. ``artifactType`` and layer media type
- ``application/vnd.shirudo.upatch.v1``, the empty config, one layer
- holding the ``.upatch`` file, annotation
- ``org.opencontainers.image.title`` ``<id>.upatch``. An ``add``
- publishes the load artifact, a ``delete`` the unload directive.
-
-Publication document
-~~~~~~~~~~~~~~~~~~~~
-
-.. code-block:: text
-
- {"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>}}
-
-.. list-table::
- :header-rows: 1
- :widths: 28 72
-
- * - Key
- - Value
- * - ``schema``
- - ``1``. Required.
- * - ``tree_id``
- - A package name. Required.
- * - ``generation``
- - Required. 1 for the first publication, one more for each append.
- From 0 to 2\ :sup:`63` - 2.
- * - ``parent_manifest_digest``
- - Digest of the publication manifest this one replaces. Absent in
- the first publication.
- * - ``base.seq``
- - Required. 0 for the first segment of the tree, otherwise the
- ``head.seq`` of the sealed segment before it.
- * - ``base.segment_manifest_digest``
- - Required when ``base.seq`` is above 0 and refused at 0. Digest of
- the sealed publication manifest of the segment before this one.
- * - ``base.history_root``
- - Required when ``base.seq`` is above 0 and refused at 0. 64 hex
- digits: the ``history_root`` every node's ``outcomes`` record
- holds at ``base.seq``, see `Node records`_.
- * - ``operations``
- - Required. At most 512. Each ``seq`` is one more than the previous
- one, and the first is ``base.seq + 1``. At least one when
- ``base.seq`` is above 0.
- * - ``head.seq``
- - Required. The ``seq`` of the last operation, or ``base.seq`` when
- there is none. Below 2\ :sup:`63` - 1.
-
-Unknown keys are ignored.
-
-Operation
-~~~~~~~~~
-
-.. code-block:: text
-
- {"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>"}
-
-.. list-table::
- :header-rows: 1
- :widths: 28 72
-
- * - Key
- - Value
- * - ``seq``
- - Positive sequence number.
- * - ``op``
- - ``add`` or ``delete``.
- * - ``id``
- - The upatch name of the artifact. Must be a valid upatch name.
- * - ``selector``
- - Which nodes apply the operation, see `Selector`_. ``bpm tree
- append`` always writes it. Absent or ``{}``, it matches every node.
- * - ``artifact.repository``
- - ``oci://<registry>/<repository>`` the artifact manifest lives in.
- * - ``artifact.manifest_digest``
- - Digest of the artifact manifest.
- * - ``artifact.layer_digest``
- - Digest of the ``.upatch`` layer.
- * - ``artifact.payload_sha256``
- - ``sha256:`` and the artifact's header ``payload_sha256``.
- * - ``fixes``
- - Optional, on an ``add`` only: the IDs of the advisories the upatch
- fixes, 1 to 16 strings of 1 to 255 bytes of letters, digits,
- ``.``, ``_``, ``:`` and ``-``, each once, in byte order. A
- convention of the keepalive backend, not of shirudo: the CMS
- signature covers it, the operation digest does not, and the target
- never reads, checks or measures it, so a malformed one never makes
- a node refuse the publication. ``bpm tree append`` writes it after
- ``artifact`` from the Beefile's ``fixes``
- (:doc:`/upatches/publish/beefile`), leaves it out when the list is
- empty, carries every earlier operation's list into the next
- generation unchanged, and refuses to append to a publication whose
- list breaks these rules.
- * - ``operation_digest``
- - ``sha256:`` and the SHA-256 of the canonical operation, see
- `Operation digest`_.
-
-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.
-
-.. list-table::
- :header-rows: 1
- :widths: 26 30 44
-
- * - Key
- - Type
- - Matches when
- * - ``architecture``
- - list of strings
- - One value equals ``uname`` machine, for example ``x86_64``.
- * - ``kernel_release_prefix``
- - list of strings
- - The kernel release starts with the value, followed by the end, a
- ``.`` or a ``-``.
- * - ``kernel_build_id``
- - list of strings
- - One value equals the kernel's GNU build ID from
- ``/sys/kernel/notes``, lowercase hex. A kernel without one never
- matches.
- * - ``kconfig``
- - object of lists
- - For each option, its value in ``/proc/config.gz``, else
- ``/boot/config-<release>``, is in the list. ``# CONFIG_<x> is not
- set`` reads as ``n``. ``kernel_config`` is accepted as an alias when
- parsing.
- * - ``labels``
- - object of lists
- - For each key, the node label's value is in the list. Node labels
- come from ``etc/shirudo/node.labels`` in the config image. A node
- without labels never matches.
-
-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``.
-- ``selector`` keys in byte order: ``architecture``, ``kconfig``,
- ``kernel_build_id``, ``kernel_release_prefix``, ``labels``. Empty lists
- are left out. ``kconfig`` and ``labels`` keys in byte order.
-- List values in the published order. ``bpm tree append`` sorts them in
- byte order before it publishes.
-- ``artifact`` keys in the order ``repository``, ``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
-:doc:`eventlog`.
-
-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 runtime image's initial
- certificate.
-#. The document parses with the rules above, ``tree_id`` is a package
- name, and every operation has a valid ``id``, ``op`` and digests and a
- correct ``operation_digest``.
-#. ``tree_id`` equals the one the node recorded.
-#. A publication other than the recorded one has a higher
- ``generation``. A direct successor that names a
- ``parent_manifest_digest`` names the recorded manifest.
-#. ``head.seq`` is not below the node's last applied ``seq``.
-#. When ``base.seq`` lies past the node's last applied ``seq``, 0 for a
- node without a state, the node walks back to it through the sealed
- segments, see `Walk`_.
-#. Base check: the ``history_root`` of the node's ``outcomes`` at
- ``base.seq``, 32 zero bytes at 0, equals ``base.history_root``.
-#. Prefix check: the publication's operation digests, folded from
- ``base.history_root`` up to the node's last applied ``seq``, give the
- node's ``history_root`` there. 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 with
- ``EKEYREJECTED``.
-
-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 fetches back to the
-segment its last applied ``seq`` lies in, then applies the segments
-forwards. 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 fetches
- ``manifests/<base.segment_manifest_digest>``. The sealed segment must
- pass checks 1 to 3 above, hash to that digest, have the same
- ``tree_id``, end at its successor's ``base.seq`` and have a lower
- ``generation`` (``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.
-
-Node records
-~~~~~~~~~~~~
-
-The target keeps these under ``/var/lib/shirudo/bpm/upatch-tree/``. They are
-not published.
-
-.. list-table::
- :header-rows: 1
- :widths: 22 78
-
- * - File
- - Content
- * - ``state.json``
- - JSON object with ``schema`` (1), ``tree_id``, ``generation``,
- ``manifest_digest``, ``head_seq`` and ``segment_base_seq`` of the
- publication the node last accepted, ``last_seq``,
- ``projection_root`` and ``projection_root_tpm``. ``head_seq`` and
- ``segment_base_seq`` are the publication's ``head.seq`` and
- ``base.seq``. A sync records a publication, each segment of a walk
- in turn, once it passes the checks above and an interrupted
- operation is completed, before it processes the first new
- operation of it, so 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. ``last_seq`` also moves past
- operations whose selector does not match. 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 ``schema``
- (1), ``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, with ``schema`` (1), ``seq``, ``outcome``,
- ``projection_root`` and ``history_root``. ``outcome`` is 1 for an
- operation that was applied, 2 for one whose selector did not
- match and 3 for an ``add`` that was measured but not loaded
- because of ``attach_target_missing``. ``projection_root`` is the
- node's projection root after the operation, which an unmatched
- one leaves where it was. ``history_root`` is the SHA-256 of
- ``shirudo-tree-history``, a NUL byte, the previous history root
- and the raw operation digest, starting from 32 zero bytes: it
- counts every operation, whatever its outcome, so it is the same
- on every node at the same ``seq``. A line is written and synced
- to disk before the ``state.json`` that covers it, and a line at
- or below ``last_seq`` is never rewritten. Lines past ``last_seq``
- and a last line without its newline are what a sync that stopped
- left: the next sync drops them before it appends. It then 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``). Nothing rebuilds or prunes the file:
- the keepalive reads its last 512 operations from it whatever
- segments held them (:doc:`/reference/cli/status`).
- * - ``pending.json``
- - JSON object with ``schema`` (1), ``seq``, ``id`` and
- ``operation_digest`` while an operation is in progress. The next
- sync completes the operation without applying it again when the
- tree eventlog or this boot's eventlog already records it, and
- applies it again otherwise. Completing it writes the ``outcomes``
- lines the stopped sync did not commit: outcome 2 for each
- operation between ``last_seq`` and the pending one, which that
- sync passed over, then the pending operation's, 3 when it is an
- ``add`` whose upatch is not loaded, with its ``status/<id>``, and
- 1 otherwise. An ``add`` applied again whose upatch
- a stopped sync already loaded with its payload counts as
- installed.
- * - ``artifacts/<hex>.upatch``
- - Fetched artifacts, named by their layer digest.
- * - ``status/<id>``
- - ``skipped: module not loaded`` for an ``add`` whose attach target
- was missing.
-
-:doc:`/reference/files` lists every file shirudo keeps.
-
Limits
------
@@ -698,38 +318,17 @@ Limits
- 4 MiB
* - Index entries
- 512
- * - Tree operations per publication
- - 512
- * - Tree walk of a node that has processed an operation,
- ``TREE_MAX_WALK_OPS``
- - 65,536 operations from its last applied ``seq``
- * - Tree walk of a node that has processed none, ``TREE_MAX_JOIN_OPS``
- - 1,048,576 operations from ``seq`` 0
* - 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.
-
Related
-------
+- :doc:`beefile`
+- :doc:`upatch-tree`
- :doc:`/upatches/publish/publishing`
- :doc:`/operate/run/deliver-packages`
- :doc:`/reference/cli/bpm`
-- :doc:`configuration` for repository and tree settings
+- :doc:`/reference/configuration` for repository settings
diff --git a/Documentation/reference/formats/index.rst b/Documentation/reference/formats/index.rst
index f0893110..bc1aa61f 100644
--- a/Documentation/reference/formats/index.rst
+++ b/Documentation/reference/formats/index.rst
@@ -2,20 +2,23 @@
SPDX-License-Identifier: BSD-2-Clause
Copyright (c) 2026 Authors of shirudo
-Formats and settings
-====================
+Formats
+=======
-The formats shirudo reads and writes: the signed ``.upatch`` container,
-packages, signed indexes and upatch trees, the configuration files and
-their keys, the eventlog, the ``shirudo status --json`` document and the
-OTLP documents shirudo exports.
+The formats shirudo reads and writes, in the order a upatch meets them:
+the Beefile that describes a package, the signed ``.upatch`` container,
+the package and the signed index that lists it, the upatch tree, the
+``shirudo status --json`` document a target reports, and the OTLP
+documents it exports, its keepalive and its map logs and metrics.
.. toctree::
:titlesonly:
+ beefile
upatch-format
bpm-formats
- configuration
- eventlog
+ upatch-tree
status-json
otlp
+ keepalive
+ map-export
diff --git a/Documentation/reference/formats/keepalive.rst b/Documentation/reference/formats/keepalive.rst
new file mode 100644
index 00000000..72c93f2b
--- /dev/null
+++ b/Documentation/reference/formats/keepalive.rst
@@ -0,0 +1,410 @@
+..
+ SPDX-License-Identifier: BSD-2-Clause
+ Copyright (c) 2026 Authors of shirudo
+
+:page-type: Reference
+:audience: Operators
+
+Keepalive
+=========
+
+The keepalive is the status record a target's TPM quotes and sends to
+its collector: one OTLP log record that ``shirudo status --otel`` sends
+when ``shirudo-keepalive.timer`` runs it. The transport, the endpoint
+and the resource it shares with the map documents are in :doc:`otlp`.
+
+.. _keepalive-format:
+
+Log record
+----------
+
+One log record in ``resourceLogs[0].scopeLogs[0].logRecords``:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 30 70
+
+ * - Field
+ - Value
+ * - ``timeUnixNano``, ``observedTimeUnixNano``
+ - Wall clock when shirudo builds the document, nanoseconds since
+ the epoch, decimal string.
+ * - ``severityNumber``, ``severityText``
+ - ``9`` ``INFO`` for ``ok``. ``13`` ``WARN`` for ``degraded``,
+ ``init-pending`` and ``reboot-pending``. ``17`` ``ERROR`` for
+ every other verdict, ``tampered`` and ``lsm-off`` included.
+ * - ``eventName``
+ - ``shirudo.keepalive``
+ * - ``body``
+ - ``{"stringValue": <body>}``: the keepalive body
+ (:ref:`keepalive-body-format`) as one string, never a
+ ``kvlistValue``. A collector
+ may re-encode a structure, and the quote covers these exact
+ bytes.
+ * - Attribute ``shirudo.quote``
+ - The one attribute, a string: the TPM quote of the body, below.
+
+``timeUnixNano`` and the resource attributes are for display only. They
+identify nothing and order nothing; the quote does both.
+
+``shirudo.quote`` has three fields in this order, separated by ``;``
+with no blanks, each in standard base64 with padding:
+
+.. code-block:: none
+
+ attest=<TPMS_ATTEST>;sig=<TPMT_SIGNATURE>;ak=<TPMT_PUBLIC>
+
+.. list-table::
+ :header-rows: 1
+ :widths: 14 86
+
+ * - Field
+ - Value
+ * - ``attest``
+ - The ``TPMS_ATTEST`` the TPM signed, without the ``TPM2B`` size: a
+ ``TPM2_Quote`` whose qualifying data is the SHA-256 of the body
+ bytes and whose PCR selection is one SHA-256 bank with no PCR set.
+ Its clock information, ``resetCount`` and ``clock``, orders the
+ keepalives of one node.
+ * - ``sig``
+ - The marshalled ``TPMT_SIGNATURE`` over ``attest``: ECDSA with
+ SHA-256.
+ * - ``ak``
+ - The marshalled ``TPMT_PUBLIC`` of the attestation key, without
+ the ``TPM2B`` size: the fixed-template P-256 ECDSA primary under
+ the endorsement hierarchy that :doc:`/reference/cli/attest` uses.
+ ``000b`` and the SHA-256 of these bytes is the key's name, which
+ identifies the node. The quote's signer is the key's qualified
+ name under the endorsement hierarchy.
+
+:doc:`/reference/cli/quote-check` checks a quote against its body without
+a TPM. An attestation quote always selects a PCR, so it cannot pass as
+a keepalive quote. A quote that checks proves that the body is
+unchanged since the key signed it, not that the key lives in a TPM.
+
+When no TPM answers or the quote fails, ``status --otel`` sends nothing.
+A body that JSON cannot carry unchanged, one with a NUL byte or
+malformed UTF-8, is not sent either; the body ``status`` builds is never
+one.
+
+The keepalive uses ``map_export.otel_endpoint``,
+``map_export.tenant_id``, ``map_export.otel_insecure``,
+``map_export.otel_retries`` and ``map_export.otlp_max_bytes``.
+``status --otel`` exits ``1`` when the export fails and ``2`` when the
+``map_export.*`` settings are invalid.
+
+.. _keepalive-body-format:
+
+Keepalive body
+--------------
+
+The body is the record the quote covers, the bytes that ``status
+--keepalive`` prints. It is one compact JSON object in UTF-8: no blank
+or newline between tokens, no trailing newline, at most 4095 bytes. Its
+23 keys are always present and come in the order of the tables below,
+which group them as identity, health, upatch tree and loaded set; a key
+that does not apply is ``null``, never left out. A hash is 64 lowercase
+hex digits. An integer is a JSON number with no sign, fraction or
+exponent.
+
+.. code-block:: none
+
+ Identity schema boot_id version_id config_root kernel_release
+ image_id image_version image_root
+ Health verdict cond flags tamper integrity
+ Upatch tree tree_id generation base_seq last_seq base_root
+ projection_root mask
+ Loaded set set_sha256 count not_ok
+
+A collector reads a condition, a tamper counter and an integrity counter
+by its place. A new one is added after the last, never put between two.
+
+Identity
+~~~~~~~~
+
+Which boot, build, configuration, kernel and image the record speaks
+for. Nothing in the body names the host: the attestation key of the
+quote identifies the node.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 18 16 66
+
+ * - Key
+ - Type
+ - Value
+ * - ``schema``
+ - string
+ - ``shirudo.keepalive/1``.
+ * - ``boot_id``
+ - string
+ - The kernel's ``/proc/sys/kernel/random/boot_id``, a UUID.
+ * - ``version_id``
+ - hash
+ - The binary's ``SHIRUDO_VERSION_ID``, as ``shirudo version
+ --version-id`` prints it (:doc:`/reference/versions`).
+ * - ``config_root``
+ - hash or ``null``
+ - The dm-verity root of the selected signed config image. ``null``
+ unless that config is active.
+ * - ``kernel_release``
+ - string
+ - The kernel release, as ``uname -r`` prints it.
+ * - ``image_id``
+ - string or ``null``
+ - ``IMAGE_ID`` of ``/etc/os-release``, else of
+ ``/usr/lib/os-release``. ``null`` when neither has it.
+ * - ``image_version``
+ - string or ``null``
+ - ``IMAGE_VERSION`` of the same file. ``null`` when it has none.
+ * - ``image_root``
+ - hash or ``null``
+ - ``roothash=`` of the kernel command line, else ``usrhash=``,
+ lowercased. ``null`` when neither is there or the one taken is
+ not 64 hex digits.
+
+Health
+~~~~~~
+
+What the node reports about itself, as ``shirudo status`` evaluates it.
+The detail strings of the conditions stay in ``status --json``; the body
+carries only the outcomes.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 18 16 66
+
+ * - Key
+ - Type
+ - Value
+ * - ``verdict``
+ - string
+ - The verdict of :doc:`/reference/cli/status`: ``tampered``,
+ ``lsm-off``, ``init-pending``, ``reboot-pending``, ``degraded``
+ or ``ok``.
+ * - ``cond``
+ - integer
+ - The seven conditions, two bits each, 0 to 16383.
+ * - ``flags``
+ - integer
+ - Bits that qualify what the body reports.
+ * - ``tamper``
+ - array of integers or ``null``
+ - Every counter of :doc:`/security/tamper-counters`, zeros
+ included, in the order of that page. ``null`` with
+ ``tamper_unavailable``.
+ * - ``integrity``
+ - array of integers or ``null``
+ - Every counter of :doc:`/security/integrity-counters` the same
+ way. ``null`` with ``integrity_unavailable``.
+
+``cond`` holds two bits per condition, condition *i* at bits ``2i`` and
+``2i+1``:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 10 30 60
+
+ * - *i*
+ - Condition
+ - Bits
+ * - 0
+ - ``LsmAttached``
+ - 0 and 1
+ * - 1
+ - ``KeyringSealed``
+ - 2 and 3
+ * - 2
+ - ``ChainIntact``
+ - 4 and 5
+ * - 3
+ - ``UpatchesMeasured``
+ - 6 and 7
+ * - 4
+ - ``TpmMeasured``
+ - 8 and 9
+ * - 5
+ - ``ConfigActive``
+ - 10 and 11
+ * - 6
+ - ``XdpCovered``
+ - 12 and 13
+
+Each pair is ``00`` not evaluated, ``01`` ``OK``, ``10`` ``WARN`` or
+``11`` ``ALERT``. All seven ``OK`` is ``5461``.
+
+The bits of ``flags``:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 8 24 68
+
+ * - Bit
+ - Name
+ - Set when
+ * - 0
+ - ``register_rebound``
+ - The register was bound more than once for this TPM reset.
+ * - 1
+ - ``bound_late``
+ - This boot's ``init`` record says the register was bound from the
+ root file system, not from the initrd.
+ * - 2
+ - ``tree_log_mismatch``
+ - The tree eventlog does not replay to the ``projection_root`` of
+ ``state.json``, or the outcomes record lacks a line the window
+ needs; ``base_root`` and ``mask`` are then ``null``.
+ * - 3
+ - ``tamper_unavailable``
+ - The tamper counters cannot be read; ``tamper`` is ``null``.
+ * - 4
+ - ``tree_op_pending``
+ - A tree operation was left in flight: ``pending.json`` existed
+ before or after the read, after a sync stopped mid-operation.
+ * - 5
+ - ``snapshot_unsettled``
+ - ``state.json`` kept changing while the body was read, which the
+ config operation lock leaves to a writer outside it.
+ * - 6
+ - ``integrity_unavailable``
+ - The integrity counters cannot be read; ``integrity`` is ``null``.
+
+Upatch tree
+~~~~~~~~~~~
+
+Where the node is in the upatch tree it follows and what it did at each
+operation of a window of the last 512. All seven keys are ``null`` when
+the node follows no tree or its tree state cannot be read. The window
+and the outcomes come from the outcomes record of
+:doc:`/reference/formats/upatch-tree`, which keeps every operation the
+node processed, those of sealed segments included.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 18 16 66
+
+ * - Key
+ - Type
+ - Value
+ * - ``tree_id``
+ - string or ``null``
+ - The ``tree_id`` of the upatch tree the node follows
+ (:ref:`upatch-tree-format`).
+ * - ``generation``
+ - integer or ``null``
+ - The ``generation`` of the publication the node recorded.
+ * - ``base_seq``
+ - integer or ``null``
+ - The sequence number the window starts after: the head of the
+ recorded publication less 512, or 0 for a tree of 512 operations
+ or fewer.
+ * - ``last_seq``
+ - integer or ``null``
+ - The last operation the node processed.
+ * - ``base_root``
+ - hash or ``null``
+ - The node's projection root after ``base_seq``, 64 zeros at 0.
+ ``null`` with ``tree_log_mismatch``.
+ * - ``projection_root``
+ - hash or ``null``
+ - The node's projection root after ``last_seq``, as ``state.json``
+ records it.
+ * - ``mask``
+ - string or ``null``
+ - The outcome of every operation of the window. ``""`` for a
+ window of no operation, ``null`` with ``tree_log_mismatch``.
+
+``mask`` is standard base64 with padding of two bits per operation, from
+``base_seq + 1`` to the head of the recorded publication: ``01``
+applied, ``10`` passed over, ``11`` module absent, ``00`` not reached,
+which every operation past ``last_seq`` is. The first operation takes
+the two highest bits of the first byte, the next the two below them,
+and the last byte is padded with ``00``. A full window of 512 operations
+is 128 bytes, 172 characters.
+
+Loaded set
+~~~~~~~~~~
+
+What is loaded now, as one hash and two counts, the same size for one
+upatch or a thousand.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 18 16 66
+
+ * - Key
+ - Type
+ - Value
+ * - ``set_sha256``
+ - hash
+ - SHA-256 over a ``<payload_sha256> <name>`` line for every loaded
+ upatch, sorted by name: the ``set_digest`` form of the ``init``
+ event (:doc:`/reference/eventlog`). Upatches loaded outside the
+ tree are included.
+ * - ``count``
+ - integer
+ - The upatches loaded.
+ * - ``not_ok``
+ - integer
+ - The loaded upatches the tree holds a status file for.
+
+Example
+~~~~~~~
+
+The body of a target with verdict ``ok`` that follows no tree:
+
+.. code-block:: json
+
+ {"schema":"shirudo.keepalive/1","boot_id":"82639935-1127-4dab-91b5-f818eabc7f13","version_id":"d0d7aa800303439023907d1979d917d46a21bec21f816689c138728a28e84af9","config_root":"6d5ed552f448a1c07e3b9d24f5a86c1e0b7d93f2c4e5a6b7180c9d2e3f4a5b6c","kernel_release":"7.3.0-bpf-next+","image_id":null,"image_version":null,"image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[15,0,0,0,0,1,0,0,0,0,0,8,0,0,0,0,0,1,0,0,1,0,0,0,0,0,7,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":null,"generation":null,"base_seq":null,"last_seq":null,"base_root":null,"projection_root":null,"mask":null,"set_sha256":"5f0c2e8b7a1d4c3f9e6b2a0d8c7f1e3b5a9d4c2e6f8b0a1d3c5e7f9b2d4a6c8e","count":1,"not_ok":0}
+
+Keepalive document
+------------------
+
+The keepalive of a target with verdict ``ok``, as the code builds it.
+Angle brackets mark values that vary, and the body string is shortened
+to its first keys:
+
+.. code-block:: json
+
+ {
+ "resourceLogs": [
+ {
+ "resource": {
+ "attributes": [
+ {"key": "service.name", "value": {"stringValue": "shirudo"}},
+ {"key": "service.version", "value": {"stringValue": "<version>"}},
+ {"key": "host.name", "value": {"stringValue": "<host>"}}
+ ]
+ },
+ "scopeLogs": [
+ {
+ "scope": {"name": "shirudo.keepalive", "version": "<version>"},
+ "logRecords": [
+ {
+ "timeUnixNano": "<ns>",
+ "observedTimeUnixNano": "<ns>",
+ "severityNumber": 9,
+ "severityText": "INFO",
+ "eventName": "shirudo.keepalive",
+ "body": {
+ "stringValue": "{\"schema\":\"shirudo.keepalive/1\",\"boot_id\":\"<boot-id>\",\"version_id\":\"<version-id>\",...}"
+ },
+ "attributes": [
+ {"key": "shirudo.quote", "value": {"stringValue": "attest=<base64>;sig=<base64>;ak=<base64>"}}
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+
+Related
+-------
+
+- :doc:`otlp`
+- :doc:`/reference/cli/status`
+- :doc:`/reference/cli/quote-check`
+- :doc:`/operate/run/telemetry`
+- :doc:`/operate/backend/index`
diff --git a/Documentation/reference/formats/map-export.rst b/Documentation/reference/formats/map-export.rst
new file mode 100644
index 00000000..f17b1e88
--- /dev/null
+++ b/Documentation/reference/formats/map-export.rst
@@ -0,0 +1,225 @@
+..
+ SPDX-License-Identifier: BSD-2-Clause
+ Copyright (c) 2026 Authors of shirudo
+
+:page-type: Reference
+:audience: Operators
+
+Map logs and metrics
+====================
+
+What ``shirudo upatch map --otel`` and ``shirudo upatch map --all``
+export from a upatch's maps: a log record or the decoder's metrics per
+map, a reference to a snapshot stored in S3, or a line of JSON. The
+transport, the endpoint and the resource it shares with the keepalive
+are in :doc:`otlp`.
+
+Map snapshot log
+----------------
+
+One log record per map:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 30 70
+
+ * - Field
+ - Value
+ * - ``timeUnixNano``, ``observedTimeUnixNano``
+ - Wall clock when shirudo builds the document, nanoseconds since
+ the epoch, decimal string.
+ * - ``severityNumber``, ``severityText``
+ - ``9``, ``INFO``
+ * - ``eventName``
+ - ``shirudo.bpf.map.snapshot``
+ * - ``body``
+ - The value the map's decoder returns, as an OTLP value. Without a
+ decoder, a ``kvlistValue`` of the map's contents, see
+ `Undecoded body`_.
+ * - Attribute ``shirudo.upatch.name``
+ - The upatch name.
+ * - Attribute ``shirudo.upatch.location``
+ - The upatch's attach point.
+ * - Attribute ``shirudo.map.name``
+ - The map name.
+ * - Attribute ``shirudo.map.type``
+ - The map type name.
+ * - Attribute ``shirudo.map.max_entries``
+ - Integer.
+ * - Attribute ``shirudo.map.n_entries``
+ - Integer, entries read.
+ * - Attribute ``shirudo.map.n_cpus``
+ - Integer.
+ * - Attribute ``shirudo.map.serialized``
+ - Boolean, the map was read through its serializer.
+ * - Attribute ``shirudo.map.truncated``
+ - Boolean, the read stopped before the last entry.
+
+A decoded body larger than ``map_export.log_record_max_bytes`` (default
+1048576, at most ``map_export.otlp_max_bytes``) fails with ``E2BIG``.
+
+Undecoded body
+~~~~~~~~~~~~~~
+
+.. list-table::
+ :header-rows: 1
+ :widths: 30 70
+
+ * - Key
+ - Value
+ * - ``name``, ``type``, ``max_entries``, ``n_entries``
+ - The map.
+ * - ``n_cpus``
+ - Per-CPU maps only.
+ * - ``serialized``
+ - Boolean.
+ * - ``serialized_pages``, ``serialized_bytes``, ``pages``
+ - Serializer-backed maps. Each page has ``page_index``,
+ ``cursor``, ``next_cursor``, ``done``, ``flags``, ``chunks``,
+ ``bytes`` and ``data_hex``.
+ * - ``skipped``
+ - The reason, for a map type shirudo cannot read generically.
+ * - ``truncated``, ``n_truncated_at``
+ - Other maps. ``n_truncated_at`` only when truncated.
+ * - ``btf``
+ - ``key_type``, ``value_type``, and ``key_type_def`` and
+ ``value_type_def`` when known.
+ * - ``entries``
+ - Each with ``key`` and ``value``, or for per-CPU maps ``key``,
+ ``values_per_cpu`` and ``sum``, formatted from BTF.
+
+Map metrics
+-----------
+
+A decoder that declares the metric signal returns a list of OTLP
+``Metric`` objects. shirudo sends them as
+``resourceMetrics[0].scopeMetrics[0].metrics`` under the resource and
+scope of :ref:`otlp-resource-scope` and adds no attributes.
+
+Signal selection
+~~~~~~~~~~~~~~~~
+
+.. list-table::
+ :header-rows: 1
+ :widths: 40 60
+
+ * - Map
+ - Export
+ * - Has a decoder
+ - The signal the decoder declares, log or metric.
+ * - No decoder, unsigned per-CPU integer value
+ - Classified as a metric. Metrics come only from decoders, so the
+ export fails with ``ENODATA``.
+ * - No decoder, any other map
+ - Log record with the undecoded body.
+
+For an undecoded map ``upatch map`` prints the choice on standard
+error as ``otel: selected <signal> for <type> map <name>: <reason>``.
+
+S3 snapshots
+------------
+
+When a decoded map's document fails with ``E2BIG`` and an S3 URI is
+set (``--s3-uri=<uri>`` or ``map_export.s3_uri``), shirudo uploads the
+snapshot to S3 and sends a reference log record instead. Undecoded,
+skipped and truncated maps are not uploaded.
+``map_export.s3_uri`` requires ``map_export.otel_endpoint``.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 30 70
+
+ * - Property
+ - Value
+ * - URI
+ - ``s3://<bucket>[/<prefix>]``. Bucket: 3 to 63 characters from
+ ``a-z``, ``0-9``, ``.`` and ``-``, starting and ending with a
+ letter or digit. Prefix: at most 512 bytes, no control
+ characters, ``?``, ``#``, ``.`` or ``..`` segments.
+ * - Object
+ - The decoder's JSON output, gzip-compressed, at most 64 MiB
+ before compression.
+ * - Key
+ - ``[<prefix>/]<host>/<upatch>/<map>/<sha256>.json.gz``.
+ ``<host>`` is the host name with every character other than
+ ``A-Z``, ``a-z``, ``0-9``, ``-``, ``_`` and ``.`` replaced by
+ ``_``. ``<sha256>`` is the digest of the compressed object.
+ * - URL
+ - With ``AWS_ENDPOINT_URL_S3``: ``<endpoint>/<bucket>/<key>``.
+ Else ``https://<bucket>.s3.<region>.amazonaws.com/<key>``, or
+ ``https://s3.<region>.amazonaws.com/<bucket>/<key>`` for a
+ bucket name with a dot.
+ * - Request
+ - ``PUT`` signed with AWS SigV4, with ``If-None-Match: *``,
+ ``Cache-Control: immutable``, ``x-amz-content-sha256``,
+ ``x-amz-checksum-sha256``, ``x-amz-meta-shirudo-schema: 1``,
+ ``x-amz-meta-shirudo-upatch`` and ``x-amz-meta-shirudo-map``.
+ ``412`` counts as already uploaded.
+ * - Timeout and retries
+ - 10 seconds per attempt. Retries as for OTLP, also on ``408``,
+ ``409`` and ``500``.
+ * - Cleartext
+ - As for OTLP, for ``AWS_ENDPOINT_URL_S3``. Insecure mode also
+ turns off certificate verification for the AWS endpoints.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 40 60
+
+ * - Variable
+ - Value
+ * - ``AWS_ACCESS_KEY_ID``, ``AWS_SECRET_ACCESS_KEY``
+ - Required. Missing credentials fail with ``EACCES``.
+ * - ``AWS_SESSION_TOKEN``
+ - Sent as ``x-amz-security-token``.
+ * - ``AWS_REGION``, ``AWS_DEFAULT_REGION``
+ - Region, in this order, default ``us-east-1``.
+ * - ``AWS_ENDPOINT_URL_S3``
+ - S3-compatible endpoint, path-style.
+ * - ``AWS_CA_BUNDLE``
+ - CA bundle for the S3 endpoint.
+
+The reference log record goes to the logs endpoint, whatever signal
+the decoder declares, and is not subject to
+``map_export.otlp_max_bytes``:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 44 56
+
+ * - Field
+ - Value
+ * - ``eventName``
+ - ``shirudo.bpf.map.snapshot.reference``
+ * - ``severityNumber``, ``severityText``
+ - ``9``, ``INFO``
+ * - ``body``
+ - ``stringValue``: ``BPF map snapshot stored in S3: <uri>``
+ * - Attributes
+ - The map snapshot attributes above, and
+ ``shirudo.map.snapshot.uri``,
+ ``shirudo.map.snapshot.format`` (``shirudo.map.v1+json``),
+ ``shirudo.map.snapshot.content_type`` (``application/json``),
+ ``shirudo.map.snapshot.content_encoding`` (``gzip``),
+ ``shirudo.map.snapshot.size_bytes``,
+ ``shirudo.map.snapshot.uncompressed_size_bytes`` and
+ ``shirudo.map.snapshot.sha256``.
+
+JSON lines
+----------
+
+``map_export.json_path`` or ``upatch map --json=<path>`` appends one line
+per map to a file, instead of OTLP or besides it. The line is the JSON
+value the map's decoder returns, not an OTLP document. A map without a
+decoder fails with ``ENODATA``. ``map_export.json_path`` must be an
+absolute path. A file or directory that carries shirudo's seal label is
+refused. A new file gets mode ``0644``.
+
+Related
+-------
+
+- :doc:`otlp`
+- :doc:`/reference/cli/upatch-map`
+- :doc:`/upatches/write/decoders`
+- :doc:`/operate/run/telemetry`
+- :doc:`/reference/configuration`
diff --git a/Documentation/reference/formats/otlp.rst b/Documentation/reference/formats/otlp.rst
index bbc1200d..1d62c08b 100644
--- a/Documentation/reference/formats/otlp.rst
+++ b/Documentation/reference/formats/otlp.rst
@@ -18,13 +18,13 @@ one ``POST`` from a one-shot command:
* - Document
- Sent by
- Signal
- * - Status keepalive
+ * - :doc:`Status keepalive <keepalive>`
- ``shirudo status --otel``
- One log record
- * - Map snapshot
+ * - :doc:`Map snapshot <map-export>`
- ``shirudo upatch map --otel``, ``shirudo upatch map --all``
- One log record or the decoder's metrics, per map
- * - Map snapshot reference
+ * - :doc:`Map snapshot reference <map-export>`
- The same, when a snapshot goes to S3
- One log record
@@ -59,7 +59,7 @@ Transport
- TLS 1.3 only, hybrid ML-KEM key exchange
(``X25519MLKEM768``, ``SecP256r1MLKEM768``). A host listed in
``tls.classical_hosts`` may also use ``X25519`` and
- ``secp256r1``, see :doc:`configuration`.
+ ``secp256r1``, see :doc:`/reference/configuration`.
* - Cleartext
- ``http://`` only to ``localhost``, ``127.0.0.1`` or ``[::1]``,
unless insecure mode is on. Other schemes are refused.
@@ -167,6 +167,8 @@ A tenant id, from ``--tenant-id=<id>`` or ``map_export.tenant_id``, is 1
to 128 characters from ``A-Z``, ``a-z``, ``0-9``, ``.``, ``_`` and
``-``. shirudo sends it as ``X-Tenant-ID``.
+.. _otlp-resource-scope:
+
Resource and scope
------------------
@@ -195,335 +197,17 @@ Every document has one resource and one scope.
Attribute values follow the OTLP JSON encoding: ``stringValue``,
``intValue`` as a decimal string, ``boolValue``.
-Status keepalive
-----------------
-
-One log record in ``resourceLogs[0].scopeLogs[0].logRecords``:
-
-.. list-table::
- :header-rows: 1
- :widths: 30 70
-
- * - Field
- - Value
- * - ``timeUnixNano``, ``observedTimeUnixNano``
- - Wall clock when shirudo builds the document, nanoseconds since
- the epoch, decimal string.
- * - ``severityNumber``, ``severityText``
- - ``9`` ``INFO`` for ``ok``. ``13`` ``WARN`` for ``degraded``,
- ``init-pending`` and ``reboot-pending``. ``17`` ``ERROR`` for
- every other verdict, ``tampered`` and ``lsm-off`` included.
- * - ``eventName``
- - ``shirudo.keepalive``
- * - ``body``
- - ``{"stringValue": <body>}``: the keepalive body that ``status
- --keepalive`` prints (:doc:`/reference/cli/status`), the compact
- JSON object as one string, never a ``kvlistValue``. A collector
- may re-encode a structure, and the quote covers these exact
- bytes.
- * - Attribute ``shirudo.quote``
- - The one attribute, a string: the TPM quote of the body, below.
-
-``timeUnixNano`` and the resource attributes are for display only. They
-identify nothing and order nothing; the quote does both.
-
-``shirudo.quote`` has three fields in this order, separated by ``;``
-with no blanks, each in standard base64 with padding:
-
-.. code-block:: none
-
- attest=<TPMS_ATTEST>;sig=<TPMT_SIGNATURE>;ak=<TPMT_PUBLIC>
-
-.. list-table::
- :header-rows: 1
- :widths: 14 86
-
- * - Field
- - Value
- * - ``attest``
- - The ``TPMS_ATTEST`` the TPM signed, without the ``TPM2B`` size: a
- ``TPM2_Quote`` whose qualifying data is the SHA-256 of the body
- bytes and whose PCR selection is one SHA-256 bank with no PCR set.
- Its clock information, ``resetCount`` and ``clock``, orders the
- keepalives of one node.
- * - ``sig``
- - The marshalled ``TPMT_SIGNATURE`` over ``attest``: ECDSA with
- SHA-256.
- * - ``ak``
- - The marshalled ``TPMT_PUBLIC`` of the attestation key, without
- the ``TPM2B`` size: the fixed-template P-256 ECDSA primary under
- the endorsement hierarchy that :doc:`/reference/cli/attest` uses.
- ``000b`` and the SHA-256 of these bytes is the key's name, which
- identifies the node. The quote's signer is the key's qualified
- name under the endorsement hierarchy.
-
-:doc:`/reference/cli/quote-check` checks a quote against its body without
-a TPM. An attestation quote always selects a PCR, so it cannot pass as
-a keepalive quote. A quote that checks proves that the body is
-unchanged since the key signed it, not that the key lives in a TPM.
-
-When no TPM answers or the quote fails, ``status --otel`` sends nothing.
-A body that JSON cannot carry unchanged, one with a NUL byte or
-malformed UTF-8, is not sent either; the body ``status`` builds is never
-one.
-
-The keepalive uses ``map_export.otel_endpoint``,
-``map_export.tenant_id``, ``map_export.otel_insecure``,
-``map_export.otel_retries`` and ``map_export.otlp_max_bytes``.
-``status --otel`` exits ``1`` when the export fails and ``2`` when the
-``map_export.*`` settings are invalid.
-
-Map snapshot log
-----------------
-
-One log record per map:
-
-.. list-table::
- :header-rows: 1
- :widths: 30 70
-
- * - Field
- - Value
- * - ``timeUnixNano``, ``observedTimeUnixNano``
- - Wall clock when shirudo builds the document, nanoseconds since
- the epoch, decimal string.
- * - ``severityNumber``, ``severityText``
- - ``9``, ``INFO``
- * - ``eventName``
- - ``shirudo.bpf.map.snapshot``
- * - ``body``
- - The value the map's decoder returns, as an OTLP value. Without a
- decoder, a ``kvlistValue`` of the map's contents, see
- `Undecoded body`_.
- * - Attribute ``shirudo.upatch.name``
- - The upatch name.
- * - Attribute ``shirudo.upatch.location``
- - The upatch's attach point.
- * - Attribute ``shirudo.map.name``
- - The map name.
- * - Attribute ``shirudo.map.type``
- - The map type name.
- * - Attribute ``shirudo.map.max_entries``
- - Integer.
- * - Attribute ``shirudo.map.n_entries``
- - Integer, entries read.
- * - Attribute ``shirudo.map.n_cpus``
- - Integer.
- * - Attribute ``shirudo.map.serialized``
- - Boolean, the map was read through its serializer.
- * - Attribute ``shirudo.map.truncated``
- - Boolean, the read stopped before the last entry.
-
-A decoded body larger than ``map_export.log_record_max_bytes`` (default
-1048576, at most ``map_export.otlp_max_bytes``) fails with ``E2BIG``.
-
-Undecoded body
-~~~~~~~~~~~~~~
-
-.. list-table::
- :header-rows: 1
- :widths: 30 70
-
- * - Key
- - Value
- * - ``name``, ``type``, ``max_entries``, ``n_entries``
- - The map.
- * - ``n_cpus``
- - Per-CPU maps only.
- * - ``serialized``
- - Boolean.
- * - ``serialized_pages``, ``serialized_bytes``, ``pages``
- - Serializer-backed maps. Each page has ``page_index``,
- ``cursor``, ``next_cursor``, ``done``, ``flags``, ``chunks``,
- ``bytes`` and ``data_hex``.
- * - ``skipped``
- - The reason, for a map type shirudo cannot read generically.
- * - ``truncated``, ``n_truncated_at``
- - Other maps. ``n_truncated_at`` only when truncated.
- * - ``btf``
- - ``key_type``, ``value_type``, and ``key_type_def`` and
- ``value_type_def`` when known.
- * - ``entries``
- - Each with ``key`` and ``value``, or for per-CPU maps ``key``,
- ``values_per_cpu`` and ``sum``, formatted from BTF.
-
-Map metrics
------------
-
-A decoder that declares the metric signal returns a list of OTLP
-``Metric`` objects. shirudo sends them as
-``resourceMetrics[0].scopeMetrics[0].metrics`` under the resource and
-scope above and adds no attributes.
-
-Signal selection
-~~~~~~~~~~~~~~~~
-
-.. list-table::
- :header-rows: 1
- :widths: 40 60
-
- * - Map
- - Export
- * - Has a decoder
- - The signal the decoder declares, log or metric.
- * - No decoder, unsigned per-CPU integer value
- - Classified as a metric. Metrics come only from decoders, so the
- export fails with ``ENODATA``.
- * - No decoder, any other map
- - Log record with the undecoded body.
-
-For an undecoded map ``upatch map`` prints the choice on standard
-error as ``otel: selected <signal> for <type> map <name>: <reason>``.
-
-S3 snapshots
-------------
-
-When a decoded map's document fails with ``E2BIG`` and an S3 URI is
-set (``--s3-uri=<uri>`` or ``map_export.s3_uri``), shirudo uploads the
-snapshot to S3 and sends a reference log record instead. Undecoded,
-skipped and truncated maps are not uploaded.
-``map_export.s3_uri`` requires ``map_export.otel_endpoint``.
-
-.. list-table::
- :header-rows: 1
- :widths: 30 70
-
- * - Property
- - Value
- * - URI
- - ``s3://<bucket>[/<prefix>]``. Bucket: 3 to 63 characters from
- ``a-z``, ``0-9``, ``.`` and ``-``, starting and ending with a
- letter or digit. Prefix: at most 512 bytes, no control
- characters, ``?``, ``#``, ``.`` or ``..`` segments.
- * - Object
- - The decoder's JSON output, gzip-compressed, at most 64 MiB
- before compression.
- * - Key
- - ``[<prefix>/]<host>/<upatch>/<map>/<sha256>.json.gz``.
- ``<host>`` is the host name with every character other than
- ``A-Z``, ``a-z``, ``0-9``, ``-``, ``_`` and ``.`` replaced by
- ``_``. ``<sha256>`` is the digest of the compressed object.
- * - URL
- - With ``AWS_ENDPOINT_URL_S3``: ``<endpoint>/<bucket>/<key>``.
- Else ``https://<bucket>.s3.<region>.amazonaws.com/<key>``, or
- ``https://s3.<region>.amazonaws.com/<bucket>/<key>`` for a
- bucket name with a dot.
- * - Request
- - ``PUT`` signed with AWS SigV4, with ``If-None-Match: *``,
- ``Cache-Control: immutable``, ``x-amz-content-sha256``,
- ``x-amz-checksum-sha256``, ``x-amz-meta-shirudo-schema: 1``,
- ``x-amz-meta-shirudo-upatch`` and ``x-amz-meta-shirudo-map``.
- ``412`` counts as already uploaded.
- * - Timeout and retries
- - 10 seconds per attempt. Retries as for OTLP, also on ``408``,
- ``409`` and ``500``.
- * - Cleartext
- - As for OTLP, for ``AWS_ENDPOINT_URL_S3``. Insecure mode also
- turns off certificate verification for the AWS endpoints.
-
-.. list-table::
- :header-rows: 1
- :widths: 40 60
-
- * - Variable
- - Value
- * - ``AWS_ACCESS_KEY_ID``, ``AWS_SECRET_ACCESS_KEY``
- - Required. Missing credentials fail with ``EACCES``.
- * - ``AWS_SESSION_TOKEN``
- - Sent as ``x-amz-security-token``.
- * - ``AWS_REGION``, ``AWS_DEFAULT_REGION``
- - Region, in this order, default ``us-east-1``.
- * - ``AWS_ENDPOINT_URL_S3``
- - S3-compatible endpoint, path-style.
- * - ``AWS_CA_BUNDLE``
- - CA bundle for the S3 endpoint.
-
-The reference log record goes to the logs endpoint, whatever signal
-the decoder declares, and is not subject to
-``map_export.otlp_max_bytes``:
-
-.. list-table::
- :header-rows: 1
- :widths: 44 56
-
- * - Field
- - Value
- * - ``eventName``
- - ``shirudo.bpf.map.snapshot.reference``
- * - ``severityNumber``, ``severityText``
- - ``9``, ``INFO``
- * - ``body``
- - ``stringValue``: ``BPF map snapshot stored in S3: <uri>``
- * - Attributes
- - The map snapshot attributes above, and
- ``shirudo.map.snapshot.uri``,
- ``shirudo.map.snapshot.format`` (``shirudo.map.v1+json``),
- ``shirudo.map.snapshot.content_type`` (``application/json``),
- ``shirudo.map.snapshot.content_encoding`` (``gzip``),
- ``shirudo.map.snapshot.size_bytes``,
- ``shirudo.map.snapshot.uncompressed_size_bytes`` and
- ``shirudo.map.snapshot.sha256``.
-
-JSON lines
-----------
-
-``map_export.json_path`` or ``upatch map --json=<path>`` appends one line
-per map to a file, instead of OTLP or besides it. The line is the JSON
-value the map's decoder returns, not an OTLP document. A map without a
-decoder fails with ``ENODATA``. ``map_export.json_path`` must be an
-absolute path. A file or directory that carries shirudo's seal label is
-refused. A new file gets mode ``0644``.
-
-Keepalive structure
--------------------
-
-The keepalive of a target with verdict ``ok``, as the code builds it.
-Angle brackets mark values that vary, and the body string is shortened
-to its first keys:
-
-.. code-block:: json
-
- {
- "resourceLogs": [
- {
- "resource": {
- "attributes": [
- {"key": "service.name", "value": {"stringValue": "shirudo"}},
- {"key": "service.version", "value": {"stringValue": "<version>"}},
- {"key": "host.name", "value": {"stringValue": "<host>"}}
- ]
- },
- "scopeLogs": [
- {
- "scope": {"name": "shirudo.keepalive", "version": "<version>"},
- "logRecords": [
- {
- "timeUnixNano": "<ns>",
- "observedTimeUnixNano": "<ns>",
- "severityNumber": 9,
- "severityText": "INFO",
- "eventName": "shirudo.keepalive",
- "body": {
- "stringValue": "{\"schema\":\"shirudo.keepalive/1\",\"boot_id\":\"<boot-id>\",\"version_id\":\"<version-id>\",...}"
- },
- "attributes": [
- {"key": "shirudo.quote", "value": {"stringValue": "attest=<base64>;sig=<base64>;ak=<base64>"}}
- ]
- }
- ]
- }
- ]
- }
- ]
- }
+This page gives what every document shares: the transport, the endpoint,
+the environment and the resource. :doc:`keepalive` and :doc:`map-export`
+give the documents.
Related
-------
+- :doc:`keepalive`
+- :doc:`map-export`
- :doc:`/operate/run/telemetry`
- :doc:`/reference/cli/status`
-- :doc:`/reference/cli/quote-check`
- :doc:`/reference/cli/upatch-map`
- :doc:`/upatches/write/decoders`
-- :doc:`status-json`
-- :doc:`configuration`
+- :doc:`/reference/configuration`
diff --git a/Documentation/reference/formats/status-json.rst b/Documentation/reference/formats/status-json.rst
index 1a391cce..00c3e219 100644
--- a/Documentation/reference/formats/status-json.rst
+++ b/Documentation/reference/formats/status-json.rst
@@ -10,8 +10,8 @@ status JSON
``shirudo status --json`` prints one JSON object on one line. The
status keepalive that ``status --otel`` sends carries a smaller record,
-the keepalive body that ``status --keepalive`` prints, see :doc:`otlp`.
-Options, exit status and the keys of the keepalive body are in
+the keepalive body that ``status --keepalive`` prints, see
+:ref:`keepalive-body-format`. Options and exit status are in
:doc:`/reference/cli/status`. How to read a report is in
:doc:`/operate/run/read-status`.
@@ -645,7 +645,7 @@ tpm
``/var/lib/shirudo/eventlog``, all boots), ``bytes``, and
``events`` with ``--include-eventlog``.
-:doc:`eventlog` defines the records and the replay.
+:doc:`/reference/eventlog` defines the records and the replay.
upatch_tree
-----------
@@ -682,7 +682,7 @@ upatch_tree
state cannot be read, as the keepalive's ``tree_log_mismatch``
has it, and ``null`` when the log cannot be replayed.
-:doc:`bpm-formats` defines the tree state.
+:doc:`upatch-tree` defines the tree state.
Optional blocks
---------------
@@ -787,7 +787,7 @@ Fields to alert on
- A different shirudo build runs on the target.
A collector that stops receiving the keepalive from a target has lost
-the target or its export, see :doc:`otlp`.
+the target or its export, see :doc:`keepalive`.
Example
-------
@@ -1048,5 +1048,6 @@ Related
- :doc:`/reference/cli/status`
- :doc:`/operate/run/read-status`
- :doc:`/security/tamper-counters`
-- :doc:`eventlog`
+- :doc:`/reference/eventlog`
- :doc:`otlp`
+- :doc:`keepalive`
diff --git a/Documentation/reference/formats/upatch-tree.rst b/Documentation/reference/formats/upatch-tree.rst
new file mode 100644
index 00000000..3e95b109
--- /dev/null
+++ b/Documentation/reference/formats/upatch-tree.rst
@@ -0,0 +1,667 @@
+..
+ SPDX-License-Identifier: BSD-2-Clause
+ Copyright (c) 2026 Authors of shirudo
+
+:page-type: Reference
+:audience: upatch authors, operators
+
+.. _upatch-tree-format:
+
+upatch tree
+===========
+
+An 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
+(:ref:`keepalive-body-format`) 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 :doc:`/contribute/testing/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
+--------
+
+The objects and keys of a tree, and where each is defined:
+
+.. code-block:: none
+
+ In the registry Registry objects
+ publication manifest <repository>:stable
+ document layer, signature layer the signed publication
+ sealed segments earlier publications, by digest
+ artifact manifests one .upatch per operation
+ Publication document Publication document
+ schema format version
+ tree_id which tree, for life
+ generation which publication
+ parent_manifest_digest the one it replaces
+ base where this segment starts
+ operations the list, at most 512
+ head.seq last operation
+ Operation Operation
+ seq, op, id position, add or delete, upatch
+ selector which nodes apply it
+ artifact where the .upatch is
+ fixes advisories, for the backend
+ operation_digest hash of the operation
+ Selector Selector
+ architecture, kernel_release_prefix, kernel_build_id,
+ kconfig, labels
+
+Digests in the tree carry a ``sha256:`` prefix, as OCI does; the
+keepalive leaves it out.
+
+What is signed
+--------------
+
+.. list-table::
+ :header-rows: 1
+ :widths: 24 40 36
+
+ * - Object
+ - Protection
+ - Checked by
+ * - Publication document
+ - Detached CMS signature over the exact document bytes.
+ - ``bpm tree sync``, against the active config's non-revoked BPF
+ signer set.
+ * - Artifact manifest and ``.upatch`` layer
+ - Not signed. Each signed operation pins them by
+ ``manifest_digest``, ``layer_digest`` and ``payload_sha256``.
+ - ``bpm tree sync``.
+ * - ``.upatch`` file
+ - CMS signature, ML-DSA-87, over ``loader_insns || data``.
+ - The kernel, at every load and unload.
+
+The detached signature uses the CMS profile of
+:doc:`bpm-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
+-----
+
+.. list-table::
+ :header-rows: 1
+ :widths: 24 30 46
+
+ * - Name
+ - Source
+ - Rule
+ * - ``tree_id``
+ - ``--tree-id``, else the package name of the first append
+ - A package name (:doc:`bpm-formats`). Fixed for the life of the
+ tree. Distinct from the operation ``id``.
+ * - Operation ``id``
+ - Beefile ``[upatches.tree] id``
+ - Must equal the upatch name of the artifact it publishes, so the
+ source file's basename. ``bpm tree append`` and ``bpm tree sync``
+ both refuse a mismatch.
+
+Registry objects
+----------------
+
+.. list-table::
+ :header-rows: 1
+ :widths: 26 74
+
+ * - Object
+ - Content
+ * - Publication manifest
+ - At ``<repository>:<reference>``, ``stable`` unless
+ ``--reference`` names another tag. OCI image manifest,
+ ``schemaVersion`` 2, ``artifactType``
+ ``application/vnd.shirudo.upatch.tree.v1``, the empty config, and
+ exactly one document layer and one signature layer, in that order.
+ Its bytes are exactly those ``bpm tree append`` writes: compact
+ JSON with the keys ``schemaVersion``, ``mediaType``,
+ ``artifactType``, ``config`` and ``layers`` in this order, and each
+ descriptor's ``mediaType``, ``digest`` and ``size``. A target and
+ ``bpm tree append`` refuse a manifest in any other form, so that the
+ manifest digest a target records and a successor names as its
+ parent or segment follows from the two signed layers.
+ * - Sealed segment
+ - A publication manifest that a later segment names in
+ ``base.segment_manifest_digest``, unchanged since it was the
+ current one. Tagged ``segment-<k>``, ``k`` counting the sealed
+ segments from 1, only so that registry garbage collection keeps
+ it; targets fetch it by digest and never read the tag.
+ * - Document layer
+ - The publication document, media type
+ ``application/vnd.shirudo.upatch.tree.v1+json``.
+ * - Signature layer
+ - Detached CMS signature over the document layer's bytes, media type
+ ``application/vnd.shirudo.upatch.tree.signature.v1``.
+ * - Artifact manifest
+ - One per operation, tagged ``upatch-<id>-<payload16>``, where
+ ``<payload16>`` is the first 16 hex digits of the artifact's
+ ``payload_sha256``. ``artifactType`` and layer media type
+ ``application/vnd.shirudo.upatch.v1``, the empty config, one layer
+ holding the ``.upatch`` file, annotation
+ ``org.opencontainers.image.title`` ``<id>.upatch``. An ``add``
+ publishes the load artifact, a ``delete`` the unload directive.
+
+Publication document
+--------------------
+
+One JSON object per generation. Every append signs a new document that
+holds the segment's operations so far.
+
+.. code-block:: text
+
+ {"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>}}
+
+.. list-table::
+ :header-rows: 1
+ :widths: 28 72
+
+ * - Key
+ - Value
+ * - ``schema``
+ - ``1``. Required.
+ * - ``tree_id``
+ - A package name. Required.
+ * - ``generation``
+ - Required. 1 for the first publication, one more for each append.
+ From 0 to 2\ :sup:`63` - 2.
+ * - ``parent_manifest_digest``
+ - Digest of the publication manifest this one replaces. Absent in
+ the first publication.
+ * - ``base.seq``
+ - Required. 0 for the first segment of the tree, otherwise the
+ ``head.seq`` of the sealed segment before it.
+ * - ``base.segment_manifest_digest``
+ - Required when ``base.seq`` is above 0 and refused at 0. Digest of
+ the sealed publication manifest of the segment before this one.
+ * - ``base.history_root``
+ - Required when ``base.seq`` is above 0 and refused at 0. 64 hex
+ digits: the ``history_root`` every node's ``outcomes`` record
+ holds at ``base.seq``, see `Node records`_.
+ * - ``operations``
+ - Required. At most 512. Each ``seq`` is one more than the previous
+ one, and the first is ``base.seq + 1``. At least one when
+ ``base.seq`` is above 0.
+ * - ``head.seq``
+ - Required. The ``seq`` of the last operation, or ``base.seq`` when
+ there is none. Below 2\ :sup:`63` - 1.
+
+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.
+
+.. code-block:: text
+
+ {"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>"}
+
+.. list-table::
+ :header-rows: 1
+ :widths: 28 72
+
+ * - Key
+ - Value
+ * - ``seq``
+ - Positive sequence number.
+ * - ``op``
+ - ``add`` or ``delete``.
+ * - ``id``
+ - The upatch name of the artifact. Must be a valid upatch name.
+ * - ``selector``
+ - Which nodes apply the operation, see `Selector`_. ``bpm tree
+ append`` always writes it. Absent or ``{}``, it matches every node.
+ * - ``artifact.repository``
+ - ``oci://<registry>/<repository>`` the artifact manifest lives in.
+ * - ``artifact.manifest_digest``
+ - Digest of the artifact manifest.
+ * - ``artifact.layer_digest``
+ - Digest of the ``.upatch`` layer.
+ * - ``artifact.payload_sha256``
+ - ``sha256:`` and the artifact's header ``payload_sha256``.
+ * - ``fixes``
+ - Optional, on an ``add`` only: the IDs of the advisories the upatch
+ fixes, 1 to 16 strings of 1 to 255 bytes of letters, digits,
+ ``.``, ``_``, ``:`` and ``-``, each once, in byte order. A
+ convention of the keepalive backend, not of shirudo: the CMS
+ signature covers it, the operation digest does not, and the target
+ never reads, checks or measures it, so a malformed one never makes
+ a node refuse the publication. ``bpm tree append`` writes it after
+ ``artifact`` from the Beefile's ``fixes``
+ (:doc:`/reference/formats/beefile`), leaves it out when the list is
+ empty, carries every earlier operation's list into the next
+ generation unchanged, and refuses to append to a publication whose
+ list breaks these rules.
+ * - ``operation_digest``
+ - ``sha256:`` and the SHA-256 of the canonical operation, see
+ `Operation digest`_.
+
+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.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 26 30 44
+
+ * - Key
+ - Type
+ - Matches when
+ * - ``architecture``
+ - list of strings
+ - One value equals ``uname`` machine, for example ``x86_64``.
+ * - ``kernel_release_prefix``
+ - list of strings
+ - The kernel release starts with the value, followed by the end, a
+ ``.`` or a ``-``.
+ * - ``kernel_build_id``
+ - list of strings
+ - One value equals the kernel's GNU build ID from
+ ``/sys/kernel/notes``, lowercase hex. A kernel without one never
+ matches.
+ * - ``kconfig``
+ - object of lists
+ - For each option, its value in ``/proc/config.gz``, else
+ ``/boot/config-<release>``, is in the list. ``# CONFIG_<x> is not
+ set`` reads as ``n``. ``kernel_config`` is accepted as an alias when
+ parsing.
+ * - ``labels``
+ - object of lists
+ - For each key, the node label's value is in the list. Node labels
+ come from ``etc/shirudo/node.labels`` in the config image. A node
+ without labels never matches.
+
+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``.
+- ``selector`` keys in byte order: ``architecture``, ``kconfig``,
+ ``kernel_build_id``, ``kernel_release_prefix``, ``labels``. Empty lists
+ are left out. ``kconfig`` and ``labels`` keys in byte order.
+- List values in the published order. ``bpm tree append`` sorts them in
+ byte order before it publishes.
+- ``artifact`` keys in the order ``repository``, ``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
+:doc:`/reference/eventlog`.
+
+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``. :doc:`beefile` gives the keys; the selector tables
+become ``selector``, with each list sorted in byte order.
+
+.. code-block:: toml
+
+ [[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:
+
+.. code-block:: json
+
+ {"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 runtime image's initial
+ certificate.
+#. The document parses with the rules above, ``tree_id`` is a package
+ name, and every operation has a valid ``id``, ``op`` and digests and a
+ correct ``operation_digest``.
+#. ``tree_id`` equals the one the node recorded.
+#. A publication other than the recorded one has a higher
+ ``generation``. A direct successor that names a
+ ``parent_manifest_digest`` names the recorded manifest.
+#. ``head.seq`` is not below the node's last applied ``seq``.
+#. When ``base.seq`` lies past the node's last applied ``seq``, 0 for a
+ node without a state, the node walks back to it through the sealed
+ segments, see `Walk`_.
+#. Base check: the ``history_root`` of the node's ``outcomes`` at
+ ``base.seq``, 32 zero bytes at 0, equals ``base.history_root``.
+#. Prefix check: the publication's operation digests, folded from
+ ``base.history_root`` up to the node's last applied ``seq``, give the
+ node's ``history_root`` there. 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 with
+ ``EKEYREJECTED``.
+
+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 fetches back to the
+segment its last applied ``seq`` lies in, then applies the segments
+forwards. 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 fetches
+ ``manifests/<base.segment_manifest_digest>``. The sealed segment must
+ pass checks 1 to 3 above, hash to that digest, have the same
+ ``tree_id``, end at its successor's ``base.seq`` and have a lower
+ ``generation`` (``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``.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 10 10 44 18 18
+
+ * - ``outcomes``
+ - ``mask``
+ - Operation
+ - Loads or unloads
+ - Into the chain and register
+ * - 1
+ - ``01``
+ - The selector matched and the operation was applied.
+ - yes
+ - yes
+ * - 2
+ - ``10``
+ - The selector did not match: passed over for good.
+ - no
+ - no
+ * - 3
+ - ``11``
+ - The selector matched, but an ``add``'s attach target was missing
+ (``attach_target_missing``): measured, not loaded, with
+ ``status/<id>``.
+ - no
+ - yes
+ * - none
+ - ``00``
+ - Not reached yet: past ``last_seq``.
+ - 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.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 22 78
+
+ * - File
+ - Content
+ * - ``state.json``
+ - JSON object with ``schema`` (1), ``tree_id``, ``generation``,
+ ``manifest_digest``, ``head_seq`` and ``segment_base_seq`` of the
+ publication the node last accepted, ``last_seq``,
+ ``projection_root`` and ``projection_root_tpm``. ``head_seq`` and
+ ``segment_base_seq`` are the publication's ``head.seq`` and
+ ``base.seq``. A sync records a publication, each segment of a walk
+ in turn, once it passes the checks above and an interrupted
+ operation is completed, before it processes the first new
+ operation of it, so 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. ``last_seq`` also moves past
+ operations whose selector does not match. 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 ``schema``
+ (1), ``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, with ``schema`` (1), ``seq``, ``outcome``,
+ ``projection_root`` and ``history_root``. ``outcome`` is 1 for an
+ operation that was applied, 2 for one whose selector did not
+ match and 3 for an ``add`` that was measured but not loaded
+ because of ``attach_target_missing``. ``projection_root`` is the
+ node's projection root after the operation, which an unmatched
+ one leaves where it was. ``history_root`` is the SHA-256 of
+ ``shirudo-tree-history``, a NUL byte, the previous history root
+ and the raw operation digest, starting from 32 zero bytes: it
+ counts every operation, whatever its outcome, so it is the same
+ on every node at the same ``seq``. A line is written and synced
+ to disk before the ``state.json`` that covers it, and a line at
+ or below ``last_seq`` is never rewritten. Lines past ``last_seq``
+ and a last line without its newline are what a sync that stopped
+ left: the next sync drops them before it appends. It then 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``). Nothing rebuilds or prunes the file:
+ the keepalive reads its last 512 operations from it whatever
+ segments held them (:doc:`/reference/cli/status`).
+ * - ``pending.json``
+ - JSON object with ``schema`` (1), ``seq``, ``id`` and
+ ``operation_digest`` while an operation is in progress. The next
+ sync completes the operation without applying it again when the
+ tree eventlog or this boot's eventlog already records it, and
+ applies it again otherwise. Completing it writes the ``outcomes``
+ lines the stopped sync did not commit: outcome 2 for each
+ operation between ``last_seq`` and the pending one, which that
+ sync passed over, then the pending operation's, 3 when it is an
+ ``add`` whose upatch is not loaded, with its ``status/<id>``, and
+ 1 otherwise. An ``add`` applied again whose upatch
+ a stopped sync already loaded with its payload counts as
+ installed.
+ * - ``artifacts/<hex>.upatch``
+ - Fetched artifacts, named by their layer digest.
+ * - ``status/<id>``
+ - ``skipped: module not loaded`` for an ``add`` whose attach target
+ was missing.
+
+:doc:`/reference/files` lists every file shirudo keeps.
+
+Limits
+------
+
+.. list-table::
+ :header-rows: 1
+ :widths: 50 50
+
+ * - Item
+ - Limit
+ * - Operations per publication
+ - 512
+ * - Values per selector list
+ - 16, of fewer than 256 bytes
+ * - ``kconfig`` and ``labels`` keys
+ - 64 each
+ * - Walk of a node that has processed an operation,
+ ``TREE_MAX_WALK_OPS``
+ - 65,536 operations from its last applied ``seq``
+ * - Walk of a node that has processed none, ``TREE_MAX_JOIN_OPS``
+ - 1,048,576 operations from ``seq`` 0
+ * - 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.
+
+.. code-block:: text
+
+ {"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:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 22 26 26 26
+
+ * - Operation
+ - Node A: ``x86_64``, 7.4.2, ``role=edge``, XFS ``m``, ``xfs``
+ loaded
+ - Node B: ``aarch64``, 7.3.9, ``role=core``, XFS ``y``
+ - Node C: ``x86_64``, 7.4.2, ``role=core``, XFS ``m``, ``xfs`` not
+ loaded
+ * - 1 ``add kernel-obs``
+ - ``01``
+ - ``01``
+ - ``01``
+ * - 2 ``add net-guard``
+ - ``01``
+ - ``10``, architecture
+ - ``10``, label
+ * - 3 ``add xfs-fix``
+ - ``01``
+ - ``10``, release
+ - ``11``, module not loaded
+ * - 4 ``delete kernel-obs``
+ - ``01``
+ - ``01``
+ - ``01``
+ * - 5 ``add kernel-obs``
+ - ``01``
+ - ``01``
+ - ``01``
+ * - Loaded
+ - ``kernel-obs`` (new), ``net-guard``, ``xfs-fix``
+ - ``kernel-obs`` (new)
+ - ``kernel-obs`` (new)
+ * - Chained
+ - 1 to 5
+ - 1, 4, 5
+ - 1, 3, 4, 5
+ * - ``mask``
+ - ``"VUA="``
+ - ``"aUA="``
+ - ``"bUA="``
+
+Each node's keepalive reports ``last_seq`` 5, its ``mask`` and its
+``projection_root``, folded from the digests of the operations it
+chained.
+
+Related
+-------
+
+- :doc:`beefile` for the ``[upatches.tree]`` keys
+- :doc:`bpm-formats` for packages and the repository index
+- :doc:`keepalive` for what a node reports of its walk
+- :doc:`/upatches/publish/publishing`
+- :doc:`/reference/cli/bpm` for ``bpm tree append``, ``sync`` and ``show``
+- :doc:`/reference/configuration` for the tree settings
diff --git a/Documentation/reference/index.rst b/Documentation/reference/index.rst
index e028b4e8..08e0fb5c 100644
--- a/Documentation/reference/index.rst
+++ b/Documentation/reference/index.rst
@@ -6,7 +6,7 @@ Reference
=========
Facts to look up: every command and its options, the formats shirudo
-reads and writes, its settings, the failure categories and exit status,
+reads and writes, its settings and its eventlog, the failure categories and exit status,
the files and extended attributes it keeps, its systemd units and the
environment variables it reads. Each fact has one home here, and the
other sections link to it.
@@ -17,6 +17,8 @@ other sections link to it.
cheat-sheet
cli/index
formats/index
+ configuration
+ eventlog
failure-categories
files
systemd-units
diff --git a/Documentation/reference/systemd-units.rst b/Documentation/reference/systemd-units.rst
index e3165e70..fe35690e 100644
--- a/Documentation/reference/systemd-units.rst
+++ b/Documentation/reference/systemd-units.rst
@@ -194,7 +194,7 @@ The keepalive is sent only when ``map_export.otel_endpoint``,
``OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`` or ``OTEL_EXPORTER_OTLP_ENDPOINT``
names an endpoint, and only with its TPM quote: a run whose TPM does not
answer or does not quote fails and sends nothing. See
-:doc:`/reference/formats/otlp`.
+:doc:`/reference/formats/keepalive`.
A keepalive and a ``bpm tree sync`` do not run at once. Every target
command holds the config operation lock for its whole run, and a sync
@@ -261,7 +261,7 @@ shirudo-map-export.service
- ``infinity``
The destinations come from the ``map_export.*`` settings, see
-:doc:`/reference/formats/configuration`.
+:doc:`/reference/configuration`.
shirudo-bpm-repo-update.service
-------------------------------
@@ -382,7 +382,7 @@ Related
- :doc:`/reference/environment` for the variables the
``EnvironmentFile=`` files set
-- :doc:`/reference/formats/configuration` for the settings the services
+- :doc:`/reference/configuration` for the settings the services
read
- :doc:`/reference/cli/init`, :doc:`/reference/cli/status`,
:doc:`/reference/cli/upatch-map` and :doc:`/reference/cli/bpm` for the
diff --git a/Documentation/reference/versions.rst b/Documentation/reference/versions.rst
index ab535cfb..80bab339 100644
--- a/Documentation/reference/versions.rst
+++ b/Documentation/reference/versions.rst
@@ -149,8 +149,8 @@ target reads:
- 1
- Not checked.
-:doc:`/reference/formats/bpm-formats` describes the package, index and
-tree documents.
+:doc:`/reference/formats/bpm-formats` describes the package and index
+documents, :doc:`/reference/formats/upatch-tree` the tree documents.
Documents the target writes for operators, collectors and scripts:
@@ -164,7 +164,7 @@ Documents the target writes for operators, collectors and scripts:
* - Eventlog record ``schema``
- 1
- Not checked by ``status``, ``init``, ``attest`` or ``attest
- verify``. See :doc:`/reference/formats/eventlog`.
+ verify``. See :doc:`/reference/eventlog`.
* - Evidence document ``schema``, with ``kind``
``shirudo-attestation``
- 1
@@ -211,7 +211,7 @@ State the target keeps for itself:
Configuration and bootstrap files carry no version. Unknown keys in the
two bootstrap files and the host file draw a warning, and a config image
whose ``shirudo.conf`` holds a key other than ``eventlog.max_bytes`` or
-``map_export.*`` is refused (:doc:`/reference/formats/configuration`).
+``map_export.*`` is refused (:doc:`/reference/configuration`).
The config image's hash tree must carry the standard ``veritysetup``
superblock, version 1, with hash type 1, SHA-256, 4096-byte blocks and a
32-byte salt.
diff --git a/Documentation/start/guides/publish-package.rst b/Documentation/start/guides/publish-package.rst
index be0a5e67..ac038df6 100644
--- a/Documentation/start/guides/publish-package.rst
+++ b/Documentation/start/guides/publish-package.rst
@@ -202,7 +202,7 @@ Remove it
Next steps
----------
-- :doc:`/upatches/publish/beefile` describes every key of a ``Beefile``.
+- :doc:`/reference/formats/beefile` describes every key of a ``Beefile``.
- :doc:`/upatches/publish/publishing` publishes to a registry and to the signed
upatch tree.
- :doc:`/operate/run/deliver-packages` registers repositories in the signed
diff --git a/Documentation/upatches/index.rst b/Documentation/upatches/index.rst
index 9aa9af48..d9240ad7 100644
--- a/Documentation/upatches/index.rst
+++ b/Documentation/upatches/index.rst
@@ -10,7 +10,7 @@ an observation into a signed upatch and ship it as a package. Start with
:doc:`/upatches/learn/concepts`, then follow
:doc:`/upatches/learn/kernel-fix-tutorial` from a real kernel fix to a
published package. :doc:`/upatches/write/attach-kinds` and
-:doc:`/upatches/publish/beefile` are the references to keep at hand, and
+:doc:`/reference/formats/beefile` are the references to keep at hand, and
:doc:`/upatches/test/debugging` explains each way a load can fail.
- :doc:`learn/index`: concepts, the kernel-fix tutorial and the example
diff --git a/Documentation/upatches/learn/concepts.rst b/Documentation/upatches/learn/concepts.rst
index 62d847eb..61ca602a 100644
--- a/Documentation/upatches/learn/concepts.rst
+++ b/Documentation/upatches/learn/concepts.rst
@@ -202,7 +202,7 @@ file, the eventlog record and the target of its unload directive.
``--name`` sets another.
* - name in a package
- The base name of the ``source`` in the Beefile, the same rule
- without an override. :doc:`/upatches/publish/beefile` has the details.
+ without an override. :doc:`/reference/formats/beefile` has the details.
* - tree id
- Equal to the upatch name. :doc:`/upatches/publish/publishing` explains
why.
diff --git a/Documentation/upatches/learn/examples.rst b/Documentation/upatches/learn/examples.rst
index 2e4a594f..eb5e6cba 100644
--- a/Documentation/upatches/learn/examples.rst
+++ b/Documentation/upatches/learn/examples.rst
@@ -99,10 +99,10 @@ checked against an exploit.
:doc:`/upatches/learn/kernel-fix-tutorial` takes the third detector from its fix
to a package, as an ``fentry`` program. ``kernel-cve.bee`` itself does not
build, and its tree entries do not match its upatch names.
-:doc:`/upatches/publish/beefile` lists what is wrong with it.
+:doc:`/reference/formats/beefile` lists what is wrong with it.
Related
-------
- :doc:`/upatches/learn/kernel-fix-tutorial` to write a detector of your own
-- :doc:`/upatches/publish/beefile` for the keys both Beefiles use
+- :doc:`/reference/formats/beefile` for the keys both Beefiles use
diff --git a/Documentation/upatches/learn/kernel-fix-tutorial.rst b/Documentation/upatches/learn/kernel-fix-tutorial.rst
index cf2a58fb..4e33ec44 100644
--- a/Documentation/upatches/learn/kernel-fix-tutorial.rst
+++ b/Documentation/upatches/learn/kernel-fix-tutorial.rst
@@ -375,7 +375,7 @@ tree ``id`` must equal it. The selector limits the tree entry to kernels
built with IPv6. A target evaluates it against ``/proc/config.gz`` or
``/boot/config-<release>``. A target that has neither does not match, and
a target that does not match an entry passes over it for good.
-:doc:`/upatches/publish/beefile` lists every key.
+:doc:`/reference/formats/beefile` lists every key.
Build the package:
diff --git a/Documentation/upatches/publish/beefile.rst b/Documentation/upatches/publish/beefile.rst
deleted file mode 100644
index 3593b9d0..00000000
--- a/Documentation/upatches/publish/beefile.rst
+++ /dev/null
@@ -1,445 +0,0 @@
-..
- SPDX-License-Identifier: BSD-2-Clause
- Copyright (c) 2026 Authors of shirudo
-
-:page-type: Reference
-:audience: upatch authors
-
-Beefile reference
-=================
-
-A Beefile describes a package: its name, the files it ships, the upatches
-``shirudo bpm build`` compiles and signs into it, and the entries
-``shirudo bpm tree append`` publishes to an upatch tree. ``bpm build``
-reads ``<context>/Beefile``, or the file given with ``--file``, and treats
-the directory that holds it as the package directory. Every path in the
-Beefile is relative to that directory. The package archives the Beefile
-unchanged as its ``Beefile`` member. :doc:`/reference/cli/bpm` lists the
-command options and :doc:`/reference/formats/bpm-formats` the archive
-format.
-
-Syntax
-------
-
-A Beefile is a small subset of TOML, read line by line.
-
-- Each line holds one table header, one ``key = value`` pair, a comment
- or nothing.
-- A value is a quoted string or an array of quoted strings on the same
- line. A ``"..."`` string takes the escapes ``\n``, ``\r``, ``\t``,
- ``\\`` and ``\"``; a ``'...'`` string takes none. A tree id or
- selector value holding a control character, as the first three spell,
- is refused by ``bpm tree append``, as no node could read the
- publication.
-- ``#`` starts a comment outside a string.
-- Numeric values are accepted for policy bit masks; booleans, inline
- tables and values that span lines are not supported.
-- ``[[upatches.rodata]]``, ``[[upatches.policy]]`` and the
- ``[upatches.tree]`` tables belong to the
- ``[[upatches]]`` entry above them. Write an entry's own keys before its
- first sub-table: a key after ``[upatches.tree]`` belongs to that table.
-
-``bpm build`` reports every error in the file, of syntax or of content,
-as ``bpm build: <file> is not a valid Beefile``, without a line number.
-For a ``fixes`` it refuses, a ``Beefile: fixes ...`` line before that one
-says what is wrong with the list.
-
-Keys
-----
-
-``[package]``
-~~~~~~~~~~~~~
-
-.. list-table::
- :header-rows: 1
- :widths: 18 14 10 58
-
- * - Key
- - Type
- - Required
- - Rules
- * - ``name``
- - string
- - yes
- - The package name: 1 to 127 characters of letters, digits, ``.``,
- ``_`` and ``-``, starting with a letter or a digit. The archive is
- ``<name>-<version>.bee``.
- * - ``description``
- - string
- - no
- - Read and ignored.
- * - ``license``
- - string
- - no
- - Read and ignored.
- * - ``authors``
- - array of strings
- - no
- - Read and ignored.
-
-A ``README.md`` in the package directory is added to the package, and
-``shirudo bpm info`` prints it.
-
-``[[files]]``
-~~~~~~~~~~~~~
-
-One table per file to ship as it is: headers, generator programs, lists,
-reproducers.
-
-.. list-table::
- :header-rows: 1
- :widths: 18 14 10 58
-
- * - Key
- - Type
- - Required
- - Rules
- * - ``source``
- - string
- - yes
- - A regular file inside the package directory. Not absolute, no
- ``..`` component, and its real path must not leave the directory.
- * - ``target``
- - string
- - no
- - The member path in the package. Default: ``source``. Not absolute,
- no empty, ``.`` or ``..`` component.
-
-``[[upatches]]``
-~~~~~~~~~~~~~~~~
-
-One table per upatch to build. ``bpm build`` compiles a ``.bpf.c``,
-signs the object into a load artifact and generates its unload directive
-from the artifact's payload digest, so a package always ships both.
-
-.. list-table::
- :header-rows: 1
- :widths: 18 14 10 58
-
- * - Key
- - Type
- - Required
- - Rules
- * - ``source``
- - string
- - yes
- - A ``.bpf.c``, ``.bpf.o`` or ``.o`` file inside the package
- directory, under the same rules as a file ``source``. The upatch
- name is its base name without ``.bpf.c``, ``.bpf.o`` or ``.o``.
- There is no key to set another name.
- * - ``type``
- - string
- - no
- - ``bpf``, the default and the only value, in any case.
- * - ``load_target``
- - string
- - no
- - The member path of the load artifact. Default:
- ``upatches/<base>.upatch``, with ``<base>`` the source's base name
- without ``.bpf.c`` or ``.bpf.o``, or without its last extension.
- * - ``unload_target``
- - string
- - no
- - The member path of the unload directive. Default:
- ``upatches/<base>.unload.upatch``.
-
-Keep both targets directly under :src:`upatches/`. On a target, ``bpm
-install`` loads every file in the package's :src:`upatches/` directory whose
-name contains ``.upatch`` but not ``.unload.upatch``, in name order, and
-``bpm uninstall`` applies every ``upatches/*.unload.upatch`` in reverse
-name order. ``bpm upgrade`` applies the old version's unload directives
-before it loads the new version, and pairs ``<x>.unload.upatch`` with
-``<x>.upatch`` to restore the old version when the new one fails. An
-artifact elsewhere is shipped but never loaded.
-
-``bpm build`` compiles a ``.bpf.c`` as ``shirudo build`` does, see
-:doc:`/reference/cli/build`, but in the package directory. It finds
-libbpf's headers in
-``./vendor/libbpf`` there, or in the operator package's
-``/usr/share/shirudo/bpf/include``, and ``vmlinux.h`` at ``--vmlinux``,
-then at ``./vmlinux.h`` and ``./vendor/linux/vmlinux.h`` of the directory
-``bpm build`` runs in, then of the package directory, then at the
-installed path. ``bpm build`` passes no extra compiler flags.
-
-``[[upatches.rodata]]``
-~~~~~~~~~~~~~~~~~~~~~~~
-
-Generated data for one ``const`` variable in the upatch's ``.rodata``. A
-generator program produces the variable's bytes from an input file at
-``bpm build``, and an updater program does the same at ``bpm config
-update``, which re-signs the upatch without compiling it again.
-
-.. list-table::
- :header-rows: 1
- :widths: 18 14 10 58
-
- * - Key
- - Type
- - Required
- - Rules
- * - ``symbol``
- - string
- - yes
- - The variable's name in the object's BTF, at most 127 characters.
- * - ``input``
- - string
- - yes
- - The default input, a regular file inside the package directory,
- not absolute, without ``..``.
- * - ``generator``
- - array of strings
- - yes
- - The command for ``bpm build``, 1 to 16 arguments.
- * - ``update``
- - array of strings
- - yes
- - The command for ``bpm config update``, 1 to 16 arguments.
-
-The first argument of a command that contains a ``/``, or else the
-second, must be a regular file inside the package directory, such as
-``["python3", "gen_watch_rodata.py"]``. shirudo runs the command without
-a shell, with ``execvp``, in the package directory, and appends ``--input
-<path> --symbol <symbol> --output <path>``. The program writes the
-variable's raw bytes to the output file. A result whose length differs
-from the variable's size fails the build.
-
-An input is named by its file name up to the first dot: ``watch.list``
-is ``watch``. ``--rodata-input <name>=<path>`` replaces the input of every
-entry with that name for one build. An override for a name that no entry
-has fails. Entries that share a name must name the same input.
-
-``[[upatches.policy]]``
-~~~~~~~~~~~~~~~~~~~~~~~
-
-A policy table declares a named bit and the absolute paths whose
-``security.bpf.shirudo.policy`` xattrs this upatch labels. The builder
-embeds the entries in the signed ``SHPL`` section. Its presence opts the
-upatch into shirudo's shared task ``shirudo_task_policy`` and socket
-``shirudo_sock_policy`` maps. The generated loader reuses both pinned maps
-rather than creating private copies. The BPF source must declare the map
-ABI, normally by including ``policy.h`` after ``vmlinux.h`` and the
-libbpf headers.
-
-.. code-block:: toml
-
- [[upatches.policy]]
- id = "apache"
- bit = 0x1
- paths = ["/usr/local/apache", "/usr/bin/apache"]
-
-``id`` maps to one one-hot 64-bit mask. ``bit`` is read as hexadecimal,
-with or without ``0x``, so ``bit = 10`` is ``0x10``. Repeating the same
-ID and mask in other upatches extends that policy; an ID cannot change
-masks, and two different IDs cannot use the same mask in one package.
-Every path is absolute and may name a non-executable file.
-
-For an upatch with at least one policy table, include ``policy.h`` in
-its BPF source so it declares both shared maps with the required ABI.
-It also brings ``XATTR_POLICY``, the name of the xattr, for a program
-that reads it. The header is installed beside the shirudo BPF headers.
-The signed ``SHPL`` section opts the upatch into these bindings;
-declaring the maps without policy tables leaves them as ordinary
-upatch-owned maps. Signed BPF programs can write the maps, so enforcement
-programs must treat them as read-only by contract. Root can give its own
-processes any bit, through a file system it mounts whose executables
-carry the xattr, so let a bit restrict what a task may do, never exempt
-it from a rule.
-
-The generator and the updater run on the operator host with the
-operator's rights. The target receives only the signed result. Without
-``--file``, ``bpm config update`` takes the Beefile and the updater from the
-base package and runs them. It also trusts the base package's unsigned
-header to locate ``.rodata`` before it re-signs, so run it only on a base
-package you built or verified yourself.
-
-``[upatches.tree]``
-~~~~~~~~~~~~~~~~~~~
-
-Optional. Present when ``bpm tree append`` is to publish the upatch as a
-tree operation.
-
-.. list-table::
- :header-rows: 1
- :widths: 18 14 10 58
-
- * - Key
- - Type
- - Required
- - Rules
- * - ``id``
- - string
- - yes
- - The operation's identity across generations. A valid upatch name,
- and equal to the upatch's name, the source's base name:
- ``bpm tree append`` refuses an artifact whose name differs, and so
- does the target.
- * - ``load_artifact``
- - string
- - no
- - The member that an ``add`` publishes. Default: ``load_target``.
- * - ``unload_artifact``
- - string
- - no
- - The member that a ``delete`` publishes. Default:
- ``unload_target``.
- * - ``fixes``
- - array of strings
- - no
- - The IDs of the advisories the upatch fixes, such as
- ``fixes = ["EXAMPLE-0101"]``: 1 to 16 IDs, each once and of 1 to
- 255 bytes of letters, digits, ``.``, ``_``, ``:`` and ``-``. The
- key may appear once.
-
-``fixes`` is a convention of the keepalive backend, which reads it to say
-which nodes are exposed to an advisory. Nodes ignore it: it selects
-nothing, and no target reads, checks or measures it. ``bpm build``
-checks the form of each ID, not that the advisory exists, and refuses a
-list that breaks the rules above, an empty list and a value that is not
-an array of strings. It keeps the Beefile as written; the order of the
-IDs does not matter, because the list is published in byte order.
-``bpm tree append`` writes it on the operation it publishes as an
-``add``, outside the operation digest, and never on a ``delete``
-(:doc:`publishing`).
-
-``[upatches.tree.selector]``
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Optional. Says where the operation applies. Every key holds an array of 1
-to 16 accepted values, and each key may appear once.
-
-.. list-table::
- :header-rows: 1
- :widths: 25 75
-
- * - Key
- - Matches when
- * - ``kernel_release_prefix``
- - ``uname -r`` starts with a value and continues with ``.``, ``-`` or
- nothing: ``7.2`` matches ``7.2.0`` and ``7.2-rc1``, not ``7.20``.
- * - ``kernel_build_id``
- - the running kernel's GNU build ID from ``/sys/kernel/notes``, in
- lowercase hex, equals a value. A kernel without one never matches.
- * - ``architecture``
- - ``uname -m`` equals a value, such as ``x86_64``, ``aarch64`` or
- ``riscv64``.
-
-``[upatches.tree.selector.kconfig]``
- Up to 64 keys, each a Kconfig option, once, with its accepted values,
- such as ``CONFIG_IPV6 = ["y", "m"]``. An option that is not set matches
- ``"n"``. The target reads ``/proc/config.gz`` and, when that is
- missing, is not one whole gzip stream or names none of the options,
- ``/boot/config-<release>``, each of at most 4 MiB. A target with
- neither does not match, and one whose configuration cannot be read
- stops the sync at the operation. A line of 1024 bytes or more is
- skipped whole, so its option reads as not set.
-``[upatches.tree.selector.labels]``
- Up to 64 keys, each a node label, once, with its accepted values, such
- as ``env = ["prod", "canary"]``. The target reads its labels from the
- signed config image's ``etc/shirudo/node.labels``. A target without
- labels does not match.
-
-A target matches a selector when it matches every key given, and a key
-when it matches one of its values. An entry without a selector applies
-everywhere. A target that does not match an operation passes over it and
-never comes back to it, also after a kernel upgrade or a label change.
-
-Unknown keys and tables
------------------------
-
-.. list-table::
- :header-rows: 1
- :widths: 50 50
-
- * - Where
- - Result
- * - an unknown key in ``[package]``, ``[[files]]``, ``[[upatches]]``,
- ``[[upatches.rodata]]``, ``[[upatches.policy]]`` or
- ``[upatches.tree.selector]``
- - refused
- * - an unknown array of tables, ``[[name]]``
- - refused
- * - an unknown table under ``upatches.tree``
- - refused, because a selector the builder cannot read would widen
- the rollout
- * - a table name with quotes, or blanks around its dots, such as
- ``[upatches ."tree".selector]``
- - refused, for the same reason
- * - an unknown key in ``[upatches.tree]``
- - ignored, as metadata for newer publishers, unless it is
- ``selector``, quoted or dotted, such as
- ``selector.architecture = ["aarch64"]``, which is refused
- * - a key before the first table, or in a table with any other name
- - ignored
-
-Limits and reserved names
--------------------------
-
-.. list-table::
- :header-rows: 1
- :widths: 50 50
-
- * - Limit
- - Value
- * - ``[[files]]`` tables
- - 128
- * - ``[[upatches]]`` tables
- - 128
- * - ``[[upatches.rodata]]`` tables per upatch
- - 16
- * - arguments per ``generator`` or ``update`` command
- - 16
- * - ``[[upatches.policy]]`` tables per upatch
- - 64
- * - ``paths`` per policy table
- - 16
- * - values per selector key
- - 16
- * - IDs in ``fixes``
- - 16, of 255 bytes each
- * - keys in each of ``kconfig`` and ``labels``
- - 64
- * - length of a string in a selector or command
- - 255 bytes
- * - package version, ``--version``
- - A SemVer 2.0.0 version of at most 127 characters, such as
- ``1.2.0``, ``1.2.0-rc.1`` or ``1.2.0+build.5``
- * - member path including ``<name>-<version>/``
- - 99 bytes, the limit of a ustar name
- * - ``.bee`` file
- - 256 MiB for all member files together
-
-Every member path must be unique, and none may lie below another: a
-name is a file or a directory, not both, so ``a`` and ``a/b`` do not go
-into one package. ``Beefile``, ``README.md``, ``cert.der`` and
-``build-environment.json`` are reserved for the members ``bpm build``
-writes itself, and no member path lies below one of them either. A
-member path longer than the ustar limit fails the build with ``bpm
-build: File name too long``, and members of more than 256 MiB together,
-or one of that size alone, with ``bpm build: the members of the package
-are more than 256 MiB together, the most a target installs``: a target
-unpacks no more.
-
-Example
--------
-
-:src:`upatches/kernel-obs/Beefile` declares one upatch with generated
-``.rodata`` and ships its generators:
-
-.. literalinclude:: ../../../upatches/kernel-obs/Beefile
- :language: toml
-
-:src:`upatches/kernel-cve/kernel-cve.bee` breaks these rules and is not a
-model. Two of its load targets make member paths longer than 99 bytes
-with any version, so ``bpm build`` fails. Its tree ids name the CVE
-directories while its upatch names are the detectors' base names, so
-``bpm tree append`` would refuse every entry. And its
-``unload_artifact`` paths name members the package does not have.
-
-Related
--------
-
-- :doc:`/upatches/publish/publishing` for building, pushing and appending a
- package
-- :doc:`/reference/cli/bpm` for ``bpm build`` and ``bpm config update``
-- :doc:`/reference/formats/bpm-formats` for the archive, the index and the
- tree
diff --git a/Documentation/upatches/publish/index.rst b/Documentation/upatches/publish/index.rst
index 88d3a22a..1d5745f0 100644
--- a/Documentation/upatches/publish/index.rst
+++ b/Documentation/upatches/publish/index.rst
@@ -5,11 +5,10 @@
Package and publish
===================
-Describe a package in its Beefile, build it, and publish it to a
-repository index or the upatch tree.
+Describe a package in its Beefile (:doc:`/reference/formats/beefile`),
+build it, and publish it to a repository index or the upatch tree.
.. toctree::
:titlesonly:
- beefile
publishing
diff --git a/Documentation/upatches/publish/publishing.rst b/Documentation/upatches/publish/publishing.rst
index 7625b5c4..fb1b9e13 100644
--- a/Documentation/upatches/publish/publishing.rst
+++ b/Documentation/upatches/publish/publishing.rst
@@ -23,7 +23,7 @@ Before you begin
describes.
- The signing key whose certificate your targets trust, in a key
directory. The same key signs the upatches, the index and the tree.
-- A package directory with a Beefile, as :doc:`/upatches/publish/beefile`
+- A package directory with a Beefile, as :doc:`/reference/formats/beefile`
describes, whose
upatches you have tested, as :doc:`/upatches/test/testing` describes.
- Push access to an OCI registry. shirudo reads credentials from
@@ -210,7 +210,8 @@ whatever the registry served.
Next steps
----------
-- :doc:`/reference/formats/bpm-formats` for the index and the tree
+- :doc:`/reference/formats/bpm-formats` for the index
+- :doc:`/reference/formats/upatch-tree` for the tree
documents
- :doc:`/operate/run/deliver-packages` to configure targets
- :doc:`/operate/run/attest` to verify what targets loaded