feat: snapshot Linux-first RMM MVP and pause handover
Rust development slice / linux (push) Failing after 1m10s

This commit is contained in:
BuTzZ
2026-11-12 22:06:25 +01:00
commit 6c3203d725
194 changed files with 49234 additions and 0 deletions
+259
View File
@@ -0,0 +1,259 @@
# Typed RootHelper bridge contract (implementation, not native acceptance)
**Dedicated-runner update:** the current deployment and readiness protocol is
defined in [`../../deploy/linux/apt-helper-README.md`](../../deploy/linux/apt-helper-README.md).
The actual additive domain schema-2 types and AptNativeAcceptance variant have
since landed and are exercised by a local exact-signature/helper roundtrip test.
Agent routing and nonce/root-peer/identity/profile/stack-bound readiness are
implemented. Older descriptions below of absent domain fields or missing runner
describe the earlier increment, not a remaining implementation gate. Real VM
profile/probe/installation acceptance remains unmeasured, not passed.
## Current integration status / exact outstanding domain change
The helper now contains a real provider bridge in
`crates/privileged-helper/src/apt.rs`, called by its existing peer-credential
authenticated IPC handler, **not** by a script wrapper. The domain job source
was leased to the backend worker during this dispatch; it was not edited.
Legacy package jobs cannot supply the required manifest and remain gated.
No package capability was added to the agent. No native package/service/reboot
operation, VM action, helper installation or acceptance record occurred here.
Required additive domain/backend contract, before capability advertisement:
1. Define typed `AptExecutionManifest` **schema 2**, `ResolvedAptTransaction`
schema 1 and `PackageArchive` in domain (same exact fields/serde shape as the
helper types below; do not make domain depend on the helper crate). All deny
unknown/duplicate fields. No `serde_json::Value` opaque action authorization.
2. Existing `Action::EnsurePackage` and `Action::ApplyUpdates` gain a field
`apt_manifest: Option<AptExecutionManifest>`, default None for legacy reads.
Execution/validation requires Some for APT. Serialization MUST preserve the
complete object; ignoring unknown fields is explicitly detected and denied by
`APT_DOMAIN_MANIFEST_NOT_CONFIGURED`. No unsigned IPC manifest field exists.
3. Add a dedicated Action variant with this exact JSON shape:
```json
{
"action": "apt_native_acceptance",
"recipe_id": "rmm-apt-fixture-install-1.0",
"recipe_version": "1",
"apt_manifest": {"<all schema-2 fields below>": "<replace this placeholder>"}
}
```
`Action::name()` and permit.action are `apt_native_acceptance`. Root-only,
explicit dev-test, specific target, fixed UI-authorized job/attempt. The
upgrade recipe is `rmm-apt-fixture-update-1.1` and needs another job. This is
NOT an alias of run_script/diagnostic arbitrary execution. Backend plan/UI
allowlisting must show full transaction, exact hashes, origin, no-reboot,
execution identity and test-acceptance nature before approval.
4. For fixture ensure_package the outer recipe_id/version must match the nested
transaction exactly as strings. For apply_updates, outer provider=`apt`,
packages=`["rmm-mvp-test"]`, reboot_policy=`never`, nested upgrade recipe
only. Other original action parameters are retained and compared against the
domain's typed serialization, never accepted through parameter aliases.
5. Backend validation/planning/signing must validate both manifest transaction
representations, generate JobPayload once and sign its exact payload hash in
the existing Ed25519 permit. Keep all existing target/tenant/generation,
authorization/plan/job/attempt/identity/time bindings. Planning needs the
inspected root runtime/config hashes and immutable baseline/fingerprint.
6. Agent forwarding/capability negotiation must be separately integrated after
the domain contract and native prerequisites are complete. This dispatch did
not change agent/protocol/server files. No optimistic capability claim.
Current clear gates include `APT_PROVIDER_NOT_CONFIGURED`,
`APT_MANIFEST_NOT_CONFIGURED`, `APT_DOMAIN_MANIFEST_NOT_CONFIGURED`; an older
domain may reject the action even earlier as INVALID_JOB/unknown field. That
earlier rejection is not a fallback or authorization shortcut.
## Public Rust API
Current additive passive/no-change contract is documented in
`deploy/linux/runtime-README.md` ("Passive APT planning and declarative
no-change"). `readiness::PlanningResult` is returned only by authenticated
`apt_planning_v1`; it creates no capability. `planning-status` can create only
content-addressed root metadata seals. A normal exact already-desired fixture
returns driver `verified_no_change` / `POSTCONDITION_ALREADY_MET`, never a fake
`POSTCONDITIONS_VERIFIED` transaction/hook. Parent consumption and all signature,
manifest/runtime/native-record/artifact/current-state gates remain required.
```
apt::ProviderConfig // serde deny_unknown_fields
apt::AptExecutionManifest // schema 2
apt::ResolvedAptTransaction // schema 1
apt::PackageArchive
apt::is_apt_action(&JobPayload) -> bool
apt::policy_header(&JobPayload, &ProviderConfig) -> anyhow::Result<()>
apt::prepare(&Binding, &Request, &ProviderConfig, DateTime<Utc>)
-> anyhow::Result<PreparedApt>
PreparedApt::execute(self, &rusqlite::Connection) -> anyhow::Result<Outcome>
apt::install_known_payloads() -> anyhow::Result<()>
```
PreparedApt has no public fields/unchecked constructor. `prepare` independently
calls Binding::verify (exact Ed25519 request/grant and all existing bindings),
checks policy, exact signed manifest/domain preservation/code/runtime bindings,
installed trusted bytes and pre-grant prefetched artifacts. Parent consumes and
save_start-persists the request before execute. Execute independently requires
the corresponding consumed row (same agent/generation/job/attempt, result NULL)
and the exact originally saved request/signature/permit/plan/authorization.
Its stable effect_armed_ledger_id is `apt-<grant UUID>-<SQLite rowid>`.
## Exact manifest schema 2 inside Action.apt_manifest
```
type: "rmm.apt.helper-action"
schema_version: 2
action: "apt-native-acceptance" | "apt-execute"
execution_profile: "dev-test"
transaction_sha256: SHA256(transaction_bytes)
resolved_apt_transaction: complete typed ResolvedAptTransaction object
transaction_bytes: Vec<u8> / JSON array of integer bytes
provider_sha256: SHA256(exact installed Python provider bytes)
hook_sha256: SHA256(exact installed fixed hook bytes)
apt_config_sha256: SHA256(print-config output bytes)
runtime_sha256: SHA256(canonical inspect-runtime output object)
test_result_id: ASCII identifier [A-Za-z0-9_.-], 1..128 bytes
```
The full object AND exact transaction bytes are required. Deserialize the bytes
with the strict typed schema and require equality to the nested object. The
provider writes those **same bytes**, not reformatted JSON, to expectation.json.
It copies **the full original Request.job_bytes unchanged** to signed-action.json;
job_payload_sha256 in context is SHA256 of those complete domain job bytes.
The Python loader now requires that full JobPayload envelope and checks the
nested action, job/attempt/root identity, inner bytes/hash/object and code pins.
A detached old standalone schema-1 helper-action manifest is no longer accepted.
ResolvedAptTransaction fields (all mandatory): schema_version=1, recipe_id,
recipe_version="1", platform="ubuntu-24.04-amd64",
resolver_config_version="rmm-apt-local-v1", no_reboot=true, status_fingerprint,
baseline_sha256, packages. PackageArchive fields: name, architecture,
old_version (null/string), new_version, origin, sha256, size, archive_path.
Only the code-pinned single-package fixture install/upgrade is configured.
Production and arbitrary catalogs remain denied; a test acceptance does not
authorize another recipe/closure/profile. Exact fixture hashes are in README.
## Root configuration / trusted installation / prefetch
Existing root-owned 0600 helper config gains optional `apt_provider` (absent =
disabled). No new secret/environment variable or caller-supplied path:
```json
{
"schema_version": 1,
"execution_profile": "dev-test",
"allow_fixture_bootstrap": true,
"allowed_recipes": ["rmm-apt-fixture-install-1.0", "rmm-apt-fixture-update-1.1"],
"runtime_sha256": "<operator-reviewed canonical runtime hash>",
"apt_config_sha256": "<operator-reviewed exact config output hash>"
}
```
These are local policy limits, not approvals. Keep the existing binding,
signing-key pin, agent UID/socket GID and parent ledger provisioning unchanged.
No artifact URL/network fetch exists in the root provider.
Planned administrator tool installation, **not executed**:
```
/usr/local/libexec/rmm-privileged-helper --install-apt-provider
```
Root-only, fixed paths, create-only: embeds Python/hook bytes at Rust compile
time, writes root-owned `/usr/lib/rmm-apt-transaction/{apt_transaction.py,hook}`
(0644/0755), `/var/lib/rmm-apt-transaction` and archives/baselines/history (0700),
and `install-metadata.json` (0600, provider/hook hashes). Refuses existing files/
directories instead of replacing/chmodding them. Partial installation requires
explicit operator reconciliation; no automatic deletion/repair. On each use,
installed bytes and metadata must match the helper's compiled known payloads.
The interpreter is fixed `/usr/bin/python3 -I`, root-owned resolved interpreter;
all provider/store path components are root-owned, nonsymlink and not writable
by group/others. This installation creates no acceptance or grant.
Planned explicit pre-grant fixture preparation, **not executed**:
```
/usr/bin/python3 -I /usr/lib/rmm-apt-transaction/apt_transaction.py provision-fixture-store
```
Only the two pinned deterministic fixture archives can be created, never an
arbitrary archive/URL. Archives and `prefetch-<sha>.json` receipts are fsynced,
root-owned 0600, exclusive creation. Receipt fields: schema_version=1, sha256,
size, sealed_at_ms. Helper requires receipt time <= permit.not_before, matching
actual SHA256/size/single-link archive. Missing/writable/symlinked/unprefetched
artifacts fail before consumption. All downloads/imports must finish before the
final short grant, never during execution. Artifact mTLS fetch elsewhere must
ultimately yield the same root-verified sealed-store contract, not an agent path.
The same preparation stores complete canonical dpkg baseline at
`baselines/<baseline_sha256>.json` and emits baseline hash/status fingerprint
for the approved immutable plan. It creates neither jobs nor authorization.
For subsequent changed baselines, the root-only `prepare-baseline` mode samples
current dpkg state and creates a new content-addressed canonical baseline before
the new plan/final grant. An identical existing baseline is only read/verified,
never rewritten; changed state creates another hash file, never resets archives,
receipts or acceptance/attempt markers. It creates no job authority. Do not
modify a sealed file or fake a fingerprint. Archive preparation is create-only.
Root `inspect-runtime` / `print-config` provide the planning measurements; hash
inspect-runtime's canonical JSON object **without its trailing newline**. Review
the measured binary/OS/dpkg configuration rather than blindly trusting a hash.
## Handoff, outcomes, recovery and unit prerequisites
Parent handler retains its existing device lock, consumes once, save_start
persists exact signed request, and rechecks clock/grant before effects. Bridge
creates active/0700 and expectation/signed-action/baseline/config/context files
0600 using exclusive nofollow writes and file/directory fsync. Context schema 2
contains the same grant/job/attempt/authorization/plan IDs and original UTC
deadline translated to CLOCK_MONOTONIC, not a fresh 60-second grant.
An old active directory can only move to history/<old grant UUID> when the same
parent ledger contains a definitive succeeded/failed result. Unknown/null,
unrecognized/partial handoffs or existing history destination block execution.
No tombstone/native bootstrap-attempt record is removed. Parent grant/attempt
consumption survives any active-directory move.
Python receives only fixed mode/path argv and two hash/ledger fields via stdin,
with cleared environment; no shell, secret argv or script conversion. Structured
stdout is bounded to 64 KiB (excess drained without unbounded allocation), raw
stderr discarded. Never timeout-kill APT. Client timeout is unknown while the
helper keeps running and eventually journals the real result.
Exit 0 alone is never success. Strict JSON effect_state/code/evidence validation
requires bound ledger, exact package versions, full snapshot hash, installed
fixture payload hash, and bootstrap test flags/native-record/test-result binding.
Malformed/nonzero/missing/wrong evidence -> unknown. known_failed with an armed
marker -> unknown, not failed. Existing finish() leaves consumed.result NULL for
unknown/awaiting_reboot and persists execution_evidence, retaining the device lock.
**Existing helper systemd unit is not an APT-capability deployment.** Its
ProtectSystem=strict/other hardening can prevent the required store/package
writes and namespace setup. A separately reviewed native runner/unit profile
must permit the narrowly agreed fixture writes and setup capabilities while
preserving the provider's final sandbox. No unit sandbox was weakened here.
Do not announce capability based solely on a successful helper build.
Local verification commands/results are reported in the dispatch return.
Native helper installation, IPC package execution, lock probe, fixture install/
update and VM approval/acceptance remain unrun. Tests using private temporary
ledgers/mock children are not native acceptance evidence.
Actually executed for this bridge increment:
```
/home/Kevin/.cargo/bin/cargo fmt -p rmm-privileged-helper -- --check
/home/Kevin/.cargo/bin/cargo clippy -p rmm-privileged-helper --lib --bin rmm-privileged-helper --tests -- -D warnings
/home/Kevin/.cargo/bin/cargo test -p rmm-privileged-helper --lib --bin rmm-privileged-helper
PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s tests/apt_transaction -p 'test_*.py' -v
```
Final results: formatting and warning-denying Clippy passed; **16 library + 2
binary Rust tests passed**, **41 Python tests passed**, AST syntax checks passed
for **6 Python files**. No full workspace suite was run. An initial Rust test
fixture used legacy ApplyUpdates, which the current domain rejected as
`INVALID_JOB`; cryptographic/parent-ledger tests were corrected to use an
existing valid signed action without executing it or allowing it as an APT
action. This is not evidence that the missing domain package contract landed.
+365
View File
@@ -0,0 +1,365 @@
# Root-helper APT transaction provider / explicit first native acceptance
Current dedicated runner/probe/profile/agent integration and executed local
checks: [`../../deploy/linux/apt-helper-README.md`](../../deploy/linux/apt-helper-README.md).
The general helper unit remains unchanged; actual native VM measurements are
still required. Readiness alone advertises no accepted package capability.
**Helper integration contract update:**
[`HELPER-CONTRACT.md`](HELPER-CONTRACT.md) defines the implemented Rust helper
bridge, root installation/store layout, schema-2 embedded manifest and exact
remaining additive domain fields. It supersedes the older standalone signed
helper-action example below: signed-action.json must now contain the **full
original JobPayload bytes**, with `action.apt_manifest`, including exact
`transaction_bytes`. No detached/unsigned manifest is accepted. No agent
capability or native acceptance follows from this bridge build.
**Implemented, locally tested; NOT integrated or VM-tested.** No host package
installation, VM access, real native acceptance, production evidence, grant
issuance or WebUI approval has been performed here. The native process path is
real code (unshare/mount/capabilities/seccomp/APT/dpkg), not merely a parser;
its root/native execution is still unverified. Local root/installer execution
in tests is explicitly mocked. No real acceptance record was created.
Python >=3.9, standard library; OS dependencies: APT/dpkg, util-linux
unshare/mount, libseccomp.so.2, Linux x86-64 namespaces/seccomp/capabilities.
Only Ubuntu 24.04 amd64 is eligible; this is not a support/acceptance claim.
No Rust API, Cargo workspace changes, network endpoint, signature verifier,
grant service or automatic retry is included.
## The circular gate is replaced, not bypassed
There are now two distinct helper-only CLI operations:
```
/usr/bin/python3 -I /usr/lib/rmm-apt-transaction/apt_transaction.py native-acceptance
/usr/bin/python3 -I /usr/lib/rmm-apt-transaction/apt_transaction.py execute
```
* `native-acceptance`: dedicated **dev-test** action, exactly one code-pinned
fixture install OR upgrade, its own fixed job/attempt and actual WebUI approval.
It permits only absence of a *previous* native record for that fixture recipe.
It uses the same signed binding, archives, native sandbox, hooks, locks,
deadlines and independent verification as normal execution. No force/insecure/
skip-validation flag exists.
* `execute`: requires an existing matching record **and** a freshly verified,
separately UI-approved normal job/startgrant. An acceptance record never
substitutes for any signature or authorization.
**Scope matrix:** records produced here authorize only their exact fixture
recipe, package closure, runtime identity and **dev-test** profile. Production
is rejected (`PRODUCTION_ACCEPTANCE_REQUIRED`), even for a test record. General
catalog packages are rejected (`FIXTURE_RECIPE`); the bootstrap does not certify
arbitrary packages or widen provider support. Supporting those needs a separate
reviewed native-acceptance policy/provider revision, not relabelling this record.
The legacy unsigned administrator-created `native-acceptance.json` schema 1
is no longer used. Old helper contexts (schema 1) are rejected as well.
Each of these is a separate, one-time bootstrap recipe (recipe_version `1`):
| recipe_id | exact transition | architecture | origin |
|---|---|---|---|
| `rmm-apt-fixture-install-1.0` | absent -> 1.0 | all | rmm-test |
| `rmm-apt-fixture-update-1.1` | 1.0 -> 1.1 | all | rmm-test |
Exactly one package, `rmm-mvp-test`, no dependencies/scripts/triggers. One job
never installs both versions. Upgrade requires another fixed UI-approved job.
Pinned deterministic Debian ar/USTAR archives, **20,672 bytes each**:
```
1.0 74036ae81223deab3aae994fd2a2a695af408741777e1ce17dcb4e32f1235867
1.1 ef67c9fe0ba1443fcfe465768e1204763063c369a2a1da04af6027d8a9c00491
```
`build_fixture.py EXISTING_PRIVATE_OUTPUT_DIR` creates those exact bytes with
fixed metadata. It refuses overwrites and never installs/imports/publishes.
Real local dpkg-deb control/payload inspection confirms the only installed file
is `/usr/share/rmm-mvp-test/version`, with the selected version plus newline.
The builder now uses deterministic stdlib ar/USTAR construction, not the previous
timestamp-dependent `dpkg-deb --build` output. Older built archives do **not**
qualify for bootstrap; import these pinned bytes manually into the approved
catalog, verify and seal them before requesting the final 60-second grant.
## Mandatory signed-action and verified-helper contract
This module does **not** verify signatures. The root helper is the trust boundary.
Before writing any handoff files or invoking either mode, it MUST independently:
1. Verify the signed grant type/schema/algorithm/key, online validity and actual
human WebUI authorization (or explicitly labelled allowed dev-test UI
simulation), tenant/asset/agent identity and generation/assignment bindings.
2. Verify plan hash, job payload hash **of exact bytes**, fixed job/attempt,
action, execution profile, recipe/version, code/hook/config/runtime hashes,
exact complete resolved transaction and deadlines against that signed grant.
3. Enforce an explicit helper operation allowlist: `apt-native-acceptance` only
from the dedicated dev-test fixture-bootstrap action, never a generic
diagnostic/shell/API request. `apt-execute` must not invoke bootstrap mode.
4. Recheck trusted clocks/current rights and durably consume the grant and
attempt in its parent journal BEFORE spawning. Reject previous/uncertain
attempts. Unprivileged network/MCP callers cannot write these files or invoke
an unrestricted privileged subprocess API. Preserve peer-credential checks.
### Signed job payload: exact schema 1
The following object itself is the **signed/grant-hash-bound job payload**,
stored unchanged as `active/signed-action.json`; it is NOT an extra unsigned
root manifest or a caller's `verified: true` assertion. Fields are mandatory:
```json
{
"type": "rmm.apt.helper-action",
"schema_version": 1,
"action": "apt-native-acceptance",
"execution_profile": "dev-test",
"transaction_sha256": "<SHA256 of exact expectation.json bytes>",
"resolved_apt_transaction": "<complete OBJECT defined below, not a string/reference>",
"provider_sha256": "<installed apt_transaction.py SHA256>",
"hook_sha256": "<fixed installed hook SHA256>",
"apt_config_sha256": "<apt_config() bytes SHA256>",
"runtime_sha256": "<canonical runtime_identity() SHA256>",
"test_result_id": "<fixed acceptance evidence ID>"
}
```
The string placeholder for `resolved_apt_transaction` above MUST be replaced
with the complete nested object in actual payloads. Normal mode uses action
`apt-execute`. Production is a recognized profile but cannot use these test
records. The helper must verify the signed action, not merely trust ownership
of a separately supplied hash. The provider rechecks exact signed-payload hash,
type/schema/action/profile, nested transaction equality and code/config/runtime
bindings; it relies on the helper for cryptography and grant consumption.
### ResolvedAptTransaction schema 1
All fields mandatory; unknown fields/types and duplicate JSON keys are rejected:
```
schema_version: integer = 1
recipe_id: one exact fixture recipe above
recipe_version: "1"
platform: "ubuntu-24.04-amd64"
resolver_config_version: "rmm-apt-local-v1"
no_reboot: true
status_fingerprint: 64 lowercase hex characters
baseline_sha256: 64 lowercase hex characters
packages: [PackageArchive] # exactly one for this accepted scope
```
`PackageArchive` exact fields:
```
name: "rmm-mvp-test"
architecture: "all"
old_version: null for install, "1.0" for update
new_version: "1.0" for install, "1.1" for update
origin: "rmm-test"
sha256: corresponding code-pinned hash above
size: 20672
archive_path: "/var/lib/rmm-apt-transaction/archives/<same sha256>.deb"
```
The general parser still understands up to 128 package changes / 1 MiB, but that
does not authorize a broader execution scope. Frozen dataclasses/tuple closure;
strict Debian version ordering via read-only typed `dpkg --compare-versions`.
Status fingerprint hashes raw status/architecture/extended_states and trigger
database state. Dirty dpkg updates, pending triggers, repair, reinstall,
downgrade, removal, crossgrade and core/kernel/boot packages are unsupported.
`active/baseline.json` is the complete canonical all-package snapshot from
`installed_snapshot()` (`dpkg-query`), not just the changed package:
```json
{"package:architecture":{"version":"<version>","status":"install ok installed"}}
```
Its canonical byte SHA256 binds `baseline_sha256`. A new install requires actual
absence, not leftover config-files. Existing consistent noninstalled entries may
be present for other packages. Fingerprint/baseline are rechecked in the native
hook, not accepted from simulation as authorization.
### VerifiedHelperContext schema 2
Root helper writes `active/context.json` only after the checks/consumption above:
```json
{
"schema_version": 2,
"transaction_sha256": "<exact expectation.json bytes SHA256>",
"job_payload_sha256": "<exact signed-action.json bytes SHA256>",
"action": "apt-native-acceptance",
"execution_profile": "dev-test",
"effect_armed_ledger_id": "<stable parent journal row>",
"grant_id": "<verified grant ID>",
"job_id": "<fixed job ID>",
"attempt_id": "<fixed attempt ID>",
"authorization_id": "<UI authorization ID>",
"plan_sha256": "<verified plan hash>",
"not_before_ms": 1794484800000,
"start_before_ms": 1794484860000,
"boot_id": "<current boot UUID>",
"monotonic_start_before_ns": 123456789000
}
```
UTC integer milliseconds; start window <=60,000ms, exclusive upper deadline.
Helper translates that same verified deadline to same-boot CLOCK_MONOTONIC ns;
never grants another fresh window. Both clocks/boot are checked after expensive
verification, before native launch and at the final hook gate. An installation
validly started is not aborted merely because its start deadline later expires.
## Deployment / exact invocation
Planned, **not deployed here**. Root helper/operator installs reviewed files:
* `apt_transaction.py` -> `/usr/lib/rmm-apt-transaction/apt_transaction.py`, 0644
* fixed `hook` -> `/usr/lib/rmm-apt-transaction/hook`, 0755
* `/var/lib/rmm-apt-transaction` and `active`, 0700, root-owned
* sealed archives in `archives/`, root-owned; no nonroot writer
* active expectation/context/baseline/signed-action/apt.conf files, 0600
* empty root-owned active `empty`, `lists`, `cache` directories, 0700
All path components must be real root-owned nonsymlink/non-group/world-writable
paths. `apt.conf` must equal `apt_config()` bytes. Read-only `print-config` emits
them; root-only `inspect-runtime` emits canonical measured runtime identity for
the helper/planner's reviewed signed payload, not an acceptance claim.
For **either** operation, stdin is exactly:
```json
{"transaction_sha256":"<same approved hash>","effect_armed_ledger_id":"<same parent row>"}
```
Use sanitized environment and close inherited private fds. No secrets in argv.
An acceptance request must invoke `native-acceptance`; a normal signed action
must invoke `execute`. Mixing the two is rejected. Internal `hook` and
`sandbox-worker` modes are not exposed as privileged IPC operations.
## Native pipeline and evidence publication
Both modes run the same pipeline:
1. Root/signed action/recipe/runtime/preconditions/actual archive validation;
constant hook/config/code binding before APT. Native provider flock only
serializes this provider, never replaces APT's locks.
2. Bootstrap additionally writes/fsyncs O_EXCL
`bootstrap-attempt-<fixed recipe_id>.json` in BASE, independently of active/
and grant IDs. One-time per recipe; no automatic deletion/reset/retry, even
after a failed native precheck. An operator must reconcile failures and use
a separately reviewed lifecycle/revision, not remove tombstones to retry.
3. Separate native child via fixed `unshare --mount --pid --fork --mount-proc
--net`, private propagation, tmpfs `/run`/`tmp`/`var/tmp`/`dev`, protected
readonly/masked kernel/boot/control-plane/tool/archive paths.
4. Drop bounding/effective/permitted capability sets to exactly filesystem/UID
subset `{0,1,3,4,6,7,8,31}`; inherited/ambient empty. No SYS_BOOT/SYS_ADMIN/
SYS_PTRACE/KILL/RAWIO/NET_ADMIN/MKNOD. Set NoNewPrivileges, load inherited
seccomp denying reboot/kexec, module loading, mount/namespace changes,
ptrace/process writes and other kernel-control operations.
5. **Actual native prechecks inside that child:** different PID/mount/net ns,
expected namespace PID1, exact caps/NNP/Seccomp, readonly mount flags, tmpfs
identity, masked sysrq, no conventional systemd/dbus/helper sockets; invalid
reboot magic and invalid kexec flags/fds must return EPERM. These calls never
contain valid reboot magic/commands or valid kexec input. No PID1 signals.
6. Hold real existing `/var/lib/dpkg/lock-frontend` with fcntl; a separate native
`apt-get -o DPkg::Lock::Timeout=0 check` must report that frontend-lock conflict
(100 + expected lock diagnostic). `check` is read-only, not an installation
probe. Never delete locks, kill owners or use simulation to prove locking.
A busy foreign lock vetoes the bootstrap. Release only this process's fd.
7. Fsync native-prechecks record, then sandbox-ready marker. Native APT uses
exact local archives, `--no-download --no-remove --no-install-recommends` and
constant isolated config. No global APT hooks/sources/preferences; reviewed
dpkg global config is runtime-hash-bound in the signed action. Native foreign
lock wait remains bounded to 10 seconds.
8. Mandatory v3 pre-dpkg hook repeats signed/runtime/scope/sandbox checks,
validates the whole actual action set, actual hashes/control/payload,
status/baseline and final deadline; O_EXCL + file/directory fsync effect-armed
marker **before returning 0**. Second hook is vetoed. No fallback.
Immediately after successful file/directory fsync, UTC/monotonic deadline and
boot identity are checked again. Expiry vetoes the hook while retaining its
armed marker: conservative unknown/reconciliation, never marker reuse.
9. After native child exit 0 and valid bound markers/result, independently query
**all** installed versions/statuses, detect unexpected changes, require empty
`dpkg --audit` and exact installed fixture version-file bytes. Private /run
reboot flag is combined with host flag. Bootstrap requires no reboot flag.
10. Only then publish root-owned 0600 schema-2
`acceptance-<fixed recipe_id>.json`, staging/fsync complete bytes before
exclusive publication and directory fsync. No failed/stale-start/partial/
unknown execution is promoted. Parent must treat publication/IO uncertainty
as unknown and reconcile; a record is never an excuse to retry that job.
Record binds exact approved recipe/packages, full measured runtime (tool, hook,
APT config, resolved binaries including APT/dpkg/dpkg-deb/dpkg-query/Python/
unshare/mount/shell/libseccomp hashes and version strings, OS/kernel identity,
dpkg config fingerprint), transaction/job-payload/plan hashes, grant/job/attempt/
authorization/test-result IDs, precheck/hook/postcondition hashes and completion
time. It explicitly contains `test_acceptance: true`, `noProductionEvidence: true`.
Install and upgrade have separate records; one does not certify the other.
## Result / safety bounds
One JSON result on stdout: `effect_state` = `known_failed`, `verified`, or
`unknown`; stable `code`; structured `evidence`. Every structured bootstrap
result, including veto/unknown, carries `evidence.test_acceptance=true` and
`evidence.noProductionEvidence=true`. Verified bootstrap additionally reports
record hash/test-result ID. Exit 0 means structured result, not job success.
Malformed CLI/hook input exits 100 with generic diagnostics. Parent must journal
missing output/death/partial markers after possible launch as unknown.
No `awaitreboot` output in this version: no post-boot completion condition exists.
No reboot is invoked. Any reboot/follow-up/retry needs another fixed approved job.
No auto-configure-all, autoremove, dist-upgrade, repair, index refresh, installer
timeout killing, or automatic record/attempt clearing is provided.
APT retains its frontend lock and normally hands off the inner dpkg lock.
**No claim that both locks are held during the hook.** Direct foreign dpkg and
malicious root are outside the frontend-lock guarantee; native inner locking
still applies. Root scripts are intrinsically trusted host-filesystem code;
this is not general malicious-root containment or arbitrary deferred-side-effect
verification. Bootstrap avoids that expansion by accepting only pinned
script/trigger/dependency-free fixtures. Existing dpkg triggers/global config,
kernel, root administrators, trusted binaries/helper remain in the TCB.
## Primary sources and actual local verification
APT 2.7.14 sources read before parser implementation:
* <https://github.com/Debian/apt/blob/2.7.14/doc/apt.conf.5.xml>
* <https://github.com/Debian/apt/blob/2.7.14/apt-pkg/deb/dpkgpm.cc>
* <https://github.com/Debian/apt/blob/2.7.14/apt-pkg/deb/debsystem.cc>
Native read-only lock probe checked against `DoCheck` (`Cache.Open/CheckDeps`,
not dpkg/install) in:
<https://github.com/Debian/apt/blob/2.7.14/cmdline/apt-get.cc>.
Hook protocol **VERSION 3**, nine fields:
`name old-version old-arch old-multiarch direction new-version new-arch
new-multiarch action`. New install old triple `- - none`; `<` install/upgrade,
`>` downgrade/removal; action absolute archive path or `**CONFIGURE**`/
`**REMOVE**`. Config lines precede a blank separator and support percent escaping
and repeated unnamed lists. SHA/size/origin are NOT transmitted in v3: actual
sealed files are independently checked. Whole closure must match, including one
configure per unpack; extra/missing/repeated actions are vetoed.
`tests/apt_transaction/fixtures/install-v3.txt` is source-derived, **not a native
installation capture**.
Actually executed unprivileged, with **no host package mutation**:
```
PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s tests/apt_transaction -p 'test_*.py' -v
```
**39 tests passed** at the documentation update. Original 22 guard/archive/
parser/preconditions tests plus pinned fixture/control inspection, context/
signed manifest/recipe/profile/runtime binding, native-record matrix, fsync/
partial/negative evidence rejection, mocked full driver success/unknown/failure/
stale/redelivery, mocked native mount/capability/namespace/socket introspection,
and local unprivileged seccomp invalid-input EPERM probes.
The post-fsync deadline regression advances mocked UTC/monotonic clocks (both
and each independently), observes nonzero hook outcome/no modeled dpkg start,
and verifies that the durable marker survives and prevents a second handoff.
Native root/installer/VM parts are explicitly mocked under private temporary
BASE paths; mock-generated records are deleted with those dirs and are NOT
native evidence. Safe invalid-input probes and seccomp loading really ran in
short-lived unprivileged children. No valid reboot/kexec operation or host PID1
signal was attempted. Deterministic .deb bytes were really built/read/inspected,
never installed. Full root sandbox, real APT lock conflict, native fixture
install/update, helper signature integration and VM acceptance remain **unrun**.
File diff suppressed because it is too large Load Diff
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/python3
"""Build pinned script-free .deb artifacts; NEVER install or publish them."""
import importlib.util
import json
import os
from pathlib import Path
import stat
import sys
sys.dont_write_bytecode = True
SPEC = importlib.util.spec_from_file_location('apt_transaction',
Path(__file__).with_name('apt_transaction.py'))
apt = importlib.util.module_from_spec(SPEC)
sys.modules[SPEC.name] = apt
SPEC.loader.exec_module(apt)
def build(output):
output = Path(output).resolve(strict=True)
st = output.stat()
if not stat.S_ISDIR(st.st_mode) or st.st_uid != os.getuid() or st.st_mode & 0o077:
raise ValueError('output must be an owned private directory')
records = []
for version in ('1.0', '1.1'):
destination = output / ('rmm-mvp-test_' + version + '_all.deb')
data = apt.fixture_archive(version)
apt.require(apt.digest(data) == apt.FIXTURE_SHA256[version], 'FIXTURE_PINNED_BYTES')
with destination.open('xb') as stream:
stream.write(data)
records.append({'name': 'rmm-mvp-test', 'new_version': version,
'architecture': 'all', 'origin': 'rmm-test',
'sha256': apt.digest(data), 'size': len(data),
'local_build_path': str(destination)})
return records
if __name__ == '__main__':
if len(sys.argv) != 2:
sys.exit('usage: build_fixture.py EXISTING_PRIVATE_OUTPUT_DIRECTORY')
print(json.dumps(build(sys.argv[1]), indent=2))
+2
View File
@@ -0,0 +1,2 @@
#!/bin/sh
exec /usr/bin/python3 -I /usr/lib/rmm-apt-transaction/apt_transaction.py hook