| 1 | // A project's consent to read access: who the project lets read it. |
| 2 | // |
| 3 | // Read access is a grant to a principal, and it takes two consents. A |
| 4 | // project names its readers here, in policy/read/ on its main. The |
| 5 | // instance's identity registry (schema/identity.cue) grants each reader read |
| 6 | // at an edge read boundary, for this project or for every project. A |
| 7 | // principal reads a project only where both say so. The reader `anyone` is |
| 8 | // the reader who presents no credential: a project is public where both |
| 9 | // consents let `anyone` read it. |
| 10 | // |
| 11 | // Every reader is named, the operator included. A project the operator |
| 12 | // reads names the operator here, as it names any other reader. Membership, |
| 13 | // push access and approval give no read access. |
| 14 | // |
| 15 | // The policy names the project it is for, and the project's publication |
| 16 | // identity. A policy read from another project grants nothing there. An |
| 17 | // instance grant that names this project names this identity too, so a new |
| 18 | // project that reuses the name does not inherit the old project's grants. |
| 19 | // |
| 20 | // The policy lives in policy/read/, beside and not inside policy/instance/ |
| 21 | // and policy/project/. Those two directories are verification-policy |
| 22 | // layers, which schema/verification.cue closes to its own fields. |
| 23 | // |
| 24 | // Validate a policy: |
| 25 | // cue vet -c schema/read.cue policy/read/*.cue |
| 26 | package read |
| 27 | |
| 28 | import "strings" |
| 29 | |
| 30 | // project is the name of the project this policy is for: the name the |
| 31 | // instance lists it under. |
| 32 | project!: #ProjectName |
| 33 | |
| 34 | // identity is the project's publication identity: 32 lowercase hex digits, |
| 35 | // chosen at random when the project's policy/read is first written, and |
| 36 | // never changed. |
| 37 | identity!: #Identity |
| 38 | |
| 39 | // readers is the set of principals the project lets read it. An empty set |
| 40 | // lets no one read. close keeps out a key that does not match #Principal: |
| 41 | // a pattern constrains only the keys it matches, and a struct that is not |
| 42 | // closed takes any other key unconstrained. |
| 43 | readers!: close({[#Principal]: true}) |
| 44 | |
| 45 | // #ProjectName is a project's name, as schema/valley.cue names projects. |
| 46 | #ProjectName: =~"^[a-zA-Z0-9][a-zA-Z0-9._-]*$" & strings.MaxRunes(64) |
| 47 | |
| 48 | // #Identity is a publication identity. |
| 49 | #Identity: =~"^[0-9a-f]{32}$" |
| 50 | |
| 51 | // #Principal is a principal's name, as schema/identity.cue names |
| 52 | // principals. `anyone` is the reader who presents no credential. |
| 53 | #Principal: =~"^[a-zA-Z0-9][a-zA-Z0-9._-]*$" |
| 54 | |
| 55 | // A file's top level cannot be closed, so a stray top-level field, such as |
| 56 | // a `reader:` typo, conflicts with this sentinel and fails vet with an |
| 57 | // error naming the field. |
| 58 | [!="project" & !="identity" & !="readers"]: "INVALID: unknown top-level field; only \"project\", \"identity\" and \"readers\" are allowed" |