-
Notifications
You must be signed in to change notification settings - Fork 4k
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
KMS - Ability to import an AWS managed key by its alias #5953
Comments
I see two different options for implementing support for key aliases. The current The most robust and involved option would be to handle lookup of the key ARN from the alias using a context query, similar to how The above assumes that every time we need a reference to a KMS Key, we need the Key ARN; however, many CloudFormation resources that reference KMS keys allow for using the Key alias directly, as long as the key and stack are in the same account. Here are a few documented examples: (CloudTrail Trail, CodeBuild Pipeline, DocDB Cluster). An alternative approach would make use of the fact that many resources can directly use the Key alias, and not do a lookup unless necessary. The current Rather than forcing the alias-only key to conform to the In lieu of any conflicting guidance or opinions, I can take a crack at the initial approach (context query lookup). |
@njlynch I think I have a simpler solution for all of this :). How about if we had this method available (name TBD, of course): const awsS3Key: kms.IAlias = kms.Alias.fromAliasName(this, 'AwsS3Key', 'aws/s3'); Remember that Thoughts on this @njlynch ? |
@skinny85 - Yes, I think I missed that public grant(grantee: iam.IGrantable, ...actions: string[]): iam.Grant {
+ if (this.aliasTargetKey === undefined) {
+ throw new Error('Alias without an aliasTargetKey does not support "grant"');
+ }
return this.aliasTargetKey.grant(grantee, ...actions);
} With this approach, a new method isn't necessary; the existing This approach is certainly the simplest, although it feels a bit hacky to effectively error out all of the |
Changing I'm also thinking about @njlynch if you want to give this change a shot in a PR, got for it! I'll gladly review it 🙂. Thanks, |
Supports importing an Alias by alias name only, without the underlying reference to the Key ARN. Useful in scenarios where only the alias is needed in a reference by a Construct. fixes #5953 ---- Tested via a simple repro script: ```ts const key = kms.Alias.fromAliasName(this, 'myKey', 'alias/myTestKey'); new cloudtrail.Trail(this, 'CloudTrail', { sendToCloudWatchLogs: true, kmsKey: key }); ``` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Hello, I don't think this addresses the initial request/concern. If I do it like this (I'm using python), kms.Alias.from_alias_name(self, "myKey", "alias/myTestKey").alias_target_key , but I get this error: jsii.errors.JSIIError: Cannot access aliasTargetKey on an Alias imnported by Alias.fromAliasName(). Please advise. How can I lookup key arn from its alias name/arn? |
@dtserekhman-starz - This feature was tracking the more lightweight version where only the alias was needed (e.g., with CloudTrail). Can you open a new feature request for that "lookupKey" functionality? |
It would be nice to be able to reuse existing/default keys that come with every AWS account, without having to hardcode their full ARNs, e.g. by providing just their alias.
Currently, it's only possible through:
const key = kms.Key.fromKeyArn(this, "default", "arn:aws:kms:us-east-1:xxxxx:key/390a2c1f-xxxx-4abd-xxxx-c17e04362ba9")
It would be nice to have something like:
const key = kms.Key.fromKeyAlias(this, "default", "alias:aws/s3")
Like it is currently possible to be done using Terraform:
https://www.terraform.io/docs/providers/aws/d/kms_key.html
Use Case
I am currently creating a CloudTrail that sends log files to an S3 bucket. The CloudTrail has the option for "encrypting logs using KMS". However, in order to pass it the default S3 key that AWS provided me, I need to be able to find/import it. The only possibility currently, is the following method, which is far from an ideal solution because it requires me to hardcode the key ID in the ARN (a highly dynamic string). This makes the CDK stack less reusable and portable across regions and AWS accounts (another account will have a different key ID for the default S3 key for example).
Proposed Solution
A new method like:
const key = kms.Key.fromAlias(this, "default", "alias:kms/s3")
Other
Current code:
This is a 🚀 Feature Request
The text was updated successfully, but these errors were encountered: