Skip to main content

BasicAuth

The BasicAuth middleware grants access to services to authorized users only.


Configuration Example

---
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: test-auth
namespace: traefik
spec:
basicAuth:
secret: authsecret

Configuration Options

FieldDescriptionDefaultRequired
usersArray of authorized users. Each user must be declared using the name:hashed-password format. (More information here)""No
usersFilePath to an external file that contains the authorized users for the middleware.
The file content is a list of name:hashed-password. (More information here)
""No
realmAllow customizing the realm for the authentication."traefik"No
headerFieldAllow defining a header field to store the authenticated user.""No
removeHeaderAllow removing the authorization header before forwarding the request to your service.falseNo

users

  • If both users and usersFile are provided, the two are merged. The contents of usersFile have precedence over the values in users.
  • For security reasons, the field users doesn't exist for Kubernetes IngressRoute, and one should use the secret field instead.

Kubernetes Secrets

The option users supports Kubernetes secrets.

Kubernetes kubernetes.io/basic-auth secret type

Kubernetes supports a special kubernetes.io/basic-auth secret type. This secret must contain two keys: username and password.

Please note that these keys are not hashed or encrypted in any way, and therefore is less secure than other methods. You can find more information on the Kubernetes Basic Authentication Secret Documentation

usersFile

  • If both users and usersFile are provided, the two are merged. The contents of usersFile have precedence over the values in users.
  • For security reasons, the field users doesn't exist for Kubernetes IngressRoute, and one should use the secret field instead.

Passwords format

Passwords must be hashed using MD5, SHA1, or BCrypt. Use htpasswd to generate the passwords.