gunk-dev/the-valley

security.md

source4cbb5ec9c5dbmain's published tip history
78.9 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 an approval made with the operator's key.
19Whether that key must be a hardware key that needs a touch is a **deployment choice**. A policy
20requires one with `approval.hardware`, and enforcing that requirement is **not built** (see
21[Filing takes a touch](#3-filing-takes-a-touch-not-built)). An approval gate that the gated agent
22can administer is only a setting that agent controls. A gate counts as done only when a check has
23shown it refusing what it should refuse.
24
25## The path a change takes
26
27| Step | Gate | Status |
28| ---- | ------------------------------------------------- | ----------------- |
29| 1 | Agents are not the operator | Deployment choice |
30| 2 | Only the operator can file an integration request | Implemented |
31| 3 | Filing takes a touch | Not built |
32| 4 | Hosts deploy only what the operator signed | Not built |
33| 5 | A failed rollout rolls back or holds | Deployment choice |
34
35### 1. Agents are not the operator
36
37Agents must never act with the operator's identity or keys. The-valley names every pusher by its
38key, so each agent can have an identity of its own. The deployment keeps the agents apart from the
39operator's account, keys and secrets (**deployment choice**).
40
41- **The boundary.** A deployment runs its agents outside the operator's Unix account, in a boundary
42 such as a VM with its own kernel. The boundary has no host directory shares and no operator
43 secrets. An agent is assumed to have root inside the boundary.
44- **Their own identities.** Agents push with their own keys under their own principal, with a push
45 grant and no `approve` grant (**deployment choice**). The hook takes the principal from the key
46 that logged in (`valleyhook/shell.go`). Like any admitted key, an agent's key can push topic
47 branches and create attestation refs. No key can create or update a ref named like another ref,
48 such as a branch whose name begins with `refs/`, because git reads, fetches and pushes to such a
49 ref in place of a missing one (`implemented`, `valleyhook/policy.go`; checked by `protect-e2e` and
50 `valleyhook-unit`). The hook accepts an attestation ref only when every note in it verifies under
51 a known signer (`valleyhook/policy.go`, `valleyhook/attestation.go`). An agent's key can also
52 create change records, which makes the agent's principal the owner of those changes, and add
53 versions to them (`valleyhook/record.go`). A record never makes anything land. The integrator
54 reads records only to refuse a request or to void a withdrawn change's requests
55 (`integrator/records.go`). Any principal that can create a record can hold back a head by
56 recording it in a change and unreadying that change. Only an `approve` holder may delete that
57 record, and deleting it releases the head.
58- **Agent-run conversation storage.** The agent-run client stores conversations in project storage
59 at `refs/the-valley/flow/data`. SSH writes require a named grant (**implemented**). The project
60 names its writers in `valley.cue` (**deployment choice**).
61
62 Grant holders can create, update, force-push, or delete this ref, subject to the `protection`,
63 symbolic-ref, and lookalike rules. The grant covers only this ref. The rules for `approve`,
64 `restack`, and other refs apply independently. The host reserves every other ref under
65 `refs/the-valley/flow/`, even when a broad grant pattern matches it (**implemented**).
66
67 Publication mirrors and the web publisher omit this ref, even with a public read grant. SSH
68 fetches bypass read grants. Any key admitted for the host's `git` user can fetch the ref from any
69 repository that holds it (**implemented**).
70
71 Checked by `valleyhook-unit`, `protect-e2e`, and `cue-vet`.
72
73- **Caps.** The deployment caps the boundary's CPU, memory and I/O, so agents cannot starve the
74 valley host.
75- **Egress.** The boundary reaches only what agents need, such as name resolution, ssh to the valley
76 host and HTTPS to the public internet. Everything else is dropped: private and other
77 special-purpose address ranges, other ports on the host, and spoofed sources.
78- **ssh into the valley host.** From the agents' network, sshd admits only the valley git user, with
79 no forwarding, TTY or tunnel. The host module's `Match User git` block turns off TCP, agent and
80 X11 forwarding and tunnels, and leaves stream-local forwarding on (`nix/valley-host.nix`). The
81 deployment adds `DisableForwarding yes` and `PermitTTY no` to close the rest (see
82 [Repositories and the git user](./architecture.md#repositories-and-the-git-user)).
83- **Tools that follow `main`.** `valley self-update` can keep an agent's `valley` at the tip of
84 `main`, through the flake's home-manager module (see
85 [Version and self-update](./architecture.md#version-and-self-update)). It installs only a commit
86 that has landed, built from the exact commit `git ls-remote` named, once it passes a smoke test.
87 The valley host and the machine the operator approves from must not run it. Their `valley` stays
88 at the version their system configuration pins, so a landing never changes the tool that approves
89 or admits the next change.
90
91Checks: `ssh-e2e` runs the git user's sshd block behind a real sshd. No check in this repository
92exercises a deployment's boundary, caps or egress. A deployment that runs agents needs its own
93checks for them, with negative controls that show each forbidden connection refused.
94
95### 2. Only the operator can file an integration request
96
97The push hook refuses an integration-request ref unless the pushing principal holds the `approve`
98grant (`valleyhook/policy.go`). The grant is also accepted as `request`: a principal holding either
99name holds it (`valleyhook/grants.go`). The principal comes from the key that logged in, and a
100client cannot set it (`valleyhook/shell.go`). Checks: `protect-e2e`, `identity-e2e`, and `ssh-e2e`,
101which uses test identities, a grant holder and a non-holder, behind a real sshd.
102
103Who holds the grant is a **deployment choice**. A deployment that gives it to the operator's
104principal alone makes the operator the only one who can file. Every key of that principal then holds
105the grant.
106
107The security invariant is the operator's approval: only content the operator approved lands. The
108request names the exact head that was approved, and the integrator lands only what a request names
109(`integrator/refs.go`). Checks: `integrator-e2e` and `valley-ready`.
110
111The `restack` grant is the host restacker's, and it files nothing. The hook lets a holder that
112neither owns a change nor holds `approve` add exactly one version to the change's record, while the
113change is `ready`. The version keeps the branch and title of the active one, and names the holder as
114its uploader. A holder may also write restack reports (`refs/the-valley/restack/main/*`). The grant
115authorises no other record write, no record delete, and nothing on integration requests
116(`valleyhook/record.go`, `valleyhook/report.go`). Checks: `protect-e2e` and `identity-e2e`.
117
118A `restack` holder is still a named principal, and keeps every ordinary power of one. So a
119compromised restacker key can:
120
121- rewrite or delete unprotected branches;
122- add arbitrary versions to other owners' ready changes;
123- create and manage its own records, and write valid plan-graph updates;
124- publish misleading reports, consume storage, exhaust a record's capacity, or withhold work.
125
126It cannot write a protected `main`, file, replace or withdraw a request, write an integrator
127outcome, or forge a check signature. It can relay evidence someone else signed, as any key can. The
128hook proves who uploaded a version and nothing about its content: not that it is a rebase of the old
129head, holds only the change's content, keeps its message and author, or sits on `main`. What
130protects the operator is approval. A request names the exact head the operator approved, so a
131version the restacker added lands only once the operator approves that head. Review compares a
132version with its approved version from git objects, and never trusts a report's account of it (see
133the architecture's
134[Review against the approved version](./architecture.md#review-against-the-approved-version)).
135
136On a host, the restacker runs as the Unix user `valley-restacker` in its own group
137`valley-restacker` (`nix/valley-host.nix`). That user has no filesystem access to the served
138repositories. It connects to them only over local SSH as its principal, so every write it makes goes
139through the hook. It holds no integrator key, no worker key, and no signing name, so it cannot sign
140evidence or a landing. Its own private key is provisioned outside the Nix store and passed to the
141service by systemd as a credential (`LoadCredential`). Enrolling the principal, granting it
142`restack`, and provisioning the private key are a **deployment choice**. Check: `restack-host-e2e`.
143
144Readiness is different. A change record's state is the author's workflow signal, and the integrator
145enforces it as closely as refs allow. It does not enforce it atomically. A record written between
146the integrator's last read of the records and its move of the target can be missed. That can land a
147head the operator approved and the author has since paused. It can never land content the operator
148did not approve. The race-free design binds each approval to the record commit the approver read in
149a signed `the-valley/approval/v1` statement (`implemented`, see
150[Approval statement](./reference.md#approval-statement-the-valleyapprovalv1)). The hook stores
151approvals, and takes them only from a holder of the `approve` grant: owning the change, holding
152`restack`, and being in `protection.writers` confer nothing (`implemented`, checked by
153`valleyhook-unit`). It checks an approval's form and that it names the head of any request beside it
154when written. It does not check whose key signed it, so a stored approval proves nothing until a
155reader verifies it under its own approval keys. A later request-only push or two racing non-atomic
156pushes can still leave a note beside a request it does not name; such a pair is not an approval, and
157the landing gate that would compare them is **not built** (see
158[Change records](./architecture.md#change-records)). A project can declare `retainChangeRecords` so
159that no push deletes a record and its history shows any withdrawal (`implemented`; setting it is a
160**deployment choice**). Gating landings on approvals is **not built**; it would require retained
161records.
162
163### 3. Filing takes a touch (not built)
164
165This gate is **not built**. Its design gives the `approve` grant to hardware keys that need a touch
166for every signature, and verifies each filing with `sigverify` or `approval`. Until it is built,
167filing a request needs the operator's principal and no touch. `sigverify` itself is checked by
168`sigverify-unit` and `sigverify-e2e`, including a touchless-signature negative test. Enrolling a
169hardware-backed key and signing an approval statement on a YubiKey PIV slot are `implemented` (see
170[Approval signers files](./reference.md#approval-signers-files) and
171[Approval statement](./reference.md#approval-statement-the-valleyapprovalv1)): the registry schema
172accepts `bound: "hardware"` with an attestation, the identity renderer verifies the attestation and
173lists touch-always keys in `approval-signers-hardware`, and the `approval` command signs statements
174with the key in a YubiKey's PIV slot. With an approval key selected, `valley approve` and review's
175`[a]pprove` sign the version they file and publish the note beside the request (`implemented`), and
176a refused signature publishes nothing. A YubiKey asks for a PIN and a touch as its slot's policies
177say. Selecting a PIV slot is the operator's choice of key; requiring a touch-always key belongs to
178`approval.hardware`, which accepts only keys `approval-signers-hardware` lists. Requiring a signed
179approval, or a touch, when a change is filed or integrated is **not built**.
180
181### 4. Hosts deploy only what the operator signed (not built)
182
183A host that deploys what lands on the valley should activate only a release the operator signed. The
184design has each such host verify a signed, sequenced release tag before it activates anything, and
185never track `main`. `sigverify` verifies such a tag (`implemented`, checked by `sigverify-unit` and
186`sigverify-e2e`). Nothing calls it yet. The deployment supplies the host-side caller, which must
187meet [sigverify's caller's contract](../sigverify/README.md#the-callers-contract) (**not built**).
188
189Until a host verifies signed releases, a host that builds and activates the tip of `main` deploys
190whatever lands, without checking who made it (**deployment choice**). Nothing bounds the delay
191between a landing and its activation.
192
193### 5. A failed rollout rolls back or holds
194
195The-valley does not deploy the hosts that use what lands. A deployment's own activation step does,
196and it must roll back or hold when a rollout fails (**deployment choice**):
197
198- It checks a new system's health before it keeps the system.
199- On a failure, it switches back to the running system. It does not apply the failed revision again
200 until the operator clears it.
201- When it cannot switch back, or a run is interrupted, it holds for the operator.
202- A change that needs a reboot is checked after the reboot. When that check fails, the last good
203 system is staged back for the next boot.
204
205On the valley host itself, the-valley holds pushes while its own configuration settles.
206`valley-init` deletes its converged record before it links the hooks, and `valleyhook shell` refuses
207a push while that record does not match the running configuration (`nix/valley-host.nix`,
208`valleyhook/shell.go`). The operator can also hold every push with a hold file. Checked by
209`init-e2e` and `ssh-e2e` (see
210[valley-init and the push hold](./architecture.md#valley-init-and-the-push-hold)).
211
212## Threat model
213
214| Threat | Response |
215| ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
216| 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). |
217| 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). |
218| 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. |
219| 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). |
220| 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. |
221| A lost hardware key | An offline backup hardware key holds every role (see [Trust roots](#trust-roots)). |
222| 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). |
223| A reader of the edge | A pass exports only the projects that both consents in that pass authorize some reader to read, `anyone` or a named principal. It omits every other project from the export and bundles it builds. A reader without a session reads the projects `anyone` may read. A signed-in reader reads those and the projects its principal may read (see [Who can read a project](#who-can-read-a-project)). |
224| 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)). |
225| 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)). |
226
227Rendered Markdown adds no active content to the edge's origin (**implemented**). `valley-web`
228renders a Markdown file with package `web/markdown`, which writes only its own fixed set of elements
229and attributes: headings, paragraphs, emphasis, code, quotes, lists, tables and links. It escapes
230every byte of text and every attribute value it takes from the file, and shows raw HTML as text. A
231link is written only for an `http` or `https` destination that names a host, a `mailto` destination,
232or a relative one resolved inside the source browser. A destination that holds a backslash anywhere
233is refused, whether the file writes it as a backslash, an escape or an entity. A browser may read a
234backslash as a slash, so the renderer cannot tell where such a destination's path or host starts. An
235image is a link, never an `img` element. No `style` attribute is written, so the
236Content-Security-Policy is unchanged but for the stylesheet's hash. The package's fuzz test holds
237its output to that set.
238
239## Refs are read by their exact names
240
241Each program listed below reads a ref by its exact name (`implemented`). `git rev-parse`, and every
242git command given a ref name, does not stop at the name it is given. For a missing ref, git tries
243other names in turn, among them `refs/tags/<name>` and `refs/heads/<name>`. A branch named
244`refs/heads/registry` is stored as `refs/heads/refs/heads/registry`. A program that asked git for a
245missing `refs/heads/registry` would read that branch.
246
247The valley host's hook refuses to create or update a ref named like another ref (`implemented`,
248`valleyhook/policy.go`). A host repository can hold one made before the hook refused them, and a
249repository the hook does not guard, such as a local clone, can hold one at any time.
250
251So each of these programs reads a ref once, by its exact name, and from then on reads the object the
252ref held. It reads a local ref with `git show-ref`, and a remote one from the `git ls-remote` line
253that names it. A missing ref is missing:
254
255- The identity compiler fails when the instance repository has no registry ref, and the last good
256 files stay in place (`identity/registry.go`).
257- The integrator refuses a request named for a change that has no record. It does not judge a
258 request whose target is missing, and a withdrawn change does not void such a request. A request
259 with no memo has none, and the signers publication is written when there is none yet. It reads
260 evidence through the objects its refs held when it listed them. A request that is gone when the
261 integrator lands its head is not reported as moved, and the landing's transaction does not touch
262 it (`integrator/`).
263- The integrator reads the floor at `--instance-ref` (`composed/composed.go`). The restacker takes
264 only the `git ls-remote` line that names that ref exactly (`restack/main.go`). An instance
265 repository with no such ref has no floor, and the pass is refused.
266- The web publisher reads the instance repository's `main`, its project list and its registry ref
267 with `readaccess.ResolveRef`. It refuses an instance repository with no `main` or no project list.
268 It reads a project's `main` the same way, at the object it staged
269 (`web/cmd/valley-web-publish/valley.go`).
270- `valley-read-coverage` reads the registry ref, the project list and each project's `main` with
271 `readaccess.ResolveRef` (`readaccess/cmd/valley-read-coverage/main.go`).
272- The check worker reads its own evidence ref exactly, and fetches the floor at the commit the
273 owning valley's `refs/heads/main` names (`status/worker.go`). `valley ready --stamp` finds no
274 local branch when the one it names is missing (`status/ready.go`).
275- `valley review`, `valley approve` and `valley checks` read `origin/main` and the change's branch
276 by their exact names (`status/review.go`, `status/approve.go`, `status/checks.go`). approve reads
277 `origin/main` once, and reads the merge base and both policy layers at that commit. The floor is
278 fetched at the commit the owning valley's `refs/heads/main` names. A request ref missing on origin
279 is missing, whatever a branch named like it holds.
280
281The identity compiler, the integrator and the restacker refuse a configured ref that is not a full
282ref name, such as `main`.
283
284`git push` matches the ref it writes the same way. With `<ref>` missing on origin, a push to `<ref>`
285writes a branch named `<ref>` instead, and with both present git refuses the push as ambiguous.
286`valley approve` reads origin before it pushes. While origin holds a ref whose name ends in the
287request ref's or an evidence ref's name, approve pushes nothing and names that ref (`implemented`).
288On the valley host, the hook refuses such a push rather than writing it, because the ref it would
289write is named like another ref (`implemented`, `valleyhook/policy.go`). The other programs that
290push do not check origin for such a ref before they push (**not built**).
291
292Checks: `identity-e2e` compiles with `refs/heads/registry` missing and a forged registry at
293`refs/heads/refs/heads/registry`, and the compilation fails with the files unchanged.
294`integrator-unit`, `restack-unit`, `web-unit`, `readaccess-unit`, `valley-ready` and
295`valley-request` each make the ref git would read in place of a missing one, and show that the
296program ignores it. `integrator-unit` deletes an evidence ref after the integrator lists it.
297`valley-request` approves with a branch on origin named like the request, with a tag named like the
298remote-tracking ref of `main` or of a branch that origin lacks, and with an owning valley whose
299`main` is missing. It also runs the check worker with a tag named like the worker's own evidence
300ref. `protect-e2e` and `valleyhook-unit` check the hook's refusal.
301
302## A wakeup grants nothing
303
304The check worker's wake mark is an empty file, `due`, in a directory the host makes (`implemented`,
305see [The worker's wakeups](architecture.md#the-workers-wakeups)). Only the git user and the
306integrator's user can create it, through the `valley-worker-wake` group. The worker never reads its
307contents. A mark only starts a pass sooner. The pass decides what to build from the refs it reads
308over SSH, and pushes what it builds through the pre-receive hook, as any pass does. The directory
309gives the worker no access to the repositories on disk, and the worker stays out of the repository
310group. A forged or repeated mark costs one pass that reads every project and builds nothing new. The
311unauthenticated bus starts no pass: nothing consumes it.
312
313## A move of main starts one unit
314
315A host's `services.valley.onMain` bindings start services of the host's own when a project's `main`
316moves (`implemented`, see
317[A host's own unit when main moves](architecture.md#a-hosts-own-unit-when-main-moves)). The host's
318NixOS configuration declares each binding, and the operator changes it there.
319
320Each binding's bridge runs as a Unix user of its own, `valley-on-main-<name>`, which holds no grant
321over any unit: the system manager refuses it a start, stop or restart of its bound service, or of
322any other. It can only write a commit file and a request file in its runtime directory; the system
323manager's path unit starts the bound service while the request exists. The integrator, the worker,
324the restacker and the git user gain nothing.
325
326The bridge runs in the git group, which reads every repository and writes the integrated ones. Its
327unit sees the data directory as an empty read-only file system, with only its repository bound in
328read-only, and the host's key files are out of reach.
329
330The bridge's user never writes the service's environment. systemd imports every assignment in an
331environment file, so a user that could write one would choose the service's loader and interpreter
332settings, and the service may run as root. The service's first command, run as root, removes the
333request, accepts the commit file only as one commit ID, without following a symbolic link, and
334writes the environment file into `/run/valley-on-main/`, which only root can write. The repository
335path in it is the module's. So a compromised bridge can only have its bound service started, for a
336commit it chooses, as often as the service's start limit allows. A service that deploys should check
337that the commit is one it expects. The bridge reads no event from the bus, which is unauthenticated:
338a forged event starts nothing.
339
340Checked by `onmain-e2e`, where the bridge's user and the git user are refused a start of the bound
341service, and the bridge's user another service, a stop and a restart, and where an assignment the
342bridge's user adds to the commit file fails the service's start without starting it again. Checked
343also by `onmain-unit`, which refuses every commit file but one commit ID, and by `module-eval`.
344
345## Who can read telemetry
346
347Telemetry is read and reported over the git user's SSH route, by principals the host names
348(`implemented`; who is named is a `deployment choice`, `services.valley.telemetry`).
349
350- **The principal comes from the key.** The git user's shell derives it from the key sshd
351 authenticated, as it does for a push, and drops any principal the session's environment names. An
352 untagged key has no principal and gets nothing.
353- **Two grants, each for itself.** `observe` reads every source. It is host-wide, because the shared
354 units' logs span every project, and a project's read consent does not imply it. `report` sends
355 records about the sender's own runs and reads nothing. The grants are in a file the host module
356 writes from `services.valley.telemetry`; the identity registry grants neither.
357- **A closed command.** The shell parses the telemetry command whole and refuses anything else. A
358 refused command reaches nothing: neither `git-shell` nor the collector. There is no path, unit
359 name, pattern, environment or service control in the interface. Reading works while pushes are
360 held, and a forced-command key still runs only its forced command.
361- **One local peer.** The collector's socket is the git user's alone (mode 0600), and the collector
362 checks its peer is that user. Anything that runs as the git user could connect and name any
363 principal. The shared git account is one trust boundary, and the socket is not a second one inside
364 it.
365- **An unprivileged collector.** The collector runs as its own user in a sandbox that can write only
366 its state directory. It is in the `systemd-journal` group, so its account can read the whole
367 system journal; its code asks only for the units the manifest names. It reads unit properties from
368 a fixed list, which leaves out the environment. It holds no key and no grant on the repositories,
369 and cannot enter the worker's private directory. The git user is in none of its groups, and cannot
370 read the diagnostics on disk.
371- **Reports are claims.** A report is stored under the principal the shell derived and the time the
372 host received it. The sender's own times are kept as the sender's, and a field the format does not
373 have, a principal, a receipt time or a host producer's record type is refused. A report is bounded
374 in size and count, and each reporter's stream in bytes, so no reporter can fill the host's disk.
375- **Output is untrusted.** Build and service output is whatever a check author or a program printed.
376 It is shown only with `--logs`, marked untrusted, with every control character escaped. Observing
377 shared logs is a privilege: nothing promises that a project's build output holds no secret.
378- **Telemetry decides nothing.** No record is evidence, and nothing reads one to approve, land or
379 build anything. Losing telemetry loses observations and nothing else: approval, pushes, checks,
380 the worker and the integrator go on without it.
381
382## Trust roots
383
384The operator's trust roots are hardware keys that the deployment supplies (**deployment choice**):
385
386- **Two hardware keys**, a primary and an offline backup. Each holds every role: an approve key that
387 needs a touch, and a release signing key that needs a PIN and a touch. No gate uses these keys
388 yet, because the gates of steps 3 and 4 are **not built**.
389- **An offline root for trust-root changes**, such as a Tillitis TKey. `sigverify` has a
390 `tkey-signer` class for it (`implemented`). Nothing uses one for trust-root changes yet (**not
391 built**).
392
393## What a client trusts to read a landing
394
395A client decides that a version landed through a commit the integrator wrote (`landed-recorded`) by
396verifying the integrator's transfer statement. It verifies the statement with a known-signers file
397and the integrator's signing name. By default it reads both from the host's publication at
398`refs/the-valley/signers` in the instance repository (`implemented`; see
399[the signers publication](./architecture.md#the-signers-publication)).
400
401That publication is project storage, not source. No change, review or check governs it. The client
402trusts it for a different reason: only the host's machinery writes it, never a push. The push hook
403refuses every push to it (`implemented`, checked by `signers-e2e` and `publish-e2e`). On the host,
404the publisher writes it from the file and the name the controllers use (`implemented`, checked by
405`signers-e2e`). The integrator can write it too, because the instance repository is group-writable
406and the integrator is in that group to land code there (`implemented`, `nix/valley-host.nix`). So a
407client that reads it trusts the host's disk, the host's configuration and the integrator. It already
408trusts the same host to serve `main`, and the same integrator to decide what lands on it.
409
410A revocation reaches clients through the publication. Once the registry lets no key sign, the
411compiler writes a known-signers file with no key in it, and the host publishes that file. A client
412then verifies no transfer statement with the revoked keys (`implemented`, checked by `signers-e2e`).
413What a client remembers of a verified statement does not outlive its key: the client opens the note
414under the current file on every read (`implemented`, checked by `signers-e2e` and `rebase-unit`).
415Someone who can write the user's cache directory can skip a statement's digest and merge checks, but
416cannot make a statement count that the integrator did not sign and its records do not bind. Two runs
417of the publisher take turns under a lock, so a run that read the file before a rotation cannot
418publish it over a run that read it after (`implemented`, checked by `signers-e2e`).
419
420The publication also carries the approval signers files and the instance identity, so a client can
421show who may approve in which instance (`implemented`, checked by `integrator-unit` and
422`module-eval`). The publication gives an approval no authority: a gate that enforces approvals reads
423the host's own files (**not built**). The publisher runs when a published input changes, reads every
424input again after each publication, and publishes again until nothing it read has changed. A change
425made after a run's last reading waits for the next change to a published input, since systemd misses
426a change made while the run is under way (see
427[The signers publication](./architecture.md#the-signers-publication)). Until that next run, a client
428can show a revoked key as valid. So after revoking a signing or approval key, the operator confirms
429the publication: compare `known-signers`, `approval-signers` and `approval-signers-hardware` at
430`refs/the-valley/signers` in the instance repository with the compiled files, and start
431`valley-signers.service` by hand if they differ. A host that configures no approval keys publishes
432empty files rather than keeping old ones. A clone of the instance repository derives the same
433identity, so instances that share history, project names and approval keys share approvals.
434
435The client finds the instance repository through `policy/valley` at `main`'s tip on origin, which is
436integrated source. A change that lands a new `policy/valley` points clients at another repository's
437publication. A flag or a variable set on the client replaces the publication for the value it gives.
438The restacker reads neither the publication nor the variables, only its own flags.
439
440A wrong publication cannot by itself make a version read `landed-recorded`. That also takes the
441integrator's landing record for the version's head, or for a landing made before landing records
442existed, its outcome record, saying the head landed as that commit. No push may write either record
443(`implemented`, checked by `protect-e2e` and `valleyhook-unit`). A wrong publication can make a real
444landing read `uncertain`.
445
446## Who can read a project
447
448Read access to a project requires two consents ([Read access](./architecture.md#read-access)). A
449project's own `policy/read` names the principals allowed to read it. The instance's identity
450registry grants principals read access at an `edge-read` boundary, for named projects or for all
451projects. Both consents must match, so the project's policy and the instance's registry each hold a
452key (`implemented`, `readaccess/access.go`).
453
454- **`anyone`**, the reader who presents no credential, is authorized at an edge for the projects
455 whose `policy/read` names `anyone` and which a read grant to `anyone` covers at that destination
456 (`implemented`).
457- **A named principal**, including the operator, is evaluated by the same two-consent rule in
458 `readaccess/`. When started with `--origin`, `valley-web` serves a request that carries a valid
459 session cookie as that session's principal (`implemented`). `valley-web` builds each response from
460 the projects its reader may see: those the stored authorization lets `anyone` read, together with
461 those it lets the reader's principal read (`implemented`, `web/server/plan.go`).
462- **Membership, push access, approval and restacking** grant no read access at the edge.
463
464Which principals each project's policy names and which grants the registry declares are a
465**deployment choice**.
466
467**What reaches the edge.** A project reaches the edge only under two consents: its `policy/read`
468names a reader, and a read grant at the destination's `edge-read` boundary covers that reader for
469the project (`implemented`, `web/cmd/valley-web-publish/valley.go`). A reader with both consents is
470an effective reader of the project. For a principal with no keys, such as `anyone` or a reader who
471holds only read links, an `edge-read` grant is the only grant it may hold. A publisher pass exports
472every project that has an effective reader — including a project that only named principals may
473read, and no other project — in one shared export for all readers of the edge. A separate signed
474authorization names each exported project's readers, and the edge serves a project only to them
475(`implemented`, `web/cmd/valley-web-publish/policy.go`; see
476[The authorization decides what is served](#the-edges-receiver)). A read grant at an `edge-read`
477boundary is consent to send a project's reader view to the destination that boundary names.
478
479**Exported knots.** A project's knots and comments are exported with it, so a reader of a project
480reads all of its plan and discussion. For each exported project, the export and bundle hold the
481project's reader view in plaintext: every knot and comment in its plan graph, its ready changes, and
482`main` with its history (`implemented`, `web/export/project.go`). No knot is exported to some of a
483project's readers and not to others.
484
485**An edge compromise discloses every exported project.** Once an export is sent to an edge, that
486edge is the security boundary for what it holds. Its administrators, and any process with access to
487its storage, can read every exported project, whoever its readers are, and any withdrawn material
488the edge still keeps. Activating a newer export changes which generation the edge serves. It does
489not guarantee that an older generation is deleted: the edge's store keeps a generation that a reader
490still holds, or whose deletion failed, until a later sweep removes it (`implemented`,
491`web/export/store.go`). Withdrawing a project stops the edge from serving it. It does not delete the
492project from the edge's storage: its text stays in the active export until a later content pass
493replaces it.
494
495**Groups place exported projects and grant no read access.** A project reaches the edge only when
496`valley.cue` places it in a group, because a project without a group has no web URL. Placing a
497project in a group gives it a web URL once it has an effective reader. Omitting `group` keeps a
498project off the web even when it has effective readers. The export includes only groups that have at
499least one exported project, along with the web names, former names, and short aliases of exported
500projects (`implemented`, `web/export/project.go`). Groups with no exported project are omitted, and
501so are the web names, former names, and short aliases of projects that are not exported. The web
502server reads only the export. Requests for a project the reader may not see — whether under its
503group, another group, a former name, or a short alias — return the same `404` page byte for byte as
504requests for a project that does not exist (`implemented`, `web/server/server.go`). A group alias
505redirects any path under it to the group's `name` before checking whether the project exists, so
506hidden and nonexistent projects redirect identically and then return `404`.
507
508**Each response holds one reader's projects.** A project the reader may not see adds nothing to the
509reader's pages: no link, no navigation entry, no alias or former name, no redirect, no source route,
510and no title, status, or reference text of its knots (`implemented`, `web/server/projection.go`,
511`web/server/knot.go`). The server builds the reader's pages from copies of the projects in the
512reader's view. In those copies, each knot keeps the `state` that the host derived, while references
513into other projects are removed from its derived lists and cleared in its edges (see
514[Each reader's view](./architecture.md#each-readers-view)). Before looking up a referenced project,
515a page checks that the entire reference value matches a shape allowed for its field, so a malformed
516value that begins with a visible project name names nothing either. What the reader learns of a
517hidden blocker matches what the export already exposes for everyone: a single opaque "a knot in an
518unpublished project" while the blocker remains open. Readers who may see the same projects share one
519index, and neither the index nor the pages built from it ever name the reader. Because the export on
520the edge includes projects readable only by named principals, this view filter is what hides those
521projects from other readers.
522
523**Authored text is published as written.** The view filter removes only what the server derives
524about other projects. It cannot remove private information that an author wrote into a visible
525project: a knot's body or comment, a README, or an absolute link is shown as written. Writing about
526a private project inside a public one discloses it.
527
528**Responses are private, and carry no active content.** Every response, including a redirect, an
529error page, a `HEAD` response, and an archive, carries `Cache-Control: private, no-store` and
530`Vary: Cookie`, carries no `ETag`, and is never answered `304` (`implemented`,
531`web/server/server.go`). No shared cache therefore stores one reader's response for another. Each
532route has its own `Content-Security-Policy` (`implemented`, `web/server/render.go`): the knots pages
533admit their one inline script by its SHA-256 hash, every other route admits no script, and no route
534lets a script open a network connection. Rendered Markdown writes only a fixed set of elements and
535attributes, escapes the repository's text, and writes no script, form, image, or `style` attribute
536(`implemented`, `web/markdown`). `Referrer-Policy: no-referrer` keeps a link leaving the edge from
537sending the page's address. An archive is a gzipped attachment sent with `nosniff`, and no
538repository file is served inline. Serving active project content would require a separate origin
539that never receives a reader's cookie, because another path on the same origin would not isolate it.
540
541**A grant is bound to a project.** A grant that names a specific project binds both its name and its
542publication identity, so a new project that reuses an old project's name with a new identity is not
543covered by the old grant. A policy is valid only for the project repository it is read from. A
544policy or registry that is missing, fails schema validation, or exceeds its size bounds consents to
545nothing (`implemented`, `readaccess/read.go`).
546
547**The registry is read at its ref by that exact name.** The publisher and `valley-read-coverage`
548resolve the registry ref with `git show-ref`, which checks that exact full ref name (`implemented`,
549`readaccess/read.go`). `git rev-parse` is not used to resolve ref names, because when a ref such as
550`refs/heads/registry` is missing it falls back to `refs/heads/refs/heads/registry`, a branch any
551pusher can create. Instead, `git show-ref` resolves the ref name to an object ID, `git rev-parse`
552peels that object ID to a commit, and all subsequent reads use that commit ID. When the configured
553registry ref is not `refs/heads/main`, an instance repository without it has no registry, so no
554project is exported. A repository without `refs/heads/main` cannot be an instance repository, so
555when `refs/heads/main` is missing the publisher aborts the pass instead of building an empty export
556(`implemented`, `web/cmd/valley-web-publish/valley.go`). The host module rejects a
557`services.valley.identity.ref` that is not a full ref name (`implemented`, `nix/valley-host.nix`).
558
559**SSH fetches ignore read grants.** Read grants govern only web exports. On the valley host, every
560SSH key admitted for the git user can fetch every repository (`valleyhook/shell.go`). The git user's
561shell gates pushes and leaves fetching open. An admitted key without a principal tag runs as no
562principal (`VALLEY_PRINCIPAL` stays unset), whereas `anyone` applies only to unauthenticated edge
563reads.
564
565**Withdrawal.** When a project loses its last effective reader, the next pass's policy path signs an
566authorization that omits the project and sends it to the receiver before any content work begins
567(`implemented`, `web/cmd/valley-web-publish/policy.go`). When it loses one of several readers, the
568authorization drops that reader alone, and the project stays for the others. The receiver stores the
569authorization without waiting for any content upload or commit, and `valley-web` stops serving the
570project — or, unless `anyone` may still read it, stops serving it to the removed reader — on the
571next request (`implemented`, `web/export/authorize.go`, `web/server/server.go`). The policy path
572reads only the instance repository, the identity registry, and the `main` branch and `policy/read`
573of each project a read grant selects. Because it reads no plan graph or knots, a broken or
574unreadable plan graph cannot delay a withdrawal. If a selected project's own policy cannot be read,
575the project keeps only the readers from the last acknowledged authorization that a current grant
576still covers under that authorization's publication identity. That kept access applies only while
577the receiver still holds that acknowledged authorization, and the project gains no reader.
578Withdrawals for other projects still take effect (`implemented`,
579`web/cmd/valley-web-publish/policy.go`, `web/export/authorization.go`). A publisher state restored
580from an older backup keeps no such access. Projects that no read grant selects are not read
581(`implemented`, `web/cmd/valley-web-publish/read_test.go`). If the instance repository or the
582registry cannot be read, the pass signs no authorization, and the withdrawal waits for a later pass
583that can read them.
584
585**Growth never blocks a restriction.** A receiver reads an authorization of at most 256 KiB, and the
586publisher signs nothing larger (`implemented`, `web/export/authorization.go`). An authorization
587grows with every project, reader, and read link it names. When the full authorization would exceed
588the limit, the pass signs and sends a bounded fallback in its place: the last authorization the
589receiver acknowledged, minus every project, reader, and read link that the current check does not
590allow. The fallback adds nothing. It carries the next sequence and the check's `basis`, just as the
591full authorization would, so the receiver admits it. A withdrawal or revocation that coincides with
592growth therefore still reaches the edge. The pass then fails, naming the overflow and the pending
593additions, and no addition reaches the edge until the authorization fits (`implemented`,
594`web/cmd/valley-web-publish/policy.go`).
595
596A pass signs the full authorization only when its signed size leaves 64 bytes of room under the 256
597KiB limit. Those 64 bytes cover a longer `sequence` and an added `basis` record in a later fallback.
598Because an authorization that the receiver admitted earlier may have been signed without that room,
599the pass measures the fallback before signing it, and never assumes that it fits. When the fallback
600itself exceeds the limit, the pass restricts it further, one access at a time, until it fits. It
601drops access in this order:
602
6031. Projects kept only on the `basis`, such as a project whose policy could not be read.
6042. Readers, each time from the project with the most remaining readers.
6053. Read links.
6064. As the last resort, the pass sends an authorization that grants nothing. It always fits, and it
607 fails closed.
608
609Each step only removes access, so the restriction costs availability and never confidentiality. The
610pass fails, and it names every access the restriction dropped beside the pending additions
611(`implemented`, `web/export/authorization.go`, `web/cmd/valley-web-publish/policy.go`).
612
613Authorizations have no serving expiry: while the valley host cannot reach the edge, the edge
614continues serving what the stored authorization allows. Once the host reaches the edge again, the
615next pass re-evaluates the policy and sends a fresh authorization, which takes effect even if the
616pass's content upload fails. Unbuilt parts of read access are listed in
617[Not deployed or not wired yet](./architecture.md#not-deployed-or-not-wired-yet).
618
619Checks: `readaccess-unit` reads both consents from real commits under the real schemas, including
620policies that redeclare a schema definition and trees with malformed entry names. `web-server-unit`
621serves `anyone` and two named readers over signed fixtures holding private projects
622(`TestNamedReadersSeeTheirOwnProjects`), compares a knot whose hidden blocker is done or open across
623an export without the blocker's project and one holding it for another reader
624(`TestAHiddenBlockerReadsAlikeInEitherExport`), and checks every route's headers
625(`TestEveryResponseCarriesItsRoutesHeaders`). It also serves the real publisher's output to `anyone`
626and to each named reader (`TestThePublishersOutputServesEachReader`), verifying that two named
627readers see different private projects and that no page names a private project to a reader who may
628not see it. That test injects each reader's principal into the request, and uses no link or session.
629`web-push-e2e` checks the headers on the packaged `valley-web`, sends a project two named readers
630may read to the edge with both in its authorization, keeps a project with no effective reader off
631it, and answers anonymous requests for both with `404` on every route. It also signs a named reader
632in with a link. The session follows `/` to the projects page, finds that project there, and reads
633its tree page, its knots page, its knot, its archive and the knots page of every project. Anonymous
634requests for that project's tree page, knots page, knot page and archive answer `404`, anyone's
635projects page does not list it, and anyone's knots page leaves its knot out. Once a pass delivers
636the link's revocation, the test checks only that the session gets `404` for the project's tree page.
637`web-unit` verifies that the publisher requires both consents and authorizes each project's
638effective readers (`TestVisibilityNeedsBothConsents`) and that no private sentinel appears in any
639export or bundle (`TestPrivateSentinelsNeverLeave`). Both `web-unit`
640(`TestTheRegistryIsReadAtItsRef`) and `readaccess-unit` (`TestRegistryRef`) verify that no project
641is exported when the registry ref is missing even if `refs/heads/refs/heads/registry` grants
642`anyone` read. `module-eval` rejects a short registry ref. `cue-vet` and `identity-schema` test both
643schemas against their rejected examples.
644
645## The web publisher
646
647`valley-web-publish` runs on the valley host and uploads signed exports of every project with an
648effective reader to the edge. It reads local repositories, signs each manifest with its own key, and
649connects out to the receiver. Nothing on the edge connects back to the valley host.
650
651**Only projects with an effective reader leave the host.** A pass exports a project only when three
652conditions hold: the project's `policy/read` names a principal, a read grant for the destination
653covers that principal for the project, and the host declaration places the project in a group
654(`implemented`, `web/cmd/valley-web-publish/valley.go`). The principal may be `anyone` or a named
655principal. A project that only named principals may read reaches the edge's store, and the edge
656serves it to those principals alone (see
657[What reaches the edge](./architecture.md#what-reaches-the-edge)).
658
659**The export key signs every manifest.** On its first start, the publisher generates an Ed25519 key
660in its state directory and writes the key's verifier line beside it under the signing name
661`<instance>/web-export` (`implemented`, `web/cmd/valley-web-publish/state.go`). The receiver admits
662only manifests that open under a verifier line it pins. Pinning that verifier line on the edge is a
663**deployment choice**. On NixOS, the state directory belongs to the unit with mode `0700`
664(`implemented`, `nix/web-publisher.nix`).
665
666**The pass runs confined.** On NixOS, the publisher's two units, the pass and the policy path alone,
667run as one dynamic user, `valley-web-publish`, in the `git` group (`implemented`,
668`nix/web-publisher.nix`). They share the state and cache directories, so the shared user keeps one
669unit's start from changing the directories' owner under the other's running pass. The host
670repositories are mounted read-only, and the host filesystem is read-only except for the unit's state
671and cache directories and its private temporary directories. The `git` user's SSH identity and the
672host's signing, mirror, and backup keys are mounted inaccessible. The unit's `safe.directory` list
673names only the repositories the host declares. The unit can still read the host's other repositories
674through the filesystem. The full filesystem sandbox is **not built**.
675
676**The pass connects only to allowed IP addresses.** The unit denies all IP traffic
677(`IPAddressDeny=any`) and allows only the addresses in
678`services.valley.webPublisher.allowedAddresses` (`implemented`, `nix/web-publisher.nix`). The module
679refuses to build when `allowedAddresses` is empty. A pass reads local repositories and runs `valley`
680commands that use no network, so it needs to reach only the receiver. Which receiver addresses to
681list is a **deployment choice**. The upload client connects directly to the receiver and ignores
682proxy environment variables such as `HTTPS_PROXY` (`implemented`,
683`web/cmd/valley-web-publish/upload.go`).
684
685**The unit checks that the IP filter is active before each pass.** When the kernel or service
686manager lacks cgroup BPF support, systemd logs a warning and leaves `IPAddressDeny` and
687`IPAddressAllow` unenforced. Before each pass, the unit therefore runs
688`valley-web-publish-egress-check` inside the unit's own cgroup (`ExecStartPre`, `implemented`,
689`nix/web-publisher.nix`). The check sends a UDP datagram to `198.51.100.1` port `9`, an address the
690filter must block. The pass starts only when that send fails immediately with `EPERM`. If the
691datagram goes out or fails with any other error, the check aborts the pass and logs the reason. The
692module refuses `allowedAddresses` entries that cover `198.51.100.1`. The host needs a route to
693`198.51.100.1`, such as a default route, so the datagram reaches the cgroup filter instead of
694failing earlier with no route. The check uses UDP because the cgroup filter returns `EPERM` on
695`send` at once, whereas a dropped TCP SYN waits for a connection timeout.
696
697**Host names resolve outside the unit.** The unit sets `GODEBUG=netdns=cgo` so the publisher
698resolves host names through the C library instead of Go's built-in resolver (`implemented`,
699`nix/web-publisher.nix`). `nix/packages.nix` builds the publisher with cgo enabled. On NixOS, the C
700library queries `nscd` over a local Unix socket, and `nscd` sends the DNS query from outside the
701unit's cgroup. When `nscd` is enabled (`services.nscd.enable`, on by default in NixOS; a
702**deployment choice**), `allowedAddresses` needs only the receiver's addresses. If `nscd` is
703disabled, the C library sends DNS queries from inside the unit, and the filter blocks them unless
704`allowedAddresses` also includes the DNS resolver.
705
706The cgroup filter checks only the destination IP address. It permits every port on an allowed
707address and checks the resolved address independently of the host name in `--receiver`.
708
709Checks: `module-eval` verifies the unit's IP filter, `ExecStartPre` check, `GODEBUG` setting,
710filesystem confinement, and credentials, and verifies that evaluation fails when `allowedAddresses`
711is empty or covers `198.51.100.1`. `web-publisher-e2e` boots a NixOS VM and runs the rendered unit
712with a probe script in place of the publisher. Inside the unit, the egress check passes; run by root
713outside the unit, the same check fails because root's datagram reaches `198.51.100.1`. The probe
714verifies that Git accepts a declared repository and refuses an undeclared repository as dubiously
715owned. It verifies that repository writes fail and that the git SSH key, backup SSH key, and raw
716token file cannot be read. It also verifies that the unit can connect to a listener on its allowed
717address, and that the C library resolves a name served by a DNS server on a disallowed address.
718
719## The edge's receiver
720
721`valley-web-receive` accepts uploads from the publisher on the edge, and `valley-web` serves the
722active generation (see [The receiver](./architecture.md#the-receiver)). Two independent checks guard
723an upload.
724
725**The authorization decides what is served.** The receiver stores an authorization only when it
726opens under a pinned verifier, carries the authorization's type line, names the receiver's instance
727and destination, and carries a sequence greater than the stored one's (`implemented`,
728`web/export/authorization.go`). It accepts an authorization regardless of age, so no clock fault
729holds up a narrowing. `valley-web` reads the stored authorization on every request and again before
730each response's headers, under a lock that the receiver takes to replace the authorization. It
731serves a project only while the authorization names the project with the export's identity for it
732(`implemented`, `web/server/server.go`). A missing or invalid authorization serves no project. A
733content manifest names no reader. The receiver builds a repository only for a project the
734authorization names, and content never repairs or replaces the authorization. No content upload,
735however late, grants or restores access (`implemented`, `web/export/store.go`). The guarantee covers
736every response whose headers are written after the receiver replies (`implemented`,
737`web/export/authorize.go`). A response whose headers were written before continues to completion.
738
739**A withdrawn project's plaintext stays until it is replaced.** After a withdrawal, the receiver
740deletes the project's repository once no reader holds the active generation (`implemented`,
741`web/export/authorize.go`). The signed `export.json` keeps its bytes, so the project's plan text
742stays on the edge's disk until a later activation replaces the generation and the old one is
743deleted. Withdrawal hides a project from readers while leaving its plan text in the active
744`export.json` until the next activation.
745
746**The manifest's signature decides what content the edge holds.** The receiver stages a manifest
747only when it opens under a pinned verifier, names the receiver's instance and destination, and
748carries a sequence newer than any accepted sequence (`implemented`, `web/export/manifest.go`). It
749keeps only bodies whose size and SHA-256 the manifest declares, and activates a generation only when
750every bundle passes acceptance (`implemented`, `web/export/body.go`, `web/export/bundle.go`). Only a
751holder of the publisher's export key can put content or an authorization on the edge. The bearer
752token grants upload access alone.
753
754**A rollback of the edge serves nothing from the store.** The store's entry point is a descriptor
755file (`store`), which binaries of the first store layout refuse. Its payloads live under `v2/`,
756which those binaries never read (`implemented`, `web/export/store.go`). Neither a rolled-back binary
757nor a missing authorization can serve the store's content. The receiver deletes nothing outside its
758descriptor and `v2/` (`implemented`), so the first layout's state stays beside the descriptor until
759the operator deletes it by hand. It held public projects only, and a rolled-back binary pointed at
760it serves that old public export.
761
762**The token decides who may use the receiver.** Every request must carry the bearer token in its
763`Authorization` header. The receiver checks the header before reading the request body and refuses
764an unauthenticated request as `unauthenticated` (`implemented`,
765`web/cmd/valley-web-receive/receive.go`). A stranger who reaches the receiver cannot trigger
766manifest verification, stream a body into staging, or start a commit. A holder of the token without
767the export key can spend the receiver's staging and request capacity up to its caps, while what the
768edge serves stays signed by the publisher.
769
770**The token stays out of the Nix store and out of `valley-web`'s reach.** On NixOS, both modules
771load the token file as a systemd credential for their own unit from a path outside the Nix store,
772and both refuse a store path at evaluation time (`implemented`, `nix/web-publisher.nix`,
773`nix/web-receiver.nix`). `valley-web` runs as a separate user without that credential. The publisher
774refuses HTTP redirects, so it sends the token only to the configured receiver URL (`implemented`,
775`web/cmd/valley-web-publish/upload.go`). Neither program prints the token. Where a container host
776stores the token file, and who can read it there, is a **deployment choice**.
777
778**The token stays secret only on an encrypted or private network path.** Every upload request
779carries the token. Whether the publisher reaches the receiver over HTTPS, through a TLS-terminating
780reverse proxy, or over a private network is a **deployment choice**. Sending requests over plain
781HTTP across an untrusted network exposes the token to anyone who can read that network.
782
783**`valley-web` has read-only access to the store.** It opens the store read-only and writes nothing
784there (`implemented`, `web/export/store.go`). On NixOS its unit mounts the state directory read-only
785(`implemented`, `nix/web-receiver.nix`). Its other writable paths are temporary: its private `/tmp`
786and `/var/tmp` from `PrivateTmp` (hidden from other units and removed when the unit stops) and
787`/dev/shm` from `PrivateDevices` (`implemented`, `nix/web-receiver.nix`). Those temporary paths are
788separate from the state directory, and the receiver ignores them. A fault in `valley-web`, which
789handles requests from arbitrary readers, reaches neither the staging area nor the token.
790
791**`valley-web` writes one directory of its own: the browser state.** When `--origin` is set,
792`valley-web` writes `browser/` inside the state directory and writes nothing else (`implemented`,
793`web/readerstate/`). On NixOS, `valley-web.service` can write only `<stateDir>/browser` (besides its
794temporary paths), and `valley-web-receive.service` cannot access `<stateDir>/browser`
795(`deployment choice`, `nix/web-receiver.nix`). `browser/` stores each redeemed link's credential ID,
796the principal and verifier it was redeemed under, and the SHA-256 hash of its session token. It
797never stores a link secret or a raw session token. With write access to `browser/`, a faulty or
798compromised `valley-web` can do these things and no more:
799
800- It can sign readers out, refuse to redeem a link, or make every session unusable.
801- It can make a link redeemable again by deleting its record from `browser/state`, but only while
802 the host's signed authorization still binds that link.
803- It cannot grant any session more access than the stored authorization allows for that session's
804 principal. It cannot modify the authorization, an export, or a repository, and it cannot read the
805 receiver's token.
806
807Because `valley-web` already has read access to the entire store, a fault in `valley-web` could
808already serve anything in the store. Writing `browser/` adds no read access beyond that.
809
810**Link secrets and session tokens stay in `valley-web`'s memory.** A redemption `POST` carries a
811link's secret, and every authenticated request carries a session token. When started with
812`--origin`, `valley-web` marks its process non-dumpable before opening `browser/` or listening, and
813refuses to start if it cannot (`implemented`, `web/nodump/`). That prevents core dumps and stops
814other processes running as the same user from reading `valley-web`'s memory through `ptrace` or
815`/proc`. On NixOS, `valley-web.service` also sets `LimitCORE=0` (`deployment choice`,
816`nix/web-receiver.nix`).
817
818Checks: `web-receiver-unit` verifies that the receiver refuses requests with no token, a wrong
819token, a non-Bearer scheme, or two `Authorization` headers before staging anything
820(`TestAnUnauthenticatedRequestIsRefused`), answers `OPTIONS *` with a withheld body immediately on
821every connection without reading the body (`TestOptionsStarHoldsNoConnection`), and refuses stale,
822future-dated, foreign-key, and foreign-destination manifests
823(`TestAManifestIsAdmittedOnlyWhenFresh`). It also verifies that the receiver stores an authorization
824dated long ago by its sequence, refuses a replayed authorization, and refuses a request of the first
825protocol (`TestAnAuthorizationIsAdmittedBySequence`). `web-unit` (`TestPublishesToTheRealReceiver`)
826verifies that a pass with a wrong token is refused while the edge keeps serving the active export,
827and (`TestStoreDescriptorLeavesTheFirstLayout`) that both store openers refuse a directory and that
828a new store deletes none of the first layout's state beside it. It verifies that a restored
829publisher state keeps no withdrawn access (`TestARestoredStateRestoresNoWithdrawnAccess`), and that
830a paused prune keeps a repository an authorization names again
831(`TestAPruneKeepsWhatAnAuthorizationNamesAgain`). `web-server-unit` verifies that a withdrawal takes
832effect at the next request, that a response rendered while the authorization changed is rendered
833again, and that a withdrawal stored while a response holds the serving lock returns only after that
834response's headers are written (`TestAuthorizationIsReadOnEveryRequest`,
835`TestAResponseIsHeldToTheAuthorizationWhenWritten`,
836`TestAWithdrawalWaitsForAResponseItsCheckAdmitted`), and that a request waits for a held serving
837lock only until its deadline or until its reader goes away
838(`TestAServingLockWaitEndsWithTheRequest`). `web-unit` verifies that the bounded fallback keeps only
839access both authorizations allow, and that an authorization over the limit is never signed
840(`TestNarrowKeepsOnlyWhatBothAllow`, `TestSignRefusesAnAuthorizationOverTheLimit`). It verifies that
841a fallback over the limit drops access in its order until it fits (`TestFitDropsAccessInItsOrder`).
842It verifies that a fallback narrowed from a stored authorization that filled the limit, with a
843project kept on the `basis` and a `sequence` one digit longer, still delivers a reader's withdrawal
844(`TestAFallbackOverTheLimitStillDeliversAWithdrawal`). It also verifies that when no nonempty
845fallback fits within the limit, the pass sends an authorization that grants nothing
846(`TestTheLastResortGrantsNothing`). `web-push-e2e` pushes an authorization past the limit with 1,800
847new readers while it withdraws a project, and checks that the withdrawal reaches the edge and the
848pass fails naming the overflow. It also withdraws a project with `--policy-only` while an upload is
849stalled, and checks that the stalled upload restores nothing and that a store with its authorization
850removed serves no project. `module-eval` verifies the credentials and users both modules render and
851rejects a token path in the Nix store. `web-publisher-e2e` verifies in a NixOS VM that the
852publisher's unit receives the token as a credential while the token file on disk stays readable by
853root alone.
854
855## Bearer read credentials
856
857The project accepts bearer read credentials for reading at an `edge-read` boundary. A read link, and
858the browser session it becomes, identifies one registry principal. Its authority is that principal's
859effective read grants, which need both the project's consent and an instance grant.
860
861- **No project scope:** A credential is bound to its principal only. What it reads changes as that
862 principal's grants and the projects' consents change.
863- **The operator's link:** The operator's link reaches every project the stored authorization lets
864 `anyone` read, plus the projects the operator's own grants and consents allow, and nothing more
865 (`implemented`, `web/server/plan.go`). No principal is special at the edge: the authorization
866 names the operator as a reader of exactly the projects the operator's own grants and consents
867 allow (`implemented`, `web/cmd/valley-web-publish/policy.go`).
868- **Lifetime:** A link secret works once: the edge permanently records each redemption, and no
869 authorization can reset it (`implemented`, `web/readerstate/`). A session has no server-side
870 expiry on the edge, and every `GET` or `HEAD` response that passes the final session check renews
871 the browser cookie for 30 days (`implemented`). The cookie uses the `__Host-` prefix with
872 `Secure`, `HttpOnly`, and `SameSite=Lax`. Like the link it came from, a copied session token
873 grants its principal's read access for as long as the session remains valid.
874- **Sessions follow the host:** A session remains valid only while the host's signed authorization
875 binds its link to the principal and verifier under which the link was redeemed (`implemented`).
876 Revoking a link ends its session as soon as the receiver stores the next authorization. If a later
877 authorization restores that exact binding (for example after restoring the valley host from a
878 backup), the session becomes valid again unless the reader signed out. Losing every read grant
879 leaves the session reading only what `anyone` may read. Signing out permanently removes the
880 session token's hash from the edge.
881- **Revocation:** The host can revoke one credential, every credential of a principal, or a read
882 grant (`implemented` on the host). Revocation reaches the edge with the next authorization the
883 receiver stores. Each pass reads the credential file as it signs, and carries the links the file
884 holds then (`implemented`). A revoke holds the links lock, which a pass holds from its read of the
885 file until it has signed, so once a revoke has finished, no pass signs the revoked link
886 (`implemented`). The lock lives in the credential file's root-owned directory, and root follows no
887 path the publisher controls to take it (`deployment choice`). A registry expiry removes the
888 principal's grants on the first policy pass after the date. Extending the date restores access
889 through the same unrevoked credentials.
890- **Restore:** Restoring the valley host from a backup restores its read links as they were when the
891 backup was taken. A link revoked after the backup is active again once the next pass delivers the
892 restored file (`implemented`). The project accepts this: going back to a backup restores the
893 access of that time. To cut off every link after a restore, the operator runs
894 `valley-web-link revoke --all`. After a loss of the edge's state, the operator revokes every link
895 and issues new ones.
896- **Edge state:** The edge creates an initial empty `browser/state` only when the stored
897 authorization contains no link bindings (`implemented`). Before `browser/state` is first created,
898 or after the edge loses `browser/state` or its whole volume, no link that the host had already
899 bound can be redeemed, so no already-used link becomes redeemable again. If `browser/state` cannot
900 be read, the edge leaves the file untouched and serves only `anyone` until the operator removes it
901 and re-initializes the state. Restoring an older, valid copy of `browser/state` onto the edge is
902 not detected: links redeemed after that backup was taken can be redeemed again while the host
903 still binds them.
904- **Limits:** These credentials never authorize push, approval, restacking, registry governance or
905 credential enrollment. Passkeys stay the route to anything beyond reading. A principal with no
906 keys may hold edge-read grants alone (`schema/identity.cue`, `implemented`).
907- **No edge-local emergency stop:** The edge's only access state is what the host signs.
908- **Placement:** The project's identity rules otherwise refuse bearer secrets, keep sessions short,
909 and give every bearer credential an expiry. These read credentials alone are exempt from those
910 three rules. Principals and grants stay in the registry. Credential verifiers live in protected
911 host state outside every repository, in a credential file that only root writes and that never
912 holds a secret (`implemented`). The secret of a new link never reaches a core dump: the link
913 command makes its process non-dumpable, and the wrapper sets `ulimit -c 0` (`implemented`). At the
914 edge, `valley-web` also marks itself non-dumpable, so posted link secrets and session tokens never
915 reach a core dump either.
916
917## Secrets
918
919The valley host needs a few secrets, and the deployment provisions each one as a file outside the
920Nix store (**deployment choice**; see
921[What a deployment supplies](./architecture.md#what-a-deployment-supplies)). They are the
922integrator's signing key, the git user's ssh key for mirror pushes, and the backup's credentials.
923
924A deployment must keep these secrets, and every key that decrypts them, out of agents' reach. Two
925properties of encrypted secrets bear on that:
926
927- A copy of any recipient's private key decrypts every secret encrypted to it, on any machine. When
928 secrets are encrypted to host keys, each host's key is a software private key that can decrypt
929 them.
930- Old ciphertext stays decryptable by every key it was encrypted to. A secret once encrypted to a
931 key that agents could read must be replaced with a new secret, not only re-encrypted.
932
933## What the operator does
934
935- Approves changes, with `[a]pprove` in `valley review` or with `valley approve`. Approving a change
936 files its integration request. This is the only act on this list that a check enforces (step 2).
937- Holds the hardware keys and manages the deployment's secrets.
938- Signs releases and approves protected path classes, once those gates exist (**not built**).
939
940## The autonomy ladder
941
942Automation grows in deterministic forms, under policy the operator signs. Agents never decide for
943themselves when to deploy.
944
9451. **Today.** An approved landing on `main` is the gate. A host that deploys from `main` deploys it
946 on its next run.
9472. **Signed releases** (**not built**). A signed release is the gate, and a landing does not deploy.
948 One touch and PIN signs a batch. Rollout through canaries, soak and rollback runs unattended.
9493. **A batched cadence.** A scheduled release promotes everything accumulated, and one touch signs
950 it.
9514. **Approved upstreams.** When a deployment's inputs, the-valley among them, land through
952 approval-gated integration, a change that only updates those inputs can land when its checks
953 pass. Those updates still ship through releases.
9545. **A delegated release signer.** A machine key in the release environment, out of agents' reach,
955 signs releases that touch only declared low-risk path classes. The operator signs that policy
956 with a touch. Entry criterion: a record of health-gated rollback catching real failures in
957 production, and a measured count of touches per week.
958
959## Residual risks
960
961- **Agents must not be able to land outside the valley.** If a host deploys from a repository on a
962 forge, an agent with merge rights there can deploy without an approval. A deployment gives agents'
963 accounts no merge rights on such a repository.
964- **Old secret ciphertext stays decryptable.** A secret encrypted to a key that agents could once
965 read stays readable with that key, in every copy of the ciphertext, until the secret is rotated.
966- **An escape from an agent VM on the valley host reaches the host.** The VM has its own kernel, and
967 an escape through KVM or the hypervisor reaches the host that runs the valley.
968- **Every key of the operator's principal holds `approve`.** Filing needs no touch until step 3 is
969 built.
970- **Check definitions come from the change.** A change can edit the flake check it is judged by,
971 though not the policy that requires it.
972- **Hosts must not update from an unsigned branch.** A host that upgrades itself from a branch
973 without a signature check deploys whatever reaches that branch. When the branch is on a forge
974 rather than on the valley, no gate in this document applies to it.
975- **Readiness is not enforced atomically.** A change paused in the moment before the integrator
976 moves the target can still land, at the head the operator approved (step 2).
977- **Every admitted key can fetch every repository.** Read grants govern web exports alone. Any SSH
978 key sshd admits for the git user, including an agent's key, can fetch any project on the valley
979 host.
980- **Additions wait while the authorization is too large.** While the full authorization is over the
981 256 KiB limit, each pass sends the bounded fallback and fails. No project, reader, or read link is
982 added at the edge until the operator brings the authorization under the limit. If the fallback
983 also exceeds the limit, the edge loses the access that the pass dropped to make the fallback fit
984 until the authorization is brought back under the limit.
985- **A withdrawal waits on reading the instance and the registry.** A pass that cannot read the
986 instance repository or its registry signs no authorization, and the edge keeps serving what it
987 has. A selected project whose own policy cannot be read keeps the readers from the receiver's
988 current authorization that a grant still covers, until a pass can read the project's policy.
989- **A withdrawn project's plan text stays on the edge's disk.** The signed `export.json` keeps a
990 withdrawn project's knots and comments until a later activation replaces the generation.
991- **A session's token is a bearer secret.** Anyone who copies a reader's session cookie can read as
992 that reader until the reader signs out or the host revokes the link. The edge enforces no
993 server-side session expiry.
994- **The receiver's token is a shared secret.** The publisher and the receiver share one bearer
995 token, and every upload request carries it. Anyone holding the token can fill the receiver's
996 request slots and staging area up to its caps, delaying uploads while the flood lasts. Plain HTTP
997 over an untrusted network exposes the token in transit.
998- **Anyone who reaches the receiver can occupy its connection limit.** An unauthenticated client can
999 open all 32 concurrent connections and hold each one for up to the 10-second header timeout,
1000 delaying uploads while the flood lasts. Which network peers can reach the receiver's listener is a
1001 **deployment choice**.
1002- **The bus has no authentication.** Any local process on the valley host can publish events.
1003 Nothing treats an event as authoritative.
1004- **Listing `integrator` in `protection.writers` opens a push path to `main`.** The integrator moves
1005 `main` on disk and needs no place in `protection.writers`. A deployment that lists `integrator`
1006 there lets any key tagged `integrator` push `main` directly. No declared or registry key may carry
1007 that tag.