Skip to content

feat(ec2): support KMS keys for block device mappings for both instances and launch templates#18326

Merged
mergify[bot] merged 23 commits intoaws:masterfrom
markussiebert:feat/block-device-mappings-with-kms-cmk
Feb 1, 2022
Merged

feat(ec2): support KMS keys for block device mappings for both instances and launch templates#18326
mergify[bot] merged 23 commits intoaws:masterfrom
markussiebert:feat/block-device-mappings-with-kms-cmk

Conversation

@markussiebert
Copy link
Copy Markdown
Contributor

@markussiebert markussiebert commented Jan 9, 2022

This pullrequest will add the optional kmsKeyId property to the EbsDeviceOptions Interface. Whit this, it will be possible to specify the kmsKeyId used for encrypting the ebs volumes when launching instances. At the moment I already use this via an escape hatch in my projects, but it's not that handy as the block device mapping is an array.

I don't like to only specify a kmsKeyId (= ARN) but accepting an kms.IKey in the properties would be a bigger change.

fixes: #18309
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link
Copy Markdown

gitpod-io bot commented Jan 9, 2022

@github-actions github-actions bot added the @aws-cdk/aws-kms Related to AWS Key Management label Jan 9, 2022
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jan 9, 2022

Title does not follow the guidelines of Conventional Commits. Please adjust title before merge.

@markussiebert markussiebert changed the title Feat/block device mappings with kms cmk feat: Allow specifying the kms key in block device mappings (for instances and launch-templates) Jan 9, 2022
@njlynch njlynch added @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud and removed @aws-cdk/aws-kms Related to AWS Key Management labels Jan 20, 2022
@mergify mergify bot dismissed njlynch’s stale review January 24, 2022 08:53

Pull request has been modified.

* Properties of an EBS block device
*/
export interface EbsDeviceProps extends EbsDeviceSnapshotOptions {
export interface EbsDeviceProps extends EbsDeviceSnapshotOptions, EbsDeviceOptions {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary and/or intentional?

It feels like omitting the encrypted property from the EbsDeviceProps was an intentional decision, so I'm a little wary of undoing it. Any details you can provide here?

Copy link
Copy Markdown
Contributor Author

@markussiebert markussiebert Jan 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consider this a bug or it was unintentionally, or left over from early days.

The class BlockDeviceVolume offers two ebs related static methods:

public static ebsFromSnapshot(snapshotId: string, options: EbsDeviceSnapshotOptions = {}): BlockDeviceVolume {

public static ebs(volumeSize: number, options: EbsDeviceOptions = {}): BlockDeviceVolume {

both call the constructor of the class

   * @param ebsDevice EBS device info
   * @param virtualName Virtual device name
   */
  protected constructor(public readonly ebsDevice?: EbsDeviceProps, public readonly virtualName?: string) {
  }

I thought extending the EbsDeviceProps that are only used within the protected constructor would be the right thing to do. Because both SnapshotOptions and DeviceOptions are the properties of the ebs volume, but you can't specify them at the same time (but this is handled by the mentioned static methods).

So yes, it was intentionally to change this, in order to get kms encryption for device mappings working.

Apart from that, this prop is reused here:

const { iops, volumeType } = ebs;

If I don't extend the props, I could not access the encryption properties.

But as already said: The static methods ebs and ebsFromSnapshot take care of not combining incompatible properties.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@njlynch what do you think?

@mergify mergify bot dismissed njlynch’s stale review January 31, 2022 09:42

Pull request has been modified.

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Feb 1, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@njlynch njlynch changed the title feat: Allow specifying the kms key in block device mappings (for instances and launch-templates) feat(ec2): support KMS keys for block device mappings for both instances and launch templates Feb 1, 2022
@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: b731123
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 17dbe5f into aws:master Feb 1, 2022
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Feb 1, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

eladb pushed a commit that referenced this pull request Feb 1, 2022
…h instances and launch templates (#18326)"

Reverts commit 17dbe5f. in the meantime until we figure out the longer term solution.

Fixes #18676
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
…ces and launch templates (aws#18326)

This pullrequest will add the optional ```kmsKeyId``` property to the ```EbsDeviceOptions``` Interface. Whit this, it will be possible to specify the kmsKeyId used for encrypting the ebs volumes when launching instances. At the moment I already use this via an escape hatch in my projects, but it's not that handy as the block device mapping is an array.

I don't like to only specify a kmsKeyId (= ARN) but accepting an ```kms.IKey``` in the properties would be a bigger change.

fixes: aws#18309
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(aws-ec2): Add KmsKeyId property to launchtemplate -> blockdevicemapping -> ebs

4 participants