Files
ShellBook/deploy
Florian Schmidt b7051d2479 Merge branch 't3/implement-auth-deploy'
Integrate auth, config, watcher and terminal wiring in buildApp: auth guards every API route by default, notebook watcher events feed the /api/events hub, the terminal runs in the configured workspace, and SHELLBOOK_DATA_DIR is the single data directory variable. The systemd unit uses KillMode=process so tmux sessions survive service restarts.
2026-11-16 00:11:06 +01:00
..

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. In the CT run the printed password command. It also accepts one password line on stdin; do not pass passwords as arguments. Source-checkout command: SHELLBOOK_DATA_DIR=/var/lib/shellbook pnpm --filter @shellbook/server set-password.
  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; password changes do not revoke existing cookies. For emergency revocation stop the service, delete session-secret from the data directory and start it again.

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 regression: bash deploy/test/template-picker.test.sh. The scripts require bash, use LF endings, and avoid early-consuming pipelines under pipefail. Proxmox, systemd, Tailscale and SSH require deployment validation.