Merge pull request #16020 from lucasdrpires/feat/server-token-auth
Make identity of backend applications valid
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend': patch
|
||||
---
|
||||
|
||||
Make identity valid if subject of token is a backstage server-2-server auth token
|
||||
@@ -94,14 +94,11 @@ function isSupportedTemplate(entity: TemplateEntityV1beta3) {
|
||||
* until someone explicitly passes an IdentityApi. When we have reasonable confidence that most backstage deployments
|
||||
* are using the IdentityApi, we can remove this function.
|
||||
*/
|
||||
function buildDefaultIdentityClient({
|
||||
logger,
|
||||
}: {
|
||||
logger: Logger;
|
||||
}): IdentityApi {
|
||||
function buildDefaultIdentityClient(options: RouterOptions): IdentityApi {
|
||||
return {
|
||||
getIdentity: async ({ request }: IdentityApiGetIdentityRequest) => {
|
||||
const header = request.headers.authorization;
|
||||
const { logger } = options;
|
||||
|
||||
if (!header) {
|
||||
return undefined;
|
||||
@@ -131,6 +128,10 @@ function buildDefaultIdentityClient({
|
||||
throw new TypeError('Expected string sub claim');
|
||||
}
|
||||
|
||||
if (sub === 'backstage-server') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Check that it's a valid ref, otherwise this will throw.
|
||||
parseEntityRef(sub);
|
||||
|
||||
@@ -178,8 +179,7 @@ export async function createRouter(
|
||||
const logger = parentLogger.child({ plugin: 'scaffolder' });
|
||||
|
||||
const identity: IdentityApi =
|
||||
options.identity || buildDefaultIdentityClient({ logger });
|
||||
|
||||
options.identity || buildDefaultIdentityClient(options);
|
||||
const workingDirectory = await getWorkingDirectory(config, logger);
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user