Traefik API config example usando Wildcard certificates y HTTP username/password (basic auth)

Based on nuestro previous post Simple Traefik docker-compose setup with Lets Encrypt Cloudflare DNS-01 y TLS-ALPN-01 y HTTP-01 challenges este es el TOML config que uso para allow access al Traefik dashboard usando HTTPS y my Let’s encrypt wildcard certificate. In este example, sera reachable under traefik.mydomain.com. Place el config en /opt/traefik/conf/api.toml asumiendo que has setup Traefik based on nuestro example.

traefik_api.toml
[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 un new password string usando htpasswd:

generate_htpasswd.sh
htpasswd -n admin

When prompted, enter el password y then copy el password tal como admin:$apr1$ocvmQb0w$Bwlbz3V2VVRZlcu46X0zK0 al [http.middlewares.auth.basicAuth] section:

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

Deberia se ver como nuestro full example above.


Echa un vistazo a artículos similares por categoría: Traefik