From 4a4f410687519b11e8ec816f1d979cb8aaddbfdd Mon Sep 17 00:00:00 2001 From: Jordan Kueh Date: Fri, 25 Jul 2025 11:50:00 +1000 Subject: [PATCH] Adding a configuration option to revert to the native Backstage authentication behaviour --- src/plugin.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/plugin.ts b/src/plugin.ts index e3366da..392168a 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -55,10 +55,18 @@ export const pagerDutyPlugin = createBackendPlugin({ }) }), ); - httpRouter.addAuthPolicy({ - path: '/', - allow: 'unauthenticated', - }); + + // The default Backstage behaviour is to require authentication on routes. + // https://backstage.io/docs/backend-system/core-services/http-router/#using-the-service + // Setting disableUnauthenticatedAccess to true will revert this plugin's route authentication + // policy back to the default Backstage behaviour. + const disableUnauthenticatedAccess = config.getOptionalBoolean('pagerDuty.disableUnauthenticatedAccess') ?? false; + if (!disableUnauthenticatedAccess) { + httpRouter.addAuthPolicy({ + path: '/', + allow: 'unauthenticated', + }); + } }, }); }