Hi everyone,
I'd like to configure Traefik in a manner that ensures my docker-compose
is secure-by-default and I'd like to strike a balance where it minimizes potential errors while being user-friendly (i.e. easy and safe copy-pasting compose configuration).
Network Configuration:
- Two networks are in play:
10.0.0.0/24
(MAIN
) and192.168.1.0/24
(GUEST
). - All services should be accessible from
MAIN
. However, only selected ones should be open toGUEST
.
Desired Label Configuration:
Here's a brief outline of my ideal scenario:
whoami:
image: containous/whoami
container_name: whoami
labels:
- "traefik.enable=true"
whoami-guest:
image: containous/whoami
container_name: whoami-guest
labels:
- "traefik.enable=true"
- "traefik.guest.enable=true"
In this setup:
whoami
should only be reachable fromMAIN
.whoami-guest
should be accessible from bothMAIN
andGUEST
.
Challenges:
Introducing an ipWhitelist
middleware requires this label:
- "traefik.http.routers.whoami.middlewares=main-ipwhitelist@file"
This isn't ideal because the router name needs to match the specific container name (no easy copy-pasting). While one could simplify with:
- "traefik.http.routers.{{ .Name }}.middlewares=main-ipwhitelist@file"
It's still not fully secure-by-default. Without any middleware, the container shouldn't be accessible. I tried using the docker provider's constraints
to not auto-create routers for middleware-free services. Yet, something like this doesn't work:
constraints: "Label(`traefik.http.routers.{{ .Name }}.middlewares`, `main-ipwhitelist`) || Label(`traefik.http.routers.{{ .Name }}.middlewares`, `guest-ipwhitelist`)"
Unfortunately, constraints
doesn't support templating.
Potential Solutions:
- Is there a method to activate middleware through a label that doesn't need including the service name within the label itself?
- Could we add a default blacklist middleware to all routers? This would restrict all traffic except from MAIN and GUEST. Then, on a per-service basis, we could introduce selective whitelisting for either MAIN or GUEST networks.
Does anyone have ideas for solutions that could meet my needs? Your input would be greatly appreciated!