I've set up a minimal reproducible example for the issues I'm facing. I'm using the usersfile for basic auth middleware, but it doesn't seem to be working.
I've mounted the file with the hashed username and password correctly to the Traefik volume.
I generated the password using the following commands:
docker run --rm httpd:alpine htpasswd -nbm username 'password'
username:$apr1$zBGR6Unt$4VgFO4TLbSuX0GIyjNN.n0
docker run --rm httpd:alpine htpasswd -nbm username2 'password' | sed -e s/\\$/\\$\\$/g
username2:$$apr1$$gSLgJsXF$$HBny7qMhGk3r4ZmOIFjCC0
Here's the content of whoami.txt:
username:$apr1$zBGR6Unt$4VgFO4TLbSuX0GIyjNN.n0
username2:$$apr1$$gSLgJsXF$$HBny7qMhGk3r4ZmOIFjCC0
Here's the content of docker-compose.yml:
services:
traefik:
command:
- "--providers.docker"
- "--entrypoints.web.address=:80"
- "--log.level=DEBUG"
depends_on:
- whoami
image: traefik:v3.2.1
ports:
- mode: host
published: 80
target: 80
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./whoami-users.txt:/configuration/whoami-users.txt:ro
whoami:
image: traefik/whoami
labels:
- traefik.http.routers.whoami.rule=Host(`localhost`)
- traefik.http.routers.whoami.entrypoints=web
- traefik.http.routers.whoami.service=whoami
- traefik.http.services.whoami.loadbalancer.server.port=80
- traefik.http.middlewares.whoami-basicauth.basicauth.removeheader=true
- traefik.http.middlewares.whoami-basicauth.basicauth.usersfile=/configuration/whoami-users.txt
- traefik.http.routers.whoami.middlewares=whoami-basicauth
I've also tried to authenticate using curl
, but I keep getting a 401 Unauthorized
response:
curl -u username:password http://localhost:80
401 Unauthorized
curl -u username2:password http://localhost:80
401 Unauthorized