gunk-dev/the-valley

verification.md

source933f202462e5main's published tip history
14.2 KiB · Rendered
1# Verification
2
3The reframe — attestation-with-revocation instead of CI-as-gate, and the failure-mode trade it makes
4— is an architecture bet; see [architecture.md](./architecture.md). This document holds what the
5attestation phase actually needs: the two kinds of checks, what an attestation is about, and what
6makes one hard to forge.
7
8The shape of an attestation — its statement, its signer, its envelope, where it is stored, and how
9several of them compose — is fixed by
10[dcr-0de694f](../.the-valley/decisions/dcr-0de694f-phase2-attestation-shape.md), and the statement's
11fields are [schema/attestation.cue](../schema/attestation.cue). How a statement is written down and
12signed is [dcr-de9d996](../.the-valley/decisions/dcr-de9d996-statement-text-and-signed-note.md), and
13the sections below are that decision's detail.
14
15## Two kinds of checks, two kinds of attestation
16
17The system must distinguish what an attestation is claiming. A single "checks passed" signature is
18the SLSA mistake worth avoiding.
19
20- **Pure checks** — `nix build`, `nix flake check`, lint/type-check as derivations,
21 `nixosTest`-style integration tests (effectful inside, pure outside). Inputs content-addressed,
22 outputs deterministic; the attestation carries input, derivation, and output hashes, so **any
23 verifier can re-derive and confirm**. These are the strong attestations.
24- **Effectful checks** — real-network tests, external APIs, benchmarks, anything not
25 bit-reproducible. The attestation is a notarization: "sealed environment $E ran $T at time $t and
26 observed $result." Trust here is closer to "I trust the signer."
27
28Wherever a check can be moved from effectful to pure (via `nixosTest` or microVM sandboxing), it
29should be.
30
31## The subject is a tree digest
32
33An attestation is about a tree, not about a commit. The digest that names that tree is
34`valley-tree-v1`, and it is defined so that anyone holding the tree can recompute it from the tree
35alone.
36
37Take every entry of the tree: every blob and every symlink, at its path relative to the root. Render
38each one as a line
39
40 <mode> <sha256 of the content, in hex> <byte length of the path> <path>
41
42where the mode is git's — `100644`, `100755`, or `120000` for a symlink, whose content is its target
43— and the byte length is written out in decimal. Sort the lines by path, ascending, comparing bytes.
44Put `valley-tree-v1` and a newline in front of them. The digest is the SHA-256 of the result, in
45lowercase hex.
46
47The path's byte length is written out because a path can contain a newline, and an entry boundary a
48path could forge is a digest an attacker could steer. Directories are not entries: a directory is
49implied by the paths beneath it, and git holds no empty ones. A submodule is rejected rather than
50digested, because a tree that reaches outside itself is not a thing this digest can be a function
51of.
52
53Nothing else enters the manifest. Not the commit, not the author, not the time, not a store path.
54That is what makes an attestation survive the integrator's rebase: the same tree under a rewritten
55commit has the same digest, so the attestation still names it. It is also what binds an attestation
56to a base, since a tree is the base and the change together
57([ida-cbcbb3c](../.the-valley/ideas/ida-cbcbb3c-attestations-bind-to-a-base.md)).
58
59The same manifest digests a pure check's output, so the digest a statement records for what a check
60produced and the digest it records for what the check ran over are the same kind of thing.
61
62## A statement is written down as lines
63
64A signature covers bytes, so a statement has one written form and every implementation must produce
65it exactly. That form is `valley-statement-v1`, and it is lines.
66
67The first line is `valley-statement-v1`, the name of the form. Every line after it is a key, one
68space, and a value. The lines are sorted by key, ascending, comparing bytes, and the text ends with
69a newline.
70
71 valley-statement-v1
72 predicate.check.name prose-format
73 predicate.check.runner nix
74 predicate.result passed
75 predicateType the-valley/check/pure/v1
76 statementType the-valley/attestation/v1
77 subject.digest.valley-tree-v1 73847e0b…
78 subject.primary valley-tree-v1
79
80A key is the path from the document's root to the value, with a dot between segments. A segment that
81is a decimal number is an index into an array, so `provenance.delegation.0.principal` is the
82principal of the first recorded delegation.
83
84The form has no escapes, and that is why it was chosen. A value is written as its own bytes, so
85there is exactly one way to write it and nothing for two implementations to disagree about. What
86follows from that is a short list of things a statement may not carry, each refused rather than
87escaped or dropped:
88
89- **Only strings at the leaves.** A number, a boolean and a null have no written form, because
90 nobody has decided one and a guess would be a guess about signed bytes.
91- **No empty value.** A line's value is what follows its first space, so an empty one would be an
92 invisible trailing space. A field a statement does not carry is left out.
93- **No control character in a value.** A newline is where a line ends, so there is no way to write
94 one inside a value.
95- **No empty object and no empty array.** They have no lines, so they cannot be written down. They
96 are refused rather than dropped, which is what keeps what was validated and what was signed the
97 same document.
98- **Field names are a letter, then letters, digits and dashes.** That keeps a name clear of the dot
99 that separates segments, the space that separates key from value, and the digits that mark an
100 index.
101
102Arrays are dense: indices run from 0 with no gaps, in decimal without leading zeros. Line order over
103indices is byte order, so `.10` sits between `.1` and `.2`; a reader rebuilds an array from the
104index and never from the order the lines arrive in.
105
106Reading the form back enforces every rule above, so text that parses is text a renderer would have
107produced. That is what makes "these bytes are the written form of what they say" something a
108verifier settles by reading, rather than a claim it has to take on trust.
109
110[schema/attestation.cue](../schema/attestation.cue) is the gate, and it holds every value and every
111field name to what a line can carry. So a statement with no written form fails validation before a
112run has built anything, rather than in a renderer after a check has already passed.
113
114## The envelope is a signed note
115
116A statement is signed as a **note**: the statement text, a blank line, and one or more signature
117lines. Each signature line is an em-dash (U+2014), a space, the signer's name, a space, and base64
118of a four-byte key hash followed by the raw Ed25519 signature over the text.
119
120 valley-statement-v1
121 predicate.result passed
122 …
123
124 — laddie.gunk.dev/attestations sEDvC7HO4DfL5ZxbZPFvoVWq2Wt5eGTqZx2h…
125 — witness.gunk.dev/attestations lDb9C3YrmxnO0/YWsmWjiu2kteNvGqfQstCy…
126
127This is the format `golang.org/x/mod/sumdb/note` defines and transparency log checkpoints are
128published in. It is the envelope for what it does to composition: several parties attesting to one
129subject are sibling signature lines under one text, so a signature cannot be lifted onto a different
130statement — it sits under the text it covers, and moving it means moving that text with it. It is
131also the envelope a [Phase 6](./roadmap.md#phase-6--trust-backstop) checkpoint arrives in, so the
132same envelope carries an attestation now and a checkpoint later rather than changing at the
133boundary.
134
135A signature covers the text and nothing else: not the signer's name, not a namespace, and no git
136object ([ida-51605e8](../.the-valley/ideas/ida-51605e8-authenticity-not-git-coupled.md)). So what
137separates an attestation from any other note a key signs is the text's own first line, which is why
138statement text opens by naming its form.
139
140**The signer's name** is the host's fully qualified name, a slash, and what it is signing:
141`laddie.gunk.dev/attestations`. The host part says which machine to go and ask about a key. The
142suffix keeps a key signing attestations distinct, as a verifier key, from the same key signing
143anything else — the name is inside the key hash, so the same public key published under two names is
144two verifier keys and cannot be confused.
145
146**What a verifier is given** is a set of known keys, one per line: the name, the key hash its name
147and public key produce, and the public key itself.
148
149 laddie.gunk.dev/attestations+1f9c40b2+AbUmzL2tCH0nR9…
150
151That is the whole of it. There is no allowed-signers file, no certificate and no directory lookup. A
152signature by a key not among them is a signature by nobody the verifier accepts, and a signature by
153one of them that does not check out refuses the whole note — one good signature standing beside a
154forgery is not a note to read past.
155
156The host signs with a raw Ed25519 key. `/etc/ssh/ssh_host_ed25519_key` is the natural production
157identity, because the host already has it and it already says which host this is, but the key is a
158parameter and provisioning one is deployment.
159
160## The helper
161
162`nix run .#attest` is the Phase 2 helper. `attest run` digests the tree, runs the checks over an
163export of that tree rather than over the working directory, composes one statement per check, vets
164each against [schema/attestation.cue](../schema/attestation.cue), writes each out as statement text,
165signs each as a note, and stores them at
166`refs/the-valley/attestations/<tree digest>/<signer key hash>`. With `--push` it publishes the topic
167branch and that ref in one atomic native-git push. A failing check publishes nothing, and neither
168does a statement the schema rejects or a statement with no written form.
169
170The signing key is a parameter (`--key`), as is the name it signs under (`--name`, defaulting to
171this host's). There is no unsigned mode: a run with no key available fails rather than emitting a
172statement nobody signed.
173
174`attest verify` takes a note and a known-keys file, and checks four things: that the note's text is
175the written form of what it says, that the statement satisfies the schema, that every signature by a
176key the verifier holds checks out over exactly those bytes, and — given `--repo` — that the tree in
177front of the verifier is the tree the statement names. `--signer` names a signer whose signature
178must be present. Re-running a pure check and confirming its output digest is witness
179re-verification, and belongs to [Phase 6](./roadmap.md#phase-6--trust-backstop) rather than here.
180
181`attest render` writes a JSON document as statement text, `attest sign` turns statement text into a
182note or adds a signature line to one, and `attest key` prints the verifier key for a signing key.
183Those bytes are an interop contract rather than an internal step: a second implementation that
184writes them differently signs different bytes over the same statement, and every signature already
185made stops verifying against it. So [attest/conformance/](../attest/conformance/) holds fixed
186documents paired with their exact text and notes, along with the documents and texts that must be
187refused, and the flake's `attest-conformance` check runs the whole set.
188
189The run provenance a statement carries — the harness, the model, digests of the prompt and the
190context, and the delegation chain — is supplied by the caller (`--provenance`) or absent. Nothing
191collects those values today.
192
193## The mechanism stack
194
195Without a TEE, attestations are exactly as trustworthy as the signing key — the same trust model as
196code signing, plenty for non-adversarial settings. But the mechanisms stack:
197
198| Mechanism | What it gets you | Residual attack |
199| ---------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
200| Signing key | "The signer says these checks passed" | Anyone with the key can lie |
201| Content-addressed attestation tool | The tool itself is a known Nix derivation; the attestation names its hash | Malicious dev can ship a patched tool, but it will not match the canonical hash |
202| Hermetic sandbox | `nix build` sandbox; `nixosTest` VMs; microVMs for non-Nix checks | Local root can still bypass — but bypass leaves evidence |
203| Re-derivation audit | Pure attestations encode every input hash; verifier re-runs and confirms bit-identical | None for pure checks; effectful checks not re-verifiable |
204| Witness sampling | Random fraction of attestations re-run on another node; trust score per attester | None — this is the backstop |
205| Transparency log (Tessera-backed) | Every attestation appended to an external append-only log with an inclusion proof; anyone can audit existence and content over time | Orthogonal to the others — gives non-repudiation and tamper evidence, not correctness of the computation. Independent and complementary. |
206
207Stacked, a determined local-root actor can still forge an attestation — but only visibly (tool hash
208mismatch), temporarily (re-derivation eventually detects), and within a bounded window (before their
209trust score is recalculated). For pure-derivation checks this lands roughly at SLSA Level 3; for
210effectful checks, lower — but the system knows which kind each attestation is.