gunk-dev/the-valley

verification.md

source806feada68e6main's published tip history
16.3 KiB · Rendered
1# Verification
2
3An attestation is a signed statement about a check and its result. It identifies the tree checked,
4the computation or observation performed, and any supplied provenance. The integrator uses that
5statement as evidence under the project's governing policy.
6
7This document defines the current formats and helper behavior. Independent re-verification and
8transparency publication remain [Phase 6 work](./roadmap.md#phase-6--trust-backstop). The
9[attestation decision](../.the-valley/decisions/dcr-0de694f-phase2-attestation-shape.md) defines the
10overall shape; the
11[text and signature decision](../.the-valley/decisions/dcr-de9d996-statement-text-and-signed-note.md)
12fixes the signed representation.
13
14## Pure and effectful checks
15
16A **pure check** claims a reproducible computation over identified inputs. Examples include builds,
17lint, and tests packaged as Nix derivations. Its statement records the input digest, derivation
18digest, output digest, and result. Another verifier can attempt the same computation and compare
19those values.
20
21An **effectful check** records an observation of a changing environment. Examples include a test
22against a live API or a measurement whose result is not reproducible from fixed inputs. Its
23statement records the check, environment, time, and observed result. Repeating it later produces a
24new observation, not necessarily confirmation of the old one.
25
26A test involving services may still be packaged as a pure check if the relevant environment is
27controlled, for example in a `nixosTest` VM. Doing that reduces dependence on mutable external
28state. Classifying a runner as pure is still a claim about its execution conditions and
29reproducibility.
30
31The policy chooses the required runner. An attestation cannot select a weaker transfer rule for
32itself by claiming a different check kind. [Integration](./integration.md#evaluating-a-request)
33defines how the two kinds of evidence transfer to a new base.
34
35## Tree identity
36
37The primary subject of an attestation is a digest of the checked tree. A Git commit ID may accompany
38it as an advisory identifier, but does not define the subject.
39
40The `valley-tree-v1` digest is SHA-256 over a canonical manifest:
41
421. Begin with `valley-tree-v1` followed by a newline.
432. Enumerate every regular file, executable file, and symlink at its path relative to the tree root.
443. Sort entries by path bytes in ascending order.
454. Append each entry in this form, followed by a newline:
46
47 ```text
48 <mode> <SHA-256 of content in lowercase hex> <path byte length in decimal> <path>
49 ```
50
51Modes are Git's `100644`, `100755`, and `120000`. A symlink's content is its target. Directories are
52implied by the paths beneath them and have no entries of their own. Submodules are rejected because
53their content is not contained in the tree being digested.
54
55The path length prevents an embedded newline in a path from being confused with an entry boundary.
56The final digest is rendered as lowercase hexadecimal.
57
58Commit metadata, timestamps, and store locations do not enter the manifest. Two commits containing
59the same tree therefore have the same subject digest. If rebasing changes the tree, the original
60attestation still names the original tree; the integrator must establish whether its evidence
61transfers. [Base binding](../.the-valley/ideas/ida-cbcbb3c-attestations-bind-to-a-base.md) explains
62that distinction.
63
64The helper uses the same manifest for a pure check's output. A single-file output is represented as
65an entry at the empty path.
66
67### Input and derivation digests
68
69`valley-inputs-v1` identifies the set of input names reported by a runner. Its manifest begins with
70`valley-inputs-v1` and a newline. Names are sorted by bytes and deduplicated. Each is written as its
71byte length in decimal, a space, the name, and a newline. SHA-256 over that manifest, rendered in
72lowercase hex, is the digest.
73
74The Nix runner obtains these names from the derivation's referenced store paths. It separately
75hashes the derivation file's bytes with SHA-256. These are the two values recomputed for pure
76evidence transfer. The definitions and reference implementation are in
77[attest/digest.go](../attest/digest.go) and [attest/check.go](../attest/check.go).
78
79## Statement text
80
81A signature covers bytes, so each statement has one canonical text representation. The first line is
82the statement type. Each remaining line contains a field path, one space, and a value. The text ends
83with a newline.
84
85This schematic example abbreviates digests and is not a valid statement to submit:
86
87```text
88the-valley/attestation/v1
89subject.primary valley-tree-v1
90subject.digest.git-sha1 99b5f2f7…
91subject.digest.valley-tree-v1 73847e0b…
92predicateType the-valley/check/pure/v1
93predicate.check.name prose-format
94predicate.check.runner nix
95predicate.check.attribute prose-format
96predicate.result passed
97predicate.inputs.valley-inputs-v1 8df8c199…
98predicate.derivation.sha256 ef69ed0c…
99predicate.output.valley-tree-v1 cf1f5a9c…
100provenance.harness example-harness
101provenance.model example-model
102provenance.delegation.0.principal human:operator
103provenance.delegation.0.grant authorized project work
104```
105
106The first line identifies both the kind of document and its version. It also distinguishes these
107signed bytes from other kinds of statement the same key might sign.
108
109Dots separate field-path segments. A decimal segment denotes an array index:
110`provenance.delegation.0.principal` names the principal in the first recorded delegation.
111
112### Line order
113
114Render fields in this order, omitting only fields the statement does not carry:
115
1161. Statement type, as the first line.
1172. `subject.primary`, then `subject.digest` entries.
1183. `predicateType`.
1194. `predicate` fields in the order defined for that predicate type.
1205. `provenance`: `harness`, `model`, `prompt`, `context`, then `delegation`.
121
122The check predicate orders are:
123
124| `the-valley/check/pure/v1` | `the-valley/check/effectful/v1` |
125| --------------------------- | ------------------------------- |
126| `predicate.check.name` | `predicate.check.name` |
127| `predicate.check.runner` | `predicate.check.runner` |
128| `predicate.check.attribute` | `predicate.check.attribute` |
129| `predicate.check.command` | `predicate.check.command` |
130| `predicate.result` | `predicate.environment` |
131| `predicate.inputs` | `predicate.observedAt` |
132| `predicate.derivation` | `predicate.result` |
133| `predicate.output` | |
134
135The third predicate, `the-valley/integration/transfer/v1`, records the integrator's decision that
136evidence applies to the landed tree. Its field order is:
137
138| Field or group | Meaning |
139| ------------------------------------------------------------ | --------------------------------------------------- |
140| `predicate.change` | Change identifier |
141| `predicate.target` | Target ref |
142| `predicate.base` | Digest set identifying the originally attested tree |
143| `predicate.policy` | Digest set identifying the governing policy |
144| `predicate.required` | Explicit zero-check case, when applicable |
145| `predicate.checks.<i>.name`, `.rule`, `.evidence`, `.inputs` | Per-check transfer verdicts |
146
147A transfer statement must use exactly one of two forms:
148
149- When checks were required, `predicate.checks` contains an entry for each, and `predicate.required`
150 is absent.
151- When none were required, it contains `predicate.required none`, and `predicate.checks` is absent.
152
153An empty array cannot represent the zero-check case because it produces no lines.
154
155Digest sets and other maps whose keys vary by caller sort by key. Arrays use numeric index order, so
156element 10 follows element 9. Each recorded delegation writes `principal` before `grant`. A field
157without a defined position is rejected. New fields need a defined order and appropriate versioning;
158arbitrary document fragments have no independent canonical form.
159
160### Allowed values
161
162The text format has no escaping. Its constraints are part of the signing contract:
163
164- Leaves must be nonempty strings. Numbers, booleans, and null are rejected.
165- Values cannot contain ASCII control characters, including newlines.
166- Empty objects and arrays are rejected, rather than silently dropped.
167- Field names begin with an ASCII letter and continue with letters, digits, or dashes.
168- Array indices start at zero, have no gaps, and use decimal without leading zeros.
169
170A verifier accepts text only if parsing it and rendering the resulting document reproduces the same
171bytes. Duplicate keys, incorrect ordering, unsupported fields, and values that cannot be represented
172therefore fail verification.
173
174[schema/attestation.cue](../schema/attestation.cue) validates statement fields and values. Schema
175validation and canonical rendering must agree on the document being signed.
176
177## Signed notes
178
179A signed note contains the statement text, a blank line, and one or more signature lines. Each
180signature line has this form and ends with a newline:
181
182```text
183— <signer name> <base64 of key hash followed by signature>
184```
185
186The leading character is an em dash, U+2014. The base64 payload contains the four-byte key hash in
187big-endian order followed by the raw Ed25519 signature over the statement text, including its final
188newline.
189
190This is the signed-note format used by `golang.org/x/mod/sumdb/note`. Several signers add sibling
191signature lines under the same statement text. Adding a signature does not change the claim or the
192bytes earlier signers covered.
193
194The signature covers the statement text. It does not cover Git objects, envelope fields, or the
195signer's displayed name. The statement type on the first line provides the distinction between kinds
196of signed claim.
197
198### Signing names and verifier keys
199
200The naming convention is a host's fully qualified name followed by the signing purpose, for example
201`laddie.gunk.dev/attestations`.
202
203A verifier receives known keys as one line per key:
204
205```text
206<name>+<eight hexadecimal digits of key hash>+<base64 public-key encoding>
207```
208
209The public-key encoding contains the algorithm byte followed by the public key. The hash is the
210first four bytes of SHA-256 over the name, a newline, the algorithm byte, and the public key.
211Publishing one raw key under two names therefore produces two verifier identities.
212
213Unknown signatures do not establish trust. At least one recognized signature must verify, and an
214invalid signature claiming a recognized key causes the whole note to fail. A valid sibling signature
215does not excuse that failure.
216
217The helper signs with a raw Ed25519 key supplied by the host. A host SSH key can serve this role;
218provisioning and custody are deployment concerns. Native SSH commit signing and signed-note
219verification are separate formats with separate verifier configuration.
220
221The planned physical human approval in the
222[core decision](../.the-valley/decisions/dcr-9c75283-substrate-adoption-and-the-core.md) needs its
223own usable signing mechanism. The current host-signed note does not establish that a person
224physically approved the change.
225
226## The helper
227
228`nix run .#attest -- <command>` runs the reference helper. Its commands are:
229
230| Command | Behavior |
231| -------- | ----------------------------------------------------------------------------------------------------------------------- |
232| `run` | Run checks over an export of a committed tree, compose and sign one statement per check, and store the evidence locally |
233| `verify` | Validate the note, statement, and recognized signatures; optionally compare the subject with a repository tree |
234| `digest` | Compute the tree digest for a revision |
235| `inputs` | Evaluate pure checks and print input and derivation digests without building them |
236| `render` | Render a statement supplied as JSON into canonical text |
237| `sign` | Sign statement text or add a signature to an existing note |
238| `key` | Print the verifier key corresponding to a signing key |
239
240`attest run` uses committed content rather than uncommitted files in the working directory. The key
241is supplied with `--key`; `--name` selects the signing name, defaulting to the host's. There is no
242unsigned mode. A failing check, invalid statement, or signing failure prevents publication.
243
244Evidence is stored beneath:
245
246```text
247refs/the-valley/attestations/<tree digest>/<signer key hash>
248```
249
250With `--push`, the helper publishes the topic branch and its attestation ref in one atomic native
251Git push. This does not submit an integration request. The
252[contributor workflow](./contribute.md#publishing-and-requesting-integration) explains how
253`valley review` publishes evidence and a request together.
254
255`attest verify` checks canonical text, schema validity, and signatures by recognized keys. With
256`--repo`, it also checks the named tree; `--signer` requires a particular signer's signature. It
257does not rerun the check. Witness re-verification is a separate planned operation.
258
259Run provenance is optional caller input through `--provenance`. It can record the harness, model,
260prompt and context digests, and delegation chain. The helper does not collect those values
261automatically or establish that a recorded delegation was authorized.
262
263The files in [attest/conformance/](../attest/conformance/) pair documents with exact text and signed
264notes, and include inputs that must be rejected. The `attest-conformance` check tests this
265interoperability contract.
266
267## Trust and limits
268
269The mechanisms establish different things:
270
271| Mechanism | What it establishes | What it does not establish |
272| --------------------------------- | ------------------------------------------------------------------------------ | ---------------------------------------------------------------------- |
273| Signature | A recognized key signed these bytes | That the stated check actually ran or the signer described it honestly |
274| Tree and computation digests | Which content and computation the claim identifies | That the check itself enforces the intended requirement |
275| Reproducible execution | A basis for independently checking a result | Proof from the author's report alone |
276| Pinned tool and check definitions | Which implementations are intended to run | That a compromised host actually used them |
277| Witness re-verification, planned | Independent comparison for the checks sampled | Immediate detection or coverage of every accepted claim |
278| Transparency log, planned | Evidence of publication and later tampering under the log's verification model | Correctness of execution or automatic recovery from a bad change |
279
280A host with access to a signing key can make a false but correctly signed statement, including a
281false claim about the tool it used. A sandbox helps control normal execution but cannot make the
282host's own report independent of that host.
283
284There is also a current
285[check-definition gap](../.the-valley/bugs/bd-eaefe82-check-definitions-come-from-the-branch.md):
286the policy comes from governing state, but check derivations still come from the candidate tree.
287Rerunning a weakened check can reproduce its result without detecting the weakened requirement.
288
289The proposed trust system still needs rules for sampling, new signers, revocation, retention, and
290recovery after a false claim has already been accepted. These limits do not establish a supply-chain
291assurance level or a guaranteed detection window.