| 1 | # Security and rollouts |
| 2 | |
| 3 | This document describes how the-valley protects the hosts it runs on and the hosts that deploy what |
| 4 | lands on it. It follows the path a change takes, and names the gate at each step and its status. The |
| 5 | components 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 | |
| 8 | The 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 | |
| 17 | The main threat is an AI agent acting as the operator. So the gates must hold even when an agent |
| 18 | ignores its instructions. The human act of authority is a touch on a hardware key. An approval gate |
| 19 | that the gated agent can administer is only a setting that agent controls |
| 20 | ([ida-b7025b5](../archive/.the-valley/ideas/ida-b7025b5-human-decisions-are-signed-acts.md)). A gate |
| 21 | counts as done only when a check has shown it refusing what it should refuse |
| 22 | ([oc-9949561](../archive/.the-valley/outcomes/oc-9949561-push-replication.md)). |
| 23 | |
| 24 | ## The path a change takes |
| 25 | |
| 26 | | Step | Gate | Status | |
| 27 | | ---- | ------------------------------------------------- | ----------------- | |
| 28 | | 1 | Agents are not the operator | Deployment choice | |
| 29 | | 2 | Only the operator can file an integration request | Implemented | |
| 30 | | 3 | Filing takes a touch | Not built | |
| 31 | | 4 | Hosts deploy only what the operator signed | Not built | |
| 32 | | 5 | A failed rollout rolls back or holds | Deployment choice | |
| 33 | |
| 34 | ### 1. Agents are not the operator |
| 35 | |
| 36 | Agents must never act with the operator's identity or keys. The-valley names every pusher by its |
| 37 | key, so each agent can have an identity of its own. The deployment keeps the agents apart from the |
| 38 | operator's account, keys and secrets (**deployment choice**). |
| 39 | |
| 40 | - **The boundary.** A deployment runs its agents outside the operator's Unix account, in a boundary |
| 41 | such as a VM with its own kernel. The boundary has no host directory shares and no operator |
| 42 | secrets. An agent is assumed to have root inside the boundary. |
| 43 | - **Their own identities.** Agents push with their own keys under their own principal, with a push |
| 44 | grant and no `approve` grant (**deployment choice**). The hook takes the principal from the key |
| 45 | that logged in (`valleyhook/shell.go`). Like any admitted key, an agent's key can push topic |
| 46 | branches and create attestation refs. The hook accepts an attestation ref only when every note in |
| 47 | it verifies under a known signer (`valleyhook/policy.go`, `valleyhook/attestation.go`). An agent's |
| 48 | key can also create change records, which makes the agent's principal the owner of those changes, |
| 49 | and add versions to them (`valleyhook/record.go`). A record never makes anything land. The |
| 50 | integrator reads records only to refuse a request or to void a withdrawn change's requests |
| 51 | (`integrator/records.go`). Any principal that can create a record can hold back a head by |
| 52 | recording it in a change and unreadying that change. Only an `approve` holder may delete that |
| 53 | record, and deleting it releases the head. |
| 54 | - **Caps.** The deployment caps the boundary's CPU, memory and I/O, so agents cannot starve the |
| 55 | valley host. |
| 56 | - **Egress.** The boundary reaches only what agents need, such as name resolution, ssh to the valley |
| 57 | host and HTTPS to the public internet. Everything else is dropped: private and other |
| 58 | special-purpose address ranges, other ports on the host, and spoofed sources. |
| 59 | - **ssh into the valley host.** From the agents' network, sshd admits only the valley git user, with |
| 60 | no forwarding, TTY or tunnel. The host module's `Match User git` block turns off TCP, agent and |
| 61 | X11 forwarding and tunnels, and leaves stream-local forwarding on (`nix/valley-host.nix`). The |
| 62 | deployment adds `DisableForwarding yes` and `PermitTTY no` to close the rest (see |
| 63 | [Repositories and the git user](./architecture.md#repositories-and-the-git-user)). |
| 64 | - **Tools that follow `main`.** `valley self-update` can keep an agent's `valley` at the tip of |
| 65 | `main`, through the flake's home-manager module (see |
| 66 | [Version and self-update](./architecture.md#version-and-self-update)). It installs only a commit |
| 67 | that has landed, built from the exact commit `git ls-remote` named, once it passes a smoke test. |
| 68 | The valley host and the machine the operator approves from must not run it. Their `valley` stays |
| 69 | at the version their system configuration pins, so a landing never changes the tool that approves |
| 70 | or admits the next change. |
| 71 | |
| 72 | Checks: `ssh-e2e` runs the git user's sshd block behind a real sshd. No check in this repository |
| 73 | exercises a deployment's boundary, caps or egress. A deployment that runs agents needs its own |
| 74 | checks for them, with negative controls that show each forbidden connection refused. |
| 75 | |
| 76 | ### 2. Only the operator can file an integration request |
| 77 | |
| 78 | The push hook refuses an integration-request ref unless the pushing principal holds the `approve` |
| 79 | grant (`valleyhook/policy.go`). The grant is also accepted as `request`: a principal holding either |
| 80 | name holds it (`valleyhook/grants.go`). The principal comes from the key that logged in, and a |
| 81 | client cannot set it (`valleyhook/shell.go`). Checks: `protect-e2e`, `identity-e2e`, and `ssh-e2e`, |
| 82 | which uses test identities, a grant holder and a non-holder, behind a real sshd. |
| 83 | |
| 84 | Who holds the grant is a **deployment choice**. A deployment that gives it to the operator's |
| 85 | principal alone makes the operator the only one who can file. Every key of that principal then holds |
| 86 | the grant. |
| 87 | |
| 88 | The security invariant is the operator's approval: only content the operator approved lands. The |
| 89 | request names the exact head that was approved, and the integrator lands only what a request names |
| 90 | (`integrator/refs.go`). Checks: `integrator-e2e` and `valley-ready`. |
| 91 | |
| 92 | The `restack` grant is the host restacker's, and it files nothing. The hook lets a holder that |
| 93 | neither owns a change nor holds `approve` add exactly one version to the change's record, while the |
| 94 | change is `ready`. The version keeps the branch and title of the active one, and names the holder as |
| 95 | its uploader. A holder may also write restack reports (`refs/the-valley/restack/main/*`). The grant |
| 96 | authorises no other record write, no record delete, and nothing on integration requests |
| 97 | (`valleyhook/record.go`, `valleyhook/report.go`). Checks: `protect-e2e` and `identity-e2e`. |
| 98 | |
| 99 | A `restack` holder is still a named principal, and keeps every ordinary power of one. So a |
| 100 | compromised restacker key can: |
| 101 | |
| 102 | - rewrite or delete unprotected branches; |
| 103 | - add arbitrary versions to other owners' ready changes; |
| 104 | - create and manage its own records, and write valid plan-graph updates; |
| 105 | - publish misleading reports, consume storage, exhaust a record's capacity, or withhold work. |
| 106 | |
| 107 | It cannot write a protected `main`, file, replace or withdraw a request, write an integrator |
| 108 | outcome, or forge a check signature. It can relay evidence someone else signed, as any key can. The |
| 109 | hook proves who uploaded a version and nothing about its content: not that it is a rebase of the old |
| 110 | head, holds only the change's content, keeps its message and author, or sits on `main`. What |
| 111 | protects the operator is approval. A request names the exact head the operator approved, so a |
| 112 | version the restacker added lands only once the operator approves that head. Review compares a |
| 113 | version with its approved version from git objects, and never trusts a report's account of it (see |
| 114 | the architecture's |
| 115 | [Review against the approved version](./architecture.md#review-against-the-approved-version)). |
| 116 | |
| 117 | Readiness is different. A change record's state is the author's workflow signal, and the integrator |
| 118 | enforces it as closely as refs allow. It does not enforce it atomically. A record written between |
| 119 | the integrator's last read of the records and its move of the target can be missed. That can land a |
| 120 | head the operator approved and the author has since paused. It can never land content the operator |
| 121 | did not approve. The race-free design binds each approval to the record's withdraw generation in a |
| 122 | signed approval statement (**not built**). |
| 123 | |
| 124 | ### 3. Filing takes a touch (not built) |
| 125 | |
| 126 | This gate is **not built**. Its design gives the `approve` grant to hardware keys that need a touch |
| 127 | for every signature, and verifies each filing with `sigverify`. Until it is built, filing a request |
| 128 | needs the operator's principal and no touch. `sigverify` itself is checked by `sigverify-unit` and |
| 129 | `sigverify-e2e`, including a touchless-signature negative test. The registry schema does not accept |
| 130 | hardware-backed keys yet. |
| 131 | |
| 132 | ### 4. Hosts deploy only what the operator signed (not built) |
| 133 | |
| 134 | A host that deploys what lands on the valley should activate only a release the operator signed. The |
| 135 | design has each such host verify a signed, sequenced release tag before it activates anything, and |
| 136 | never track `main`. `sigverify` verifies such a tag (`implemented`, checked by `sigverify-unit` and |
| 137 | `sigverify-e2e`). Nothing calls it yet. The deployment supplies the host-side caller, which must |
| 138 | meet [sigverify's caller's contract](../sigverify/README.md#the-callers-contract) (**not built**). |
| 139 | |
| 140 | Until a host verifies signed releases, a host that builds and activates the tip of `main` deploys |
| 141 | whatever lands, without checking who made it (**deployment choice**). Nothing bounds the delay |
| 142 | between a landing and its activation. |
| 143 | |
| 144 | ### 5. A failed rollout rolls back or holds |
| 145 | |
| 146 | The-valley does not deploy the hosts that use what lands. A deployment's own activation step does, |
| 147 | and it must roll back or hold when a rollout fails (**deployment choice**): |
| 148 | |
| 149 | - It checks a new system's health before it keeps the system. |
| 150 | - On a failure, it switches back to the running system. It does not apply the failed revision again |
| 151 | until the operator clears it. |
| 152 | - When it cannot switch back, or a run is interrupted, it holds for the operator. |
| 153 | - A change that needs a reboot is checked after the reboot. When that check fails, the last good |
| 154 | system is staged back for the next boot. |
| 155 | |
| 156 | On the valley host itself, the-valley holds pushes while its own configuration settles. |
| 157 | `valley-init` deletes its converged record before it links the hooks, and `valleyhook shell` refuses |
| 158 | a push while that record does not match the running configuration (`nix/valley-host.nix`, |
| 159 | `valleyhook/shell.go`). The operator can also hold every push with a hold file. Checked by |
| 160 | `init-e2e` and `ssh-e2e` (see |
| 161 | [valley-init and the push hold](./architecture.md#valley-init-and-the-push-hold)). |
| 162 | |
| 163 | ## Threat model |
| 164 | |
| 165 | | Threat | Response | |
| 166 | | ----------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 167 | | 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). | |
| 168 | | 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). | |
| 169 | | 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). | |
| 170 | | 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). | |
| 171 | | 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. | |
| 172 | | A lost hardware key | An offline backup hardware key holds every role (see [Trust roots](#trust-roots)). | |
| 173 | | 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). | |
| 174 | |
| 175 | ## Trust roots |
| 176 | |
| 177 | The operator's trust roots are hardware keys that the deployment supplies (**deployment choice**): |
| 178 | |
| 179 | - **Two hardware keys**, a primary and an offline backup. Each holds every role: an approve key that |
| 180 | needs a touch, and a release signing key that needs a PIN and a touch. No gate uses these keys |
| 181 | yet, because the gates of steps 3 and 4 are **not built**. |
| 182 | - **An offline root for trust-root changes**, such as a Tillitis TKey. `sigverify` has a |
| 183 | `tkey-signer` class for it (`implemented`). Nothing uses one for trust-root changes yet (**not |
| 184 | built**). |
| 185 | |
| 186 | ## What a client trusts to read a landing |
| 187 | |
| 188 | A client decides that a version landed through an integrator merge (`landed-recorded`) by verifying |
| 189 | the integrator's transfer statement. It verifies the statement with a known-signers file and the |
| 190 | integrator's signing name. By default it reads both from the host's publication at |
| 191 | `refs/the-valley/signers` in the instance repository (`implemented`; see |
| 192 | [the signers publication](./architecture.md#the-signers-publication)). |
| 193 | |
| 194 | That publication is project storage, not source. No change, review or check governs it. The client |
| 195 | trusts it for a different reason: only the host's machinery writes it, never a push. The push hook |
| 196 | refuses every push to it (`implemented`, checked by `signers-e2e` and `publish-e2e`). On the host, |
| 197 | the publisher writes it from the file and the name the controllers use (`implemented`, checked by |
| 198 | `signers-e2e`). The integrator can write it too, because the instance repository is group-writable |
| 199 | and the integrator is in that group to land code there (`implemented`, `nix/valley-host.nix`). So a |
| 200 | client that reads it trusts the host's disk, the host's configuration and the integrator. It already |
| 201 | trusts the same host to serve `main`, and the same integrator to decide what lands on it. |
| 202 | |
| 203 | A revocation reaches clients through the publication. Once the registry lets no key sign, the |
| 204 | compiler writes a known-signers file with no key in it, and the host publishes that file. A client |
| 205 | then verifies no transfer statement with the revoked keys (`implemented`, checked by `signers-e2e`). |
| 206 | Two runs of the publisher take turns under a lock, so a run that read the file before a rotation |
| 207 | cannot publish it over a run that read it after (`implemented`, checked by `signers-e2e`). |
| 208 | |
| 209 | The client finds the instance repository through `policy/valley` at `main`'s tip on origin, which is |
| 210 | integrated source. A change that lands a new `policy/valley` points clients at another repository's |
| 211 | publication. A flag or a variable set on the client replaces the publication for the value it gives. |
| 212 | The restacker reads neither the publication nor the variables, only its own flags. |
| 213 | |
| 214 | A wrong publication cannot by itself make a version read `landed-recorded`. That also takes the |
| 215 | integrator's outcome record for the version, saying it landed at the version's head, and no push may |
| 216 | write an outcome record. A wrong publication can make a real landing read `uncertain`. |
| 217 | |
| 218 | ## Secrets |
| 219 | |
| 220 | The valley host needs a few secrets, and the deployment provisions each one as a file outside the |
| 221 | Nix store (**deployment choice**; see |
| 222 | [What a deployment supplies](./architecture.md#what-a-deployment-supplies)). They are the |
| 223 | integrator's signing key, the git user's ssh key for mirror pushes, and the backup's credentials. |
| 224 | |
| 225 | A deployment must keep these secrets, and every key that decrypts them, out of agents' reach. Two |
| 226 | properties of encrypted secrets bear on that: |
| 227 | |
| 228 | - A copy of any recipient's private key decrypts every secret encrypted to it, on any machine. When |
| 229 | secrets are encrypted to host keys, each host's key is a software private key that can decrypt |
| 230 | them. |
| 231 | - Old ciphertext stays decryptable by every key it was encrypted to. A secret once encrypted to a |
| 232 | key that agents could read must be replaced with a new secret, not only re-encrypted. |
| 233 | |
| 234 | ## What the operator does |
| 235 | |
| 236 | - Approves changes, with `[a]pprove` in `valley review` or with `valley approve`. Approving a change |
| 237 | files its integration request. This is the only act on this list that a check enforces (step 2). |
| 238 | - Holds the hardware keys and manages the deployment's secrets. |
| 239 | - Signs releases and approves protected path classes, once those gates exist (**not built**). |
| 240 | |
| 241 | ## The autonomy ladder |
| 242 | |
| 243 | Automation grows in deterministic forms, under policy the operator signs. Agents never decide for |
| 244 | themselves when to deploy. |
| 245 | |
| 246 | 1. **Today.** An approved landing on `main` is the gate. A host that deploys from `main` deploys it |
| 247 | on its next run. |
| 248 | 2. **Signed releases** (**not built**). A signed release is the gate, and a landing does not deploy. |
| 249 | One touch and PIN signs a batch. Rollout through canaries, soak and rollback runs unattended. |
| 250 | 3. **A batched cadence.** A scheduled release promotes everything accumulated, and one touch signs |
| 251 | it. |
| 252 | 4. **Approved upstreams.** When a deployment's inputs, the-valley among them, land through |
| 253 | approval-gated integration, a change that only updates those inputs can land when its checks |
| 254 | pass. Those updates still ship through releases. |
| 255 | 5. **A delegated release signer.** A machine key in the release environment, out of agents' reach, |
| 256 | signs releases that touch only declared low-risk path classes. The operator signs that policy |
| 257 | with a touch. Entry criterion: a record of health-gated rollback catching real failures in |
| 258 | production, and a measured count of touches per week. |
| 259 | |
| 260 | ## Residual risks |
| 261 | |
| 262 | - **Agents must not be able to land outside the valley.** If a host deploys from a repository on a |
| 263 | forge, an agent with merge rights there can deploy without an approval. A deployment gives agents' |
| 264 | accounts no merge rights on such a repository. |
| 265 | - **Old secret ciphertext stays decryptable.** A secret encrypted to a key that agents could once |
| 266 | read stays readable with that key, in every copy of the ciphertext, until the secret is rotated. |
| 267 | - **An escape from an agent VM on the valley host reaches the host.** The VM has its own kernel, and |
| 268 | an escape through KVM or the hypervisor reaches the host that runs the valley. |
| 269 | - **Every key of the operator's principal holds `approve`.** Filing needs no touch until step 3 is |
| 270 | built. |
| 271 | - **Check definitions come from the change.** A change can edit the flake check it is judged by |
| 272 | ([bd-eaefe82](../archive/.the-valley/bugs/bd-eaefe82-check-definitions-come-from-the-branch.md)). |
| 273 | - **Hosts must not update from an unsigned branch.** A host that upgrades itself from a branch |
| 274 | without a signature check deploys whatever reaches that branch. When the branch is on a forge |
| 275 | rather than on the valley, no gate in this document applies to it. |
| 276 | - **Readiness is not enforced atomically.** A change paused in the moment before the integrator |
| 277 | moves the target can still land, at the head the operator approved (step 2). |
| 278 | - **The bus has no authentication.** Any local process on the valley host can publish events. |
| 279 | Nothing treats an event as authoritative. |
| 280 | - **Listing `integrator` in `protection.writers` opens a push path to `main`.** The integrator moves |
| 281 | `main` on disk and needs no place in `protection.writers`. A deployment that lists `integrator` |
| 282 | there lets any key tagged `integrator` push `main` directly. No declared or registry key may carry |
| 283 | that tag. |