API

Traefik exposes a number of information through an API handler, such as the configuration of all routers, services, middlewares, etc.

As with all features of Traefik, this handler can be enabled with the static configuration.

Security

Enabling the API in production is not recommended, because it will expose all configuration elements,including sensitive data.

In production, it should be at least secured by authentication and authorizations.

A good sane default (non exhaustive) set of recommendationswould be to apply the following protection mechanisms:

  • At the transport level:NOT publicly exposing the API's port,keeping it restricted to internal networks(as in the principle of least privilege, applied to networks).

Configuration

If you enable the API, a new special service named [email protected] is created and then can be reference in a router.

To enable the API handler:

  1. [api]
  1. api: {}
  1. --api=true

And then you will able to reference it like this.

  1. - "traefik.http.routers.api.rule=PathPrefix(`/api`) || PathPrefix(`/dashboard`)"
  2. - "[email protected]"
  3. - "traefik.http.routers.api.middlewares=auth"
  4. - "traefik.http.middlewares.auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
  1. "labels": {
  2. "traefik.http.routers.api.rule": "PathPrefix(`/api`) || PathPrefix(`/dashboard`)"
  3. "traefik.http.routers.api.service": "[email protected]"
  4. "traefik.http.routers.api.middlewares": "auth"
  5. "traefik.http.middlewares.auth.basicauth.users": "test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
  6. }
  1. # Declaring the user list
  2. labels:
  3. - "traefik.http.routers.api.rule=PathPrefix(`/api`) || PathPrefix(`/dashboard`)"
  4. - "[email protected]"
  5. - "traefik.http.routers.api.middlewares=auth"
  6. - "traefik.http.middlewares.auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
  1. [http.routers.my-api]
  2. rule="PathPrefix(`/api`) || PathPrefix(`/dashboard`)"
  3. service="[email protected]"
  4. middlewares=["auth"]
  5. [http.middlewares.auth.basicAuth]
  6. users = [
  7. "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/",
  8. "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
  9. ]
  1. http:
  2. routers:
  3. api:
  4. rule: PathPrefix(`/api`) || PathPrefix(`/dashboard`)
  5. service: [email protected]
  6. middlewares:
  7. - auth
  8. middlewares:
  9. auth:
  10. basicAuth:
  11. users:
  12. - "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"
  13. - "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"

insecure

Enable the API in insecure mode, which means that the API will be available directly on the entryPoint named traefik.

Note

If the entryPoint named traefik is not configured, it will be automatically created on port 8080.

  1. [api]
  2. insecure = true
  1. api:
  2. insecure: true
  1. --api.insecure=true

dashboard

Optional, Default=true

Enable the dashboard. More about the dashboard features here.

  1. [api]
  2. dashboard = true
  1. api:
  2. dashboard: true
  1. --api.dashboard=true

debug

Optional, Default=false

Enable additional endpoints for debugging and profiling, served under /debug/.

  1. [api]
  2. debug = true
  1. api:
  2. debug: true
  1. --api.debug=true

Endpoints

All the following endpoints must be accessed with a GET HTTP request.

PathDescription
/api/http/routersLists all the HTTP routers information.
/api/http/routers/{name}Returns the information of the HTTP router specified by name.
/api/http/servicesLists all the HTTP services information.
/api/http/services/{name}Returns the information of the HTTP service specified by name.
/api/http/middlewaresLists all the HTTP middlewares information.
/api/http/middlewares/{name}Returns the information of the HTTP middleware specified by name.
/api/tcp/routersLists all the TCP routers information.
/api/tcp/routers/{name}Returns the information of the TCP router specified by name.
/api/tcp/servicesLists all the TCP services information.
/api/tcp/services/{name}Returns the information of the TCP service specified by name.
/api/entrypointsLists all the entry points information.
/api/entrypoints/{name}Returns the information of the entry point specified by name.
/api/versionReturns information about Traefik version.
/debug/varsSee the expvar Go documentation.
/debug/pprof/See the pprof Index Go documentation.
/debug/pprof/cmdlineSee the pprof Cmdline Go documentation.
/debug/pprof/profileSee the pprof Profile Go documentation.
/debug/pprof/symbolSee the pprof Symbol Go documentation.
/debug/pprof/traceSee the pprof Trace Go documentation.