From 068a68c87e4d0d72c09c4a55034c6baddec22fca Mon Sep 17 00:00:00 2001 From: Timothy Deakin Date: Sat, 13 Apr 2024 17:15:10 +0100 Subject: [PATCH] refactor: cache key endpoint Signed-off-by: Timothy Deakin --- .../src/helpers.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/auth-backend-module-aws-alb-provider/src/helpers.ts b/plugins/auth-backend-module-aws-alb-provider/src/helpers.ts index 1af02ce9ec..e4bdf847c4 100644 --- a/plugins/auth-backend-module-aws-alb-provider/src/helpers.ts +++ b/plugins/auth-backend-module-aws-alb-provider/src/helpers.ts @@ -73,12 +73,16 @@ export const makeProfileInfo = ( const getPublicKeyEndpoint = (region: string) => { const commercialEndpoint = `https://public-keys.auth.elb.${encodeURIComponent( region, - )}.amazonaws.com/`; + )}.amazonaws.com`; const govEndpoint = `https://s3-${encodeURIComponent( region, - )}.amazonaws.com/aws-elb-public-keys-prod-${encodeURIComponent(region)}/`; + )}.amazonaws.com/aws-elb-public-keys-prod-${encodeURIComponent(region)}`; - return region.startsWith('us-gov') ? govEndpoint : commercialEndpoint; + if (region.startsWith('us-gov')) { + return govEndpoint; + } + + return commercialEndpoint; }; export const provisionKeyCache = (region: string, keyCache: NodeCache) => { @@ -92,7 +96,7 @@ export const provisionKeyCache = (region: string, keyCache: NodeCache) => { } const keyText: string = await fetch( - getPublicKeyEndpoint(region) + header.kid, + `${getPublicKeyEndpoint(region)}/${encodeURIComponent(header.kid)}`, ).then(response => response.text()); const keyValue = crypto.createPublicKey(keyText);