demo: Deploy to the box VM

The demo repository's flake gets a deploy-rs node, `box`, with a small
custom profile whose activation writes its version, using nixpkgs'
deploy-rs so builds are quick, and its nixpkgs locked to this
repository's. The box VM lets `box` use `sudo` and copy unsigned
paths, and the broker's policy covers the builder and deploys, so a
pushed branch can be deployed and its package changes approved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jackos1998andClaude Opus 5.5 committed 2026-11-24 02:01:35 +00:00
1 parent ddee51d092
commit 9d54664f5c
7 files changed
+142 -13

No files matched your search

+15 -2
View File
@@ -71,6 +71,16 @@ let
{ match.target = "vault"; action = "deny"; }
];
};
# Agent-written Nix runs in the builder once its use is approved; `master` is reviewed
builder = {
action = "ask";
leases = [ "5m" "1h" ];
rules = [{ match.on_branch = "true"; action = "auto"; }];
};
deploy = {
action = "ask";
leases = [ "5m" ];
};
# Approvals show whether the file and its recipients match `master`; reading always asks
secret = {
action = "ask";
@@ -88,7 +98,7 @@ let
ssh = "${ssh}";
key = "${state}/broker-key";
known_hosts = "${state}/known_hosts";
targets = lib.genAttrs [ "web" "router" "vault" ] (_: {
targets = lib.genAttrs [ "box" "web" "router" "vault" ] (_: {
hostname = "localhost";
user = "box";
ssh_opts = [ "-p" (toString demo.ports.boxSsh) ];
@@ -230,7 +240,7 @@ in
exec = ''
set -eu
umask 077
export PATH=${lib.makeBinPath (with pkgs; [ coreutils git rage openssl wireguard-tools ])}
export PATH=${lib.makeBinPath (with pkgs; [ coreutils git rage openssl wireguard-tools jq ])}
if [ ! -d ${repositories}/repo.git ]; then
for name in dev broker; do
@@ -243,6 +253,9 @@ in
cp -r ${./nix/demo/repo}/. "$work"
chmod -R u+w "$work"
mkdir "$work/secrets"
# nixpkgs as this repository locks it, so the builder already has it
jq '{nodes: {root: {inputs: {nixpkgs: "nixpkgs"}}, nixpkgs: .nodes[.nodes.root.inputs.nixpkgs]}, root: "root", version: 7}' \
${./flake.lock} > "$work/flake.lock"
cat > "$work/secrets.nix" <<EOF
# The agenix rules: who each secret is encrypted to.
let
+30 -3
View File
@@ -25,7 +25,7 @@ demo # the agents' VM, on this terminal
| 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 | `localhost:2222`, as `box` | `devenv up` (process `box`) |
| Box VM ([`box.nix`](../nix/demo/box.nix)): `sshd` for the targets, and the deploy target | `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` |
@@ -39,7 +39,8 @@ CID are in [`settings.nix`](../nix/demo/settings.nix). The broker's configuratio
[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.
- **Targets:** `box`, `web`, `router` and `vault` all reach the box VM; `box` is also the deploy
node.
- **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.
@@ -48,6 +49,8 @@ CID are in [`settings.nix`](../nix/demo/settings.nix). The broker's configuratio
- `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 ask.
There's no binary cache, so `slop build` says it isn't configured.
## Approving
@@ -105,6 +108,27 @@ approvals show the new files as on `master`. To check a value as the demo person
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 box VM
`demo-box` in the devenv shell logs in to the box VM as `box`, with the broker's key, to see what
@@ -117,7 +141,10 @@ The VMs keep nothing: `poweroff` (or Ctrl-A X) stops the agents' VM, and each bo
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.
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`.
+1 -1
View File
@@ -497,5 +497,5 @@ Both wait until a concrete need comes up.
- **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, passkey
approvals and secrets (with the builder and a protected main branch) by hand.
approvals, secrets and deploys (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).
+7
View File
@@ -33,6 +33,13 @@ let
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
Deploys, of the profile `demo` in flake.nix to the box VM (`demo-box cat /run/demo/version`
on the host shows what's active):
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 & asks to use the builder, builds, then asks again
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).
+16 -4
View File
@@ -1,6 +1,7 @@
# The box the demo's SSH targets reach: `sshd` with a `box` account for the broker's key. `devenv up`
# runs it with `SHARED_DIR` holding the broker's public key and the box's host key, which it keeps
# between runs so the broker's `known_hosts` stays valid.
# The box the demo's SSH targets reach: `sshd` with a `box` account for the broker's key, which may
# use `sudo` and copy store paths, so the broker can deploy to it. `devenv up` runs it with
# `SHARED_DIR` holding the broker's public key and the box's host key, which it keeps between runs
# so the broker's `known_hosts` stays valid.
{ pkgs }:
let
inherit (pkgs) lib;
@@ -16,7 +17,8 @@ in
virtualisation = {
graphics = false;
diskImage = null;
memorySize = 512;
# Copied closures live in memory
memorySize = 1024;
restrictNetwork = true;
forwardPorts = [{
from = "host";
@@ -26,6 +28,16 @@ in
};
users.users.box.isNormalUser = true;
# Deploys: activation as root, and closures copied in unsigned (the store is the VM runner's
# writable overlay). Nothing is substituted, since the VM has no network.
security.sudo.extraRules = [{
users = [ "box" ];
commands = [{ command = "ALL"; options = [ "NOPASSWD" ]; }];
}];
nix.settings = {
trusted-users = [ "root" "box" ];
substituters = lib.mkForce [ ];
};
services.openssh = {
enable = true;
hostKeys = [{ path = hostKey; type = "ed25519"; }];
+5 -1
View File
@@ -8,4 +8,8 @@ only `demo-merge <branch>` on the host moves it, standing in for a person mergin
- `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.
`flake.nix` has a deploy-rs node, `box`, with one profile, `demo`: a small app whose activation
writes its version to `/run/demo/version`.
Change secrets with `slop secret` (`slop guide` explains it), commit, and push a branch. Deploy a
pushed commit with `slop deploy box`.
+68 -2
View File
@@ -1,7 +1,73 @@
# 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.
# with `secrets.nix`, the secrets and `flake.lock` beside this file.
{
description = "slop-broker demo repository";
outputs = { self }: { };
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = { self, nixpkgs }:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
# Change this, push a branch and `slop deploy box`: the approval shows the version change
version = "1.0";
app = pkgs.writeTextFile {
name = "demo-app-${version}";
destination = "/bin/demo-app";
executable = true;
text = ''
#!${pkgs.runtimeShell}
echo "demo app ${version}"
'';
};
# A profile deploy-rs can activate, as `deploy-rs.lib.<system>.activate.custom` makes them,
# with nixpkgs' build of deploy-rs so nothing needs compiling
activatable = base: activate: pkgs.buildEnv {
name = "activatable-${base.name}";
paths = [
base
(pkgs.writeTextFile {
name = "deploy-rs-activate";
destination = "/deploy-rs-activate";
executable = true;
text = ''
#!${pkgs.runtimeShell}
set -eu
if [ "''${BOOT:-}" = 1 ]; then
echo "nothing to stage for boot"
exit 0
fi
${activate}
'';
})
(pkgs.writeTextFile {
name = "activate-rs";
destination = "/activate-rs";
executable = true;
text = ''
#!${pkgs.runtimeShell}
exec ${pkgs.deploy-rs}/bin/activate "$@"
'';
})
];
};
in
{
packages.x86_64-linux.default = app;
# The broker reaches nodes by its own SSH targets, so `hostname` isn't used
deploy.nodes.box = {
hostname = "localhost";
profiles.demo = {
user = "root";
path = activatable app ''
mkdir -p /run/demo
echo ${version} > /run/demo/version
echo "demo app ${version} is active"
'';
};
};
};
}