interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / docs / NATIVE_PACKAGE.md

206 lines · 13976 bytes Raw Blame History Rendered
1# Reproducible native package with owner-signed verification (P11 cut 1b)
2
3STATUS: IMPLEMENTED host-side (build, tbs, sign, verify, self-test). Nothing in
4this document installs, boots or touches a machine. Gate N7 stays NOT_RUN.
5SECURITY_IMPACT: RECOVERY (the package is what install, update and recovery
6will carry; the format is covered by `docs/NATIVE_IMAGE_SLOTS.md`).
7
8This is the "reproducible native package with exact component/model/firmware
9manifests and owner-signed verification" item of work package P11 (AIEN
10native v1 plan, aien-architecture CURRENT_EXECUTION_PLAN addendum 2026-10-12).
11Format 2 (2026-10-12) adds the provenance record the owner asked for: "matching
12two builds demonstrates reproducibility under the recorded build conditions.
13Connecting the signed package to reviewed source also requires recording the
14source revision, toolchain, inputs, and resulting digest. Keep that evidence
15with the release candidate."
16
17## What a package is
18
19### Integrated CPU service profile
20
21For the resident production CPU service, select `--variant service-hardware-staging`
22with `--owner-pubkeys`, `--machine-id` and `--model`. The recipe uses
23`CK_SERVICE=1 CK_HARDWARE_STAGING=1` and the in-tree inference library. The
24existing Makefile enforces owner provisioning, the resident lifecycle and
25boot-disk-only model ingest; no QEMU fw_cfg model fallback or TEST Store keys
26are selected. This profile builds a package only; it neither installs nor boots it.
27
28The standalone inference library is built offline, locked, in release mode for
29`aarch64-unknown-none` twice, using fresh Cargo homes and target directories.
30Inherited Rust environment flags and caller, repository and user Cargo
31configuration are excluded: Cargo runs from a fresh scratch directory with
32an absolute manifest path. Configuration in the scratch directory's ancestors
33is refused. The standalone crate has only local in-tree dependencies.
34Untracked files, including ignored files, in either inference crate are refused
35so Cargo cannot auto-discover an unrecorded `build.rs` or Rust module.
36Both libraries, both service images and both owner-key slot loaders must match.
37The package carries `inputs/libaienos_infer_kernel.a` in `SHA256SUMS`, binding
38the exact linked archive through the existing signed package provenance.
39
40Format 3 records the fixed inference recipe, Cargo/rustc versions, inference
41manifest and lock digests, archive bytes/digest and reproducibility result.
42`input_make_vars` binds the archive digest alongside the owner file digests.
43Verification requires exactly one of each service field, checks the archive
44and checksum coverage, and recomputes manifest/lock digests from the recorded
45revision when available. `--same-host` also compares Rust toolchain versions.
46Inference fields on other profiles are refused; existing profiles remain supported.
47
48`--model` records the supplied model's size and digest; its bytes are not embedded
49or decoded by packaging. Preparing and verifying `MODEL.MAP`, actual model
50inference, owner receipt authority, attended boot and recovery still require
51their own acceptance evidence. Public owner fixtures used by the self-test
52qualify the build recipe only and cannot authorize deployment. A dirty-tree
53package is test evidence, never a release candidate.
54
55`scripts/native_package.sh build --out DIR --generation N [...]` makes:
56
57| File | Content |
58|---|---|
59| `image/BOOTAA64.EFI` | the image (core, full, or hardware-staging variant), mode 444 |
60| `PACKAGE.txt` | the provenance record, `key value` lines (next table) |
61| `SHA256SUMS` | `sha256sum` lines over the image and `PACKAGE.txt` |
62| `PROVENANCE.txt` | `package_sha256 <64 hex>` = SHA-256(`SHA256SUMS`): the resulting package digest. It is a separate file because `SHA256SUMS` covers `PACKAGE.txt`, so `PACKAGE.txt` cannot hold a digest of `SHA256SUMS` |
63| `slot/MANIFEST.bin` | the unsigned slot manifest (`native/boot/slot_format.h`): generation, digests, commit, timestamp = commit time, **provenance = `package_sha256`** |
64| `slot/MANIFEST.tbs` | the 448 bytes the owner signs, written by `tbs --package DIR --pubkey HEX64` (or `build --pubkey`). The manifest's `signer_id` (SHA-256 of the owner public key) lies inside the signed bytes, so the bytes to sign depend on which key will sign |
65| `slot/MANIFEST.signed.bin` | after `sign`: the manifest with signer id and signature, verified before it is written |
66
67`PACKAGE.txt` lines (format 3; the loader lines are in "Slot loader in the package"), grouped as the owner's correction names them:
68
69| Group | Lines |
70|---|---|
71| Source revision | `format 3`, `repo aien-dev/aienux`, `commit <40 hex>`, `commit_time <unix seconds>`, `tree_clean yes` (`no` only for test builds with `--allow-dirty`) |
72| What was asked for | `variant`, `generation`, `policy_generation`, `min_rollback_generation` |
73| Toolchain | `toolchain_cross <prefix or none>` (the `CROSS` value the kernel Makefile resolves, asked from make itself), `toolchain_cc`, `toolchain_ld`, `toolchain_objcopy` (first line of `<CROSS>gcc/ld/objcopy --version`), `toolchain_make` (first line of `make --version`), `build_host_arch` (`uname -m`) |
74| Inputs | `input_make_goal` (`all` for core, `full` otherwise), `input_make_vars` (`none`, or `CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS=sha256:<hex> CK_MACHINE_ID=sha256:<hex>`), `input_env_ck none` (any `CK_*` in the environment or in an outer make's `MAKEFLAGS` is refused, so nothing unrecorded selects the image), `input_makefile_sha256` (`native/kernel/Makefile`), `input_image_ld_sha256` (`native/boot/image.ld`), `pin <repo> <sha>` per `--pins` line, `model_bytes`/`model_sha256` from `--model`, `firmware <name> <bytes> <sha256>` per `--firmware`, and for the staging variant `owner_pubkeys_sha256` and `machine_id_sha256` |
75| Resulting image | `image image/BOOTAA64.EFI`, `image_bytes`, `image_sha256`, `image_sha512`, `reproducible two_clean_builds_identical` |
76
77The resulting package digest is `PROVENANCE.txt` `package_sha256`.
78
79One signature covers everything: the manifest signs the image digest and the
80provenance; the provenance is `package_sha256`; `SHA256SUMS` covers
81`PACKAGE.txt` and the image. Change any record line and the provenance no
82longer matches; the self-test proves each of these refusals.
83
84The slot loader `SLOTLDR.EFI` is part of the package since P11 cut 3 (format
853): see "Slot loader in the package" at the end of this document.
86
87## What the record proves and what it does not
88
89- **Two identical builds prove reproducibility under the recorded conditions
90 only.** The same commit, built twice in fresh directories with the recorded
91 toolchain, gave the same bytes. It says nothing about other compilers,
92 other hosts or other flags.
93- **The record is what ties the package to reviewed source.** The commit
94 (with `tree_clean yes`), the toolchain lines, the inputs and the resulting
95 digests together say "these bytes came from that reviewed revision, built
96 this way". Anyone with the repository can check the commit, its time and
97 the Makefile and linker-script digests (`verify` does), and with the same
98 toolchain can rebuild and compare the image digest.
99- **It does not prove the toolchain itself is trustworthy.** A compromised
100 compiler or linker produces the same wrong bytes every time, so a
101 reproducible build inherits its flaws. The toolchain lines name what was
102 trusted; they do not vouch for it.
103- **Pins, model and firmware are recorded, not re-checked.** The package
104 carries their digests, not the files; `verify` prints them as recorded.
105- Keep the whole package directory (record, sums, provenance, manifests)
106 with the release candidate: it is the evidence.
107
108## Rules the script enforces
109
110- **Committed tree only.** A dirty working tree (tracked files changed) is
111 refused. Tests may pass `--allow-dirty`; the record then says
112 `tree_clean no`, and `verify` and `sign` refuse that package unless given
113 `--allow-dirty` too (`sign-test` accepts it; the TEST key never signs for
114 hardware).
115- **Reproducible or not signable** (TRUST-1 Q24). The image is built twice
116 into two fresh directories; if the two differ, no package is written. On
117 2026-10-12 the full image reproduced byte for byte across clean builds
118 (sha256 540b7f75... at aienos 6e3c492).
119- **No unrecorded inputs.** `CK_*` variables in the environment or passed
120 down in `MAKEFLAGS` are refused; the variant's make goal and variables are
121 the only ones used, and they are recorded.
122- **Never overwritten, never re-signed in place.** `--out` must not exist;
123 `sign` refuses when `MANIFEST.signed.bin` exists.
124- **Private keys never on the Spark.** `tbs --pubkey` emits the to-be-signed
125 bytes for that public key; the owner signs them on the offline machine
126 (`openssl pkeyutl -sign -inkey owner_root.key.pem -rawin -in MANIFEST.tbs -out MANIFEST.sig`,
127 `docs/OWNER_KEY_CEREMONY.md`) and `sign --sig MANIFEST.sig --pubkey <64 hex>`
128 attaches the signature after verifying it. Before 2026-10-12 `ck_slot_tool
129 tbs` emitted the bytes with an empty `signer_id`, while `attach-sig` checks
130 the signature with `signer_id` filled in, so no real offline signature could
131 attach; `tbs` now requires `--pubkey` and the self-test signs with a
132 throwaway OpenSSL key end to end. `sign-test` uses the RFC 8032 TEST 1 key
133 and is for tests only; `ck_owner_gen` and the slot tool refuse that key for
134 hardware.
135- **Verify fails closed.** `verify --package DIR --keys FILE` checks
136 `SHA256SUMS`, `PROVENANCE.txt`, every record line it can recompute
137 (exactly one of each required line; image bytes, SHA-256 and SHA-512;
138 `tree_clean`; the make goal and variables against the variant; the commit
139 time, Makefile and `image.ld` digests against the commit when the
140 repository has it), the provenance binding, the commit match, the signed
141 manifest's signature under the owner keys (`tools/ck_owner_gen.c` file
142 format), and that the signed manifest equals the built one in every field
143 but signer/signature. With `--same-host` it also compares the toolchain
144 lines with the toolchain running here; without it they are printed as
145 `recorded`. Every line is printed as `checked` or `recorded`. An unsigned
146 package is refused unless `--allow-unsigned` (reported as not installable).
147
148## Self-test
149
150`make -C native/kernel package-test` runs `scripts/native_package_test.sh`:
15185 checks. Build with pins/model/firmware; every PACKAGE.txt line including
152each provenance line against an independent computation; the manifest
153provenance equals `package_sha256`; refusals for an existing output, a bad
154pin, owner files on the wrong variant, `CK_*` in the environment and in
155`MAKEFLAGS`, a dirty tree (in a scratch worktree of HEAD, the real checkout is
156never touched), an unsigned package, double signing, the wrong owner key, a
157tampered image, a tampered PACKAGE.txt with and without re-made sums and
158`PROVENANCE.txt`, a tampered or missing `PROVENANCE.txt`, a flipped signature
159byte, a missing SHA256SUMS, another package's signed manifest, a
160non-reproducible build via a test hook; twelve record tampers with re-made
161sums (tree_clean, Makefile and image.ld digests, commit time, image SHA-512
162and size, make goal and variables, `input_env_ck`, a missing and a duplicated
163line, and a toolchain line under `--same-host`); the hardware-staging variant
164with the labelled TEST-FIXTURE owner files; and the offline signing round
165trip with a throwaway OpenSSL Ed25519 key (`tbs` without and with
166`--pubkey`, the TEST key refused, a signature over signer-less bytes refused,
167a dirty-tree package refused for a real signature, attach, verify under the
168keys file, `signer_id` equal to OpenSSL's SHA-256 of the raw public key).
169About 40 s, nothing booted.
170
171## What is still missing for N7
172
173The package is the input to the updater (slots cut 3, QEMU only:
174`docs/NATIVE_IMAGE_SLOTS.md` section 9) and to the known-good recovery image
175(slots cut 4). The owner approved the slot loader on 2026-10-12
176(`docs/NATIVE_IMAGE_SLOTS.md` section 2); the package carries it since cut 3
177(section below). Install today is still
178the one-time BootNext procedure of `docs/NATIVE_BOOT_ONE_TIME.md`, which N7
179rejects as the supported path.
180
181## Slot loader in the package (P11 cut 3)
182
183Format 3 adds the A/B slot loader (`native/boot/slot_loader.c`,
184`docs/NATIVE_IMAGE_SLOTS.md`) to every package:
185
186| File / line | Meaning |
187| --- | --- |
188| `loader/SLOTLDR.EFI` | `make slot-loader`, built twice from the same tree like the image; the two builds must be byte-identical or `build` refuses |
189| `loader loader/SLOTLDR.EFI` | path inside the package |
190| `loader_keys owner` or `test` | `owner` for `--variant hardware-staging`: the `--owner-pubkeys` file is the loader's `CK_SLOT_KEYS` (Owner Root keys; `ck_slot_tool keys-c` refuses an RFC 8032 TEST key in it). `test` for `core` and `full`: the labelled TEST 1 key loader (`CK_TEST_SLOT_KEY=1`), never for hardware |
191| `loader_bytes`, `loader_sha256` | size and SHA-256 of the loader |
192| `loader_reproducible two_clean_builds_identical` | the two builds matched |
193
194`SHA256SUMS` covers `loader/SLOTLDR.EFI`, so the owner's one signature over
195the slot manifest (whose provenance is `package_sha256`) binds the loader too.
196The loader itself is not a slot payload: it is installed on the ESP once
197(owner-attended, not part of this cut) and verifies slot manifests with the
198keys it was built with. `verify` refuses a package whose loader bytes or
199digest differ from the record, whose `loader_keys` does not match the
200variant, a `test` loader without its "TEST-ONLY key" note, or an `owner`
201loader carrying any TEST-ONLY note. Self-test rows (`make package-test`):
202record lines, coverage by `SHA256SUMS`, a tampered loader byte, a missing
203loader, tampered `loader_sha256` / `loader_keys` / missing `loader_bytes`
204lines, and the hardware-staging package's owner-key loader without a
205TEST-ONLY note. Format 2 packages (no loader) are refused by format 3
206`verify`; rebuild them.