Traefik API config example using Wildcard certificates and HTTP username/password (basic auth)

Based on our previous post Simple Traefik docker-compose setup with Lets Encrypt Cloudflare DNS-01 & TLS-ALPN-01 & HTTP-01 challenges this is the TOML config I use to allow access to the Traefik dashboard using HTTPS and my Let’s encrypt wildcard certificate. In this example, it will be reachable under traefik.mydomain.com. Place the config in /opt/traefik/conf/api.toml assuming you have setup Traefik based on our example.

[http.routers.traefik-api]
rule = "Host(`traefik.mydomain.com`)"
service = "api@internal"
middlewares = ["auth"]
[http.routers.traefik-api.tls]
certresolver = "cloudflare"
[[http.routers.traefik-api.tls.domains]]
main = "mydomain.com"
sans = ["*.mydomain.com"]

[http.middlewares.auth.basicAuth]
users = [
  "admin:$apr1$ocvmQb0w$Bwlbz3V2VVRZlcu46X0zK0",
]

Create a new password string using htpasswd:

htpasswd -n admin

When prompted, enter the password and then copy the password such as admin:$apr1$ocvmQb0w$Bwlbz3V2VVRZlcu46X0zK0 to the [http.middlewares.auth.basicAuth] section:

[http.middlewares.auth.basicAuth]
users = [
  "COPY IT HERE"
]

It should look like our full example above.