diff --git a/AGENTS.md b/AGENTS.md index 9bb87ce..b1135d9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -188,6 +188,19 @@ change, and keep the documented layout and `lib.my.c.home.vlans` in sync. These APs are not managed by the flake; only their DNS records are. Read and update `docs/sites/home/aps.md` when changing an AP or its VLAN layout. +## Working from `slop-cannon` + +Agents on `slop-cannon` have no deploy or SSH keys, so `deploy` and `ssh-machine` don't work there. +Use `slop` instead; `slop guide` explains it. Requests that need approval can wait up to five +minutes for a human. See [`docs/slop-broker.md`](docs/slop-broker.md). + +- `slop status`, `slop logs` and `slop failed` look at a box without waiting for approval. +- `slop ssh -- ` runs anything else. Nodes are the deploy-rs nodes on `master`; + `--host @` reaches other boxes. +- `slop deploy …` builds and deploys a pushed commit; `--boot` stages it for the next boot. +- `slop build …` builds a pushed commit's flake attributes into the binary cache. +- `slop requests` lists your pending requests and leases. + ## Secrets age-encrypted secrets in `secrets/`, managed with **ragenix**. Each module declares diff --git a/docs/deployment.md b/docs/deployment.md index 79c2344..9ac8e30 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -305,7 +305,9 @@ systems as `system-`, homes as `home-` (with `@` changed to `-at-`), `package-`, and the development `shell`. Each result is pushed to the Harmonia cache with [`ci/push-to-cache.sh`](../ci/push-to-cache.sh). Before the first push, the workflow deletes cache-profile generations older than its retention period, then collects -unreachable paths so a full cache cannot prevent collection from being reached. +unreachable paths so a full cache cannot prevent collection from being reached. Paths pushed by +`slop build` survive collection through their own GC roots (see +[`slop-broker.md`](slop-broker.md#binary-cache)). When `.#ciIfdReasons.x86_64-linux` lists an active exception, CI logs a warning with the reason and allows import from derivation for the target builds. It runs a build-capable flake diff --git a/docs/sites/colony/shill/containers/middleman.md b/docs/sites/colony/shill/containers/middleman.md index b25b0b0..3f235b9 100644 --- a/docs/sites/colony/shill/containers/middleman.md +++ b/docs/sites/colony/shill/containers/middleman.md @@ -42,7 +42,7 @@ username/password provider. Its cookie domain is `.nul.ie`; gated vhosts include [Pocket ID](https://pocket-id.org) (`services.pocket-id`) is a passkey-only OpenID Connect provider at `id.nul.ie`, for apps that sign in with OIDC (first the `slop-broker` approvals web -app, see [`slop-broker.md`](../../../../slop-broker.md)). It is meant to replace nginx-sso's +app, see [`slop-broker.md`](../../../../slop-broker.md#approvals-web-app)). It is meant to replace nginx-sso's Google sign-in later, with oauth2-proxy in front of apps that lack OIDC. - Listens on `127.0.0.1:1411` behind nginx and keeps its SQLite database in `/var/lib/pocket-id` @@ -108,6 +108,7 @@ all vhosts are `onlySSL`, kTLS and HTTP/2. "SSO" = gated behind nginx-sso (`gene | `librespeed.ams1.int.nul.ie` | `localhost:8989` | librespeed on the internal domain (internal wildcard cert) | | `paseo-relay.nul.ie` | `localhost:4000` | Paseo relay; websockets with long timeouts; `/metrics` blocked | | `slop.nul.ie` | static Paseo web app | falls back to `index.html`; precompressed files served as-is | +| `approve.slop.nul.ie` | `palace.h.nul.ie:8095` | [`slop-broker`](../../../../slop-broker.md#approvals-web-app)'s approvals web app, which handles sign-in itself (Pocket ID) | | `md.nul.ie` | `object-ctr:3000` | HedgeDoc; websockets | | `pb.nul.ie` | `object-ctr:8088` | wastebin | | `photos.nul.ie` | `jackflix-ctr:2342` | PhotoPrism; websockets | diff --git a/docs/sites/colony/shill/containers/object.md b/docs/sites/colony/shill/containers/object.md index 59ef1ea..bfce7b3 100644 --- a/docs/sites/colony/shill/containers/object.md +++ b/docs/sites/colony/shill/containers/object.md @@ -12,7 +12,7 @@ Object storage and the Nix binary cache, plus HedgeDoc and wastebin. | Service | Port | Purpose | | --- | --- | --- | | MinIO | `9000` (S3) / `9001` (console) | S3-compatible object storage, `s3.nul.ie` + `*.s3.nul.ie` (virtual-host style via `MINIO_DOMAIN`), console at `minio.nul.ie`; region `eu-central-1`; data on the `/mnt/minio` XFS volume | -| Harmonia | `5000` | Nix binary cache at `nix-cache.nul.ie` — `harmonia-dev` cache serves `shill`'s `/nix/store` out of a dedicated store view rooted at `/var/lib/harmonia` (bind-mounted from `/mnt/nix-cache`), signed with the `nix-cache.key` secret; a `harmonia` user with authorized keys exists for cache pushes | +| Harmonia | `5000` | Nix binary cache at `nix-cache.nul.ie` — `harmonia-dev` cache serves `shill`'s `/nix/store` out of a dedicated store view rooted at `/var/lib/harmonia` (bind-mounted from `/mnt/nix-cache`), signed with the `nix-cache.key` secret; a `harmonia` user with authorized keys exists for cache pushes, including `slop-broker`'s on `palace`, which is restricted to the store protocol and GC roots (`services.slop-broker-cache`, see [`slop-broker.md`](../../../../slop-broker.md#binary-cache)) | | HedgeDoc | `3000` | collaborative markdown notes at `md.nul.ie`; Postgres on [colony-psql](colony-psql.md); anonymous edits but no anonymous notes, email login, no open email registration | | wastebin | `8088` | pastebin at `pb.nul.ie` | | atticd | `8069` | **currently disabled** (`services.atticd.enable = false`) — an alternative Nix cache that would store locally and sit behind `nix-cache.nul.ie`; config (including the `object/atticd.env` secret) is kept around | diff --git a/docs/sites/home/palace.md b/docs/sites/home/palace.md index 58b47df..ffa3874 100644 --- a/docs/sites/home/palace.md +++ b/docs/sites/home/palace.md @@ -27,6 +27,8 @@ feeds them SR-IOV VFs, PCI NVMe drives, LVM disks and an NVMe-oF disk. the `main` thin pool (`services.lvm.boot.thin.enable`). - AMD box (`kvm-amd`, `amd_iommu=on`, microcode updates); the kernel is built with `ACPI_APEI_PCIEAER`/`PCIEAER` for the PCIe passthrough work below. +- Runs [`slop-broker`](../../slop-broker.md) for `slop-cannon`'s agents (see + [below](#slop-broker)). ## Network assignments @@ -142,7 +144,7 @@ run before stage-two module loading. `sfh` requires the `frigate` LV before QEMU | `cellar` | 8c × 2t | 16 GiB | `cellar-hi` VF 0 (`44:00.1`); NVMe `41:00.0`–`43:00.0` | pinned to NUMA node 1; split IRQ chip + vIOMMU | | `river` | 3c × 2t | 4 GiB | `river-rdma` VF 1 (`44:00.2`), `river-dave` VF 4 (`44:00.5`), `river-jim-tap` | only an ESP local disk (plus an installer ISO) — root is NVMe-oF from `cellar` | | `sfh` | 8c × 2t | 32 GiB | `sfh-hi` VF 2 (`44:00.3`), `sfh-ctrs` VF 3 (`44:00.4`); two USB host ports | no boot disk — netboots; gets the `hdds/frigate` LV | -| `slop-cannon` | 16c × 2t | 48 GiB | `slop-cannon-ut` VF 5 (`44:00.6`) | disk is NVMe-oF from `cellar`, connected by `palace` (plus an installer ISO) | +| `slop-cannon` | 16c × 2t | 24 GiB | `slop-cannon-ut` VF 5 (`44:00.6`) | disk is NVMe-oF from `cellar`, connected by `palace` (plus an installer ISO) | `slop-cannon`'s vCPUs are overcommitted (the VMs total more vCPUs than the host's 32 threads) so coding agents can burst; `vm@slop-cannon` has a low `CPUWeight`, so `cellar`, `river` and `sfh` @@ -175,9 +177,52 @@ SPDK only checks the host NQN, which root in the guest could forge. - `devices/global_filter` rejects `/dev/nvme*` in `lvm.conf`, so `palace` never activates the guest's volume group (also called `main`). `palace` has no NVMe of its own. +## `slop-broker` + +`palace` runs [`slop-broker`](../../slop-broker.md), which carries out privileged operations for +the agents on `slop-cannon` after policy and, usually, a human approve them. + +- `slop-cannon` reaches it only over vsock: the VM has a `vhost-vsock-pci` device, and the broker + identifies it by that device's CID. Policy is set per operation in + [`palace/slop-broker.nix`](../../../nixos/boxes/home/palace/slop-broker.nix). +- The broker holds the deploy key (age secret `palace/slop-broker-deploy.key`). That key is root on + every box, so `palace` must be treated as being as sensitive as a workstation with `.keys/`. +- Deploys are built by `slop-broker-build`, a user without keys that the broker reaches over SSH + (`services.slop-broker-builder`). It fetches + commits from Gitea with a read-only deploy key on `dev/nixfiles` (age secret + `palace/slop-broker-git.key`, mirrored in `/var/lib/slop-broker-build/repository.git`) and builds + with `palace`'s Nix daemon, so builds use the host's spare CPU and memory. +- Because they run agent-written Nix, builds (the `nixbld` group) and the builder's own fetches + are kept off internal networks like `lan-untrusted` is (`lib.my.c.internalNets`), and only + `git` gets the builder's Gitea key. `nix-daemon.service` has memory limits and a low + `CPUWeight`, so builds can't starve the VMs. Builds you run on `palace` yourself are confined + the same way. +- Agents' use of the builder (the `builder` step of `slop deploy` and `slop build`) asks, showing + the commits and their diff, with a one-hour lease on offer; commits already on `master` don't + ask. `slop build` then pushes without asking again, while deploys still ask once built. +- `slop build` outputs are pushed to the binary cache on [`object`](../colony/shill/containers/object.md) + as `harmonia`, with a key of the broker's own (age secret `palace/slop-broker-cache.key`) whose + forced command allows only the store protocol and adding GC roots (see + [Binary cache](../../slop-broker.md#binary-cache)). +- Answer requests on `palace` as `dev` with `slop-approve`. In a terminal it shows each request + in full, asks for an answer and waits for new ones; `slop-approve list` and + `slop-approve ` (any unique ID prefix) work from scripts. `slop-approve log` + shows recent requests, answers and results from the audit log + (`/var/lib/slop-broker/audit.jsonl`, also in the journal). +- The [approvals web app](../../slop-broker.md#approvals-web-app) listens on TCP port 8095, + which the firewall opens only to `middleman`, the reverse proxy for `approve.slop.nul.ie`. + Approvers sign in through Pocket ID (client secret in age secret + `palace/slop-broker-oidc-secret`); its sessions, push subscriptions and push signing key are in + `/var/lib/slop-broker/web`. Deploys to the routers need a fresh passkey there. +- Requesters and approvers on other boxes log in over SSH as `slop`, whose keys can only run the + broker's forced command (see the + [design](https://git.nul.ie/dev/slop-broker/src/branch/main/docs/design.md#other-requesters-and-approvers)). + ## Notable config files - [`nixos/boxes/home/palace/default.nix`](../../../nixos/boxes/home/palace/default.nix) — host hardware, networkd (links/bridges/SR-IOV), LVM. - [`nixos/boxes/home/palace/vms/default.nix`](../../../nixos/boxes/home/palace/vms/default.nix) — VM instances, boot ordering and `slop-cannon`'s disk connection. +- [`nixos/boxes/home/palace/slop-broker.nix`](../../../nixos/boxes/home/palace/slop-broker.nix) — + the broker's policy for `slop-cannon`, its deploy key and the VM's vsock device. diff --git a/docs/sites/home/slop-cannon.md b/docs/sites/home/slop-cannon.md index 04ac785..d882ef7 100644 --- a/docs/sites/home/slop-cannon.md +++ b/docs/sites/home/slop-cannon.md @@ -13,7 +13,7 @@ inside it. | vCPUs | RAM | Disk | Network | Other | |---|---|---|---|---| -| 16c × 2t (overcommitted) | 48 GiB | 512 GiB virtio, NVMe-oF from `cellar` via `palace` | SR-IOV VF 5 (`44:00.6`) on VLAN 120 | installer ISO | +| 16c × 2t (overcommitted) | 24 GiB | 512 GiB virtio, NVMe-oF from `cellar` via `palace` | SR-IOV VF 5 (`44:00.6`) on VLAN 120 | installer ISO | `vm@slop-cannon` has a low `CPUWeight` on `palace`, so `cellar`, `river` and `sfh` win under contention. `palace` has `kvm_amd` `nested=1`, so the guest has `/dev/kvm`. @@ -25,7 +25,8 @@ contention. `palace` has `kvm_amd` `nested=1`, so the guest has `/dev/kvm`. - A normal deploy node (`deploy .#slop-cannon`, `ssh-machine slop-cannon`). - Everything inside the guest is treated as agent-controlled. The boundaries are outside it: the `untrusted` filter on the routers, the VLAN tag on the NIC and the disk connection on - `palace`. Credentials for deploying or logging into other boxes stay outside the VM. + `palace`. Credentials for deploying or logging into other boxes stay outside the VM, with + [`slop-broker`](../../slop-broker.md) on `palace`. ## Network assignments @@ -101,8 +102,9 @@ from the app don't survive a restart. It: - requires relay replay protection; - turns off dictation and voice, which would otherwise download a large local speech model; - hides providers other than Claude and Codex; -- adds a "Claude, accept edits" agent profile. Each provider's default mode is hardcoded upstream - (Claude `auto`, Codex `auto-review`), and profiles are the only way to preset one. +- adds "Claude, bypass permissions" and "Codex, full access" agent profiles. Each provider's + default mode is hardcoded upstream (Claude `auto`, Codex `auto-review`), and profiles are the + only way to preset one, so pick a profile when starting an agent for the permissive mode. ### Connectivity @@ -150,12 +152,25 @@ Paseo has the full rights of `slop-cannon`, and `slop-cannon` has root: anyone w password or a pairing controls the VM. - Claude Code and Codex come from the shared `my.agents` home-manager module. -- Claude's user settings deny raw `deploy`, `ssh-machine` and `.keys/`, and ask before - `slop-deploy` / `slop-ssh`. Claude's managed settings (`/etc/claude-code/managed-settings.json`) - repeat the `deny` rules and disable bypass mode. All of these match command text and live inside - the guest, so they steer agents rather than enforce anything. -- Codex stores its credentials in a file and uses its standard Linux sandbox. -- Deployments and administrative SSH to other boxes are handled by an operator outside the VM. +- Claude's user settings deny raw `deploy` and `ssh-machine`, and allow `slop`, since the broker + asks a human where its policy says so. The checkout's `.keys/` only has the committed public + keys, so reading it isn't denied. Claude's managed settings + (`/etc/claude-code/managed-settings.json`) repeat the `deny` rules. All of these match command + text and live inside the guest, so they steer agents towards `slop` rather than enforce + anything. +- Agents are permissive by default, since the VM is the boundary and + [`slop-broker`](../../slop-broker.md) gates everything that needs credentials: Claude starts in + `bypassPermissions` (the `deny` rules still apply), and Codex runs without approvals or its + sandbox (`approval_policy = "never"`, `sandbox_mode = "danger-full-access"`). Agents started + through Paseo use its defaults unless started with one of the profiles above. +- Codex stores its credentials in a file. + +### Privileged operations + +Agents ask [`slop-broker`](../../slop-broker.md) on `palace` for anything needing credentials, with +the `slop` command (`my.agents.slop.enable`). It connects over vsock (CID 3; see +[`palace`](palace.md#slop-broker)). The agent guide, `slop guide`, is installed as a Claude rule +(`~/.claude/rules/slop.md`) and as Codex's `AGENTS.md`. ## SSH and first login @@ -200,9 +215,11 @@ To set up provider logins and repos on a fresh agent home, connect with `ssh slo - [`nixos/boxes/home/palace/vms/slop-cannon.nix`](../../../nixos/boxes/home/palace/vms/slop-cannon.nix) — the box: users, Paseo, Claude settings, `slop-clone`, `slop-pair`, disk layout, network. +- [`nixos/boxes/home/palace/slop-broker.nix`](../../../nixos/boxes/home/palace/slop-broker.nix) — + the broker's policy for this box and the VM's vsock device. - [`nixos/boxes/home/palace/vms/default.nix`](../../../nixos/boxes/home/palace/vms/default.nix) — the VM on `palace` and `slop-cannon-disk.service`. - [`nixos/boxes/home/palace/default.nix`](../../../nixos/boxes/home/palace/default.nix) — VF 5, the NVMe host ID and the LVM filter. - [`home-manager/modules/agents/default.nix`](../../../home-manager/modules/agents/default.nix) — - shared Claude Code and Codex configuration. + shared Claude Code and Codex configuration, including the `slop` client and guide. diff --git a/docs/slop-broker.md b/docs/slop-broker.md index 5fde071..57cc7a2 100644 --- a/docs/slop-broker.md +++ b/docs/slop-broker.md @@ -10,6 +10,20 @@ repository, which this flake takes as the `slop-broker` input. This page covers it; for how it works, read the repository's [design](https://git.nul.ie/dev/slop-broker/src/branch/main/docs/design.md). +## Boxes + +| Box | Role | +|---|---| +| [`palace`](sites/home/palace.md) | Runs the broker, its builder and the approvals web app's listener; holds the deploy key | +| [`slop-cannon`](sites/home/slop-cannon.md) | The agents' VM; reaches the broker over vsock | +| [`object`](sites/colony/shill/containers/object.md) | The binary cache that `slop build` pushes to | +| [`middleman`](sites/colony/shill/containers/middleman.md) | Publishes the approvals web app at `approve.slop.nul.ie`, Pocket ID at `id.nul.ie` and Paseo's web app at `slop.nul.ie` | + +`palace`'s configuration is [`palace/slop-broker.nix`](../nixos/boxes/home/palace/slop-broker.nix): +the requesters, the `agent` policy they share, the secrets, and the web app settings. Its SSH +targets are the deploy-rs nodes on `master`, which the builder reads there, so a new box is a +target once it's merged. + ## In this flake - **Input:** `slop-broker` in [`flake.nix`](../flake.nix). Its overlay provides `pkgs.slop-broker`, @@ -17,9 +31,53 @@ it; for how it works, read the repository's `services.slop-broker-cache` and `programs.slop`. Update it with `nix flake update slop-broker`. - **Persistence:** [`tmproot.nix`](../nixos/modules/tmproot.nix) keeps `/var/lib/slop-broker` and the builder's home when those services are enabled. +- **Firewall:** the web app's port is open only to `middleman`, in `palace`'s configuration. - **Agents:** `my.agents.slop` (in the shared `agents` home-manager module) installs `slop` and adds the guide (`share/slop-broker/slop-tools.md`) as a Claude rule (`~/.claude/rules/slop.md`) and - as Codex's `AGENTS.md`. + as Codex's `AGENTS.md`. `slop-cannon` enables it, allows `Bash(slop:*)` in Claude and keeps the + `deny` rules for raw `deploy` and `ssh-machine`. +- **`AGENTS.md`:** "Working from `slop-cannon`" points agents at `slop` instead of `deploy` and + `ssh-machine`. Extend it as operations land. - **Devshell:** `slop` and `slop-approve`, built from the locked input. `slop` uses `.keys/slop-request.key` over SSH when that file exists; an approver key never goes in `.keys/`, because agents can read the checkout. + +## Binary cache + +`slop build` pushes into Harmonia's store on `object` as `harmonia`, whose broker key is limited to +the store protocol and GC roots (`services.slop-broker-cache` in `object`'s configuration). CI +collects garbage in that store on every run, which the roots survive until they expire (see the +[design](https://git.nul.ie/dev/slop-broker/src/branch/main/docs/design.md#binary-cache)). + +## Approvals web app + +`middleman` proxies `approve.slop.nul.ie` to port 8095 on `palace`. Approvers sign in through +Pocket ID at `id.nul.ie` (client `slop-approve`, restricted to the group `slop-approvers`; its +secret is `palace/slop-broker-oidc-secret`). Deploys to the routers (`river`, `stream` and +`estuary`) need a fresh passkey. See the +[design](https://git.nul.ie/dev/slop-broker/src/branch/main/docs/design.md#approvals-web-app). + +## `slop.nul.ie` + +`slop.nul.ie` replaces `paseo.nul.ie` for the Paseo web app on `middleman` (`paseoWebUi` in +`vhosts.nix`, `app.baseUrl` in `slop-cannon.nix`), and `*.slop.nul.ie` is reserved for previews. +The relay stays on `paseo-relay.nul.ie` for now, because existing pairings use that hostname. + +Previews on `*.slop.nul.ie` will be same-site with every other `nul.ie` service, so a preview page +can set cookies on `.nul.ie` and browsers send `SameSite=Lax` cookies (including the SSO session) +with its requests to other `nul.ie` services. A separate domain would avoid this; `nul.ie` is kept +for simplicity. + +## Rollout + +Each step updates this page, the box pages and `AGENTS.md` as it lands. + +1. **Done:** `slop.nul.ie`; the broker core, box queries, SSH transport, deploys and builds on + `palace`; Pocket ID at `id.nul.ie`. +2. **Approvals web app:** remove the temporary `http://localhost:8095/auth/callback` from the + `slop-approve` client, deploy `palace` and `middleman`. +3. **Secrets:** the broker's age identity joins `.keys/dev.pub` in the recipients that + `secrets.nix` generates (one full rekey), so the dev key never goes to `palace`. +4. **DNS**, with a Cloudflare token of the broker's own for the public zones. +5. **Previews** on `*.slop.nul.ie`, through `middleman`. +6. **TCP forwards and a cache for VM builds**, if needed. diff --git a/nixos/boxes/colony/vms/shill/containers/middleman/vhosts.nix b/nixos/boxes/colony/vms/shill/containers/middleman/vhosts.nix index 3ba433e..f1a2aac 100644 --- a/nixos/boxes/colony/vms/shill/containers/middleman/vhosts.nix +++ b/nixos/boxes/colony/vms/shill/containers/middleman/vhosts.nix @@ -416,6 +416,15 @@ in useACMEHost = pubDomain; }; + # `slop-broker`'s approvals web app, which handles sign-in itself + "approve.slop.${pubDomain}" = { + locations."/" = { + proxyPass = "http://palace.${home.domain}:8095"; + extraConfig = proxyHeaders; + }; + useACMEHost = pubDomain; + }; + "id.${pubDomain}" = let pocketId = { diff --git a/nixos/boxes/colony/vms/shill/containers/object.nix b/nixos/boxes/colony/vms/shill/containers/object.nix index 8a23365..118d888 100644 --- a/nixos/boxes/colony/vms/shill/containers/object.nix +++ b/nixos/boxes/colony/vms/shill/containers/object.nix @@ -183,6 +183,18 @@ in environment.systemPackages = [ minioPkgs.minio-client ]; services = { + # `slop build` on `palace` pushes into Harmonia's store + slop-broker-cache = { + enable = true; + user = "harmonia"; + store = "/var/lib/harmonia"; + # As `ci/push-to-cache.sh` does; `harmonia-dev`'s runtime directory + home = "/run/harmonia"; + brokerKeys = [ + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJMx9rrKaPGFnwdvdEKCHyonMjWi/kDWMkbZkSEHijhp slop-broker cache (palace)" + ]; + }; + atticd = { enable = false; environmentFile = config.age.secrets."object/atticd.env".path; diff --git a/nixos/boxes/home/palace/default.nix b/nixos/boxes/home/palace/default.nix index ded4f14..dde5299 100644 --- a/nixos/boxes/home/palace/default.nix +++ b/nixos/boxes/home/palace/default.nix @@ -5,7 +5,7 @@ let inherit (lib.my.c.home) domain vlans prefixes vips vlanDns hiMTU; in { - imports = [ ./vms ]; + imports = [ ./slop-broker.nix ./vms ]; nixos.systems.palace = { system = "x86_64-linux"; diff --git a/nixos/boxes/home/palace/slop-broker.nix b/nixos/boxes/home/palace/slop-broker.nix new file mode 100644 index 0000000..6bea05d --- /dev/null +++ b/nixos/boxes/home/palace/slop-broker.nix @@ -0,0 +1,150 @@ +{ + nixos.systems.palace.configuration = { lib, config, allAssignments, ... }: + let + # `slop-cannon`'s vsock address; the kernel reports it for every connection from the guest + slopCannonCid = 3; + + # Home's pair, and colony's + routers = [ "river" "stream" "estuary" ]; + + middleman = allAssignments.middleman.internal; + webPort = config.services.slop-broker.web.port; + in + { + my = { + secrets.files = { + "palace/slop-broker-deploy.key" = { + owner = "root"; + mode = "0400"; + }; + # Pushes `slop build` outputs into Harmonia's store on `object` + "palace/slop-broker-cache.key" = { + owner = "root"; + mode = "0400"; + }; + # The approvals web app's client secret at Pocket ID + "palace/slop-broker-oidc-secret" = { + owner = "root"; + mode = "0400"; + }; + # Read-only deploy key for `dev/nixfiles` on Gitea + "palace/slop-broker-git.key" = { + owner = "slop-broker-build"; + group = "slop-broker-build"; + mode = "0400"; + }; + }; + + vms.instances.slop-cannon.qemuFlags = [ "device vhost-vsock-pci,guest-cid=${toString slopCannonCid}" ]; + + # Builds and the builder run agent-written Nix, so like `lan-untrusted` they only get the + # Internet (and `resolved`'s stub, which builds use for DNS) + firewall.extraRules = '' + table inet filter { + chain agent-builds { + ct state established,related return + ip daddr 127.0.0.53 meta l4proto { tcp, udp } th dport 53 return + ${lib.my.c.internalNets.nftReject} + } + chain output { + meta skgid ${toString config.ids.gids.nixbld} jump agent-builds + meta skuid slop-broker-build jump agent-builds + } + # Only `middleman`, which publishes it, may reach the web app; `input` (not `wan-tcp`, which + # ends in `return`) gets these after everything else + chain input { + ip saddr ${middleman.ipv4.address} tcp dport ${toString webPort} accept + ip6 saddr ${middleman.ipv6.address} tcp dport ${toString webPort} accept + } + } + ''; + }; + + # Builds commits for `slop deploy` and `slop build`, as a user without keys; reached over SSH + # like a separate box + services.slop-broker-builder = { + enable = true; + repository = "git@git.nul.ie:dev/nixfiles.git"; + keyFile = config.age.secrets."palace/slop-broker-git.key".path; + brokerKeys = [ (lib.trim (builtins.readFile lib.my.c.sshKeyFiles.deploy)) ]; + }; + + services.slop-broker = { + enable = true; + approvers = [ config.my.user.config.name ]; + + # For coding agents, wherever they run + policies.agent.ops = { + # Fixed read-only commands built by the broker + query.action = "auto"; + # Running agent-written Nix at all; approvers see the commits and diff. Commits already + # on `master` have been reviewed. + builder = { + action = "ask"; + leases = [ "1h" ]; + rules = [ + { + match.on_branch = "true"; + action = "auto"; + } + ]; + }; + deploy = { + action = "ask"; + # The routers carry everything else; a bad deploy there is hard to reach and undo + rules = map + (node: { + match.node = node; + action = "ask"; + confirm = "passkey"; + }) + routers; + }; + # The source was reviewed for `builder`, and the cache only gets what `palace` built + build.action = "auto"; + ssh = { + action = "ask"; + leases = [ "5m" "1h" ]; + }; + }; + + requesters.slop-cannon = { + vsockCid = slopCannonCid; + policy = "agent"; + }; + + ssh = { + enable = true; + keyFile = config.age.secrets."palace/slop-broker-deploy.key".path; + }; + deploy.enable = true; + cache = { + enable = true; + hostname = "object-ctr.${lib.my.c.colony.domain}"; + user = "harmonia"; + keyFile = config.age.secrets."palace/slop-broker-cache.key".path; + }; + + # `approve.slop.nul.ie`, published by `middleman`; approvers sign in with Pocket ID + web = { + enable = true; + address = "::"; + url = "https://approve.slop.${lib.my.c.pubDomain}"; + issuer = "https://id.${lib.my.c.pubDomain}"; + clientSecretFile = config.age.secrets."palace/slop-broker-oidc-secret".path; + }; + }; + + # The ruleset check runs where `slop-broker-build` doesn't exist + networking.nftables.preCheckRuleset = '' + sed 's/skuid slop-broker-build/skuid nobody/g' -i ruleset.conf + ''; + + # Builds share the host with the VMs, including the router; keep them from starving those + systemd.services.nix-daemon.serviceConfig = { + MemoryHigh = "32G"; + MemoryMax = "40G"; + CPUWeight = 20; + }; + }; +} diff --git a/nixos/boxes/home/palace/vms/default.nix b/nixos/boxes/home/palace/vms/default.nix index 97a92b0..8ed91bb 100644 --- a/nixos/boxes/home/palace/vms/default.nix +++ b/nixos/boxes/home/palace/vms/default.nix @@ -272,7 +272,7 @@ cpus = 16; threads = 2; }; - memory = 49152; + memory = 24576; cleanShutdown.timeout = 120; drives = [ installerDisk diff --git a/nixos/boxes/home/palace/vms/slop-cannon.nix b/nixos/boxes/home/palace/vms/slop-cannon.nix index d7d41d9..edceef7 100644 --- a/nixos/boxes/home/palace/vms/slop-cannon.nix +++ b/nixos/boxes/home/palace/vms/slop-cannon.nix @@ -35,17 +35,14 @@ in giteaKey = config.age.secrets."slop-cannon/gitea-key".path; paseoPasswordFile = config.age.secrets."slop-cannon/paseo.env".path; - # Steer agents to the approval broker; these match command text, so they aren't a boundary + # Steer agents to the approval broker; these match command text, so they aren't a boundary. + # `.keys/` only has the committed public keys here, which agents may read. claudeDeny = [ "Bash(deploy:*)" "Bash(ssh-machine:*)" - "Read(**/.keys/**)" - "Edit(**/.keys/**)" - ]; - claudeAsk = [ - "Bash(slop-deploy:*)" - "Bash(slop-ssh:*)" ]; + # The broker asks a human where policy says so; a second prompt here would only add noise + claudeAllow = [ "Bash(slop:*)" ]; slopClone = pkgs.writeShellApplication { name = "slop-clone"; @@ -192,16 +189,26 @@ in }; home-manager.users.${agentUser} = { - my.agents.enable = true; + my.agents = { + enable = true; + slop.enable = true; + }; home.packages = [ slopClone slopPair ]; programs = { + # Permissive by default: the VM is the boundary, and `slop-broker` gates what needs + # credentials claude-code.settings.permissions = { + defaultMode = "bypassPermissions"; + allow = claudeAllow; deny = claudeDeny; - ask = claudeAsk; }; - codex.settings.cli_auth_credentials_store = "file"; + codex.settings = { + cli_auth_credentials_store = "file"; + approval_policy = "never"; + sandbox_mode = "danger-full-access"; + }; # The shared config pins `IdentityFile` for every host ssh.settings."git.nul.ie" = { @@ -212,10 +219,7 @@ in # Not editable by the agent user without `doas`; a convenience, not a boundary environment.etc."claude-code/managed-settings.json".text = toJSON { - permissions = { - disableBypassPermissionsMode = "disable"; - deny = claudeDeny; - }; + permissions.deny = claudeDeny; }; systemd = { @@ -281,12 +285,20 @@ in # Keep agents from changing modes, answering prompts or opening terminals mcp.injectIntoAgents = false; relay.requireProtectedSecurity = true; + # Paseo can't change a provider's default mode, only offer these; `slop-broker` gates + # what needs credentials agentProfiles = [ { - id = "claude-accept-edits"; - name = "Claude, accept edits"; + id = "claude-bypass"; + name = "Claude, bypass permissions"; provider = "claude"; - modeId = "acceptEdits"; + modeId = "bypassPermissions"; + } + { + id = "codex-full-access"; + name = "Codex, full access"; + provider = "codex"; + modeId = "full-access"; } ]; }; diff --git a/secrets/palace/slop-broker-cache.key.age b/secrets/palace/slop-broker-cache.key.age new file mode 100644 index 0000000..45f0792 --- /dev/null +++ b/secrets/palace/slop-broker-cache.key.age @@ -0,0 +1,20 @@ +-----BEGIN AGE ENCRYPTED FILE----- +YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNzaC1lZDI1NTE5IGV0MnpwUSB0SVFO +dlQ0NGJma0dCVmFjdGN0VUxIT2w5OEwyN0F2bFd3RFh2a3FKRkE4CmxXT0RKMGw4 +TjdacUIvc3VDMSs2NGVTOVdhcWVYaERvK1ZQZUFBeWIyMjgKLT4gWDI1NTE5IGZX +WkpSWlFOMERENGovdTR5ZTJDQ0JXMm1lZjJjNjV2aTAyL1UzbUFFRGMKY05jMWxp +bGtDNWtkeUlsTHY0WlFLVnNqWFIwSlRBS1JQbkZqUUw5ZUFIawotPiA+WzZ0XmB1 +eC1ncmVhc2UgXwo5UmF5ckVvS0NjSC84NFFiQ1dMNmtpQzBMSUw2bkNTZy91ZGtW +TFJncjhoRmx0bVN5Zk81SFRyM2E0Qjl6VHp3ClhNVXJVMWcKLS0tIEQ3M3FvRWFF +YW9pWVJYZnEvZktWVUtDbjV3TFVCZy9HTTNjakZSYjA0bm8KzMxyslaZAQarj+PB +Wqu4DoRCZTAV5qnTK2NBlRetkGYvfMMxcHUY6M089TwQN24eBrNmK187n6lhKhIG +f0usT0r3K6x5CpFv+jXd+slYEGm95FQ7ofHeV5MHuS7XeLyyCElRbjX06zducBTR +imskizjWob5Sdc6vzdqWxX1kTuXFCIT1x06MztCVdA9hU1zk7u+DEoipiQ3XZvIe +tP0xyhJfNu1WH+61Piib39mVgi5wBm4YCDz702x1nRVb29tujIze5X8W4zm3rMoN +Bg6cAevwcGMp8+2ZDgqQ/WeTm/HNAjMvTqRGwckQIu3HcTjiIIdi9dV06x7XM4Oo +sjflYwkfynY3YaX+0InZN2yBiKbvlzStd7J0XU/n226YhuNwXrMDUXvFM2/+HSl8 +cC+UP7cHmaw3SDu9By3OrqqpHQsqJi1qzhunQpwmdUnoL88tStvu9yuWTX6FotBk +e4pRSVlR15/YmvS/NZxYyURaqidc91TuDbhSatU21xiNr1YitaoqJE5bHlAkKAMq +ofNkSgwV9ekkxZEBrVBC2C3A+lAW/c3JOoejqaAoByk755TN+S2Wz4vMs4+bvNr9 +Qr6kedWHzg== +-----END AGE ENCRYPTED FILE----- diff --git a/secrets/palace/slop-broker-deploy.key.age b/secrets/palace/slop-broker-deploy.key.age new file mode 100644 index 0000000..7e4c68e --- /dev/null +++ b/secrets/palace/slop-broker-deploy.key.age @@ -0,0 +1,10 @@ +age-encryption.org/v1 +-> ssh-ed25519 et2zpQ D6sQ1TprrCFgQd1Ukd4ZmutvzGNWhaE4ycp8PwGncE0 +440RZtql1+26lzUAP5MfpGIGQkapbjVKq7HXInUGTws +-> X25519 16lP6V5g10e8pLknK3BbbemGA3Xy8Ss0tJF3aqDZTTc +jCs8Q2+id/Mayx2ug2/nx/fI/Gl4XNACjcexGPHKORc +-> i2-grease +67/XLBq8tu7YiLVxQjT+k+g +--- DMVhOUJCMm/7QIRPfguhuM7OJ69IfqvyZufaW3Yn0zI +Q"ƒlr¹°�æRæµx7KzÙß»¡ ¨6±5\îÀ�þ¼"4Ñ´£Hž¥¹xNÝ'Hj‚¯Ñüþj¼8a´¡aéÎJ,P¸HÊqèI…ÝùšöE¹É…ûû��ªZþ‰i?ü¶æ•5!q®ÕR)ÞÑV3kå¾`Ÿª�5ö×Z¯ÕFZw, EY�î©æ¨)®SðQ/WCö hŸÄØÅ_ÏqIÒ(½ž`b�ýŠx¨¶âªjëq“y»üj#ô —‹÷TÑ©¯©ÀJâþ†|¶ÜÂÝÑñŒÁ %û2áz„a:ˆrúïŽ?ýì®XÒT9¯L³*8å[¥ÞG^Ç,ºâáüæ?¢oÅS¦É³¼#…Í \ No newline at end of file diff --git a/secrets/palace/slop-broker-git.key.age b/secrets/palace/slop-broker-git.key.age new file mode 100644 index 0000000..40d7a4c --- /dev/null +++ b/secrets/palace/slop-broker-git.key.age @@ -0,0 +1,20 @@ +-----BEGIN AGE ENCRYPTED FILE----- +YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNzaC1lZDI1NTE5IGV0MnpwUSBNZGNH +ZDZUd2FzMnhCQnFnRTFSYkhja3dzS3RNakg0STJlNFQ2cVZoZ21zCi9Kb3hpT1R3 +eGw0dlVqZnpoOUFUbWpUZFJaL3R2Q1ZWNzY4SmFRNUJ0YTAKLT4gWDI1NTE5IFk3 +TzBuMnpTdDhKaUpOcUZPdWlnbGswQS9RUkJXeUVVQU4vV2pkOGdGeEUKYVRGTjlZ +R1AwMXlaZG9hZitSVmZMbjdRdHFDZXhCWUdtSXBxMEtXcFNSTQotPiBfUHNBUlBG +LWdyZWFzZSAzN2Z3SCB2Ynx0aSBXcS9QCnFMenJOTlp6b244MnVLVmdrVEgwTDNX +MytqTXEyZkdJYlhHRUUvZm1ZVjBTRjJjSzFVeWRtSVRKcmkzYTZ0NmMKCi0tLSA0 +bG51Q21UVHVMaHVyWm1QQnR0Yk9RV0t0eVNLeTJ0SnlZd3kyWFRJU1lJChiXRnaP +84zPID0v+PEd3K1Y6NdMaedbxowSwAQ26KmxqDh33aklgWQIHc9KT92HN2/3yQBN +75zVunCPfuZvz9BSRIg14PaMWx/x1uJ65P5kuqJs2aKndywpJ7BNdFZ6+TMJENIs +9oi47QyoaWL4z1qThkVp0+lAWNJP/VwdM4GepZPbvu7hlbpDWtnAx//LETfoGhzf +uUs1MeTGha9W/XvFPre2522faynqdqJGwBps4e5G6J5AkiwBPLXcSEvf6SrJ04gm +k8HH7ftZWvRSiEXzUjh63et5XbS9+uZIbJc3vFOGbUzIiMsIZcx+KlrT4hAgXAco +X5wKHdnnyxbbs9n9FAaeKrISmWniEOrnaM4Tl7/KUS9/VoVtW2wLbjzcli3dR7ms +kKq/JbAYdhRs/CDQWNo0JUrh7R/lRRB40CpoJgzhEgc9JT0q6COrkHQitIwvFwlh +yeKKdt9PbBu3XTay0BduvY2PI4zPya+fCiUiQ360fiRP0tto/K+I48rrIgKwAl0b +gypvXclE7SuHFVYOB0Pb7n+Nj+2n5cl8OLb1RiECS9XqMOHgeSdTLPen/5T3dNK0 +ff08qWf0zZA+huSPNRyouT4xNTafBaKPu0krP0aWhekeRhdH04UO +-----END AGE ENCRYPTED FILE----- diff --git a/secrets/palace/slop-broker-oidc-secret.age b/secrets/palace/slop-broker-oidc-secret.age new file mode 100644 index 0000000..03a7b63 --- /dev/null +++ b/secrets/palace/slop-broker-oidc-secret.age @@ -0,0 +1,12 @@ +-----BEGIN AGE ENCRYPTED FILE----- +YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNzaC1lZDI1NTE5IGV0MnpwUSArUjRL +WXcwaUVMbTgwWXY0WlBLT3ByZE9GN3M1VitGMEh1MTlRSVZoQ0JZCms1TjU5YWtm +YjNSUVplMlhtY3pOMzlVTlh3SEk4LzhTenArVEt4YmJyS2MKLT4gWDI1NTE5IFFh +YlllbFFWZzlGa0QvcXk5MWVhTEowekFuTy9QQjB3WXo2RzdpUkNLSE0KR2JoMG9K +UElHQmpqWGJ1NVV0UzNIcGFaRVJRayt4TXhOT3Y3Uit3RHFKdwotPiBdSi1ncmVh +c2UgUApkRlN2MXJGTVZ2NFYxZkc3NktHM1BrN0ZwVmlUZWhJeGtjcDFDMS9HRnhO +UE5qbEQrOHNjeDJuelB6STlEYVh6CkFjamVEcEx5REswCi0tLSBsQ1BqMXhyVWp0 +RDJZUDVnVjA0RjVMZXdnck5uUnA4bkZmU01RKzA5UndrCrIa+3q8xp9SJ7zAGom1 +1jbM/Ezso4v61kP1tvWInA+21Y9glrq13rlZ3vTxe08hgVbI8YPbhsZWoEtg5B0I +93w= +-----END AGE ENCRYPTED FILE-----