Basic Auth does not work

Hello there.
I'm trying to get basic auth working. I got it to prompt me for the auth, but its not accepting my password.
Heres my config

When trying to login, it just logs

time="2022-10-05T18:23:43Z" level=debug msg="Authentication failed" middlewareName=auth@docker middlewareType=BasicAuth

What's up?

We use different structure in our docker-compose.yml, note "-", "="

  - 'traefik.enable=true'
  - 'traefik.http.routers.certbot.entrypoints=web'

Make sure to have a hashed password and in docker-compose.yml every single $ is escaped to $$.

Do not put a space before username. Maybe username " shorty" works?

Hey thanks for the reply. Yeah, I use that syntax in my file. I just used docker compose convert becasue I'm loading from ENV varibles so you could see how it is. The actual compose file looks like this

version: '3'

    # The official v2 Traefik docker image
    image: traefik:v2.8
    # Enables the web UI and tells Traefik to listen to docker
    command: --providers.docker
    container_name: traefik
      - "80:80"
      - "444:443"
      # So that Traefik can listen to the Docker events
      # TODO: Don't bind the full docker sock
      - /var/run/docker.sock:/var/run/docker.sock
      - type: bind
        source: ./traefik.yml
        target: /etc/traefik/traefik.yml
    restart: always
      - "traefik.http.routers.dashboard.rule=Host(``)"
      - "traefik.http.routers.dashboard.service=api@internal"
      - "traefik.http.routers.dashboard.middlewares=auth"
      - "traefik.http.middlewares.auth.basicauth.users=${user}:${pass}"
      - "traefik.enable=true"
        name: traefik        

Note no space before the name. I've not escaped the $'s in my .env file, but docker compose seems to be doing it fine, and it seesm traefik got it fine, from the debug logs.


Thanks for your help

Ok i figured it out. Apparently .env files in docker will convert $'s if and only if they have capital letters after them. As such most of my dollar signs were working, except for one, and escaping would be needed on just one. I was able to avoid this by wrapping my thing in single quotes.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.