From 5e47b024966192bc840b5e4a8a6b54e12082a676 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Wed, 1 Feb 2023 11:50:56 -0600 Subject: [PATCH 1/5] Update Authelia configs and include site-confs sample for Authelia --- README.md | 1 + readme-vars.yml | 1 + .../nginx/authelia-location.conf.sample | 26 ++++++++++++-- .../nginx/authelia-server.conf.sample | 36 +++++++++---------- .../nginx/site-confs/authelia.conf.sample | 32 +++++++++++++++++ .../s6-overlay/s6-rc.d/init-nginx-config/run | 3 ++ 6 files changed, 77 insertions(+), 22 deletions(-) create mode 100644 root/defaults/nginx/site-confs/authelia.conf.sample diff --git a/README.md b/README.md index 1c74f79..9b615eb 100755 --- a/README.md +++ b/README.md @@ -335,6 +335,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64 ## Versions +* **01.02.23:** - [Existing users should update:](https://github.com/linuxserver/docker-swag/blob/master/README.md#updating-configs) authelia-location.conf and authelia-server.conf - Update Authelia configs and include site-confs sample for Authelia. * **21.01.23:** - Unpin certbot version (allow certbot 2.x). !!BREAKING CHANGE!! We are temporarily removing the certbot porkbun plugin until a new version is released that is compatible with certbot 2.x. * **20.01.23:** - Rebase to alpine 3.17 with php8.1. * **16.01.23:** - Remove nchan module because it keeps causing crashes. diff --git a/readme-vars.yml b/readme-vars.yml index 040a324..9fad95c 100755 --- a/readme-vars.yml +++ b/readme-vars.yml @@ -154,6 +154,7 @@ app_setup_block: | # changelog changelogs: + - { date: "01.02.23:", desc: "[Existing users should update:](https://github.com/linuxserver/docker-swag/blob/master/README.md#updating-configs) authelia-location.conf and authelia-server.conf - Update Authelia configs and include site-confs sample for Authelia." } - { date: "21.01.23:", desc: "Unpin certbot version (allow certbot 2.x). !!BREAKING CHANGE!! We are temporarily removing the certbot porkbun plugin until a new version is released that is compatible with certbot 2.x." } - { date: "20.01.23:", desc: "Rebase to alpine 3.17 with php8.1." } - { date: "16.01.23:", desc: "Remove nchan module because it keeps causing crashes." } diff --git a/root/defaults/nginx/authelia-location.conf.sample b/root/defaults/nginx/authelia-location.conf.sample index b7e37ae..5331a9c 100644 --- a/root/defaults/nginx/authelia-location.conf.sample +++ b/root/defaults/nginx/authelia-location.conf.sample @@ -1,15 +1,35 @@ -## Version 2022/08/20 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/authelia-location.conf.sample +## Version 2023/02/01 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/authelia-location.conf.sample # Make sure that your authelia container is in the same user defined bridge network and is named authelia # Make sure that the authelia configuration.yml has 'path: "authelia"' defined +## Send a subrequest to Authelia to verify if the user is authenticated and has permission to access the resource. auth_request /authelia/api/verify; -auth_request_set $target_url $scheme://$http_host$request_uri; + +## Set the $target_url variable based on the original request. +set_escape_uri $target_url $scheme://$http_host$request_uri; + +## Save the upstream response headers from Authelia to variables. auth_request_set $user $upstream_http_remote_user; auth_request_set $groups $upstream_http_remote_groups; auth_request_set $name $upstream_http_remote_name; auth_request_set $email $upstream_http_remote_email; + +## Inject the response headers from the variables into the request made to the backend. proxy_set_header Remote-User $user; proxy_set_header Remote-Groups $groups; proxy_set_header Remote-Name $name; proxy_set_header Remote-Email $email; -error_page 401 =302 https://$http_host/authelia/?rd=$target_url; + +## Set $authelia_backend to route requests to the current domain by default +set $authelia_backend $http_host; +## In order for Webauthn to work with multiple subdomains Authelia must operate on a separate subdomain +## To use Authelia on a separate subdomain: +## * comment the $authelia_backend line above +## * rename /config/nginx/site-conf/authelia.conf.sample to /config/nginx/site-conf/authelia.conf +## * make sure that your dns has a cname set for authelia +## * uncomment the $authelia_backend line below and change example.com to your domain +## * restart the swag container +#set $authelia_backend authelia.example.com; + +## If the subreqest returns 200 pass to the backend, if the subrequest returns 401 redirect to the portal. +error_page 401 =302 https://$authelia_backend/authelia/?rd=$target_url; diff --git a/root/defaults/nginx/authelia-server.conf.sample b/root/defaults/nginx/authelia-server.conf.sample index dfb34f3..2cb68e1 100644 --- a/root/defaults/nginx/authelia-server.conf.sample +++ b/root/defaults/nginx/authelia-server.conf.sample @@ -1,6 +1,8 @@ -## Version 2022/09/22 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/authelia-server.conf.sample +## Version 2023/02/01 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/authelia-server.conf.sample # Make sure that your authelia container is in the same user defined bridge network and is named authelia +# Make sure that the authelia configuration.yml has 'path: "authelia"' defined +## Virtual endpoints created by nginx to forward auth requests. location ^~ /authelia { include /config/nginx/proxy.conf; include /config/nginx/resolver.conf; @@ -9,40 +11,36 @@ location ^~ /authelia { } location = /authelia/api/verify { + ## Essential Proxy Configuration internal; include /config/nginx/resolver.conf; set $upstream_authelia authelia; - proxy_pass_request_body off; proxy_pass http://$upstream_authelia:9091; - proxy_set_header Content-Length ""; - # Timeout if the real server is dead - proxy_next_upstream error timeout invalid_header http_500 http_502 http_503; - - # [REQUIRED] Needed by Authelia to check authorizations of the resource. - # Provide either X-Original-URL and X-Forwarded-Proto or - # X-Forwarded-Proto, X-Forwarded-Host and X-Forwarded-Uri or both. - # Those headers will be used by Authelia to deduce the target url of the user. - # Basic Proxy Config - client_body_buffer_size 128k; - proxy_set_header Host $host; + ## Headers + ## The headers starting with X-* are required. proxy_set_header X-Original-URL $scheme://$http_host$request_uri; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Original-Method $request_method; proxy_set_header X-Forwarded-Method $request_method; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header X-Forwarded-Uri $request_uri; - proxy_set_header X-Forwarded-Ssl on; - proxy_redirect http:// $scheme://; - proxy_http_version 1.1; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header Content-Length ""; proxy_set_header Connection ""; + + ## Basic Proxy Configuration + proxy_pass_request_body off; + proxy_next_upstream error timeout invalid_header http_500 http_502 http_503; # Timeout if the real server is dead + proxy_redirect http:// $scheme://; + proxy_http_version 1.1; proxy_cache_bypass $cookie_session; proxy_no_cache $cookie_session; proxy_buffers 4 32k; + client_body_buffer_size 128k; - # Advanced Proxy Config + ## Advanced Proxy Configuration send_timeout 5m; proxy_read_timeout 240; proxy_send_timeout 240; diff --git a/root/defaults/nginx/site-confs/authelia.conf.sample b/root/defaults/nginx/site-confs/authelia.conf.sample new file mode 100644 index 0000000..6300b1c --- /dev/null +++ b/root/defaults/nginx/site-confs/authelia.conf.sample @@ -0,0 +1,32 @@ +## Version 2023/02/01 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/site-confs/authelia.conf.sample +# make sure that your dns has a cname set for authelia + +server { + listen 443 ssl; + listen [::]:443 ssl; + + server_name authelia.*; + + include /config/nginx/ssl.conf; + + client_max_body_size 0; + + location / { + include /config/nginx/proxy.conf; + include /config/nginx/resolver.conf; + set $upstream_app authelia; + set $upstream_port 9091; + set $upstream_proto http; + proxy_pass $upstream_proto://$upstream_app:$upstream_port; + + } + + location ~ (/authelia)?/api/verify { + include /config/nginx/resolver.conf; + set $upstream_app authelia; + set $upstream_port 9091; + set $upstream_proto http; + proxy_pass $upstream_proto://$upstream_app:$upstream_port; + + } +} diff --git a/root/etc/s6-overlay/s6-rc.d/init-nginx-config/run b/root/etc/s6-overlay/s6-rc.d/init-nginx-config/run index e94c92a..c265930 100755 --- a/root/etc/s6-overlay/s6-rc.d/init-nginx-config/run +++ b/root/etc/s6-overlay/s6-rc.d/init-nginx-config/run @@ -13,6 +13,9 @@ fi if [[ ! -f /config/nginx/authelia-server.conf ]]; then cp /defaults/nginx/authelia-server.conf.sample /config/nginx/authelia-server.conf fi +if [[ ! -f /config/nginx/site-confs/authelia.conf ]]; then + cp /defaults/nginx/site-confs/authelia.conf.sample /config/nginx/site-confs/authelia.conf +fi # copy old ldap config file to new location if [[ -f /config/nginx/ldap.conf ]] && [[ ! -f /config/nginx/ldap-server.conf ]]; then From 777fa62481f04c4d9fc9868d7e4b8839d6473509 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Wed, 1 Feb 2023 19:35:23 -0600 Subject: [PATCH 2/5] Add new headers --- .../defaults/nginx/authelia-location.conf.sample | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/root/defaults/nginx/authelia-location.conf.sample b/root/defaults/nginx/authelia-location.conf.sample index 5331a9c..566d1b2 100644 --- a/root/defaults/nginx/authelia-location.conf.sample +++ b/root/defaults/nginx/authelia-location.conf.sample @@ -8,18 +8,30 @@ auth_request /authelia/api/verify; ## Set the $target_url variable based on the original request. set_escape_uri $target_url $scheme://$http_host$request_uri; -## Save the upstream response headers from Authelia to variables. +## Save the upstream authorization response headers from Authelia to variables. +auth_request_set $authorization $upstream_http_authorization; +auth_request_set $proxy_authorization $upstream_http_proxy_authorization; + +## Inject the authorization response headers from the variables into the request made to the backend. +proxy_set_header Authorization $authorization; +proxy_set_header Proxy-Authorization $proxy_authorization; + +## Save the upstream metadata response headers from Authelia to variables. auth_request_set $user $upstream_http_remote_user; auth_request_set $groups $upstream_http_remote_groups; auth_request_set $name $upstream_http_remote_name; auth_request_set $email $upstream_http_remote_email; -## Inject the response headers from the variables into the request made to the backend. +## Inject the metadata response headers from the variables into the request made to the backend. proxy_set_header Remote-User $user; proxy_set_header Remote-Groups $groups; proxy_set_header Remote-Name $name; proxy_set_header Remote-Email $email; +## Include the Set-Cookie header if present. +auth_request_set $set_cookie $upstream_http_set_cookie; +add_header Set-Cookie $set_cookie; + ## Set $authelia_backend to route requests to the current domain by default set $authelia_backend $http_host; ## In order for Webauthn to work with multiple subdomains Authelia must operate on a separate subdomain From db4e66112643a5a13e3b5514754417934dab365c Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Fri, 3 Feb 2023 09:14:53 -0600 Subject: [PATCH 3/5] Update authelia-location.conf.sample --- root/defaults/nginx/authelia-location.conf.sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/defaults/nginx/authelia-location.conf.sample b/root/defaults/nginx/authelia-location.conf.sample index 566d1b2..ddd7e0c 100644 --- a/root/defaults/nginx/authelia-location.conf.sample +++ b/root/defaults/nginx/authelia-location.conf.sample @@ -34,7 +34,7 @@ add_header Set-Cookie $set_cookie; ## Set $authelia_backend to route requests to the current domain by default set $authelia_backend $http_host; -## In order for Webauthn to work with multiple subdomains Authelia must operate on a separate subdomain +## In order for Webauthn to work with multiple domains Authelia must operate on a separate subdomain ## To use Authelia on a separate subdomain: ## * comment the $authelia_backend line above ## * rename /config/nginx/site-conf/authelia.conf.sample to /config/nginx/site-conf/authelia.conf From 0d92109b684368a5d1021b041b477c1879cc159a Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Sun, 5 Feb 2023 16:45:56 -0600 Subject: [PATCH 4/5] Unify auth config approach --- .../nginx/authelia-location.conf.sample | 21 ++------ .../nginx/authelia-server.conf.sample | 52 +++++++++++-------- root/defaults/nginx/proxy.conf.sample | 1 + 3 files changed, 34 insertions(+), 40 deletions(-) diff --git a/root/defaults/nginx/authelia-location.conf.sample b/root/defaults/nginx/authelia-location.conf.sample index ddd7e0c..e7e07eb 100644 --- a/root/defaults/nginx/authelia-location.conf.sample +++ b/root/defaults/nginx/authelia-location.conf.sample @@ -1,12 +1,11 @@ -## Version 2023/02/01 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/authelia-location.conf.sample +## Version 2023/02/05 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/authelia-location.conf.sample # Make sure that your authelia container is in the same user defined bridge network and is named authelia # Make sure that the authelia configuration.yml has 'path: "authelia"' defined ## Send a subrequest to Authelia to verify if the user is authenticated and has permission to access the resource. auth_request /authelia/api/verify; - -## Set the $target_url variable based on the original request. -set_escape_uri $target_url $scheme://$http_host$request_uri; +## If the subreqest returns 200 pass to the backend, if the subrequest returns 401 redirect to the portal. +error_page 401 = @authelia_proxy_signin; ## Save the upstream authorization response headers from Authelia to variables. auth_request_set $authorization $upstream_http_authorization; @@ -31,17 +30,3 @@ proxy_set_header Remote-Email $email; ## Include the Set-Cookie header if present. auth_request_set $set_cookie $upstream_http_set_cookie; add_header Set-Cookie $set_cookie; - -## Set $authelia_backend to route requests to the current domain by default -set $authelia_backend $http_host; -## In order for Webauthn to work with multiple domains Authelia must operate on a separate subdomain -## To use Authelia on a separate subdomain: -## * comment the $authelia_backend line above -## * rename /config/nginx/site-conf/authelia.conf.sample to /config/nginx/site-conf/authelia.conf -## * make sure that your dns has a cname set for authelia -## * uncomment the $authelia_backend line below and change example.com to your domain -## * restart the swag container -#set $authelia_backend authelia.example.com; - -## If the subreqest returns 200 pass to the backend, if the subrequest returns 401 redirect to the portal. -error_page 401 =302 https://$authelia_backend/authelia/?rd=$target_url; diff --git a/root/defaults/nginx/authelia-server.conf.sample b/root/defaults/nginx/authelia-server.conf.sample index 2cb68e1..b744419 100644 --- a/root/defaults/nginx/authelia-server.conf.sample +++ b/root/defaults/nginx/authelia-server.conf.sample @@ -1,8 +1,8 @@ -## Version 2023/02/01 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/authelia-server.conf.sample +## Version 2023/02/05 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/authelia-server.conf.sample # Make sure that your authelia container is in the same user defined bridge network and is named authelia # Make sure that the authelia configuration.yml has 'path: "authelia"' defined -## Virtual endpoints created by nginx to forward auth requests. +# location for authelia subfolder requests location ^~ /authelia { include /config/nginx/proxy.conf; include /config/nginx/resolver.conf; @@ -10,39 +10,47 @@ location ^~ /authelia { proxy_pass http://$upstream_authelia:9091; } +# location for authelia auth requests location = /authelia/api/verify { - ## Essential Proxy Configuration internal; + include /config/nginx/proxy.conf; include /config/nginx/resolver.conf; set $upstream_authelia authelia; - proxy_pass http://$upstream_authelia:9091; + proxy_pass http://$upstream_authelia:9091/authelia/api/verify; ## Headers - ## The headers starting with X-* are required. - proxy_set_header X-Original-URL $scheme://$http_host$request_uri; - proxy_set_header X-Original-Method $request_method; - proxy_set_header X-Forwarded-Method $request_method; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_set_header X-Forwarded-Host $http_host; - proxy_set_header X-Forwarded-Uri $request_uri; - proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Content-Length ""; - proxy_set_header Connection ""; ## Basic Proxy Configuration proxy_pass_request_body off; - proxy_next_upstream error timeout invalid_header http_500 http_502 http_503; # Timeout if the real server is dead - proxy_redirect http:// $scheme://; - proxy_http_version 1.1; - proxy_cache_bypass $cookie_session; - proxy_no_cache $cookie_session; - proxy_buffers 4 32k; client_body_buffer_size 128k; ## Advanced Proxy Configuration send_timeout 5m; - proxy_read_timeout 240; - proxy_send_timeout 240; - proxy_connect_timeout 240; +} + +# Virtual location for authelia 401 redirects +location @authelia_proxy_signin { + internal; + + ## Set the $target_url variable based on the original request. + set_escape_uri $target_url $scheme://$http_host$request_uri; + + ## Include the Set-Cookie header if present. + auth_request_set $set_cookie $upstream_http_set_cookie; + add_header Set-Cookie $set_cookie; + + ## Set $authelia_backend to route requests to the current domain by default + set $authelia_backend $http_host; + ## In order for Webauthn to work with multiple domains authelia must operate on a separate subdomain + ## To use authelia on a separate subdomain: + ## * comment the $authelia_backend line above + ## * rename /config/nginx/proxy-confs/authelia.conf.sample to /config/nginx/proxy-confs/authelia.conf + ## * make sure that your dns has a cname set for authelia + ## * uncomment the $authelia_backend line below and change example.com to your domain + ## * restart the swag container + #set $authelia_backend authelia.example.com; + + return 302 https://$authelia_backend/authelia/?rd=$target_url; } diff --git a/root/defaults/nginx/proxy.conf.sample b/root/defaults/nginx/proxy.conf.sample index c5a7210..8d6d6e5 100644 --- a/root/defaults/nginx/proxy.conf.sample +++ b/root/defaults/nginx/proxy.conf.sample @@ -31,5 +31,6 @@ proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-Ssl on; proxy_set_header X-Forwarded-Uri $request_uri; +proxy_set_header X-Original-Method $request_method; proxy_set_header X-Original-URL $scheme://$http_host$request_uri; proxy_set_header X-Real-IP $remote_addr; From 9e7ef6154d6e0332c8ff84c59a85ed55cb8f7d19 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Sun, 5 Feb 2023 17:14:34 -0600 Subject: [PATCH 5/5] Remove authelia site-conf A proxy-conf is already included --- .../nginx/site-confs/authelia.conf.sample | 32 ------------------- .../s6-overlay/s6-rc.d/init-nginx-config/run | 3 -- 2 files changed, 35 deletions(-) delete mode 100644 root/defaults/nginx/site-confs/authelia.conf.sample diff --git a/root/defaults/nginx/site-confs/authelia.conf.sample b/root/defaults/nginx/site-confs/authelia.conf.sample deleted file mode 100644 index 6300b1c..0000000 --- a/root/defaults/nginx/site-confs/authelia.conf.sample +++ /dev/null @@ -1,32 +0,0 @@ -## Version 2023/02/01 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/site-confs/authelia.conf.sample -# make sure that your dns has a cname set for authelia - -server { - listen 443 ssl; - listen [::]:443 ssl; - - server_name authelia.*; - - include /config/nginx/ssl.conf; - - client_max_body_size 0; - - location / { - include /config/nginx/proxy.conf; - include /config/nginx/resolver.conf; - set $upstream_app authelia; - set $upstream_port 9091; - set $upstream_proto http; - proxy_pass $upstream_proto://$upstream_app:$upstream_port; - - } - - location ~ (/authelia)?/api/verify { - include /config/nginx/resolver.conf; - set $upstream_app authelia; - set $upstream_port 9091; - set $upstream_proto http; - proxy_pass $upstream_proto://$upstream_app:$upstream_port; - - } -} diff --git a/root/etc/s6-overlay/s6-rc.d/init-nginx-config/run b/root/etc/s6-overlay/s6-rc.d/init-nginx-config/run index c265930..e94c92a 100755 --- a/root/etc/s6-overlay/s6-rc.d/init-nginx-config/run +++ b/root/etc/s6-overlay/s6-rc.d/init-nginx-config/run @@ -13,9 +13,6 @@ fi if [[ ! -f /config/nginx/authelia-server.conf ]]; then cp /defaults/nginx/authelia-server.conf.sample /config/nginx/authelia-server.conf fi -if [[ ! -f /config/nginx/site-confs/authelia.conf ]]; then - cp /defaults/nginx/site-confs/authelia.conf.sample /config/nginx/site-confs/authelia.conf -fi # copy old ldap config file to new location if [[ -f /config/nginx/ldap.conf ]] && [[ ! -f /config/nginx/ldap-server.conf ]]; then