gunk-dev/the-valley

attestation.cue

source07d67d385df1main's published tip history
10.2 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// #AsciiKey is the key shape a statement's object members are held to:
68// printable ASCII, from space through tilde.
69//
70// This is a property of the signed bytes rather than a naming preference.
71// Canonical form sorts object members by their UTF-8 bytes; RFC 8785 sorts
72// them by UTF-16 code units. The two orderings agree over ASCII and part
73// company above it, so a non-ASCII key is two implementations rendering the
74// same statement into different bytes — and the way that failure surfaces is
75// a signature that does not verify, with nothing naming the key that caused
76// it.
77//
78// Every key in this file is fixed here and is ASCII, so no statement today
79// can carry one. The constraint is written down anyway, because the first
80// map keyed by a caller rather than by this file is where the property
81// silently stops holding.
82#AsciiKey: =~"^[\\x20-\\x7e]*$"
83
84// #AsciiKeyed is how a map with caller-supplied keys is written. Nothing
85// uses it yet: every map the statement carries today — the digest sets, the
86// provenance — is keyed by names this file fixes. The direction that
87// introduces one is the ecosystem-specific key-value context strings of
88// ida-d2dc957, and whatever field carries them unifies with this, so a key
89// the canonical form cannot order fails `cue vet` rather than reaching a
90// signer:
91//
92// context: #AsciiKeyed & {[string]: string}
93#AsciiKeyed: {[#AsciiKey]: _}
94
95// The two kinds of claim of design/verification.md. A pure check's
96// attestation is re-derivable: it carries input, derivation and output
97// digests, and any verifier can re-run and confirm. An effectful check's
98// attestation is a notarization: a named environment ran the check at a
99// stated time and observed a result, and trust in it is trust in the
100// signer.
101#PredicateType: "the-valley/check/pure/v1" | "the-valley/check/effectful/v1"
102
103// #PureCheck is the re-derivable claim. The three digests are what a
104// verifier re-derives against: it evaluates the same check over the same
105// subject tree, and must arrive at the same derivation and the same
106// output.
107#PureCheck: {
108 check: #CheckRun
109 result: #Result
110
111 // The check's inputs, as the runner named them.
112 inputs: #DigestSet
113
114 // The derivation that was built.
115 derivation: #DigestSet
116
117 // What the build produced.
118 output: #DigestSet
119}
120
121// #EffectfulCheck is the notarization. It carries no re-derivation
122// digests, because there is nothing to re-derive: an effectful check is
123// not bit-reproducible, which is the whole reason it is a separate
124// predicate type.
125#EffectfulCheck: {
126 check: #CheckRun
127 result: #Result
128
129 // The environment the check ran in, named by whoever sealed it. A
130 // verifier can do nothing with this but read it; it is what the
131 // notarization is a notarization *of*.
132 environment: string
133
134 // When the result was observed, RFC 3339 in UTC. Present here and
135 // absent from #PureCheck on purpose: a pure claim that carried a time
136 // would stop being a function of its inputs.
137 observedAt: =~"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
138}
139
140// #CheckRun is the check that ran, named the way the verification policy
141// of schema/verification.cue names it, so the two documents agree on what
142// a check is called.
143#CheckRun: {
144 // The check's name in the project's policy.
145 name: #Name
146
147 // The runner kind. "nix" builds a flake check attribute and claims
148 // purity strongly; "command" runs a command line and claims nothing
149 // beyond having run it.
150 runner: "nix" | "command"
151
152 // The flake check attribute, for the nix runner.
153 attribute?: #Name
154
155 // The command line, for the command runner.
156 command?: string
157
158 if runner == "nix" {
159 attribute: #Name
160 command?: _|_
161 }
162 if runner == "command" {
163 command: string
164 attribute?: _|_
165 }
166}
167
168// A check either passed or it did not. The helper publishes nothing when a
169// check fails, but "failed" is admitted here because a statement that
170// could not record a failure would be a schema that only permits good
171// news.
172#Result: "passed" | "failed"
173
174// #Provenance is the record of the run that produced the tree, carried as
175// content. An agent run holds no key (ida-a8243d2), so none of this is
176// self-asserted: it is attributed inside the host's signed statement
177// (ida-45178f6), and it is true exactly to the extent the host is trusted.
178#Provenance: {
179 // The harness that ran the agent.
180 harness?: string
181
182 // The model the harness drove.
183 model?: string
184
185 // Digests of the prompt and of the context the run was given. Digests
186 // rather than content: the value is committed to by the signature
187 // while the text itself stays wherever it lives.
188 prompt?: #DigestSet
189 context?: #DigestSet
190
191 // The delegation chain, as recorded. Phase 2 records; it does not
192 // check. Verifying a chain belongs to an enforcement point, and the
193 // first one is Phase 3's integrator.
194 delegation?: [...#Delegation]
195}
196
197// #Delegation is one step of a recorded chain: who acted, and what the
198// step conveyed. Both are free strings because no naming scheme for
199// principals has been decided, and pinning one here would decide it.
200#Delegation: {
201 principal: string
202 grant?: string
203}
204
205// Names are lowercase, dash-separated, and short — the same shape as check
206// names in schema/verification.cue and project names in schema/valley.cue.
207#Name: =~"^[a-z0-9][a-z0-9-]*$"
208
209// ----------------------------------------------------------------------
210// The statement.
211//
212// The top level of this package is itself a statement, so a composed
213// statement is validated by vetting it against this file directly. The
214// parts above are definitions; the document they make is here.
215
216// The document kind, versioned. A verifier reads this before anything
217// else, so a future revision can be told apart without guessing.
218statementType: "the-valley/attestation/v1"
219
220// What the statement is about.
221subject: #Subject
222
223// The kind of claim, versioned. The version is part of the name, so a
224// statement says which revision of a claim shape it was written against,
225// and the format can grow without invalidating what already exists.
226predicateType: #PredicateType
227
228// The run that produced the tree, carried as content. Optional, and every
229// field inside it is optional: nothing in the reference implementation
230// collects these values today, so they are caller-supplied or absent
231// rather than invented.
232provenance?: #Provenance
233
234// The claim itself. Its shape follows from the predicate type, and it is
235// constrained only through that type — which is the mechanism that puts
236// the pure-versus-effectful distinction inside the signed bytes. A
237// statement claiming purity cannot omit the digests a verifier re-derives
238// against, and one claiming a notarization cannot smuggle them in.
239if predicateType == "the-valley/check/pure/v1" {
240 predicate: #PureCheck
241}
242if predicateType == "the-valley/check/effectful/v1" {
243 predicate: #EffectfulCheck
244}
245
246// A file's top level cannot be closed (embedding #Statement would open it
247// instead — embedding lifts closedness), so reject stray top-level fields
248// explicitly: anything but the statement's fields — a `predicat:` typo, a
249// carriage concern like `signature:` — conflicts with this sentinel and
250// fails vet with an error naming the field.
251[!="statementType" & !="subject" & !="predicateType" & !="predicate" & !="provenance"]: "INVALID: unknown top-level field; only \"statementType\", \"subject\", \"predicateType\", \"predicate\" and \"provenance\" are allowed"