gunk-dev/the-valley

bd-75c8721-pushes-could-write-any-namespace.md

sourcefe48b06af1c9main's published tip history
8.7 KiB · Rendered
1---
2type: bug
3id: bd-75c8721
4status: closed
5title: A push could write any namespace the hook did not name, replacement refs included
6created: 2026-10-04
7source: adversarial review of the push boundary, 2026-10-04
8---
9
10# A push could write any namespace the hook did not name
11
12The pre-receive hook guarded two things: protected refs, and the create-only attestation namespace.
13Every other ref was open to any key that could push. Two of those open namespaces were holes.
14
15The first was `refs/replace/*`. A replacement ref makes git read one object in place of another,
16wherever git looks the first one up. git honours replacement refs by default. The identity compiler
17read the registry from the instance repository's tip with plain `git ls-tree` and `git show`, and
18the integrator read the floor, the project's policy and a change's tree the same way. So a pushed
19`refs/replace/<blob>` could swap in a registry that authorized any key as anything, or a floor that
20required nothing, without moving a ref anyone watches. Every reader would have agreed on the forged
21content, because every reader asks git the same question.
22
23The second was the integration-request namespace. [[dcr-e544f20]]
24([decisions/dcr-e544f20-access-is-verbs-on-projects.md](../decisions/dcr-e544f20-access-is-verbs-on-projects.md))
25defines a request verb whose gate is a check of namespace writes against the principals holding it.
26No such check existed, so any key that could push could ask for anything to land. Who may file
27requests is the human gate on a valley whose floor demands approval statements, so the verb had to
28ship with its gate.
29
30## The resolution
31
32The hook's rules are one Go program, [valleyhook/](../../../valleyhook/). It runs on every project a
33host serves, protected or not, and the hook a host installs only hands it the pushing principal, the
34project's declared push policy, the grants, and the keys attestations are checked against. A write
35must pass every rule that applies to its ref, and no rule stands in for another:
36
37- Replacement refs, notes, and the valley's namespace other than attestations and integration
38 requests take no push, whatever a declaration says.
39- A ref that is symbolic in the repository takes no push, because git would write the ref it points
40 at.
41- Topic branches are open.
42- An attestation ref may only be created. Its name must be exactly `<tree digest>/<key hash>`. It
43 must point at a tree of notes, read one object at a time within fixed bounds on depth, entries,
44 and bytes, each checked before anything past it is read. Every note must open under the keys a
45 controller here accepts, the way a verifier opens it, be about that tree, and carry a verified
46 signature under that key hash. A host that names no such keys accepts no attestation.
47- An integration request takes the request grant, whoever else the project's protection names.
48- Every other ref, tags included, takes a named grant of the project, which names the principals it
49 opens a pattern to.
50- A protected ref also takes a declared writer.
51
52The request grant is a boundary kind in the identity schema, `"request"`. The compiler writes each
53holder into a grants file the hook reads. A host can also grant it by hand, and the two add up. The
54hand grant matters the first time: the hook refuses the request that would land the registry change
55granting request, unless the host already grants it to whoever files that change.
56
57The note envelope has one reading, the note module ([note/](../../../note/)), which `attest` signs
58and verifies with and the hook checks pushed notes with. A relayer can change a note's signature
59block and nothing else, and every line it could add that one reader refuses, every reader refuses.
60So a note the hook lets into the create-only namespace is a note every verifier opens.
61
62Replacement refs are also turned off wherever git is read for a decision: in the identity compiler,
63in `attest` (so a standalone `attest verify` too), in the integrator and every program it runs, and
64in the `valley` CLI. Each one also drops the inherited `GIT_*` variables that could point git at
65other objects. A replacement ref already on a host is therefore inert, and valley-init reports any
66it finds on every activation without deleting it.
67
68Things around the hook could still have bypassed it, and each is closed.
69
70A pre-receive hook the module did not write, or a `core.hooksPath` set at any scope, to an empty
71value included, would run instead of the policy. valley-init fails the activation over either, and a
72project that wants a hook of its own composes it after the policy, where it can only refuse more.
73
74A failed activation leaves no write path open. The git user's login shell is the valley's
75(`valleyhook shell`), and it refuses every push until valley-init has recorded that it converged on
76the configuration the shell was rendered with. valley-init removes that record before anything else
77it does and writes it last. The operator can also hold pushes with a file valley-init never touches.
78Fetches stay open.
79
80The principal arrives one way. The shell reads the key sshd authenticated, finds that key's entry in
81the files sshd authorized it from, and takes the tag on it. A principal or any `GIT_*` variable the
82session arrived with is dropped, so a misconfigured sshd that passes client environment through
83still names nobody and sets nothing git reads. The module also refuses such an sshd outright: an
84`AcceptEnv` or `SetEnv` that could admit the principal or a `GIT_*` variable, in any Match block,
85with the keyword in any case, and any `PermitUserEnvironment` but `no`. It refuses a key declared
86under two tags, and the git user's keys come only from the declared and compiled files.
87
88The instance repository must declare protection of the ref the floor and the registry are read from.
89
90## What remains
91
92The hook does not check that an attestation's signer is the principal pushing it. The signer and the
93pusher are routinely different principals. A host's own key signs the claims `attest run` makes on
94it, and the operator's key pushes them.
95
96The request namespace does not record who filed a request. Any holder of the grant can therefore
97replace or withdraw any request, not only its own. The grant is the boundary: who holds request is
98decided in the registry, and the registry is governed.
99
100## Rolling it out
101
102The order matters, because the hook refuses the very request that lands a registry change, and
103because requests already queued were filed before anything checked who filed them.
104
1051. Tag every key the host declares by hand that acts for a principal. An untagged entry for a key
106 the registry also holds is read first and pushes as nobody, and the compiler refuses that
107 registry rather than compile a grant that would never apply.
1082. Declare `services.valley.grants.request` for whoever files the registry change, and protect the
109 instance repository's main.
1103. Build the new system before switching to it, and list the integrators it defines, including any
111 for a project this deployment newly protects.
1124. Before the switch, block git logins without touching sshd, by giving the git user a shell that
113 refuses every session, and drain the git sessions already running. Hold pushes with the
114 operator's hold file. Mask and stop every integrator, those running now and those the new system
115 defines. Then deploy. The switch restores the valley's shell, which honours the hold through
116 valley-init's convergence until the audits below are done. After the switch, list the integrators
117 from the running system's unit files and confirm each is masked and inactive. Resolve whatever
118 valley-init refuses: a hand-written pre-receive hook, a `core.hooksPath`. Read the replacement
119 refs it reports before deleting them.
1205. Audit the integration-request queue. A request records no filer. Where a request's origin is in
121 doubt, withdraw it, to be filed again by a principal holding the grant.
1226. Release the hold, then start the integrators again.
1237. Land the registry change granting request. Keep the hand grant until the compiled grants file
124 names the holders and a request filed from a holder's own key is accepted.
1258. Remove the hand grant, deploy, and file a request from the holder's key once more.
126
127A protected project that moves onto the valley afterwards gets its first `main` by a seed on the
128host ([integration.md](../../design/integration.md), _A protected stream starts from a seed_).
129
130## Related
131
132- [[dcr-e544f20]]
133 ([decisions/dcr-e544f20-access-is-verbs-on-projects.md](../decisions/dcr-e544f20-access-is-verbs-on-projects.md))
134 — the request verb, whose gate this ships.
135- [[dcr-b87f6e8]]
136 ([decisions/dcr-b87f6e8-identity-is-a-governed-registry.md](../decisions/dcr-b87f6e8-identity-is-a-governed-registry.md))
137 — the registry the grant compiles from, and the boundary rule it follows.