gunk-dev/the-valley

security.md

sourcec7821e7e238bmain's published tip history
10.7 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, its status, and the check that demonstrates it. A
5claim with no check says so. The components are described in [architecture.md](./architecture.md),
6and the planned gates are in [roadmap.md](./roadmap.md).
7
8The main threat is an AI agent acting as the operator. So the gates must hold even when an agent
9ignores its instructions. The human act of authority is a touch on a hardware key. An approval gate
10that the gated agent can administer is only a setting that agent controls
11([ida-b7025b5](../archive/.the-valley/ideas/ida-b7025b5-human-decisions-are-signed-acts.md)). A gate
12counts as done only when a check has shown it refusing what it should refuse
13([oc-9949561](../archive/.the-valley/outcomes/oc-9949561-push-replication.md)).
14
15## The path a change takes
16
17| Step | Gate | Status |
18| ---- | ------------------------------------------------- | -------------------------- |
19| 1 | Agents are not the operator | Live |
20| 2 | Only the operator can file an integration request | Live |
21| 3 | Filing takes a touch | Queued |
22| 4 | Hosts deploy only what the operator signed | Designed, redesign pending |
23| 5 | Bad rollouts undo themselves | Live |
24
25### 1. Agents are not the operator
26
27The coordinator and all agents run in the `klaus-env` VM on classic-laddie (cosmo
28`modules/klaus-env/`, `hosts/classic-laddie/klaus-env.nix`, `docs/klaus-env.md`). The operator's
29Unix account runs no agents.
30
31- **The boundary is the VM.** The guest has no host directory shares and no operator secrets. It
32 runs its own Nix daemon. Root inside the guest is accepted.
33- **Its own identities.** On GitHub the guest acts as `patflynn-agent`. On the valley its key
34 belongs to the `klaus-env` principal, which may push topic branches and nothing else.
35- **Caps.** The VM has 8 vCPUs and 10 GiB of memory. Its systemd slice caps CPU at 900% and memory
36 at 12 GiB, so guest builds cannot starve the host.
37- **Egress.** Host firewall tables (`modules/klaus-env/host.nix`) let the guest reach the two LAN
38 DNS resolvers, ssh on the host itself, and TCP 443 on public IPv4. Everything else is dropped:
39 private and other special-purpose ranges, the tailnet, other host ports, spoofed sources and all
40 IPv6.
41- **ssh into the host.** From the guest's subnet, sshd admits only the valley git user, with no
42 forwarding, TTY or tunnel.
43
44Checks: cosmo `checks.x86_64-linux.klaus-env-firewall` (a three-node VM test with negative
45controls), `klaus-env-sshd` (the host's real sshd config) and `klaus-env-check` (the probe tool's
46unit tests). From inside the running guest, `klaus-env-check` probes the live boundary; its last run
47passed 54 of 54. That the guest's valley key cannot file a request is shown by the refusal of a
48request push from the guest (step 2).
49
50### 2. Only the operator can file an integration request
51
52The push hook refuses an integration-request ref unless the pushing principal holds the `request`
53grant (`valleyhook/policy.go`). The principal comes from the key that logged in, and a client cannot
54set it (`valleyhook/shell.go`). The registry gives `request` to the operator's principal only. Every
55key of that principal holds it.
56
57Checks: `protect-e2e` and `ssh-e2e` (a real sshd, a grant holder and a non-holder) in the-valley.
58From the guest, a request push and a `refs/replace` push are refused and a topic push is accepted.
59
60### 3. Filing takes a touch (queued)
61
62The `request` grant moves to the operator's `ssh:valley-approve` YubiKey keys, verified with
63`sigverify`. Until then, filing a request needs the operator's principal and no touch. `sigverify`
64itself is checked by `sigverify-unit` and `sigverify-e2e`, including a touchless-signature negative
65test. The registry schema does not accept hardware-backed keys yet.
66
67### 4. Hosts deploy only what the operator signed (designed, redesign pending)
68
69The design is M1-C: hosts verify signed, sequenced release tags and never track `main`. It is being
70rebuilt on `sigverify`. Today the converging hosts (classic-laddie, weller, cutie-pi and sweetie-pi)
71build and activate the tip of cosmo's `main` (cosmo `modules/converge/`, `docs/converge.md`). On
72classic-laddie and weller a GitHub push webhook starts the run. Every converging host also runs it
73hourly. So a merge to cosmo's `main` deploys within the hour.
74
75### 5. Bad rollouts undo themselves
76
77cosmo's converge activates a new generation with `switch-to-configuration test`, then runs the last
78known good generation's health check (cosmo `modules/converge/`, `docs/converge.md`). The health
79check covers required units, an sshd banner, the default route, and on the Pis their DNS service.
80
81- **Pass:** converge commits the generation with `switch`.
82- **Fail:** converge switches back to the running system, quarantines the revision, and records
83 `phase=failed`. A quarantined revision is not applied again until the operator clears it or `main`
84 moves past it.
85- **Kernel or boot changes:** converge stages the generation for the next boot. After the reboot,
86 the health check runs. On failure, converge stages the last good generation back and the next
87 reboot restores it.
88- **Resolvers:** a Pi does not reboot while its peer resolver is unhealthy (cosmo
89 `hosts/pi-dns/peer-check.nix`). classic-laddie has a public fallback resolver.
90
91Checks: cosmo `checks.x86_64-linux.cosmo-rebuild`, `cosmo-rebuild-vm` (a VM test of rollback),
92`auto-reboot`, `resolver-redundancy` and `converge-status`.
93
94## Threat model
95
96| Threat | Response today |
97| ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
98| 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). |
99| 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). |
100| A compromised agent | Assume arbitrary commands inside the VM. The VM has no production secrets and no signing sockets, and its egress is limited. |
101| A broken but honest change | Owed checks must pass before a landing. A bad rollout rolls back (step 5). A human signature authorizes risk; it does not prove correctness. |
102| A lost hardware key | An offline backup YubiKey is enrolled for every role. |
103| classic-laddie compromised or down | Other hosts keep their current systems. Recovery that does not depend on classic-laddie is planned with M1-C. |
104| A bad network or DNS change | Pi reboots wait for a healthy peer resolver, and classic-laddie has a fallback resolver. unifi-sync has no automatic trigger and runs only by hand. |
105
106## Trust roots
107
108- **Two YubiKeys**, a primary and an offline backup. Each holds an approve key
109 (`ssh:valley-approve`, touch), a release key (`ssh:cosmo-release`, PIN and touch) and an age PIV
110 identity for secrets. The ssh keys are enrolled, and no code uses them yet. The age identities are
111 cosmo's `keys.admins` (cosmo `secrets/keys.nix`).
112- **A Tillitis TKey** is planned as the offline root for trust-root changes. It is not set up yet.
113 `sigverify` has a `tkey-signer` class for it.
114- **Host ssh keys**, which agenix uses to decrypt each host's secrets (cosmo `secrets/keys.nix`).
115
116## Secrets
117
118cosmo keeps its secrets in agenix (cosmo `secrets/secrets.nix`, `docs/secrets-management.md`). Every
119secret is encrypted to the two YubiKey age identities and the host keys, and to no user key. So
120decrypting a secret off a host takes a YubiKey touch. Decrypted secrets on a host are mode `0400`.
121No check asserts the recipient list. A rekey is verified by reading the age headers.
122
123## What only the operator does
124
125- Files integration requests, with `valley review` and `[a]sk`.
126- Merges on GitHub, for repositories still developed there.
127- Rekeys and edits secrets, with a YubiKey touch.
128- Later, with M1-C: signs releases and approves protected path classes.
129
130## The autonomy ladder
131
132Automation comes back in deterministic forms, under policy the operator signs. Agents never decide
133for themselves when to deploy.
134
1351. **Today.** A human merge is the gate, and a merge deploys within the hour.
1362. **After M1-C.** A signed release is the gate, and a merge does not deploy. One touch and PIN
137 signs a batch. Rollout through canaries, soak and rollback runs unattended.
1383. **A batched cadence.** A scheduled release promotes everything accumulated, and one touch signs
139 it.
1404. **Approved upstreams.** When klaus, the-valley and the other inputs land through approval-gated
141 integration, cosmo's bumps of them can merge when checks pass. They still ship through releases.
1425. **A delegated release signer.** A machine key in the release environment, out of agents' reach,
143 signs releases that touch only declared low-risk path classes. The operator signs that policy
144 with a touch. Entry criterion: health-gated rollback has caught real failures in production, and
145 the touches per week are measured.
146
147## Residual risks
148
149- **`patflynn-agent` can write to cosmo on GitHub.** An agent could merge to cosmo's `main`, which
150 deploys within the hour. This closes when cosmo moves onto the valley (M5).
151- **Old secret ciphertext stays decryptable.** cosmo's git history holds secrets encrypted to a key
152 agents could once read. Rotation is deferred.
153- **A guest escape lands on classic-laddie.** The VM shares classic-laddie's kernel and hypervisor,
154 and classic-laddie also runs the valley.
155- **Every key of the operator's principal holds `request`.** Filing needs no touch until step 3
156 lands.
157- **Check definitions come from the change.** A change can edit the flake check it is judged by
158 ([bd-eaefe82](../archive/.the-valley/bugs/bd-eaefe82-check-definitions-come-from-the-branch.md)).
159 the-valley's own code paths owe only the floor's `unclassified` checks.
160- **Two hosts update unsigned.** johnny-walker and makers-nix run `system.autoUpgrade` from GitHub
161 (cosmo `modules/common/system.nix`).
162- **The bus has no authentication.** Any local process on classic-laddie can publish events. Nothing
163 treats an event as authoritative.