aws / aws/aws-cdk

(aws-kms): Alias.fromAliasName does not validate the alias name

Open
#36,693 2 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-kms bug effort/small p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

When using `Alias.fromAliasName` the alias name is not prefixed with "alias/" if its not already provided.
In comparsion, when using `new Alias`, alias name is prefixed with "alias/"

https://github.com/aws/aws-cdk/blob/7da5aebcd87b8ba61cbb2adda01806f94a6bc608/packages/aws-cdk-lib/aws-kms/lib/alias.ts#L244-L248
vs
https://github.com/aws/aws-cdk/blob/7da5aebcd87b8ba61cbb2adda01806f94a6bc608/packages/aws-cdk-lib/aws-kms/lib/alias.ts#L331-L333

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Last Known Working CDK Library Version

_No response_

### Expected Behavior

Alias should be prefixed with alias/ when imported using Alias.fromAliasName when not already prefixed with alias/

### Current Behavior

Alias is not prefixed with alias/

### Reproduction Steps

```
Alias.fromAliasName(
this,
"Foo",
"my-alias-name",
).aliasName; // my-alias-name

new Alias(this, "FooNew", {
aliasName: "my-alias-name",
}).aliasName; // alias/my-alias-name
```

### Possible Solution

Add required alias prefix when alias is not already prefixed

### Additional Information/Context

I can provide a pull request with a fix

### AWS CDK Library version (aws-cdk-lib)

aws-cdk-lib@2.230.0

### AWS CDK CLI version

cdk@2.1100.3

### Node.js Version

22.21.1

### OS

macos

### Language

TypeScript

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start in packages/aws-cdk-lib/aws-kms/lib/alias.ts, comparing the referenced lines for Alias.fromAliasName and new Alias, then reproduce the two aliasName calls shown in the issue. Done means imported names without alias/ expose the same prefixed aliasName behavior as new Alias while already-prefixed names remain valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, security
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.