Adding basic authentication doesn't work

Hello,

The basic auth works as expected but you have to remove auth header to avoid conflict with grafana auth.

https://docs.traefik.io/v2.1/middlewares/basicauth/#removeheader

version: "3.7"

services:
  traefik:
    image: traefik:v2.1.3
    command:
      - --log.level=INFO
      - --api.insecure=true
      - --providers.docker=true
      - --providers.docker.exposedbydefault=false
      - --entrypoints.web.address=:80
      - --entrypoints.websecure.address=:443
    ports:
      - 80:80
      - 443:443
      # The Web UI (enabled by --api.insecure=true)
      - 8080:8080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./letsencrypt:/letsencrypt

  grafana:
    image: grafana/grafana:6.6.0 
    labels:
      traefik.enable: true

      # HTTP (LAN) connection
      traefik.http.routers.grafana_lan.rule: Host(`lan.localhost`) && PathPrefix(`/grafana`)
      traefik.http.routers.grafana_lan.entrypoints: web
      traefik.http.routers.grafana_lan.middlewares: grafana_auth,strip_grafana_prefix
      
      # HTTPS (WAN) connection
      # traefik.http.routers.grafana_wan.rule: Host(`wan.localhost`) && PathPrefix(`/grafana`)
      # traefik.http.routers.grafana_wan.entrypoints: websecure
      # traefik.http.routers.grafana_wan.tls: true
      # traefik.http.routers.grafana_wan.middlewares: grafana_auth,strip_grafana_prefix
      
      # Tell Traefik to use the port grafana to connect to `my-container`
      traefik.http.services.grafana.loadbalancer.server.port: 3000
      
      # middlewares
      traefik.http.middlewares.grafana_auth.basicauth.users: user:$$apr1$$q8eZFHjF$$Fvmkk//V6Btlaf2i/ju5n/ # user/password
      traefik.http.middlewares.grafana_auth.basicauth.removeheader: true
      traefik.http.middlewares.strip_grafana_prefix.stripprefix.prefixes: /grafana

    environment:
    - GF_SERVER_ROOT_URL=http://lan.localhost/grafana
1 Like