From 339c67dc524529e6d0397831ee5fa03bf03f0afe Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 12 Sep 2024 13:21:27 +0200 Subject: [PATCH] auth-backend-module-microsoft-provider: avoid halting backend startup Signed-off-by: Patrik Oldsberg --- .changeset/kind-hornets-sort.md | 5 +++++ .../src/authenticator.ts | 13 +++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 .changeset/kind-hornets-sort.md diff --git a/.changeset/kind-hornets-sort.md b/.changeset/kind-hornets-sort.md new file mode 100644 index 0000000000..b7288d5f7c --- /dev/null +++ b/.changeset/kind-hornets-sort.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-auth-backend-module-guest-provider': patch +--- + +This provider will now reject authentication attempts rather than halt backend startup when `dangerouslyAllowOutsideDevelopment` is not set in production. diff --git a/plugins/auth-backend-module-guest-provider/src/authenticator.ts b/plugins/auth-backend-module-guest-provider/src/authenticator.ts index f12e551f39..1ea2e124ab 100644 --- a/plugins/auth-backend-module-guest-provider/src/authenticator.ts +++ b/plugins/auth-backend-module-guest-provider/src/authenticator.ts @@ -15,7 +15,7 @@ */ import { createProxyAuthenticator } from '@backstage/plugin-auth-node'; -import { NotImplementedError } from '@backstage/errors'; +import { NotAllowedError } from '@backstage/errors'; export const guestAuthenticator = createProxyAuthenticator({ defaultProfileTransform: async () => { @@ -25,13 +25,14 @@ export const guestAuthenticator = createProxyAuthenticator({ const allowOutsideDev = config.getOptionalBoolean( 'dangerouslyAllowOutsideDevelopment', ); - if (process.env.NODE_ENV !== 'development' && allowOutsideDev !== true) { - throw new NotImplementedError( - 'The guest provider cannot be used outside of a development environment', + return process.env.NODE_ENV !== 'development' && allowOutsideDev !== true; + }, + async authenticate(_, disabled) { + if (disabled) { + throw new NotAllowedError( + "The guest provider cannot be used outside of a development environment unless 'auth.providers.guest.dangerouslyAllowOutsideDevelopment' is enabled", ); } - }, - async authenticate() { return { result: {} }; }, });