Skip to content

(aws-kms): Add support for HMAC keys #23727

Closed
@matthias-pichler

Description

@matthias-pichler

Describe the feature

KMS not only supports symmetric and asymmetric keys but also HMAC keys: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-kms-key.html#cfn-kms-key-keyspec

It would be great to have 1st class support for them in the cdk.

Use Case

I want to implement the OAuth2 authorization_code flow with a nonce that is hmac verified and use KMS to do the signing.

Proposed Solution

Add the missing values to the KeySpec and KeyUsage enums:

 const hmacKey = new kms.Key(this, "HMACSecret", {
      enabled: true,
      enableKeyRotation: true,
      keySpec: kms.KeySpec.HMAC_256,
      keyUsage: kms.KeyUsage.GENERATE_VERIFY_MAC,
    });

Other Information

Trying to override the enum values with strings directly (like this):

const hmacKey = new kms.Key(this, "HMACSecret", {
      enabled: true,
      enableKeyRotation: true,
      keySpec: "HMAC_256" as any,
      keyUsage: "GENERATE_VERIFY_MAC" as any,
    });

currently fails due to the validation here

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.60.0

Environment details (OS name and version, etc.)

MacOS, Node 18

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-kmsRelated to AWS Key Managementeffort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.good first issueRelated to contributions. See CONTRIBUTING.mdp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions