I have a setup in which I have Traefik in Docker Compose, alongside with some services. I'm using label based configuration, with an extra traefik.yml config file (will show it below). I'm interested in protecting my services using IP WhiteListing.
The problem I'm facing is that, from time to time, what it seems to be randomly, I try to access my services and I get a "Forbidden" error message. Upon closer inspection of Traefik logs, it shows the ip address of my Docker network which is obviously not in the whitelist, and it gets rejected. I have to fix this by restarting the whole machine, even restarting the Traefik container doesn't fix it
This is an example with Syncthing. The proxy docker network has been created externally using docker commands:
Same problem here. I also have an external docker network, coincidentally named proxy as well, which has all the containers in it that traefik should be able to proxy. But what i can add to this, is that not even services outside of docker work as usual anymore. They were defined in the config file provider, with the services using loadBalancers.
Except that sometimes they work, but other times they don't. I don't even necessarily have to restart / recreate traefik or reboot the system, seems pretty arbitrary to me.
The weird thing is, sometimes / for some services it seems to recognize the client at first, but at the same time there seem to be requests from the docker network ip. I get the same "Forbidden" error, bc traefik probably sends out an 403 to the client on the whitelist. From the logs:
time="2024-03-30T16:45:57+01:00" level=debug msg="Rejecting IP <DOCKER_NETWORK_IP>: \"<DOCKER_NETWORK_IP>\" matched none of the trusted IPs" middlewareName=myWhitelist@file middlewareType=IPAllowLister
time="2024-03-30T16:45:57+01:00" level=debug msg="Accepting IP <ACTUAL_CLIENT_IP>" middlewareName=myWhitelist@file middlewareType=IPAllowLister
time="2024-03-30T16:45:57+01:00" level=debug msg="Accepting IP <ACTUAL_CLIENT_IP>" middlewareType=IPAllowLister middlewareName=myWhitelist@file
time="2024-03-30T16:45:57+01:00" level=debug msg="Accepting IP <ACTUAL_CLIENT_IP>" middlewareName=myWhitelist@file middlewareType=IPAllowLister
time="2024-03-30T16:45:57+01:00" level=debug msg="Accepting IP <ACTUAL_CLIENT_IP>" middlewareType=IPAllowLister middlewareName=myWhitelist@file
time="2024-03-30T16:45:58+01:00" level=debug msg="Rejecting IP <DOCKER_NETWORK_IP>: \"<DOCKER_NETWORK_IP>\" matched none of the trusted IPs" middlewareName=myWhitelist@file middlewareType=IPAllowLister
time="2024-03-30T16:45:58+01:00" level=debug msg="Rejecting IP <DOCKER_NETWORK_IP>: \"<DOCKER_NETWORK_IP>\" matched none of the trusted IPs" middlewareName=myWhitelist@file middlewareType=IPAllowLister
time="2024-03-30T16:45:58+01:00" level=debug msg="Rejecting IP <DOCKER_NETWORK_IP>: \"<DOCKER_NETWORK_IP>\" matched none of the trusted IPs" middlewareName=myWhitelist@file middlewareType=IPAllowLister
Other times, the client IP never even reaches traefik it seems:
time="2024-03-30T17:06:20+01:00" level=debug msg="Rejecting IP <DOCKER_NETWORK_IP>: \"<DOCKER_NETWORK_IP>\" matched none of the trusted IPs" middlewareName=myWhitelist@file middlewareType=IPAllowLister
time="2024-03-30T17:06:26+01:00" level=debug msg="Rejecting IP <DOCKER_NETWORK_IP>: \"<DOCKER_NETWORK_IP>\" matched none of the trusted IPs" middlewareName=myWhitelist@file middlewareType=IPAllowLister
time="2024-03-30T17:06:31+01:00" level=debug msg="Rejecting IP <DOCKER_NETWORK_IP>: \"<DOCKER_NETWORK_IP>\" matched none of the trusted IPs" middlewareName=myWhitelist@file middlewareType=IPAllowLister
time="2024-03-30T17:06:33+01:00" level=debug msg="Rejecting IP <DOCKER_NETWORK_IP>: \"<DOCKER_NETWORK_IP>\" matched none of the trusted IPs" middlewareName=myWhitelist@file middlewareType=IPAllowLister
At first i thought this was due to my attempt to introduce IPv6 addresses to the whitelist (which does not work atm), but when removing those and thereby restoring the old config, the issue persists. So from my perspective, this seems to affect setups regardless of their config (as from an upgrade of traefik or docker or anything).
Neither the deprecated IPWhitelist, nor the new IPAllowList work. The only thing working right now is to deactivate it.
Hello I completely forgot about this post I made. I didn't manage to solve this specific problem, however, after careful consideration and lots of trial and error I concluded a couple things:
It's not Traefik's fault but Tailscale VPN (I was using this to access my services), everytime a reconnection happened (either because connection was lost or because Tailscale refreshed the connection) made the ip solving fail.
IP Whitelisting is not suitable for what I was trying to achieve, that is, protecting my services based on the incoming IP address
IP address can be faked to gain access to restricted services
So, I removed the IP whitelist middleware and used Authelia instead to put a login page before the actual services proxied with Traefik.
This actually works nicely and my services are properly protected, I can even set 2FA.
The only minor inconvenience was automated bash scripts I had that made some random requests, now require extra login, but i implemented it and everything works well.
IP Whitelisting is not suitable for what I was trying to achieve
I'm not sure about that. I know that when using zerotier (don't know if this is the case for tailscale as well) you get IPs from a specified range, eg. CIDR, so you could add those to the whitelist and you should be good to go. It also bugs me that it seems that this used to work flawlessly in the past and then stopped working seemingly without a config change.
For now I'll check out Authelia as well, thanks for the hint.
Nonetheless, here are the config files. I omitted a lot of stuff, feel free to ask if you need something else. Maybe it has something to to with the securityHeaders middleware?
Which version worked, which version doesn’t work anymore?
Note that you don’t need tls: {} or tls=true on router when TLS is already enabled on entrypoint.
You should not use ports: on any service other than Traefik, as that can potentially be used to circumvent Traefik security middlewares. Within a Docker network it is not necessary to expose ports, all are reachable.
Which version worked, which version doesn’t work anymore?
Well, now that i tested it, it doesn't seem to be related to traefik at all. In small steps I went down to version 2.7 (which on dockerhub was pushed to 2 years ago) and sadly they all don't work. So it may be docker related, or due to the nature of my network at home spanning over several subnets.
For the ip whitelist, i can try and find other solutions, but the root of the problem that traefik only gets to see the docker network ip could be troublesome in other unrelated cases as well i believe.
Note that you don’t need tls: {} or tls=true on router when TLS is already enabled on entrypoint.
thank you, I wrote that config two years ago and always pushed things around from one end to the other (and still do lol), so I'm happy about anything that i can remove.
You should not use ports
For services (load balancers) in the file provider i guess i have to. And for Home Assistant: I need to expose the port bc some devices don't play nicely with traefik it seems, so they are connected to the dockerhost directly. I also get kicked out of the webui and the app from time to time and have to login again, which seems to be related to putting it behind a reverse proxy.
All the other services that are running inside docker and are accessed through traefik don't expose any ports.
I got it working again by removing IPv6 support on the dockerhost. Seems to be more to it than just slapping an IPv6 address onto it and calling it a day lol.
The log now also shows the client IP (IPv4) again.