Files
ShellBook/deploy/README.md
T

73 lines
4.9 KiB
Markdown

# Deploy ShellBook (M5 / #6)
Access is root-equivalent across managed hosts. Restrict CT port 8080 to the
Traefik host with the Proxmox firewall; use HTTPS and limit the router to your
LAN/Tailscale addresses. No password is set initially: API access fails closed.
1. Copy `deploy/` to the Proxmox VE 9 host. As root run
`bash deploy/proxmox/create-ct.sh`. Defaults: unprivileged Debian 13 CT 501,
2 cores, 2 GiB RAM, 16 GiB disk, DHCP on vmbr0, onboot, nesting and TUN.
Overrides: `CTID`, `CT_STORAGE`, `TEMPLATE_STORAGE`, `CT_BRIDGE`, `CT_IP`
(Proxmox ip syntax), `CT_HOSTNAME`, `CT_CORES`, `CT_MEMORY`, `CT_DISK_GB`.
Existing CTs must be unprivileged Debian 13 of the host architecture; they
may reboot when TUN passthrough is added. No raw config appending is used.
2. Optionally supply `SHELLBOOK_REPO`, `SHELLBOOK_REF`, `SHELLBOOK_HOST`,
`SHELLBOOK_PORT`, `SHELLBOOK_TRUSTED_PROXIES` (comma-separated proxy IPs),
and `TS_AUTHKEY` in the host environment. Auth keys are transferred in a
mode-0600 temporary file and removed, never stored in the service env.
3. Open ShellBook in your browser. In the CT run `cat /var/lib/shellbook/setup-token`
and enter the token with a new password (at least 12 characters) in the setup screen.
This token is private, survives restart, and is deleted after setup. It is never logged.
Alternative password CLI: `SHELLBOOK_DATA_DIR=/var/lib/shellbook pnpm --filter @shellbook/server set-password`
from the checkout (hidden prompt or one password line on stdin; never arguments).
4. Run `claude` as shellbook and use `/login`. Authorize
`/home/shellbook/.ssh/id_ed25519.pub` on managed hosts. The service user has
no sudo access. Initialize notebooks manually if templates were absent.
5. Install the Traefik example in its file-provider directory and replace the
hostname, CT address, TLS resolver and allowed networks. Set the actual
Traefik peer IP in `/etc/shellbook/env` as `SHELLBOOK_TRUSTED_PROXIES`, then
`systemctl restart shellbook`. Only configured proxies can influence HTTPS
detection (and thus Secure cookies). TLS terminates at Traefik.
Standalone CT installation: run `bash deploy/install.sh` as root on Debian 13.
The installer can be rerun; it preserves env, password, workspace, SSH key and
session signing secret. It builds the checkout but does not pull on rerun.
Updates: `bash /opt/shellbook/deploy/update.sh` (root). Failure before restart
leaves the running service in place. Check `journalctl -u shellbook`.
Configuration is `/etc/shellbook/env`; data is `/var/lib/shellbook` (back it up
along with workspace and service-user home). `SHELLBOOK_SESSION_SECONDS` defaults
to 2592000 (30 days). Cookies survive restart. Logout clears the browser cookie;
Settings supports changing the password and signing out all sessions; both revoke
older cookies and close active WebSockets, while the current browser receives a fresh
cookie. CLI password changes invalidate cookies on their next request. For emergency
revocation stop the service, delete `session-secret`, and restart it.
Settings also shows paths, versions, and Claude CLI status, and opens the terminal
for `claude` then `/login` as the service user. A credentials file's existence is only
a hint, not proof that a login is valid.
Forward auth is off by default. To enable it set
`SHELLBOOK_FORWARD_AUTH_HEADER=Remote-User` and trusted proxy IPs. The header is
accepted only from an exact direct peer IP on that list (IPv4-mapped IPv6 is
normalized). Traefik must strip incoming identity headers and set its own after
authentication; block direct CT access. Built-in password login remains available.
WebSocket clients must send the same session cookie; cross-origin API requests
are rejected. Custom browser clients must use the public Host header.
Build choices: esbuild is a well-known TypeScript bundler; it bundles the source
`@shellbook/core` via an explicit alias, while npm dependencies (including native
node-pty) stay external. Production therefore retains installed node_modules.
`@fastify/static` supplies Fastify-compatible static serving and safe file paths;
the static directory is served only when index.html exists, with SPA fallback
outside `/api`. Node 22 comes from nodejs.org's latest-v22.x binary release,
verified with its SHA-256 manifest downloaded over HTTPS. This avoids third-party
apt signing-key compatibility issues on Debian 13. Rerun the installer to update
Node 22 security releases; unattended upgrades cover Debian packages only.
Build tools support node-pty compilation. Claude uses its native installer.
Local deployment regressions: `bash deploy/test/template-picker.test.sh` and
`bash deploy/test/ct-config.test.sh`, `bash deploy/test/install-script.test.sh`. Existing CTs with a manual TUN mount entry
(earlier Tailscale setups) keep it; no `dev0` is added on top.
The scripts require bash, use LF endings, and avoid early-consuming pipelines
under pipefail. Proxmox, systemd, Tailscale and SSH require deployment validation.