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