gunk-dev/the-valley

attestation.cue

source01f84ae34d8amain's published tip history
15.0 KiB
1// The statement a Phase 2 attestation signs: a typed, versioned record of
2// what check ran, over what tree, with what result (dcr-0de694f). The
3// statement is the only thing signed. The envelope around it — a signed
4// note, whose text is the statement and whose signature lines sit beneath
5// it — and the git ref that note is stored at are carriage, and neither is
6// described here.
7//
8// The statement is self-contained: a verifier that holds these bytes and
9// the tree they name needs nothing else to understand the claim. That is
10// why the pure-versus-effectful distinction of archive/design/verification.md is
11// `predicateType` — inside the signed bytes — rather than a property of
12// where the statement was found.
13//
14// This file is the gate a statement passes on the way in and on the way
15// out, and it reads JSON. What a signature covers is the statement's
16// written form, which is lines (archive/design/verification.md); the two carry the
17// same fields, and the constraints below on what a value may be are what
18// keep every validated statement writable as lines.
19//
20// Like the host and event schemas, this file is deliberately not Nix. A
21// statement travels between machines and outlives the tool that wrote it.
22//
23// Validate a statement: cue vet -c schema/attestation.cue <statement>.json
24package attestation
25
26// #Subject identifies what is attested to, as a digest set: several named
27// digests of the same object, under different naming schemes. `primary`
28// names the member that IS the identity, and it is always a
29// content-addressed digest of the tree — which is what makes an
30// attestation survive a rebase, and what binds it to the base the change
31// was produced against (ida-cbcbb3c). Every other member is advisory: a
32// commit hash is useful for finding the change and is never relied on for
33// identity, because identity may not be coupled to git (ida-51605e8).
34#Subject: {
35 // The naming scheme that identifies the subject. Only a
36 // content-addressed tree digest may hold this position; widening it
37 // means adding a second content-addressing scheme, deliberately not
38 // before one exists.
39 primary: "valley-tree-v1"
40
41 // The digests. The primary member must be present — a subject
42 // identified only by advisory members has no identity at all.
43 digest: #DigestSet
44 digest: (primary): _
45}
46
47// #DigestSet is a set of digests of one object, keyed by the scheme that
48// produced them. Closed: an unrecognised scheme is a verifier that cannot
49// check what it was handed, so it fails vet rather than being carried
50// through as an opaque string.
51#DigestSet: {
52 // The valley tree digest, defined in archive/design/verification.md. SHA-256
53 // over a canonical manifest of the tree's entries, so it is a function
54 // of the tree alone: no commit, no author, no time, no path outside
55 // the tree.
56 "valley-tree-v1"?: #Sha256
57
58 // SHA-256 over a canonical manifest of a pure check's input paths,
59 // defined alongside the tree digest.
60 "valley-inputs-v1"?: #Sha256
61
62 // SHA-256 over an object's bytes.
63 sha256?: #Sha256
64
65 // A git object id, advisory only. Both hash algorithms git ships are
66 // admitted, because which one a repository uses is not the
67 // attestation's concern.
68 "git-sha1"?: =~"^[0-9a-f]{40}$"
69 "git-sha256"?: =~"^[0-9a-f]{64}$"
70}
71
72#Sha256: =~"^[0-9a-f]{64}$"
73
74// #Line is what a statement's every string value is held to: text that one
75// line can carry. Not empty, and holding no ASCII control character.
76//
77// This is a property of the signed bytes rather than a stylistic
78// preference. A statement is written out as lines, and the form has no
79// escapes: a value is written as its own bytes, which is what leaves two
80// implementations nothing to disagree about. So a value carrying a newline
81// has no written form at all, and one that is empty would leave an
82// invisible trailing space behind. Both fail here, before a run has built
83// anything, rather than in a renderer after a check has passed.
84#Line: =~"^[^\\x00-\\x1f\\x7f]+$"
85
86// #KeySegment is the shape of every field name a statement carries: a
87// letter, then letters, digits and dashes.
88//
89// This too is about the signed bytes. A field's name is written into the
90// key that names its line, dots separate one segment of that key from the
91// next, a space separates the key from the value, and a segment that is a
92// number is an array index. A name holding any of those would be a line
93// that reads back as something other than what was written.
94//
95// Every name in this file is fixed here and satisfies it, so no statement
96// today can carry one that does not. The constraint is written down anyway,
97// because the first map keyed by a caller rather than by this file is where
98// the property silently stops holding.
99#KeySegment: =~"^[A-Za-z][A-Za-z0-9-]*$"
100
101// #SegmentKeyed is how a map with caller-supplied keys is written. Nothing
102// uses it yet: every map the statement carries today — the digest sets, the
103// provenance — is keyed by names this file fixes. The direction that
104// introduces one is the ecosystem-specific key-value context strings of
105// ida-d2dc957, and whatever field carries them unifies with this, so a key
106// with no written form fails `cue vet` rather than reaching a signer:
107//
108// context: #SegmentKeyed & {[string]: #Line}
109#SegmentKeyed: {[#KeySegment]: _}
110
111// The two kinds of claim of archive/design/verification.md. A pure check's
112// attestation is re-derivable: it carries input, derivation and output
113// digests, and any verifier can re-run and confirm. An effectful check's
114// attestation is a notarization: a named environment ran the check at a
115// stated time and observed a result, and trust in it is trust in the
116// signer.
117//
118// The third kind is not a claim about a check at all. An integrator's
119// transfer statement says that evidence produced over one tree stands for
120// another — the commit-point record of dcr-439b771.
121#PredicateType: "the-valley/check/pure/v1" |
122 "the-valley/check/effectful/v1" |
123 "the-valley/integration/transfer/v1"
124
125// #PureCheck is the re-derivable claim. The three digests are what a
126// verifier re-derives against: it evaluates the same check over the same
127// subject tree, and must arrive at the same derivation and the same
128// output.
129#PureCheck: {
130 check: #CheckRun
131 result: #Result
132
133 // The check's inputs, as the runner named them.
134 inputs: #DigestSet
135
136 // The derivation that was built.
137 derivation: #DigestSet
138
139 // What the build produced.
140 output: #DigestSet
141}
142
143// #EffectfulCheck is the notarization. It carries no re-derivation
144// digests, because there is nothing to re-derive: an effectful check is
145// not bit-reproducible, which is the whole reason it is a separate
146// predicate type.
147#EffectfulCheck: {
148 check: #CheckRun
149 result: #Result
150
151 // The environment the check ran in, named by whoever sealed it. A
152 // verifier can do nothing with this but read it; it is what the
153 // notarization is a notarization *of*.
154 environment: #Line
155
156 // When the result was observed, RFC 3339 in UTC. Present here and
157 // absent from #PureCheck on purpose: a pure claim that carried a time
158 // would stop being a function of its inputs.
159 observedAt: =~"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
160}
161
162// #Transfer is the integrator's claim at the commit point (dcr-439b771):
163// the evidence a contributor produced over one tree stands for the tree
164// this statement's subject names, and here is the verdict on every check
165// the policy required.
166//
167// It is not a claim that any check ran. The integrator runs nothing; it
168// compares digests. What it asserts is that the comparison came out equal,
169// under a policy it names, over an evidence set it cites.
170#Transfer: {
171 // The change that landed, named by the request it arrived as.
172 change: #Line
173
174 // The stream it landed on, as a full ref name.
175 target: #Line
176
177 // The approved head's tree, which the contributor's attestations
178 // bind to (ida-cbcbb3c). The subject is the tree that landed; when
179 // the two are equal, nothing intervened. Each statement in checks is
180 // cited with its own subject, which on a moved landing may be the
181 // landed tree rather than this one.
182 base: #DigestSet
183
184 // The policy the verdict was derived under, resolved from the
185 // integrator's own checkout at the target tip and never from the
186 // submitted tree (bd-eaefe82). The advisory git member says which tip
187 // that was; the content digest is what pins the composed document.
188 policy: #DigestSet
189
190 // What the policy required of this change, written one of two ways,
191 // and never both.
192 //
193 // `checks` carries one entry per required check, in the order the
194 // integrator judged them. It is never empty: a value has a written
195 // form only if it has lines, and an array with no elements has none,
196 // so an empty list is a statement that cannot be signed.
197 //
198 // `required: "none"` is the zero case said out loud. A policy that
199 // requires nothing of a diff is an ordinary outcome — every path the
200 // diff touches is covered by a class that asks for nothing, or the
201 // diff touches no path at all — and the change lands on that basis.
202 // Absence carries the claim here rather than an empty container,
203 // which is the same absent-versus-empty rule the rest of the form
204 // keeps: a field a statement does not carry is left out, and what is
205 // left out is stated by the field beside it rather than inferred from
206 // a missing line.
207 {
208 checks: [#CheckTransfer, ...#CheckTransfer]
209 required?: _|_
210 } | {
211 required: "none"
212 checks?: _|_
213 }
214}
215
216// #CheckTransfer is one check's verdict at the commit point. Only
217// transferred checks are recorded: a statement carrying an invalidated one
218// would be a statement about a change that did not land.
219#CheckTransfer: {
220 // The check's name in the project's policy.
221 name: #Name
222
223 // How it transferred. "closure" is the pure rule — the input-closure
224 // digest recomputed on the landed tree equalled the attested one.
225 // "untouched" is the effectful rule — no intervening landing touched
226 // the requiring class's paths, and the observation was inside the
227 // declared window. "unmoved" is neither rule needing to run, because
228 // the landed tree is the tree the cited statement attests: the change's
229 // tree, or on a moved landing the landing tree's own evidence.
230 rule: "closure" | "untouched" | "unmoved"
231
232 // The statement this verdict is about, cited by a digest of the
233 // bytes a signature covers.
234 evidence: #DigestSet
235
236 // The input closure recomputed on the landed tree, for the closure
237 // rule. Equal to the attested statement's `inputs` by construction:
238 // an unequal one is not a transfer and is not written down.
239 inputs?: #DigestSet
240}
241
242// #CheckRun is the check that ran, named the way the verification policy
243// of schema/verification.cue names it, so the two documents agree on what
244// a check is called.
245#CheckRun: {
246 // The check's name in the project's policy.
247 name: #Name
248
249 // The runner kind. "nix" builds a flake check attribute and claims
250 // purity strongly; "command" runs a command line and claims nothing
251 // beyond having run it.
252 runner: "nix" | "command"
253
254 // The flake check attribute, for the nix runner.
255 attribute?: #Name
256
257 // The command line, for the command runner. One line: a check whose
258 // command spans several has no written form, so it is refused here
259 // rather than in a renderer after the check has run.
260 command?: #Line
261
262 if runner == "nix" {
263 attribute: #Name
264 command?: _|_
265 }
266 if runner == "command" {
267 command: #Line
268 attribute?: _|_
269 }
270}
271
272// A check either passed or it did not. The helper publishes nothing when a
273// check fails, but "failed" is admitted here because a statement that
274// could not record a failure would be a schema that only permits good
275// news.
276#Result: "passed" | "failed"
277
278// #Provenance is the record of the run that produced the tree, carried as
279// content. An agent run holds no key (ida-a8243d2), so none of this is
280// self-asserted: it is attributed inside the host's signed statement
281// (ida-45178f6), and it is true exactly to the extent the host is trusted.
282#Provenance: {
283 // The harness that ran the agent.
284 harness?: #Line
285
286 // The model the harness drove.
287 model?: #Line
288
289 // Digests of the prompt and of the context the run was given. Digests
290 // rather than content: the value is committed to by the signature
291 // while the text itself stays wherever it lives.
292 prompt?: #DigestSet
293 context?: #DigestSet
294
295 // The delegation chain, as recorded. Phase 2 records; it does not
296 // check. Verifying a chain belongs to an enforcement point, and the
297 // first one is Phase 3's integrator.
298 delegation?: [...#Delegation]
299}
300
301// #Delegation is one step of a recorded chain: who acted, and what the
302// step conveyed. Both are free strings because no naming scheme for
303// principals has been decided, and pinning one here would decide it.
304#Delegation: {
305 principal: #Line
306 grant?: #Line
307}
308
309// Names are lowercase, dash-separated, and short — the same shape as check
310// names in schema/verification.cue and project names in schema/valley.cue.
311#Name: =~"^[a-z0-9][a-z0-9-]*$"
312
313// ----------------------------------------------------------------------
314// The statement.
315//
316// The top level of this package is itself a statement, so a composed
317// statement is validated by vetting it against this file directly. The
318// parts above are definitions; the document they make is here.
319
320// The document kind, versioned. A verifier reads this before anything
321// else, so a future revision can be told apart without guessing.
322statementType: "the-valley/attestation/v1"
323
324// What the statement is about.
325subject: #Subject
326
327// The kind of claim, versioned. The version is part of the name, so a
328// statement says which revision of a claim shape it was written against,
329// and the format can grow without invalidating what already exists.
330predicateType: #PredicateType
331
332// The run that produced the tree, carried as content. Optional, and every
333// field inside it is optional: nothing in the reference implementation
334// collects these values today, so they are caller-supplied or absent
335// rather than invented.
336provenance?: #Provenance
337
338// The claim itself. Its shape follows from the predicate type, and it is
339// constrained only through that type — which is the mechanism that puts
340// the pure-versus-effectful distinction inside the signed bytes. A
341// statement claiming purity cannot omit the digests a verifier re-derives
342// against, and one claiming a notarization cannot smuggle them in.
343if predicateType == "the-valley/check/pure/v1" {
344 predicate: #PureCheck
345}
346if predicateType == "the-valley/check/effectful/v1" {
347 predicate: #EffectfulCheck
348}
349if predicateType == "the-valley/integration/transfer/v1" {
350 predicate: #Transfer
351}
352
353// A file's top level cannot be closed (embedding #Statement would open it
354// instead — embedding lifts closedness), so reject stray top-level fields
355// explicitly: anything but the statement's fields — a `predicat:` typo, a
356// carriage concern like `signature:` — conflicts with this sentinel and
357// fails vet with an error naming the field.
358[!="statementType" & !="subject" & !="predicateType" & !="predicate" & !="provenance"]: "INVALID: unknown top-level field; only \"statementType\", \"subject\", \"predicateType\", \"predicate\" and \"provenance\" are allowed"