OpenID Connect Authentication
The OIDC Authentication middleware secures your applications by delegating the authentication to an external provider
Configuration Example
- Middleware OIDC
- Kubernetes Secret
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: test-oidc
namespace: whoami
spec:
plugin:
oidc:
issuer: "https://tenant.auth0.com/realms/myrealm"
redirectUrl: "/callback"
clientID: "urn:k8s:secret:my-secret:clientId"
clientSecret: "urn:k8s:secret:my-secret:clientSecret"
session:
name: customsessioncookiename
sliding: false
refresh: false
expiry: 10
sameSite: none
httpOnly: false
secure: true
stateCookie:
name: customstatecookiename
maxAge: 10
sameSite: none
httpOnly: true
secure: true
forwardHeaders:
Group: grp
Expires-At: exp
claims: Equals(`grp`, `admin`)
csrf: {}
apiVersion: v1
kind: Secret
metadata:
name: my-secret
stringData:
clientID: my-oidc-client-name
clientSecret: mysecret
Configuration Options
| Field | Description | Default | Required |
|---|---|---|---|
issuer | Defines the URL to the OpenID Connect provider (for example, https://accounts.google.com). It should point to the server which provides the OpenID Connect configuration. | "" | Yes |
redirectUrl | Defines the URL used by the OpenID Connect provider to redirect back to the middleware once the authorization is complete. (More information here) | "" | Yes |
clientID | Defines the unique client identifier for an account on the OpenID Connect provider, must be set when the clientSecret option is set. (More information here) | "" | Yes |
clientSecret | Defines the unique client secret for an account on the OpenID Connect provider, must be set when the clientID option is set. (More information here) | "" | Yes |
claims | Defines the claims to validate in order to authorize the request. The claims option can only be used with JWT-formatted token. (More information here) | "" | No |
usernameClaim | Defines the claim that will be evaluated to populate the clientusername in the access logs. The usernameClaim option can only be used with JWT-formatted token. | "" | No |
identity | Defines the claim whose value identifies the caller, used for cache partitioning by the semantic cache middleware. For example, grp uses the grp claim. If the claim is missing from the token, the middleware resolves no identity for that request. | sub | No |
forwardHeaders | Defines the HTTP headers to add to requests and populates them with values extracted from the access token claims returned by the authorization server. Claims to be forwarded that are not found in the JWT result in empty headers. The forwardHeaders option can only be used with JWT-formatted token. To see this option in action, check out the OIDC + RateLimit & DistributedRateLimit guide. | [] | No |
clientConfig.tls.ca | PEM-encoded certificate bundle or a URN referencing a secret containing the certificate bundle used to establish a TLS connection with the authorization server (More information here) | "" | No |
clientConfig.tls.cert | PEM-encoded certificate or a URN referencing a secret containing the certificate used to establish a TLS connection with the Vault server (More information here) | "" | No |
clientConfig.tls.key | PEM-encoded key or a URN referencing a secret containing the key used to establish a TLS connection with the Vault server. (More information here) | "" | No |
clientConfig.tls.insecureSkipVerify | Disables TLS certificate verification when communicating with the authorization server. Useful for testing purposes but strongly discouraged for production. (More information here) | false | No |
clientConfig.timeoutSeconds | Defines the time before giving up requests to the authorization server. | 5 | No |
clientConfig.maxRetries | Defines the number of retries for requests to authorization server that fail. | 3 | No |
pkce | Defines the Proof Key for Code Exchange as described in RFC 7636. | false | No |
discoveryParams | A map of arbitrary query parameters to be added to the openid-configuration well-known URI during the discovery mechanism. | "" | No |
trustedIssuer | Defines the issuer value to validate in JWT tokens when the issuer URL reported by the discovery endpoint differs from the issuer in the tokens. Allows discovery to work when there's a mismatch between the discovery URL and the token issuer, while still validating tokens against the expected issuer. More information here. | "" | No |
disableIssuerCheck | Disables issuer validation in JWT tokens. When set to true, the middleware does not validate that the issuer claim in JWT tokens matches the expected issuer. Useful for debugging purposes but strongly discouraged for production environments. More information here. | false | No |
scopes | The scopes to request. Must include openid. | openid | No |
authParams | A map of the arbitrary query parameters to be passed to the Authentication Provider. When a prompt key is set to an empty string in the AuthParams,the prompt parameter is not added to the OAuth2 authorization URL Which means the user won't be prompted for consent. | "" | No |
disableLogin | Disables redirections to the authentication provider This can be useful for protecting APIs where redirecting to a login page is undesirable. | false | No |
loginUrl | Defines the URL used to start authorization when needed. All other requests that are not already authorized will return a 401 Unauthorized. When left empty, all requests can start authorization. It can be a path ( /login for example), a host and a path (example.com/login) or a complete URL (https://example.com/login). Only http and https schemes are supported. | "" | No |
logoutUrl | Defines the URL on which the session should be deleted in order to log users out. It can be a path ( /logout for example), a host and a path (example.com/logout) or a complete URL (https://example.com/logout). Only http and https schemes are supported. | "" | No |
postLoginRedirectUrl | If set and used in conjunction with loginUrl, the middleware will redirect to this URL after successful login. It can be a path ( /after/login for example), a host and a path (example.com/after/login) or a complete URL (https://example.com/after/login). Only http and https schemes are supported. | "" | No |
postLogoutRedirectUrl | If set and used in conjunction with logoutUrl, the middleware will redirect to this URL after logout. It can be a path ( /after/logout for example), a host and a path (example.com/after/logout) or a complete URL (https://example.com/after/logout). Only http and https schemes are supported. | "" | No |
backchannelLogoutUrl | Defines the URL called by the OIDC provider when a user logs out (see https://openid.net/specs/openid-connect-rpinitiated-1_0.html#OpenID.BackChannel). It can be a path ( /backchannel-logout for example), a host and a path (example.com/backchannel-logout) or a complete URL (https://example.com/backchannel-logout). Only http and https schemes are supported. This feature is currently in an experimental state and has been tested exclusively with the Keycloak OIDC provider. | "" | No |
backchannelLogoutSessionsRequired | This specifies whether the OIDC provider includes the sid (session ID) Claim in the Logout Token to identify the user session (see https://openid.net/specs/openid-connect-backchannel-1_0.html#BCRegistration). If omitted, the default value is false. This feature is currently in an experimental state and has been tested exclusively with the Keycloak OIDC provider. | false | No |
stateCookie.name | Defines the name of the state cookie. | "MIDDLEWARE_NAME-state" | No |
stateCookie.path | Defines the URL path that must exist in the requested URL in order to send the Cookie header. The %x2F ('/') character is considered a directory separator, and subdirectories will match as well. For example, if stateCookie.path is set to /docs, these paths will match: /docs,/docs/web/,/docs/web/http. | "/" | No |
stateCookie.domain | Defines the hosts that are allowed to receive the cookie. If specified, then subdomains are always included. For example, if it is set to example.com, then cookies are included on subdomains like api.example.com. | "" | No |
stateCookie.maxAge | Defines the number of seconds after which the state cookie should expire. A zero or negative number will expire the cookie immediately. | 600 | No |
stateCookie.sameSite | Informsbrowsers how they should handle the state cookie on cross-site requests. Setting it to lax or strict can provide some protection against cross-site request forgery attacks (CSRF). More information here. | lax | No |
stateCookie.httpOnly | Forbids JavaScript from accessing the cookie. For example, through the Document.cookie property, the XMLHttpRequest API, or the Request API. This mitigates attacks against cross-site scripting (XSS). | true | No |
stateCookie.secure | Defines whether the state cookie is only sent to the server when a request is made with the https scheme. | false | No |
session.name | The name of the session cookie. | "MIDDLEWARE_NAME-session" | No |
session.path | Defines the URL path that must exist in the requested URL in order to send the Cookie header. The %x2F ('/'') character is considered a directory separator, and subdirectories will match as well. For example, if stateCookie.path is set to /docs, these paths will match: /docs,/docs/web/,/docs/web/http. | "/" | No |
session.domain | Specifies the hosts that are allowed to receive the cookie. If specified, then subdomains are always included. If specified, then subdomains are always included. For example, if it is set to example.com, then cookies are included on subdomains like api.example.com. | "" | No |
session.expiry | Number of seconds after which the session should expire. A zero or negative number is prohibited. | 86400 (24h) | No |
session.sliding | Forces the middleware to renew the session cookie each time an authenticated request is received. | true | No |
session.refresh | Enables the access token refresh when it expires. | true | No |
session.sameSite | Inform browsers how they should handle the session cookie on cross-site requests. Setting it to lax or strict can provide some protection against cross-site request forgery attacks (CSRF). More information here. | lax | No |
session.httpOnly | Forbids JavaScript from accessing the cookie. For example, through the Document.cookie property, the XMLHttpRequest API, or the Request API. This mitigates attacks against cross-site scripting (XSS). | true | No |
session.secure | Defines whether the session cookie is only sent to the server when a request is made with the https scheme. | false | No |
store.keyPrefix | Defines the prefix of the key for the entries that store the sessions. | "" | No |
session.store.redis.endpoints | Endpoints of the Redis instances to connect to (example: redis.traefik-hub.svc.cluster.local:6379) | "" | Yes |
session.store.redis.username | The username Traefik Hub will use to connect to Redis | "" | No |
session.store.redis.password | The password Traefik Hub will use to connect to Redis | "" | No |
session.store.redis.database | The database Traefik Hub will use to store information. | 0 | No |
session.store.redis.cluster | Enable Redis Cluster | "" | No |
session.store.redis.tls.caBundle | Custom CA bundle | "" | No |
session.store.redis.tls.cert | TLS certificate | "" | No |
session.store.redis.tls.key | TLS key | "" | No |
session.store.redis.tls.insecureSkipVerify | Allow skipping the TLS verification | false | No |
session.store.redis.sentinel.masterSet | Name of the set of main nodes to use for main selection. Required when using Sentinel. | "" | No |
session.store.redis.sentinel.username | Username to use for sentinel authentication (can be different from username) | "" | No |
session.store.redis.sentinel.password | Password to use for sentinel authentication (can be different from password) | "" | No |
csrf | When enabled, a CSRF cookie, named hub-csrf-token, is bound to the OIDC session to protect service from CSRF attacks. It is based on the Signed Double Submit Cookie implementation as defined by the OWASP Foundation. Moreinformation here. | "" | No |
csrf.secure | Defines whether the CSRF cookie is only sent to the server when a request is made with the https scheme. | false | No |
csrf.headerName | Defines the name of the header used to send the CSRF token value received previously in the CSRF cookie. | Hub-Csrf-Token | No |
redirectUrl
Add specific rule on the IngressRoute
The URL informs the OpenID Connect provider how to return to the middleware. If the router rule is accepting all paths on a domain, no extra work is needed. If the router rule is specific about the paths allowed, the path set in this option should be included.
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: whoami
spec:
entryPoints:
- web
- websecure
routes:
# Rules to match the loginUrl and redirectUrl can be added into
# your current router.
- match: Path(`/myapi`) || Path(`/login`) || Path(`/callback`)
kind: Rule
middlewares:
- name: test-oidc
This URL will not be passed to the upstream application, but rather handled by the middleware itself. The chosen URL should therefore not conflict with any URLs needed by the upstream application.
This URL sometimes needs to be set in the OpenID Connect Provider's configuration as well (like for Google Accounts for example).
It can be the absolute URL, relative to the protocol (inherits the request protocol), or relative to the domain (inherits the request domain and protocol). See the following examples.