gunk-dev/the-valley

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

source818813f26b40main's published tip history
6.8 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, every note about that tree and signed under that key hash. Where
44 the host names the keys a controller accepts, the signature must verify under one of them.
45- An integration request takes the request grant, whoever else the project's protection names.
46- Every other ref, tags included, takes a named grant of the project, which names the principals it
47 opens a pattern to.
48- A protected ref also takes a declared writer.
49
50The request grant is a boundary kind in the identity schema, `"request"`. The compiler writes each
51holder into a grants file the hook reads. A host can also grant it by hand, and the two add up. The
52hand grant matters the first time: the hook refuses the request that would land the registry change
53granting request, unless the host already grants it to whoever files that change.
54
55Replacement refs are also turned off wherever git is read for a decision: in the identity compiler,
56in `attest` (so a standalone `attest verify` too), in the integrator and every program it runs, and
57in the `valley` CLI. Each one also drops the inherited `GIT_*` variables that could point git at
58other objects. A replacement ref already on a host is therefore inert, and valley-init reports any
59it finds on every activation without deleting it.
60
61Three things around the hook could still have bypassed it, and each is refused. A pre-receive hook
62the module did not write, or a `core.hooksPath` from any scope, would run instead of the policy, so
63valley-init fails the activation over either; a project that wants a hook of its own composes it
64after the policy, where it can only refuse more. The instance repository must declare protection of
65the ref the floor and the registry are read from. And sshd is held to the one way a principal
66arrives: the tag on the key's own entry. The module refuses an sshd that accepts the principal
67variable from the client, sets it itself, or reads more of the user's environment than that one
68variable. It also refuses a key declared under two tags. The git user's keys come only from the
69declared and compiled files, and valley-init refuses a `~/.ssh/environment` in its home.
70
71## What remains
72
73The hook does not check that an attestation's signer is the principal pushing it. The signer and the
74pusher are routinely different principals. A host's own key signs the claims `attest run` makes on
75it, and the operator's key pushes them. On a host that names no verifier keys, the hook checks what
76a note claims about its signer and not the signature, so a name there can still be taken by a note
77claiming a signer it was not signed by.
78
79The request namespace does not record who filed a request. Any holder of the grant can therefore
80replace or withdraw any request, not only its own. The grant is the boundary: who holds request is
81decided in the registry, and the registry is governed.
82
83## Rolling it out
84
85The order matters, because the hook refuses the very request that lands a registry change.
86
871. Check that every key the host declares by hand that acts for a principal is tagged with it. An
88 untagged entry for a key the registry also holds wins in sshd and pushes as nobody, and the
89 compiler now refuses that registry rather than compile a grant that would never apply.
902. Declare `services.valley.grants.request` for whoever files the registry change, and protect the
91 instance repository's main. Then deploy.
923. Resolve whatever valley-init refuses: a hand-written pre-receive hook, a `core.hooksPath`, a
93 `~/.ssh/environment` in the git user's home. Read the replacement refs it reports before deleting
94 them.
954. Before the integrator runs again, audit the integration-request queue. The requests already there
96 were filed before anything checked who filed them, and a request records no filer. Where a
97 request's origin is in doubt, withdraw it and have it filed again by a principal holding the
98 grant.
995. Land the registry change granting request, and check that the compiled grants file names the
100 holders. Then check that a push from a holder's own key is accepted, with the tag the compiled
101 file gives it.
1026. Only then remove the hand grant.
103
104## Related
105
106- [[dcr-e544f20]]
107 ([decisions/dcr-e544f20-access-is-verbs-on-projects.md](../decisions/dcr-e544f20-access-is-verbs-on-projects.md))
108 — the request verb, whose gate this ships.
109- [[dcr-b87f6e8]]
110 ([decisions/dcr-b87f6e8-identity-is-a-governed-registry.md](../decisions/dcr-b87f6e8-identity-is-a-governed-registry.md))
111 — the registry the grant compiles from, and the boundary rule it follows.