Skip to content
FlyCockpit
WS Model Proxy/ Operations & Upgrading
WS Model Proxy logo

Operations, Hardening & Upgrading

WS Model ProxyRust + TypeScriptMIT
Repository

Complete environment variable reference, reverse proxy and PostgreSQL requirements, security hardening, backup and restore procedures, and the 0.4.x to 1.0 upgrade guide.

Platforms: Linux, macOS, Windows (node) · Docker (server)

This guide covers production deployment configuration, operational requirements, password peppering and secret rotation, backups and restores, and upgrading from 0.4.x to 1.0.0.

Environment Variable Reference

Required in Production

Variable Description
DATABASE_URL PostgreSQL 17 connection string (postgresql://user:pass@host:5432/dbname).
BETTER_AUTH_SECRET Random secret of at least 32 characters. Derives purpose-specific HMAC keys for API keys, agent tokens, node credentials, enrollment codes, share invites, signed media URLs, routing digests, password peppering, and JWT signing-key encryption.
BETTER_AUTH_URL Canonical public HTTPS origin with no path or trailing slash (e.g. https://models.example.com). Must be https:// when WMP_MCP_ENABLED=true (except loopback in dev).
NODE_ENV Set to production. Weak secrets become hard boot failures.
TRUST_PROXY_HOPS Exact number of reverse proxies appending to X-Forwarded-For (0 direct, 1 behind one proxy or cloudflared, 2 behind cloudflared + local proxy). Required in production.

Database, Migrations, and Server Runtime

Variable Default Description
DATABASE_POOL_MAX 10 Shared Prisma connection pool size (minimum 3; reserves room for password writes and nested revocation).
MIGRATE_ON_START true Apply pending Prisma migrations automatically at container start. Set false when running a separate one-shot migrate container before rollout (app then waits up to 300 s).
PORT / SERVER_PORT 3000 HTTP listening port inside the container (WEB_PORT maps the loopback host port in compose.yaml).
BUILD_VERSION git SHA Build commit baked into the bundle; a 40-hex value tells the Nodes page when a node’s wsmp is outdated.
WMP_RATE_LIMIT_SCALE 1 Multiplier (0.1–100) for built-in rate-limit budgets; windows stay fixed. Per-recipient email and failed-password caps are always enforced.
SSR_CACHE_TTL_SECONDS 60 Anonymous SSR HTML cache TTL for public locale pages (0 disables).
RELAY_REQUEST_RETENTION_DAYS 14 Days to retain raw per-request relay rows (minute rollups keep 30 days; hourly rollups keep 13 months).

Signup, Auth, and Optional SMTP

Variable Default Description
SIGNUP_ENABLED false Public self-signup toggle. Admins can still send invite links when disabled.
ADMIN_EMAIL unset Sole email address allowed to bootstrap the first admin on a fresh production database when SIGNUP_ENABLED=false.
BETTER_AUTH_SECRET_PREVIOUS unset Previous BETTER_AUTH_SECRET, set temporarily only during password-pepper rotation.
CORS_ORIGIN unset Set only on split-origin deployments where the web UI runs on a different origin than the API.
SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS, SMTP_FROM unset Optional SMTP transport (587 STARTTLS or 465 implicit TLS). Setting SMTP_HOST turns on required email verification, password reset emails, and email 2FA OTP.

Model API, Cloud Fallback, and Audio Spool

Variable Default Description
MODEL_API_KEEPALIVE_AFTER_MS 30000 Delay before committing HTTP 200 with x-wsmp-keepalive: 1 and 15 s keepalive pulses (0 disables).
WMP_PUBLIC_PROVIDER_EGRESS_ENABLED true Global kill switch for cloud provider HTTP egress and :external model IDs.
WMP_PROVIDER_CREDENTIAL_ENCRYPTION_KEYS unset AES-256-GCM keyring for stored cloud provider credentials: active-v:base64-32-byte-key,old-v:base64-32-byte-key. First key encrypts; trailing keys decrypt only.
WMP_PROVIDER_ALLOW_PRIVATE_NETWORKS false Allow private/loopback URLs for custom cloud providers (public HTTPS is enforced by default).
MODEL_API_TRANSCRIPTION_SPOOL_DIR OS temp Private directory for replayable multipart audio uploads.
MODEL_API_TRANSCRIPTION_MAX_UPLOAD_BYTES 94371840 Per-file audio ceiling (90 MiB; fits under Cloudflare’s 100 MB body cap).
MODEL_API_TRANSCRIPTION_MAX_MULTIPART_BYTES 95420416 Total multipart request ceiling (91 MiB; hard cap 1074790400).
MODEL_API_TRANSCRIPTION_MAX_SPOOL_BYTES 1073741824 Max total spool disk usage (1 GiB).
MODEL_API_TRANSCRIPTION_MAX_CONCURRENT_UPLOADS 4 Concurrent multipart transcription uploads allowed.
MODEL_API_TRANSCRIPTION_MIN_FREE_BYTES 268435456 Minimum free disk space required on the spool filesystem (256 MiB).
MODEL_API_TRANSCRIPTION_UPLOAD_TIMEOUT_MS 900000 Multipart upload timeout (15 minutes).

MCP, Agent Tokens, Terminals, Media, and CLI Distribution

Variable Default Description
WMP_MCP_ENABLED true Enables /mcp, OAuth 2.1, discovery endpoints, and MCP login/consent pages (false closes them with 404).
WMP_AGENT_TOKEN_MAX_LIFETIME_DAYS 90 Maximum expiry for new agent tokens (1–3650 days).
WMP_AGENT_TOKEN_ALLOW_NO_EXPIRY true Allow non-expiring agent tokens. Turning false also blocks existing no-expiry tokens until re-enabled.
WMP_TERMINAL_USER_LIMIT 8 Max simultaneous browser terminals per user across all nodes (1–64).
WMP_TERMINAL_CLI_LIMIT 4 Server backstop for browser terminals per node (1–64; lowest of server and node setting wins).
WMP_AGENT_UPDATE_WINDOWS false Enable dashboard-triggered updates on Windows nodes (off by default while Windows binaries are unsigned).
WMP_CLI_RELEASE_BASE_URL GitHub Release Optional HTTPS mirror URL for /install.sh and /install.ps1 release archives and sha256.sum.
WMP_CLI_SOURCE_REV unset Optional 40-char commit SHA forcing /install.sh to build wsmp from source via Cargo.
MEDIA_STORAGE, MEDIA_ROOT off Set MEDIA_STORAGE=local and a writable absolute MEDIA_ROOT volume to enable /v1/files uploads.
MEDIA_MAX_UPLOAD_BYTES 26214400 Max upload size per media file (25 MiB).
MEDIA_MAX_BYTES_PER_USER 536870912 Per-user media storage quota (512 MiB; 0 disables).
MEDIA_PUBLIC_BASE_URL BETTER_AUTH_URL Public origin for signed media URLs if different from the app origin.

Backups

Variable Default Description
BACKUP_ENABLED false Opt in to automatic pre-migration (and pre-drop) verified pg_dump backups. Requires a writable /backups mount and/or BACKUP_S3_BUCKET, or startup refuses to migrate.
BACKUP_S3_BUCKET, BACKUP_S3_ACCESS_KEY_ID, BACKUP_S3_SECRET_ACCESS_KEY unset Off-site S3-compatible upload destination (use a dedicated write-only/non-deleting key).
BACKUP_S3_REGION, BACKUP_S3_ENDPOINT, BACKUP_S3_FORCE_PATH_STYLE, BACKUP_S3_SSE, BACKUP_S3_PREFIX database prefix S3 endpoint configuration (BACKUP_S3_FORCE_PATH_STYLE=true for MinIO/R2 path-style; BACKUP_S3_SSE=AES256 on AWS).
BACKUP_SCHEDULE, BACKUP_HOUR_UTC, BACKUP_KEEP off / 3 / 14 Read only by the optional backup-schedule service (compose.backups.yaml). Set BACKUP_SCHEDULE=daily to enable.

Infrastructure Requirements

  • Stop grace period >= 52 s: On SIGTERM, WMP drains HTTP, closes /mcp admissions, shuts down relay sessions and background sweeps, and exits within 47 s. Docker’s default 10 s grace cuts this short with SIGKILL. Always configure stop_grace_period: 52s (Compose) or terminationGracePeriodSeconds: 52 (Kubernetes).
  • Preserve the docker-entrypoint.sh → tini chain: The image entrypoint runs startup checks and migrations, unsets all BACKUP_S3_* variables so the running web server and /proc/1/environ never hold S3 writer credentials, and then execs tini -- <CMD>.
  • Reverse proxy Host header & compression: Preserve the canonical public Host header so MCP OAuth and DPoP htu verification succeed behind TLS termination. Enable gzip/brotli compression at the proxy.
  • PostgreSQL 17 & session pooling only: Every Prisma connection forces TimeZone=UTC on connect. Never place a transaction-mode pooler (such as PgBouncer pool_mode=transaction) in front of Postgres; connect directly or use session pooling.
  • Health probes: Use GET /health for container liveness (process-only, independent of Postgres) and GET /ready for deployment readiness (checks SELECT 1 against Postgres within 3 s).

Production Hardening

Password Pepper and Secret Rotation

Password hashes use Better Auth’s scrypt wrapped in AES-256-GCM under an HKDF-SHA256 key derived from BETTER_AUTH_SECRET (pw1:<16-hex-fingerprint>:<ciphertext>). A database-only leak does not expose crackable password hashes without BETTER_AUTH_SECRET.

To rotate BETTER_AUTH_SECRET cleanly:

  1. Stop the server completely.
  2. Set BETTER_AUTH_SECRET_PREVIOUS=<old> and BETTER_AUTH_SECRET=<new> (both strong, >= 32 characters, distinct), then start the server. On startup, WMP re-wraps all password hashes under the new key inside a single locked transaction before listening.
  3. Verify the log says none remain under the previous key (or check with pnpm doctor:app), then remove BETTER_AUTH_SECRET_PREVIOUS and restart.

Warning: Rotating BETTER_AUTH_SECRET invalidates all browser sessions, TOTP enrollments, model API keys, agent tokens, node credentials, and enrollment codes—every node must re-enroll with a fresh Replace code. Always back up BETTER_AUTH_SECRET separately from database dumps. If a key is permanently lost, stop the server and run pnpm auth:pepper:reset-unusable --allow-non-local (dry run first, then --confirm <count>) to replace unreadable hashes so affected users can recover via Forgot password (requires SMTP).

Password Recovery Revocation Sweeps

When a user completes a mailed password reset (or an admin sets a password via the authorized recovery API), WMP runs two revocation sweeps under the user’s owner fence—before and after writing the new hash—revoking all sessions, pending 2FA challenges, model API keys, agent tokens, MCP/OAuth grants and tokens, node credentials, and unrevoked enrollment codes, and promptly closing active relay sockets. Node records and runtime definitions remain intact; reconnect existing nodes with fresh Replace enrollment codes.

A normal signed-in password change with “sign out other devices” revokes other browser sessions and API/MCP credentials while keeping node credentials intact.

Hardening Checklist

  • Keep PostgreSQL unpublished on host networks and bind app to 127.0.0.1 only.
  • Set TRUST_PROXY_HOPS accurately and verify with pnpm doctor:app.
  • Configure WMP_PROVIDER_CREDENTIAL_ENCRYPTION_KEYS before storing cloud provider keys.
  • Run a single web replica in v1 so in-memory rate limits and live revocation listeners cover every request.
  • Use a dedicated non-deleting S3 key for backups and enable bucket versioning + lifecycle rules.

Backup and Restore

Automatic backups default to off (BACKUP_ENABLED=false). To enable pre-migration backups and daily local/off-site dumps with Compose:

docker compose --env-file /etc/wsmp/private.env \
  -f compose.yaml -f compose.backups.yaml up -d --build
  • Local storage: Mount a writable volume at /backups. Pre-migration hooks keep the newest 5 pre-migrate-*.dump files; the daily scheduler keeps BACKUP_KEEP (default 14) daily-*.dump files.
  • S3 off-site copy: Uploads use conditional If-None-Match: * (never overwriting or deleting objects). Grant the backup IAM key only GetObject, GetObjectVersion, PutObject, and AbortMultipartUpload, and configure bucket versioning plus lifecycle expiration (including 7-day abort for incomplete multipart uploads).
  • Manual backup:
    docker run --rm --network <db-network> -v <backups-volume>:/backups \
      -e DATABASE_URL="$DATABASE_URL" ghcr.io/flycockpit/ws-model-proxy:v1.0.0 backup
  • Restore (preview first, then confirm):
    # 1. Stop the app container first
    # 2. Preview and verify archive integrity without changing data
    docker run --rm --network <db-network> -v <backups-volume>:/backups \
      -e DATABASE_URL="$DATABASE_URL" ghcr.io/flycockpit/ws-model-proxy:v1.0.0 \
      restore latest
    
    # 3. Apply in a single transaction (snapshots existing DB first when --replace is used)
    docker run --rm --network <db-network> -v <backups-volume>:/backups \
      -e DATABASE_URL="$DATABASE_URL" ghcr.io/flycockpit/ws-model-proxy:v1.0.0 \
      restore latest --replace --confirm RESTORE:ws-model-proxy
    For S3 restores (s3://<bucket>/<key>), --etag <etag> is required (and --version-id <id> is supported on versioned buckets). On Linux Compose deployments, /app/scripts/backup/host.sh (app-db.sh) automates stopping the app container, running guided restore, and restarting app safely.

Restore Exit Codes & Drills

Exit Code Meaning Target State
0 Restore committed cleanly. Restored
3 Refused, previewed, or cancelled before the transaction started. Unchanged
4 Restore failed and provably rolled back (ROLLED BACK). Unchanged
1 / 129 / 130 / 143 Outcome uncertain (interrupted after COMMIT sent) or post-commit error. Keep app stopped and inspect DB

Test backups periodically against an empty scratch database named restore_drill (never production):

docker run --rm --network <db-network> -v <backups-volume>:/backups \
  -e DATABASE_URL="postgresql://.../restore_drill" \
  ghcr.io/flycockpit/ws-model-proxy:v1.0.0 restore-drill latest

Note: The container image bundles PostgreSQL 17 pg_dump/pg_restore. Never run a PostgreSQL major version newer than the image’s client, or pg_dump will fail and block pre-migration backups.

Upgrading from 0.4.x to 1.0.0

Release 1.0 introduces relay protocol 4.0, committed Prisma Migrate history (replacing prisma db push), and fine-grained MCP scopes. Schedule a maintenance window and upgrade the server and all nodes together.

1. Pre-upgrade checklist

  • Be on 0.4.3: Automatic database adoption recognizes only the 0.4.3 schema. If you are on 0.4.2 or earlier, deploy 0.4.3 once with APPLY_SCHEMA=safe first.
  • Take a backup: Take a manual pg_dump -Fc or provider snapshot, or set BACKUP_ENABLED=true with /backups and/or BACKUP_S3_* configured before starting 1.0. (In 1.0, mounting /backups alone no longer enables pre-migration backups without BACKUP_ENABLED=true.)
  • Replace APPLY_SCHEMA with MIGRATE_ON_START: Remove APPLY_SCHEMA from your env file (safe maps to MIGRATE_ON_START=true, off maps to false, and dangerous is refused).
  • Audit no-expiry agent tokens: If you run with WMP_AGENT_TOKEN_ALLOW_NO_EXPIRY=false, existing no-expiry agent tokens will be blocked immediately on 1.0 until replaced with dated tokens or the flag is turned back on.
  • Audit mcp:write OAuth clients: Stored grants are converted automatically to mcp:read plus all six fine scopes, and already-issued JWTs carrying mcp:write return 401 invalid_token prompting a one-time refresh. Clients hard-coding mcp:write must switch to fine scopes.
  • Review unified memory overrides: On unified nodes (AMD APUs, Apple silicon, GB10), GPU-side memory is now capped by acceleratorMemoryGb, not memoryGb.

2. Upgrade the server

Stop the 0.4.3 container and start the 1.0.0 image. On first start, the migration runner compares your database against 0_init inside a rolled-back transaction:

  • If it matches, it logs adopted a v0.4.3 database, records 0_init, runs the pre-migration backup (if BACKUP_ENABLED=true), and applies 20261112000000_upgrade_to_1_0_0 (backfilling runGeneration, stripping retired completions capability keys, and pruning orphaned pool sidecars).
  • If it differs, startup halts with NOT ADOPTED and changes nothing.

To roll back to 0.4.3 after a failed upgrade, restore your pre-upgrade backup before starting the 0.4.3 image.

3. Upgrade every wsmp node

Because 1.0 refuses 0.4.x CLIs with HTTP 426 before the relay connects, the dashboard cannot push this one upgrade. Run on each node:

# Script-installed nodes (Linux / macOS) — downloads over plain HTTPS
wsmp update
# Or re-run the server's installer:
curl -fsSL https://models.example.com/install.sh | sh

# Homebrew installs
brew update && brew upgrade wsmp
# Windows nodes (then run `wsmp service install` to migrate the task to the SID-based name)
irm https://models.example.com/install.ps1 | iex
wsmp service install

On Linux nodes, run wsmp service install once after upgrading to enable systemd lingering and refresh the sanitized service PATH (and migrate any legacy root service to an ordinary account). Finally, verify every node reconnects on the Nodes page. Note that the repository’s default branch is now main.