Skip to content

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

@WtfJoke

Description

@WtfJoke

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/"

public static fromAliasName(scope: Construct, id: string, aliasName: string): IAlias {
class Import extends Resource implements IAlias {
public readonly keyArn = Stack.of(this).formatArn({ service: 'kms', resource: aliasName });
public readonly keyId = aliasName;
public readonly aliasName = aliasName;

vs
if (!aliasName.startsWith(REQUIRED_ALIAS_PREFIX)) {
aliasName = REQUIRED_ALIAS_PREFIX + aliasName;
}

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)

[email protected]

AWS CDK CLI version

[email protected]

Node.js Version

22.21.1

OS

macos

Language

TypeScript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-kmsRelated to AWS Key ManagementbugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions