From 5e72ec9c0c9d826c048627180d96a3e94df7bedd Mon Sep 17 00:00:00 2001 From: "Jens L." Date: Tue, 26 Nov 2024 15:38:23 +0100 Subject: [PATCH] root: support running authentik in subpath (#8675) * initial subpath support Signed-off-by: Jens Langhammer * make outpost compatible Signed-off-by: Jens Langhammer * fix static files somewhat Signed-off-by: Jens Langhammer * fix web interface Signed-off-by: Jens Langhammer * fix most static stuff Signed-off-by: Jens Langhammer * fix most web links Signed-off-by: Jens Langhammer * fix websocket Signed-off-by: Jens Langhammer * fix URL for static files Signed-off-by: Jens Langhammer * format web Signed-off-by: Jens Langhammer * add root redirect for subpath Signed-off-by: Jens Langhammer * update docs Signed-off-by: Jens Langhammer * set cookie path Signed-off-by: Jens Langhammer * Update internal/config/struct.go Co-authored-by: Marc 'risson' Schmitt Signed-off-by: Jens L. * fix sfe Signed-off-by: Jens Langhammer * bump required version Signed-off-by: Jens Langhammer * fix flow background Signed-off-by: Jens Langhammer * fix lint and some more links Signed-off-by: Jens Langhammer * format Signed-off-by: Jens Langhammer * fix impersonate Signed-off-by: Jens Langhammer * fix Signed-off-by: Jens Langhammer --------- Signed-off-by: Jens Langhammer Signed-off-by: Jens L. Signed-off-by: Jens L. Co-authored-by: Marc 'risson' Schmitt --- authentik/brands/api.py | 4 +- authentik/brands/models.py | 13 ++++ authentik/core/templates/base/header_js.html | 3 + authentik/core/templates/base/skeleton.html | 4 +- authentik/core/templates/login/base_full.html | 6 +- authentik/core/views/interface.py | 2 + .../providers/rac/templates/if/rac.html | 4 +- authentik/flows/models.py | 9 ++- authentik/flows/templates/if/flow-sfe.html | 4 +- authentik/lib/default.yml | 1 + authentik/lib/sentry.py | 3 +- authentik/root/settings.py | 4 +- authentik/root/urls.py | 9 ++- authentik/root/websocket.py | 14 +++- cmd/server/healthcheck.go | 2 +- cmd/server/server.go | 2 +- internal/config/struct.go | 5 ++ internal/outpost/ak/api.go | 17 +++-- internal/outpost/ak/api_ws.go | 5 +- internal/web/metrics.go | 2 +- internal/web/proxy.go | 10 ++- internal/web/static.go | 72 +++++++++++++------ internal/web/web.go | 39 +++++----- web/packages/sfe/src/index.ts | 5 +- web/src/admin/AdminInterface/AdminSidebar.ts | 3 +- web/src/admin/users/UserImpersonateForm.ts | 3 +- web/src/common/api/config.ts | 2 +- web/src/common/global.ts | 6 ++ web/src/common/ws.ts | 6 +- .../enterprise/EnterpriseStatusBanner.ts | 5 +- web/src/elements/notifications/APIDrawer.ts | 5 +- .../notifications/NotificationDrawer.ts | 3 +- web/src/elements/sidebar/SidebarUser.ts | 13 +++- web/src/flow/FlowExecutor.ts | 1 + web/src/flow/FlowInspector.ts | 6 +- web/src/flow/providers/SessionEnd.ts | 5 +- web/src/user/LibraryApplication/index.ts | 4 +- .../ak-library-application-empty-list.ts | 4 +- web/src/user/UserInterface.ts | 5 +- .../details/UserSettingsFlowExecutor.ts | 6 +- .../details/stages/prompt/PromptStage.ts | 4 +- .../configuration/configuration.mdx | 10 +++ website/docs/install-config/reverse-proxy.md | 2 + 43 files changed, 236 insertions(+), 96 deletions(-) diff --git a/authentik/brands/api.py b/authentik/brands/api.py index 2f0486a688..5f730e0403 100644 --- a/authentik/brands/api.py +++ b/authentik/brands/api.py @@ -84,8 +84,8 @@ class CurrentBrandSerializer(PassiveSerializer): matched_domain = CharField(source="domain") branding_title = CharField() - branding_logo = CharField() - branding_favicon = CharField() + branding_logo = CharField(source="branding_logo_url") + branding_favicon = CharField(source="branding_favicon_url") ui_footer_links = ListField( child=FooterLinkSerializer(), read_only=True, diff --git a/authentik/brands/models.py b/authentik/brands/models.py index 3a7bc775cf..12e975b1de 100644 --- a/authentik/brands/models.py +++ b/authentik/brands/models.py @@ -10,6 +10,7 @@ from structlog.stdlib import get_logger from authentik.crypto.models import CertificateKeyPair from authentik.flows.models import Flow +from authentik.lib.config import CONFIG from authentik.lib.models import SerializerModel LOGGER = get_logger() @@ -71,6 +72,18 @@ class Brand(SerializerModel): ) attributes = models.JSONField(default=dict, blank=True) + def branding_logo_url(self) -> str: + """Get branding_logo with the correct prefix""" + if self.branding_logo.startswith("/static"): + return CONFIG.get("web.path", "/")[:-1] + self.branding_logo + return self.branding_logo + + def branding_favicon_url(self) -> str: + """Get branding_favicon with the correct prefix""" + if self.branding_favicon.startswith("/static"): + return CONFIG.get("web.path", "/")[:-1] + self.branding_favicon + return self.branding_favicon + @property def serializer(self) -> Serializer: from authentik.brands.api import BrandSerializer diff --git a/authentik/core/templates/base/header_js.html b/authentik/core/templates/base/header_js.html index 4e1b53c2fa..944bf587ed 100644 --- a/authentik/core/templates/base/header_js.html +++ b/authentik/core/templates/base/header_js.html @@ -9,6 +9,9 @@ versionFamily: "{{ version_family }}", versionSubdomain: "{{ version_subdomain }}", build: "{{ build }}", + api: { + base: "{{ base_url }}", + }, }; window.addEventListener("DOMContentLoaded", function () { {% for message in messages %} diff --git a/authentik/core/templates/base/skeleton.html b/authentik/core/templates/base/skeleton.html index 074fcc1556..e2f063b071 100644 --- a/authentik/core/templates/base/skeleton.html +++ b/authentik/core/templates/base/skeleton.html @@ -9,8 +9,8 @@ {% block title %}{% trans title|default:brand.branding_title %}{% endblock %} - - + + {% block head_before %} {% endblock %} diff --git a/authentik/core/templates/login/base_full.html b/authentik/core/templates/login/base_full.html index 483bae7245..cbab6c2ed5 100644 --- a/authentik/core/templates/login/base_full.html +++ b/authentik/core/templates/login/base_full.html @@ -4,7 +4,7 @@ {% load i18n %} {% block head_before %} - + {% include "base/header_js.html" %} @@ -13,7 +13,7 @@ {% block head %}