Closed MrNova111 closed 1 year ago
Hi @MrNova111,
Thanks for your interest in ldapAuth
.
is there a straight forward way to have per container settings (for example, a different set of Allowed Groups) without duplicating common settings such as LDAP URL?
Unfortunately, there isn't. If you try to overwrite the middleware configs traefik
will return an error like this:
traefik | time="2022-10-25T13:17:18Z" level=error msg="Middleware defined multiple times with different configurations in [...]" providerName=docker middlewareName=ldap_auth
I believe I may have figured out a solution that uses go templating. In my configuration file I defined a template that contains all my common settings, and then created a middleware instance for each container router that references the common template:
{{define "ldapTemplate"}}Url: ldaps://example.org{{end}}
{{define "ldapConfig"}}http:
middlewares:
ui-ldapAuth:
plugin:
ldapAuth:
LogLevel: DEBUG
{{template "ldapTemplate"}}
AllowedGroups:
- groupA
web-ldapAuth:
plugin:
ldapAuth:
LogLevel: DEBUG
{{template "ldapTemplate"}}
AllowedGroups:
- groupB
{{end}}
{{template "ldapConfig"}}
Then I simply assign each container service its own middleware:
version: '3.5'
services:
traefik:
image: traefik:v2.9
volumes:
- ./traefik.yml:/etc/traefik/traefik.yml:ro
- ./ldapAuth-conf.yml:/dynamic-conf/ldapAuth-conf.yml:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
ui:
labels:
- traefik.enable=true
- traefik.http.routers.ui.rule=Host(`ui.localhost`)
- traefik.http.routers.ui.tls=true
- traefik.http.routers.ui.middlewares=ui-ldapAuth@file
web:
labels:
- traefik.enable=true
- traefik.http.routers.web.rule=Host(`web.localhost`)
- traefik.http.routers.web.tls=true
- traefik.http.routers.web.middlewares=web-ldapAuth@file
Apologies if I am missing something in documentation or examples, but is there a straight forward way to have per container settings (for example, a different set of Allowed Groups) without duplicating common settings such as LDAP URL?