Skip to content

Commit

Permalink
web: only load version context when authenticated (goauthentik#12482)
Browse files Browse the repository at this point in the history
* only add version context for authz interface

Signed-off-by: Jens Langhammer <[email protected]>

* rename enterprise aware interface

Signed-off-by: Jens Langhammer <[email protected]>

* dont log startup error

Signed-off-by: Jens Langhammer <[email protected]>

---------

Signed-off-by: Jens Langhammer <[email protected]>
  • Loading branch information
BeryJu authored Dec 25, 2024
1 parent 9589063 commit ffd5234
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 26 deletions.
10 changes: 8 additions & 2 deletions internal/web/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"goauthentik.io/internal/utils/sentry"
)

var (
ErrAuthentikStarting = errors.New("authentik starting")
)

func (ws *WebServer) configureProxy() {
// Reverse proxy to the application server
director := func(req *http.Request) {
Expand All @@ -38,7 +42,7 @@ func (ws *WebServer) configureProxy() {
}))
ws.mainRouter.PathPrefix(config.Get().Web.Path).HandlerFunc(sentry.SentryNoSample(func(rw http.ResponseWriter, r *http.Request) {
if !ws.g.IsRunning() {
ws.proxyErrorHandler(rw, r, errors.New("authentik starting"))
ws.proxyErrorHandler(rw, r, ErrAuthentikStarting)
return
}
before := time.Now()
Expand All @@ -59,7 +63,9 @@ func (ws *WebServer) configureProxy() {
}

func (ws *WebServer) proxyErrorHandler(rw http.ResponseWriter, req *http.Request, err error) {
ws.log.WithError(err).Warning("failed to proxy to backend")
if !errors.Is(err, ErrAuthentikStarting) {
ws.log.WithError(err).Warning("failed to proxy to backend")
}
rw.WriteHeader(http.StatusBadGateway)
em := fmt.Sprintf("failed to connect to authentik backend: %v", err)
// return json if the client asks for json
Expand Down
9 changes: 3 additions & 6 deletions web/src/admin/AdminInterface/AdminInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { configureSentry } from "@goauthentik/common/sentry";
import { me } from "@goauthentik/common/users";
import { WebsocketClient } from "@goauthentik/common/ws";
import { EnterpriseAwareInterface } from "@goauthentik/elements/Interface";
import { AuthenticatedInterface } from "@goauthentik/elements/Interface";
import "@goauthentik/elements/ak-locale-context";
import "@goauthentik/elements/enterprise/EnterpriseStatusBanner";
import "@goauthentik/elements/messages/MessageContainer";
Expand All @@ -29,12 +29,12 @@ import PFDrawer from "@patternfly/patternfly/components/Drawer/drawer.css";
import PFPage from "@patternfly/patternfly/components/Page/page.css";
import PFBase from "@patternfly/patternfly/patternfly-base.css";

import { SessionUser, UiThemeEnum, Version } from "@goauthentik/api";
import { SessionUser, UiThemeEnum } from "@goauthentik/api";

import "./AdminSidebar";

@customElement("ak-interface-admin")
export class AdminInterface extends EnterpriseAwareInterface {
export class AdminInterface extends AuthenticatedInterface {
@property({ type: Boolean })
notificationDrawerOpen = getURLParam("notificationDrawerOpen", false);

Expand All @@ -43,9 +43,6 @@ export class AdminInterface extends EnterpriseAwareInterface {

ws: WebsocketClient;

@state()
version?: Version;

@state()
user?: SessionUser;

Expand Down
6 changes: 3 additions & 3 deletions web/src/elements/Interface/EnterpriseContextController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import type { ReactiveController } from "lit";
import type { LicenseSummary } from "@goauthentik/api";
import { EnterpriseApi } from "@goauthentik/api";

import type { AkEnterpriseInterface } from "./Interface";
import type { AkAuthenticatedInterface } from "./Interface";

export class EnterpriseContextController implements ReactiveController {
host!: ReactiveElementHost<AkEnterpriseInterface>;
host!: ReactiveElementHost<AkAuthenticatedInterface>;

context!: ContextProvider<{ __context__: LicenseSummary | undefined }>;

constructor(host: ReactiveElementHost<AkEnterpriseInterface>) {
constructor(host: ReactiveElementHost<AkAuthenticatedInterface>) {
this.host = host;
this.context = new ContextProvider(this.host, {
context: authentikEnterpriseContext,
Expand Down
22 changes: 14 additions & 8 deletions web/src/elements/Interface/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export type AkInterface = HTMLElement & {
brand?: CurrentBrand;
uiConfig?: UIConfig;
config?: Config;
version?: Version;
};

const brandContext = Symbol("brandContext");
Expand All @@ -29,16 +28,14 @@ const modalController = Symbol("modalController");
const versionContext = Symbol("versionContext");

export class Interface extends AKElement implements AkInterface {
@state()
uiConfig?: UIConfig;

[brandContext]!: BrandContextController;

[configContext]!: ConfigContextController;

[modalController]!: ModalOrchestrationController;

[versionContext]!: VersionContextController;
@state()
uiConfig?: UIConfig;

@state()
config?: Config;
Expand All @@ -57,7 +54,6 @@ export class Interface extends AKElement implements AkInterface {
this[brandContext] = new BrandContextController(this);
this[configContext] = new ConfigContextController(this);
this[modalController] = new ModalOrchestrationController(this);
this[versionContext] = new VersionContextController(this);
}

_activateTheme(theme: UiThemeEnum, ...roots: DocumentOrShadowRoot[]): void {
Expand All @@ -83,20 +79,30 @@ export class Interface extends AKElement implements AkInterface {
}
}

export type AkEnterpriseInterface = AkInterface & {
export type AkAuthenticatedInterface = AkInterface & {
licenseSummary?: LicenseSummary;
version?: Version;
};

const enterpriseContext = Symbol("enterpriseContext");

export class EnterpriseAwareInterface extends Interface {
export class AuthenticatedInterface extends Interface {
[enterpriseContext]!: EnterpriseContextController;
[versionContext]!: VersionContextController;

@state()
licenseSummary?: LicenseSummary;

@state()
version?: Version;

constructor() {
super();
}

_initContexts(): void {
super._initContexts();
this[enterpriseContext] = new EnterpriseContextController(this);
this[versionContext] = new VersionContextController(this);
}
}
6 changes: 3 additions & 3 deletions web/src/elements/Interface/VersionContextController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import type { ReactiveController } from "lit";
import type { Version } from "@goauthentik/api";
import { AdminApi } from "@goauthentik/api";

import type { AkInterface } from "./Interface";
import type { AkAuthenticatedInterface } from "./Interface";

export class VersionContextController implements ReactiveController {
host!: ReactiveElementHost<AkInterface>;
host!: ReactiveElementHost<AkAuthenticatedInterface>;

context!: ContextProvider<{ __context__: Version | undefined }>;

constructor(host: ReactiveElementHost<AkInterface>) {
constructor(host: ReactiveElementHost<AkAuthenticatedInterface>) {
this.host = host;
this.context = new ContextProvider(this.host, {
context: authentikVersionContext,
Expand Down
4 changes: 2 additions & 2 deletions web/src/elements/Interface/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EnterpriseAwareInterface, Interface } from "./Interface";
import { AuthenticatedInterface, Interface } from "./Interface";

export { Interface, EnterpriseAwareInterface };
export { Interface, AuthenticatedInterface };
export default Interface;
4 changes: 2 additions & 2 deletions web/src/user/UserInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { me } from "@goauthentik/common/users";
import { WebsocketClient } from "@goauthentik/common/ws";
import "@goauthentik/components/ak-nav-buttons";
import { AKElement } from "@goauthentik/elements/Base";
import { EnterpriseAwareInterface } from "@goauthentik/elements/Interface";
import { AuthenticatedInterface } from "@goauthentik/elements/Interface";
import "@goauthentik/elements/ak-locale-context";
import "@goauthentik/elements/buttons/ActionButton";
import "@goauthentik/elements/enterprise/EnterpriseStatusBanner";
Expand Down Expand Up @@ -253,7 +253,7 @@ class UserInterfacePresentation extends AKElement {
//
//
@customElement("ak-interface-user")
export class UserInterface extends EnterpriseAwareInterface {
export class UserInterface extends AuthenticatedInterface {
@property({ type: Boolean })
notificationDrawerOpen = getURLParam("notificationDrawerOpen", false);

Expand Down

0 comments on commit ffd5234

Please sign in to comment.