Follow-up to the /terminal authorization fix: a full-codebase security review surfaced several more issues, fixed here. All changes are designed to roll out with no interruption to existing deployments — no forced migration, no manual re-key, no boot failure. Self-healing secret management (utils/secrets.ts): - JWT_SECRET / ENCRYPTION_KEY auto-generate to strong values on first boot and persist to the app_data volume (0600, outside the DB) when not set to a strong value in the environment. Replaces the prior behavior of running on the public repo defaults. - decrypt() tries the current key plus every legacy/default key, so existing device credentials keep decrypting after a key change; a startup sweep re-encrypts stale rows forward (db/reencryptCredentials.ts). - verifyToken() accepts the current signing secret plus prior *strong* secrets (never the public defaults), so rotation doesn't invalidate live sessions; sessions signed with a default secret require one re-login. - Dockerfile pre-creates /app/data as the app user so the non-root process can persist to a fresh named volume; app_data volume added to both compose files; compose secret defaults changed to empty (auto-gen). Authorization / input: - Default Socket.IO namespace now requires a valid JWT (was unauthenticated and broadcasting fleet-activity events); frontend sends the token and drops the shared socket on logout. - Webhook delivery blocks SSRF to loopback/private/link-local/CGNAT ranges and pins the request to the validated IP (WebhookService.ts). - Rate limit added to /auth/totp/verify; global mutation backstop on /api. - Password policy (>=10 chars, letter+digit) enforced on set/change/create. - system.ts used verifyToken as middleware (always 500); now requireAuth. Hardening: - CSP + HSTS/nosniff/frame-deny headers in nginx, scoped to allow the OpenStreetMap tile/geocoding hosts the maps use. Docs/tests: - README secret section rewritten for the self-healing model. - New unit tests for secret resolution, persistence, rotation, and legacy-key decryption (97 tests pass). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
125 lines
3.4 KiB
YAML
125 lines
3.4 KiB
YAML
version: '3.8'
|
|
|
|
# Pre-built image deployment — no source code or build toolchain required.
|
|
# For development/build-from-source, use docker-compose.yml instead.
|
|
|
|
services:
|
|
nginx:
|
|
image: ghcr.io/2gt-media-group-llc/mikrotik-manager-nginx:latest
|
|
ports:
|
|
- "${HTTP_PORT:-80}:80"
|
|
- "${HTTPS_PORT:-443}:443"
|
|
volumes:
|
|
- certs_data:/certs
|
|
depends_on:
|
|
backend:
|
|
condition: service_healthy
|
|
restart: unless-stopped
|
|
networks:
|
|
- app-network
|
|
|
|
backend:
|
|
image: ghcr.io/2gt-media-group-llc/mikrotik-manager-backend:latest
|
|
environment:
|
|
TZ: ${TZ:-UTC}
|
|
NODE_ENV: production
|
|
DATABASE_URL: postgresql://mikrotik:${DB_PASSWORD:-mikrotik_secure_pw}@postgres:5432/mikrotik_manager
|
|
REDIS_URL: redis://redis:6379
|
|
INFLUXDB_URL: http://influxdb:8086
|
|
INFLUXDB_TOKEN: ${INFLUXDB_TOKEN:-mytoken123456789}
|
|
INFLUXDB_ORG: ${INFLUXDB_ORG:-mikrotik-manager}
|
|
INFLUXDB_BUCKET: ${INFLUXDB_BUCKET:-metrics}
|
|
# Leave unset to auto-generate & persist strong secrets on first boot
|
|
# (stored in the app_data volume). Set them to pin your own values.
|
|
JWT_SECRET: ${JWT_SECRET:-}
|
|
ENCRYPTION_KEY: ${ENCRYPTION_KEY:-}
|
|
CORS_ORIGIN: ${CORS_ORIGIN:-https://localhost,http://localhost,https://127.0.0.1,http://127.0.0.1}
|
|
PORT: 3001
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
influxdb:
|
|
condition: service_healthy
|
|
volumes:
|
|
- backups_data:/app/backups
|
|
- certs_data:/certs
|
|
- app_data:/app/data
|
|
cap_add:
|
|
- NET_RAW
|
|
restart: unless-stopped
|
|
networks:
|
|
- app-network
|
|
healthcheck:
|
|
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:3001/api/health"]
|
|
interval: 15s
|
|
timeout: 10s
|
|
retries: 5
|
|
start_period: 30s
|
|
|
|
postgres:
|
|
image: postgres:15-alpine
|
|
environment:
|
|
POSTGRES_DB: mikrotik_manager
|
|
POSTGRES_USER: mikrotik
|
|
POSTGRES_PASSWORD: ${DB_PASSWORD:-mikrotik_secure_pw}
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
restart: unless-stopped
|
|
networks:
|
|
- app-network
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U mikrotik -d mikrotik_manager"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
start_period: 10s
|
|
|
|
redis:
|
|
image: redis:7-alpine
|
|
command: redis-server --appendonly yes
|
|
volumes:
|
|
- redis_data:/data
|
|
restart: unless-stopped
|
|
networks:
|
|
- app-network
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
|
|
influxdb:
|
|
image: influxdb:2.7
|
|
environment:
|
|
DOCKER_INFLUXDB_INIT_MODE: setup
|
|
DOCKER_INFLUXDB_INIT_USERNAME: admin
|
|
DOCKER_INFLUXDB_INIT_PASSWORD: ${INFLUXDB_ADMIN_PASSWORD:-admin_password_123}
|
|
DOCKER_INFLUXDB_INIT_ORG: ${INFLUXDB_ORG:-mikrotik-manager}
|
|
DOCKER_INFLUXDB_INIT_BUCKET: ${INFLUXDB_BUCKET:-metrics}
|
|
DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: ${INFLUXDB_TOKEN:-mytoken123456789}
|
|
volumes:
|
|
- influxdb_data:/var/lib/influxdb2
|
|
restart: unless-stopped
|
|
networks:
|
|
- app-network
|
|
healthcheck:
|
|
test: ["CMD", "influx", "ping"]
|
|
interval: 15s
|
|
timeout: 10s
|
|
retries: 10
|
|
start_period: 30s
|
|
|
|
volumes:
|
|
postgres_data:
|
|
redis_data:
|
|
influxdb_data:
|
|
backups_data:
|
|
certs_data:
|
|
app_data:
|
|
|
|
networks:
|
|
app-network:
|
|
driver: bridge
|