diff --git a/README.md b/README.md index e296739..2a87d04 100755 --- a/README.md +++ b/README.md @@ -335,7 +335,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64 ## Versions -* **01.02.23:** - Add includable confs for authentik. +* **05.02.23:** - [Existing users should update:](https://github.com/linuxserver/docker-swag/blob/master/README.md#updating-configs) proxy.conf - Add includable confs for authentik * **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 bcc2f5d..1a629a3 100755 --- a/readme-vars.yml +++ b/readme-vars.yml @@ -154,7 +154,7 @@ app_setup_block: | # changelog changelogs: - - { date: "01.02.23:", desc: "Add includable confs for authentik" } + - { date: "05.02.23:", desc: "[Existing users should update:](https://github.com/linuxserver/docker-swag/blob/master/README.md#updating-configs) proxy.conf - Add includable confs for authentik" } - { 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/authentik-location.conf b/root/defaults/nginx/authentik-location.conf.sample similarity index 53% rename from root/defaults/nginx/authentik-location.conf rename to root/defaults/nginx/authentik-location.conf.sample index 06d8c11..1322314 100644 --- a/root/defaults/nginx/authentik-location.conf +++ b/root/defaults/nginx/authentik-location.conf.sample @@ -1,23 +1,22 @@ -## Version 2022/08/20 +## Version 2023/02/05 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/authentik-location.conf.sample # Make sure that your authentik container is in the same user defined bridge network and is named authentik-server -############################## -# authentik-specific config -############################## -auth_request /outpost.goauthentik.io/auth/nginx; -error_page 401 = @goauthentik_proxy_signin; -auth_request_set $auth_cookie $upstream_http_set_cookie; -add_header Set-Cookie $auth_cookie; +## Send a subrequest to Authentik to verify if the user is authenticated and has permission to access the resource. +auth_request /outpost.goauthentik.io/auth/nginx; -# translate headers from the outposts back to the actual upstream +## Save the upstream metadata response headers from Authentik to variables. auth_request_set $authentik_username $upstream_http_x_authentik_username; auth_request_set $authentik_groups $upstream_http_x_authentik_groups; auth_request_set $authentik_email $upstream_http_x_authentik_email; auth_request_set $authentik_name $upstream_http_x_authentik_name; auth_request_set $authentik_uid $upstream_http_x_authentik_uid; +## Inject the metadata response headers from the variables into the request made to the backend. proxy_set_header X-authentik-username $authentik_username; proxy_set_header X-authentik-groups $authentik_groups; proxy_set_header X-authentik-email $authentik_email; proxy_set_header X-authentik-name $authentik_name; proxy_set_header X-authentik-uid $authentik_uid; + +## If the subreqest returns 200 pass to the backend, if the subrequest returns 401 redirect to the portal. +error_page 401 = @authentik_auth_request; diff --git a/root/defaults/nginx/authentik-server.conf b/root/defaults/nginx/authentik-server.conf deleted file mode 100644 index 047308c..0000000 --- a/root/defaults/nginx/authentik-server.conf +++ /dev/null @@ -1,27 +0,0 @@ -## Version 2022/09/22 -# Make sure that your authentik container is in the same user defined bridge network and is named authentik-server - - # all requests to /outpost.goauthentik.io must be accessible without authentication - location /outpost.goauthentik.io { - include /config/nginx/resolver.conf; - set $upstream_authentik authentik-server; - proxy_pass http://$upstream_authentik:9000/outpost.goauthentik.io; - # ensure the host of this vserver matches your external URL you've configured - # in authentik - proxy_set_header Host $host; - proxy_set_header X-Original-URL $scheme://$http_host$request_uri; - add_header Set-Cookie $auth_cookie; - auth_request_set $auth_cookie $upstream_http_set_cookie; - proxy_pass_request_body off; - proxy_set_header Content-Length ""; - } - - # Special location for when the /auth endpoint returns a 401, - # redirect to the /start URL which initiates SSO - location @goauthentik_proxy_signin { - internal; - add_header Set-Cookie $auth_cookie; - return 302 /outpost.goauthentik.io/start?rd=$request_uri; - # For domain level, use the below error_page to redirect to your authentik server with the full redirect path - # return 302 https://authentik.company/outpost.goauthentik.io/start?rd=$scheme://$http_host$request_uri; - } diff --git a/root/defaults/nginx/authentik-server.conf.sample b/root/defaults/nginx/authentik-server.conf.sample new file mode 100644 index 0000000..4bdb965 --- /dev/null +++ b/root/defaults/nginx/authentik-server.conf.sample @@ -0,0 +1,45 @@ +## Version 2023/02/05 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/authentik-server.conf.sample +# Make sure that your authentik container is in the same user defined bridge network and is named authentik-server + +# location for authentik auth requests +location /outpost.goauthentik.io { + include /config/nginx/proxy.conf; + include /config/nginx/resolver.conf; + set $upstream_authentik authentik-server; + proxy_pass http://$upstream_authentik:9000/outpost.goauthentik.io; + + ## Headers + proxy_set_header Content-Length ""; + + ## Basic Proxy Configuration + proxy_pass_request_body off; + client_body_buffer_size 128k; + + ## Advanced Proxy Configuration + send_timeout 5m; +} + +# Virtual location for authentik 401 redirects +location @authentik_401_redirect { + 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 $authentik_backend to route requests to the current domain by default + set $authentik_backend $http_host; + ## In order for Webauthn to work with multiple domains authentik must operate on a separate subdomain + ## To use authentik on a separate subdomain: + ## * comment the $authentik_backend line above + ## * rename /config/nginx/proxy-confs/authentik.conf.sample to /config/nginx/proxy-confs/authentik.conf + ## * make sure that your dns has a cname set for authentik + ## * uncomment the $authentik_backend line below and change example.com to your domain + ## * restart the swag container + #set $authentik_backend authentik.example.com; + + return 302 https://$authentik_backend/authentik/?rd=$target_url; +} diff --git a/root/defaults/nginx/proxy.conf.sample b/root/defaults/nginx/proxy.conf.sample index c5a7210..ec61d9f 100644 --- a/root/defaults/nginx/proxy.conf.sample +++ b/root/defaults/nginx/proxy.conf.sample @@ -1,4 +1,4 @@ -## Version 2022/09/01 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/proxy.conf.sample +## Version 2023/02/05 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/proxy.conf.sample # Timeout if the real server is dead proxy_next_upstream error timeout invalid_header http_500 http_502 http_503; @@ -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; 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..5ba2b21 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 @@ -14,6 +14,14 @@ if [[ ! -f /config/nginx/authelia-server.conf ]]; then cp /defaults/nginx/authelia-server.conf.sample /config/nginx/authelia-server.conf fi +# copy authentik config files if they don't exist +if [[ ! -f /config/nginx/authentik-location.conf ]]; then + cp /defaults/nginx/authentik-location.conf.sample /config/nginx/authentik-location.conf +fi +if [[ ! -f /config/nginx/authentik-server.conf ]]; then + cp /defaults/nginx/authentik-server.conf.sample /config/nginx/authentik-server.conf +fi + # copy old ldap config file to new location if [[ -f /config/nginx/ldap.conf ]] && [[ ! -f /config/nginx/ldap-server.conf ]]; then cp /config/nginx/ldap.conf /config/nginx/ldap-server.conf