Hardened Deployment
Guides, route-group overviews, and live schema entry points for the Plexichat backend.
Hardened deployment profile (FI-like)
This runbook describes a concrete, validated-as-possible hardened deployment profile for Plexichat in financial-institution-like (FI-like) environments. It builds on admin hardening and the measured figures in load testing and capacity.
Scope and honesty: this profile hardens configuration and deployment topology (TLS termination, strict origins/hosts/CORS, admin restrictions, ClamAV, least-privilege credentials, audit/retention, secrets handling). It is not, by itself, a compliance certification. Validate controls against your regulator/framework (e.g., SOC 2, PCI DSS, GLBA), your threat model, and your change-management process before production use.
Before you begin
- Deploy from the
plexichat/directory with the project venv and Docker Compose v2. - Use a non-production environment first. Capacity and scanning behavior are workload-sensitive (see load-testing.md).
- The Docker supply-chain policy in
docker-compose.ymlapplies: pin released tags, verify image digests/SHAs out of band, keep.envchmod 600(umask 077), and never commit secrets. NO_STRICT_CONFIGmust remainfalsein production. The server enforces security checks in production (src/server/security_checks.py); placeholder/default security keys/passwords abort production boot. Setapplication.environment: production(hardened config does this).
Profile artifacts (concrete)
All paths below are relative to plexichat/:
| Artifact | Purpose |
|---|---|
config/hardened.yaml |
Secure config overlay consistent with src/config_defaults.py / src/config_defaults_authentication.py. Sets production, strict admin, CORS/origin allowlist placeholders, proxy trust, TLS-at-edge posture, Postgres/Valkey, ClamAV required, encryption/rate limits/audit/docs auth. |
docs/deployment/hardened/docker-compose.hardened.yml |
Compose override: uses PLEXICHAT_CONFIG=/app/config/hardened.yaml, binds backend to loopback, requires ClamAV, removes public RustFS exposure, mounts hardened nginx template. |
docs/deployment/hardened/nginx.hardened.conf |
Edge TLS termination + reverse proxy reference (HSTS, security headers, proxy headers, /admin edge-allowlist hook, WebSocket/gateway timeouts). Mount real certificates. |
docs/deployment/hardened/.env.hardened.example |
Secret names/template only — no real secrets. Copy to .env. |
1. Reverse proxy + TLS
Requirement: terminate TLS at a trusted reverse proxy; do not expose the backend directly.
- Provision certificates from an approved CA (or an internal CA consistent with policy). Place
fullchain.pem/privkey.pemwhere the edge mounts/etc/nginx/certs(or use your managed ingress). Do not rely on self-signed certs in production. - Use
docs/deployment/hardened/nginx.hardened.confas the edge reference: HTTPS redirect, TLS 1.2/1.3, HSTS (max-age=31536000; includeSubDomains— enable preload only after validation), security headers, and proxying of/api/,/gateway,/docs,/openapi.json,/redoc,/admintobackend:8000. - Forward
Host,X-Real-IP,X-Forwarded-For, andX-Forwarded-Proto(the hardened nginx config does). Inconfig/hardened.yaml, setapi.trust_x_forwarded_for: trueandapi.trusted_proxiesto only your proxy IPs/CIDRs. Never trust arbitrary forwarded headers. - Keep
tls.enabled: falsein the backend when the proxy terminates TLS (the default hardened posture). If you terminate TLS at the backend instead, settls.enabled: truewith managedtls.cert_path/tls.key_pathand reviewstatic_client/proxy topology accordingly. - WebSocket gateway: clients connect to
wss://<host>/gateway(not/ws, not under/api/v1). Ensure the proxy passesUpgrade/Connectionand uses long timeouts (see nginx config). Readiness:GET /api/v1/ready; health:GET /api/v1/health.
2. Strict origins, hosts, and CORS
- CORS (API): set
api.cors_originsto your exact public origin(s) (e.g.,https://chat.example). Wildcards are rejected by the API when wildcard CORS is not explicitly allowed (src/api/config.py). Keepapi.cors_allow_credentialsonly if required; restrict methods/headers to what the client needs. - WebSocket origins: set
websocket.allowed_originsto the same exact origin(s). - Admin origins/hosts: keep
admin_ui.allowed_origins: []unless cross-origin admin access is explicitly required and reviewed. Keepadmin_ui.host_restriction.enabled: trueandallowed_hoststo loopback/explicit management sources. - Config-loader note (important):
ConfigLoader._deep_mergeconcatenates/deduplicates lists (defaults + overlay). Verify effective values after merge (command inconfig/hardened.yamlheader). The hardened profile also removes the non-loopback admin host fromsrc/config_defaults.pyso code defaults do not inject an environment-specific IP. Reviewapi.cors_origins/websocket.allowed_originseffective values for your release and run with explicit, minimal allowlists.
3. Admin restricted to loopback / allowlist
Builds on Admin hardening (src/api/routes/admin/utils.py, src/core/admin/__init__.py).
- Application layer:
admin_ui.host_restriction.enabled: true,allowed_hosts: [127.0.0.1, localhost, ::1]plus explicit management jump-host/proxy IPs only when required. Keepadmin_ui.blocked_ipscurrent. - Edge layer (defense in depth): enforce an allowlist for
/adminat nginx/ingress (seegeo $admin_allowedhook innginx.hardened.conf) or restrict via VPN/private network. Do not expose/adminpublicly. - AuthN/AuthZ: opaque admin sessions, explicit
require_admin_permissionscopes (no wildcards),require_otp: true,force_password_change_first_login: true, tight session limits/timeouts. - Destructive actions:
admin_ui.approval_workflows.enabled: true,single_admin_bypass: false, multi-admin approval forusers.force_purge,users.delete,servers.delete(tune to policy). - Admin TLS/rate limits: keep admin behind TLS; keep
admin_ui.rate_limitand globalrate_limiting.enabled: true.
4. ClamAV required and tuned
media.scanner_enabled: truein hardened config; server envSCANNER_ENABLED=truein the hardened compose override (src/config_defaults.py:media.scanner_enabled/scanner_host/scanner_port;src/core/media/_scanning.py;src/server/config_loader.pyappliesSCANNER_*env overrides).- Point
SCANNER_HOST/SCANNER_PORTat theclamavservice (compose network) or your approved scanner endpoint. Do not bypass scanning for user uploads in FI-like use. - Keep signature databases fresh (compose includes
clamav+clamav-unofficial-sigs). Monitor freshness and scan failures; treat scanner unavailability per your policy (fail closed for uploads where feasible). - Tune limits to your attachment policy and scanner capacity: compose sets
StreamMaxLength/MaxScanSize/MaxFileSize/MaxScanTime; align withmedia.size_limits/proxy limits andclient_max_body_sizeat the edge. Re-validate with realistic files and load-testing.md (ClamAV is a notable RAM/CPU baseline).
5. Least-privilege DB / Valkey / RustFS credentials
- PostgreSQL: dedicated application role (not superuser) with privileges only on the application database/schema;
POSTGRES_SSLMODE=requireminimum, preferverify-fullwith CA material when not on a fully trusted network. Rotate passwords; store in a secret manager/.env (chmod 600). Connection settings:config/hardened.yamldatabase.postgres.*(env-interpolated). - Valkey: require
VALKEY_PASSWORD(compose fails fast if unset); enable TLS (valkey.ssl/ deployment TLS) when traffic crosses untrusted networks; restrict network access to backend/authorized clients; use a dedicated ACL/user if your Valkey version/policy supports it. - RustFS/S3: create a bucket-scoped access key for the app (no console/admin reuse); keep
RUSTFS_CORS_ALLOWED_ORIGINSempty unless a separate signed-browser-upload flow is explicitly configured; do not expose RustFS publicly (hardened compose removes published ports).media.storage_backend: s3,encrypt_at_rest: true. - Network segmentation: only the edge publishes 80/443; backend bound to loopback in the hardened override; data services internal-only.
6. Audit logging and retention
admin_ui.audit.log_to_file: true,log_to_database: true,sensitive_actions_always_db: true,retention_days: 365(tune to legal/policy). Forward logs to your SIEM; review regularly (docs/admin-hardening.md).authentication.account_deletion.audit_logandauthentication.dsar.audit_logprovide hash-chained audit options with optional S3 backup — enable/point to approved storage per retention/legal-hold policy.- Protect log integrity (append-only storage/WORM where required), restrict access, and define deletion/hold procedures. Backups (restic) are encrypted by
RESTIC_PASSWORD; use an offsite secondary repo for resilience.
7. Secret management guidance
- Never commit secrets.
.envholds DB/Valkey/S3/restic and related secrets: create withumask 077, keepchmod 600(compose policy). - Generate with a CSPRNG: e.g.
openssl rand -base64 32or your platform secret manager. Replace everyCHANGE_ME_*in.env.hardened.example. - Key material:
PLEXICHAT_SYSTEM_KEY/PLEXICHAT_MESSAGE_KEYand keyrings under/home/plexichat/.plexichat(compose volume). Losing keys makes encrypted data unrecoverable — back up key material securely and separately per policy. Production boot aborts on placeholder/insecure security keys/passwords (src/server/security_checks.py). - Runtime config rewrite: the backend image may rewrite its mounted config (e.g., first-boot generated values); mount config writable as compose does, but treat secret-bearing values as env/secret-manager sourced, not hand-edited in git.
- Prefer a secret manager (Vault/KMS/SM/ESO) over flat files for production; inject env vars at runtime. Rotate credentials/keys on a schedule and after incidents.
8. Measured capacity (reference)
Size using measured, workload-specific numbers — not estimates alone. See Load testing and capacity for the scaffold (plexichat/loadtest/), scenarios (login/Argon2, idle WS, message send/fanout), how to read the capacity knee with docker stats, and reference-host component measurements/estimates. Key drivers: Argon2 logins, 1 backend asyncio process by default, per-member permission fanout, encryption + blind-index + write-time search indexing, Valkey/Postgres/RustFS/ClamAV baseline RAM. Run login_load.py, ws_idle.py, msg_send.py against your target and re-run bench_primitives.py on that host.
Step-by-step operator runbook
- Prepare host/network: isolate the deployment network; allow inbound 80/443 to the edge only; restrict
/adminto management networks; plan RTP/UDP30000-30100exposure only if WebRTC is required. - Pin and verify supply chain: set
BACKEND_VERSION/CLIENT_VERSIONto released tags; verify image digests/compose SHA perdocker-compose.ymlpolicy; do not track unverifieddevcompose. - Create secrets:
cp docs/deployment/hardened/.env.hardened.example .env && (umask 077; chmod 600 .env). Fill all required values (CSPRNG). Set realPLEXICHAT_PUBLIC_SERVER_URL, passkey RP/origin, scanner, and least-privilege DB/Valkey/S3/backup credentials. - Configure origins/hosts: edit
config/hardened.yaml— setapi.cors_originsandwebsocket.allowed_originsto your exacthttps://origin(s); setapi.trusted_proxiesto proxy IPs/CIDRs; confirm admin allowlists. Verify effective merged config (list-merge note above). - Provision TLS: install real
fullchain.pem/privkey.peminto the certs volume/mount; confirmnginx.hardened.confserver_name/OCSP/DNS settings for your CA/baseline. - Start services: from
plexichat/,docker compose -f docker-compose.yml -f docs/deployment/hardened/docker-compose.hardened.yml up -d. Confirmdb,valkey,clamav,backendhealthy; RustFS internal-only. - Migrations: auto-migrate is enabled by default; to apply/preview explicitly:
docker compose exec backend python main.py migrate-db [--dry-run](see deployment index). - Validate controls:
GET https://<host>/api/v1/readyand/api/v1/health; confirm HTTPS redirect/HSTS/headers; confirm CORS rejects unlisted origins; confirm/adminreachable only from allowlisted sources and requires OTP/permissions; confirm uploads are scanned (ClamAV healthy/fresh); confirm docs auth ifdocs.security.require_auth: true. - Logging/backup: verify admin/audit logs flowing to SIEM; verify restic schedule/retention and a restore test; protect key material backups.
- Capacity: run the load-test scaffold against this hardened, non-production-equivalent instance and record the capacity knee (load-testing.md).
NO_STRICT_CONFIG / production checks
- Keep
NO_STRICT_CONFIG=false(hardened compose sets it). Do not bypass strict/production safety checks. application.environment: productionenables production enforcement;src/server/security_checks.pyaborts production boot on default/placeholder security keys/passwords (e.g.,media.signing_key, weak DB/Valkey/turn secrets, message-key warnings) and on other insecure defaults. Resolve warnings by supplying real secrets/config — not by downgrading environment.- CLI validates config and exits on failure unless
NO_STRICT_CONFIG=true(development-only escape hatch; seesrc/cli/main.py/README). Do not use in hardened/FI deployments.
Validation performed for this profile
- Config keys in
config/hardened.yamlwere checked againstsrc/config_defaults.py,src/config_defaults_authentication.py, andsrc/config_defaults_artifacts.py(no unknown keys). - Overlay is valid YAML and contains no real secrets (env placeholders / example domains only).
- Effective-merge behavior and list-concatenation risk are documented;
src/config_defaults.pyhardened to remove a non-loopback adminallowed_hostsentry. - Runtime integration/load tests were not executed in this task; operators must validate in their environment (health checks, scanning, CORS/admin restrictions, backups, and load tests).