Skip to content

fix(docker): harden production docker-compose — remove direct backend port exposure and document TLS expectations #31

Open

Description

@SckyzO

fix(docker): harden production docker-compose — remove direct backend port exposure and document TLS expectations

Symptom

The production deployment manifest (docker-compose.prod.yml) has two issues that affect every operator who deploys Rackscope using the published GHCR images:

  1. The backend container is published on host port 8000, bypassing the frontend's reverse proxy. Any client that can reach the host network can call the API directly on port 8000, completely bypassing the security headers (HSTS, CSP, X-Frame-Options, etc.) set by the frontend's bundled nginx.

  2. The production stack serves HTTP on port 80 only, with no TLS termination. The operator is implicitly expected to put a reverse proxy (Traefik, Caddy, cloud LB) in front, but this expectation is not stated anywhere — neither in the compose file nor in the deployment documentation. A naive operator running docker compose -f docker-compose.prod.yml up -d exposes Rackscope to the network in clear HTTP.

Technical Analysis

Issue 1 — backend port exposure

# docker-compose.prod.yml:13-18
services:
  backend:
    image: ghcr.io/sckyzO/rackscope-backend:${RACKSCOPE_VERSION:-latest}
    restart: unless-stopped
    ports:
      - "8000:8000"   # ← exposes backend directly to the host
    volumes:
      - ./config:/app/config

The frontend image bundles its own nginx (frontend/nginx.prod.conf:17-24) which proxies /api/ to backend:8000 via the Docker internal network. The backend port mapping on the host is redundant and dangerous: it provides a second entry point that does not pass through nginx, hence does not benefit from:

  • X-Content-Type-Options: nosniff
  • X-Frame-Options: DENY
  • X-XSS-Protection: 1; mode=block
  • Referrer-Policy
  • Content-Security-Policy

It also makes a future auth_basic or rate-limiting layer at the nginx level impossible to rely on, because the bypass channel is always open.

The internal healthcheck (healthcheck.test: ["CMD", "curl", "-f", "http://localhost:8000/healthz"] at line 30) runs inside the backend container, hitting localhost:8000. It does not require the port to be published on the host.

Issue 2 — implicit TLS expectation

# docker-compose.prod.yml:36-43
  frontend:
    image: ghcr.io/sckyzO/rackscope-frontend:${RACKSCOPE_VERSION:-latest}
    restart: unless-stopped
    ports:
      - "80:80"   # ← HTTP only
    depends_on:
      backend:
        condition: service_healthy

The bundled nginx (frontend/nginx.prod.conf:2) listens on plain HTTP. The header Strict-Transport-Security is not set (the dev compose's nginx does set it, but the prod image's nginx does not). Some operators will deploy this directly on a public IP with no TLS proxy in front, and Rackscope will silently serve unencrypted traffic.

This is a documentation and discoverability problem, not a code defect — the design assumes upstream TLS termination, but does not communicate it.

Proposed Fix

Fix 1 — remove the direct backend port mapping

Edit docker-compose.prod.yml:

   backend:
     image: ghcr.io/sckyzO/rackscope-backend:${RACKSCOPE_VERSION:-latest}
     restart: unless-stopped
-    ports:
-      - "8000:8000"
     volumes:
       - ./config:/app/config

The backend remains reachable from the frontend container via the Docker network (http://backend:8000 from inside frontend's nginx). External clients reach the API exclusively via http://<host>/api/... through the frontend's nginx proxy.

If an operator needs local debug access to the backend (rare), they can bind the port to localhost only by overriding in a docker-compose.override.yml:

services:
  backend:
    ports:
      - "127.0.0.1:8000:8000"

Document this escape hatch in the admin guide.

Fix 2 — make the TLS expectation explicit

Two changes:

A. Add a prominent comment block at the top of docker-compose.prod.yml explaining the deployment model:

# Rackscope — Production stack
#
# This stack assumes an upstream TLS-terminating reverse proxy
# (Traefik, Caddy, cloud LB, Cloudflare, ...) in front of the frontend container.
# The frontend serves HTTP on port 80 internally; the upstream proxy
# is expected to handle TLS, HSTS, and any organisation-specific access controls.
#
# DO NOT expose this stack directly on a public network without an upstream
# TLS proxy. See:
#   - docs/admin-guide/deployment.md       — full deployment guide
#   - docs/admin-guide/reverse-proxy.md    — Traefik / Caddy / nginx samples
#
# Usage:
#   export RACKSCOPE_VERSION=1.0.0
#   docker compose -f docker-compose.prod.yml up -d

B. Add a new doc file rackscope_documentation/docs/admin-guide/reverse-proxy.md with three minimal-but-complete samples:

  1. Traefik v3 with Let's Encrypt — for self-hosted ops with a public IP
  2. Caddy 2 with automatic TLS — for the simplest setup
  3. nginx external — for organisations that already run nginx as their edge proxy

Each sample is a 20-line config that the operator can copy/paste and adapt.

C. Optional companion artifact (out of scope for this PR but recommended as a follow-up) — provide a docker-compose.prod-tls.yml bundled variant that includes Traefik with Let's Encrypt by default. Tracked separately if requested.

Test Checklist

Compose smoke tests (CI or local)

  • docker compose -f docker-compose.prod.yml config validates (no syntax error)
  • docker compose -f docker-compose.prod.yml up -d brings up backend and frontend
  • curl -fsS http://localhost/api/healthz returns 200 (via frontend nginx)
  • curl -fsS http://localhost:8000/healthz fails to connect (port no longer bound — confirms fix 1)
  • Inside the frontend container, curl http://backend:8000/healthz still returns 200 (internal network unaffected)

Documentation tests

  • docs/admin-guide/reverse-proxy.md renders cleanly (markdownlint)
  • The Traefik sample uses an explicit version pin
  • The Caddy sample produces a valid Caddyfile
  • The nginx sample includes Strict-Transport-Security and matches the security header set bundled in frontend/nginx.prod.conf (consistency between internal and external proxy chains)

Backwards-compat tests

  • Existing healthcheck on the backend container still passes (curl -f http://localhost:8000/healthz from inside the container)
  • No environment variable change required for existing deployments
  • Operators currently relying on the published port 8000 see a clear comment in the migration notes pointing them at the localhost override pattern

Impact and Severity

Breaking Changes

Behavioural change for operators currently relying on http://<host>:8000/api/...:

  • After this PR, the only way to reach the API is via http://<host>/api/... (through the frontend nginx).
  • This is a tightening, not a contract break — the API URL http://<host>/api/... was already documented and supported.
  • Operators who need port 8000 explicitly can opt back in via the documented override pattern.

Release notes must call out:

Production deployments: the backend container no longer publishes port 8000 on the host. The API remains available via the frontend reverse proxy (http://<host>/api/...). If you previously hit port 8000 directly, switch to the frontend endpoint or add a docker-compose.override.yml binding the port to 127.0.0.1 only.

Related

Out of Scope

  • Bundling a Traefik+Let's Encrypt variant (docker-compose.prod-tls.yml) — separate follow-up if requested
  • Adding TLS termination to the frontend image itself (would force every operator to manage certs in-container; the upstream-proxy model is intentionally simpler)
  • Changing the dev compose (docker-compose.dev.yml) — already has TLS via the nginx service, not affected

Activity

  1. added
    enhancement
    security
    on May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementsecurity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions