Problem with default configurations/middlewares while using with consul catalog

I tried to use default middleware functionality as mentioned in the blog post, using the consul catalog as a provider so that I don't have to manually add tags on each consul instance.

The middleware is being applied to the routers but the lookup is in the form of @ instead of using the defined middleware in the config file.

Below is the example config.toml

[api]
    insecure = true
    debug = true

[http.middlewares]
  [http.middlewares.usersData.forwardAuth]
    address = "https://example.com/auth"

[entryPoints.web.http]
    middlewares=["usersData"]

[providers.consulCatalog]
    refreshInterval = "2s"
    exposedByDefault = true    
    [providers.consulCatalog.endpoint]
        address = "XXXXXX"
        token = "XXXXXX"
        scheme = "https"

Traefik version

Version:      2.2.0
Codename:     chevrotin
Go version:   go1.14.1
Built:        2020-03-25T17:32:57Z
OS/Arch:      linux/amd64

Output

ERRO[2020-04-12T18:44:08+05:30] middleware "usersData@consulcatalog" does not exist  routerName=consul@consulcatalog entryPointName=web
ERRO[2020-04-12T18:44:08+05:30] middleware "usersData@consulcatalog" does not exist  entryPointName=web routerName=web@consulcatalog
ERRO[2020-04-12T18:44:10+05:30] middleware "usersData@consulcatalog" does not exist  entryPointName=web routerName=web@consulcatalog
ERRO[2020-04-12T18:44:10+05:30] middleware "usersData@consulcatalog" does not exist  entryPointName=web routerName=consul@consulcatalog
ERRO[2020-04-12T18:44:12+05:30] middleware "usersData@consulcatalog" does not exist  entryPointName=web routerName=consul@consulcatalog
ERRO[2020-04-12T18:44:12+05:30] middleware "usersData@consulcatalog" does not exist  entryPointName=web routerName=web@consulcatalog
ERRO[2020-04-12T18:44:14+05:30] middleware "usersData@consulcatalog" does not exist  entryPointName=web routerName=consul@consulcatalog

You must use an explicit middleware name (ie with the provider namespace) in the static configuration.

https://docs.traefik.io/v2.2/middlewares/overview/#provider-namespace

I can't define a middlware like this:

[http.middlewares]
  [http.middlewares.usersData@consulcatalog.forwardAuth]
    address = "https://example.com/auth"

Please read the documentation https://docs.traefik.io/v2.2/middlewares/overview/#provider-namespace

to be clear:

[entryPoints.web.http]
    middlewares=["usersData@file"]

I understood that! But I want to define middleware in the static configuration and apply it to all routers. By the way I tried replacing usersData to usersData@file but here is the output I received.

ERRO[2020-04-22T14:27:24+05:30] middleware "usersData@file" does not exist    entryPointName=web routerName=consul@consulcatalog
ERRO[2020-04-22T14:27:24+05:30] middleware "usersData@file" does not exist    entryPointName=web routerName=web@consulcatalog
ERRO[2020-04-22T14:27:26+05:30] middleware "usersData@file" does not exist    entryPointName=web routerName=consul@consulcatalog
ERRO[2020-04-22T14:27:26+05:30] middleware "usersData@file" does not exist    entryPointName=web routerName=web@consulcatalog
ERRO[2020-04-22T14:27:28+05:30] middleware "usersData@file" does not exist    entryPointName=web routerName=consul@consulcatalog
ERRO[2020-04-22T14:27:28+05:30] middleware "usersData@file" does not exist    entryPointName=web routerName=web@consulcatalog

and the config

[http.middlewares]
  [http.middlewares.usersData.forwardAuth]
    address = "https://example.com/auth"


[entryPoints.web.http]
    middlewares=["usersData@file"]

@ldez Is that configuration right?

the middleware cannot be define in the static configuration, they must be define in the dynamic configuration.

could you provide your full configuration.

[api]
    insecure = true
    debug = true

[http.middlewares]
  [http.middlewares.usersData.forwardAuth]
    address = "https://example.com/auth"

[entryPoints.web.http]
    middlewares=["usersData"]

[providers.consulCatalog]
    refreshInterval = "2s"
    exposedByDefault = true    
    [providers.consulCatalog.endpoint]
        address = "XXXXXX"
        token = "XXXXXX"
        scheme = "http"

The dynamic configuration and the static configuration must be defined in separated files:


traefik.toml
[api]
    insecure = true
    debug = true

[entryPoints.web.http]
    middlewares=["usersData@file"]

[providers.consulCatalog]
    refreshInterval = "2s"
    exposedByDefault = true    
    [providers.consulCatalog.endpoint]
        address = "XXXXXX"
        token = "XXXXXX"
        scheme = "http"

[providers.file]
    directory = "/dyn/"
    watch = true
/dyn/config.toml
[http.middlewares]
  [http.middlewares.usersData.forwardAuth]
    address = "https://example.com/auth"

Perfect! It worked. We need to mention middlewares as:

[entryPoints]
    [entryPoints.web]
        address = ":80"
    [entryPoints.web.http]
        middlewares=["usersData@file"]

Thanks!