gunk-dev/the-valley

main.go

sourceef0e6a83672emain's published tip history
4.4 KiB
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 from anybody not in the grants it writes;
9// this program is the step between the document and those three gates.
10package main
11
12import (
13 "fmt"
14 "os"
15)
16
17const usage = `usage: identity <command> [flags]
18
19 compile render the registry at a repository's tip into the artifacts
20 the enforcement boundaries check
21 help print this message
22
23The registry is one declared CUE document in the instance repository
24(dcr-b87f6e8), read from that repository's integrated tip and never from a
25working tree: an edit in a branch or a worktree governs nothing until it
26lands. Three artifacts come out of it.
27
28The known-signers file is every attestation-capable key, written as the
29note format's verifier keys. It is both the integrator's acceptance list
30and any reader's ` + "`attest verify --known-keys`" + `, so it holds every key that
31signs — the integrator's own included. A key's signing name is recorded per
32key, because the note format's key hash binds the name to the key: the same
33key published under a second name is a second, unrelated verifier key.
34
35The authorized_keys file is every key of every principal holding a grant at
36a boundary of kind "git-push", each line tagging its key with the
37principal's name. sshd puts that tag in the environment of the receive-pack
38the pre-receive hook runs under, which is the only thing that can tell one
39pusher from another over a shared git user.
40
41The grants file is every grant the pre-receive hook checks, one line per
42holder: "request <principal>" for each principal holding a grant at a
43boundary of kind "request". The hook takes writes to the integration
44request namespace only from a principal named there.
45
46The registry is read with git's replacement refs off and with no GIT_
47variable or user or system configuration inherited, so the registry
48compiled is the one the tip holds and not an object something else has
49been made to stand in for.
50
51Expiry is enforced here, because a document has no clock. An entry whose
52expiry has arrived is omitted from every artifact and noted on stderr, and
53the rest of the registry still compiles — so access ends at the first
54convergence after expiry.
55
56One state is refused rather than compiled: a registry where, after the
57expiry cut, no remaining principal holds a grant at a boundary of kind
58"registry". Nobody would govern the registry's own stream, so the whole
59render fails with an error naming governanceOrphaned and the last good
60artifacts stand. The rule is here and not in the schema for the same reason
61expiry is — the state is reached by the clock, and a document has none.
62
63A render that fails leaves the last good artifacts exactly as they were.
64All of them are computed in full before any is written, and each is
65replaced by rename. A schema violation, an unreachable repository or a bug
66here costs the compilation and never the git user's access.
67
68flags:
69 --repo DIR the bare instance repository carrying the registry
70 --ref REF the ref whose tip is read (default refs/heads/main)
71 --dir DIR the registry's directory in that tip (default
72 identity)
73 --schema FILE the identity schema (default
74 $VALLEY_IDENTITY_SCHEMA)
75 --known-signers FILE where the verifier keys are written
76 --authorized-keys FILE where the tagged authorized_keys is written
77 --grants FILE where the grants the pre-receive hook checks are
78 written
79 --now YYYY-MM-DD the day expiry is judged against (default: today,
80 UTC)
81`
82
83func main() {
84 if len(os.Args) < 2 {
85 fmt.Fprint(os.Stderr, usage)
86 os.Exit(2)
87 }
88 var err error
89 switch os.Args[1] {
90 case "compile":
91 err = compile(os.Args[2:])
92 case "help", "-h", "--help":
93 fmt.Print(usage)
94 return
95 default:
96 fmt.Fprintf(os.Stderr, "identity: unknown command %q\n\n%s", os.Args[1], usage)
97 os.Exit(2)
98 }
99 if err != nil {
100 fmt.Fprintf(os.Stderr, "identity: %v\n", err)
101 os.Exit(1)
102 }
103}