Archive sessions, allow spaces in names, stop tripping the SSH rate limit

Connection refused: the dev box's UFW `limit` rule refuses the 6th new
SSH connection from one address within 30 s. Every page view made two
calls (list, repos) and every button one more, so stopping two sessions
and refreshing hit it (kernel log: "UFW LIMIT BLOCK" from prod's IP).
The web app now multiplexes all calls over one connection
(ControlMaster=auto, ControlPersist=120), with the socket in its private
temp dir. compose.yaml gets `init: true` so the backgrounded master is
reaped; the app warns if it runs as PID 1.

Spaces in names: `create` now takes a title (letters, digits, '-',
single spaces, <= 48 chars). The slug used for the directory, branch,
unit and tmux socket is derived from it; the title is shown on the page
and passed to claude as --name. A plain slug still maps to itself.

Archive: new remote verbs `archive` (stop + flag, keeps checkout and
conversation) and `unarchive` (back to the list, still stopped). An
archived session refuses `start`. The page lists archived sessions in a
collapsible section. `list` re-reads state under the lock before saving
a Remote Control URL so it can't undo a concurrent archive.

Also: name/branch validation used re.match with `$`, which accepts a
trailing newline; it now uses fullmatch.

Tested end to end with a throwaway 127.0.0.1 key and the real container:
24 remote calls went over 1 TCP connection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rog8S9b5qKaw6nUicxXLkM
This commit is contained in:
agent 2026-10-06 09:42:40 +00:00
parent 2569937fa7
commit 0738171f1e
7 changed files with 244 additions and 32 deletions

View file

@ -31,8 +31,8 @@ from="<IP of reudy.net>",restrict,command="…/sessions-ctl --remote" ssh-ed2551
- **`command=`**: whatever prod asks for, sshd runs `sessions-ctl --remote`. It
reads `$SSH_ORIGINAL_COMMAND`, splits it without a shell, and accepts only
`list repos status create start stop health`. Names and branches are
checked against strict patterns; repos are picked by key from an allowlist
`list repos status create start stop archive unarchive health`. Names,
titles and branches are checked against strict patterns; repos are picked by key from an allowlist
in the config, so no URL or path crosses the link.
- **`restrict`**: no PTY, no port/agent/X11 forwarding. (Tested: `-L` is refused.)
- **`from=`**: the key only works from the address `reudy.net` resolves to.
@ -83,7 +83,11 @@ Claude Code field. If a Claude Code update breaks it, the session shows
## How a session lives
- `create NAME REPO [BASE]`: clones the repo into `~/sessions/NAME`, creates
- `create TITLE REPO [BASE]`: the title is what you type, e.g. `Fix login bug`
(letters, digits, `-` and single spaces, up to 48 chars). The session's NAME
is derived from it (`fix-login-bug`) and used for the directory, branch, unit
and tmux socket. The title is shown on the page and is the session's name in
the Claude app. It clones the repo into `~/sessions/NAME`, creates
branch `session/NAME`, writes `~/.local/state/sessions/NAME.json` (with a
fixed conversation UUID) and runs `systemctl --user enable --now
claude-session@NAME`.
@ -97,6 +101,9 @@ Claude Code field. If a Claude Code update breaks it, the session shows
linger on.
- **Stop:** `disable --now`, so the session stays stopped across reboots until you
start it again.
- **Archive:** stops the session and moves it to the page's "Archived" section.
The checkout and the conversation are kept; **Unarchive** puts it back in the
list, stopped. An archived session can't be started until it's unarchived.
- **Limits:** `max_running` in the config (default 2). Each unit has
`MemoryHigh=1200M` and `MemoryMax=1600M`, which apply to claude and everything
it runs.
@ -151,7 +158,7 @@ file and run:
```sh
podman build -t localhost/sessions-web web/
podman run -d --name sessions-web --restart unless-stopped \
podman run -d --name sessions-web --restart unless-stopped --init \
--env-file ~/.config/sessions-web/env -p 127.0.0.1:8470:8470 \
--read-only --tmpfs /tmp --cap-drop ALL --security-opt no-new-privileges \
localhost/sessions-web
@ -176,6 +183,8 @@ sessions.reudy.net {
| "forbidden: this page must be served behind Authelia" | The route has no forward_auth, or the user isn't in `SESSIONS_ALLOWED_USERS` |
| Container exits with "configuration error" | One of the env values was pasted incompletely. Run `sessions-ctl keygen --rotate` again and paste all five lines |
| Page says "dev box unreachable: Permission denied" | Prod's outgoing IP isn't the one `reudy.net` resolves to, or the env holds an old key. On the dev box, `sudo journalctl -u ssh -n 20` shows the source IP. `sessions-ctl refresh-access` shows what `from=` holds |
| "dev box unreachable: … Connection refused" | The dev box's UFW `limit` rule refuses the 6th new SSH connection from one address within 30 s (`journalctl -k \| grep "UFW LIMIT BLOCK"`). The app reuses one connection (`ControlPersist`), so this needs an unusual burst or a container that can't keep its control socket in `/tmp` |
| Container log: "running as PID 1" | Start it with `--init` (compose: `init: true`), otherwise exited SSH master connections pile up as zombies |
| "Host key verification failed" | The dev box's host key changed. Check that the change is expected, then update `SESSIONS_DEV_HOST_KEY`. Never turn off checking |
| Session `failed` | `journalctl --user -u claude-session@NAME -n 50`. After 5 crashes in 10 min systemd gives up; fix the cause, then Start again |
| "stuck on the folder-trust prompt" | `tmux -L claude-NAME attach`, accept, detach. Then the trust field has moved in a Claude Code update, so fix `trust_workspace()` |