fix(discord-agent-workspace): confine the bot with bwrap in a user unit, not ProtectHome=

Where the user manager can't mount (Ubuntu's
kernel.apparmor_restrict_unprivileged_userns=1), ProtectHome= and
friends are dropped without an error and the service runs unconfined.
Ship a generic unit, as cloros1 runs: tmux for /login, bwrap for the
confinement.

Generated-by: Claude Opus 5.5
This commit is contained in:
dckc committed 2026-11-23 15:41:30 -06:00
1 parent cf83169064
commit e16e856eca
2 files changed
+48 -1

No files matched your search

+5 -1
View File
@@ -62,7 +62,11 @@ Whoever can message the bot can make it act with the session's powers: files, sh
## 4. Keeping it running
The session must stay open. Simplest: run it inside `tmux` (`tmux new -s bot`, start Claude, detach with Ctrl-b d; `tmux attach -t bot` to look in). On Linux, a systemd user unit can start it at boot and keep it out of secrets it doesn't need (`ProtectHome=read-only`, `ReadWritePaths=` the workspace and `~/.claude`, `InaccessiblePaths=` `~/.ssh` and other credential dirs).
The session must stay open. Simplest: run it inside `tmux` (`tmux new -s bot`, start Claude, detach with Ctrl-b d; `tmux attach -t bot` to look in). An expired login shows only in that terminal, never on Discord, so that's where `/login` happens.
On Linux, a systemd user unit can start it at boot and confine it: [claude-bot.service](claude-bot.service) runs Claude in tmux under `bwrap`, with everything read-only but the workspace, `~/.claude`, `~/.claude.json` and `~/.cache`, and credential dirs hidden. Hiding `$XDG_RUNTIME_DIR` also hides the systemd and D-Bus sockets, so `systemd-run` can't escape. Add `loginctl enable-linger` so it runs while they're logged out.
Use bwrap, not `ProtectHome=`, `ReadWritePaths=` and friends: where the user manager can't mount (Ubuntu's `kernel.apparmor_restrict_unprivileged_userns=1`), it silently runs the service unconfined. Check the live process: if `readlink /proc/<pid>/ns/mnt` matches the user's shell, it isn't confined.
## 5. First task