I opened a bug report on GitHub but it was flagged by a bot because it "might be a configuration problem or relates to something that doesn't look like a bug."
Here's my docker-compose.yml:
version: '3'
services:
reverse-proxy:
# The official v2.0 Traefik docker image
image: traefik:v2.0
# Enables the web UI and tells Traefik to listen to docker
command:
- "--api=true"
- "--api.debug=true"
# - "--api.insecure=true"
- "--providers.rest=true"
# - "--providers.rest.insecure=true"
- "--ping=true"
- "--providers.docker"
- "--entrypoints.web.address=:80"
- "--entrypoints.web-secure.address=:443"
- "--entryPoints.traefik.address=:8080"
- "--accesslog.filters.retryattempts=true"
- "--accesslog=true"
- "--log.level=DEBUG"
ports:
# The HTTP port
- "80:80"
# The Web UI (enabled by --api.insecure=true)
- "8080:8080"
volumes:
# So that Traefik can listen to the Docker events
- /var/run/docker.sock:/var/run/docker.sock
labels:
- "traefik.http.routers.api.rule=Host(`localhost`)"
- "traefik.http.routers.api.service=api@internal"
- "traefik.http.routers.api.middlewares=myAuth"
- "traefik.http.middlewares.myAuth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
(I left the insecure lines commented so it's easy to toggle)
I know I was able to PUT a file in Traefik 1.7 with user credentials, so either I'm missing something, configured incorrectly, or the provider has lost this functionality. As other posts have indicated, there's no documentation page for the Rest provider anymore which has made it difficult to understand what configuration is necessary and appropriate.
When I tried running that file I wasn't able to access anything.
These are the commands I was originally testing with and the responses using my file:
$ curl -X PUT -d @t.json -u test2:test2 "localhost:8080/api/providers/rest"
404 page not found
$ curl localhost:8080 -u test2:test2
<a href="/dashboard/">Found</a>.
When I was running your file:
$ curl localhost:8080 -u test2:test2
curl: (7) Failed to connect to localhost port 8080: Connection refused
$ curl -X PUT -d @t.json -u test2:test2 "localhost:8080/api/providers/rest"
curl: (7) Failed to connect to localhost port 8080: Connection refused
# Using your commands
$ curl api.localhost/api/providers/docker
curl: (6) Could not resolve host: api.localhost
$ curl -v -d "{}" -X PUT rest.localhost/api/providers/rest
* Could not resolve host: rest.localhost
* Closing connection 0
curl: (6) Could not resolve host: rest.localhost
Thanks @ldez! Yep I understand the middlewares fix and realized that after my last comment.
After diffing my original file to yours, the reason I wasn't able to get it working was because I didn't realize raefik.http.routers.rest or rest@internal existed as concepts. I knew about api's equivalents, though.