gunk-dev/the-valley

attestation.cue

sourceb9d42e2a97e7main's published tip history
8.8 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 detached
4// SSHSIG signature under the namespace "the-valley.attestation.v1" — and
5// the git ref it is stored at are carriage, and neither is described here.
6//
7// The statement is self-contained: a verifier that holds these bytes and
8// the tree they name needs nothing else to understand the claim. That is
9// why the pure-versus-effectful distinction of design/verification.md is
10// `predicateType` — inside the signed bytes — rather than a property of
11// where the statement was found.
12//
13// Like the host and event schemas, this file is deliberately not Nix. A
14// statement travels between machines and outlives the tool that wrote it.
15//
16// Validate a statement: cue vet -c schema/attestation.cue <statement>.json
17package attestation
18
19// #Subject identifies what is attested to, as a digest set: several named
20// digests of the same object, under different naming schemes. `primary`
21// names the member that IS the identity, and it is always a
22// content-addressed digest of the tree — which is what makes an
23// attestation survive a rebase, and what binds it to the base the change
24// was produced against (ida-cbcbb3c). Every other member is advisory: a
25// commit hash is useful for finding the change and is never relied on for
26// identity, because identity may not be coupled to git (ida-51605e8).
27#Subject: {
28 // The naming scheme that identifies the subject. Only a
29 // content-addressed tree digest may hold this position; widening it
30 // means adding a second content-addressing scheme, deliberately not
31 // before one exists.
32 primary: "valley-tree-v1"
33
34 // The digests. The primary member must be present — a subject
35 // identified only by advisory members has no identity at all.
36 digest: #DigestSet
37 digest: (primary): _
38}
39
40// #DigestSet is a set of digests of one object, keyed by the scheme that
41// produced them. Closed: an unrecognised scheme is a verifier that cannot
42// check what it was handed, so it fails vet rather than being carried
43// through as an opaque string.
44#DigestSet: {
45 // The valley tree digest, defined in design/verification.md. SHA-256
46 // over a canonical manifest of the tree's entries, so it is a function
47 // of the tree alone: no commit, no author, no time, no path outside
48 // the tree.
49 "valley-tree-v1"?: #Sha256
50
51 // SHA-256 over a canonical manifest of a pure check's input paths,
52 // defined alongside the tree digest.
53 "valley-inputs-v1"?: #Sha256
54
55 // SHA-256 over an object's bytes.
56 sha256?: #Sha256
57
58 // A git object id, advisory only. Both hash algorithms git ships are
59 // admitted, because which one a repository uses is not the
60 // attestation's concern.
61 "git-sha1"?: =~"^[0-9a-f]{40}$"
62 "git-sha256"?: =~"^[0-9a-f]{64}$"
63}
64
65#Sha256: =~"^[0-9a-f]{64}$"
66
67// The two kinds of claim of design/verification.md. A pure check's
68// attestation is re-derivable: it carries input, derivation and output
69// digests, and any verifier can re-run and confirm. An effectful check's
70// attestation is a notarization: a named environment ran the check at a
71// stated time and observed a result, and trust in it is trust in the
72// signer.
73#PredicateType: "the-valley/check/pure/v1" | "the-valley/check/effectful/v1"
74
75// #PureCheck is the re-derivable claim. The three digests are what a
76// verifier re-derives against: it evaluates the same check over the same
77// subject tree, and must arrive at the same derivation and the same
78// output.
79#PureCheck: {
80 check: #CheckRun
81 result: #Result
82
83 // The check's inputs, as the runner named them.
84 inputs: #DigestSet
85
86 // The derivation that was built.
87 derivation: #DigestSet
88
89 // What the build produced.
90 output: #DigestSet
91}
92
93// #EffectfulCheck is the notarization. It carries no re-derivation
94// digests, because there is nothing to re-derive: an effectful check is
95// not bit-reproducible, which is the whole reason it is a separate
96// predicate type.
97#EffectfulCheck: {
98 check: #CheckRun
99 result: #Result
100
101 // The environment the check ran in, named by whoever sealed it. A
102 // verifier can do nothing with this but read it; it is what the
103 // notarization is a notarization *of*.
104 environment: string
105
106 // When the result was observed, RFC 3339 in UTC. Present here and
107 // absent from #PureCheck on purpose: a pure claim that carried a time
108 // would stop being a function of its inputs.
109 observedAt: =~"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
110}
111
112// #CheckRun is the check that ran, named the way the verification policy
113// of schema/verification.cue names it, so the two documents agree on what
114// a check is called.
115#CheckRun: {
116 // The check's name in the project's policy.
117 name: #Name
118
119 // The runner kind. "nix" builds a flake check attribute and claims
120 // purity strongly; "command" runs a command line and claims nothing
121 // beyond having run it.
122 runner: "nix" | "command"
123
124 // The flake check attribute, for the nix runner.
125 attribute?: #Name
126
127 // The command line, for the command runner.
128 command?: string
129
130 if runner == "nix" {
131 attribute: #Name
132 command?: _|_
133 }
134 if runner == "command" {
135 command: string
136 attribute?: _|_
137 }
138}
139
140// A check either passed or it did not. The helper publishes nothing when a
141// check fails, but "failed" is admitted here because a statement that
142// could not record a failure would be a schema that only permits good
143// news.
144#Result: "passed" | "failed"
145
146// #Provenance is the record of the run that produced the tree, carried as
147// content. An agent run holds no key (ida-a8243d2), so none of this is
148// self-asserted: it is attributed inside the host's signed statement
149// (ida-45178f6), and it is true exactly to the extent the host is trusted.
150#Provenance: {
151 // The harness that ran the agent.
152 harness?: string
153
154 // The model the harness drove.
155 model?: string
156
157 // Digests of the prompt and of the context the run was given. Digests
158 // rather than content: the value is committed to by the signature
159 // while the text itself stays wherever it lives.
160 prompt?: #DigestSet
161 context?: #DigestSet
162
163 // The delegation chain, as recorded. Phase 2 records; it does not
164 // check. Verifying a chain belongs to an enforcement point, and the
165 // first one is Phase 3's integrator.
166 delegation?: [...#Delegation]
167}
168
169// #Delegation is one step of a recorded chain: who acted, and what the
170// step conveyed. Both are free strings because no naming scheme for
171// principals has been decided, and pinning one here would decide it.
172#Delegation: {
173 principal: string
174 grant?: string
175}
176
177// Names are lowercase, dash-separated, and short — the same shape as check
178// names in schema/verification.cue and project names in schema/valley.cue.
179#Name: =~"^[a-z0-9][a-z0-9-]*$"
180
181// ----------------------------------------------------------------------
182// The statement.
183//
184// The top level of this package is itself a statement, so a composed
185// statement is validated by vetting it against this file directly. The
186// parts above are definitions; the document they make is here.
187
188// The document kind, versioned. A verifier reads this before anything
189// else, so a future revision can be told apart without guessing.
190statementType: "the-valley/attestation/v1"
191
192// What the statement is about.
193subject: #Subject
194
195// The kind of claim, versioned. The version is part of the name, so a
196// statement says which revision of a claim shape it was written against,
197// and the format can grow without invalidating what already exists.
198predicateType: #PredicateType
199
200// The run that produced the tree, carried as content. Optional, and every
201// field inside it is optional: nothing in the reference implementation
202// collects these values today, so they are caller-supplied or absent
203// rather than invented.
204provenance?: #Provenance
205
206// The claim itself. Its shape follows from the predicate type, and it is
207// constrained only through that type — which is the mechanism that puts
208// the pure-versus-effectful distinction inside the signed bytes. A
209// statement claiming purity cannot omit the digests a verifier re-derives
210// against, and one claiming a notarization cannot smuggle them in.
211if predicateType == "the-valley/check/pure/v1" {
212 predicate: #PureCheck
213}
214if predicateType == "the-valley/check/effectful/v1" {
215 predicate: #EffectfulCheck
216}
217
218// A file's top level cannot be closed (embedding #Statement would open it
219// instead — embedding lifts closedness), so reject stray top-level fields
220// explicitly: anything but the statement's fields — a `predicat:` typo, a
221// carriage concern like `signature:` — conflicts with this sentinel and
222// fails vet with an error naming the field.
223[!="statementType" & !="subject" & !="predicateType" & !="predicate" & !="provenance"]: "INVALID: unknown top-level field; only \"statementType\", \"subject\", \"predicateType\", \"predicate\" and \"provenance\" are allowed"