Repository navigation
Description
Problem
Nothing in upstream records where a sandbox template came from, who changed it, or which snapshot a
sandbox ran on. The control plane's only trail is the ownership-plane audit stream sh:cp:audit
(packages/control-plane/src/ownership.ts, AUDIT_STREAM): a Redis stream trimmed to about
AUDIT_MAXLEN entries, not chained, and not exportable as a self-checking document. Templates
themselves are a fixed env list (SH_SANDBOX_TEMPLATES, sandbox-config.ts), so after the fact an
operator cannot show which image, gate record and policy produced the hands a run used, nor prove that
a record was not edited, dropped or reordered.
For benchmark runs (one template per task instance), and for any audit, that chain is what lets a
result be traced to the exact snapshot it ran on.
Proposal
An append-only provenance store in the control plane, one hash chain per stream, exportable and
verifiable offline with the Python standard library alone.
- Store (
packages/control-plane/src/provenance.ts,ProvenanceStore): a directory on the control
plane's persistent volume. The control plane opens it fromSH_PROVENANCE_DIR(absolute path) with
the template store of Keep sandbox templates in a control-plane store, with builds, tags, readiness and a read API #736, which shares the directory; unset, nothing is recorded and nothing
changes. One file per record underrecords/, named by its digest; one head per stream
underheads/; cited documents (gate records) byte for byte underblobs/, by sha256. A record is
written (exclusive create, fsync) before its stream's head moves (write-temp, fsync, rename), so a
crash leaves an orphan record, never a head naming a missing one. Appends to one stream are
serialized. The directory is checked writable at start, so a missing or read-only volume fails the
start rather than the first write. - Records (
moca-provenance-record/1):{stream, seq, prev, kind, subject, at, body}. A record's
digest is the sha256 of its canonical JSON (keys sorted, no whitespace, integers only, so a second
implementation writes the same bytes);prevnames the previous record's digest. Streams are
policyandtemplate/<id>(later units addmembers). Kinds:policy,create,gate,build,
check,activate,deactivate,tag,visibility,owner,retire,reject,use,sandbox,
session. The units that produce those events write them (the template store, self-serve create,
the host agent's build reports, activation, retire); this issue adds the store, the format and the
checks. - Every cross-record reference is a record digest, never a time or a name:
check.policy,
check.build,retire.buildRecord,reject.buildRecord, and theleaseof asandboxorsession
record (theactivaterecord it came from). A run then joins its build by equality alone. - A sandbox's span on its template's chain: a
sandboxrecord at create (sandboxId, buildId,
templateManifestHash, lease, expiresAt) and one at the end (state: terminated,reason: deleted
withendedAt, orexpired, written once by the janitor's sweep when it first sees the expiry). - Export (
moca-provenance-export/1,ProvenanceStore.export()): the requested template streams,
the policy stream they cite, every stream head with its count, and every gate record agaterecord
names. - Offline verification:
deploy/sbx/template-onboarding/verify-provenance.py EXPORT.json [--head STREAM=sha256:…]andverifyExport()in TypeScript apply the same rules: every record's
digest, each stream'sseq/prevchain up to its head and count, every blob's sha256, eachcheck
citing a policy record of the export, eachgateciting a blob of it.--headcompares a head kept
elsewhere, which is what catches an export that dropped its latest records. Exit 0 verified, 1 a check
failed (each printed), 2 usage. - Redaction:
redact-provenance.py STORE_DIR TEMPLATE_ID --pattern RE [--apply](control plane
stopped) rewrites the matching records of one stream and every later one, moves the head, and appends
a note toredactions.log(counts and heads, never the matched text).--catalog-onlyredacts text
only the catalog keeps. Dry run by default. It exists for data that must not be kept; an export taken
before a redaction no longer verifies against the new head, by design.
What the PR will contain
One PR, about 1,390 added lines with tests.
packages/control-plane/src/provenance.ts(store, canonical JSON, export,verifyExport),
src/index.ts(exports), thesandboxrecord hooks insrc/sandbox-handlers.ts(createSandbox,
sandboxEnded,recordExpiries; inert until a store is configured). ReadingSH_PROVENANCE_DIRin
src/main.tscomes with Keep sandbox templates in a control-plane store, with builds, tags, readiness and a read API #736, which opens the store and the catalog together.deploy/sbx/template-onboarding/verify-provenance.py,redact-provenance.py.- Tests:
packages/control-plane/test/provenance.test.ts(chain, concurrent appends, an edited record
file refused, restart continuity, export, tampering cases; it runs the Python verifier on the same
exports asverifyExport, so the two cannot drift), and the "every link of a sandbox is a record
digest" case. - Docs: the provenance section (§7) of the template lifecycle design.
Depends on
Nothing. Later template issues write their records into it: #736 (store), #737 (self-serve create),
#741 (host agent), #742 (activation lease), #749 (retire), #751 (sessions), #739 (members stream),
#752 (egress digests on sandbox records).
How to verify
pnpm -C packages/control-plane test -- provenancepython3 deploy/sbx/template-onboarding/verify-provenance.py <export.json>on an export the test
writes, then again after editing one byte of a record (exit 1), and with--headnaming an older
head (exit 1).
Limits / out of scope
- Digests, not signatures: an export proves itself consistent; only
--headagainst a head kept
elsewhere catches truncation. Signing images or an SBOM are out of scope. - No HTTP export route yet: the export is the store's
export(); an authorized
GET /v1/provenance/export?template=<id>is planned in the design, not in this PR. - The verifier does not re-run each
checkagainst its policy, nor match abuildrecord's manifest
hash to a snapshot at hand. - A store written before a record kind existed links those events by time, not by digest; a verifier
older than a kind refuses a store holding it. - One control-plane process per store directory.
Assisted-By: Claude Code
Activity
fix(control-plane): write a provenance file once without a check-then…
feat(control-plane): record template provenance in a hash chain, veri…
feat(control-plane): template tags, edits and owner transfer through …
docs(sbx): the template onboarding guide, its step list and the folde…
docs(sbx): template governance, the process and how its rules are owned