diff --git a/README.md b/README.md index ea9623f..1adaf02 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/docs/demo.md b/docs/demo.md index 60e1a07..c107d1b 100644 --- a/docs/demo.md +++ b/docs/demo.md @@ -31,7 +31,7 @@ flowchart TB shell["devenv shell:
slop-approve, demo-merge"] subgraph host["Host (devenv up)"] - pocket["Pocket ID
localhost:1411"] + pocket["Pocket ID, with sign-in
localhost:1411"] broker["Broker, with the web app
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 | | Part of the broker | -| [Pocket ID](https://pocket-id.org), for approvers to sign in | | `devenv up` (process `pocket-id`) | +| [Pocket ID](https://pocket-id.org), for approvers to sign in, if they do (see [Approving](#approving)) | | `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 once||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 ; the passkey also approves - `router` requests. Web Push works when the broker can reach the browser's push service. +- **Web app:** , 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 ` 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. diff --git a/nix/demo/agent.nix b/nix/demo/agent.nix index d0ab94a..354c953 100644 --- a/nix/demo/agent.nix +++ b/nix/demo/agent.nix @@ -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 ${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; diff --git a/nix/demo/sign-in.nix b/nix/demo/sign-in.nix new file mode 100644 index 0000000..d05ae47 --- /dev/null +++ b/nix/demo/sign-in.nix @@ -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; + }; + }; + }; +}