Skip to content

Securing the Traefik dashboard — basic-auth, IP allow-list, and forwardAuth

Put the Traefik v3 dashboard behind real authentication — basic-auth for quick wins, IP allow-list for office access, forwardAuth for SSO and audit logs.

The default api.insecure: true Traefik dashboard on port 8080 is fine for the first five minutes of an install and a liability from the sixth onward. It serves the full control plane unauthenticated — every router, service, backend URL, certificate, middleware, and the Traefik version, the last of which is enough to pick the right CVE to throw at it. This article covers the three secure patterns we deploy: basic-auth (good for break-glass), IP allow-list (good for office or VPN), and forwardAuth backed by an SSO proxy (good for everywhere else). All three start by turning the insecure mode off.

How to verify

# The dashboard MUST NOT answer on 0.0.0.0:8080
ss -lntp | grep :8080 && echo "FAIL — dashboard is publicly exposed"
# The protected dashboard MUST return 401 without credentials
curl -sI https://traefik.example.com/dashboard/ | head -1
# With credentials it should return 200
curl -sI -u admin:correct-password https://traefik.example.com/dashboard/ | head -1
# The api/rawdata endpoint should also be auth-gated
curl -sI https://traefik.example.com/api/rawdata | head -1

If :8080 answers, the legacy insecure path is still on. If /api/rawdata returns 200 without auth, the auth middleware was applied to the dashboard router but not to the api router; both need it.

What’s happening

The dashboard is just the Traefik API served as HTML. Three URL prefixes matter: /api/ (raw JSON, used by the dashboard JS to render), /dashboard/ (the HTML UI), and /ping (the healthcheck endpoint, deliberately unauthenticated). Securing the dashboard means covering both /api/ and /dashboard/ with the same middleware chain — api@internal is the service that serves both.

Traefik v3 keeps api.insecure: false by default, but the chart and some quickstarts still flip it on. When it is off, there is no built-in route at all — you must create an IngressRoute (K8s) or a router in a file provider (Docker, file) that points at api@internal. That router is where you attach auth.

The procedure

Pattern 1 — basic-auth in a file provider (Docker, file)

  1. Generate the hash on the box running Traefik:

    htpasswd -nbB ops 'rotate-quarterly'
    # ops:$2y$05$abcd1234...
  2. Write the dynamic config. Note $ is doubled because docker compose’s variable substitution eats single dollars.

    # /opt/traefik/dynamic/dashboard.yml
    http:
      middlewares:
        dashboard-auth:
          basicAuth:
            users:
              - "ops:$$2y$$05$$abcd1234..."
      routers:
        dashboard:
          rule: "Host(`traefik.example.com`) && (PathPrefix(`/dashboard`) || PathPrefix(`/api`))"
          entryPoints: [websecure]
          service: api@internal
          middlewares:
            - dashboard-auth
          tls:
            certResolver: letsencrypt
  3. Reload via docker compose up -d — file watcher picks up the change without restart, but compose ensures the bind mount is current.

Pattern 2 — IP allow-list

Useful when access is from a fixed office IP or a corporate VPN.

http:
  middlewares:
    office-only:
      ipAllowList:
        sourceRange:
          - "203.0.113.0/24"
          - "198.51.100.42/32"
    dashboard-auth:
      basicAuth:
        users:
          - "ops:$$2y$$05$$abcd1234..."
  routers:
    dashboard:
      rule: "Host(`traefik.example.com`) && (PathPrefix(`/dashboard`) || PathPrefix(`/api`))"
      entryPoints: [websecure]
      service: api@internal
      middlewares:
        - office-only
        - dashboard-auth
      tls:
        certResolver: letsencrypt

Order matters: the IP check runs first, so an off-network attacker gets dropped before basic-auth even sees the request.

Pattern 3 — forwardAuth with SSO

For dashboards that real engineers log into, basic-auth is friction. ForwardAuth delegates the decision to an external auth service (oauth2-proxy, authelia, an internal IdP), which can do SSO, MFA, and emit audit logs.

http:
  middlewares:
    sso-auth:
      forwardAuth:
        address: "http://oauth2-proxy.internal:4180/oauth2/auth"
        trustForwardHeader: true
        authResponseHeaders:
          - X-Forwarded-User
          - X-Forwarded-Email
  routers:
    dashboard:
      rule: "Host(`traefik.example.com`) && (PathPrefix(`/dashboard`) || PathPrefix(`/api`))"
      entryPoints: [websecure]
      service: api@internal
      middlewares:
        - sso-auth
      tls:
        certResolver: letsencrypt

See traefik-oauth2-proxy-integration for the full oauth2-proxy wiring.

Pattern 4 — Kubernetes IngressRoute

The same shape applies, just expressed as CRDs:

apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: dashboard-auth
  namespace: traefik
spec:
  basicAuth:
    secret: dashboard-auth-secret
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: dashboard
  namespace: traefik
spec:
  entryPoints: [websecure]
  routes:
    - match: Host(`traefik.example.com`) && (PathPrefix(`/dashboard`) || PathPrefix(`/api`))
      kind: Rule
      middlewares:
        - name: dashboard-auth
      services:
        - name: api@internal
          kind: TraefikService
  tls:
    secretName: dashboard-tls

Common pitfalls

  • Protecting /dashboard/ but leaving /api/ open — anyone can curl /api/http/routers and dump the entire config. The router rule must cover both prefixes.
  • Forgetting the trailing slash — /dashboard and /api need PathPrefix(...) not exact match; users hitting /dashboard/ without the slash should still resolve.
  • Using basic-auth without TLS — the password is sent base64-encoded on every request; never put the dashboard on the plain web entrypoint.
  • Hardcoding the basic-auth string in a docker-compose env var — the file is checked into Git unmasked. Use a .env file or a secret store, and keep the hash (never the plaintext) in config.
  • Mounting the Docker socket read-write — even with the dashboard secured, a writable socket inside the Traefik container is a container escape primitive. Mount as :ro.

A locked-down dashboard is the single highest-impact hardening step for a Traefik install. We treat dashboard access — basic-auth credential rotation, IP allow-list updates, SSO group membership — as a recurring operational item in our managed operations playbook. For the broader auth middleware surface see traefik-jwt-auth-middleware.