broker: Containers as targets #14

Merged
dev merged 1 commits from containers-as-targets into main 2026-11-28 18:11:43 +00:00

Stacked on #13 (its commit is the first one here); merge that first.

slop status, logs, failed and ssh take node.container-<name>, the name slop deploy already takes, so agents can check a container (such as shill.container-middleman) without an approved slop ssh on its host.

Lookup. The builder now evaluates each node's profile names. A node's container-<name> profiles are the containers requests can name; others are refused before anything runs (unknown container …, exit 125), and slop refuses node.<anything else>.

What runs. The broker reaches the node as usual and runs the command there as root through the node's sudo, via systemd-machined:

Operation Remote command
status <sudo> root systemctl --machine=<name> status --no-pager [-- <unit>]
logs <sudo> root journalctl --machine=<name> --no-pager --output=short-iso --lines=N [--since=…] --unit=<unit>
failed <sudo> root systemctl --machine=<name> list-units --failed --no-pager
ssh <sudo> root systemd-run --machine=<name> --quiet --wait --collect --pipe --expand-environment=no -- /bin/sh -l [-c <line>]

Stdin, output and the exit status pass through for ssh. Approvers see the remote command (with sudo … root and --machine), and container ssh requests carry a Runs field saying so.

Policy. A container's scope is { target = <node>; container = <name>; }:

  • Rules for a node apply to its containers, so palace's query.action = "auto" covers container queries without changes. Rules can match container ("*" for any) to tell them apart; the NixOS module allows the field.
  • Leases key on the whole scope, so a lease for shill doesn't cover shill.container-x, or the reverse.

Quoting. Remote commands go to the node's login shell as one quoted string. Inside single quotes fish reads \\ and \' as escapes, so shell_quote now puts quotes and backslashes outside the quotes, escaped, which POSIX shells and fish read alike. I checked the output in sh, bash and fish; with the old quoting, fish fails on a\\b \'.

Dependency on the container framework: only the container-<name> profile naming. Anything systemd-machined knows by that name works, whether a NixOS container or plain systemd-nspawn.

Tests:

  • Unit tests cover parsing, scopes, the remote commands and quoting, plus a broker test with a policy rule on container and an unknown container.
  • The VM test gets a NixOS container, web. status, logs and failed run without asking. ssh asks again despite the lease for local, and passes stdin through, runs as root in web and returns exit 3. Unknown containers and local.system are refused.
  • cargo test and checks.x86_64-linux.vm pass locally.

Protocol: PROTOCOL_VERSION 3, so slop on slop-cannon and castle must be updated with the broker. No version bump here; I'll bump in a release PR after both this and #13 merge.

Docs: slop-tools.md, docs/design.md, docs/architecture.md.

🤖 Generated with Claude Code

Stacked on #13 (its commit is the first one here); merge that first. `slop status`, `logs`, `failed` and `ssh` take `node.container-<name>`, the name `slop deploy` already takes, so agents can check a container (such as `shill.container-middleman`) without an approved `slop ssh` on its host. **Lookup.** The builder now evaluates each node's profile names. A node's `container-<name>` profiles are the containers requests can name; others are refused before anything runs (`unknown container …`, exit 125), and `slop` refuses `node.<anything else>`. **What runs.** The broker reaches the node as usual and runs the command there as root through the node's `sudo`, via `systemd-machined`: | Operation | Remote command | |---|---| | `status` | `<sudo> root systemctl --machine=<name> status --no-pager [-- <unit>]` | | `logs` | `<sudo> root journalctl --machine=<name> --no-pager --output=short-iso --lines=N [--since=…] --unit=<unit>` | | `failed` | `<sudo> root systemctl --machine=<name> list-units --failed --no-pager` | | `ssh` | `<sudo> root systemd-run --machine=<name> --quiet --wait --collect --pipe --expand-environment=no -- /bin/sh -l [-c <line>]` | Stdin, output and the exit status pass through for `ssh`. Approvers see the remote command (with `sudo … root` and `--machine`), and container `ssh` requests carry a `Runs` field saying so. **Policy.** A container's scope is `{ target = <node>; container = <name>; }`: - Rules for a node apply to its containers, so `palace`'s `query.action = "auto"` covers container queries without changes. Rules can match `container` (`"*"` for any) to tell them apart; the NixOS module allows the field. - Leases key on the whole scope, so a lease for `shill` doesn't cover `shill.container-x`, or the reverse. **Quoting.** Remote commands go to the node's login shell as one quoted string. Inside single quotes `fish` reads `\\` and `\'` as escapes, so `shell_quote` now puts quotes and backslashes outside the quotes, escaped, which POSIX shells and `fish` read alike. I checked the output in `sh`, `bash` and `fish`; with the old quoting, `fish` fails on `a\\b \'`. **Dependency on the container framework:** only the `container-<name>` profile naming. Anything `systemd-machined` knows by that name works, whether a NixOS container or plain `systemd-nspawn`. **Tests:** - Unit tests cover parsing, scopes, the remote commands and quoting, plus a broker test with a policy rule on `container` and an unknown container. - The VM test gets a NixOS container, `web`. `status`, `logs` and `failed` run without asking. `ssh` asks again despite the lease for `local`, and passes stdin through, runs as root in `web` and returns exit 3. Unknown containers and `local.system` are refused. - `cargo test` and `checks.x86_64-linux.vm` pass locally. **Protocol:** `PROTOCOL_VERSION` 3, so `slop` on `slop-cannon` and `castle` must be updated with the broker. No version bump here; I'll bump in a release PR after both this and #13 merge. Docs: `slop-tools.md`, `docs/design.md`, `docs/architecture.md`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
slop-cannon Bot added 2 commits 2026-11-28 17:34:22 +00:00
broker: Never block reading a requester's stdin
CI / Check (pull_request) Successful in 4m53s
CI / Check (push) Canceled after 3m47s
00d3c65cfd
The reader passed stdin to the operation through a channel 16 deep and
waited when it was full, so a requester sending stdin to an operation
that doesn't read it stopped the reader, and the broker no longer saw
it disconnect: the operation kept running.

Buffer stdin without waiting, up to 1 MiB (a requester sending more is
treated as gone), and drop it for operations that don't read it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
broker: Containers as targets
CI / Check (pull_request) Successful in 5m17s
CI / Check (push) Canceled after 0s
4b2c32636e
`slop status`, `logs`, `failed` and `ssh` take `node.container-<name>`,
the name `slop deploy` already takes, so agents can check a container
without asking for `slop ssh` on its host.

- The builder evaluates each node's profile names; its
  `container-<name>` profiles are the containers requests can name.
- Commands run on the node as root through its `sudo`:
  `systemctl --machine`, `journalctl --machine` and, for `ssh`,
  `systemd-run --machine --pipe --wait` with `/bin/sh -l`.
- A container's scope is its node as `target` plus `container`, so
  node rules apply to it while leases stay per target. Rules can
  match `container`.
- Remote commands are now quoted so `fish` reads them as POSIX shells
  do: it treats `\\` and `\'` as escapes inside single quotes.

`PROTOCOL_VERSION` 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dev merged commit 4b2c32636e into main 2026-11-28 18:11:43 +00:00
dev deleted branch containers-as-targets 2026-11-28 18:11:43 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dev/slop-broker#14