Skip to content

Add kms naming #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/index.keyrotate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import { KEYUTIL, KJUR } from 'jsrsasign'

const client = new KMSClient({})

const ALIAS_PREVIOUS = 'alias/sts/PREVIOUS'
const ALIAS_CURRENT = 'alias/sts/CURRENT'
const ALIAS_PENDING = 'alias/sts/PENDING'
const ALIAS_PREVIOUS = process.env.PREVIOUS_KEY!.toString()
const ALIAS_CURRENT = process.env.CURRENT_KEY!.toString()
const ALIAS_PENDING = process.env.PENDING_KEY!.toString()

const ALIASES: string[] = [
ALIAS_PREVIOUS,
Expand Down
2 changes: 1 addition & 1 deletion src/index.sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import base64url from 'base64url'

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

const KEY_ALIAS_CURRENT = 'alias/sts/CURRENT'
const KEY_ALIAS_CURRENT = process.env.CURRENT_KEY!.toString()
const logger = new Logger()

export const handler = async (apiEvent: APIGatewayEvent, context: Context): Promise<APIGatewayProxyResult> => {
Expand Down
23 changes: 21 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ export interface AwsJwtStsProps {
* Optional custom name for the CloudWatch Alarm monitoring Key Rotation Lambda failures, default: sts-key_rotate_errors_lambda-alarm
*/
readonly alarmNameKeyRotationLambdaFailed?: string

/**
* current kms key name
*/
readonly currentKeyName?: string

/**
* previous kms key name
*/
readonly previousKeyName?: string

/**
* pending kms key name
*/
readonly pendingKeyName?: string
}

/* eslint-disable no-new */
Expand Down Expand Up @@ -208,7 +223,10 @@ export class AwsJwtSts extends Construct {
architecture,
environment: {
S3_BUCKET: oidcbucket.bucketName,
ISSUER: issuer
ISSUER: issuer,
CURRENT_KEY: 'alias/' + (props.currentKeyName ?? 'sts/CURRENT'),
PREVIOUS_KEY: 'alias/' + (props.previousKeyName ?? 'sts/PREVIOUS'),
PENDING_KEY: 'alias/' + (props.pendingKeyName ?? 'sts/PENDING')
}
})

Expand All @@ -223,7 +241,8 @@ export class AwsJwtSts extends Construct {
architecture,
environment: {
ISSUER: issuer,
DEFAULT_AUDIENCE: props.defaultAudience
DEFAULT_AUDIENCE: props.defaultAudience,
CURRENT_KEY: 'alias/' + (props.currentKeyName ?? 'sts/CURRENT')
}
})

Expand Down
7 changes: 7 additions & 0 deletions src/test/index.keyrotate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import { mockClient } from 'aws-sdk-client-mock'
import { KMSClient, GetPublicKeyCommand, DescribeKeyCommand } from '@aws-sdk/client-kms'
import { S3Client } from '@aws-sdk/client-s3'

process.env = { // set env vars as they are called on load of the file
CURRENT_KEY: 'alias/sts/CURRENT',
PREVIOUS_KEY: 'alias/sts/PREVIOUS',
PENDING_KEY: 'alias/sts/PENDING'
}

// eslint-disable-next-line import/first
import { handler } from '../index.keyrotate'

const kmsMock = mockClient(KMSClient)
Expand Down
2 changes: 2 additions & 0 deletions src/test/index.sign.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
SignCommand
} from '@aws-sdk/client-kms'

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

const kmsMock = mockClient(KMSClient)
Expand Down
Loading