Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Traefik Basic Auth

I have recently started using Traefik with Docker and I must say it is fantastic. The trouble I am having at the moment is when I apply basic auth middleware to my Traefik dashboard and then go to load the dashboard, it constantly prompts for my the username and password on an endless loop and I can never get to the dashboard. However, it works perfectly fine without the basic auth and I can load my dashboard just fine. Please can anyone help with this? It has been driving me crazy for the last few days. Please see my samples below. (Note for the password hash I have tried both with and without an extra dollar sign at the beginning and neither work). Thank you in advance.

My Docker Compose file:

version: '3'
services:
  traefik:
    image: "traefik:v2.2"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /home/user/traefik/traefik.yml:/etc/traefik/traefik.yaml:ro
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.api.rule=Host(`traefik.com`)"
      - "traefik.http.routers.api.entrypoints=insecure"
      - "traefik.http.routers.api.service=api@internal"
      - "traefik.http.routers.api.middlewares=api-auth"
      - "traefik.http.middlewares.api-auth.basicauth.users=admin:$$..."
networks:
  default:
    external:
      name: "web"

My Traefik.yml file

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    network: "web" # Custom docker network
    exposedByDefault: false 

entryPoints:
  insecure:
    address: ":80"
  secure:
    address: ":443"

api:
  dashboard: true
like image 998
user3915932 Avatar asked Jul 26 '26 20:07

user3915932


1 Answers

It seems related to the hash password. ALL $ signs must be escaped by another $, not the first one at the beginning. Moreover, not every crypt functions are handled. Try to generate a password with this: echo $(htpasswd -nb user password) | sed -e s/\\$/\\$\\$/g as indicated in https://docs.traefik.io/middlewares/basicauth/#users

like image 51
toussa Avatar answered Jul 28 '26 13:07

toussa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!