Skip to Content
mlab docs

Reverse proxy and TLS

Serve ir.mlab.sh over HTTPS behind Caddy, nginx or Traefik: the upstream, the headers that matter, body size, and the settings that must match your hostname.

app speaks plain HTTP on port 8080 inside the container, published on the host as ${APP_PORT:-8080}. It does no TLS itself. Put a reverse proxy in front of it and send users to the proxy only.

What the app expects from the proxy

TopicRequirement
Upstreamhttp://127.0.0.1:8080 when the proxy runs on the host, http://app:8080 when it shares the compose network.
PathServe on its own hostname, at /. The app's routes are absolute (/api/v1, /assets, /uploads, /auth/login...), so a sub-path such as /ir/ is not supported.
HTTPSRequired in production. The session cookie mlab_session carries Secure unless COOKIE_SECURE=false, so browsers only return it over HTTPS.
Client IPThe app takes the client IP from Forwarded / X-Forwarded-For when present, otherwise the TCP peer. Make the proxy overwrite X-Forwarded-For with the real client address.
Body sizeAPI JSON bodies are capped at 2 MiB, evidence uploads at 50 MB, avatars at 5 MB. Allow at least 50 MB plus multipart overhead (60m in the examples).
WebSockets / SSENot used. No upgrade handling needed.
Security headersThe app already sends X-Content-Type-Options, X-Frame-Options: DENY, X-XSS-Protection, Referrer-Policy and Permissions-Policy. It does not send HSTS: add it at the proxy.
CompressionThe app compresses responses itself. Proxy compression is optional.

Why overwrite X-Forwarded-For. The client IP feeds the request log and the per-IP rate limits on second-factor codes and passkeys. If the proxy appends to a header the client sent (nginx $proxy_add_x_forwarded_for), a client can choose the IP the app sees.

Settings that must match the public hostname

Add these to .env once you know the URL users will type. env_file: .env passes them to app.

# Links back to alerts, cases and incidents in webhook messages.
PUBLIC_URL=https://ir.example.com

# Keep the session cookie HTTPS-only (default).
COOKIE_SECURE=true

# Passkeys are bound to this host. Set both, or neither (passkeys then hidden).
# Changing them later invalidates every registered passkey.
WEBAUTHN_RP_ID=ir.example.com
WEBAUTHN_ORIGIN=https://ir.example.com

Then docker compose up -d app to apply.

When the proxy runs on the same host, also stop publishing app on every interface. In docker-compose.yml:

services:
  app:
    ports:
      - "127.0.0.1:${APP_PORT:-8080}:8080"

Caddy

Example. Caddy obtains and renews the certificate itself, and by default replaces X-Forwarded-For with the connecting address unless you configure trusted_proxies. It does not touch a client-supplied Forwarded header, which the app reads first, so remove it.

Caddyfile
ir.example.com {
    request_body {
        max_size 60MB
    }
    header Strict-Transport-Security "max-age=31536000"
    reverse_proxy 127.0.0.1:8080 {
        header_up -Forwarded
    }
}

nginx

Example, with certificates from certbot.

/etc/nginx/sites-available/ir.example.com
server {
    listen 80;
    server_name ir.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name ir.example.com;

    ssl_certificate     /etc/letsencrypt/live/ir.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/ir.example.com/privkey.pem;

    client_max_body_size 60m;
    add_header Strict-Transport-Security "max-age=31536000" always;

    location / {
        proxy_pass         http://127.0.0.1:8080;
        proxy_set_header   Host              $host;
        proxy_set_header   X-Forwarded-For   $remote_addr;   # overwrite, don't append
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_set_header   Forwarded         "";             # drop any client-supplied value
    }
}

Optional additions are covered in Hardening: a rate limit on /api/v1/auth/login and refusing Authorization: Internal from outside.

Traefik

Example with the Docker provider, Traefik joined to the compose network and an ACME resolver named le defined in its static configuration. Traefik strips X-Forwarded-* headers coming from untrusted clients by default; don't enable forwardedHeaders.insecure on the entrypoint. The Forwarded header, which the app reads first, is removed with a headers middleware.

docker-compose.override.yml
services:
  app:
    ports: !reset []          # stop publishing 8080 on the host (Compose 2.24+)
    labels:
      - traefik.enable=true
      - traefik.http.routers.ir.rule=Host(`ir.example.com`)
      - traefik.http.routers.ir.entrypoints=websecure
      - traefik.http.routers.ir.tls.certresolver=le
      - traefik.http.routers.ir.middlewares=ir-headers
      - traefik.http.middlewares.ir-headers.headers.stsSeconds=31536000
      - traefik.http.middlewares.ir-headers.headers.customrequestheaders.Forwarded=
      - traefik.http.services.ir.loadbalancer.server.port=8080

Traefik buffers no request bodies by default, so the 50 MB evidence limit needs no extra middleware.

Plain HTTP (lab only)

If you must serve the console over plain HTTP on anything other than localhost, set COOKIE_SECURE=false. Otherwise sign-in appears to succeed and the next page sends you back to the login form, because the browser never returns the Secure cookie. The app logs a warning at every boot while this is set.

Check it

# Through the proxy: expect HTTP 200 and a small JSON greeting.
curl -si https://ir.example.com/api/v1/ | head -n 1

Then sign in from a browser and check in the developer tools that the mlab_session cookie is marked Secure and HttpOnly.

On this page