| 1 | --- |
| 2 | type: bug |
| 3 | id: bd-75c8721 |
| 4 | status: closed |
| 5 | title: A push could write any namespace the hook did not name, replacement refs included |
| 6 | created: 2026-10-04 |
| 7 | source: adversarial review of the push boundary, 2026-10-04 |
| 8 | --- |
| 9 | |
| 10 | # A push could write any namespace the hook did not name |
| 11 | |
| 12 | The pre-receive hook guarded two things: protected refs, and the create-only attestation namespace. |
| 13 | Every other ref was open to any key that could push. Two of those open namespaces were holes. |
| 14 | |
| 15 | The first was `refs/replace/*`. A replacement ref makes git read one object in place of another, |
| 16 | wherever git looks the first one up. git honours replacement refs by default. The identity compiler |
| 17 | read the registry from the instance repository's tip with plain `git ls-tree` and `git show`, and |
| 18 | the 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 |
| 20 | required nothing, without moving a ref anyone watches. Every reader would have agreed on the forged |
| 21 | content, because every reader asks git the same question. |
| 22 | |
| 23 | The 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)) |
| 25 | defines a request verb whose gate is a check of namespace writes against the principals holding it. |
| 26 | No such check existed, so any key that could push could ask for anything to land. Who may file |
| 27 | requests is the human gate on a valley whose floor demands approval statements, so the verb had to |
| 28 | ship with its gate. |
| 29 | |
| 30 | ## The resolution |
| 31 | |
| 32 | The hook's rules are one Go program, [valleyhook/](../../valleyhook/). It runs on every project a |
| 33 | host serves, protected or not, and the hook a host installs only hands it the pushing principal, the |
| 34 | project's declared push policy, the grants, and the keys attestations are checked against. A write |
| 35 | must 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 | |
| 52 | The request grant is a boundary kind in the identity schema, `"request"`. The compiler writes each |
| 53 | holder into a grants file the hook reads. A host can also grant it by hand, and the two add up. The |
| 54 | hand grant matters the first time: the hook refuses the request that would land the registry change |
| 55 | granting request, unless the host already grants it to whoever files that change. |
| 56 | |
| 57 | The note envelope has one reading, the note module ([note/](../../note/)), which `attest` signs and |
| 58 | verifies with and the hook checks pushed notes with. A relayer can change a note's signature block |
| 59 | and nothing else, and every line it could add that one reader refuses, every reader refuses. So a |
| 60 | note the hook lets into the create-only namespace is a note every verifier opens. |
| 61 | |
| 62 | Replacement refs are also turned off wherever git is read for a decision: in the identity compiler, |
| 63 | in `attest` (so a standalone `attest verify` too), in the integrator and every program it runs, and |
| 64 | in the `valley` CLI. Each one also drops the inherited `GIT_*` variables that could point git at |
| 65 | other objects. A replacement ref already on a host is therefore inert, and valley-init reports any |
| 66 | it finds on every activation without deleting it. |
| 67 | |
| 68 | Things around the hook could still have bypassed it, and each is closed. |
| 69 | |
| 70 | A pre-receive hook the module did not write, or a `core.hooksPath` set at any scope, to an empty |
| 71 | value included, would run instead of the policy. valley-init fails the activation over either, and a |
| 72 | project that wants a hook of its own composes it after the policy, where it can only refuse more. |
| 73 | |
| 74 | A 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 |
| 76 | the configuration the shell was rendered with. valley-init removes that record before anything else |
| 77 | it does and writes it last. The operator can also hold pushes with a file valley-init never touches. |
| 78 | Fetches stay open. |
| 79 | |
| 80 | The principal arrives one way. The shell reads the key sshd authenticated, finds that key's entry in |
| 81 | the files sshd authorized it from, and takes the tag on it. A principal or any `GIT_*` variable the |
| 82 | session arrived with is dropped, so a misconfigured sshd that passes client environment through |
| 83 | still 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, |
| 85 | with the keyword in any case, and any `PermitUserEnvironment` but `no`. It refuses a key declared |
| 86 | under two tags, and the git user's keys come only from the declared and compiled files. |
| 87 | |
| 88 | The instance repository must declare protection of the ref the floor and the registry are read from. |
| 89 | |
| 90 | ## What remains |
| 91 | |
| 92 | The hook does not check that an attestation's signer is the principal pushing it. The signer and the |
| 93 | pusher are routinely different principals. A host's own key signs the claims `attest run` makes on |
| 94 | it, and the operator's key pushes them. |
| 95 | |
| 96 | The request namespace does not record who filed a request. Any holder of the grant can therefore |
| 97 | replace or withdraw any request, not only its own. The grant is the boundary: who holds request is |
| 98 | decided in the registry, and the registry is governed. |
| 99 | |
| 100 | ## Rolling it out |
| 101 | |
| 102 | The order matters, because the hook refuses the very request that lands a registry change, and |
| 103 | because requests already queued were filed before anything checked who filed them. |
| 104 | |
| 105 | 1. 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. |
| 108 | 2. Declare `services.valley.grants.request` for whoever files the registry change, and protect the |
| 109 | instance repository's main. |
| 110 | 3. Before deploying, stop the integrators and confirm they are inactive. Hold pushes with the |
| 111 | operator's hold file. The new shell honours it from the moment the host switches, through |
| 112 | valley-init's convergence, until the audits below are done. |
| 113 | 4. Deploy. Resolve whatever valley-init refuses: a hand-written pre-receive hook, a |
| 114 | `core.hooksPath`. Read the replacement refs it reports before deleting them. |
| 115 | 5. Audit the integration-request queue. A request records no filer. Where a request's origin is in |
| 116 | doubt, withdraw it, to be filed again by a principal holding the grant. |
| 117 | 6. Release the hold, then start the integrators again. |
| 118 | 7. Land the registry change granting request. Keep the hand grant until the compiled grants file |
| 119 | names the holders and a request filed from a holder's own key is accepted. |
| 120 | 8. Remove the hand grant, deploy, and file a request from the holder's key once more. |
| 121 | |
| 122 | A protected project that moves onto the valley afterwards gets its first `main` by a seed on the |
| 123 | host ([integration.md](../../design/integration.md), _A protected stream starts from a seed_). |
| 124 | |
| 125 | ## Related |
| 126 | |
| 127 | - [[dcr-e544f20]] |
| 128 | ([decisions/dcr-e544f20-access-is-verbs-on-projects.md](../decisions/dcr-e544f20-access-is-verbs-on-projects.md)) |
| 129 | — the request verb, whose gate this ships. |
| 130 | - [[dcr-b87f6e8]] |
| 131 | ([decisions/dcr-b87f6e8-identity-is-a-governed-registry.md](../decisions/dcr-b87f6e8-identity-is-a-governed-registry.md)) |
| 132 | — the registry the grant compiles from, and the boundary rule it follows. |