| 1 | // identity compiles a valley instance's identity registry — the declared |
| 2 | // CUE document naming who the instance grants something to (dcr-b87f6e8) — |
| 3 | // into the artifacts its enforcement boundaries check. |
| 4 | // |
| 5 | // It renders, and enforces nothing itself. sshd refuses a key that is not |
| 6 | // in the authorized_keys it writes, the integrator refuses evidence signed |
| 7 | // by nobody in the known-signers it writes, and the pre-receive hook |
| 8 | // refuses an integration request or a restack write from anybody not in |
| 9 | // the grants it writes; this program is the step between the document and |
| 10 | // those three gates. It also writes the two approval signers files, which |
| 11 | // no gate reads. |
| 12 | package main |
| 13 | |
| 14 | import ( |
| 15 | "fmt" |
| 16 | "os" |
| 17 | ) |
| 18 | |
| 19 | const usage = `usage: identity <command> [flags] |
| 20 | |
| 21 | compile render the registry at a repository's tip into the artifacts |
| 22 | the enforcement boundaries check |
| 23 | help print this message |
| 24 | |
| 25 | The registry is one declared CUE document in the instance repository |
| 26 | (dcr-b87f6e8), read from that repository's integrated tip and never from a |
| 27 | working tree: an edit in a branch or a worktree governs nothing until it |
| 28 | lands. Three artifacts come out of it, and two approval signers files when |
| 29 | asked for. |
| 30 | |
| 31 | The known-signers file is every attestation-capable key, written as the |
| 32 | note format's verifier keys. It is both the integrator's acceptance list |
| 33 | and any reader's ` + "`attest verify --known-keys`" + `, so it holds every key that |
| 34 | signs — the integrator's own included. A key's signing name is recorded per |
| 35 | key, because the note format's key hash binds the name to the key: the same |
| 36 | key published under a second name is a second, unrelated verifier key. |
| 37 | |
| 38 | The authorized_keys file is every key of every principal holding a grant at |
| 39 | a boundary of kind "git-push", each line tagging its key with the |
| 40 | principal's name. The git user's shell reads the tag off the entry of the |
| 41 | key sshd authenticated and hands it to the pre-receive hook, which is the |
| 42 | only thing that can tell one pusher from another over a shared git user. |
| 43 | |
| 44 | The grants file is every grant the pre-receive hook checks, one line per |
| 45 | holder: "request <principal>" for each principal holding the approve grant, |
| 46 | at a boundary of kind "approve" or of kind "request", and "restack |
| 47 | <principal>" for each holding one at a boundary of kind "restack". The two |
| 48 | kinds are one grant: the approve grant, also accepted as request. A |
| 49 | principal holding both is written once, and a registry using either kind |
| 50 | compiles the same file. The hook takes writes to the integration request |
| 51 | namespace only from a holder of the approve grant. It takes a version |
| 52 | added to another principal's ready change, and a restack report, only from |
| 53 | one named under restack. |
| 54 | |
| 55 | The two approval signers files hold the keys whose signed approvals |
| 56 | count. They are written as the note format's verifier keys, and each line |
| 57 | is named by the principal who approves with its key. No gate reads them. |
| 58 | |
| 59 | approval-signers lists every key of every unexpired human holding the |
| 60 | approve grant. approval-signers-hardware lists the keys from it whose |
| 61 | entry carries a YubiKey attestation that verifies and whose touch policy |
| 62 | is always: the YubiKey asks for a touch before every signature. |
| 63 | |
| 64 | An attestation is two PEM certificates: the one the YubiKey wrote for the |
| 65 | PIV slot holding the key, and the YubiKey's own f9 certificate, which |
| 66 | signed it. It verifies when the slot certificate chains through the f9 |
| 67 | certificate and Yubico's PIV intermediates to Yubico Attestation Root 1, |
| 68 | and the key it names is the entry's public key. This program carries that |
| 69 | root and those intermediates, and a registry cannot add others. An |
| 70 | attestation that does not verify fails the render. So does one stating a |
| 71 | PIN or touch policy other than the values Yubico specifies: 1, 2 and 3. |
| 72 | Each attestation that verifies is reported on stderr with the YubiKey's |
| 73 | serial number, firmware, PIN policy and touch policy, for whoever reviews |
| 74 | the enrollment. |
| 75 | |
| 76 | A key that approves belongs to one principal: one also listed under |
| 77 | another principal fails the render. |
| 78 | |
| 79 | The registry is read with git's replacement refs off and with no GIT_ |
| 80 | variable or user or system configuration inherited, so the registry |
| 81 | compiled is the one the tip holds and not an object something else has |
| 82 | been made to stand in for. |
| 83 | |
| 84 | Every key of the registry's export is read spelled exactly as the schema |
| 85 | spells its field. A key the schema does not give fails the render, and so |
| 86 | does a key that appears twice in one object. A registry may reopen a |
| 87 | schema definition and add a field to it, such as Grants beside grants, and |
| 88 | Go's JSON decoder alone would read that field as grants. |
| 89 | |
| 90 | Expiry is enforced here, because a document has no clock. An entry whose |
| 91 | expiry has arrived is omitted from every artifact and noted on stderr, and |
| 92 | the rest of the registry still compiles — so access ends at the first |
| 93 | convergence after expiry. |
| 94 | |
| 95 | One key authorized as two principals is refused too, whether both entries |
| 96 | are the registry's or one is the host's own (--declared-keys). sshd |
| 97 | authorizes a key by the first entry that names it, so which principal such |
| 98 | a key pushes as would depend on the order of lines and files. |
| 99 | |
| 100 | One state is refused rather than compiled: a registry where, after the |
| 101 | expiry cut, no remaining principal holds a grant at a boundary of kind |
| 102 | "registry". Nobody would govern the registry's own stream, so the whole |
| 103 | render fails with an error naming governanceOrphaned and the last good |
| 104 | artifacts stand. The rule is here and not in the schema for the same reason |
| 105 | expiry is — the state is reached by the clock, and a document has none. |
| 106 | |
| 107 | A render that fails leaves the last good artifacts exactly as they were. |
| 108 | All of them are computed in full before any is written, and each is |
| 109 | replaced by rename. A schema violation, an unreachable repository or a bug |
| 110 | here costs the compilation and never the git user's access. |
| 111 | |
| 112 | flags: |
| 113 | --repo DIR the bare instance repository carrying the registry |
| 114 | --ref REF the ref whose tip is read (default refs/heads/main) |
| 115 | --dir DIR the registry's directory in that tip (default |
| 116 | identity) |
| 117 | --schema FILE the identity schema (default |
| 118 | $VALLEY_IDENTITY_SCHEMA) |
| 119 | --known-signers FILE where the verifier keys are written |
| 120 | --authorized-keys FILE where the tagged authorized_keys is written |
| 121 | --grants FILE where the grants the pre-receive hook checks are |
| 122 | written |
| 123 | --approval-signers FILE |
| 124 | where the verifier keys of every approval key are |
| 125 | written. None is written without it. |
| 126 | --approval-signers-hardware FILE |
| 127 | where the verifier keys of the hardware approval |
| 128 | keys are written. None is written without it. |
| 129 | --declared-keys FILE the authorized_keys lines the host declares by |
| 130 | hand. A registry key that is also declared under |
| 131 | another tag, or untagged, fails the render: sshd |
| 132 | reads the declared entry first, so the key would |
| 133 | never push as its registry principal. |
| 134 | --now YYYY-MM-DD the day expiry, and the validity of an |
| 135 | attestation's certificates, are judged against |
| 136 | (default: today, UTC) |
| 137 | ` |
| 138 | |
| 139 | func main() { |
| 140 | if len(os.Args) < 2 { |
| 141 | fmt.Fprint(os.Stderr, usage) |
| 142 | os.Exit(2) |
| 143 | } |
| 144 | var err error |
| 145 | switch os.Args[1] { |
| 146 | case "compile": |
| 147 | err = compile(os.Args[2:]) |
| 148 | case "help", "-h", "--help": |
| 149 | fmt.Print(usage) |
| 150 | return |
| 151 | default: |
| 152 | fmt.Fprintf(os.Stderr, "identity: unknown command %q\n\n%s", os.Args[1], usage) |
| 153 | os.Exit(2) |
| 154 | } |
| 155 | if err != nil { |
| 156 | fmt.Fprintf(os.Stderr, "identity: %v\n", err) |
| 157 | os.Exit(1) |
| 158 | } |
| 159 | } |