2019-02-26 13:50:07 +00:00
|
|
|
# BasicAuth
|
|
|
|
|
|
|
|
Adding Basic Authentication
|
|
|
|
{: .subtitle }
|
|
|
|
|
|
|
|
![BasicAuth](../assets/img/middleware/basicauth.png)
|
|
|
|
|
|
|
|
The BasicAuth middleware is a quick way to restrict access to your services to known users.
|
|
|
|
|
|
|
|
## Configuration Examples
|
|
|
|
|
2019-03-29 11:34:05 +00:00
|
|
|
```yaml tab="Docker"
|
|
|
|
# Declaring the user list
|
|
|
|
labels:
|
2019-04-03 12:32:04 +00:00
|
|
|
- "traefik.http.middlewares.test-auth.basicauth.users=test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"
|
|
|
|
```
|
|
|
|
|
|
|
|
```yaml tab="Kubernetes"
|
|
|
|
# Declaring the user list
|
|
|
|
apiVersion: traefik.containo.us/v1alpha1
|
|
|
|
kind: Middleware
|
|
|
|
metadata:
|
|
|
|
name: test-auth
|
|
|
|
spec:
|
|
|
|
basicAuth:
|
|
|
|
users:
|
|
|
|
- test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/
|
|
|
|
- test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0
|
2019-03-29 11:34:05 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
```toml tab="File"
|
|
|
|
# Declaring the user list
|
|
|
|
[http.middlewares]
|
|
|
|
[http.middlewares.test-auth.basicauth]
|
2019-04-03 12:32:04 +00:00
|
|
|
users = [
|
|
|
|
"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/",
|
|
|
|
"test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
|
|
|
|
]
|
2019-03-29 11:34:05 +00:00
|
|
|
```
|
2019-02-26 13:50:07 +00:00
|
|
|
|
|
|
|
## Configuration Options
|
|
|
|
|
|
|
|
### General
|
|
|
|
|
|
|
|
Passwords must be encoded using MD5, SHA1, or BCrypt.
|
|
|
|
|
|
|
|
!!! tip
|
|
|
|
|
|
|
|
Use `htpasswd` to generate the passwords.
|
|
|
|
|
2019-04-03 12:32:04 +00:00
|
|
|
### `users`
|
2019-02-26 13:50:07 +00:00
|
|
|
|
|
|
|
The `users` option is an array of authorized users. Each user will be declared using the `name:encoded-password` format.
|
|
|
|
|
|
|
|
!!! Note
|
|
|
|
|
|
|
|
If both `users` and `usersFile` are provided, the two are merged. The content of `usersFile` has precedence over `users`.
|
|
|
|
|
2019-04-03 12:32:04 +00:00
|
|
|
### `usersFile`
|
2019-02-26 13:50:07 +00:00
|
|
|
|
|
|
|
The `usersFile` option is the path to an external file that contains the authorized users for the middleware.
|
|
|
|
|
|
|
|
The file content is a list of `name:encoded-password`.
|
|
|
|
|
|
|
|
??? example "A file containing test/test and test2/test2"
|
|
|
|
|
|
|
|
```
|
|
|
|
test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/
|
|
|
|
test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0
|
|
|
|
```
|
|
|
|
|
|
|
|
!!! Note
|
|
|
|
|
|
|
|
If both `users` and `usersFile` are provided, the two are merged. The content of `usersFile` has precedence over `users`.
|
|
|
|
|
2019-04-03 12:32:04 +00:00
|
|
|
### `realm`
|
2019-02-26 13:50:07 +00:00
|
|
|
|
|
|
|
You can customize the realm for the authentication with the `realm` option. The default value is `traefik`.
|
|
|
|
|
2019-04-03 12:32:04 +00:00
|
|
|
### `headerField`
|
2019-02-26 13:50:07 +00:00
|
|
|
|
|
|
|
You can customize the header field for the authenticated user using the `headerField`option.
|
|
|
|
|
2019-04-03 12:32:04 +00:00
|
|
|
```yaml tab="Docker"
|
|
|
|
labels:
|
|
|
|
- "traefik.http.middlewares.my-auth.basicauth.headerField=X-WebAuth-User"
|
|
|
|
```
|
2019-02-26 13:50:07 +00:00
|
|
|
|
2019-04-03 12:32:04 +00:00
|
|
|
```yaml tab="Kubernetes"
|
|
|
|
apiVersion: traefik.containo.us/v1alpha1
|
|
|
|
kind: Middleware
|
|
|
|
metadata:
|
|
|
|
name: my-auth
|
|
|
|
spec:
|
|
|
|
basicAuth:
|
|
|
|
# ...
|
|
|
|
headerField: X-WebAuth-User
|
|
|
|
```
|
|
|
|
|
|
|
|
```toml tab="File"
|
|
|
|
[http.middlewares.my-auth.basicauth]
|
|
|
|
# ...
|
|
|
|
headerField = "X-WebAuth-User"
|
|
|
|
```
|
2019-02-26 13:50:07 +00:00
|
|
|
|
2019-04-03 12:32:04 +00:00
|
|
|
### `removeHeader`
|
2019-02-26 13:50:07 +00:00
|
|
|
|
|
|
|
Set the `removeHeader` option to `true` to remove the authorization header before forwarding the request to your service. (Default value is `false`.)
|