gunk-dev/the-valley

security.md

sourcedd562cb7aff6main's published tip history
19.8 KiB · Rendered
1# Security and rollouts
2
3This document describes how the-valley and cosmo protect the operator's hosts. It follows the path a
4change takes, and names the gate at each step and its status. The components are described in
5[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
8Deployment records and host configuration below describe the reference deployment (**deployment
9choice**): `cosmo` is the reference NixOS fleet, `klaus` is the agent runner, `classic-laddie` is
10the primary valley host, and `qinling` is the instance repository.
11
12The document makes three kinds of statement:
13
14- **Behaviour** is what the code does, cited to the files that do it.
15- **A deployment record** reports an observation of a live host. It names its source and date, for
16 example the cutover record of 2026-10-04 in the plan's Status table.
17- **A guarantee** names the executable check that demonstrates it. A statement with no named check
18 is unchecked, and says so.
19
20The main threat is an AI agent acting as the operator. So the gates must hold even when an agent
21ignores its instructions. The human act of authority is a touch on a hardware key. An approval gate
22that the gated agent can administer is only a setting that agent controls
23([ida-b7025b5](../archive/.the-valley/ideas/ida-b7025b5-human-decisions-are-signed-acts.md)). A gate
24counts as done only when a check has shown it refusing what it should refuse
25([oc-9949561](../archive/.the-valley/outcomes/oc-9949561-push-replication.md)).
26
27## The path a change takes
28
29| Step | Gate | Status |
30| ---- | ------------------------------------------------- | -------------------------- |
31| 1 | Agents are not the operator | Live |
32| 2 | Only the operator can file an integration request | Live |
33| 3 | Filing takes a touch | Queued |
34| 4 | Hosts deploy only what the operator signed | Designed, redesign pending |
35| 5 | A failed rollout rolls back or holds | Live |
36
37### 1. Agents are not the operator
38
39The cutover record of 2026-10-04 (plan Status) puts the coordinator and all agents in the
40`klaus-env` VM on classic-laddie, and no agents in the operator's Unix account. The VM is defined in
41cosmo `modules/klaus-env/` and `hosts/classic-laddie/klaus-env.nix`.
42
43- **The boundary is the VM.** The guest runs its own NixOS kernel under cloud-hypervisor, using the
44 host's KVM. It has no host directory shares and no operator secrets. It runs its own Nix daemon.
45 Root inside the guest is accepted.
46- **Its own identities.** On GitHub the guest acts as `patflynn-agent`. On the valley, the cutover
47 record registers the guest's key as the `klaus-env` principal, with a push grant and no `approve`
48 grant. Like any admitted key, it can push topic branches and create attestation refs. The hook
49 accepts an attestation ref only when every note in it verifies under a known signer
50 (`valleyhook/policy.go`, `valleyhook/attestation.go`). It can also create change records, which
51 makes it the owner of every agent change, and add versions to them (`valleyhook/record.go`). A
52 record never makes anything land. The integrator reads records only to refuse a request, and to
53 void a withdrawn change's requests (`integrator/records.go`). So any principal that may create a
54 record can hold back a head, by recording it in a change it then unreadies. Only an `approve`
55 holder may delete that record, and deleting it releases the head.
56- **Caps.** The VM has 8 vCPUs and 10 GiB of memory. Its systemd slice caps CPU at 900% and memory
57 at 12 GiB, and gives it a low I/O weight. The source notes the I/O weighting is advisory on ZFS.
58 No check exercises the caps.
59- **Egress.** Host firewall tables (`modules/klaus-env/host.nix`) let the guest reach the two LAN
60 DNS resolvers, ssh on the host itself, and TCP 443 on public IPv4. Everything else is dropped:
61 private and other special-purpose ranges, the tailnet, other host ports, spoofed sources and all
62 IPv6.
63- **ssh into the host.** From the guest's subnet, sshd admits only the valley git user, with no
64 forwarding, TTY or tunnel.
65- **Tools that follow `main`.** `valley self-update` can keep the guest's `valley` at the tip of
66 `main`, through the flake's home-manager module (architecture,
67 [Version and self-update](./architecture.md#version-and-self-update)). It installs only a commit
68 that has landed, built from the exact commit `git ls-remote` named, once it passes a smoke test.
69 The valley host and the machine the operator approves from do not run it. Their `valley` stays at
70 the version their system configuration pins, so a landing never changes the tool that approves or
71 admits the next change.
72
73Checks: cosmo `checks.x86_64-linux.klaus-env-firewall` (a three-node VM test with negative
74controls), `klaus-env-sshd` (the host's real sshd config) and `klaus-env-check` (the probe tool's
75unit tests). The cutover record also reports a run of `klaus-env-check` inside the live guest, which
76passed 54 of 54 probes.
77
78### 2. Only the operator can file an integration request
79
80The push hook refuses an integration-request ref unless the pushing principal holds the `approve`
81grant (`valleyhook/policy.go`). The grant is also accepted as `request`: a principal holding either
82name holds it (`valleyhook/grants.go`). The principal comes from the key that logged in, and a
83client cannot set it (`valleyhook/shell.go`). Checks: `protect-e2e`, `identity-e2e`, and `ssh-e2e`,
84which uses test identities, a grant holder and a non-holder, behind a real sshd.
85
86Who holds the grant on the live host is a deployment record. The ref-policy deployment record of
872026-10-04 (plan Status) shows the compiled grants file naming only the operator's principal. Every
88key of that principal holds the grant. The cutover record reports that, from the guest, a request
89push and a `refs/replace` push are refused and a topic push is accepted.
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
120Readiness is different. A change record's state is the author's workflow signal, and the integrator
121enforces it as closely as refs allow. It does not enforce it atomically. A record written between
122the integrator's last read of the records and its move of the target can be missed. That can land a
123head the operator approved and the author has since paused. It can never land content the operator
124did not approve. The race-free form binds each approval to the record's withdraw generation, in the
125signed approval statements of M1-C.
126
127### 3. Filing takes a touch (queued)
128
129The `approve` grant moves to the operator's `ssh:valley-approve` YubiKey keys, verified with
130`sigverify`. Until then, filing a request needs the operator's principal and no touch. `sigverify`
131itself is checked by `sigverify-unit` and `sigverify-e2e`, including a touchless-signature negative
132test. The registry schema does not accept hardware-backed keys yet.
133
134### 4. Hosts deploy only what the operator signed (designed, redesign pending)
135
136The design is M1-C: hosts verify signed, sequenced release tags and never track `main`. It is being
137rebuilt on `sigverify`.
138
139The converging hosts (classic-laddie, weller, cutie-pi and sweetie-pi) build and activate the tip of
140cosmo's `main` (cosmo `modules/converge/`, `docs/converge.md`). On classic-laddie and weller a
141GitHub push webhook starts a run. Every converging host also runs on an hourly timer with up to five
142minutes of random delay. Converge accepts any new commit on `main`; it does not check who made it.
143The build time, a standing hold, or a kernel or systemd change that waits for a reboot can delay
144activation further. No check bounds the delay.
145
146### 5. A failed rollout rolls back or holds
147
148cosmo's converge activates a new generation with `switch-to-configuration test`, then runs the last
149known good generation's health check (cosmo `modules/converge/scripts.nix`). The health check covers
150required units, an sshd banner, the default route, and on the Pis their DNS service.
151
152- **Pass:** converge commits the generation with `switch`. The health check runs before this second
153 activation, so a failure that appears only during `switch` is not checked.
154- **Fail:** converge switches back to the running system with `test`, quarantines the revision, and
155 records `phase=failed`. If switching back fails, converge holds for the operator. A quarantined
156 revision is not applied again until the operator clears it or `main` moves past it.
157- **Interrupted run:** a run interrupted midway gets one repair attempt, then holds for the operator
158 as `needs-operator`.
159- **Kernel or boot changes:** converge stages the generation for the next boot. After the reboot,
160 the health check runs. On failure, converge stages the last good generation back and the next
161 reboot restores it.
162- **Resolvers:** a Pi reboots only when a peer resolver answers, unless its own resolver is failing
163 or converge has staged a rollback (cosmo `hosts/pi-dns/peer-check.nix`). classic-laddie has a
164 public fallback resolver.
165
166Checks: cosmo `checks.x86_64-linux.cosmo-rebuild`, `cosmo-rebuild-vm` (a VM test of rollback),
167`auto-reboot`, `resolver-redundancy` and `converge-status`. The plan records open review findings on
168converge, and cosmo's ROADMAP D11 carries them as the acceptance criteria of a Go port.
169
170## Threat model
171
172| Threat | Response today |
173| ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
174| An agent acting as the operator | Agents run in `klaus-env` with their own identities and no operator keys (step 1). The push hook scopes refs by principal (step 2). |
175| The interactive coordinator | It runs in `klaus-env` with the other agents. Only a verified touch stops an agent that holds a grant, and that gate is queued (step 3). |
176| 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). |
177| A compromised agent | Assume arbitrary commands inside the VM. The VM has no production secrets and no signing sockets, and its egress is limited. |
178| 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. |
179| A lost hardware key | An offline backup YubiKey holds every role (plan Trust roots, 2026-10-04). |
180| classic-laddie compromised or down | Other hosts keep their current systems. Recovery that does not depend on classic-laddie arrives with M1-C. |
181| A bad network or DNS change | A Pi's reboot waits for a peer resolver, with the exceptions in step 5. classic-laddie has a fallback resolver. unifi-sync has no automatic trigger. |
182
183## Trust roots
184
185- **Two YubiKeys**, a primary and an offline backup. Per the plan's Trust roots record of
186 2026-10-04, each holds an approve key (`ssh:valley-approve`, touch), a release key
187 (`ssh:cosmo-release`, PIN and touch) and an age PIV identity for secrets. No code uses the ssh
188 keys yet. The age identities are cosmo's `keys.admins` (cosmo `secrets/keys.nix`).
189- **A Tillitis TKey** is the intended offline root for trust-root changes. It is not set up.
190 `sigverify` has a `tkey-signer` class for it.
191- **Host ssh keys**, which agenix uses to decrypt each host's secrets (cosmo `secrets/keys.nix`).
192
193## What a client trusts to read a landing
194
195A client decides that a version landed through an integrator merge (`landed-recorded`) by verifying
196the integrator's transfer statement. It verifies the statement with a known-signers file and the
197integrator's signing name. By default it reads both from the host's publication at
198`refs/the-valley/signers` in the instance repository (`implemented`; see
199[the signers publication](./architecture.md#the-signers-publication)).
200
201That publication is project storage, not source. No change, review or check governs it. The client
202trusts it for a different reason: only the host's machinery writes it, never a push. The push hook
203refuses every push to it (`implemented`, checked by `signers-e2e` and `publish-e2e`). On the host,
204the publisher writes it from the file and the name the controllers use (`implemented`, checked by
205`signers-e2e`). The integrator can write it too, because the instance repository is group-writable
206and the integrator is in that group to land code there (`implemented`, `nix/valley-host.nix`). So a
207client that reads it trusts the host's disk, the host's configuration and the integrator. It already
208trusts the same host to serve `main`, and the same integrator to decide what lands on it.
209
210A revocation reaches clients through the publication. Once the registry lets no key sign, the
211compiler writes a known-signers file with no key in it, and the host publishes that file. A client
212then verifies no transfer statement with the revoked keys (`implemented`, checked by `signers-e2e`).
213Two runs of the publisher take turns under a lock, so a run that read the file before a rotation
214cannot publish it over a run that read it after (`implemented`, checked by `signers-e2e`).
215
216The client finds the instance repository through `policy/valley` at `main`'s tip on origin, which is
217integrated source. A change that lands a new `policy/valley` points clients at another repository's
218publication. A flag or a variable set on the client replaces the publication for the value it gives.
219The restacker reads neither the publication nor the variables, only its own flags.
220
221A wrong publication cannot by itself make a version read `landed-recorded`. That also takes the
222integrator's outcome record for the version, saying it landed at the version's head, and no push may
223write an outcome record. A wrong publication can make a real landing read `uncertain`.
224
225## Secrets
226
227cosmo keeps its secrets in agenix (cosmo `secrets/secrets.nix`, `docs/secrets-management.md`). Every
228secret is encrypted to the two YubiKey age identities and to every host key, and to no user key.
229
230- Decrypting with a YubiKey identity takes a touch.
231- The host keys are software keys. A copy of any host's private key decrypts every secret, on any
232 machine.
233- The recipients include the host key of the retired `klaus-worker-0` VM until the next rekey.
234
235Decrypted secrets on a host are mode `0400`. No check asserts the recipient list. A rekey is
236verified by reading the age headers.
237
238## What the operator does
239
240- Approves changes, with `[a]pprove` in `valley review` or with `valley approve`. Approving a change
241 files its integration request. This is the only act on this list that a check enforces (step 2).
242- Merges on GitHub, for repositories still developed there. `patflynn-agent` can merge too (see
243 Residual risks).
244- Rekeys and edits secrets, with a YubiKey touch.
245- With M1-C: signs releases and approves protected path classes.
246
247## The autonomy ladder
248
249Automation grows in deterministic forms, under policy the operator signs. Agents never decide for
250themselves when to deploy.
251
2521. **Today.** A merge to cosmo's `main` is the gate, and converge deploys it on its next run.
2532. **After M1-C.** A signed release is the gate, and a merge does not deploy. One touch and PIN
254 signs a batch. Rollout through canaries, soak and rollback runs unattended.
2553. **A batched cadence.** A scheduled release promotes everything accumulated, and one touch signs
256 it.
2574. **Approved upstreams.** When klaus, the-valley and the other inputs land through approval-gated
258 integration, cosmo's bumps of them can merge when checks pass. They still ship through releases.
2595. **A delegated release signer.** A machine key in the release environment, out of agents' reach,
260 signs releases that touch only declared low-risk path classes. The operator signs that policy
261 with a touch. Entry criterion: a record of health-gated rollback catching real failures in
262 production, and a measured count of touches per week.
263
264## Residual risks
265
266- **`patflynn-agent` can write to cosmo on GitHub.** An agent can merge to cosmo's `main`, and
267 converge deploys it on its next run. This closes when cosmo moves onto the valley (M5).
268- **Old secret ciphertext stays decryptable.** cosmo's git history holds secrets encrypted to a key
269 agents could once read. Rotation is deferred.
270- **A guest escape lands on classic-laddie.** The guest has its own kernel. An escape through KVM or
271 cloud-hypervisor reaches classic-laddie, which also runs the valley.
272- **Every key of the operator's principal holds `approve`.** Filing needs no touch until step 3
273 lands.
274- **Check definitions come from the change.** A change can edit the flake check it is judged by
275 ([bd-eaefe82](../archive/.the-valley/bugs/bd-eaefe82-check-definitions-come-from-the-branch.md)).
276- **Two hosts update unsigned.** johnny-walker and makers-nix run `system.autoUpgrade` from GitHub
277 (cosmo `modules/common/system.nix`).
278- **Readiness is not enforced atomically.** A change paused in the moment before the integrator
279 moves the target can still land, at the head the operator approved (step 2).
280- **The bus has no authentication.** Any local process on classic-laddie can publish events. Nothing
281 treats an event as authoritative.
282- **`integrator` is a named writer of `main`.** cosmo lists it in `protection.writers` for both
283 projects (cosmo `hosts/classic-laddie/valley.cue`). A key tagged `integrator` could push `main`
284 directly. The host's declared keys carry no such tag. The registry's keys live in qinling.