# Authentication failure with traefik:2.2.1

**URL:** <https://community.traefik.io/t/authentication-failure-with-traefik-2-2-1/5897>\
**Category:** Traefik v2\
**Tags:** cli, dashboard-api, docker\
**Created:** [May 5, 2020, 3:53pm UTC](https://community.traefik.io/t/authentication-failure-with-traefik-2-2-1/5897 "2020-05-05T15:53:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![atlasloewenherz](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/atlasloewenherz/32/1986_2.png) [@atlasloewenherz](https://community.traefik.io/u/atlasloewenherz)\
**Post date:** [May 5, 2020, 3:53pm UTC](https://community.traefik.io/t/authentication-failure-with-traefik-2-2-1/5897/1 "2020-05-05T15:53:43Z")

</div>

Hello Community!

these are the steps i follow to set up traefik using docker cli and labels, I have a problem setting up the authentication where I need you help!!

1. Network with the name 'dmz' is created

```auto
docker network create dmz

```

1. starting traefik with access to the docker network dmz and listening to 80, 443 and 8080 ports:

```auto
docker run --rm --name traefik \
  --network dmz -d \
  -p 80:80 -p 443:443 -p 8080:8080 traefik:v2.2.1 
  -v /var/run/docker.sock:/var/run/docker.sock:ro 
  -v /home/bob/acme.json:/acme.json

```

1. label used and their usage

| _Label name_ | _Label value_ | _Label type_ | Description |
| --- | --- | --- | --- |
| traefik.http.routers.http-catchall.rule | HostRegexp(`{host:.+}`) | Router(HostRegexExp Rule) creation | A router object with the name _http-catchall_ |
| traefik.http.routers.http-catchall.middlewares | redirect-to-https | middlewares assignment | A middelware object reference |
| traefik.http.routers.http-catchall.entrypoints | http | entryPoint assignment | An entrypoint reference |
| traefik.http.routers.api.rule | Host("[ci.domain.com](http://ci.domain.com)") | Router Host Rule creation | A router object that handles request to [ci.domain.com](http://ci.domain.com) |
| traefik.http.routers.api.entrypoints | http-alt | entryPoint assignment | Assign an entryPoint "http-alt" to the router object "api" |
| traefik.http.routers.api.service | api@internal | Service assignment | Assign a Service "api-interal" to the router object "api" |
| traefik.http.routers.api.middlewares | auth | middelware assignment | assignment a middelware "auth" for the router object "api" |
| traefik.http.middlewares.redirect-to-https.redirectscheme.scheme | https | middelware definition | Define a middelware [redirect-to-https](https://docs.traefik.io/middlewares/redirectscheme/) |
| traefik.http.middlewares.auth.basicauth.users | admin:admin | middelware definition | Define a [BasicAuth](http://hostOfDocum) middelware and name it as "auth" |

1. traefik docker image cli configuration:

```auto
  --global.checkNewVersion=true \
  --api=true \
  --api.debug=true \
  --api.dashboard=true \
  --log=true \
  --log.level=DEBUG \
  --accessLog=true \
  --providers.docker=true \
  --providers.docker.swarmMode=false \
  --entryPoints.http.address=:80 \
  --entryPoints.https.address=:443 \
  --entryPoints.http-alt.address=:8080 \
  --providers.docker.network=dmz \
  --certificatesResolvers.ci-domain.acme.email=info@domain.com \
  --certificatesResolvers.ci-domain.acme.storage=acme.json \
  --certificatesResolvers.ci-domain.acme.httpChallenge.entryPoint=http \
  --certificatesResolvers.ci-domain.acme.caServer=https://acme-staging-v02.api.letsencrypt.org/directory

```

1. create user password pair:

```auto
root@b663a6c4fb6b:/# #according to: https://docs.traefik.io/v2.0/middlewares/basicauth/
root@b663a6c4fb6b:/# #echo $(htpasswd -nb user password) | sed -e s/\\$/\\$\\$/g
root@b663a6c4fb6b:/# #echo $(htpasswd -nb admin admin) | sed -e s/\\$/\\$\\$/g
root@b663a6c4fb6b:/# echo $(htpasswd -nb admin admin) | sed -e s/\\$/\\$\\$/g
admin:$$apr1$$42hHNsKl$$.Y7GgFRJ4HEaii4GxOCMp0
root@b663a6c4fb6b:/#

```

1. final docker cli with encrypted user:passwords

```auto
docker run --rm --name traefik \
  --network dmz -d \
  -p 80:80 -p 443:443 -p 8080:8080 \
  --label="traefik.http.routers.http-catchall.rule=HostRegexp(\`{host:.+}\`)" \
  --label="traefik.http.routers.http-catchall.middlewares=redirect-to-https" \
  --label="traefik.http.routers.http-catchall.entrypoints=http" \
  --label="traefik.http.routers.api.rule=Host(\"ci.domain.com\")" \
  --label="traefik.http.routers.api.entrypoints=http-alt" \
  --label="traefik.http.routers.api.service=api@internal" \
  --label="traefik.http.routers.api.middlewares=auth"\
  --label="traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https" \
  --label="traefik.http.middlewares.auth.basicauth.users=admin:$$apr1$$42hHNsKl$$.Y7GgFRJ4HEaii4GxOCMp0" \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  -v /home/bob/acme.json:/acme.json \
  traefik:v2.2.1 \
  --global.checkNewVersion=true \
  --api=true \
  --api.debug=true \
  --api.dashboard=true \
  --log=true \
  --log.level=DEBUG \
  --accessLog=true \
  --providers.docker=true \
  --providers.docker.swarmMode=false \
  --entryPoints.http.address=:80 \
  --entryPoints.https.address=:443 \
  --entryPoints.http-alt.address=:8080 \
  --providers.docker.network=dmz \
  --certificatesResolvers.ci-domain.acme.email=info@domain.com \
  --certificatesResolvers.ci-domain.acme.storage=acme.json \
  --certificatesResolvers.ci-domain.acme.httpChallenge.entryPoint=http \
  --certificatesResolvers.ci-domain.acme.caServer=https://acme-staging-v02.api.letsencrypt.org/directory

```

1. the errors i do get when i try to login:

```auto
184.105.139.69 - - [05/May/2020:15:31:04 +0000] "GET / HTTP/1.1" 404 19 "-" "-" 83 "-" "-" 0ms
time="2020-05-05T15:46:19Z" level=debug msg="Authentication failed" middlewareName=auth@docker middlewareType=BasicAuth
5.146.198.125 - - [05/May/2020:15:46:19 +0000] "GET /dashboard/ HTTP/1.1" 401 17 "-" "-" 84 "api@docker" "-" 0ms
time="2020-05-05T15:46:21Z" level=debug msg="Authentication failed" middlewareName=auth@docker middlewareType=BasicAuth
5.146.198.125 - - [05/May/2020:15:46:21 +0000] "GET /dashboard/ HTTP/1.1" 401 17 "-" "-" 85 "api@docker" "-" 0ms
time="2020-05-05T15:46:22Z" level=debug msg="Authentication failed" middlewareName=auth@docker middlewareType=BasicAuth
5.146.198.125 - - [05/May/2020:15:46:22 +0000] "GET /dashboard/ HTTP/1.1" 401 17 "-" "-" 86 "api@docker" "-" 0ms

```

I would be more than glad for any hints that could help me figure out whats wrong with my configs!!

thanks & regards  
Yassine

---

<div class="post-metadata">

**Author:** ![bizmate](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/bizmate/32/3313_2.png) [@bizmate](https://community.traefik.io/u/bizmate)\
**Post date:** [February 2, 2021, 8:36am UTC](https://community.traefik.io/t/authentication-failure-with-traefik-2-2-1/5897/2 "2021-02-02T08:36:03Z")

</div>

This has not been answered since May 2020, have you managed to find a solution? If i can summarise the problem you are setting up basic auth on your ci domain so the api can be displayed but get authentication errors even with a simple password.

I have the same error with versions 2.3 or 2.4 . Not sure what the problem is but there must be some problems inside traefik that does not show up in logs. I hope someone could have provided a hint on what to look for

---

<div class="post-metadata">

**Author:** ![atlasloewenherz](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/atlasloewenherz/32/1986_2.png) [@atlasloewenherz](https://community.traefik.io/u/atlasloewenherz)\
**Post date:** [March 17, 2021, 10:37pm UTC](https://community.traefik.io/t/authentication-failure-with-traefik-2-2-1/5897/3 "2021-03-17T22:37:24Z")

</div>

hi @bizmate,

yes i manaed to solve the problem creating the traefik.yml and adding the following there:

```auto
api: {}

```

just an empty api and everything from above remains as it is

good luck!
