feat: add reverse ssh sandbox targets

A sandbox behind NAT could not reach the room. A reverse target dials a tunnel-only sshd on the server, forwards localhost:22 to a loopback port, and the worker connects there.

The server assigns the port and writes one authorized_keys line per tunnel target. The key carries permitlisten for that port; the sshd allows remote forwarding only, with no shell or local forwarding. The tunnel private key is shown once and never stored; rotating it rewrites the file. The target list and setup dialog carry the command, and the docs include the sshd config and sidecar requirements.
This commit is contained in:
vhaudiquet committed 2026-11-29 19:25:14 +01:00
1 parent fc684115b5
commit d85f68a176
20 files changed
+893 -38

No files matched your search

+37 -2
View File
@@ -112,7 +112,8 @@ issue certificates.
Append that line to `~/.ssh/authorized_keys` on the target. Set the
workspace root to a directory the ssh user can write (for a normal
user, `/home/<name>`; the default is `/root`). Test the target; a
green check means ssh works.
green check means ssh works. For a machine behind NAT, choose
**Reverse SSH** instead; see below.
3. **New room.** Pick the target and provider, give the workspace
directory (for example `/home/me/rooms/demo`), and optionally a git
URL. The workspace is created on the first mention and seeded from
@@ -129,6 +130,34 @@ The agent always runs with the room's sandbox, and every command is an
ordinary ssh command. There is no approval prompt: the sandbox is the
boundary.
## Reverse SSH
A machine behind NAT can dial the server instead of accepting a
connection. This is the fallback for an account that will not install a
connector; the server still speaks ssh to the sandbox.
Reverse SSH needs a tunnel-only sshd in the app's network namespace.
`deploy/tunnel` has a config and the setup steps. The app writes the
sshd's `authorized_keys` file: one key per target, restricted to the
target's loopback port with `permitlisten`, no shell, no local
forwarding, and no non-loopback bind.
In **Settings → Sandboxes**, choose **Reverse SSH**. The server assigns
the loopback port. Save the tunnel private key shown once as
`rhema-tunnel-<target-id>` and run `chmod 600` on it. Add the target's
public key to the sandbox's `~/.ssh/authorized_keys`, then run the
command from the target's **Setup** dialog:
```sh
autossh -M 0 -N -R 127.0.0.1:22000:localhost:22 -p 2222 \
tunnel@together.example.com -i ./rhema-tunnel-<target-id> \
-o ExitOnForwardFailure=yes -o ServerAliveInterval=30
```
The sandbox needs an sshd on `localhost:22`. The tunnel key is a
credential; rotating it invalidates the old key. The tunnel sshd is
internet-facing, so patch it and rate-limit it.
## Preview
The preview shows one target per room. It is either a port inside the
@@ -201,7 +230,13 @@ Every field can be set in the YAML file (`TOGETHER_CONFIG`, default
| `TOGETHER_WEB_DIR` | `web/.output/public` | built client |
| `TOGETHER_MAX_TURN_STEPS` | `48` | step cap per turn |
| `TOGETHER_ALLOW_REGISTRATION` | `false` | whether `/register` works |
| `TOGETHER_ALLOW_PRIVATE_TARGETS` | `false` | whether a sandbox target may use a loopback or private address |
| `TOGETHER_ALLOW_PRIVATE_TARGETS` | `false` | whether a direct sandbox target may use a loopback or private address |
| `TOGETHER_TUNNEL_AUTHORIZED_KEYS` | `data/tunnel/authorized_keys` | file the tunnel sshd reads; the app writes it |
| `TOGETHER_TUNNEL_SSH_HOST` | host from `TOGETHER_PUBLIC_URL` | host shown in the reverse ssh command |
| `TOGETHER_TUNNEL_SSH_PORT` | `2222` | tunnel sshd port |
| `TOGETHER_TUNNEL_USER` | `tunnel` | account the tunnel sshd accepts |
| `TOGETHER_TUNNEL_PORT_START` | `22000` | first loopback port assigned to a reverse target |
| `TOGETHER_TUNNEL_PORT_END` | `22999` | last loopback port assigned to a reverse target |
## Security model