Traefik Forward Auth
Wraps the mesosphere/traefik-forward-auth chart — an OIDC forward-auth service. Traefik forwards incoming requests to it via a middleware, it authenticates the user against an OIDC provider (Keycloak), and returns allow/deny (plus optional RBAC on top of the OIDC claims) before Traefik lets the request through.
Why it's in KubeAid
Puts OIDC login + RBAC in front of internal ingress-exposed apps (dashboards, admin UIs) that don't have
their own auth, without changing the app. It's deployed alongside the traefik chart, which is where the
traefik-traefik-forward-auth@kubernetescrd middleware and the traefikForwardAuth client config it depends
on live.
Key values
argocd-helm-charts/traefik-forward-auth/values.yaml:
traefikForwardAuth.enabled: true,clientId: traefik-forward-auth— the OIDC client used against Keycloak.traefikForwardAuth.enableRBAC: false— RBAC checks (see below) are off by default; flip totrueper the example values to enforce ClusterRole/ClusterRoleBinding-based authorization.middleware.enabled: true— installs the Traefik middleware resource that ingress objects reference.
RBAC Support
-
Setup the value file
-
Configure the traefik-forward-auth client on keycloak
-
Add required annotation to your ingress object
---annotations:cert-manager.io/cluster-issuer: letsencrypttraefik.ingress.kubernetes.io/router.middlewares: traefik-traefik-forward-auth@kubernetescrd -
Create a clusterrole and clusterrolebinding
---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata:name: foo-whoamirules:- nonResourceURLs:- /dashboard- /admin# Regex pattern will work when `ENABLE_V3_URL_PATTERN_MATCHING:` is enabled in values file- ~^https?://whoami-auth\.kubeaid\.io/- ~^https?://traefik\.kubeaid\.io/- ~^https?://queue\.job\.kubeaid\.io/verbs:- get---# GroupapiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata:name: sre-whoami-bindingsubjects:- kind: Groupname: oidc:sreapiGroup: rbac.authorization.k8s.ioroleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: foo-whoami---# UserapiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata:name: foo-whoami-bindingsubjects:- kind: Username: foo@kubeaid.ioapiGroup: rbac.authorization.k8s.ioroleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: foo-whoami -
Open the link on your browser (whatever domain you have given in your ingress object). It should first authenticated you and if the requested endpoint is allowed for that user or group it will give 200 otherwise 404 (Not Authorized)
Debug
- Look at the traefik-forward-auth pods logs to see why the user is getting 404