Skip to main content

Authentication Middleware

Restricting Access to Your Services Traefik provides three types of authentication middlewares to restrict access to your services:
  • BasicAuth - HTTP Basic Authentication
  • DigestAuth - HTTP Digest Authentication
  • ForwardAuth - Delegate authentication to an external service

BasicAuth

The BasicAuth middleware grants access to services to authorized users only using HTTP Basic Authentication.

Configuration Examples

Configuration Options

array
Array of authorized users in name:hashed-password format. Passwords must be hashed using MD5, SHA1, or BCrypt.
Use htpasswd to generate passwords.
string
Path to an external file containing authorized users (one per line in name:hashed-password format).
string
default:"traefik"
Realm for the authentication.
string
Header field to store the authenticated user.
boolean
default:"false"
Remove the authorization header before forwarding the request to your service.

DigestAuth

The DigestAuth middleware grants access to services using HTTP Digest Authentication.

Configuration Examples

Use htdigest to generate passwords.

Configuration Options

array
Array of authorized users in name:realm:encoded-password format.
string
Path to an external file containing authorized users.
string
default:"traefik"
Realm for the authentication.
string
Header field to store the authenticated user.
boolean
default:"false"
Remove the authorization header before forwarding the request.

ForwardAuth

The ForwardAuth middleware delegates authentication to an external service. If the service responds with a 2XX code, access is granted and the original request is performed. Otherwise, the response from the authentication server is returned.

Configuration Examples

Forward-Request Headers

The following request properties are provided to the forward-auth target endpoint:

Configuration Options

string
required
Authentication server address.
boolean
default:"false"
Trust all X-Forwarded-* headers.
array
List of headers to copy from the authentication server response and set on forwarded request.
string
Regex to match headers to copy from the authentication server response.

Chaining Authentication

You can combine authentication middleware with other middlewares: