HTTP Basic Auth for Docker routes

I want to enable HTTP Basic Auth on a number of Docker containers with Traefik labels. I'm doing it like so:

pgadmin:
    labels:
      - traefik.enable=true
        # make accessible via my.host.com/pgadmin/...
      - traefik.http.routers.pgadmin.rule=(Host(`my.host.com`) && PathPrefix(`/pgadmin`))
        # HTTPS only
      - traefik.http.routers.pgadmin.entrypoints=https
      - traefik.http.routers.pgadmin.tls.certresolver=le
        # compression middleware
      - traefik.http.middlewares.my-compress.compress=true
        # basic auth middleware
      - traefik.http.middlewares.admin-auth.basicauth.users=admin:$$apr1$$ur5Gr99C$$f354Cu/lqKJYOv5M/eNdW0
        # apply middlewares to route
      - traefik.http.routers.pgadmin.middlewares=my-compress@docker,admin-auth@docker

And the middleware(s) don't seem to work! I can still browse to my.host.com/pgadmin and see no authentication.

Have you tried without @docker? This works for me:

    labels:
      - traefik.enable=true
      - traefik.http.routers.mydashboard.rule=Host(`traefik.example.com`)
      - traefik.http.routers.mydashboard.service=api@internal
      - traefik.http.routers.mydashboard.middlewares=myauth
      - traefik.http.middlewares.myauth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/

From simple Traefik example.

Also, try to reverse your order of middlewares, first auth, then compress.

Enable and check Traefik debug log (doc).

Finally note that some browsers/clients will cache the entered user/pass for a site for some time, so you won’t be asked any time.

1 Like

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