question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KMS - Ability to import an AWS managed key by its alias

See original GitHub issue

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:

export class Cloudtrail extends cdk.Stack {
    constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
        super(scope, id, props);

        const key = kms.Key.fromKeyArn(this, "default", "arn:aws:kms:us-east-1:xxxxx:key/390a2c1f-xxxx-4abd-xxxx-c17e04362ba9")

        const trail = new cloudtrail.Trail(this, 'CloudTrail', {
            sendToCloudWatchLogs: true,
            includeGlobalServiceEvents: true,
            kmsKey: key
        });
    }
}

This is a 🚀 Feature Request

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:14
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dtserekhman-starzcommented, Jun 29, 2020

Hello, I don’t think this addresses the initial request/concern. Sometimes, Alias name cannot be used in IAM Policies, but the actual KMS key ARN must be used. The above call, kms.Alias.fromAliasName(this, ‘myKey’, ‘alias/myTestKey’), returns aliasName, which is great. But then I would like to get a Key ARN from that alias name.

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?

0reactions
dtserekhman-starzcommented, Jul 1, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using aliases - AWS Key Management Service
The AWS KMS API provides full control of aliases in each account and Region. The API includes operations to create an alias (CreateAlias),...
Read more >
Importing key material in AWS KMS keys - AWS Documentation
You can monitor the use and management of a KMS key with imported key material. AWS KMS records an entry in your AWS...
Read more >
Working with aliases - AWS Key Management Service
To list only the aliases that are associated with a particular KMS key, use the KeyId parameter. Its value can be the key...
Read more >
About aliases - AWS Key Management Service
To control access to a KMS key based on its aliases, use the kms:RequestAlias or kms:ResourceAliases condition keys. For details, see ABAC for...
Read more >
Using aliases to control access to KMS keys
IAM policies might give alias permissions for all KMS keys in your AWS account. For example, the AWSKeyManagementServicePowerUser managed policy allows ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found