demo: Make sign-in to the web app optional
CI / Check (pull_request) Successful in 6m24s

The demo's web app has no sign-in by default, so trying it doesn't
need a one-time link and a passkey. `slopDemo.signIn = true;` in
`devenv.local.nix` brings back Pocket ID, now in `sign-in.nix`, for
trying sign-in and passkeys, which approving `router` needs.

Refs #28

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jackos1998andClaude Opus 5.5 committed 2026-11-29 23:38:33 +00:00
1 parent d81c78814c
commit b75b953bb5
5 files changed
+127 -91

No files matched your search

+1 -1
View File
@@ -14,7 +14,7 @@ OpenID Connect, passkeys, Web Push).
## Trying it
```sh
devenv up # the broker, its web app, Pocket ID and a box VM for the SSH targets
devenv up # the broker, its web app (without sign-in) and a box VM for the SSH targets
demo # in another terminal: the agents' VM, signed in as an agent that can send requests
```
+18 -14
View File
@@ -31,7 +31,7 @@ flowchart TB
shell["devenv shell:<br>slop-approve, demo-merge"]
subgraph host["Host (devenv up)"]
pocket["Pocket ID<br>localhost:1411"]
pocket["Pocket ID, with sign-in<br>localhost:1411"]
broker["Broker, with the web app<br>localhost:8095"]
daemon["git daemon"]
builder["Builder"]
@@ -58,7 +58,7 @@ flowchart TB
|---|---|---|
| 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`) |
| [Pocket ID](https://pocket-id.org), for approvers to sign in, if they do (see [Approving](#approving)) | <http://localhost:1411> | `devenv up` with `slopDemo.signIn` (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 |
@@ -71,15 +71,16 @@ CID are in [`settings.nix`](../nix/demo/settings.nix). The broker's configuratio
- **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.
- **Approvers:** members of your primary group, through `slop-approve` in the devenv shell, and
`demo` through the web app: everyone who opens it, or with sign-in, the Pocket ID user `demo` (in
the group `slop-approvers`).
- **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 router` asks and needs a passkey (`confirm = "passkey"`), so only the web app with
sign-in 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.
@@ -90,9 +91,13 @@ CID are in [`settings.nix`](../nix/demo/settings.nix). The broker's configuratio
- **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.
- **Web app:** <http://localhost:8095>, without sign-in: everyone who opens it approves as `demo`,
which every page says, and it can't approve requests that need a passkey. Web Push works when
the broker can reach the browser's push service.
- **Sign-in and passkeys:** add `slopDemo.signIn = true;` to `devenv.local.nix` (see
[`sign-in.nix`](../nix/demo/sign-in.nix)) and restart `devenv up`, which then runs Pocket ID too.
`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 the web app; the passkey also approves `router` requests.
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:
@@ -208,11 +213,10 @@ approved commands did; `demo-box <command>` runs one command there. Its console
## 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
scratch. The host side keeps its state in `.devenv/state/slop-demo` between runs: the keys, the
repository and the builder's mirror, the audit log, the web app's sessions, and with sign-in,
Pocket ID's database (so passkeys survive). `demo-reset` deletes it while `devenv up` isn't
running; the next `devenv up` seeds a new repository, and sets Pocket ID up again. 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.
+2 -2
View File
@@ -19,7 +19,7 @@ let
slop status web sshd.service runs without asking (policy: auto)
slop logs web sshd.service -n 20
slop ssh web -- uptime asks an approver; leases of 5m or 1h are offered
slop ssh router -- uptime asks too, and approving needs a passkey in the web app
slop ssh router -- uptime asks too, and approving needs a passkey (web app sign-in)
slop ssh vault -- true denied by policy
slop requests your pending requests and leases
slop guide the guide agents get
@@ -49,7 +49,7 @@ let
asks to use the builder, builds, then asks to push
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).
http://localhost:${toString settings.ports.web}, which has no sign-in unless it's turned on.
A request blocks until it's answered. To keep this shell, run it in the background with stdin
closed (`slop ssh` forwards stdin): `slop ssh web -- uptime </dev/null &`. `poweroff` (or
+16 -74
View File
@@ -1,7 +1,8 @@
# The demo's host side, a devenv module that `devenv.nix` imports (see `docs/demo.md`). `devenv up`
# runs the broker from this checkout, with 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. The
# devenv shell gets the commands to drive it (`demo`, `slop-approve`, `demo-merge` and the like).
# runs the broker from this checkout, with its web app and builder, the box VM its SSH targets
# reach, and the Git repository the agent pushes to. The web app has no sign-in unless
# `sign-in.nix` adds Pocket ID. The devenv shell gets the commands to drive it (`demo`,
# `slop-approve`, `demo-merge` and the like).
{ pkgs, lib, config, ... }:
let
settings = import ./settings.nix;
@@ -12,7 +13,6 @@ let
# Bare repositories the agents' VM reaches with `git://`
repositories = "${state}/git";
issuer = "http://localhost:${toString settings.ports.pocketId}";
appUrl = "http://localhost:${toString settings.ports.web}";
# The builder: `slop-broker builder`, which the broker reaches through `ssh` (see `ssh` below).
@@ -147,28 +147,25 @@ let
names.dev = "@dev@";
};
# Without sign-in unless `slopDemo.signIn` (see `sign-in.nix`)
web = {
listen = "127.0.0.1:${toString settings.ports.web}";
url = appUrl;
inherit issuer;
state_dir = "${state}/web";
} // (if config.slopDemo.signIn then {
issuer = "http://localhost:${toString settings.ports.pocketId}";
client_id = "slop-approve";
client_secret = "${state}/oidc-secret";
group = "slop-approvers";
state_dir = "${state}/web";
};
} else {
no_sign_in.approver = "demo";
});
};
# Pocket ID's admin API, with the key `devenv up` made
pocketIdApi = ''
api() {
local method=$1 path=$2
shift 2
curl -sS --fail-with-body -X "$method" "${issuer}/api/$path" \
-H "X-API-Key: $(sed -n 's/^STATIC_API_KEY=//p' ${state}/pocket-id.env)" -H 'Content-Type: application/json' "$@"
}
'';
in
{
imports = [ ./sign-in.nix ];
# For `slop-approve` in this shell
env.SLOP_APPROVE = "unix:${run}/approve.sock";
@@ -225,17 +222,8 @@ in
'';
};
demo-sign-in = {
description = "Print a one-time link that signs in to the demo's Pocket ID as the approver";
exec = ''
${pocketIdApi}
user=$(api GET 'users?search=demo' | jq -r '.data[] | select(.username == "demo") | .id')
echo "${issuer}/lc/$(api POST "users/$user/one-time-access-token" -d '{"ttl":"1h"}' | jq -r .token)"
'';
};
demo-reset = {
description = "Delete the demo's state (Pocket ID's users and passkeys, keys, repository, audit log)";
description = "Delete the demo's state (keys, repository, audit log, and Pocket ID's users and passkeys)";
exec = ''rm -rf ${state}'';
};
};
@@ -247,12 +235,7 @@ in
exec = ''
set -eu
umask 077
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; }
printf 'ENCRYPTION_KEY=%s\nSTATIC_API_KEY=%s\n' "$(key)" "$(key)" > ${state}/pocket-id.env
fi
mkdir -p ${state}/box ${state}/web ${state}/builder ${run}
# The box VM gets the broker's public key and its own host key through its shared directory
[ -e ${state}/broker-key ] || ${pkgs.openssh}/bin/ssh-keygen -q -t ed25519 -N "" -C slop-demo -f ${state}/broker-key
@@ -321,57 +304,16 @@ in
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";
after = [ "devenv:processes:pocket-id" ];
status = "test -s ${state}/oidc-secret";
exec = ''
set -eu
umask 077
${pocketIdApi}
user=$(api POST users -d '{"username":"demo","email":"demo@example.org","firstName":"Demo","lastName":"Approver","displayName":"Demo Approver","isAdmin":false}' | jq -r .id)
group=$(api POST user-groups -d '{"name":"slop-approvers","friendlyName":"slop approvers"}' | jq -r .id)
api PUT "user-groups/$group/users" -d "$(jq -n --arg u "$user" '{userIds: [$u]}')" >/dev/null
api POST oidc/clients -d '{"id":"slop-approve","name":"slop-broker demo","callbackURLs":["${appUrl}/auth/callback"],"isPublic":false,"pkceEnabled":true,"isGroupRestricted":true}' >/dev/null
api PUT oidc/clients/slop-approve/allowed-user-groups -d "$(jq -n --arg g "$group" '{userGroupIds: [$g]}')" >/dev/null
api POST oidc/clients/slop-approve/secrets | jq -j .secret > ${state}/oidc-secret.new
mv ${state}/oidc-secret.new ${state}/oidc-secret
'';
};
};
processes = lib.mkIf (!config.devenv.isTesting) {
pocket-id = {
exec = ''
set -a
. ${state}/pocket-id.env
exec ${pkgs.pocket-id}/bin/pocket-id
'';
cwd = "${state}/pocket-id";
env = {
APP_URL = issuer;
HOST = "127.0.0.1";
PORT = toString settings.ports.pocketId;
ANALYTICS_DISABLED = "true";
};
after = [ "slop-demo:keys" ];
ready = {
http.get = { port = settings.ports.pocketId; path = "/.well-known/openid-configuration"; };
period = 1;
};
};
slop-broker = {
exec = ''
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" "slop-demo:repo" ];
after = [ "slop-demo:repo" ] ++ lib.optional config.slopDemo.signIn "slop-demo:pocket-id";
ready = {
exec = "test -S ${run}/approve.sock";
period = 1;
+90
View File
@@ -0,0 +1,90 @@
# Sign-in for the demo's web app, with Pocket ID, a devenv module that `host.nix` imports. Without
# it the web app has no sign-in. Turn it on with `slopDemo.signIn = true;` in `devenv.local.nix`
# to try signing in and passkeys, which approving `router` needs.
{ pkgs, lib, config, ... }:
let
settings = import ./settings.nix;
state = "${config.devenv.state}/slop-demo";
issuer = "http://localhost:${toString settings.ports.pocketId}";
appUrl = "http://localhost:${toString settings.ports.web}";
# Pocket ID's admin API, with the key `devenv up` made
pocketIdApi = ''
api() {
local method=$1 path=$2
shift 2
curl -sS --fail-with-body -X "$method" "${issuer}/api/$path" \
-H "X-API-Key: $(sed -n 's/^STATIC_API_KEY=//p' ${state}/pocket-id.env)" -H 'Content-Type: application/json' "$@"
}
'';
in
{
options.slopDemo.signIn = lib.mkEnableOption "sign-in to the demo's web app, with Pocket ID";
config = lib.mkIf (config.slopDemo.signIn && !config.devenv.isTesting) {
scripts.demo-sign-in = {
description = "Print a one-time link that signs in to the demo's Pocket ID as the approver";
exec = ''
${pocketIdApi}
user=$(api GET 'users?search=demo' | jq -r '.data[] | select(.username == "demo") | .id')
echo "${issuer}/lc/$(api POST "users/$user/one-time-access-token" -d '{"ttl":"1h"}' | jq -r .token)"
'';
};
tasks = {
"slop-demo:pocket-id-keys" = {
description = "Make Pocket ID's keys for the demo";
exec = ''
set -eu
umask 077
mkdir -p ${state}/pocket-id
if [ ! -e ${state}/pocket-id.env ]; then
key() { ${pkgs.openssl}/bin/openssl rand -hex 32; }
printf 'ENCRYPTION_KEY=%s\nSTATIC_API_KEY=%s\n' "$(key)" "$(key)" > ${state}/pocket-id.env
fi
'';
};
# 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";
after = [ "devenv:processes:pocket-id" ];
status = "test -s ${state}/oidc-secret";
exec = ''
set -eu
umask 077
${pocketIdApi}
user=$(api POST users -d '{"username":"demo","email":"demo@example.org","firstName":"Demo","lastName":"Approver","displayName":"Demo Approver","isAdmin":false}' | jq -r .id)
group=$(api POST user-groups -d '{"name":"slop-approvers","friendlyName":"slop approvers"}' | jq -r .id)
api PUT "user-groups/$group/users" -d "$(jq -n --arg u "$user" '{userIds: [$u]}')" >/dev/null
api POST oidc/clients -d '{"id":"slop-approve","name":"slop-broker demo","callbackURLs":["${appUrl}/auth/callback"],"isPublic":false,"pkceEnabled":true,"isGroupRestricted":true}' >/dev/null
api PUT oidc/clients/slop-approve/allowed-user-groups -d "$(jq -n --arg g "$group" '{userGroupIds: [$g]}')" >/dev/null
api POST oidc/clients/slop-approve/secrets | jq -j .secret > ${state}/oidc-secret.new
mv ${state}/oidc-secret.new ${state}/oidc-secret
'';
};
};
processes.pocket-id = {
exec = ''
set -a
. ${state}/pocket-id.env
exec ${pkgs.pocket-id}/bin/pocket-id
'';
cwd = "${state}/pocket-id";
env = {
APP_URL = issuer;
HOST = "127.0.0.1";
PORT = toString settings.ports.pocketId;
ANALYTICS_DISABLED = "true";
};
after = [ "slop-demo:pocket-id-keys" ];
ready = {
http.get = { port = settings.ports.pocketId; path = "/.well-known/openid-configuration"; };
period = 1;
};
};
};
}