feat: run sandbox transports in disposable workers

The control plane opened ssh connections itself, so a malicious ssh
server attacked the process that held the database, the master key, and
every room's keys. It now starts one worker per target and workspace.
The worker gets one target key on stdin, binds loopback behind a random
token, and serves exec, files, the pty, and the preview proxy. It has no
database and no master key, and a closed stdin ends it.

The preview HTTP client moved into the worker too. The app sees a typed
response, and the worker caps bodies, output tails, handshakes, and
transport waits.

Direct targets now reject loopback, private, link-local, multicast,
unspecified, carrier-grade NAT, and documentation addresses when a
target is created and again when its worker starts.
TOGETHER_ALLOW_PRIVATE_TARGETS=1 lifts the check for a server that runs
on one private network.
This commit is contained in:
vhaudiquet committed 2026-11-29 18:22:44 +01:00
1 parent a8f7e74ba0
commit fc684115b5
16 files changed
+1355 -208

No files matched your search

+47 -6
View File
@@ -233,6 +233,40 @@ an idle period or when the owner changes the target. A room whose target
is unreachable keeps its chat: messages post, a turn fails with a room
message, and the panes show the error instead of a spinner.
### A hostile sandbox
The far side is treated as hostile input, not as a trusted peer. The
control plane never opens an ssh connection and never parses an ssh,
HTTP, or terminal byte from a sandbox. Each room gets a disposable
worker process (`rhema-together worker`) that:
- holds only that room's target key, never the master key or the
database;
- listens on loopback behind a random token;
- serves the `rhema-sandbox` HTTP protocol, a pty websocket, and a raw
preview forward socket;
- is started with a cleared environment, `PR_SET_DUMPABLE=0`, and
`PR_SET_NO_NEW_PRIVS`;
- exits when its parent closes stdin, so a crashed server leaves no
orphan holding a key.
If a hostile sandbox exploits russh, the protocol parser, or a worker
route, it lands in a process with no database, no master key, and no
provider credential. The parent kills it and starts another. A
deployment should run workers under a different UID or in a separate
container with no mount for the database and secret key; the
child-process boundary is the portable default, not the strongest tier.
Caps are part of the boundary: a 32 MiB file route cap, 50 KiB output
tails, a 16 MiB static preview cap, a 4 KiB forward handshake line, and
the upstream request timeouts. No path from a sandbox reaches a host
shell: the worker only sends commands over the transport.
The worker does not make the network safe by itself. A direct ssh target
is still a user-supplied address. Link targets are the default because
the server never dials a user's network. Direct target address checks
belong to the API and the config, not to the worker.
### Why ssh first
The ssh backend already runs commands on a remote box with no daemon on
@@ -517,10 +551,16 @@ login. The room log is the audit trail, and abort is the control.
### Outbound connections
The server dials addresses that users supply. Block loopback, link-local,
and multicast destinations by default, so a sandbox target cannot turn
the harness into a probe of its own network. An operator can allow a
private range in the config when every user is on the same network.
The default is a connector link: the sandbox dials out to the server, so
the server never dials a user-supplied address and a hostile sandbox
cannot use it as a probe of the server's network. Direct ssh remains an
opt-in compatibility mode. Its address is checked when the target is
created and again when the worker starts: loopback, private, link-local,
multicast, unspecified, carrier-grade NAT, and documentation addresses
are rejected. An operator on one private network can set
`TOGETHER_ALLOW_PRIVATE_TARGETS=1`. The worker dials the address, never
the control plane. A DNS name that resolves to a public address when the
worker starts and to a private one later is outside this check.
### Secrets
@@ -660,8 +700,9 @@ explanation.
Settled:
1. Sandbox: SSH only in v1. ecrou waits for a live mode, with the
shell-on-top runner as a possible degraded mode.
1. Sandbox: the per-room disposable worker owns every transport. A
connector link is the default; direct SSH is opt-in. ecrou waits for a
live mode, with the shell-on-top runner as a possible degraded mode.
2. Provider and model: the room owner picks both, and only the owner
changes them. Every turn spends from that config.
3. Interrupts: any member. v1 has no rate limit.