Secure all endpoints with basicauth

I'm trying to enable basicauth for all routes, so I added this line to my docker-compose commands. Roughly guessed from Configure a middleware for all IngressRoutes

      - "--entrypoints.websecure.http.middlewares.auth.basicauth.usersfile=/users"
      - "--entrypoints.websecure.http.middlewares=auth"

However, traefik can't even parse it:

command traefik error: failed to decode configuration from flags: field not found, node: basicauth

Hi @reactormonk , indeed there is a problem with your configuration. See entrypoints are part of the static configuration while the middleware declaration is considered dynamic, thus coming from your provider instead.

In Docker you have two good alternatives to declare middleware that can be reused between your services or added to the entrypoint:

  1. Add it as labels to your Traefik Proxy container, for example:
- "traefik.http.middlewares.strip.mystripprefix.prefixes=/foobar,/fiibar"

Then you keep the part that declares the middleware list on the entrypoint only in the command:

- "--entrypoints.websecure.http.middlewares=mystripprefix@docker"
  1. Load it from a File provider:
#Saved as traefik-dynamic.yaml
http:
  middlewares:
    mylist:
      ipWhiteList:
        sourceRange:
        - 127.0.0.1/8
        - 172.17.0.1/16

Then mount and load that file provider, via flag as well:

- "--entrypoints.websecure.http.middlewares=mylist@file"
- "--providers.file.filename=/configs/traefik-dynamic.yaml"

I hope one of this approaches is suitable for you!

1 Like