docs/content/integration/proxies/traefik.md
Traefik is a reverse proxy supported by Authelia.
Important: When using these guides, it's important to recognize that we cannot provide a guide for every possible method of deploying a proxy. These guides show a suggested setup only, and you need to understand the proxy configuration and customize it to your needs. To-that-end, we include links to the official proxy documentation throughout this documentation and in the See Also section.
Authelia by default only generally provides support for versions of products that are also supported by their respective developer. As such we only support the versions Traefik officially provides support for. The versions and lifetime of support for Traefik can be read about in the official Traefik Deprecation Notices documentation.
It should be noted that while these are the listed versions that are supported you may have luck with older versions.
We can officially guarantee the following versions of Traefik as these are the versions we perform integration testing with at the current time:
{{% supported-product product="traefik" format="* Traefik $version" %}}
It's strongly recommended that users setting up Authelia for the first time take a look at our Get started guide. This takes you through various steps which are essential to bootstrapping Authelia.
{{< callout context="danger" title="Security Note" icon="outline/alert-octagon" >}} In addition to this section which is important to read, you should read the Validating Forwarded Authentication reference guide and perform the validation steps as part of your regular security validation routine when using this integration. {{< /callout >}}
Important: You should read the Forwarded Headers section and this section as part of any proxy configuration. Especially if you have never read it before.
Important: The included example is NOT meant for production use. It's used expressly as an example to showcase how you can configure multiple IP ranges. You should customize this example to fit your specific architecture and needs. You should only include the specific IP address ranges of the trusted proxies within your architecture and should not trust entire subnets unless that subnet only has trusted proxies and no other services.
Traefik by default doesn't trust any other proxies requiring explicit configuration of which proxies are trusted and removes potentially fabricated headers that are likely to lead to security issues, and it is difficult to configure this incorrectly. This is an important security feature that is common with proxies with good security practices.
In the example we have four commented lines which configure trustedIPs which show an example on adding the following
networks to the trusted proxy list in Traefik:
See the Entry Points documentation for more information.
Traefik utilizes the ForwardAuth Authz implementation. The associated Metadata should be considered required.
The examples below assume you are using the default Authz Endpoints Configuration or one similar to the following minimal configuration:
server:
endpoints:
authz:
forward-auth:
implementation: 'ForwardAuth'
The examples below also assume you are using the modern
Session Configuration which includes the domain, authelia_url, and
default_redirection_url as a subkey of the session.cookies key as a list item. Below is an example of the modern
configuration as well as the legacy configuration for context.
{{< sessionTabs "Generate Random Password" >}} {{< sessionTab "Modern" >}}
session:
cookies:
- domain: '{{</* sitevar name="domain" nojs="example.com" */>}}'
authelia_url: 'https://{{</* sitevar name="subdomain-authelia" nojs="auth" */>}}.{{</* sitevar name="domain" nojs="example.com" */>}}'
default_redirection_url: 'https://www.{{</* sitevar name="domain" nojs="example.com" */>}}'
{{< /sessionTab >}} {{< sessionTab "Legacy" >}}
default_redirection_url: 'https://www.{{</* sitevar name="domain" nojs="example.com" */>}}'
session:
domain: '{{</* sitevar name="domain" nojs="example.com" */>}}'
{{< /sessionTab >}} {{< /sessionTabs >}}
Below you will find commented examples of the following docker deployment:
The below configuration looks to provide examples of running Traefik 3.x with labels to protect your endpoint (Nextcloud in this case).
Please ensure that you also setup the respective ACME configuration for your Traefik setup as this is not covered in the example below.
This guide makes a few assumptions. These assumptions may require adaptation in more advanced and complex scenarios. We can not reasonably have examples for every advanced configuration option that exists. Some of these values can automatically be replaced with documentation variables.
{{< sitevar-preferences >}}
The following are the assumptions we make:
{{< sitevar name="host" nojs="authelia" >}} on port {{< sitevar name="port" nojs="9091" >}}{{< sitevar name="tls" nojs="http" >}}://{{< sitevar name="host" nojs="authelia" >}}:{{< sitevar name="port" nojs="9091" >}} and as such:
https:// if Authelia configuration has a TLS key and
certificate defined{{< sitevar name="host" nojs="authelia" >}} in the URL if:
{{< sitevar name="port" nojs="9091" >}} in the URL if:
{{< sitevar name="domain" nojs="example.com" >}} domain:
This is an example configuration using docker compose labels:
---
networks:
net:
driver: bridge
services:
traefik:
container_name: 'traefik'
image: 'traefik:v3.5'
restart: 'unless-stopped'
command:
- '--api=true'
- '--api.dashboard=true'
- '--api.insecure=false'
- '--pilot.dashboard=false'
- '--global.sendAnonymousUsage=false'
- '--global.checkNewVersion=false'
- '--log=true'
- '--log.level=DEBUG'
- '--log.filepath=/config/traefik.log'
- '--providers.docker=true'
- '--providers.docker.exposedByDefault=false'
- '--entryPoints.http=true'
- '--entryPoints.http.address=:8080/tcp'
- '--entryPoints.http.http.redirections.entryPoint.to=https'
- '--entryPoints.http.http.redirections.entryPoint.scheme=https'
## Please see the Forwarded Header Trust section of the Authelia Traefik Integration documentation.
# - '--entryPoints.http.forwardedHeaders.trustedIPs=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,fc00::/7'
# - '--entryPoints.http.proxyProtocol.trustedIPs=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,fc00::/7'
- '--entryPoints.http.forwardedHeaders.insecure=false'
- '--entryPoints.http.proxyProtocol.insecure=false'
- '--entryPoints.https=true'
- '--entryPoints.https.address=:8443/tcp'
## Please see the Forwarded Header Trust section of the Authelia Traefik Integration documentation.
# - '--entryPoints.https.forwardedHeaders.trustedIPs=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,fc00::/7'
# - '--entryPoints.https.proxyProtocol.trustedIPs=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,fc00::/7'
- '--entryPoints.https.forwardedHeaders.insecure=false'
- '--entryPoints.https.proxyProtocol.insecure=false'
networks:
net: {}
ports:
- '80:8080'
- '443:8443'
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
- '${PWD}/data/traefik:/config'
labels:
traefik.enable: 'true'
traefik.http.routers.api.rule: 'Host(`traefik.{{< sitevar name="domain" nojs="example.com" >}}`)'
traefik.http.routers.api.entryPoints: 'https'
traefik.http.routers.api.tls: 'true'
traefik.http.routers.api.service: 'api@internal'
traefik.http.routers.api.middlewares: 'authelia@docker'
authelia:
container_name: '{{< sitevar name="host" nojs="authelia" >}}'
image: 'authelia/authelia'
restart: 'unless-stopped'
networks:
net: {}
volumes:
- '${PWD}/data/authelia/config:/config'
environment:
TZ: "Australia/Melbourne"
labels:
traefik.enable: 'true'
traefik.http.routers.authelia.rule: 'Host(`{{< sitevar name="subdomain-authelia" nojs="auth" >}}.{{< sitevar name="domain" nojs="example.com" >}}`)'
traefik.http.routers.authelia.entryPoints: 'https'
traefik.http.routers.authelia.tls: 'true'
traefik.http.middlewares.authelia.forwardAuth.address: '{{< sitevar name="tls" nojs="http" >}}://{{< sitevar name="host" nojs="authelia" >}}:{{< sitevar name="port" nojs="9091" >}}/api/authz/forward-auth'
## The following commented line is for configuring the Authelia URL in the proxy. We strongly suggest this is
## configured in the Session Cookies section of the Authelia configuration.
# traefik.http.middlewares.authelia.forwardAuth.address: '{{< sitevar name="tls" nojs="http" >}}://{{< sitevar name="host" nojs="authelia" >}}:{{< sitevar name="port" nojs="9091" >}}/api/authz/forward-auth?authelia_url=https%3A%2F%2F{{< sitevar name="subdomain-authelia" nojs="auth" >}}.{{< sitevar name="domain" nojs="example.com" >}}%2F'
traefik.http.middlewares.authelia.forwardAuth.trustForwardHeader: 'true'
traefik.http.middlewares.authelia.forwardAuth.maxResponseBodySize: '8192'
traefik.http.middlewares.authelia.forwardAuth.authResponseHeaders: 'Remote-User,Remote-Groups,Remote-Email,Remote-Name'
nextcloud:
container_name: 'nextcloud'
image: 'linuxserver/nextcloud'
restart: 'unless-stopped'
networks:
net: {}
volumes:
- '${PWD}/data/nextcloud/config:/config'
- '${PWD}/data/nextcloud/data:/data'
environment:
PUID: '1000'
PGID: '1000'
TZ: 'Australia/Melbourne'
labels:
traefik.enable: 'true'
traefik.http.routers.nextcloud.rule: 'Host(`nextcloud.{{< sitevar name="domain" nojs="example.com" >}}`)'
traefik.http.routers.nextcloud.entryPoints: 'https'
traefik.http.routers.nextcloud.tls: 'true'
traefik.http.routers.nextcloud.middlewares: 'authelia@docker'
heimdall:
container_name: 'heimdall'
image: 'linuxserver/heimdall'
restart: 'unless-stopped'
networks:
net: {}
volumes:
- '${PWD}/data/heimdall/config:/config'
environment:
PUID: '1000'
PGID: '1000'
TZ: 'Australia/Melbourne'
labels:
traefik.enable: 'true'
traefik.http.routers.heimdall.rule: 'Host(`heimdall.{{< sitevar name="domain" nojs="example.com" >}}`)'
traefik.http.routers.heimdall.entryPoints: 'https'
traefik.http.routers.heimdall.tls: 'true'
traefik.http.routers.heimdall.middlewares: 'authelia-basic@docker'
...
This example uses a compose.yml similar to the one above however it has two major differences:
labels section of the compose.yml file.cert and key options in the http.middlewares
section for the forwardAuth middlewares and the certificates in the http.serversTransports section.tls section in the http.middlewares section for
all forwardAuth middlewares, adjusting the authelia router in the http.routers section to use the
authelia-net@docker service, and commenting the authelia service in the http.service section.---
networks:
net:
driver: 'bridge'
services:
traefik:
container_name: 'traefik'
image: 'traefik:v3.5'
restart: 'unless-stopped'
command:
- '--api=true'
- '--api.dashboard=true'
- '--api.insecure=false'
- '--pilot.dashboard=false'
- '--global.sendAnonymousUsage=false'
- '--global.checkNewVersion=false'
- '--log=true'
- '--log.level=DEBUG'
- '--log.filepath=/config/traefik.log'
- '--providers.docker=true'
- '--providers.docker.exposedByDefault=false'
- '--providers.file=true'
- '--providers.file.watch=true'
- '--providers.file.directory=/config/dynamic'
- '--entryPoints.http=true'
- '--entryPoints.http.address=:8080/tcp'
- '--entryPoints.http.http.redirections.entryPoint.to=https'
- '--entryPoints.http.http.redirections.entryPoint.scheme=https'
- '--entryPoints.https=true'
- '--entryPoints.https.address=:8443/tcp'
networks:
net: {}
ports:
- '80:8080'
- '443:8443'
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
- '${PWD}/data/traefik/config:/config'
- '${PWD}/data/traefik/certificates:/certificates'
labels:
traefik.enable: 'true'
authelia:
container_name: '{{< sitevar name="host" nojs="authelia" >}}'
image: 'authelia/authelia'
restart: 'unless-stopped'
networks:
net: {}
volumes:
- '${PWD}/data/authelia/config:/config'
- '${PWD}/data/authelia/certificates:/certificates'
environment:
TZ: 'Australia/Melbourne'
labels:
traefik.enable: 'true'
nextcloud:
container_name: 'nextcloud'
image: 'linuxserver/nextcloud'
restart: 'unless-stopped'
networks:
net: {}
volumes:
- '${PWD}/data/nextcloud/config:/config'
- '${PWD}/data/nextcloud/data:/data'
environment:
PUID: '1000'
PGID: '1000'
TZ: 'Australia/Melbourne'
labels:
traefik.enable: 'true'
heimdall:
container_name: 'heimdall'
image: 'linuxserver/heimdall'
restart: 'unless-stopped'
networks:
net: {}
volumes:
- '${PWD}/data/heimdall/config:/config'
environment:
PUID: '1000'
PGID: '1000'
TZ: 'Australia/Melbourne'
labels:
traefik.enable: 'true'
whoami:
container_name: 'whoami'
image: 'traefik/whoami:latest'
restart: 'unless-stopped'
networks:
net: {}
environment:
TZ: 'Australia/Melbourne'
labels:
traefik.enable: 'true'
...
This file is part of the dynamic configuration and should have the path
${PWD}/data/traefik/config/dynamic/traefik.yml. Please see the Traefik service and the volume that mounts the
${PWD}/data/traefik/config in the docker compose above.
---
entryPoints:
web:
proxyProtocol:
insecure: false
trustedIPs: []
forwardedHeaders:
insecure: false
trustedIPs: []
websecure:
proxyProtocol:
insecure: false
trustedIPs: []
forwardedHeaders:
insecure: false
trustedIPs: []
tls:
options:
modern:
minVersion: 'VersionTLS13'
intermediate:
minVersion: 'VersionTLS12'
cipherSuites:
- 'TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256'
- 'TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256'
- 'TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384'
- 'TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384'
- 'TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305'
- 'TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305'
http:
middlewares:
authelia:
forwardAuth:
address: '{{< sitevar name="tls" nojs="http" >}}://{{< sitevar name="host" nojs="authelia" >}}:{{< sitevar name="port" nojs="9091" >}}/api/authz/forward-auth'
## The following commented line is for configuring the Authelia URL in the proxy. We strongly suggest this is
## configured in the Session Cookies section of the Authelia configuration.
# address: '{{< sitevar name="tls" nojs="http" >}}://{{< sitevar name="host" nojs="authelia" >}}:{{< sitevar name="port" nojs="9091" >}}/api/authz/forward-auth?authelia_url=https%3A%2F%2F{{< sitevar name="subdomain-authelia" nojs="auth" >}}.{{< sitevar name="domain" nojs="example.com" >}}%2F'
trustForwardHeader: true
maxResponseBodySize: 8192
authResponseHeaders:
- 'Remote-User'
- 'Remote-Groups'
- 'Remote-Email'
- 'Remote-Name'
tls:
ca: '/certificates/ca.public.crt'
cert: '/certificates/traefik.public.crt'
key: '/certificates/traefik.private.pem'
authelia-basic:
forwardAuth:
address: '{{< sitevar name="tls" nojs="http" >}}://{{< sitevar name="host" nojs="authelia" >}}:{{< sitevar name="port" nojs="9091" >}}/api/verify?auth=basic'
trustForwardHeader: true
maxResponseBodySize: 8192
authResponseHeaders:
- 'Remote-User'
- 'Remote-Groups'
- 'Remote-Email'
- 'Remote-Name'
tls:
ca: '/certificates/ca.public.crt'
cert: '/certificates/traefik.public.crt'
key: '/certificates/traefik.private.pem'
routers:
traefik:
rule: 'Host(`traefik.{{< sitevar name="domain" nojs="example.com" >}}`)'
entryPoints: 'websecure'
service: 'api@internal'
middlewares:
- 'authelia@file'
tls:
options: 'modern@file'
certResolver: 'default'
domains:
- main: '{{< sitevar name="domain" nojs="example.com" >}}'
sans:
- '*.{{< sitevar name="domain" nojs="example.com" >}}'
whoami:
rule: 'Host(`whoami.{{< sitevar name="domain" nojs="example.com" >}}`)'
entryPoints: 'websecure'
service: 'whoami-net@docker'
middlewares:
- 'authelia@file'
tls:
options: 'modern@file'
certResolver: 'default'
domains:
- main: '{{< sitevar name="domain" nojs="example.com" >}}'
sans:
- '*.{{< sitevar name="domain" nojs="example.com" >}}'
nextcloud:
rule: 'Host(`nextcloud.{{< sitevar name="domain" nojs="example.com" >}}`)'
entryPoints: 'websecure'
service: 'nextcloud-net@docker'
middlewares:
- 'authelia@file'
tls:
options: 'modern@file'
certResolver: 'default'
domains:
- main: '{{< sitevar name="domain" nojs="example.com" >}}'
sans:
- '*.{{< sitevar name="domain" nojs="example.com" >}}'
heimdall:
rule: 'Host(`heimdall.{{< sitevar name="domain" nojs="example.com" >}}`)'
entryPoints: 'websecure'
service: 'heimdall-net@docker'
middlewares:
- 'authelia-basic@file'
tls:
options: 'modern@file'
certResolver: 'default'
domains:
- main: '{{< sitevar name="domain" nojs="example.com" >}}'
sans:
- '*.{{< sitevar name="domain" nojs="example.com" >}}'
authelia:
rule: 'Host(`{{< sitevar name="subdomain-authelia" nojs="auth" >}}.{{< sitevar name="domain" nojs="example.com" >}}`)'
entryPoints: 'websecure'
service: 'authelia@file'
tls:
options: 'modern@file'
certResolver: 'default'
domains:
- main: '{{< sitevar name="domain" nojs="example.com" >}}'
sans:
- '*.{{< sitevar name="domain" nojs="example.com" >}}'
services:
authelia:
loadBalancer:
servers:
- url: '{{< sitevar name="tls" nojs="http" >}}://{{< sitevar name="host" nojs="authelia" >}}:{{< sitevar name="port" nojs="9091" >}}/'
serversTransport: 'autheliaMutualTLS'
serversTransports:
autheliaMutualTLS:
certificates:
- certFile: '/certificates/traefik.public.crt'
keyFile: '/certificates/traefik.private.pem'
rootCAs:
- '/certificates/ca.public.crt'
...
Authelia supports some of the Traefik based Kubernetes Ingress. See the Kubernetes Integration Guide for more information.
Authelia provides the means to be able to authenticate your first factor via the Proxy-Authorization header, this is compatible with Traefik.
If you have a use-case which requires the use of the Authorization header/basic authentication login prompt you can
call Authelia's /api/verify?auth=basic endpoint to force a switch to the Authorization header.
If Traefik and Authelia are defined in different docker compose stacks you may experience an issue where Traefik
complains that: middleware authelia@docker not found.
This can be avoided a couple different ways:
traefik.http.middlewares.authelia.forwardAuth.address: '{{< sitevar name="tls" nojs="http" >}}://{{< sitevar name="host" nojs="authelia" >}}:{{< sitevar name="port" nojs="9091" >}}/api/authz/forward-auth'
## The following commented line is for configuring the Authelia URL in the proxy. We strongly suggest this is
## configured in the Session Cookies section of the Authelia configuration.
# traefik.http.middlewares.authelia.forwardAuth.address: '{{< sitevar name="tls" nojs="http" >}}://{{< sitevar name="host" nojs="authelia" >}}:{{< sitevar name="port" nojs="9091" >}}/api/authz/forward-auth?authelia_url=https%3A%2F%2F{{< sitevar name="subdomain-authelia" nojs="auth" >}}.{{< sitevar name="domain" nojs="example.com" >}}%2F'
traefik.http.middlewares.authelia.forwardAuth.trustForwardHeader: 'true'
traefik.http.middlewares.authelia.forwardAuth.maxResponseBodySize: '8192'
traefik.http.middlewares.authelia.forwardAuth.authResponseHeaders: 'Remote-User,Remote-Groups,Remote-Email,Remote-Name'