BasicAuth for 2.2.8 is doing nothing

No matter what I try, no basic auth pops up. When I was on 1.7 it worked fine, but I am trying to switch to 2.2.8. Below is my docker-compose of the relevant parts, traefik and the container I am trying to get auth for.

---
version: "2"
services:
    traefik:
        image: traefik:2.2.8
        container_name: traefik
        environment:
            - CF_API_EMAIL=xxxxxx
            - CF_API_KEY=xxxxxx
        volumes:
            - /home/alex/docker/traefik/static/new-traefik.toml/:/etc/traefik/traefik.toml
            - /var/run/docker.sock:/var/run/docker.sock
            - /home/alex/docker/traefik/acme-new.json:/acme.json
            - /home/alex/docker/traefik/passwd:/passwd
        ports:
            - 80:80
            - 443:443
            - 8083:8083
        labels:
            traefik.enable: "true"
            traefik.http.routers.traefik-http.entrypoints: "web"
            traefik.http.routers.traefik-http.rule: "Host(`traefik.domain.com`)"
            traefik.http.routers.traefik-https.entrypoints: "websecure"
            traefik.http.routers.traefik-https.rule: "Host(`traefik.domain.com`)"
            traefik.http.routers.traefik-https.tls: "true"
            traefik.http.routers.traefik-https.tls.certresolver: "default"
            traefik.http.routers.traefik-http.middlewares: "traefik-https@docker"
            traefik.http.middlewares.traefik-https.redirectscheme.scheme: "https"
            traefik.http.middlewares.traefik-https.redirectScheme.permanent: "true"
            traefik.http.routers.traefik-https.service: "traefik"
            traefik.http.services.traefik.loadbalancer.server.port: "8083"
            traefik.http.middlewares.auth.basicauth.users: "alex:$$apr1$$NfRVpGna$$bpNBcS5c5mhmJ783LVK.M0"
            traefik.http.middlewares.auth.basicauth.removeheader: "true"


    tdarr_aio:
        image: haveagitgat/tdarr_aio
        container_name: tdarr_aio
        ports:
            -  8265:8265
        environment:
            - TZ=America/New_York
            - PUID=999
            - PGID=1002
        volumes:
            - /home/alex/docker/tdarr/data:/home/Tdarr/Documents/Tdarr
            - /home/alex/docker/tdarr/db:/var/lib/mongodb
            - /rome/media:/home/Tdarr/media
            - /media/scratch/docker/tdarr/transcodecache:/home/Tdarr/cache
            - /etc/localtime:/etc/localtime:ro
        restart: unless-stopped
        labels:
            traefik.enable: "true"
            traefik.http.routers.tdarr-http.entrypoints: "web"
            traefik.http.routers.tdarr-http.rule: "Host(`tdarr.domain.com`)"
            traefik.http.routers.tdarr-https.entrypoints: "websecure"
            traefik.http.routers.tdarr-https.rule: "Host(`tdarr.domain.com`)"
            traefik.http.routers.tdarr-https.tls: "true"
            traefik.http.routers.tdarr-https.tls.certresolver: "default"
            traefik.http.routers.tdarr-http.middlewares: "tdarr-https@docker"
            traefik.http.middlewares.tdarr-https.redirectscheme.scheme: "https"
            traefik.http.middlewares.tdarr-https.redirectScheme.permanent: "true"
            traefik.http.routers.tdarr-https.middlewares: "auth"
        depends_on:
            - traefik
  • This is documentation on how to attach middlewares to you router.
  • For specifying via docker labels, see this handy reference.
  • This is a docker specific section on middlewares
  • Under Routers section you will see another example of attaching middlewares, if you click on it.

Unless you attach a middleware to a router, the middleware will do nothing, since there is nothing to call it.

As you can see, the middleware is attached to the router.

I created the middleware attached to traefik container, and then I called it with

traefik.http.routers.tdarr-https.middlewares: "auth"

in other container. If this is wrong, please tell me what to do. All of my docker-compose is there for you to read.

Hello,

I updated your configuration;

version: "3.7"

services:

    traefik:
        image: traefik:2.3.1
        container_name: traefik
        environment:
            - CF_API_EMAIL=xxxxxx
            - CF_API_KEY=xxxxxx
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock
            - /home/alex/docker/traefik/acme-new.json:/acme.json
            - /home/alex/docker/traefik/passwd:/passwd
        ports:
            - 80:80
            - 443:443
        command:
          - --log.level=INFO
          - --api

          - --providers.docker.exposedbydefault=false
          
          - --entrypoints.web.address=:80
          # global redirect to https
          - --entrypoints.web.http.redirections.entryPoint.to=websecure
          - --entrypoints.web.http.redirections.entrypoint.scheme=https

          - --entrypoints.websecure.address=:443
          - --entrypoints.websecure.http.tls=true
          - --entrypoints.websecure.http.tls.certresolver=leresolver

          - --certificatesresolvers.leresolver.acme.email=your@email.com
          - --certificatesresolvers.leresolver.acme.storage=/acme.json
          - --certificatesresolvers.leresolver.acme.dnschallenge.provider=cloudflare

        labels:
            traefik.enable: 'true'
            
            traefik.http.routers.traefik-https.rule: Host(`traefik.domain.com`)
            traefik.http.routers.traefik.service: api@internal
            
            traefik.http.middlewares.auth.basicauth.users: alex:$$apr1$$NfRVpGna$$bpNBcS5c5mhmJ783LVK.M0
            traefik.http.middlewares.auth.basicauth.removeheader: 'true'

    tdarr_aio:
        image: haveagitgat/tdarr_aio
        container_name: tdarr_aio
        environment:
            - TZ=America/New_York
            - PUID=999
            - PGID=1002
        volumes:
            - /home/alex/docker/tdarr/data:/home/Tdarr/Documents/Tdarr
            - /home/alex/docker/tdarr/db:/var/lib/mongodb
            - /rome/media:/home/Tdarr/media
            - /media/scratch/docker/tdarr/transcodecache:/home/Tdarr/cache
            - /etc/localtime:/etc/localtime:ro
        restart: unless-stopped
        labels:
            traefik.enable: 'true'

            traefik.http.routers.tdarr.rule: Host(`tdarr.domain.com`)
            traefik.http.routers.tdarr.middlewares: auth

            traefik.http.services.tdarr-srv.loadbalancer.server.port: 8265

I got it working. I think it was just a combination of upgrading to 2.3.1, and upgrading the docker-compose version as I didn't actually change anything else.