The box VM holds the cache's store in a `cache` account, set up by `services.slop-broker-cache`, and the demo's broker pushes to it, so `slop build` can be tried by hand. The broker's key is only known at boot, so the module exposes its forced command for keys it can't list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
210 lines
9.6 KiB
Markdown
210 lines
9.6 KiB
Markdown
# Demo
|
|
|
|
A setup for trying the broker by hand, laid out like a real deployment: the broker runs on the host,
|
|
the agents are in a VM that reaches it only over vsock, its SSH targets are another VM, and the
|
|
agent works in a clone of a Git repository whose main branch it can't push to. Paseo and real
|
|
coding agents are out of scope: you type the agent's `slop` commands yourself.
|
|
|
|
It needs the devenv shell (direnv with `.envrc`, which provides [devenv](https://devenv.sh)) and
|
|
KVM, with `/dev/vhost-vsock` usable by your user. In one terminal:
|
|
|
|
```sh
|
|
devenv up # the host side; `devenv up -d` runs it in the background
|
|
```
|
|
|
|
and in another, in the devenv shell:
|
|
|
|
```sh
|
|
demo # the agents' VM, on this terminal
|
|
```
|
|
|
|
## What's in it
|
|
|
|
```mermaid
|
|
flowchart TB
|
|
subgraph agentvm["Agents' VM (demo)"]
|
|
slop["slop, as agent"]
|
|
clone["~/repo"]
|
|
end
|
|
|
|
browser["Browser"]
|
|
shell["devenv shell:<br>slop-approve, demo-merge"]
|
|
|
|
subgraph host["Host (devenv up)"]
|
|
pocket["Pocket ID<br>localhost:1411"]
|
|
broker["Broker, with the web app<br>localhost:8095"]
|
|
daemon["git daemon"]
|
|
builder["Builder"]
|
|
repo[("repo.git")]
|
|
end
|
|
|
|
subgraph boxvm["Box VM"]
|
|
sshd["sshd, as box<br>(nodes web, router, vault, box)"]
|
|
cache["sshd, as cache<br>(the binary cache's store)"]
|
|
end
|
|
|
|
slop -- "vsock" --> broker
|
|
clone -- "git://, through guestfwd" --> daemon --> repo
|
|
browser -- "sign in" --> pocket
|
|
browser --> broker
|
|
shell -- "approve.sock" --> broker
|
|
shell -- "moves master" --> repo
|
|
broker -- "SSH, through a wrapper" --> builder -- "fetches" --> repo
|
|
broker -- "SSH, localhost:2222" --> sshd
|
|
broker -- "SSH, localhost:2222" --> cache
|
|
```
|
|
|
|
| Part | Where | Runs |
|
|
|---|---|---|
|
|
| Broker, from this checkout (`cargo run`) | Host | `devenv up` (process `slop-broker`) |
|
|
| Web app | <http://localhost:8095> | Part of the broker |
|
|
| [Pocket ID](https://pocket-id.org), for approvers to sign in | <http://localhost:1411> | `devenv up` (process `pocket-id`) |
|
|
| Box VM ([`box.nix`](../nix/demo/box.nix)): `sshd` for the targets, the deploy target and the binary cache | `localhost:2222`, as `box`, and as `cache` for the cache | `devenv up` (process `box`) |
|
|
| Agents' VM ([`agent.nix`](../nix/demo/agent.nix)), signed in as `agent` | Your terminal | `demo` |
|
|
| The repository, seeded from [`repo/`](../nix/demo/repo) | `.devenv/state/slop-demo/git/repo.git` | `git daemon`, one per connection from the agents' VM |
|
|
| The builder (`slop-broker builder`, from this checkout) | Host | The broker, through its `ssh` |
|
|
|
|
The ports are on the host's loopback, so they must be free there; they and the agents' VM's vsock
|
|
CID are in [`settings.nix`](../nix/demo/settings.nix). The broker's configuration is in
|
|
[`host.nix`](../nix/demo/host.nix), the devenv module with the demo's host side:
|
|
|
|
- **Requester:** `agent`, the agents' VM's vsock CID. The VMs have no network beyond their
|
|
forwarded ports, and only vsock and Git link the agents' VM to the host (see
|
|
[the repository](#the-repository)).
|
|
- **Approvers:** members of your primary group, through `slop-approve` in the devenv shell, and the
|
|
Pocket ID user `demo` (in the group `slop-approvers`) through the web app.
|
|
- **Targets:** the repository's deploy-rs nodes on `master`, `box`, `web`, `router` and `vault`,
|
|
which all reach the box VM. Only `box` has a profile to deploy.
|
|
- **Policy:**
|
|
- The box queries (`slop status`, `slop logs`, `slop failed`) run without asking.
|
|
- `slop ssh web` asks, and offers leases of 5 minutes or an hour.
|
|
- `slop ssh router` asks and needs a passkey (`confirm = "passkey"`), so only the web app can
|
|
approve it.
|
|
- `slop ssh vault` is denied.
|
|
- `slop secret keys` runs without asking; the other secret requests ask, with a 5-minute
|
|
lease, except reading, which asks every time.
|
|
- Using the builder asks, with leases, except for commits already on `master`; deploys and
|
|
builds into the binary cache ask, with a 5-minute lease.
|
|
|
|
## Approving
|
|
|
|
- **Terminal:** `slop-approve` in the devenv shell lists pending requests; answer one with
|
|
`slop-approve <id> once|<lease>|deny`.
|
|
- **Web app:** `demo-sign-in` prints a one-time link that signs in to Pocket ID as `demo`. Add a
|
|
passkey when Pocket ID asks, then sign in to <http://localhost:8095>; the passkey also approves
|
|
`router` requests. Web Push works when the broker can reach the browser's push service.
|
|
|
|
A request blocks until it's answered, and `slop ssh` reads stdin to its end before asking. To keep
|
|
the agent's shell, run requests in the background with stdin closed:
|
|
|
|
```sh
|
|
slop ssh web -- uptime </dev/null &
|
|
```
|
|
|
|
## The repository
|
|
|
|
`devenv up` seeds a bare repository once, committed to `master` as Dev.
|
|
|
|
- **From [`nix/demo/repo`](../nix/demo/repo):** `flake.nix`, with the deploy-rs nodes and the
|
|
`demo` profile (see [Deploys](#deploys)).
|
|
- **Generated:** age keys for the demo person and the broker (`dev-age.key` and `broker-age.key`
|
|
in the state directory; the broker's approvals call the first `dev`), and secrets encrypted to
|
|
both:
|
|
- `secrets.nix`, the agenix rules;
|
|
- `secrets/app.env.age`, with `DB_USER` and `DB_PASSWORD`;
|
|
- `secrets/wg.key.age`, a WireGuard key, as a whole file.
|
|
- **Protected `master`:** a `pre-receive` hook refuses pushes to it, standing in for branch
|
|
protection. `demo-merge <branch>` in the devenv shell fast-forwards it to a branch, as a person
|
|
merging after review.
|
|
- **The agents' VM** clones it to `~/repo` at login, over `git://`.
|
|
- The `demo` script forwards `10.0.2.100:9418`, an address only the VM sees, to a `git daemon`
|
|
on the host for each connection (QEMU's `guestfwd`).
|
|
- So the VM can fetch and push, and reach nothing else.
|
|
- **The builder** is reached over SSH, as in a real deployment.
|
|
- The broker's `ssh` is a wrapper that runs `slop-broker builder` from this checkout's build
|
|
when the host is `builder`, and the real `ssh` otherwise.
|
|
- It's named `ssh`, so the broker's `nix copy` and `nix path-info` use it too when they read
|
|
built paths from the builder's store (`ssh-ng://builder@builder`), which the builder serves
|
|
as `nix-daemon --stdio`.
|
|
- The builder fetches from the repository's path and evaluates with the host's Nix.
|
|
|
|
### Secrets
|
|
|
|
In `~/repo` on the agents' VM:
|
|
|
|
```sh
|
|
slop secret keys secrets/app.env.age # runs without asking
|
|
echo hunter2 | slop secret set secrets/app.env.age DB_PASSWORD
|
|
slop secret generate secrets/wg.key.age --kind wireguard # prints the public key
|
|
cp secrets/app.env.age secrets/notes.age
|
|
slop secret read secrets/notes.age </dev/null & # flagged: it's secrets/app.env.age
|
|
git switch -c secrets && git commit -am "Rotate secrets" && git push origin secrets
|
|
```
|
|
|
|
`git push origin master` is refused. On the host, `demo-merge secrets` moves `master`, after which
|
|
approvals show the new files as on `master`. To check a value as the demo person:
|
|
|
|
```sh
|
|
rage -d -i .devenv/state/slop-demo/dev-age.key <(git -C .devenv/state/slop-demo/git/repo.git show master:secrets/app.env.age)
|
|
```
|
|
|
|
### Deploys
|
|
|
|
The repository's `flake.nix` has a deploy-rs node, `box`, with one profile, `demo`, deployed as
|
|
root: a small app whose activation writes its version to `/run/demo/version`. Its `nixpkgs` is
|
|
locked to this repository's, so the builder has it already, and it uses nixpkgs' build of
|
|
deploy-rs, so a build takes moments. In `~/repo` on the agents' VM:
|
|
|
|
```sh
|
|
sed -i 's/version = "1.0"/version = "1.1"/' flake.nix
|
|
git switch -c bump && git commit -am "Bump the app" && git push origin bump
|
|
slop deploy box </dev/null &
|
|
```
|
|
|
|
The first request is to use the builder, showing the commits and the diff since `master`. Once
|
|
it's approved, the builder builds the profile, the broker copies it to the box VM and compares it
|
|
with what's there, and the deploy request shows the package changes (the first deploy shows a new
|
|
profile). `demo-box cat /run/demo/version` on the host shows what's active.
|
|
|
|
The box VM lets `box` use `sudo` without a password and copy unsigned paths into its store, which
|
|
lives in memory, like everything else in the VMs.
|
|
|
|
### The binary cache
|
|
|
|
The box VM holds the binary cache's store, at `/var/lib/slop-cache`, owned by its `cache`
|
|
account, as [`services.slop-broker-cache`](../nix/modules/nixos/cache.nix) sets it up: the
|
|
broker's key may only run `nix-daemon --stdio` on that store and add GC roots. Nothing serves it
|
|
to other boxes; it's for seeing what `slop build` pushes. In `~/repo` on the agents' VM:
|
|
|
|
```sh
|
|
slop build packages.x86_64-linux.default </dev/null &
|
|
```
|
|
|
|
As with a deploy, the builder's use is approved first (or covered by a lease), then the build
|
|
request shows the outputs and their closure sizes, and once approved the broker pushes them and
|
|
prints their paths. To see them on the host:
|
|
|
|
```sh
|
|
demo-box ls /var/lib/slop-cache/nix/var/nix/gcroots/slop-broker
|
|
```
|
|
|
|
## The box VM
|
|
|
|
`demo-box` in the devenv shell logs in to the box VM as `box`, with the broker's key, to see what
|
|
approved commands did; `demo-box <command>` runs one command there. Its console output is in
|
|
`devenv processes logs box`.
|
|
|
|
## State
|
|
|
|
The VMs keep nothing: `poweroff` (or Ctrl-A X) stops the agents' VM, and each boot starts from
|
|
scratch. The host side keeps its state in `.devenv/state/slop-demo` between runs: Pocket ID's
|
|
database (so passkeys survive), the keys, the repository and the builder's mirror, the audit log
|
|
and the web app's sessions. `demo-reset`
|
|
deletes it while `devenv up` isn't running; the next `devenv up` sets Pocket ID up again and seeds
|
|
a new repository. The repository is seeded only once, so after changing
|
|
[`nix/demo/repo`](../nix/demo/repo), reset (or delete `git`, `builder` and the `*-age.*` keys in the
|
|
state directory) to use the new version.
|
|
|
|
If the broker doesn't start, read `devenv processes logs slop-broker`, and the setup's output in
|
|
`devenv up`.
|