Skip to content

Commit 31c3cb7

Browse files
authored
Merge pull request #13 from alliander-opensource/add-kms-naming
Add kms naming
2 parents ab38399 + 369199d commit 31c3cb7

6 files changed

+43
-9
lines changed

package-lock.json

+9-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.keyrotate.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import { KEYUTIL, KJUR } from 'jsrsasign'
1919

2020
const client = new KMSClient({})
2121

22-
const ALIAS_PREVIOUS = 'alias/sts/PREVIOUS'
23-
const ALIAS_CURRENT = 'alias/sts/CURRENT'
24-
const ALIAS_PENDING = 'alias/sts/PENDING'
22+
const ALIAS_PREVIOUS = process.env.PREVIOUS_KEY!.toString()
23+
const ALIAS_CURRENT = process.env.CURRENT_KEY!.toString()
24+
const ALIAS_PENDING = process.env.PENDING_KEY!.toString()
2525

2626
const ALIASES: string[] = [
2727
ALIAS_PREVIOUS,

src/index.sign.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import base64url from 'base64url'
88

99
import { Logger } from '@aws-lambda-powertools/logger'
1010

11-
const KEY_ALIAS_CURRENT = 'alias/sts/CURRENT'
11+
const KEY_ALIAS_CURRENT = process.env.CURRENT_KEY!.toString()
1212
const logger = new Logger()
1313

1414
export const handler = async (apiEvent: APIGatewayEvent, context: Context): Promise<APIGatewayProxyResult> => {

src/index.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,21 @@ export interface AwsJwtStsProps {
111111
* Optional custom name for the CloudWatch Alarm monitoring Key Rotation Lambda failures, default: sts-key_rotate_errors_lambda-alarm
112112
*/
113113
readonly alarmNameKeyRotationLambdaFailed?: string
114+
115+
/**
116+
* current kms key name
117+
*/
118+
readonly currentKeyName?: string
119+
120+
/**
121+
* previous kms key name
122+
*/
123+
readonly previousKeyName?: string
124+
125+
/**
126+
* pending kms key name
127+
*/
128+
readonly pendingKeyName?: string
114129
}
115130

116131
/* eslint-disable no-new */
@@ -208,7 +223,10 @@ export class AwsJwtSts extends Construct {
208223
architecture,
209224
environment: {
210225
S3_BUCKET: oidcbucket.bucketName,
211-
ISSUER: issuer
226+
ISSUER: issuer,
227+
CURRENT_KEY: 'alias/' + (props.currentKeyName ?? 'sts/CURRENT'),
228+
PREVIOUS_KEY: 'alias/' + (props.previousKeyName ?? 'sts/PREVIOUS'),
229+
PENDING_KEY: 'alias/' + (props.pendingKeyName ?? 'sts/PENDING')
212230
}
213231
})
214232

@@ -223,7 +241,8 @@ export class AwsJwtSts extends Construct {
223241
architecture,
224242
environment: {
225243
ISSUER: issuer,
226-
DEFAULT_AUDIENCE: props.defaultAudience
244+
DEFAULT_AUDIENCE: props.defaultAudience,
245+
CURRENT_KEY: 'alias/' + (props.currentKeyName ?? 'sts/CURRENT')
227246
}
228247
})
229248

src/test/index.keyrotate.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import { mockClient } from 'aws-sdk-client-mock'
66
import { KMSClient, GetPublicKeyCommand, DescribeKeyCommand } from '@aws-sdk/client-kms'
77
import { S3Client } from '@aws-sdk/client-s3'
88

9+
process.env = { // set env vars as they are called on load of the file
10+
CURRENT_KEY: 'alias/sts/CURRENT',
11+
PREVIOUS_KEY: 'alias/sts/PREVIOUS',
12+
PENDING_KEY: 'alias/sts/PENDING'
13+
}
14+
15+
// eslint-disable-next-line import/first
916
import { handler } from '../index.keyrotate'
1017

1118
const kmsMock = mockClient(KMSClient)

src/test/index.sign.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
SignCommand
1515
} from '@aws-sdk/client-kms'
1616

17+
process.env.CURRENT_KEY = 'key-1'// set env var as it is called on load of the file
18+
// eslint-disable-next-line import/first
1719
import { handler } from '../index.sign'
1820

1921
const kmsMock = mockClient(KMSClient)

0 commit comments

Comments
 (0)