| 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, 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 | |
| 50 | The request grant is a boundary kind in the identity schema, `"request"`. The compiler writes each |
| 51 | holder into a grants file the hook reads. A host can also grant it by hand, and the two add up. The |
| 52 | hand grant matters the first time: the hook refuses the request that would land the registry change |
| 53 | granting request, unless the host already grants it to whoever files that change. |
| 54 | |
| 55 | Replacement refs are also turned off wherever git is read for a decision: in the identity compiler, |
| 56 | in `attest` (so a standalone `attest verify` too), in the integrator and every program it runs, and |
| 57 | in the `valley` CLI. Each one also drops the inherited `GIT_*` variables that could point git at |
| 58 | other objects. A replacement ref already on a host is therefore inert, and valley-init reports any |
| 59 | it finds on every activation without deleting it. |
| 60 | |
| 61 | Three things around the hook could still have bypassed it, and each is refused. A pre-receive hook |
| 62 | the module did not write, or a `core.hooksPath` from any scope, would run instead of the policy, so |
| 63 | valley-init fails the activation over either; a project that wants a hook of its own composes it |
| 64 | after the policy, where it can only refuse more. The instance repository must declare protection of |
| 65 | the ref the floor and the registry are read from. And sshd is held to the one way a principal |
| 66 | arrives: the tag on the key's own entry. The module refuses an sshd that accepts the principal |
| 67 | variable from the client, sets it itself, or reads more of the user's environment than that one |
| 68 | variable. It also refuses a key declared under two tags. The git user's keys come only from the |
| 69 | declared and compiled files, and valley-init refuses a `~/.ssh/environment` in its home. |
| 70 | |
| 71 | ## What remains |
| 72 | |
| 73 | The hook does not check that an attestation's signer is the principal pushing it. The signer and the |
| 74 | pusher are routinely different principals. A host's own key signs the claims `attest run` makes on |
| 75 | it, and the operator's key pushes them. On a host that names no verifier keys, the hook checks what |
| 76 | a note claims about its signer and not the signature, so a name there can still be taken by a note |
| 77 | claiming a signer it was not signed by. |
| 78 | |
| 79 | The request namespace does not record who filed a request. Any holder of the grant can therefore |
| 80 | replace or withdraw any request, not only its own. The grant is the boundary: who holds request is |
| 81 | decided in the registry, and the registry is governed. |
| 82 | |
| 83 | ## Rolling it out |
| 84 | |
| 85 | The order matters, because the hook refuses the very request that lands a registry change. |
| 86 | |
| 87 | 1. 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. |
| 90 | 2. Declare `services.valley.grants.request` for whoever files the registry change, and protect the |
| 91 | instance repository's main. Then deploy. |
| 92 | 3. 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. |
| 95 | 4. 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. |
| 99 | 5. 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. |
| 102 | 6. 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. |