| 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 |
| 24 | package 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 tree the evidence was produced over — the base the |
| 178 | // contributor's attestations bind to (ida-cbcbb3c). The subject is |
| 179 | // the tree that landed; when the two are equal, nothing intervened. |
| 180 | base: #DigestSet |
| 181 | |
| 182 | // The policy the verdict was derived under, resolved from the |
| 183 | // integrator's own checkout at the target tip and never from the |
| 184 | // submitted tree (bd-eaefe82). The advisory git member says which tip |
| 185 | // that was; the content digest is what pins the composed document. |
| 186 | policy: #DigestSet |
| 187 | |
| 188 | // What the policy required of this change, written one of two ways, |
| 189 | // and never both. |
| 190 | // |
| 191 | // `checks` carries one entry per required check, in the order the |
| 192 | // integrator judged them. It is never empty: a value has a written |
| 193 | // form only if it has lines, and an array with no elements has none, |
| 194 | // so an empty list is a statement that cannot be signed. |
| 195 | // |
| 196 | // `required: "none"` is the zero case said out loud. A policy that |
| 197 | // requires nothing of a diff is an ordinary outcome — every path the |
| 198 | // diff touches is covered by a class that asks for nothing, or the |
| 199 | // diff touches no path at all — and the change lands on that basis. |
| 200 | // Absence carries the claim here rather than an empty container, |
| 201 | // which is the same absent-versus-empty rule the rest of the form |
| 202 | // keeps: a field a statement does not carry is left out, and what is |
| 203 | // left out is stated by the field beside it rather than inferred from |
| 204 | // a missing line. |
| 205 | { |
| 206 | checks: [#CheckTransfer, ...#CheckTransfer] |
| 207 | required?: _|_ |
| 208 | } | { |
| 209 | required: "none" |
| 210 | checks?: _|_ |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | // #CheckTransfer is one check's verdict at the commit point. Only |
| 215 | // transferred checks are recorded: a statement carrying an invalidated one |
| 216 | // would be a statement about a change that did not land. |
| 217 | #CheckTransfer: { |
| 218 | // The check's name in the project's policy. |
| 219 | name: #Name |
| 220 | |
| 221 | // How it transferred. "closure" is the pure rule — the input-closure |
| 222 | // digest recomputed on the landed tree equalled the attested one. |
| 223 | // "untouched" is the effectful rule — no intervening landing touched |
| 224 | // the requiring class's paths, and the observation was inside the |
| 225 | // declared window. "unmoved" is neither rule needing to run, because |
| 226 | // the landed tree is the attested tree. |
| 227 | rule: "closure" | "untouched" | "unmoved" |
| 228 | |
| 229 | // The statement this verdict is about, cited by a digest of the |
| 230 | // bytes a signature covers. |
| 231 | evidence: #DigestSet |
| 232 | |
| 233 | // The input closure recomputed on the landed tree, for the closure |
| 234 | // rule. Equal to the attested statement's `inputs` by construction: |
| 235 | // an unequal one is not a transfer and is not written down. |
| 236 | inputs?: #DigestSet |
| 237 | } |
| 238 | |
| 239 | // #CheckRun is the check that ran, named the way the verification policy |
| 240 | // of schema/verification.cue names it, so the two documents agree on what |
| 241 | // a check is called. |
| 242 | #CheckRun: { |
| 243 | // The check's name in the project's policy. |
| 244 | name: #Name |
| 245 | |
| 246 | // The runner kind. "nix" builds a flake check attribute and claims |
| 247 | // purity strongly; "command" runs a command line and claims nothing |
| 248 | // beyond having run it. |
| 249 | runner: "nix" | "command" |
| 250 | |
| 251 | // The flake check attribute, for the nix runner. |
| 252 | attribute?: #Name |
| 253 | |
| 254 | // The command line, for the command runner. One line: a check whose |
| 255 | // command spans several has no written form, so it is refused here |
| 256 | // rather than in a renderer after the check has run. |
| 257 | command?: #Line |
| 258 | |
| 259 | if runner == "nix" { |
| 260 | attribute: #Name |
| 261 | command?: _|_ |
| 262 | } |
| 263 | if runner == "command" { |
| 264 | command: #Line |
| 265 | attribute?: _|_ |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | // A check either passed or it did not. The helper publishes nothing when a |
| 270 | // check fails, but "failed" is admitted here because a statement that |
| 271 | // could not record a failure would be a schema that only permits good |
| 272 | // news. |
| 273 | #Result: "passed" | "failed" |
| 274 | |
| 275 | // #Provenance is the record of the run that produced the tree, carried as |
| 276 | // content. An agent run holds no key (ida-a8243d2), so none of this is |
| 277 | // self-asserted: it is attributed inside the host's signed statement |
| 278 | // (ida-45178f6), and it is true exactly to the extent the host is trusted. |
| 279 | #Provenance: { |
| 280 | // The harness that ran the agent. |
| 281 | harness?: #Line |
| 282 | |
| 283 | // The model the harness drove. |
| 284 | model?: #Line |
| 285 | |
| 286 | // Digests of the prompt and of the context the run was given. Digests |
| 287 | // rather than content: the value is committed to by the signature |
| 288 | // while the text itself stays wherever it lives. |
| 289 | prompt?: #DigestSet |
| 290 | context?: #DigestSet |
| 291 | |
| 292 | // The delegation chain, as recorded. Phase 2 records; it does not |
| 293 | // check. Verifying a chain belongs to an enforcement point, and the |
| 294 | // first one is Phase 3's integrator. |
| 295 | delegation?: [...#Delegation] |
| 296 | } |
| 297 | |
| 298 | // #Delegation is one step of a recorded chain: who acted, and what the |
| 299 | // step conveyed. Both are free strings because no naming scheme for |
| 300 | // principals has been decided, and pinning one here would decide it. |
| 301 | #Delegation: { |
| 302 | principal: #Line |
| 303 | grant?: #Line |
| 304 | } |
| 305 | |
| 306 | // Names are lowercase, dash-separated, and short — the same shape as check |
| 307 | // names in schema/verification.cue and project names in schema/valley.cue. |
| 308 | #Name: =~"^[a-z0-9][a-z0-9-]*$" |
| 309 | |
| 310 | // ---------------------------------------------------------------------- |
| 311 | // The statement. |
| 312 | // |
| 313 | // The top level of this package is itself a statement, so a composed |
| 314 | // statement is validated by vetting it against this file directly. The |
| 315 | // parts above are definitions; the document they make is here. |
| 316 | |
| 317 | // The document kind, versioned. A verifier reads this before anything |
| 318 | // else, so a future revision can be told apart without guessing. |
| 319 | statementType: "the-valley/attestation/v1" |
| 320 | |
| 321 | // What the statement is about. |
| 322 | subject: #Subject |
| 323 | |
| 324 | // The kind of claim, versioned. The version is part of the name, so a |
| 325 | // statement says which revision of a claim shape it was written against, |
| 326 | // and the format can grow without invalidating what already exists. |
| 327 | predicateType: #PredicateType |
| 328 | |
| 329 | // The run that produced the tree, carried as content. Optional, and every |
| 330 | // field inside it is optional: nothing in the reference implementation |
| 331 | // collects these values today, so they are caller-supplied or absent |
| 332 | // rather than invented. |
| 333 | provenance?: #Provenance |
| 334 | |
| 335 | // The claim itself. Its shape follows from the predicate type, and it is |
| 336 | // constrained only through that type — which is the mechanism that puts |
| 337 | // the pure-versus-effectful distinction inside the signed bytes. A |
| 338 | // statement claiming purity cannot omit the digests a verifier re-derives |
| 339 | // against, and one claiming a notarization cannot smuggle them in. |
| 340 | if predicateType == "the-valley/check/pure/v1" { |
| 341 | predicate: #PureCheck |
| 342 | } |
| 343 | if predicateType == "the-valley/check/effectful/v1" { |
| 344 | predicate: #EffectfulCheck |
| 345 | } |
| 346 | if predicateType == "the-valley/integration/transfer/v1" { |
| 347 | predicate: #Transfer |
| 348 | } |
| 349 | |
| 350 | // A file's top level cannot be closed (embedding #Statement would open it |
| 351 | // instead — embedding lifts closedness), so reject stray top-level fields |
| 352 | // explicitly: anything but the statement's fields — a `predicat:` typo, a |
| 353 | // carriage concern like `signature:` — conflicts with this sentinel and |
| 354 | // fails vet with an error naming the field. |
| 355 | [!="statementType" & !="subject" & !="predicateType" & !="predicate" & !="provenance"]: "INVALID: unknown top-level field; only \"statementType\", \"subject\", \"predicateType\", \"predicate\" and \"provenance\" are allowed" |