gunk-dev/the-valley

attestation.cue

sourcefbad5d235a6cmain's published tip history
11.3 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 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 (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 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 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#PredicateType: "the-valley/check/pure/v1" | "the-valley/check/effectful/v1"
118
119// #PureCheck is the re-derivable claim. The three digests are what a
120// verifier re-derives against: it evaluates the same check over the same
121// subject tree, and must arrive at the same derivation and the same
122// output.
123#PureCheck: {
124 check: #CheckRun
125 result: #Result
126
127 // The check's inputs, as the runner named them.
128 inputs: #DigestSet
129
130 // The derivation that was built.
131 derivation: #DigestSet
132
133 // What the build produced.
134 output: #DigestSet
135}
136
137// #EffectfulCheck is the notarization. It carries no re-derivation
138// digests, because there is nothing to re-derive: an effectful check is
139// not bit-reproducible, which is the whole reason it is a separate
140// predicate type.
141#EffectfulCheck: {
142 check: #CheckRun
143 result: #Result
144
145 // The environment the check ran in, named by whoever sealed it. A
146 // verifier can do nothing with this but read it; it is what the
147 // notarization is a notarization *of*.
148 environment: #Line
149
150 // When the result was observed, RFC 3339 in UTC. Present here and
151 // absent from #PureCheck on purpose: a pure claim that carried a time
152 // would stop being a function of its inputs.
153 observedAt: =~"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
154}
155
156// #CheckRun is the check that ran, named the way the verification policy
157// of schema/verification.cue names it, so the two documents agree on what
158// a check is called.
159#CheckRun: {
160 // The check's name in the project's policy.
161 name: #Name
162
163 // The runner kind. "nix" builds a flake check attribute and claims
164 // purity strongly; "command" runs a command line and claims nothing
165 // beyond having run it.
166 runner: "nix" | "command"
167
168 // The flake check attribute, for the nix runner.
169 attribute?: #Name
170
171 // The command line, for the command runner. One line: a check whose
172 // command spans several has no written form, so it is refused here
173 // rather than in a renderer after the check has run.
174 command?: #Line
175
176 if runner == "nix" {
177 attribute: #Name
178 command?: _|_
179 }
180 if runner == "command" {
181 command: #Line
182 attribute?: _|_
183 }
184}
185
186// A check either passed or it did not. The helper publishes nothing when a
187// check fails, but "failed" is admitted here because a statement that
188// could not record a failure would be a schema that only permits good
189// news.
190#Result: "passed" | "failed"
191
192// #Provenance is the record of the run that produced the tree, carried as
193// content. An agent run holds no key (ida-a8243d2), so none of this is
194// self-asserted: it is attributed inside the host's signed statement
195// (ida-45178f6), and it is true exactly to the extent the host is trusted.
196#Provenance: {
197 // The harness that ran the agent.
198 harness?: #Line
199
200 // The model the harness drove.
201 model?: #Line
202
203 // Digests of the prompt and of the context the run was given. Digests
204 // rather than content: the value is committed to by the signature
205 // while the text itself stays wherever it lives.
206 prompt?: #DigestSet
207 context?: #DigestSet
208
209 // The delegation chain, as recorded. Phase 2 records; it does not
210 // check. Verifying a chain belongs to an enforcement point, and the
211 // first one is Phase 3's integrator.
212 delegation?: [...#Delegation]
213}
214
215// #Delegation is one step of a recorded chain: who acted, and what the
216// step conveyed. Both are free strings because no naming scheme for
217// principals has been decided, and pinning one here would decide it.
218#Delegation: {
219 principal: #Line
220 grant?: #Line
221}
222
223// Names are lowercase, dash-separated, and short — the same shape as check
224// names in schema/verification.cue and project names in schema/valley.cue.
225#Name: =~"^[a-z0-9][a-z0-9-]*$"
226
227// ----------------------------------------------------------------------
228// The statement.
229//
230// The top level of this package is itself a statement, so a composed
231// statement is validated by vetting it against this file directly. The
232// parts above are definitions; the document they make is here.
233
234// The document kind, versioned. A verifier reads this before anything
235// else, so a future revision can be told apart without guessing.
236statementType: "the-valley/attestation/v1"
237
238// What the statement is about.
239subject: #Subject
240
241// The kind of claim, versioned. The version is part of the name, so a
242// statement says which revision of a claim shape it was written against,
243// and the format can grow without invalidating what already exists.
244predicateType: #PredicateType
245
246// The run that produced the tree, carried as content. Optional, and every
247// field inside it is optional: nothing in the reference implementation
248// collects these values today, so they are caller-supplied or absent
249// rather than invented.
250provenance?: #Provenance
251
252// The claim itself. Its shape follows from the predicate type, and it is
253// constrained only through that type — which is the mechanism that puts
254// the pure-versus-effectful distinction inside the signed bytes. A
255// statement claiming purity cannot omit the digests a verifier re-derives
256// against, and one claiming a notarization cannot smuggle them in.
257if predicateType == "the-valley/check/pure/v1" {
258 predicate: #PureCheck
259}
260if predicateType == "the-valley/check/effectful/v1" {
261 predicate: #EffectfulCheck
262}
263
264// A file's top level cannot be closed (embedding #Statement would open it
265// instead — embedding lifts closedness), so reject stray top-level fields
266// explicitly: anything but the statement's fields — a `predicat:` typo, a
267// carriage concern like `signature:` — conflicts with this sentinel and
268// fails vet with an error naming the field.
269[!="statementType" & !="subject" & !="predicateType" & !="predicate" & !="provenance"]: "INVALID: unknown top-level field; only \"statementType\", \"subject\", \"predicateType\", \"predicate\" and \"provenance\" are allowed"