2020-02-29 00:43:59 +00:00
|
|
|
---
|
2022-06-15 07:51:47 +00:00
|
|
|
title: "HAProxy"
|
|
|
|
description: "An integration guide for Authelia and the HAProxy reverse proxy"
|
|
|
|
lead: "A guide on integrating Authelia with the HAProxy reverse proxy."
|
2022-06-28 05:27:14 +00:00
|
|
|
date: 2020-02-29T01:43:59+01:00
|
2022-06-15 07:51:47 +00:00
|
|
|
draft: false
|
|
|
|
images: []
|
|
|
|
menu:
|
|
|
|
integration:
|
|
|
|
parent: "proxies"
|
|
|
|
weight: 340
|
|
|
|
toc: true
|
|
|
|
aliases:
|
|
|
|
- /i/haproxy
|
|
|
|
- /docs/deployment/supported-proxies/haproxy.html
|
2020-02-29 00:43:59 +00:00
|
|
|
---
|
|
|
|
|
2022-06-15 07:51:47 +00:00
|
|
|
[HAProxy] is a reverse proxy supported by __Authelia__.
|
2020-02-29 00:43:59 +00:00
|
|
|
|
2022-06-15 07:51:47 +00:00
|
|
|
*__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](#see-also) section.*
|
2020-02-29 00:43:59 +00:00
|
|
|
|
2022-06-22 12:58:23 +00:00
|
|
|
## Get Started
|
|
|
|
|
|
|
|
It's __*strongly recommended*__ that users setting up *Authelia* for the first time take a look at our
|
|
|
|
[Get Started](../prologue/get-started.md) guide. This takes you through various steps which are essential to
|
|
|
|
bootstrapping *Authelia*.
|
|
|
|
|
2020-04-28 09:17:45 +00:00
|
|
|
## Requirements
|
2020-02-29 00:43:59 +00:00
|
|
|
|
2022-06-15 07:51:47 +00:00
|
|
|
You need the following to run __Authelia__ with [HAProxy]:
|
2020-04-28 09:17:45 +00:00
|
|
|
|
2022-06-15 07:51:47 +00:00
|
|
|
* [HAProxy] 1.8.4+ (2.2.0+ recommended)
|
|
|
|
-`USE_LUA=1` set at compile time
|
2020-09-10 00:52:57 +00:00
|
|
|
* [haproxy-lua-http](https://github.com/haproxytech/haproxy-lua-http) must be available within the Lua path
|
|
|
|
* A `json` library within the Lua path (dependency of haproxy-lua-http, usually found as OS package `lua-json`)
|
2022-06-15 07:51:47 +00:00
|
|
|
* With [HAProxy] 2.1.3+ you can use the `lua-prepend-path` configuration option to specify the search path
|
2020-09-10 00:52:57 +00:00
|
|
|
* [haproxy-auth-request](https://github.com/TimWolla/haproxy-auth-request/blob/master/auth-request.lua)
|
2020-04-28 09:17:45 +00:00
|
|
|
|
2022-06-15 07:51:47 +00:00
|
|
|
## Trusted Proxies
|
|
|
|
|
|
|
|
*__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.*
|
|
|
|
|
|
|
|
With [HAProxy] the most convenient method to configure trusted proxies is to create a src ACL from the contents of a
|
|
|
|
file. The example utilizes this method and trusted proxies can then easily be added or removed from the ACL file.
|
|
|
|
|
|
|
|
[HAProxy] implicitly trusts all external proxies by default so it's important you configure this for a trusted
|
|
|
|
environment.
|
|
|
|
|
|
|
|
[HAProxy] by default __does__ trust all other proxies. This means it's essential that you configure this correctly.
|
|
|
|
|
|
|
|
In the example we have a `trusted_proxies.src.acl` file which is used by one `http-request del-header X-Forwarded-For`
|
|
|
|
line in the main configuration which shows an example of not trusting any proxies or alternatively an example on adding
|
|
|
|
the following networks to the trusted proxy list in [HAProxy]:
|
|
|
|
|
|
|
|
* 10.0.0.0/8
|
2023-01-28 22:25:32 +00:00
|
|
|
* 172.16.0.0/12
|
2022-06-15 07:51:47 +00:00
|
|
|
* 192.168.0.0/16
|
|
|
|
* fc00::/7
|
2020-04-28 09:17:45 +00:00
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
|
|
Below you will find commented examples of the following configuration:
|
|
|
|
|
2022-06-15 07:51:47 +00:00
|
|
|
* Authelia Portal
|
|
|
|
* Protected Endpoint (Nextcloud)
|
|
|
|
* Protected Endpoint with `Authorization` header for basic authentication (Heimdall)
|
2020-04-28 09:17:45 +00:00
|
|
|
|
|
|
|
With this configuration you can protect your virtual hosts with Authelia, by following the steps below:
|
2022-06-15 07:51:47 +00:00
|
|
|
|
2021-02-23 23:35:04 +00:00
|
|
|
1. Add host(s) to the `protected-frontends` or `protected-frontends-basic` ACLs to support protection with Authelia.
|
2020-04-28 09:17:45 +00:00
|
|
|
You can separate each subdomain with a `|` in the regex, for example:
|
2022-06-15 07:51:47 +00:00
|
|
|
|
|
|
|
```text
|
2020-11-24 01:35:38 +00:00
|
|
|
acl protected-frontends hdr(host) -m reg -i ^(?i)(jenkins|nextcloud|phpmyadmin)\.example\.com
|
2021-02-23 23:35:04 +00:00
|
|
|
acl protected-frontends-basic hdr(host) -m reg -i ^(?i)(heimdall)\.example\.com
|
2020-04-28 09:17:45 +00:00
|
|
|
```
|
2022-06-15 07:51:47 +00:00
|
|
|
|
2020-04-28 09:17:45 +00:00
|
|
|
2. Add host ACL(s) in the form of `host-service`, this will be utilised to route to the correct
|
|
|
|
backend upon successful authentication, for example:
|
2022-06-15 07:51:47 +00:00
|
|
|
|
|
|
|
```text
|
2020-04-28 09:17:45 +00:00
|
|
|
acl host-jenkins hdr(host) -i jenkins.example.com
|
2020-05-14 03:26:52 +00:00
|
|
|
acl host-nextcloud hdr(host) -i nextcloud.example.com
|
2020-04-28 09:17:45 +00:00
|
|
|
acl host-phpmyadmin hdr(host) -i phpmyadmin.example.com
|
2021-02-23 23:35:04 +00:00
|
|
|
acl host-heimdall hdr(host) -i heimdall.example.com
|
2020-04-28 09:17:45 +00:00
|
|
|
```
|
2022-06-15 07:51:47 +00:00
|
|
|
|
2020-04-28 09:17:45 +00:00
|
|
|
3. Add backend route for your service(s), for example:
|
2022-06-15 07:51:47 +00:00
|
|
|
|
|
|
|
```text
|
2020-04-28 09:17:45 +00:00
|
|
|
use_backend be_jenkins if host-jenkins
|
|
|
|
use_backend be_nextcloud if host-nextcloud
|
|
|
|
use_backend be_phpmyadmin if host-phpmyadmin
|
2021-02-23 23:35:04 +00:00
|
|
|
use_backend be_heimdall if host-heimdall
|
2020-04-28 09:17:45 +00:00
|
|
|
```
|
2022-06-15 07:51:47 +00:00
|
|
|
|
2020-04-28 09:17:45 +00:00
|
|
|
4. Add backend definitions for your service(s), for example:
|
2022-06-15 07:51:47 +00:00
|
|
|
|
|
|
|
```text
|
2020-04-28 09:17:45 +00:00
|
|
|
backend be_jenkins
|
|
|
|
server jenkins jenkins:8080
|
|
|
|
backend be_nextcloud
|
|
|
|
server nextcloud nextcloud:443 ssl verify none
|
|
|
|
backend be_phpmyadmin
|
|
|
|
server phpmyadmin phpmyadmin:80
|
2021-02-23 23:35:04 +00:00
|
|
|
backend be_heimdall
|
2022-06-15 07:51:47 +00:00
|
|
|
server heimdall heimdall:443 ssl verify none
|
2020-04-28 09:17:45 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### Secure Authelia with TLS
|
2022-06-15 07:51:47 +00:00
|
|
|
|
|
|
|
There is a [known limitation](https://github.com/TimWolla/haproxy-auth-request/issues/12) with haproxy-auth-request with
|
|
|
|
regard to TLS-enabled backends. If you want to run Authelia TLS enabled the recommended workaround utilises [HAProxy]
|
|
|
|
itself to proxy the requests. This comes at a cost of two additional TCP connections, but allows the full [HAProxy]
|
|
|
|
configuration flexibility with regard to TLS verification as well as header rewriting. An example of this configuration
|
|
|
|
is also be provided below.
|
2020-04-28 09:17:45 +00:00
|
|
|
|
|
|
|
#### Configuration
|
|
|
|
|
2022-06-15 07:51:47 +00:00
|
|
|
##### trusted_proxies.src.acl
|
|
|
|
|
|
|
|
```text
|
|
|
|
10.0.0.0/8
|
|
|
|
172.16.0.0/12
|
|
|
|
192.168.0.0/16
|
|
|
|
fc00::/7
|
2020-04-28 10:53:06 +00:00
|
|
|
```
|
2022-06-15 07:51:47 +00:00
|
|
|
|
|
|
|
##### haproxy.cfg
|
|
|
|
|
|
|
|
```text
|
2020-04-28 09:17:45 +00:00
|
|
|
global
|
2020-09-10 00:52:57 +00:00
|
|
|
# Path to haproxy-lua-http, below example assumes /usr/local/etc/haproxy/haproxy-lua-http/http.lua
|
|
|
|
lua-prepend-path /usr/local/etc/haproxy/?/http.lua
|
2020-04-28 09:17:45 +00:00
|
|
|
# Path to haproxy-auth-request
|
|
|
|
lua-load /usr/local/etc/haproxy/auth-request.lua
|
|
|
|
log stdout format raw local0 debug
|
|
|
|
|
|
|
|
defaults
|
|
|
|
mode http
|
|
|
|
log global
|
|
|
|
option httplog
|
|
|
|
|
|
|
|
frontend fe_http
|
2022-06-15 07:51:47 +00:00
|
|
|
bind *:443 ssl crt example.com.pem
|
|
|
|
|
|
|
|
## Trusted Proxies.
|
|
|
|
http-request del-header X-Forwarded-For
|
|
|
|
|
|
|
|
## Comment the above directive and the two directives below to enable the trusted proxies ACL.
|
|
|
|
# acl src-trusted_proxies src -f trusted_proxies.src.acl
|
|
|
|
# http-request del-header X-Forwarded-For if !src-trusted_proxies
|
|
|
|
|
|
|
|
## Ensure X-Forwarded-For is set for the auth request.
|
|
|
|
acl hdr-xff_exists req.hdr(X-Forwarded-For) -m found
|
|
|
|
http-request set-header X-Forwarded-For %[src] if !hdr-xff_exists
|
|
|
|
option forwardfor
|
|
|
|
|
2020-04-28 09:17:45 +00:00
|
|
|
# Host ACLs
|
2020-11-24 01:35:38 +00:00
|
|
|
acl protected-frontends hdr(host) -m reg -i ^(?i)(nextcloud)\.example\.com
|
2021-02-23 23:35:04 +00:00
|
|
|
acl protected-frontends-basic hdr(host) -m reg -i ^(?i)(heimdall)\.example\.com
|
2020-04-28 09:17:45 +00:00
|
|
|
acl host-authelia hdr(host) -i auth.example.com
|
|
|
|
acl host-nextcloud hdr(host) -i nextcloud.example.com
|
2021-02-23 23:35:04 +00:00
|
|
|
acl host-heimdall hdr(host) -i heimdall.example.com
|
2020-04-28 09:17:45 +00:00
|
|
|
|
2021-03-18 08:56:08 +00:00
|
|
|
# This is required if utilising basic auth with /api/verify?auth=basic
|
|
|
|
http-request set-var(txn.host) hdr(Host)
|
|
|
|
|
2020-04-28 09:17:45 +00:00
|
|
|
http-request set-var(req.scheme) str(https) if { ssl_fc }
|
|
|
|
http-request set-var(req.scheme) str(http) if !{ ssl_fc }
|
|
|
|
http-request set-var(req.questionmark) str(?) if { query -m found }
|
2022-06-15 07:51:47 +00:00
|
|
|
|
2021-03-05 04:18:31 +00:00
|
|
|
# These are optional if you wish to use the Methods rule in the access_control section.
|
|
|
|
#http-request set-var(req.method) str(CONNECT) if { method CONNECT }
|
|
|
|
#http-request set-var(req.method) str(GET) if { method GET }
|
|
|
|
#http-request set-var(req.method) str(HEAD) if { method HEAD }
|
|
|
|
#http-request set-var(req.method) str(OPTIONS) if { method OPTIONS }
|
|
|
|
#http-request set-var(req.method) str(POST) if { method POST }
|
|
|
|
#http-request set-var(req.method) str(TRACE) if { method TRACE }
|
|
|
|
#http-request set-var(req.method) str(PUT) if { method PUT }
|
|
|
|
#http-request set-var(req.method) str(PATCH) if { method PATCH }
|
|
|
|
#http-request set-var(req.method) str(DELETE) if { method DELETE }
|
|
|
|
#http-request set-header X-Forwarded-Method %[var(req.method)]
|
|
|
|
|
2020-09-22 23:06:26 +00:00
|
|
|
# Required headers
|
2020-04-28 09:17:45 +00:00
|
|
|
http-request set-header X-Real-IP %[src]
|
2023-01-25 09:36:40 +00:00
|
|
|
http-request set-header X-Original-Method %[var(req.method)]
|
|
|
|
http-request set-header X-Original-URL %[var(req.scheme)]://%[req.hdr(Host)]%[path]%[var(req.questionmark)]%[query]
|
2020-04-28 09:17:45 +00:00
|
|
|
|
|
|
|
# Protect endpoints with haproxy-auth-request and Authelia
|
2023-01-25 09:36:40 +00:00
|
|
|
http-request lua.auth-request be_authelia /api/authz/auth-request if protected-frontends
|
2021-02-23 23:35:04 +00:00
|
|
|
# Force `Authorization` header via query arg to /api/verify
|
|
|
|
http-request lua.auth-request be_authelia /api/verify?auth=basic if protected-frontends-basic
|
2021-03-18 08:56:08 +00:00
|
|
|
|
|
|
|
# Redirect protected-frontends to Authelia if not authenticated
|
|
|
|
http-request redirect location https://auth.example.com/?rd=%[var(req.scheme)]://%[base]%[var(req.questionmark)]%[query] if protected-frontends !{ var(txn.auth_response_successful) -m bool }
|
|
|
|
# Send 401 and pass `WWW-Authenticate` header on protected-frontend-basic if not pre-authenticated
|
|
|
|
http-request set-var(txn.auth) var(req.auth_response_header.www_authenticate) if protected-frontends-basic !{ var(txn.auth_response_successful) -m bool }
|
|
|
|
http-response deny deny_status 401 hdr WWW-Authenticate %[var(txn.auth)] if { var(txn.host) -m reg -i ^(?i)(heimdall)\.example\.com } !{ var(txn.auth_response_successful) -m bool }
|
|
|
|
|
2020-04-28 09:17:45 +00:00
|
|
|
# Authelia backend route
|
|
|
|
use_backend be_authelia if host-authelia
|
2021-03-18 08:56:08 +00:00
|
|
|
|
2020-04-28 09:17:45 +00:00
|
|
|
# Service backend route(s)
|
|
|
|
use_backend be_nextcloud if host-nextcloud
|
2021-02-23 23:35:04 +00:00
|
|
|
use_backend be_heimdall if host-heimdall
|
2020-04-28 09:17:45 +00:00
|
|
|
|
|
|
|
backend be_authelia
|
|
|
|
server authelia authelia:9091
|
|
|
|
|
|
|
|
backend be_nextcloud
|
2023-02-02 07:13:18 +00:00
|
|
|
## Pass the special authorization response headers to the protected application.
|
|
|
|
acl authorization_exist var(req.auth_response_header.authorization) -m found
|
|
|
|
acl proxy_authorization_exist var(req.auth_response_header.proxy_authorization) -m found
|
|
|
|
|
|
|
|
http-request set-header Authorization %[var(req.auth_response_header.authorization)] if authorization_exist
|
|
|
|
http-request set-header Proxy-Authorization %[var(req.auth_response_header.proxy_authorization)] if proxy_authorization_exist
|
|
|
|
|
|
|
|
## Pass the special metadata response headers to the protected application.
|
2020-09-10 00:52:57 +00:00
|
|
|
acl remote_user_exist var(req.auth_response_header.remote_user) -m found
|
|
|
|
acl remote_groups_exist var(req.auth_response_header.remote_groups) -m found
|
2020-10-26 11:38:08 +00:00
|
|
|
acl remote_name_exist var(req.auth_response_header.remote_name) -m found
|
|
|
|
acl remote_email_exist var(req.auth_response_header.remote_email) -m found
|
2023-02-02 07:13:18 +00:00
|
|
|
|
2020-09-10 00:52:57 +00:00
|
|
|
http-request set-header Remote-User %[var(req.auth_response_header.remote_user)] if remote_user_exist
|
|
|
|
http-request set-header Remote-Groups %[var(req.auth_response_header.remote_groups)] if remote_groups_exist
|
2020-10-26 11:38:08 +00:00
|
|
|
http-request set-header Remote-Name %[var(req.auth_response_header.remote_name)] if remote_name_exist
|
|
|
|
http-request set-header Remote-Email %[var(req.auth_response_header.remote_email)] if remote_email_exist
|
2020-09-10 00:52:57 +00:00
|
|
|
|
2023-02-02 07:13:18 +00:00
|
|
|
## Pass the Set-Cookie response headers to the user.
|
|
|
|
acl set_cookie_exist var(req.auth_response_header.set_cookie) -m found
|
|
|
|
http-response set-header Set-Cookie %[var(req.auth_response_header.set_cookie)] if set_cookie_exist
|
|
|
|
|
2020-04-28 09:17:45 +00:00
|
|
|
server nextcloud nextcloud:443 ssl verify none
|
2021-02-23 23:35:04 +00:00
|
|
|
|
|
|
|
backend be_heimdall
|
2023-02-02 07:13:18 +00:00
|
|
|
## Pass the special authorization response headers to the protected application.
|
|
|
|
acl authorization_exist var(req.auth_response_header.authorization) -m found
|
|
|
|
acl proxy_authorization_exist var(req.auth_response_header.proxy_authorization) -m found
|
|
|
|
|
|
|
|
http-request set-header Authorization %[var(req.auth_response_header.authorization)] if authorization_exist
|
|
|
|
http-request set-header Proxy-Authorization %[var(req.auth_response_header.proxy_authorization)] if proxy_authorization_exist
|
|
|
|
|
|
|
|
## Pass the special metadata response headers to the protected application.
|
2021-02-23 23:35:04 +00:00
|
|
|
acl remote_user_exist var(req.auth_response_header.remote_user) -m found
|
|
|
|
acl remote_groups_exist var(req.auth_response_header.remote_groups) -m found
|
|
|
|
acl remote_name_exist var(req.auth_response_header.remote_name) -m found
|
|
|
|
acl remote_email_exist var(req.auth_response_header.remote_email) -m found
|
2023-02-02 07:13:18 +00:00
|
|
|
|
2021-02-23 23:35:04 +00:00
|
|
|
http-request set-header Remote-User %[var(req.auth_response_header.remote_user)] if remote_user_exist
|
|
|
|
http-request set-header Remote-Groups %[var(req.auth_response_header.remote_groups)] if remote_groups_exist
|
|
|
|
http-request set-header Remote-Name %[var(req.auth_response_header.remote_name)] if remote_name_exist
|
|
|
|
http-request set-header Remote-Email %[var(req.auth_response_header.remote_email)] if remote_email_exist
|
|
|
|
|
2023-02-02 07:13:18 +00:00
|
|
|
## Pass the Set-Cookie response headers to the user.
|
|
|
|
acl set_cookie_exist var(req.auth_response_header.set_cookie) -m found
|
|
|
|
http-response set-header Set-Cookie %[var(req.auth_response_header.set_cookie)] if set_cookie_exist
|
|
|
|
|
2021-02-23 23:35:04 +00:00
|
|
|
server heimdall heimdall:443 ssl verify none
|
2020-04-28 09:17:45 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
##### haproxy.cfg (TLS enabled Authelia)
|
2022-06-15 07:51:47 +00:00
|
|
|
|
|
|
|
```text
|
2020-04-28 09:17:45 +00:00
|
|
|
global
|
2020-09-10 00:52:57 +00:00
|
|
|
# Path to haproxy-lua-http, below example assumes /usr/local/etc/haproxy/haproxy-lua-http/http.lua
|
|
|
|
lua-prepend-path /usr/local/etc/haproxy/?/http.lua
|
2020-04-28 09:17:45 +00:00
|
|
|
# Path to haproxy-auth-request
|
|
|
|
lua-load /usr/local/etc/haproxy/auth-request.lua
|
|
|
|
log stdout format raw local0 debug
|
|
|
|
|
|
|
|
defaults
|
|
|
|
mode http
|
|
|
|
log global
|
|
|
|
option httplog
|
|
|
|
option forwardfor
|
|
|
|
|
|
|
|
frontend fe_http
|
|
|
|
bind *:443 ssl crt /usr/local/etc/haproxy/haproxy.pem
|
2022-06-15 07:51:47 +00:00
|
|
|
|
2020-04-28 09:17:45 +00:00
|
|
|
# Host ACLs
|
2020-11-24 01:35:38 +00:00
|
|
|
acl protected-frontends hdr(host) -m reg -i ^(?i)(nextcloud)\.example\.com
|
2021-02-23 23:35:04 +00:00
|
|
|
acl protected-frontends-basic hdr(host) -m reg -i ^(?i)(heimdall)\.example\.com
|
2020-04-28 09:17:45 +00:00
|
|
|
acl host-authelia hdr(host) -i auth.example.com
|
|
|
|
acl host-nextcloud hdr(host) -i nextcloud.example.com
|
2021-02-23 23:35:04 +00:00
|
|
|
acl host-heimdall hdr(host) -i heimdall.example.com
|
2020-04-28 09:17:45 +00:00
|
|
|
|
2021-03-18 08:56:08 +00:00
|
|
|
# This is required if utilising basic auth with /api/verify?auth=basic
|
|
|
|
http-request set-var(txn.host) hdr(Host)
|
|
|
|
|
2020-04-28 09:17:45 +00:00
|
|
|
http-request set-var(req.scheme) str(https) if { ssl_fc }
|
|
|
|
http-request set-var(req.scheme) str(http) if !{ ssl_fc }
|
|
|
|
http-request set-var(req.questionmark) str(?) if { query -m found }
|
2022-06-15 07:51:47 +00:00
|
|
|
|
2021-03-05 04:18:31 +00:00
|
|
|
# These are optional if you wish to use the Methods rule in the access_control section.
|
|
|
|
#http-request set-var(req.method) str(CONNECT) if { method CONNECT }
|
|
|
|
#http-request set-var(req.method) str(GET) if { method GET }
|
|
|
|
#http-request set-var(req.method) str(HEAD) if { method HEAD }
|
|
|
|
#http-request set-var(req.method) str(OPTIONS) if { method OPTIONS }
|
|
|
|
#http-request set-var(req.method) str(POST) if { method POST }
|
|
|
|
#http-request set-var(req.method) str(TRACE) if { method TRACE }
|
|
|
|
#http-request set-var(req.method) str(PUT) if { method PUT }
|
|
|
|
#http-request set-var(req.method) str(PATCH) if { method PATCH }
|
|
|
|
#http-request set-var(req.method) str(DELETE) if { method DELETE }
|
|
|
|
#http-request set-header X-Forwarded-Method %[var(req.method)]
|
2022-06-15 07:51:47 +00:00
|
|
|
|
2020-09-22 23:06:26 +00:00
|
|
|
# Required headers
|
2020-04-28 09:17:45 +00:00
|
|
|
http-request set-header X-Real-IP %[src]
|
2023-01-25 09:36:40 +00:00
|
|
|
http-request set-header X-Original-Method %[var(req.method)]
|
|
|
|
http-request set-header X-Original-URL %[var(req.scheme)]://%[req.hdr(Host)]%[path]%[var(req.questionmark)]%[query]
|
2020-04-28 09:17:45 +00:00
|
|
|
|
|
|
|
# Protect endpoints with haproxy-auth-request and Authelia
|
2023-01-25 09:36:40 +00:00
|
|
|
http-request lua.auth-request be_authelia_proxy /api/authz/auth-request if protected-frontends
|
2021-02-23 23:35:04 +00:00
|
|
|
# Force `Authorization` header via query arg to /api/verify
|
2021-03-18 08:56:08 +00:00
|
|
|
http-request lua.auth-request be_authelia_proxy /api/verify?auth=basic if protected-frontends-basic
|
|
|
|
|
|
|
|
# Redirect protected-frontends to Authelia if not authenticated
|
|
|
|
http-request redirect location https://auth.example.com/?rd=%[var(req.scheme)]://%[base]%[var(req.questionmark)]%[query] if protected-frontends !{ var(txn.auth_response_successful) -m bool }
|
|
|
|
# Send 401 and pass `WWW-Authenticate` header on protected-frontend-basic if not pre-authenticated
|
|
|
|
http-request set-var(txn.auth) var(req.auth_response_header.www_authenticate) if protected-frontends-basic !{ var(txn.auth_response_successful) -m bool }
|
|
|
|
http-response deny deny_status 401 hdr WWW-Authenticate %[var(txn.auth)] if { var(txn.host) -m reg -i ^(?i)(heimdall)\.example\.com } !{ var(txn.auth_response_successful) -m bool }
|
|
|
|
|
2020-04-28 09:17:45 +00:00
|
|
|
# Authelia backend route
|
|
|
|
use_backend be_authelia if host-authelia
|
2021-03-18 08:56:08 +00:00
|
|
|
|
2020-04-28 09:17:45 +00:00
|
|
|
# Service backend route(s)
|
|
|
|
use_backend be_nextcloud if host-nextcloud
|
2021-02-23 23:35:04 +00:00
|
|
|
use_backend be_heimdall if host-heimdall
|
2020-04-28 09:17:45 +00:00
|
|
|
|
|
|
|
backend be_authelia
|
|
|
|
server authelia authelia:9091
|
|
|
|
|
|
|
|
backend be_authelia_proxy
|
|
|
|
mode http
|
|
|
|
server proxy 127.0.0.1:9092
|
|
|
|
|
|
|
|
listen authelia_proxy
|
|
|
|
mode http
|
|
|
|
bind 127.0.0.1:9092
|
|
|
|
server authelia authelia:9091 ssl verify none
|
|
|
|
|
|
|
|
backend be_nextcloud
|
2023-02-02 07:13:18 +00:00
|
|
|
## Pass the special authorization response headers to the protected application.
|
|
|
|
acl authorization_exist var(req.auth_response_header.authorization) -m found
|
|
|
|
acl proxy_authorization_exist var(req.auth_response_header.proxy_authorization) -m found
|
|
|
|
|
|
|
|
http-request set-header Authorization %[var(req.auth_response_header.authorization)] if authorization_exist
|
|
|
|
http-request set-header Proxy-Authorization %[var(req.auth_response_header.proxy_authorization)] if proxy_authorization_exist
|
|
|
|
|
|
|
|
## Pass the special metadata response headers to the protected application.
|
2020-09-10 00:52:57 +00:00
|
|
|
acl remote_user_exist var(req.auth_response_header.remote_user) -m found
|
|
|
|
acl remote_groups_exist var(req.auth_response_header.remote_groups) -m found
|
2020-10-26 11:38:08 +00:00
|
|
|
acl remote_name_exist var(req.auth_response_header.remote_name) -m found
|
|
|
|
acl remote_email_exist var(req.auth_response_header.remote_email) -m found
|
2023-02-02 07:13:18 +00:00
|
|
|
|
2020-09-10 00:52:57 +00:00
|
|
|
http-request set-header Remote-User %[var(req.auth_response_header.remote_user)] if remote_user_exist
|
|
|
|
http-request set-header Remote-Groups %[var(req.auth_response_header.remote_groups)] if remote_groups_exist
|
2020-10-26 11:38:08 +00:00
|
|
|
http-request set-header Remote-Name %[var(req.auth_response_header.remote_name)] if remote_name_exist
|
|
|
|
http-request set-header Remote-Email %[var(req.auth_response_header.remote_email)] if remote_email_exist
|
2020-09-10 00:52:57 +00:00
|
|
|
|
2023-02-02 07:13:18 +00:00
|
|
|
## Pass the Set-Cookie response headers to the user.
|
|
|
|
acl set_cookie_exist var(req.auth_response_header.set_cookie) -m found
|
|
|
|
http-response set-header Set-Cookie %[var(req.auth_response_header.set_cookie)] if set_cookie_exist
|
|
|
|
|
2020-04-28 09:17:45 +00:00
|
|
|
server nextcloud nextcloud:443 ssl verify none
|
2021-02-23 23:35:04 +00:00
|
|
|
|
|
|
|
backend be_heimdall
|
2023-02-02 07:13:18 +00:00
|
|
|
## Pass the special authorization response headers to the protected application.
|
|
|
|
acl authorization_exist var(req.auth_response_header.authorization) -m found
|
|
|
|
acl proxy_authorization_exist var(req.auth_response_header.proxy_authorization) -m found
|
|
|
|
|
|
|
|
http-request set-header Authorization %[var(req.auth_response_header.authorization)] if authorization_exist
|
|
|
|
http-request set-header Proxy-Authorization %[var(req.auth_response_header.proxy_authorization)] if proxy_authorization_exist
|
|
|
|
|
|
|
|
## Pass the special metadata response headers to the protected application.
|
2021-02-23 23:35:04 +00:00
|
|
|
acl remote_user_exist var(req.auth_response_header.remote_user) -m found
|
|
|
|
acl remote_groups_exist var(req.auth_response_header.remote_groups) -m found
|
|
|
|
acl remote_name_exist var(req.auth_response_header.remote_name) -m found
|
|
|
|
acl remote_email_exist var(req.auth_response_header.remote_email) -m found
|
2023-02-02 07:13:18 +00:00
|
|
|
|
2021-02-23 23:35:04 +00:00
|
|
|
http-request set-header Remote-User %[var(req.auth_response_header.remote_user)] if remote_user_exist
|
|
|
|
http-request set-header Remote-Groups %[var(req.auth_response_header.remote_groups)] if remote_groups_exist
|
|
|
|
http-request set-header Remote-Name %[var(req.auth_response_header.remote_name)] if remote_name_exist
|
|
|
|
http-request set-header Remote-Email %[var(req.auth_response_header.remote_email)] if remote_email_exist
|
|
|
|
|
2023-02-02 07:13:18 +00:00
|
|
|
## Pass the Set-Cookie response headers to the user.
|
|
|
|
acl set_cookie_exist var(req.auth_response_header.set_cookie) -m found
|
|
|
|
http-response set-header Set-Cookie %[var(req.auth_response_header.set_cookie)] if set_cookie_exist
|
|
|
|
|
2021-02-23 23:35:04 +00:00
|
|
|
server heimdall heimdall:443 ssl verify none
|
2020-04-28 09:17:45 +00:00
|
|
|
```
|
|
|
|
|
2022-06-15 07:51:47 +00:00
|
|
|
## See Also
|
|
|
|
|
|
|
|
* [HAProxy Auth Request lua plugin Documentation](https://github.com/TimWolla/haproxy-auth-request)
|
|
|
|
* [Forwarded Headers]
|
|
|
|
|
2020-04-28 09:17:45 +00:00
|
|
|
[HAproxy]: https://www.haproxy.org/
|
2022-06-15 07:51:47 +00:00
|
|
|
[Forwarded Headers]: fowarded-headers
|