RousselTMLEARNING

Proxy & networking

The Traefik API: inspecting configuration and securing the dashboard

Use Traefik's REST API to inspect routers, services, middlewares and entrypoints, expose it securely with api@internal, and use it in verification scripts.

1. The API and the dashboard #

What Traefik exposes.

Endpoints #

EndpointContent
/api/overviewSummary: number of routers, services, middlewares, errors and warnings
/api/http/routers, /api/http/services, /api/http/middlewaresHTTP objects (also /api/tcp/… and /api/udp/…)
/api/entrypointsEntrypoints
/api/rawdataThe whole merged dynamic configuration
/api/versionTraefik version
/dashboard/Web interface, built on the API

2. Securing access #

Never left open.

Configuration #

Secured Traefik API
api.insecure mode publishes the API on port 8080 without protection: reserved for a development workstation.
# statique
api:
  dashboard: true            # et surtout pas insecure: true en production
# dynamique (fichier)
http:
  routers:
    tableau-de-bord:
      rule: Host(`traefik.exemple.fr`)
      entryPoints: [websecure]
      service: api@internal
      middlewares: [interne, sso]
      tls: { certResolver: le }
  middlewares:
    interne:
      ipAllowList: { sourceRange: ["10.0.0.0/8", "192.168.0.0/16"] }

3. Using the API in scripts #

Checking after each deployment.

Examples #

API=https://traefik.exemple.fr/api
curl -s $API/overview | jq '.http'                                   # totaux, avertissements, erreurs
curl -s $API/http/routers | jq -r '.[] | select(.status != "enabled") | "\(.name) \(.status) \(.error)"'
curl -s $API/http/services | jq -r '.[] | select(.serverStatus) | .name as $n | .serverStatus | to_entries[] | select(.value=="DOWN") | "\($n) \(.key) DOWN"'
curl -s $API/http/routers/app@docker | jq '{rule, service, middlewares, tls}'
Good practice: Add a check for routers in error to your deployment pipeline: a typo in a label is detected immediately.

Related articles

Traefik: securing and transforming requests with middlewares (BasicAuth, ForwardAuth…)

Traefik middlewares modify requests and responses between the router and the service: BasicAuth and ForwardAu…

Traefik: providers (Docker, Kubernetes, Nomad, Consul, files, key-value stores)

Providers feed Traefik's dynamic configuration: service discovery for Docker, Swarm, Kubernetes, Nomad and Co…

Traefik as an Ingress Controller for Kubernetes (Helm, IngressRoute, Gateway API)

Install Traefik in Kubernetes with Helm and publish applications with Ingress, the IngressRoute and Middlewar…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!