Keycloak Integration for Traefik
- Create a new
openid-connect
client in Keycloak - Set
Access Type
toconfidential
- Create Redirect URIs for your services (
https://<DOMAIN>/_oauth
) - Copy secret from
Credentials
tab - Go to
Mappers
tab and add a builtinclient roles
mapper:- Set
Client ID
to the id of your client - Set
Token Claim Name
toroles
- Disable
Add to access token
- Enable
Add to userinfo
- Save
- Set
- Create roles for your services
- Replace
<DOMAIN>
and<REALM>
placeholders inAUTH_URL
,TOKEN_URL
andUSERINFO_URL
- Set
CLIENT_ID
to your client id andCLIENT_SECRET
to your client secret - (optional) Adjust
OK_TTL
andFORBIDDEN_TTL
- Add a new label to define the auth middleware and point it to your traefik-keycloak container:
The path of this address has to match the name of a role in Keycloak. Access is granted if and only if the user is a member of this role.
traefik.http.middlewares.service-auth.forwardauth.address: http://traefik-keycloak/service
- (optional) Add a
oauth_path
query parameter to change the callback path to which Keycloak will redirect (default is/_oauth
). If you do this, you also have to adjust your Redirect URI in Keycloak. - Add a label to use this middleware in your traefik router:
traefik.http.routers.service.middlewares: service-auth