CI / Check (push) Successful in 5m59s
Pages polled `/api/version` every three seconds, then fetched the pending list and replaced it, or reloaded a request's page. Now each page follows one stream from `/events`, whose `morph` events carry a region of the page: the pending list, or the request, as a whole element with its `id`, rendered by the page's own templates. The page script morphs it into the page with idiomorph, vendored, so open details, the focus and typing stay. The stream starts with the current region, so a page catches up when the browser reconnects, and it ends when the approver signs out. `/api/version` and `/pending` are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
632 lines
37 KiB
Markdown
632 lines
37 KiB
Markdown
# slop-broker design
|
|
|
|
`slop-broker` lets coding agents use credentials they must never hold: deploy and SSH keys, the
|
|
age identity for secrets, a binary cache and DNS API tokens. Agents send it requests through the
|
|
`slop` CLI, and it carries out each one under a policy, usually after a human approves it from a
|
|
terminal, the web app or the phone.
|
|
|
|
The usual setup runs agents in a VM (the **agents' VM**) and the broker on the box that hosts it
|
|
(the **broker's box**), outside the agents' reach. Agents on other boxes can use it too (see
|
|
[Other requesters and approvers](#other-requesters-and-approvers)). The reference deployment is
|
|
[nixfiles](https://git.nul.ie/dev/nixfiles), whose `docs/slop-broker.md` describes how its boxes use
|
|
the broker.
|
|
|
|
**Status:** the core, the box queries, `slop ssh`, the SSH transport, deploys, builds, age
|
|
secrets and the approvals web app are implemented. The other operations here are
|
|
designed but not built yet (see [Planned operations](#planned-operations)). How the code is put
|
|
together is in [`architecture.md`](architecture.md); the NixOS and home-manager modules are in
|
|
[`nix/modules`](../nix/modules).
|
|
|
|
## Requests at a glance
|
|
|
|
Every request names an operation, which the requester's policy answers with `deny`, `auto` or
|
|
`ask`. What happens before that answer depends on the kind of request, because approvers should
|
|
see what a request really does, and that sometimes needs a look at the repository first.
|
|
|
|
```mermaid
|
|
flowchart TD
|
|
request["Request from slop"] --> kind{"Kind"}
|
|
kind -- "query, ssh" --> approve
|
|
kind -- "secret" --> lookup["Builder reads the main branch:<br>what the file is, its recipients"] --> approve
|
|
kind -- "deploy, build" --> describe["Builder fetches the commit:<br>commits and diff (Git only)"]
|
|
describe --> gate{"Approve use of the builder"}
|
|
gate -- "approved" --> build["Builder builds; deploys also<br>copy to the nodes and compare"] --> approve
|
|
gate -- "denied" --> denied["Denied"]
|
|
approve{"Approve the request:<br>auto, a lease or a person"}
|
|
approve -- "approved" --> run["Broker runs it with its credentials"]
|
|
approve -- "denied or expired" --> denied
|
|
```
|
|
|
|
- **Box queries and SSH** (`status`, `logs`, `failed`, `ssh`)
|
|
- Before approval: nothing. Approvers see the command.
|
|
- Once approved: the broker runs it over SSH and streams the output.
|
|
- **Secrets** (`secret keys|set|generate|rekey|read`)
|
|
- Before approval: the builder reads the main branch, so approvers see which file the content
|
|
really is and whether the recipients match the rules.
|
|
- Once approved: the broker decrypts, changes and re-encrypts, and returns the new ciphertext.
|
|
- **Deploys** (`deploy`)
|
|
- Before approval: the builder fetches the commit, and approvers first allow it to build
|
|
(they see the commits and diff). It builds, and the broker copies the result to each node and
|
|
compares it with what's installed, so approvers see package, unit and file changes.
|
|
- Once approved: the broker activates on every node.
|
|
- **Builds** (`build`)
|
|
- Before approval: as for deploys, up to building. Approvers see each output's size.
|
|
- Once approved: the broker pushes the outputs to the binary cache.
|
|
- **`requests`**: the requester's own pending requests and leases; always allowed.
|
|
|
|
Pending requests go to every approver at once: the [web app](#approvals-web-app) (with Web Push)
|
|
and `slop-approve`. How the code does it is in
|
|
[`architecture.md`](architecture.md#request-lifecycle).
|
|
|
|
## Trust model
|
|
|
|
| Part | Trusted with | Because |
|
|
|---|---|---|
|
|
| The agents' VM and other requesters | Nothing | Everything in them is agent-controlled, including root |
|
|
| The broker | Every credential; it runs each privileged step itself | It's outside the agents' reach |
|
|
| The builder | A read-only Git key | It evaluates agent-written Nix |
|
|
| The broker's box | Everything the broker holds | It should be trusted with that already |
|
|
| The repository's main branch | What approvals compare against | Only people can push to it |
|
|
|
|
- **Requests are untrusted.** That includes commands, file contents, commit IDs, labels and a
|
|
requester's own descriptions of its requests.
|
|
- **Credentials stay with the broker.** None reaches a requester; the one exception is an explicit
|
|
`slop secret read`.
|
|
- **Scopes.** Each request has a scope, which is what an approval covers (for example: deploy
|
|
`web` at commit X). The broker builds both the scope and the text shown to approvers from
|
|
validated fields, never from text the agent wrote.
|
|
- **Results are published.** Anything returned to a requester ends up in the agent's context, so
|
|
in the model provider's transcript and in the agent's session logs.
|
|
- **No agent Nix in the broker.** A builder evaluates it, as a separate user. The broker's
|
|
privileged half only copies, signs, encrypts or activates the results.
|
|
- **Secrets add little.** With deploys, the deploy key is root on every box it reaches, so also
|
|
giving the broker access to secrets doesn't widen what its box must be trusted with.
|
|
- **Protect the main branch.** Approvals show changes relative to it, and secrets are checked
|
|
against it, so requesters' Git credentials must not be able to push to it.
|
|
- **Policies are per requester.** Each requester names a policy, and several can share one; leases
|
|
and request limits are still counted per requester.
|
|
|
|
## Transport
|
|
|
|
- **vsock for the agents' VM.** The VM gets a `vhost-vsock` device with a fixed CID, and the broker
|
|
listens on `AF_VSOCK` on its box.
|
|
- The kernel-reported peer CID identifies the requester; nothing the guest sends can change it.
|
|
- The VM never connects to the broker over the network, so its network can stay isolated from
|
|
the broker's box.
|
|
- **Unix sockets** for local users on the broker's box, identified by UID.
|
|
- **Messages** are typed Rust enums shared by `slop` and the broker (the encoding is in
|
|
[`architecture.md`](architecture.md#protocol)).
|
|
- Decoding validates every value (node and unit names, ports and so on) and rejects unknown
|
|
fields.
|
|
- The request carries a protocol version, so a mismatched `slop` gets a clear error.
|
|
- **One connection per request**, carrying in order:
|
|
1. the request;
|
|
2. the operation's stdin, only after approval and only for operations that read it (`ssh`
|
|
carries its stdin in the request instead, below). The broker drops stdin an operation
|
|
doesn't read, and treats a requester sending more than 1 MiB as gone;
|
|
3. its stdout and stderr;
|
|
4. a final message with the exit status and any structured result.
|
|
|
|
If the connection closes, the broker cancels the request or kills the process it started. A
|
|
deploy's activation is the exception: stopping it partway would leave boxes half changed, so
|
|
the broker waits for it and logs how it ended.
|
|
|
|
### Other requesters and approvers
|
|
|
|
Requesters and approvers on other boxes connect with SSH instead, which reuses `sshd` for
|
|
authentication and stream handling.
|
|
|
|
- **Forced commands.** They log in as `slop` on the broker's box, and each key's forced command is
|
|
`slop-broker remote <requester|approver> <name>`.
|
|
- Keys come from `services.slop-broker.requesters.<name>.sshKeys` and
|
|
`services.slop-broker.sshApprovers.<name>`.
|
|
- The command connects to the broker's remote socket, which only `slop` can use, and tells the
|
|
broker whose key it is. The broker trusts that the same way it trusts a CID.
|
|
- **One job per key.** The module refuses the same key as both requester and approver, and the
|
|
client says which job it wants (`ssh … request` or `ssh … approve`), so a key used with the wrong
|
|
client fails with a clear error.
|
|
- A requester key only allows making requests, so the agents on that box may read it.
|
|
- An approver key must be out of their reach.
|
|
- **Policies.** The agents' VM is identified by its CID, the others by their key, and each names a
|
|
policy. For example, workstations might share one that only allows `dns`, the box queries and
|
|
`requests`.
|
|
- **Finding the broker.** The first that is set wins:
|
|
|
|
| Client | Variable | `~/.config/slop/config.toml` | Default |
|
|
|---|---|---|---|
|
|
| `slop` | `$SLOP_BROKER` | `broker` | vsock |
|
|
| `slop-approve` | `$SLOP_APPROVE` | `approve` | `approve.sock` on the box |
|
|
|
|
An `ssh:<destination>` address goes to `ssh` as is, so a `Host` entry with `IdentitiesOnly` can
|
|
pick the right key when a box has both kinds. `SLOP_SSH` replaces the `ssh` command, like
|
|
`GIT_SSH_COMMAND`.
|
|
- **home-manager.** `programs.slop.request` and `programs.slop.approve` each take a key file, and
|
|
get the `slop-request` and `slop-approve` `Host` entries and the config file pointing at them. It
|
|
writes a config file rather than session variables, because shells started before a switch don't
|
|
see new variables.
|
|
|
|
## The `slop` CLI
|
|
|
|
There is one client command. Every subcommand blocks until the request is answered,
|
|
then streams the output.
|
|
|
|
| Command | Purpose | Suggested policy |
|
|
|---|---|---|
|
|
| `slop status <node> [unit]`, `slop logs <node> <unit>`, `slop failed <node>` | Fixed read-only queries on boxes | auto |
|
|
| `slop ssh <node> -- <cmd>`, `slop ssh --host user@host[:port] -- <cmd>` | Any command over SSH | ask |
|
|
| `slop deploy <node[.profile]>… [--commit <rev>] [--boot]` | Build a pushed commit and deploy it, to all targets at once | ask |
|
|
| `slop build <attr>… [--commit <rev>]` | Build flake attributes of a pushed commit and push them to a binary cache | ask |
|
|
| `slop secret keys\|set\|generate\|rekey\|read <file> …` | Work with age secrets in the requester's checkout | `keys` auto, `read` always ask, others ask |
|
|
| `slop dns list\|set\|delete …` (planned) | Change records in public DNS zones | `list` auto, others ask |
|
|
| `slop preview <port> [--name n] [--public] [--auth basic\|sso] [--ttl 4h]` (planned) | Publish a dev server | ask |
|
|
| `slop requests` | Show this requester's pending requests and active leases | always allowed |
|
|
|
|
Every request can carry `--label` (agent, repo and a one-line reason). The CLI fills it in
|
|
automatically where it can. Approvals show it marked as agent-supplied.
|
|
|
|
## Approvals and policy
|
|
|
|
Policies are named in `services.slop-broker.policies`, and each requester picks one with `policy`,
|
|
so several requesters (agents on different boxes, say) can share one. A policy has request limits
|
|
(`maxPending`, `autoPerMinute`) and an entry per operation in `ops`. An operation without an entry
|
|
is denied; `requests` is always allowed.
|
|
|
|
Each operation's entry has its own settings:
|
|
|
|
| Option | Meaning |
|
|
|---|---|
|
|
| `action` | `auto` runs at once, `ask` waits for an approver, `deny` refuses |
|
|
| `leases` | The lease lengths approvers are offered, such as `"5m"` or `"1h"` |
|
|
| `confirm` | `"passkey"`: approving needs a fresh passkey in the web app |
|
|
| `rules` | Exceptions, checked in order. The first whose `match` fits replaces `action`, and `leases` and `confirm` where it sets them |
|
|
|
|
```nix
|
|
services.slop-broker.policies.agents.ops = {
|
|
query.action = "auto";
|
|
ssh = { action = "ask"; leases = [ "5m" "1h" ]; };
|
|
deploy = {
|
|
action = "ask";
|
|
rules = [{ match.node = "router*"; action = "ask"; confirm = "passkey"; }];
|
|
};
|
|
};
|
|
```
|
|
|
|
Rules match fields of the request's scope with globs (`*` and `?`), and each operation has its
|
|
own fields. The module and the broker refuse any other operation or field.
|
|
|
|
| Operation | Fields rules can match |
|
|
|---|---|
|
|
| `query` (`status`, `logs`, `failed`) | `target` (a node) and `container` (only for a container on it), or `host` and `port` (`--host`); `query` |
|
|
| `ssh` | `target` and `container`, or `host` and `port` |
|
|
| `deploy` | `node`, `profile`, `mode` (`switch` or `boot`), `commit`; checked per target, and the strictest answer applies |
|
|
| `builder` | `commit`, `on_branch` (`true` or `false`), `for` (`deploy` or `build`) |
|
|
| `build` | `attr`, `commit`; checked per attribute |
|
|
| `secret` | `action` (`keys`, `read`, `set`, `generate`, `rekey`), `path` |
|
|
|
|
- **Answers.** An `ask` request waits for an answer from the [web app](#approvals-web-app) or
|
|
`slop-approve` (on the broker's box, or over SSH from another), up to
|
|
`services.slop-broker.timeout`. The answers are:
|
|
- **once**;
|
|
- a **lease**: the same scope is approved for a while, and only lengths the policy allows are
|
|
offered;
|
|
- **deny**.
|
|
- **Passkeys.** `slop-approve` can only deny a request that needs a passkey. Deploys to routers are
|
|
a typical use.
|
|
- **Limits.** `auto` operations are rate-limited per requester, so a looping agent can't hammer
|
|
boxes or APIs. Pending requests are capped per requester and overall to limit notification spam.
|
|
- **Restarts** drop pending requests and leases. Deploying the broker's box doesn't restart it;
|
|
restart `slop-broker.service` for a new version or configuration to take effect.
|
|
|
|
### Approvals web app
|
|
|
|
Phone notifications are easy to lose, and a terminal isn't always at hand. The broker serves a web
|
|
app (`services.slop-broker.web`, code in [`src/web`](../src/web)) that makes approving reliable, and
|
|
on a desktop shows what `slop-approve` can only print.
|
|
|
|
- **The page is the source of truth.** It lists what's pending with full detail and the active
|
|
leases, and updates itself.
|
|
- A dismissed or missed notification costs nothing; a notification only points at its request.
|
|
- Requests that need a passkey are marked, with a padlock on their approve buttons.
|
|
- **Audit log.** The log page groups the audit file by request: who asked, what, the outcome and
|
|
who approved it.
|
|
- Filters by requester, operation and outcome, and a search.
|
|
- Each request's page shows its full timeline, including the detail approvers saw, so a
|
|
notification for a request that's since been answered still leads somewhere useful.
|
|
- **Front end.** Server-rendered HTML that works without JavaScript.
|
|
- A small script keeps the page current and manages notifications, and a service worker shows
|
|
them.
|
|
- **Live updates.** Each open page follows one stream of Server-Sent Events (`/events`).
|
|
- Each event carries a region of the page as HTML: a whole element with its `id`, such as the
|
|
pending list or a request, rendered by the same templates as the page. Agent-supplied text
|
|
is only ever escaped by them, never in the browser.
|
|
- The script morphs each region into the page with
|
|
[idiomorph](https://github.com/bigskysoftware/idiomorph) (vendored), so open details, the
|
|
focus and what's being typed stay.
|
|
- A region comes when the stream starts, so a page that lost its connection catches up when
|
|
the browser reconnects, and then when it changes. Signing out ends the stream.
|
|
- Everything shown passes through the same filter as `slop-approve` for control and
|
|
bidirectional characters.
|
|
- A strict content security policy allows only the app's own scripts.
|
|
|
|
#### Sign-in
|
|
|
|
The web app listens on the broker's box (loopback by default, `web.address`) behind a reverse
|
|
proxy that terminates TLS; only the proxy should reach it. Approvers sign in through an OpenID
|
|
Connect provider. [Pocket ID](https://pocket-id.org), which only uses passkeys, is the one it's
|
|
tested with, and the [demo](demo.md) runs it.
|
|
|
|
- **Signing in.** The broker is an OIDC client (`web.clientId`, the `openidconnect` crate, with
|
|
PKCE), and checks the ID token itself rather than trusting a header from the proxy.
|
|
- Only members of `web.group` may sign in. The provider should restrict the client to that
|
|
group, and the broker checks the token's `groups` claim too.
|
|
- Every sign-in asks the provider to authenticate afresh (`max_age=0`) and checks the token's
|
|
`auth_time`. Signing out of the app therefore means the next sign-in needs the passkey, even
|
|
while the provider's own session lasts.
|
|
- **Sessions.** A sign-in gives a session cookie (`tower-sessions`) that lasts seven days without
|
|
use.
|
|
- Sessions are kept in an SQLite database in the broker's state directory, so a restart doesn't
|
|
sign phones out.
|
|
- Answers are POSTs that need the browser's `Origin` to be the app and the session's token.
|
|
- The audit log names web approvers like `alice (web)`.
|
|
- **Per-request passkeys, optional.** Approving a request whose policy says `confirm = "passkey"`
|
|
sends the approver back to the provider with `max_age=0`, which makes it ask for the passkey
|
|
again.
|
|
- The sign-in remembers the request, the answer and a hash of what was shown.
|
|
- The broker accepts it only if the ID token is the same account's, its `auth_time` is no older
|
|
than the challenge, and the request hasn't changed.
|
|
- Pocket ID was tested to prompt and return a fresh `auth_time` for both `max_age=0` and
|
|
`prompt=login`. A provider that doesn't can't confirm these requests.
|
|
- The audit log names these approvers like `alice (web, passkey)`.
|
|
- **What a session trusts.** Anything that can use the approver's session can answer requests that
|
|
don't need a fresh passkey, including agents running as that user on a workstation. That's
|
|
accepted when agents mostly run in the agents' VM; per-request passkeys cover operations where it
|
|
matters.
|
|
|
|
#### Notifications
|
|
|
|
The web app sends [Web Push](https://web.dev/articles/push-notifications-overview) notifications to
|
|
every device an approver turns them on for. Each links to its request; on desktop browsers and
|
|
Android it also has **Once** and **Deny** buttons (Android shows at most two), which the service
|
|
worker answers with the session like the page does. Requests that need a passkey only offer
|
|
**Deny**. The broker clears a notification once its request is answered or expires.
|
|
|
|
- **Privacy.** Payloads are encrypted to the browser, so the push service (Google, Mozilla, Apple)
|
|
sees only timing and size. The broker signs pushes with a VAPID key it creates in its state
|
|
directory.
|
|
- **Where it works.** Desktop browsers deliver pushes while the browser is running, with or without
|
|
the tab. Android delivers them with everything closed. iOS (16.4 and later) only does once the
|
|
app is added to the Home Screen, and shows no buttons.
|
|
- **Endpoints.** The broker only accepts subscriptions at the major push services (Google's
|
|
`fcm.googleapis.com` and `jmt<N>.google.com`, Mozilla, Apple, Microsoft), so a session can't make
|
|
it send requests elsewhere.
|
|
- **Replacing Home Assistant.** The broker used to send Home Assistant Companion notifications
|
|
instead. Those pass through Firebase Cloud Messaging readable in transit, can be swiped away on
|
|
Android 14 and later with nothing to fall back on, and need an admin user on Home Assistant. Web
|
|
Push is end-to-end encrypted, and the page holds every pending request.
|
|
|
|
### Request details
|
|
|
|
What approvers see of a request is a `Detail` (`src/detail.rs`): fields, then sections, each a
|
|
table, a list or preformatted text. Fields and table rows have a tone, and a warning tone marks
|
|
what needs attention, such as a secret whose content belongs to another file.
|
|
|
|
- **Web app:** fields as a label/value grid that stays in view; sections under a fold, tables
|
|
styled like the audit log. The request's own page opens the fold. Fields, columns and lists
|
|
marked as code (commands, commits, paths, keys) are in monospace, and diffs are coloured.
|
|
- **Everything else** shows the text rendering: a field per line, then each section under its
|
|
title, with tables in aligned columns and warnings marked `⚠`. `slop-approve` shows it as it is,
|
|
and Web Push a cut-down version that puts headline fields first.
|
|
- **Audit log and passkeys:** the audit log keeps the text rendering, so old records read the same
|
|
whatever the structure becomes, and passkey confirmations fingerprint it.
|
|
- **Limits:** each value, row count and text section is capped, and sections past the total limit
|
|
are dropped with a note saying which.
|
|
|
|
The structure is the same for every operation; what's particular to each is only how it fills the
|
|
fields and sections:
|
|
|
|
- **SSH and queries:** the command.
|
|
- **Builder approvals:** the commit, whether it's on the main branch, the commits, changed files
|
|
and diff.
|
|
- **Deploys:** the commit, and for each profile a packages table (version and size changes), the
|
|
changed units and `/etc` files, and whether a reboot is needed.
|
|
- **Builds:** each output with its closure size.
|
|
- **Secrets:** see [what approvers see](#what-approvers-see).
|
|
|
|
A typed detail per operation was considered: every surface would need a renderer for every
|
|
operation, and nothing acts on the structure besides showing it.
|
|
|
|
### Audit log
|
|
|
|
Each request, decision, approver, lease use and result is an event with the request's ID. The
|
|
broker writes it to the journal as a line of text and to `audit.jsonl` in its state directory as a
|
|
line of JSON, keeping what approvers were shown with its structure, so the web app's history shows
|
|
it as the request did. `slop-approve log [-n 50] [--json]` shows the recent events through the
|
|
approve socket, with each request's full detail. Secret operations record the file and the blob ID of the
|
|
ciphertext they were sent, never values.
|
|
|
|
## Operations
|
|
|
|
### Box queries and SSH
|
|
|
|
- **Targets** are the deploy-rs nodes on the main branch, by name, so a new box needs a commit
|
|
there rather than a new broker config. SSH therefore needs deploys set up.
|
|
- The builder evaluates each node's `hostname`, `sshUser`, `sshOpts` and `sudo`, falling back to
|
|
the flake-wide `sshUser` and `sudo`, and its profiles' names. Only the protected branch's Nix
|
|
runs, as for secrets.
|
|
- The broker looks them up again when they're stale, or when a request names a node it doesn't
|
|
know.
|
|
- `--host` covers boxes outside them (OpenWrt, switches) with an explicit `user@host` and port.
|
|
- **Containers** are targets too, as `node.container-<name>`, the same name `slop deploy` takes:
|
|
a node's `container-<name>` profiles say which containers it has, and `<name>` is the machine
|
|
name `systemd-machined` knows the container by (a NixOS container, or any `systemd-nspawn`
|
|
machine).
|
|
- The broker reaches the node as usual and runs the command there as root, through the node's
|
|
`sudo`: `systemctl --machine`, `journalctl --machine` and, for `ssh`, `systemd-run --machine
|
|
--pipe --wait` with `/bin/sh -l -c <line>`. Stdin, output and the exit status pass through.
|
|
- Approvers see the container and the remote command, including `sudo … root` and
|
|
`--machine`.
|
|
- A container's scope has the node as `target` and the container as `container`. Rules for a
|
|
node therefore apply to its containers (match `container = "*"` to tell them apart), but a
|
|
lease covers only the target it was granted for.
|
|
- Commands go to the node's login shell as one string, quoted so that a POSIX shell and `fish`
|
|
read the same words.
|
|
- **Fixed options.** SSH runs with `-F none`, the key with `IdentitiesOnly`, no agent,
|
|
`BatchMode`, no forwarding or local commands, and the broker's own `known_hosts` (new hosts are
|
|
accepted, changed ones refused).
|
|
- **`slop ssh` always asks.** `ssh` joins its arguments into a string that the remote shell runs,
|
|
so a free-form command's text can't be judged as read-only.
|
|
- **Approvers see everything that reaches the box.** A script piped to `bash -s` is as much the
|
|
command as its arguments, so `slop ssh` sends its whole stdin with the request.
|
|
- Approvers see the line the remote shell runs (the words joined with spaces, as `ssh` sends
|
|
them) and all of the stdin, and the audit log keeps both.
|
|
- The command gets exactly that stdin and nothing more.
|
|
- Stdin must be UTF-8 text, and the command and stdin together are limited
|
|
([`MAX_SSH_SHOWN`](../src/proto.rs)) so they're always shown whole; anything else is
|
|
refused.
|
|
- **The queries can be `auto`.** `status`, `logs` and `failed` validate their arguments (unit
|
|
names, `--since`, line counts), and the broker builds the quoted remote command. They cover most
|
|
of what agents need SSH for without prompting.
|
|
|
|
### Deploys
|
|
|
|
`slop deploy <target>… [--commit <rev>] [--boot]` deploys a pushed commit of a
|
|
[deploy-rs](https://github.com/serokell/deploy-rs) flake to one or more targets, each a node (all
|
|
its profiles, like `deploy .#node`) or `node.profile` (such as `host.container-web`). The client
|
|
resolves `--commit` (default `HEAD`) to a full ID in its checkout.
|
|
|
|
The builder is a user without keys, `slop-broker-build`, whose key's forced command is
|
|
`slop-broker builder` ([`services.slop-broker-builder`](../nix/modules/nixos/builder.nix)). The
|
|
broker runs it over SSH.
|
|
|
|
1. **Describe.** The builder fetches every branch from the Git server with a read-only key, so the
|
|
agent never supplies the source.
|
|
- It refuses commits that aren't on a branch.
|
|
- This stage runs only Git: it returns the commits since the main branch, their diffstat and
|
|
their diff.
|
|
2. **Approve use of the builder.** Evaluation runs agent-written Nix, so it waits for a separate
|
|
`builder` request to be approved, which shows the commits and the diff.
|
|
- Its scope is empty, so a lease lets the agent build any commit for a while.
|
|
- Rules see the `commit`, `on_branch` (whether it's already on the main branch) and `for`
|
|
(`deploy` or `build`).
|
|
3. **Build.** The builder evaluates the targets' deploy-rs profiles and builds them with the box's
|
|
Nix daemon.
|
|
- Only `git` gets the repository key, never the evaluator.
|
|
- Build logs stream to the agent. One build runs at a time.
|
|
- The broker reads built paths from the builder's store, `nix copy --from ssh-ng://` its
|
|
user with the broker's key; the builder key's forced command serves `nix-daemon --stdio`
|
|
for that. So the builder can be on another box with a store of its own, and nothing lands
|
|
in the broker's store. The builder never holds a key to the nodes or the cache.
|
|
4. **Compare, before approval.** The broker copies the closures to each node, as deploy-rs does,
|
|
and compares each profile with the one installed.
|
|
- Nodes substitute what the caches have; progress streams to the agent.
|
|
- The comparison is a fixed read-only script. Nothing runs as root, and no agent-written code
|
|
runs.
|
|
5. **Approve the deploy.** One approval covers every target, the commit and the mode.
|
|
- Policy rules see one scope per target (`node`, `profile`, `mode`, `commit`), and the
|
|
strictest answer applies, so for example a rule can allow routers only `boot`.
|
|
6. **Activate.** On every node at once, the broker runs deploy-rs's `activate-rs` on each profile in
|
|
deploy-rs's order.
|
|
- It runs as root through the target's `sudo` command (`sudo -u` by default), inside a
|
|
transient unit (`systemd-run`), so the activation finishes even if the connection drops.
|
|
Its output streams back until then and is discarded after, since `activate-rs` stops when
|
|
it can't write.
|
|
- Switching doesn't restart the broker (`restartIfChanged = false`), so it can deploy its own
|
|
box and report the result. A new version or configuration of the broker takes effect when
|
|
it's next restarted.
|
|
- **If the agent goes away,** the broker keeps waiting for the activations and logs their
|
|
outcome. The audit log says the requester left, then how the deploy finished.
|
|
- **If the broker goes away** (a crash, or its box rebooting), the activations still finish.
|
|
Their units are named `slop-deploy-<request ID>-<profile>`, so the audit record leads to
|
|
their journals on each node.
|
|
- Output comes back prefixed with the node.
|
|
- Deploys run in parallel; an agent that needs an order sends separate requests.
|
|
|
|
There is no magic rollback, unlike deploy-rs from a workstation. `--boot` makes the new
|
|
configuration the boot default without switching to it. Activation, including `dry-activate`, runs
|
|
the new system's own code as root, so none of it happens before approval.
|
|
|
|
#### Approval contents
|
|
|
|
- **Packages:** version and size changes, from `nix store diff-closures`.
|
|
- **Configuration:** changed, added and removed systemd units (drop-ins count as their unit) and
|
|
`/etc` files, from comparing the two profiles' `etc` trees, whose entries are links into the
|
|
store. That approximates what activation will restart without running anything.
|
|
- **Reboots:** a kernel or initrd change is called out.
|
|
- **Commits:** Git's messages and diffstat, for the commits since the main branch.
|
|
|
|
The full view, in `slop-approve show <id>` or the web app, looks like this:
|
|
|
|
```text
|
|
deploy hub (switch) at 3f9c2e1a8b0c
|
|
Commit 3f9c2e1a8b0c4d…
|
|
Commits:
|
|
3f9c2e1 nixos/hub: Update Home Assistant
|
|
8a1b7d0 nixos/hass: Add Zigbee coordinator
|
|
nixos/boxes/hub/containers/hass.nix | 14 +++++++++-----
|
|
1 file changed, 9 insertions(+), 5 deletions(-)
|
|
hub.system (switch):
|
|
packages: no version changes
|
|
changed units: container@hass.service
|
|
hub.container-hass (switch):
|
|
packages:
|
|
home-assistant: 2026.11.1 → 2026.11.2, +3.4 MiB
|
|
python3.13-zha: 0.0.71 → 0.0.72
|
|
changed units: home-assistant.service
|
|
changed files: /etc/hass/configuration.yaml
|
|
```
|
|
|
|
The phone notification carries only the first line and the label. It isn't the place to review a
|
|
large deploy. For those, approve from the web app or a terminal.
|
|
|
|
### Binary cache
|
|
|
|
Anything in a cache's store is signed and trusted by every box that uses it. A path built inside
|
|
the agents' VM proves nothing, because the agent could upload a different output under the hash of
|
|
a real derivation. So the cache is filled only from builds done by the builder.
|
|
|
|
- **Requests.** `slop build <attr>… [--commit <rev>]` works like a deploy up to approval.
|
|
- Once use of the builder is approved, it builds the flake attributes.
|
|
- The `build` request shows the commits and each output with its closure size.
|
|
- The `builder` approval is where a person reviews the source; a policy can then let `build`
|
|
push without asking again.
|
|
- **Pushing.** Once approved, the broker pushes the outputs with `nix copy --to ssh-ng://` as the
|
|
store's owner (`services.slop-broker.cache`).
|
|
- That key's forced command ([`services.slop-broker-cache`](../nix/modules/nixos/cache.nix))
|
|
allows only `nix-daemon --stdio` on the cache's store, and `root <path>…`, which adds GC roots
|
|
under `gcroots/slop-broker`.
|
|
- The broker adds the roots before copying, so a garbage collection in that store can't take
|
|
the paths mid-copy.
|
|
- **Expiry.** A daily timer removes roots `keepDays` after their path was last pushed, and the
|
|
store's next collection takes the paths: agent builds are for sharing for a while, not for
|
|
keeping.
|
|
|
|
### Secrets
|
|
|
|
The broker has its own age identity, added as a recipient of the secrets it may handle next to
|
|
the people's keys, so no person's key goes to the broker's box. Adding it to an existing repository
|
|
needs one full rekey.
|
|
|
|
The requester sends the current `.age` file with each request, and the broker returns new
|
|
ciphertext. The broker never writes to a checkout.
|
|
|
|
| Command | Result | Value reaches the requester? |
|
|
|---|---|---|
|
|
| `keys <file>` | Key names of an env or JSON secret | No |
|
|
| `set <file> [<key>]` (value on stdin) | That field, or the whole file, replaced and re-encrypted | Only what it sent |
|
|
| `generate <file> [<key>] --kind password\|hex\|base64\|wireguard\|ssh-ed25519\|age` | A value the broker creates; keypair kinds return the public half | No |
|
|
| `rekey <file>` | Re-encrypted to the given recipients | No |
|
|
| `read <file>` | Plaintext | Yes, so always `ask`, never leased |
|
|
|
|
Field edits work on env files (`.env.age`, keeping every other line as it was) and JSON objects
|
|
of strings (`.json.age`). Anything else is changed whole.
|
|
|
|
#### What approvers see
|
|
|
|
The path in a request is only the requester's name for the file, and the ciphertext and the
|
|
recipients come from the requester too. Before approval, the builder fetches the main branch, which
|
|
only people should be able to push to, and the approval shows what that branch says.
|
|
|
|
- **What the content is.** The builder looks the ciphertext's Git blob ID up on the branch, and the
|
|
approval says the file is one of:
|
|
|
|
| Found | Means |
|
|
|---|---|
|
|
| The named path | The file as on the branch |
|
|
| Another path (flagged) | An agent could be sending a sensitive file's ciphertext under a harmless name, to have it read or re-encrypted to a key of its own |
|
|
| Nowhere | A new file, or one changed on a branch |
|
|
|
|
A pushed commit wouldn't prove anything here, since any branch can copy a blob to any path.
|
|
- **Whether the recipients are right.** The builder evaluates the branch's own agenix rules file
|
|
(`secrets.rules`, cached per commit) for the path.
|
|
- The approval says whether the requested recipients match it, with a table of the keys, each as
|
|
in the rules, added or removed; or that the path isn't in the rules.
|
|
- Only the protected branch's Nix is evaluated, never a requester's commit, so this doesn't need
|
|
the builder approval.
|
|
- Keys are labelled by name from `secrets.names` (well-known keys, such as people's), then from
|
|
SSH keys' comments anywhere in the branch's rules (`ssh-ed25519 AAAA… shill`, which age
|
|
ignores). Other keys are shown abbreviated.
|
|
- **The broker's own key.** The broker always adds it to the recipients, and says so, so it can
|
|
change the file later.
|
|
- **Sensitive requests.** Requests that read a secret, change who can read one or name content as
|
|
another file are marked sensitive.
|
|
- **Audit.** The audit log records the approval's text, including the blob ID, never values.
|
|
|
|
## Planned operations
|
|
|
|
### DNS
|
|
|
|
For public zones that are edited through a provider's API rather than from Nix config. Zones that
|
|
come from Nix config are changed with commits and deploys instead. Cloudflare is the first
|
|
provider.
|
|
|
|
- `slop dns list <zone> [name]` shows the live records. `slop dns set <name> <type> <value>…
|
|
[--ttl] [--proxied]` replaces the record set for that name and type, and `slop dns delete <name>
|
|
<type>` removes it.
|
|
- The approval shows the record set before and after, read live from the provider. Leases are
|
|
scoped by name and type.
|
|
- The broker uses its own API token, limited to DNS edits in the allowed zones and separate from
|
|
any other automation's tokens.
|
|
- Policy denies zone apexes, `NS`, `MX` and `_acme-challenge` names by default. Records the broker
|
|
creates get a record comment, so the approval can say whether an agent is changing one of its own
|
|
records or an existing one.
|
|
|
|
### Previews
|
|
|
|
`slop preview 5173 [--name foo] [--public] [--auth basic|sso] [--ttl 4h]` publishes a dev server
|
|
in the agents' VM under a wildcard domain until its TTL expires.
|
|
|
|
- A reverse proxy serves the wildcard domain with a wildcard certificate and proxies to the broker.
|
|
The broker looks up the host in its active previews and connects to the guest port over vsock.
|
|
The VM still accepts no inbound connections.
|
|
|
|
#### Access
|
|
|
|
The hostname and the authentication are chosen separately.
|
|
|
|
- **Secret URL (default):** the hostname is an unguessable label, for example
|
|
`foo-<26 base32 characters>.<domain>`, which is 128 random bits after the optional name.
|
|
Because DNS and the certificate are wildcards, the name never appears in the zone or in
|
|
Certificate Transparency logs. Unknown hostnames get the same 404 as expired ones. Responses
|
|
carry `Referrer-Policy: no-referrer` and `X-Robots-Tag: noindex`.
|
|
- **`--public`:** the hostname is just the name (`foo.<domain>`). Without `--auth` this is a fully
|
|
public site. Public names are never leased, so each one needs its own approval.
|
|
- **`--auth basic`:** adds basic auth with a generated password. It's shown in the approval and
|
|
returned to the agent, which needs it to test the page and controls the content anyway.
|
|
- **`--auth sso`:** adds the proxy's existing single sign-on.
|
|
- The secret URL still leaks through browser history, shared links and resolver logs. Use an auth
|
|
option for anything that matters.
|
|
- If the preview domain is a subdomain of other services' domain, preview pages are same-site with
|
|
them: they can set cookies on the parent domain, and browsers send `SameSite=Lax` cookies
|
|
(including an SSO session) with their requests to those services. A separate registrable domain
|
|
avoids this.
|
|
|
|
### TCP forwards and a cache for VM builds
|
|
|
|
- **TCP forwards:** time-limited access from the VM to one internal `host:port` (for example a
|
|
database), approved per destination.
|
|
- **VM-built paths:** a separate store with its own signing key, trusted only by the agents' VM and
|
|
by boxes that opt in. Useful for sharing agent build artifacts or keeping them across VM
|
|
rebuilds.
|
|
|
|
Both wait until a concrete need comes up.
|
|
|
|
## Agent-facing docs
|
|
|
|
- **Agent context:** the package ships [`slop-tools.md`](../slop-tools.md), which describes the
|
|
`slop` CLI and how requests behave (they block while waiting for approval, so no retrying in a
|
|
loop). `slop guide` prints it, and it's installed as `share/slop-broker/slop-tools.md` for
|
|
deployments to add to their agents' rules. Update the guide with each new operation. It asks
|
|
agents to suggest new operations when they would otherwise work around a missing one or keep
|
|
asking for the same `slop ssh` approval.
|
|
- **Agent permissions:** the broker is the gate, so an agent's own permission prompt for `slop`
|
|
would only ask twice; allow `slop` and keep denying direct use of deploy tools and keys.
|
|
- **Deployment docs:** deployment-specific notes (which nodes exist, their login shells, where the
|
|
Git server is) belong in the deployment's own agent rules.
|
|
|
|
## Scope
|
|
|
|
- **Out of scope for now:** secret tools other than age (such as `sops`), and a general
|
|
credential proxy for other APIs (forges, package registries). Agents keep using deploy keys of
|
|
their own for pushing. If more API operations are needed later, add them one at a time like
|
|
`dns`.
|