Protect with Authentik
Traefik's forwardAuth middleware can send each request to an Authentik outpost before it reaches an application. Authentik handles sign-in and returns identity headers to Traefik after successful authentication.
This guide uses the embedded outpost of the Authentik service on the same Coolify server as the protected resource. The embedded outpost runs in the authentik-server container on port 9000.
Configure Authentik
Deploy the Authentik service and give it a domain, for example https://auth.example.com. Then do these steps in the Authentik admin interface:
- Create an application with a Proxy Provider. Select one of these modes:
- Forward auth (single application): set External host to the URL of the protected application, for example
https://app.example.com. Use one provider for each application. - Forward auth (domain level): set Authentication URL to the Authentik URL, for example
https://auth.example.com, and Cookie domain to the parent domain, for exampleexample.com. One provider protects all subdomains.
- Forward auth (single application): set External host to the URL of the protected application, for example
- Open Applications > Outposts, edit authentik Embedded Outpost, and add the application to Selected Applications. If you do not do this step, the protected domain shows a white Not Found page.
- In the same outpost, open Advanced settings and make sure that
authentik_hostis the full public Authentik URL, for examplehttps://auth.example.com/.
See Authentik's forward authentication documentation for more information about the two modes.
Find the Authentik hostname
Traefik must send the forward-auth request to Authentik on the internal Docker network. Do not use the public Authentik URL.
Coolify names the container authentik-server-<service-uuid>. The <service-uuid> is the UUID of the Authentik service, which is in the URL of the service page. You can also run docker ps --filter name=authentik-server on the server.
Coolify connects the proxy to the network of the Authentik service, so Traefik can reach this container. The protected resource does not have to share a network with Authentik.
Create the Traefik middleware
Open Servers > your server > Proxy > Dynamic Configurations and create authentik-forward-auth.yaml. Replace <service-uuid> with the UUID of your Authentik service:
http:
middlewares:
authentik-forward-auth:
forwardAuth:
address: 'http://authentik-server-<service-uuid>:9000/outpost.goauthentik.io/auth/traefik'
trustForwardHeader: true
authResponseHeaders:
- X-authentik-username
- X-authentik-groups
- X-authentik-entitlements
- X-authentik-email
- X-authentik-name
- X-authentik-uid
- X-authentik-jwt
- X-authentik-meta-jwks
- X-authentik-meta-outpost
- X-authentik-meta-provider
- X-authentik-meta-app
- X-authentik-meta-versionRoute the outpost paths (single application mode)
In Forward auth (single application) mode, Authentik sends the browser to /outpost.goauthentik.io/ on the domain of the protected application to complete the sign-in. Traefik must send these paths to Authentik, not to the application. Add a router and a service for each protected domain to the same file:
http:
middlewares:
authentik-forward-auth:
# ...
routers:
app-authentik-outpost:
rule: 'Host(`app.example.com`) && PathPrefix(`/outpost.goauthentik.io/`)'
entryPoints:
- https
priority: 1000
service: authentik-outpost
tls:
certResolver: letsencrypt
services:
authentik-outpost:
loadBalancer:
servers:
- url: 'http://authentik-server-<service-uuid>:9000/outpost.goauthentik.io'Replace app.example.com with the protected domain. Add one router for each protected domain. All routers can use the same authentik-outpost service.
In Forward auth (domain level) mode, you do not need these routers. The sign-in occurs on the Authentik domain, and Coolify already routes that domain to the authentik-server container.
Attach the middleware
Open the application General page and find Container labels. Set Label management to Managed manually (edit labels yourself), then append the file-provider middleware to the existing HTTPS router:
traefik.http.routers.https-0-<resource-id>.middlewares=gzip
traefik.http.routers.https-0-<resource-id>.middlewares=gzip,authentik-forward-auth@file Save and redeploy the application.
Verify authentication
Open the protected domain in a private browser window. Traefik should redirect you to Authentik, then return you to the application after sign-in.
Troubleshooting
A broken forward-auth route can lock every user out of the protected application. Keep Coolify dashboard access on a separate domain and know how to remove the middleware label before protecting administrative services.
