demo: Add a repository, a builder and secrets

`devenv up` seeds a bare repository with an agenix rules file and two
secrets, encrypted to the demo person and the broker; a pre-receive
hook protects `master`, and `demo-merge` moves it. The agents' VM
clones it over a QEMU guestfwd to `git daemon`, and the broker reaches
`slop-broker builder` through an `ssh` wrapper, so secret requests
work as in a real deployment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jackos1998andClaude Opus 5.5 committed 2026-11-24 01:42:48 +00:00
1 parent 63b256c21b
commit ddee51d092
8 files changed
+251 -19

No files matched your search

+2 -1
View File
@@ -50,7 +50,8 @@ of devenv's scripts, `devenv test` or the demo's host side.
web app, Pocket ID and the box VM); `devenv processes logs <name>` shows a process's output and
`devenv processes down` stops them. `demo` boots the agents' VM on the terminal and holds it until
`poweroff`, so an agent should run it in the background with stdin from a pipe it controls.
`slop-approve` in the devenv shell answers requests, and `demo-box` SSHes into the box VM. Stop
`slop-approve` in the devenv shell answers requests, `demo-box` SSHes into the box VM, and
`demo-merge <branch>` moves the demo repository's protected `master`. Stop
the agents' VM with `poweroff` on its console or by stopping that background task, not with
`pkill -f`, whose pattern also matches the shell running it.
- `nix fmt` — formats Nix with `nixpkgs-fmt`. **Ask before running it on a file you didn't write**:
+145 -8
View File
@@ -2,7 +2,8 @@
# checks are in `flake.nix`.
#
# `devenv up` runs the demo's host side (see `docs/demo.md`): the broker from this checkout, with
# its web app, Pocket ID for approvers to sign in with, and the box VM its SSH targets reach.
# its web app and builder, Pocket ID for approvers to sign in with, the box VM its SSH targets
# reach, and the Git repository the agent pushes to.
{ pkgs, lib, config, ... }:
let
demo = import ./nix/demo/settings.nix;
@@ -10,9 +11,54 @@ let
# Sockets, whose paths must be short
run = "${config.devenv.runtime}/slop-demo";
issuer = "http://localhost:${toString demo.ports.pocketId}";
# Bare repositories the agents' VM reaches with `git://`
repositories = "${state}/git";
appUrl = "http://localhost:${toString demo.ports.web}";
# `@group@` becomes the user's primary group, whose members may approve
# The builder: `slop-broker builder`, which the broker reaches through `ssh` (see `ssh` below).
# The repository is a local path, so its key is never used.
builderConfig = (pkgs.formats.toml { }).generate "slop-demo-builder.toml" {
repository = "${repositories}/repo.git";
key = "/nonexistent";
branch = "master";
directory = "${state}/builder";
# The host's own Nix first, so builds go through its daemon as the user
path = [
"${pkgs.git}/bin"
"${pkgs.openssh}/bin"
"/run/current-system/sw/bin"
"/nix/var/nix/profiles/default/bin"
"${pkgs.nix}/bin"
];
};
# The broker's `ssh`: the host `builder` runs the builder from this checkout's build directly, as
# its forced command would; everything else is the real `ssh`.
ssh = pkgs.writeShellScript "slop-demo-ssh" ''
host="" previous=""
for arg; do
if [ "$previous" = -- ]; then host=$arg; break; fi
previous=$arg
done
if [ "$host" = builder ]; then
exec ${config.devenv.root}/target/debug/slop-broker builder --config ${builderConfig}
fi
exec ${pkgs.openssh}/bin/ssh "$@"
'';
# Only `demo-merge` moves `master`, standing in for branch protection and a person merging
preReceive = pkgs.writeShellScript "slop-demo-pre-receive" ''
while read -r old new ref; do
if [ "$ref" = refs/heads/master ]; then
echo "master is protected: push a branch, and merge it with \`demo-merge <branch>\` on the host" >&2
exit 1
fi
done
'';
# `@group@` becomes the user's primary group, whose members may approve, and `@dev@` the demo
# person's age public key
brokerConfig = (pkgs.formats.toml { }).generate "slop-demo.toml" {
requesters.agent = { vsock_cid = demo.agentCid; policy = "agent"; };
policies.agent.ops = {
@@ -25,6 +71,12 @@ let
{ match.target = "vault"; action = "deny"; }
];
};
# Approvals show whether the file and its recipients match `master`; reading always asks
secret = {
action = "ask";
leases = [ "5m" ];
rules = [{ match.action = "keys"; action = "auto"; }];
};
};
vsock_port = 6262;
@@ -33,7 +85,7 @@ let
audit_log = "${state}/audit.jsonl";
ssh = {
ssh = "${pkgs.openssh}/bin/ssh";
ssh = "${ssh}";
key = "${state}/broker-key";
known_hosts = "${state}/known_hosts";
targets = lib.genAttrs [ "web" "router" "vault" ] (_: {
@@ -43,6 +95,17 @@ let
});
};
deploy = {
builder = { hostname = "builder"; user = "builder"; };
nix = "${pkgs.nix}/bin/nix";
cache = "${state}/nix-cache";
};
secrets = {
identity = "${state}/broker-age.key";
names.dev = "@dev@";
};
web = {
listen = "127.0.0.1:${toString demo.ports.web}";
url = appUrl;
@@ -69,7 +132,7 @@ in
# `pkg-config` with OpenSSL for Web Push's payload encryption and SQLite for the web app's
# sessions, `git` for the builder's tests
packages = with pkgs; [ pkg-config openssl sqlite git nixpkgs-fmt curl jq ];
packages = with pkgs; [ pkg-config openssl sqlite git nixpkgs-fmt curl jq rage ];
# For `slop-approve` in this shell
env.SLOP_APPROVE = "unix:${run}/approve.sock";
@@ -86,9 +149,32 @@ in
echo "The broker isn't running: start \`devenv up\` first." >&2
exit 1
fi
# Git from the VM: connections to 10.0.2.100:9418, an address only the guest sees, each
# run a `git daemon` on the host serving the demo's repositories. Commas are doubled for
# QEMU.
daemon="${pkgs.git}/bin/git daemon --inetd --export-all --enable=receive-pack --base-path=${repositories}"
export QEMU_NET_OPTS="guestfwd=tcp:10.0.2.100:9418-cmd:''${daemon//,/,,}"
exec nix run "$DEVENV_ROOT#demo" -- "$@"
'';
};
demo-merge = {
description = "Fast-forward the demo repository's `master` to a branch, as a person merging";
exec = ''
set -eu
branch=''${1:?usage: demo-merge <branch>}
cd ${repositories}/repo.git
if ! git rev-parse --verify --quiet "refs/heads/$branch" >/dev/null; then
echo "there's no branch $branch; the agent pushes one with \`git push origin <branch>\`" >&2
exit 1
fi
if ! git merge-base --is-ancestor master "refs/heads/$branch"; then
echo "$branch isn't master plus new commits; rebase it on master first" >&2
exit 1
fi
git update-ref refs/heads/master "refs/heads/$branch"
echo "master is now at $(git rev-parse --short master)"
'';
};
demo-box = {
description = "SSH into the demo's box VM as `box`, with the broker's key";
exec = ''
@@ -106,7 +192,7 @@ in
'';
};
demo-reset = {
description = "Delete the demo's state (Pocket ID's users and passkeys, keys, audit log)";
description = "Delete the demo's state (Pocket ID's users and passkeys, keys, repository, audit log)";
exec = ''rm -rf ${state}'';
};
vm-test = {
@@ -122,7 +208,7 @@ in
exec = ''
set -eu
umask 077
mkdir -p ${state}/box ${state}/pocket-id ${state}/web ${run}
mkdir -p ${state}/box ${state}/pocket-id ${state}/web ${state}/builder ${run}
if [ ! -e ${state}/pocket-id.env ]; then
key() { ${pkgs.openssl}/bin/openssl rand -hex 32; }
@@ -136,6 +222,57 @@ in
'';
};
# Once: the repository, with secrets encrypted to the demo person and the broker. The hook is
# installed every time, so it follows changes here.
"slop-demo:repo" = {
description = "Seed the demo's repository and age identities";
after = [ "slop-demo:keys" ];
exec = ''
set -eu
umask 077
export PATH=${lib.makeBinPath (with pkgs; [ coreutils git rage openssl wireguard-tools ])}
if [ ! -d ${repositories}/repo.git ]; then
for name in dev broker; do
[ -e ${state}/$name-age.key ] || rage-keygen -o ${state}/$name-age.key 2>/dev/null
rage-keygen -y ${state}/$name-age.key > ${state}/$name-age.pub
done
dev=$(cat ${state}/dev-age.pub) broker=$(cat ${state}/broker-age.pub)
work=$(mktemp -d)
cp -r ${./nix/demo/repo}/. "$work"
chmod -R u+w "$work"
mkdir "$work/secrets"
cat > "$work/secrets.nix" <<EOF
# The agenix rules: who each secret is encrypted to.
let
dev = "$dev";
broker = "$broker";
in
{
"secrets/app.env.age".publicKeys = [ dev broker ];
"secrets/wg.key.age".publicKeys = [ dev broker ];
}
EOF
printf 'DB_USER=app\nDB_PASSWORD=%s\n' "$(openssl rand -hex 12)" |
rage -a -r "$dev" -r "$broker" -o "$work/secrets/app.env.age"
wg genkey | rage -a -r "$dev" -r "$broker" -o "$work/secrets/wg.key.age"
export GIT_AUTHOR_NAME=Dev GIT_AUTHOR_EMAIL=dev@example.org
export GIT_COMMITTER_NAME=Dev GIT_COMMITTER_EMAIL=dev@example.org
git -C "$work" init -q --initial-branch=master
git -C "$work" add .
git -C "$work" commit -q -m "Start the demo repository"
mkdir -p ${repositories}
git init -q --bare --initial-branch=master ${repositories}/repo.git
git -C "$work" push -q ${repositories}/repo.git master
rm -rf "$work"
fi
ln -sf ${preReceive} ${repositories}/repo.git/hooks/pre-receive
'';
};
# Once: the approver `demo` in the group `slop-approvers`, and the broker's OIDC client
"slop-demo:pocket-id" = {
description = "Set up the demo's approver and OIDC client in Pocket ID";
@@ -181,11 +318,11 @@ in
slop-broker = {
exec = ''
sed "s/@group@/$(id -gn)/" ${brokerConfig} > ${state}/broker.toml
sed -e "s/@group@/$(id -gn)/" -e "s/@dev@/$(cat ${state}/dev-age.pub)/" ${brokerConfig} > ${state}/broker.toml
exec cargo run -q --bin slop-broker -- serve --config ${state}/broker.toml
'';
cwd = config.devenv.root;
after = [ "slop-demo:pocket-id" ];
after = [ "slop-demo:pocket-id" "slop-demo:repo" ];
ready = {
exec = "test -S ${run}/approve.sock";
period = 1;
+1 -1
View File
@@ -28,7 +28,7 @@ How the code is put together, and how to extend it. The design and its rationale
| `tests/broker.rs` | Handler tests over an in-memory duplex stream with a fake `ssh` |
| `src/web/` | The approvals web app: routes (`mod.rs`), OIDC sign-in and passkey confirmation (`auth.rs`), Web Push (`push.rs`), the audit log by request (`history.rs`), the pages (`page.rs`) and static assets |
| `templates/`, `askama.toml` | The web app's HTML, as [askama](https://askama.rs) templates compiled into the broker; `askama.toml` passes everything they show through `ops::printable` before escaping it |
| `nix/` | The package, NixOS modules (`modules/nixos`), home-manager module (`modules/home-manager`), the VM test (`vm-test.nix`, `checks.<system>.vm`), clippy and rustfmt checks (`lints.nix`) and the demo's VMs (`demo/`, `packages.<system>.demo` and `demo-box`) |
| `nix/` | The package, NixOS modules (`modules/nixos`), home-manager module (`modules/home-manager`), the VM test (`vm-test.nix`, `checks.<system>.vm`), clippy and rustfmt checks (`lints.nix`) and the demo's VMs and repository template (`demo/`, `packages.<system>.demo` and `demo-box`) |
| `devenv.nix` | The development environment, its scripts and the demo's host side (`devenv up`); `nix develop` gives a plainer shell from `flake.nix` without them |
| `.gitea/workflows/ci.yaml` | CI: `nix flake check` |
+52 -4
View File
@@ -1,8 +1,9 @@
# 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, and its SSH targets are another VM. Paseo
and real coding agents are out of scope: you type the agent's `slop` commands yourself.
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:
@@ -26,13 +27,16 @@ demo # the agents' VM, on this terminal
| [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 | `localhost:2222`, as `box` | `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
[`devenv.nix`](../devenv.nix):
- **Requester:** `agent`, the agents' VM's vsock CID. The VMs have no network beyond their
forwarded ports, and only vsock links the agents' VM to the host.
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:** `web`, `router` and `vault` all reach the box VM.
@@ -42,6 +46,8 @@ CID are in [`settings.nix`](../nix/demo/settings.nix). The broker's configuratio
- `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.
## Approving
@@ -58,6 +64,47 @@ requests in the background with stdin closed:
slop ssh web -- uptime </dev/null &
```
## The repository
`devenv up` seeds a bare repository once from [`nix/demo/repo`](../nix/demo/repo), committed to
`master` as Dev:
- `secrets.nix`, the agenix rules, and two secrets encrypted to the demo person's age key and the
broker's: `secrets/app.env.age` (`DB_USER` and `DB_PASSWORD`) and `secrets/wg.key.age` (a
WireGuard key, as a whole file). The keys are `dev-age.key` and `broker-age.key` in the state
directory; the broker's approvals call the first `dev`.
- A `pre-receive` hook refuses pushes to `master`, standing in for branch protection.
`demo-merge <branch>` in the devenv shell fast-forwards `master` to a branch, as a person
merging after review.
The agents' VM clones it to `~/repo` at login. 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 over `git://` and reach nothing else.
The broker reaches its builder over SSH, as in a real deployment. Here its `ssh` is a wrapper that
runs `slop-broker builder` from this checkout's build when the host is `builder`, and the real
`ssh` otherwise. 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)
```
## 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
@@ -68,7 +115,8 @@ approved commands did; `demo-box <command>` runs one command there. Its console
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 audit log and the web app's sessions. `demo-reset`
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.
If the broker doesn't start, read `devenv processes logs slop-broker`, and the setup's output in
+2 -2
View File
@@ -496,6 +496,6 @@ Both wait until a concrete need comes up.
`vm-test` in the devenv shell, or `nix build -L .#checks.x86_64-linux.vm`.
- **CI** ([`ci.yaml`](../.gitea/workflows/ci.yaml)): every push runs `nix flake check`, which builds
the package with its tests, checks clippy and rustfmt (`nix/lints.nix`), and runs the VM test.
- **Demo** ([`demo.md`](demo.md)): not a test, but the quickest way to try the web app and
passkey approvals by hand.
- **Demo** ([`demo.md`](demo.md)): not a test, but the quickest way to try the web app, passkey
approvals and secrets (with the builder and a protected main branch) by hand.
- New operations add tests against fakes of what they call (deploy-rs, the DNS provider's API).
+31 -3
View File
@@ -1,9 +1,13 @@
# The demo's agents' VM: an `agent` user with `slop`, which reaches the broker on the host over
# vsock, like a real agents' VM. `devenv up` runs the broker; `demo` boots this VM on the terminal.
# vsock, like a real agents' VM, and a clone of the demo repository, which it reaches through a
# QEMU forward to `git daemon` on the host. `devenv up` runs the broker; `demo` boots this VM on the
# terminal and sets up the forward.
{ pkgs, slop-broker }:
let
inherit (pkgs) lib;
settings = import ./settings.nix;
# Only the guest sees this address; the `demo` script forwards it to the host
repository = "git://10.0.2.100/repo.git";
help = pkgs.writeShellScriptBin "demo-help" ''
cat <<'EOF'
@@ -19,6 +23,16 @@ let
slop requests your pending requests and leases
slop guide the guide agents get
Secrets, in ~/repo (a clone of the demo repository; master only moves with `demo-merge` on
the host):
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
cp secrets/app.env.age secrets/notes.age
slop secret read secrets/notes.age the approval says it's secrets/app.env.age
git switch -c secrets && git commit -am "Rotate secrets" && git push origin secrets
Approve on the host: `slop-approve` in the devenv shell, or the web app at
http://localhost:${toString settings.ports.web} (`demo-sign-in` prints a sign-in link).
@@ -58,8 +72,22 @@ in
'';
};
environment.systemPackages = [ slop-broker help ];
environment.systemPackages = [ slop-broker help pkgs.git ];
# For `slop secret`, which evaluates `secrets.nix`
nix.settings.experimental-features = [ "nix-command" "flakes" ];
environment.etc.gitconfig.text = ''
[user]
name = agent
email = agent@example.org
'';
programs.bash.loginShellInit = ''
if [ "$USER" = agent ]; then demo-help; fi
if [ "$USER" = agent ]; then
if [ ! -d ~/repo ] && ! git clone -q ${repository} ~/repo; then
echo "Cloning ${repository} failed; start the VM with \`demo\` on the host, which forwards it." >&2
fi
cd ~/repo 2>/dev/null || true
demo-help
fi
'';
})).vm
+11
View File
@@ -0,0 +1,11 @@
# slop-broker demo repository
The repository the demo's agent works in. `master` is protected: pushes to it are refused, and
only `demo-merge <branch>` on the host moves it, standing in for a person merging after review.
- `secrets.nix` is the agenix rules file: who each secret is encrypted to. `dev` is the demo's
person and `broker` is the broker's own identity.
- `secrets/app.env.age` holds `DB_USER` and `DB_PASSWORD`; `secrets/wg.key.age` is a WireGuard
private key, as a whole file.
Change secrets with `slop secret` (`slop guide` explains it), commit, and push a branch.
+7
View File
@@ -0,0 +1,7 @@
# The demo's repository, which the agent clones, changes and pushes. `devenv up` seeds it once,
# with `secrets.nix` and the secrets beside this file.
{
description = "slop-broker demo repository";
outputs = { self }: { };
}