gunk-dev/the-valley

security.md

sourcef0de1b6b5b5dmain's published tip history
49.1 KiB · Rendered
1# Security and rollouts
2
3This document describes how the-valley protects the hosts it runs on and the hosts that deploy what
4lands on it. It follows the path a change takes, and names the gate at each step and its status. The
5components are described in [architecture.md](./architecture.md), and the planned gates live in
6[the plan graph](./concepts.md#records-project-storage-the-plan-graph-and-knots) (`valley plan`).
7
8The document makes three kinds of statement:
9
10- **Behaviour** is what the code does, cited to the files that do it. It is labelled `implemented`
11 where needed. A guarantee names the executable check that demonstrates it. A statement with no
12 named check is unchecked, and says so.
13- **A deployment choice** is what a deployment configures or must supply. It is labelled
14 **deployment choice**, and the code does not enforce it.
15- **A gate that is not built** has a design but does not work yet. It is labelled **not built**.
16
17The main threat is an AI agent acting as the operator. So the gates must hold even when an agent
18ignores its instructions. The human act of authority is a touch on a hardware key. An approval gate
19that the gated agent can administer is only a setting that agent controls
20([ida-b7025b5](../archive/.the-valley/ideas/ida-b7025b5-human-decisions-are-signed-acts.md)). A gate
21counts as done only when a check has shown it refusing what it should refuse
22([oc-9949561](../archive/.the-valley/outcomes/oc-9949561-push-replication.md)).
23
24## The path a change takes
25
26| Step | Gate | Status |
27| ---- | ------------------------------------------------- | ----------------- |
28| 1 | Agents are not the operator | Deployment choice |
29| 2 | Only the operator can file an integration request | Implemented |
30| 3 | Filing takes a touch | Not built |
31| 4 | Hosts deploy only what the operator signed | Not built |
32| 5 | A failed rollout rolls back or holds | Deployment choice |
33
34### 1. Agents are not the operator
35
36Agents must never act with the operator's identity or keys. The-valley names every pusher by its
37key, so each agent can have an identity of its own. The deployment keeps the agents apart from the
38operator's account, keys and secrets (**deployment choice**).
39
40- **The boundary.** A deployment runs its agents outside the operator's Unix account, in a boundary
41 such as a VM with its own kernel. The boundary has no host directory shares and no operator
42 secrets. An agent is assumed to have root inside the boundary.
43- **Their own identities.** Agents push with their own keys under their own principal, with a push
44 grant and no `approve` grant (**deployment choice**). The hook takes the principal from the key
45 that logged in (`valleyhook/shell.go`). Like any admitted key, an agent's key can push topic
46 branches and create attestation refs. No key can create or update a ref named like another ref,
47 such as a branch whose name begins with `refs/`, because git reads, fetches and pushes to such a
48 ref in place of a missing one (`implemented`, `valleyhook/policy.go`; checked by `protect-e2e` and
49 `valleyhook-unit`). The hook accepts an attestation ref only when every note in it verifies under
50 a known signer (`valleyhook/policy.go`, `valleyhook/attestation.go`). An agent's key can also
51 create change records, which makes the agent's principal the owner of those changes, and add
52 versions to them (`valleyhook/record.go`). A record never makes anything land. The integrator
53 reads records only to refuse a request or to void a withdrawn change's requests
54 (`integrator/records.go`). Any principal that can create a record can hold back a head by
55 recording it in a change and unreadying that change. Only an `approve` holder may delete that
56 record, and deleting it releases the head.
57- **Caps.** The deployment caps the boundary's CPU, memory and I/O, so agents cannot starve the
58 valley host.
59- **Egress.** The boundary reaches only what agents need, such as name resolution, ssh to the valley
60 host and HTTPS to the public internet. Everything else is dropped: private and other
61 special-purpose address ranges, other ports on the host, and spoofed sources.
62- **ssh into the valley host.** From the agents' network, sshd admits only the valley git user, with
63 no forwarding, TTY or tunnel. The host module's `Match User git` block turns off TCP, agent and
64 X11 forwarding and tunnels, and leaves stream-local forwarding on (`nix/valley-host.nix`). The
65 deployment adds `DisableForwarding yes` and `PermitTTY no` to close the rest (see
66 [Repositories and the git user](./architecture.md#repositories-and-the-git-user)).
67- **Tools that follow `main`.** `valley self-update` can keep an agent's `valley` at the tip of
68 `main`, through the flake's home-manager module (see
69 [Version and self-update](./architecture.md#version-and-self-update)). It installs only a commit
70 that has landed, built from the exact commit `git ls-remote` named, once it passes a smoke test.
71 The valley host and the machine the operator approves from must not run it. Their `valley` stays
72 at the version their system configuration pins, so a landing never changes the tool that approves
73 or admits the next change.
74
75Checks: `ssh-e2e` runs the git user's sshd block behind a real sshd. No check in this repository
76exercises a deployment's boundary, caps or egress. A deployment that runs agents needs its own
77checks for them, with negative controls that show each forbidden connection refused.
78
79### 2. Only the operator can file an integration request
80
81The push hook refuses an integration-request ref unless the pushing principal holds the `approve`
82grant (`valleyhook/policy.go`). The grant is also accepted as `request`: a principal holding either
83name holds it (`valleyhook/grants.go`). The principal comes from the key that logged in, and a
84client cannot set it (`valleyhook/shell.go`). Checks: `protect-e2e`, `identity-e2e`, and `ssh-e2e`,
85which uses test identities, a grant holder and a non-holder, behind a real sshd.
86
87Who holds the grant is a **deployment choice**. A deployment that gives it to the operator's
88principal alone makes the operator the only one who can file. Every key of that principal then holds
89the grant.
90
91The security invariant is the operator's approval: only content the operator approved lands. The
92request names the exact head that was approved, and the integrator lands only what a request names
93(`integrator/refs.go`). Checks: `integrator-e2e` and `valley-ready`.
94
95The `restack` grant is the host restacker's, and it files nothing. The hook lets a holder that
96neither owns a change nor holds `approve` add exactly one version to the change's record, while the
97change is `ready`. The version keeps the branch and title of the active one, and names the holder as
98its uploader. A holder may also write restack reports (`refs/the-valley/restack/main/*`). The grant
99authorises no other record write, no record delete, and nothing on integration requests
100(`valleyhook/record.go`, `valleyhook/report.go`). Checks: `protect-e2e` and `identity-e2e`.
101
102A `restack` holder is still a named principal, and keeps every ordinary power of one. So a
103compromised restacker key can:
104
105- rewrite or delete unprotected branches;
106- add arbitrary versions to other owners' ready changes;
107- create and manage its own records, and write valid plan-graph updates;
108- publish misleading reports, consume storage, exhaust a record's capacity, or withhold work.
109
110It cannot write a protected `main`, file, replace or withdraw a request, write an integrator
111outcome, or forge a check signature. It can relay evidence someone else signed, as any key can. The
112hook proves who uploaded a version and nothing about its content: not that it is a rebase of the old
113head, holds only the change's content, keeps its message and author, or sits on `main`. What
114protects the operator is approval. A request names the exact head the operator approved, so a
115version the restacker added lands only once the operator approves that head. Review compares a
116version with its approved version from git objects, and never trusts a report's account of it (see
117the architecture's
118[Review against the approved version](./architecture.md#review-against-the-approved-version)).
119
120On a host, the restacker runs as the Unix user `valley-restacker` in its own group
121`valley-restacker` (`nix/valley-host.nix`). That user has no filesystem access to the served
122repositories. It connects to them only over local SSH as its principal, so every write it makes goes
123through the hook. It holds no integrator key, no worker key, and no signing name, so it cannot sign
124evidence or a landing. Its own private key is provisioned outside the Nix store and passed to the
125service by systemd as a credential (`LoadCredential`). Enrolling the principal, granting it
126`restack`, and provisioning the private key are a **deployment choice**. Check: `restack-host-e2e`.
127
128Readiness is different. A change record's state is the author's workflow signal, and the integrator
129enforces it as closely as refs allow. It does not enforce it atomically. A record written between
130the integrator's last read of the records and its move of the target can be missed. That can land a
131head the operator approved and the author has since paused. It can never land content the operator
132did not approve. The race-free design binds each approval to the record's withdraw generation in a
133signed approval statement (**not built**).
134
135### 3. Filing takes a touch (not built)
136
137This gate is **not built**. Its design gives the `approve` grant to hardware keys that need a touch
138for every signature, and verifies each filing with `sigverify`. Until it is built, filing a request
139needs the operator's principal and no touch. `sigverify` itself is checked by `sigverify-unit` and
140`sigverify-e2e`, including a touchless-signature negative test. Enrolling a hardware-backed key is
141`implemented`: the registry schema accepts `bound: "hardware"` with an attestation, the identity
142renderer verifies the attestation, and it lists qualifying keys in the hardware approval-signers
143output. Enforcing a touch when an approval is filed is **not built**.
144
145### 4. Hosts deploy only what the operator signed (not built)
146
147A host that deploys what lands on the valley should activate only a release the operator signed. The
148design has each such host verify a signed, sequenced release tag before it activates anything, and
149never track `main`. `sigverify` verifies such a tag (`implemented`, checked by `sigverify-unit` and
150`sigverify-e2e`). Nothing calls it yet. The deployment supplies the host-side caller, which must
151meet [sigverify's caller's contract](../sigverify/README.md#the-callers-contract) (**not built**).
152
153Until a host verifies signed releases, a host that builds and activates the tip of `main` deploys
154whatever lands, without checking who made it (**deployment choice**). Nothing bounds the delay
155between a landing and its activation.
156
157### 5. A failed rollout rolls back or holds
158
159The-valley does not deploy the hosts that use what lands. A deployment's own activation step does,
160and it must roll back or hold when a rollout fails (**deployment choice**):
161
162- It checks a new system's health before it keeps the system.
163- On a failure, it switches back to the running system. It does not apply the failed revision again
164 until the operator clears it.
165- When it cannot switch back, or a run is interrupted, it holds for the operator.
166- A change that needs a reboot is checked after the reboot. When that check fails, the last good
167 system is staged back for the next boot.
168
169On the valley host itself, the-valley holds pushes while its own configuration settles.
170`valley-init` deletes its converged record before it links the hooks, and `valleyhook shell` refuses
171a push while that record does not match the running configuration (`nix/valley-host.nix`,
172`valleyhook/shell.go`). The operator can also hold every push with a hold file. Checked by
173`init-e2e` and `ssh-e2e` (see
174[valley-init and the push hold](./architecture.md#valley-init-and-the-push-hold)).
175
176## Threat model
177
178| Threat | Response |
179| ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
180| An agent acting as the operator | Agents run with their own principals and no operator keys (step 1). The push hook scopes refs by principal (step 2). |
181| An interactive coordinator | An agent that directs other agents runs with them, under an agent's principal. Only a verified touch stops an agent that holds a grant, and that gate is not built (step 3). |
182| A compromised restacker | Its `restack` grant adds versions to ready changes and writes reports, never requests. What it adds lands only once the operator approves that head (step 2). Its Unix user reaches the repositories only through the hook. |
183| A compromised agent | Assume it runs arbitrary commands inside its boundary. The boundary holds no production secrets and no signing sockets, and its egress is limited (step 1). |
184| A broken but honest change | A landing needs a signed statement that each required check passed. A failed activation rolls back or holds (step 5). A human signature does not prove correctness. |
185| A lost hardware key | An offline backup hardware key holds every role (see [Trust roots](#trust-roots)). |
186| The valley host compromised or down | Hosts that deploy from it keep their current systems. A compromised valley host can move `main`, so recovery that does not depend on it needs signed releases (step 4). |
187| A reader of the edge | Reads from an export only the projects that both consents in that pass authorize `anyone` to read. A pass omits every other project from the export and bundles it builds (see [Who can read a project](#who-can-read-a-project)). |
188| A stranger reaching the receiver | The receiver refuses the request as `unauthenticated` before reading the request body, without taking a request slot. A connection flood can still delay uploads while `valley-web` keeps serving (see [The edge's receiver](#the-edges-receiver)). |
189| A stolen receiver token | The holder can spend the receiver's capacity up to its caps. Serving a new export still requires a manifest signed by the export key (see [The edge's receiver](#the-edges-receiver)). |
190
191## Refs are read by their exact names
192
193Each program listed below reads a ref by its exact name (`implemented`). `git rev-parse`, and every
194git command given a ref name, does not stop at the name it is given. For a missing ref, git tries
195other names in turn, among them `refs/tags/<name>` and `refs/heads/<name>`. A branch named
196`refs/heads/registry` is stored as `refs/heads/refs/heads/registry`. A program that asked git for a
197missing `refs/heads/registry` would read that branch.
198
199The valley host's hook refuses to create or update a ref named like another ref (`implemented`,
200`valleyhook/policy.go`). A host repository can hold one made before the hook refused them, and a
201repository the hook does not guard, such as a local clone, can hold one at any time.
202
203So each of these programs reads a ref once, by its exact name, and from then on reads the object the
204ref held. It reads a local ref with `git show-ref`, and a remote one from the `git ls-remote` line
205that names it. A missing ref is missing:
206
207- The identity compiler fails when the instance repository has no registry ref, and the last good
208 files stay in place (`identity/registry.go`).
209- The integrator refuses a request named for a change that has no record. It does not judge a
210 request whose target is missing, and a withdrawn change does not void such a request. A request
211 with no memo has none, and the signers publication is written when there is none yet. It reads
212 evidence through the objects its refs held when it listed them. A request that is gone when the
213 integrator consumes it is not reported as moved (`integrator/`).
214- The integrator reads the floor at `--instance-ref` (`composed/composed.go`). The restacker takes
215 only the `git ls-remote` line that names that ref exactly (`restack/main.go`). An instance
216 repository with no such ref has no floor, and the pass is refused.
217- The web publisher reads the instance repository's `main`, its project list and its registry ref
218 with `readaccess.ResolveRef`. It refuses an instance repository with no `main` or no project list.
219 It reads a project's `main` the same way, at the object it staged
220 (`web/cmd/valley-web-publish/valley.go`).
221- `valley-read-coverage` reads the registry ref, the project list and each project's `main` with
222 `readaccess.ResolveRef` (`readaccess/cmd/valley-read-coverage/main.go`).
223- The check worker reads its own evidence ref exactly, and fetches the floor at the commit the
224 owning valley's `refs/heads/main` names (`status/worker.go`). `valley ready --stamp` finds no
225 local branch when the one it names is missing (`status/ready.go`).
226- `valley review`, `valley approve` and `valley checks` read `origin/main` and the change's branch
227 by their exact names (`bin/valley`). approve reads `origin/main` once, and reads the merge base
228 and both policy layers at that commit. The floor is fetched at the commit the owning valley's
229 `refs/heads/main` names. A request ref missing on origin is missing, whatever a branch named like
230 it holds.
231
232The identity compiler, the integrator and the restacker refuse a configured ref that is not a full
233ref name, such as `main`.
234
235`git push` matches the ref it writes the same way. With `<ref>` missing on origin, a push to `<ref>`
236writes a branch named `<ref>` instead, and with both present git refuses the push as ambiguous.
237`valley approve` reads origin before it pushes. While origin holds a ref whose name ends in the
238request ref's or an evidence ref's name, approve pushes nothing and names that ref (`implemented`).
239On the valley host, the hook refuses such a push rather than writing it, because the ref it would
240write is named like another ref (`implemented`, `valleyhook/policy.go`). The other programs that
241push do not check origin for such a ref before they push (**not built**).
242
243Checks: `identity-e2e` compiles with `refs/heads/registry` missing and a forged registry at
244`refs/heads/refs/heads/registry`, and the compilation fails with the files unchanged.
245`integrator-unit`, `restack-unit`, `web-unit`, `readaccess-unit`, `valley-ready` and
246`valley-request` each make the ref git would read in place of a missing one, and show that the
247program ignores it. `integrator-unit` deletes an evidence ref after the integrator lists it.
248`valley-request` approves with a branch on origin named like the request, with a tag named like the
249remote-tracking ref of `main` or of a branch that origin lacks, and with an owning valley whose
250`main` is missing. It also runs the check worker with a tag named like the worker's own evidence
251ref. `protect-e2e` and `valleyhook-unit` check the hook's refusal.
252
253## Trust roots
254
255The operator's trust roots are hardware keys that the deployment supplies (**deployment choice**):
256
257- **Two hardware keys**, a primary and an offline backup. Each holds every role: an approve key that
258 needs a touch, and a release signing key that needs a PIN and a touch. No gate uses these keys
259 yet, because the gates of steps 3 and 4 are **not built**.
260- **An offline root for trust-root changes**, such as a Tillitis TKey. `sigverify` has a
261 `tkey-signer` class for it (`implemented`). Nothing uses one for trust-root changes yet (**not
262 built**).
263
264## What a client trusts to read a landing
265
266A client decides that a version landed through an integrator merge (`landed-recorded`) by verifying
267the integrator's transfer statement. It verifies the statement with a known-signers file and the
268integrator's signing name. By default it reads both from the host's publication at
269`refs/the-valley/signers` in the instance repository (`implemented`; see
270[the signers publication](./architecture.md#the-signers-publication)).
271
272That publication is project storage, not source. No change, review or check governs it. The client
273trusts it for a different reason: only the host's machinery writes it, never a push. The push hook
274refuses every push to it (`implemented`, checked by `signers-e2e` and `publish-e2e`). On the host,
275the publisher writes it from the file and the name the controllers use (`implemented`, checked by
276`signers-e2e`). The integrator can write it too, because the instance repository is group-writable
277and the integrator is in that group to land code there (`implemented`, `nix/valley-host.nix`). So a
278client that reads it trusts the host's disk, the host's configuration and the integrator. It already
279trusts the same host to serve `main`, and the same integrator to decide what lands on it.
280
281A revocation reaches clients through the publication. Once the registry lets no key sign, the
282compiler writes a known-signers file with no key in it, and the host publishes that file. A client
283then verifies no transfer statement with the revoked keys (`implemented`, checked by `signers-e2e`).
284Two runs of the publisher take turns under a lock, so a run that read the file before a rotation
285cannot publish it over a run that read it after (`implemented`, checked by `signers-e2e`).
286
287The client finds the instance repository through `policy/valley` at `main`'s tip on origin, which is
288integrated source. A change that lands a new `policy/valley` points clients at another repository's
289publication. A flag or a variable set on the client replaces the publication for the value it gives.
290The restacker reads neither the publication nor the variables, only its own flags.
291
292A wrong publication cannot by itself make a version read `landed-recorded`. That also takes the
293integrator's outcome record for the version, saying it landed at the version's head, and no push may
294write an outcome record. A wrong publication can make a real landing read `uncertain`.
295
296## Who can read a project
297
298Read access to a project requires two consents ([Read access](./architecture.md#read-access)). A
299project's own `policy/read` names the principals allowed to read it. The instance's identity
300registry grants principals read access at an `edge-read` boundary, for named projects or for all
301projects. Both consents must match, so the project's policy and the instance's registry each hold a
302key (`implemented`, `readaccess/access.go`).
303
304- **`anyone`**, the reader who presents no credential, is authorized at an edge for the projects
305 whose `policy/read` names `anyone` and which a read grant to `anyone` covers at that destination
306 (`implemented`).
307- **A named principal**, including the operator, is evaluated by the same two-consent rule in
308 `readaccess/`. However, named grants publish nothing and `valley-web` authenticates no reader
309 (**not built**), so at the edge a named principal can read only what `anyone` may read.
310- **Membership, push access, approval and restacking** grant no read access at the edge.
311
312Which principals each project's policy names and which grants the registry declares are a
313**deployment choice**.
314
315**What reaches the edge.** A publisher pass includes in its export and bundles only the projects
316that both consents captured in that pass authorize `anyone` to read at the destination
317(`implemented`, `web/cmd/valley-web-publish/valley.go`). A separate signed authorization controls
318which of those exported projects the edge serves (see
319[The authorization decides what is served](#the-edges-receiver)). Projects not authorized for
320`anyone` in that pass are omitted from the export and bundles it builds. For each exported project,
321the export and bundle hold the project's reader view in plaintext: every knot and comment in its
322plan graph, its ready changes, and `main` with its history. Once an export is sent to an edge, that
323edge is the security boundary for what it holds: its administrators, and any process with access to
324its storage, can read all of it. Activating a newer export changes which generation the edge serves.
325It does not guarantee that an older generation is deleted: the edge's store keeps a generation that
326a reader still holds, or whose deletion failed, until a later sweep removes it (`implemented`,
327`web/export/store.go`). So withdrawing a project from what the edge serves is not deleting it from
328the edge's storage. A read grant at an `edge-read` boundary is consent to send a project's reader
329view to the destination that boundary names.
330
331**Groups place public projects and grant no read access.** A project reaches the edge only when
332`valley.cue` places it in a group, because a project without a group has no web URL. Placing a
333project in a group gives it a web URL once both read-access consents authorize `anyone`. Omitting
334`group` keeps a project off the web even when both consents authorize `anyone`. The export includes
335only groups that have at least one public project, along with the web names, former names, and short
336aliases of public projects (`implemented`, `web/export/project.go`). Groups with no public projects
337are omitted, and private projects' web names, former names, and short aliases are omitted. The web
338server reads only the export. Requests for a private project — whether under its group, another
339group, a former name, or a short alias — return the same `404` page byte for byte as requests for a
340project that does not exist (`implemented`, `web/server/server.go`). A group alias redirects any
341path under it to the group's `name` before checking whether the project exists, so hidden and
342nonexistent projects redirect identically and then return `404`.
343
344**A grant is bound to a project.** A grant that names a specific project binds both its name and its
345publication identity, so a new project that reuses an old project's name with a new identity is not
346covered by the old grant. A policy is valid only for the project repository it is read from. A
347policy or registry that is missing, fails schema validation, or exceeds its size bounds consents to
348nothing (`implemented`, `readaccess/read.go`).
349
350**The registry is read at its ref by that exact name.** The publisher and `valley-read-coverage`
351resolve the registry ref with `git show-ref`, which checks that exact full ref name (`implemented`,
352`readaccess/read.go`). `git rev-parse` is not used to resolve ref names, because when a ref such as
353`refs/heads/registry` is missing it falls back to `refs/heads/refs/heads/registry`, a branch any
354pusher can create. Instead, `git show-ref` resolves the ref name to an object ID, `git rev-parse`
355peels that object ID to a commit, and all subsequent reads use that commit ID. When the configured
356registry ref is not `refs/heads/main`, an instance repository without it has no registry, so every
357project is private. An instance repository without `refs/heads/main` is not an instance repository,
358so the publisher aborts the pass instead of building an empty export (`implemented`,
359`web/cmd/valley-web-publish/valley.go`). The host module rejects a `services.valley.identity.ref`
360that is not a full ref name (`implemented`, `nix/valley-host.nix`).
361
362**SSH fetches ignore read grants.** Read grants govern only web exports. On the valley host, every
363SSH key admitted for the git user can fetch every repository (`valleyhook/shell.go`). The git user's
364shell gates pushes and leaves fetching open. An admitted key without a principal tag runs as no
365principal: its session leaves `VALLEY_PRINCIPAL` unset. It is not `anyone`, which applies only to
366unauthenticated edge reads.
367
368**Withdrawal.** When either consent for `anyone` is withdrawn, the next pass's policy path signs an
369authorization that omits the project and sends it to the receiver before any content work begins
370(`implemented`, `web/cmd/valley-web-publish/policy.go`). The receiver stores the authorization
371without waiting for any content upload or commit, and `valley-web` stops serving the project on the
372next request (`implemented`, `web/export/authorize.go`, `web/server/server.go`). The policy path
373reads only the instance repository, the identity registry, and the `main` branch and `policy/read`
374of each project selected by a read grant to `anyone`. Because it reads no plan graph or knots, a
375broken or unreadable plan graph cannot delay a withdrawal. If a selected project's own policy cannot
376be read, that project retains at most the access granted by the last authorization the receiver
377acknowledged, and only while the receiver still holds that authorization, while withdrawals for
378other projects still take effect (`implemented`, `web/export/authorization.go`). A publisher state
379restored from an older backup keeps no such access. Projects not selected by a grant to `anyone` are
380not read (`implemented`, `web/cmd/valley-web-publish/read_test.go`). If the instance repository or
381the registry cannot be read, the pass signs no authorization, and the withdrawal waits for a later
382pass that can read them. Authorizations have no serving expiry: while the valley host cannot reach
383the edge, the edge continues serving what the stored authorization allows. Once the host reaches the
384edge again, the next pass re-evaluates the policy and sends a fresh authorization, which takes
385effect even if the pass's content upload fails. Unbuilt parts of read access are listed in
386[Not deployed or not wired yet](./architecture.md#not-deployed-or-not-wired-yet).
387
388Checks: `readaccess-unit` reads both consents from real commits under the real schemas, including
389policies that redeclare a schema definition and trees with malformed entry names. `web-unit`
390verifies that the publisher requires both consents (`TestVisibilityNeedsBothConsents`) and that no
391private sentinel appears in any export or bundle (`TestPrivateSentinelsNeverLeave`). Both `web-unit`
392(`TestTheRegistryIsReadAtItsRef`) and `readaccess-unit` (`TestRegistryRef`) verify that every
393project stays private when the registry ref is missing even if `refs/heads/refs/heads/registry`
394grants `anyone` read. `module-eval` rejects a short registry ref. `cue-vet` and `identity-schema`
395test both schemas against their rejected examples.
396
397## The web publisher
398
399`valley-web-publish` runs on the valley host and uploads signed exports of public projects to the
400edge. It reads local repositories, signs each manifest with its own key, and connects out to the
401receiver. Nothing on the edge connects back to the valley host.
402
403**Only projects `anyone` may read leave the host.** A pass exports a project only when three
404conditions hold: the project's `policy/read` names `anyone`, a read grant to `anyone` for the
405destination covers the project, and the host declaration places the project in a group
406(`implemented`, `web/cmd/valley-web-publish/valley.go`). The edge serves every reader anonymously,
407so everything that reaches it is public (see
408[What reaches the edge](./architecture.md#what-reaches-the-edge)).
409
410**The export key signs every manifest.** On its first start, the publisher generates an Ed25519 key
411in its state directory and writes the key's verifier line beside it under the signing name
412`<instance>/web-export` (`implemented`, `web/cmd/valley-web-publish/state.go`). The receiver admits
413only manifests that open under a verifier line it pins. Pinning that verifier line on the edge is a
414**deployment choice**. On NixOS, the state directory belongs to the unit with mode `0700`
415(`implemented`, `nix/web-publisher.nix`).
416
417**The pass runs confined.** On NixOS, the publisher's unit runs as a dynamic user in the `git` group
418(`implemented`, `nix/web-publisher.nix`). The host repositories are mounted read-only, and the host
419filesystem is read-only except for the unit's state and cache directories and its private temporary
420directories. The `git` user's SSH identity and the host's signing, mirror, and backup keys are
421mounted inaccessible. The unit's `safe.directory` list names only the repositories the host
422declares. The unit can still read the host's other repositories through the filesystem. The full
423filesystem sandbox is **not built**.
424
425**The pass connects only to allowed IP addresses.** The unit denies all IP traffic
426(`IPAddressDeny=any`) and allows only the addresses in
427`services.valley.webPublisher.allowedAddresses` (`implemented`, `nix/web-publisher.nix`). The module
428refuses to build when `allowedAddresses` is empty. A pass reads local repositories and runs `valley`
429commands that use no network, so it needs to reach only the receiver. Which receiver addresses to
430list is a **deployment choice**. The upload client connects directly to the receiver and ignores
431proxy environment variables such as `HTTPS_PROXY` (`implemented`,
432`web/cmd/valley-web-publish/upload.go`).
433
434**The unit checks that the IP filter is active before each pass.** When the kernel or service
435manager lacks cgroup BPF support, systemd logs a warning and leaves `IPAddressDeny` and
436`IPAddressAllow` unenforced. Before each pass, the unit therefore runs
437`valley-web-publish-egress-check` inside the unit's own cgroup (`ExecStartPre`, `implemented`,
438`nix/web-publisher.nix`). The check sends a UDP datagram to `198.51.100.1` port `9`, an address the
439filter must block. The pass starts only when that send fails immediately with `EPERM`. If the
440datagram goes out or fails with any other error, the check aborts the pass and logs the reason. The
441module refuses `allowedAddresses` entries that cover `198.51.100.1`. The host needs a route to
442`198.51.100.1`, such as a default route, so the datagram reaches the cgroup filter instead of
443failing earlier with no route. The check uses UDP because the cgroup filter returns `EPERM` on
444`send` at once, whereas a dropped TCP SYN waits for a connection timeout.
445
446**Host names resolve outside the unit.** The unit sets `GODEBUG=netdns=cgo` so the publisher
447resolves host names through the C library instead of Go's built-in resolver (`implemented`,
448`nix/web-publisher.nix`). `nix/packages.nix` builds the publisher with cgo enabled. On NixOS, the C
449library queries `nscd` over a local Unix socket, and `nscd` sends the DNS query from outside the
450unit's cgroup. When `nscd` is enabled (`services.nscd.enable`, on by default in NixOS; a
451**deployment choice**), `allowedAddresses` needs only the receiver's addresses. If `nscd` is
452disabled, the C library sends DNS queries from inside the unit, and the filter blocks them unless
453`allowedAddresses` also includes the DNS resolver.
454
455The cgroup filter checks only the destination IP address. It permits every port on an allowed
456address and checks the resolved address independently of the host name in `--receiver`.
457
458Checks: `module-eval` verifies the unit's IP filter, `ExecStartPre` check, `GODEBUG` setting,
459filesystem confinement, and credentials, and verifies that evaluation fails when `allowedAddresses`
460is empty or covers `198.51.100.1`. `web-publisher-e2e` boots a NixOS VM and runs the rendered unit
461with a probe script in place of the publisher. Inside the unit, the egress check passes; run by root
462outside the unit, the same check fails because root's datagram reaches `198.51.100.1`. The probe
463verifies that Git accepts a declared repository and refuses an undeclared repository as dubiously
464owned. It verifies that repository writes fail and that the git SSH key, backup SSH key, and raw
465token file cannot be read. It also verifies that the unit can connect to a listener on its allowed
466address while connections to disallowed IPv4 and IPv6 listeners fail, and that the C library
467resolves a name served by a DNS server on a disallowed address while direct UDP packets from the
468unit to that DNS server fail with `EPERM`.
469
470## The edge's receiver
471
472`valley-web-receive` accepts uploads from the publisher on the edge, and `valley-web` serves the
473active generation (see [The receiver](./architecture.md#the-receiver)). Two independent checks guard
474an upload.
475
476**The authorization decides what is served.** The receiver stores an authorization only when it
477opens under a pinned verifier, carries the authorization's type line, names the receiver's instance
478and destination, and carries a sequence greater than the stored one's (`implemented`,
479`web/export/authorization.go`). It accepts an authorization regardless of age, so no clock fault
480holds up a narrowing. `valley-web` reads the stored authorization on every request and again before
481each response's headers, under a lock that the receiver takes to replace the authorization. It
482serves a project only while the authorization names the project with the export's identity for it
483(`implemented`, `web/server/server.go`). A missing or invalid authorization serves no project. A
484content manifest names no reader. The receiver builds a repository only for a project the
485authorization names, and content never repairs or replaces the authorization. No content upload,
486however late, grants or restores access (`implemented`, `web/export/store.go`). The guarantee covers
487every response whose headers are written after the receiver replies (`implemented`,
488`web/export/authorize.go`). A response whose headers were written before continues to completion.
489
490**A withdrawn project's plaintext stays until it is replaced.** After a withdrawal, the receiver
491deletes the project's repository once no reader holds the active generation (`implemented`,
492`web/export/authorize.go`). The signed `export.json` keeps its bytes, so the project's plan text
493stays on the edge's disk until a later activation replaces the generation and the old one is
494deleted. Withdrawal hides a project from readers while leaving its plan text in the active
495`export.json` until the next activation.
496
497**The manifest's signature decides what content the edge holds.** The receiver stages a manifest
498only when it opens under a pinned verifier, names the receiver's instance and destination, and
499carries a sequence newer than any accepted sequence (`implemented`, `web/export/manifest.go`). It
500keeps only bodies whose size and SHA-256 the manifest declares, and activates a generation only when
501every bundle passes acceptance (`implemented`, `web/export/body.go`, `web/export/bundle.go`). Only a
502holder of the publisher's export key can put content or an authorization on the edge. The bearer
503token grants upload access alone.
504
505**A rollback of the edge serves nothing.** The store's entry point is a descriptor file (`store`),
506which binaries of the first store layout refuse. Its payloads live under `v2/`, which those binaries
507never read (`implemented`, `web/export/store.go`). Neither a rolled-back binary nor a missing
508authorization can serve the store's content.
509
510**The token decides who may use the receiver.** Every request must carry the bearer token in its
511`Authorization` header. The receiver checks the header before reading the request body and refuses
512an unauthenticated request as `unauthenticated` (`implemented`,
513`web/cmd/valley-web-receive/receive.go`). A stranger who reaches the receiver cannot trigger
514manifest verification, stream a body into staging, or start a commit. A holder of the token without
515the export key can spend the receiver's staging and request capacity up to its caps, while what the
516edge serves stays signed by the publisher.
517
518**The token stays out of the Nix store and out of `valley-web`'s reach.** On NixOS, both modules
519load the token file as a systemd credential for their own unit from a path outside the Nix store,
520and both refuse a store path at evaluation time (`implemented`, `nix/web-publisher.nix`,
521`nix/web-receiver.nix`). `valley-web` runs as a separate user without that credential. The publisher
522refuses HTTP redirects, so it sends the token only to the configured receiver URL (`implemented`,
523`web/cmd/valley-web-publish/upload.go`). Neither program prints the token. Where a container host
524stores the token file, and who can read it there, is a **deployment choice**.
525
526**The token stays secret only on an encrypted or private network path.** Every upload request
527carries the token. Whether the publisher reaches the receiver over HTTPS, through a TLS-terminating
528reverse proxy, or over a private network is a **deployment choice**. Sending requests over plain
529HTTP across an untrusted network exposes the token to anyone who can read that network.
530
531**`valley-web` has read-only access to the store.** It opens the store read-only and writes nothing
532there (`implemented`, `web/export/store.go`). On NixOS its unit mounts the state directory read-only
533(`implemented`, `nix/web-receiver.nix`). The unit's only writable paths are temporary: its private
534`/tmp` and `/var/tmp` from `PrivateTmp` (hidden from other units and removed when the unit stops)
535and `/dev/shm` from `PrivateDevices` (`implemented`, `nix/web-receiver.nix`). Those temporary paths
536are separate from the state directory, and the receiver ignores them. A fault in `valley-web`, which
537handles requests from arbitrary readers, reaches neither the staging area nor the token.
538
539Checks: `web-receiver-unit` verifies that the receiver refuses requests with no token, a wrong
540token, a non-Bearer scheme, or two `Authorization` headers before staging anything
541(`TestAnUnauthenticatedRequestIsRefused`), answers `OPTIONS *` with a withheld body immediately on
542every connection without reading the body (`TestOptionsStarHoldsNoConnection`), and refuses stale,
543future-dated, foreign-key, and foreign-destination manifests
544(`TestAManifestIsAdmittedOnlyWhenFresh`). It also verifies that the receiver stores an authorization
545dated long ago by its sequence, refuses a replayed authorization, and refuses a request of the first
546protocol (`TestAnAuthorizationIsAdmittedBySequence`). `web-unit` (`TestPublishesToTheRealReceiver`)
547verifies that a pass with a wrong token is refused while the edge keeps serving the active export,
548and (`TestStoreDescriptorRetiresTheFirstLayout`) that both store openers refuse a directory. It
549verifies that a restored publisher state keeps no withdrawn access
550(`TestARestoredStateRestoresNoWithdrawnAccess`), that a paused prune keeps a repository an
551authorization names again (`TestAPruneKeepsWhatAnAuthorizationNamesAgain`), that retiring the first
552layout finishes after a stop at any step and waits for its lock
553(`TestRetiringTheFirstLayoutResumes`), and that a new store deletes nothing that only shares a name
554with the first layout's state (`TestANewStoreKeepsWhatOnlySharesTheFirstLayoutsNames`).
555`web-server-unit` verifies that a withdrawal takes effect at the next request, that a response
556rendered while the authorization changed is rendered again, and that a withdrawal stored while a
557response holds the serving lock returns only after that response's headers are written
558(`TestAuthorizationIsReadOnEveryRequest`, `TestAResponseIsHeldToTheAuthorizationWhenWritten`,
559`TestAWithdrawalWaitsForAResponseItsCheckAdmitted`), and that a request waits for a held serving
560lock only until its deadline or until its reader goes away
561(`TestAServingLockWaitEndsWithTheRequest`). `web-push-e2e` withdraws a project with `--policy-only`
562while an upload is stalled, and checks that the stalled upload restores nothing and that a store
563with its authorization removed serves no project. `module-eval` verifies the credentials and users
564both modules render and rejects a token path in the Nix store. `web-publisher-e2e` verifies in a
565NixOS VM that the publisher's unit receives the token as a credential while the token file on disk
566stays readable by root alone.
567
568## Secrets
569
570The valley host needs a few secrets, and the deployment provisions each one as a file outside the
571Nix store (**deployment choice**; see
572[What a deployment supplies](./architecture.md#what-a-deployment-supplies)). They are the
573integrator's signing key, the git user's ssh key for mirror pushes, and the backup's credentials.
574
575A deployment must keep these secrets, and every key that decrypts them, out of agents' reach. Two
576properties of encrypted secrets bear on that:
577
578- A copy of any recipient's private key decrypts every secret encrypted to it, on any machine. When
579 secrets are encrypted to host keys, each host's key is a software private key that can decrypt
580 them.
581- Old ciphertext stays decryptable by every key it was encrypted to. A secret once encrypted to a
582 key that agents could read must be replaced with a new secret, not only re-encrypted.
583
584## What the operator does
585
586- Approves changes, with `[a]pprove` in `valley review` or with `valley approve`. Approving a change
587 files its integration request. This is the only act on this list that a check enforces (step 2).
588- Holds the hardware keys and manages the deployment's secrets.
589- Signs releases and approves protected path classes, once those gates exist (**not built**).
590
591## The autonomy ladder
592
593Automation grows in deterministic forms, under policy the operator signs. Agents never decide for
594themselves when to deploy.
595
5961. **Today.** An approved landing on `main` is the gate. A host that deploys from `main` deploys it
597 on its next run.
5982. **Signed releases** (**not built**). A signed release is the gate, and a landing does not deploy.
599 One touch and PIN signs a batch. Rollout through canaries, soak and rollback runs unattended.
6003. **A batched cadence.** A scheduled release promotes everything accumulated, and one touch signs
601 it.
6024. **Approved upstreams.** When a deployment's inputs, the-valley among them, land through
603 approval-gated integration, a change that only updates those inputs can land when its checks
604 pass. Those updates still ship through releases.
6055. **A delegated release signer.** A machine key in the release environment, out of agents' reach,
606 signs releases that touch only declared low-risk path classes. The operator signs that policy
607 with a touch. Entry criterion: a record of health-gated rollback catching real failures in
608 production, and a measured count of touches per week.
609
610## Residual risks
611
612- **Agents must not be able to land outside the valley.** If a host deploys from a repository on a
613 forge, an agent with merge rights there can deploy without an approval. A deployment gives agents'
614 accounts no merge rights on such a repository.
615- **Old secret ciphertext stays decryptable.** A secret encrypted to a key that agents could once
616 read stays readable with that key, in every copy of the ciphertext, until the secret is rotated.
617- **An escape from an agent VM on the valley host reaches the host.** The VM has its own kernel, and
618 an escape through KVM or the hypervisor reaches the host that runs the valley.
619- **Every key of the operator's principal holds `approve`.** Filing needs no touch until step 3 is
620 built.
621- **Check definitions come from the change.** A change can edit the flake check it is judged by
622 ([bd-eaefe82](../archive/.the-valley/bugs/bd-eaefe82-check-definitions-come-from-the-branch.md)).
623- **Hosts must not update from an unsigned branch.** A host that upgrades itself from a branch
624 without a signature check deploys whatever reaches that branch. When the branch is on a forge
625 rather than on the valley, no gate in this document applies to it.
626- **Readiness is not enforced atomically.** A change paused in the moment before the integrator
627 moves the target can still land, at the head the operator approved (step 2).
628- **Every admitted key can fetch every repository.** Read grants govern web exports alone. Any SSH
629 key sshd admits for the git user, including an agent's key, can fetch any project on the valley
630 host.
631- **A withdrawal waits on reading the instance and the registry.** A pass that cannot read the
632 instance repository or its registry signs no authorization, and the edge keeps serving what it
633 has. A selected project whose own policy cannot be read keeps the access the receiver's current
634 authorization gives it until a pass can read it.
635- **A withdrawn project's plan text stays on the edge's disk.** The signed `export.json` keeps a
636 withdrawn project's knots and comments until a later activation replaces the generation.
637- **The receiver's token is a shared secret.** The publisher and the receiver share one bearer
638 token, and every upload request carries it. Anyone holding the token can fill the receiver's
639 request slots and staging area up to its caps, delaying uploads while the flood lasts. Plain HTTP
640 over an untrusted network exposes the token in transit.
641- **Anyone who reaches the receiver can occupy its connection limit.** An unauthenticated client can
642 open all 32 concurrent connections and hold each one for up to the 10-second header timeout,
643 delaying uploads while the flood lasts. Which network peers can reach the receiver's listener is a
644 **deployment choice**.
645- **The bus has no authentication.** Any local process on the valley host can publish events.
646 Nothing treats an event as authoritative.
647- **Listing `integrator` in `protection.writers` opens a push path to `main`.** The integrator moves
648 `main` on disk and needs no place in `protection.writers`. A deployment that lists `integrator`
649 there lets any key tagged `integrator` push `main` directly. No declared or registry key may carry
650 that tag.