Skip to content

Commit

Permalink
fix(msk): clusterName validation in Cluster class is incorrect (#32792)
Browse files Browse the repository at this point in the history
### Issue # (if applicable)

N/A

### Reason for this change
The validation for clusterName is incorrect. There are two issues:

1. The AND (&&) operators should be OR (||) operators. Currently, the validation throws an error only when both the pattern check AND length check fail. 
However, it should throw an error when EITHER check fails.
```ts
    if (
      !core.Token.isUnresolved(props.clusterName) &&
      !/^[a-zA-Z0-9]+$/.test(props.clusterName) &&
      props.clusterName.length > 64
    ) 
```

2. The pattern check is too restrictive. The current validation only allows alphanumeric characters, but hyphens (-) should also be allowed.

<img width="768" alt="image" src="https://github.com/user-attachments/assets/a53f240d-66f9-4ee1-890e-30f1fecd4a4a" />

Additionally, the error message in the AWS Management Console appears to be inconsistent with the actual validation requirements.
<img width="802" alt="image" src="https://github.com/user-attachments/assets/8aacc3b4-b85e-45c6-9e95-5de70416e069" />




### Description of changes
Removed cluster name validation due to the following reasons:

* The current validation is incorrect and not functioning as intended.
* While the correct pattern is not documented in [CFn docs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-msk-cluster.html#cfn-msk-cluster-clustername). So updating the validation might introduce regressions.
* As suggested by maintainers' comments, there is an opinion that pattern validation should not be implemented in CDK. [Ref](#32505 (comment))

Since the correct pattern is not documented clearly, I think removing the validation would be the preferable approach.



### Describe any new or updated permissions being added
Nothing.



### Description of how you validated changes
Nothing because only remove validation.


### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
mazyu36 authored Jan 13, 2025
1 parent e33ebb4 commit 41ddd46
Showing 1 changed file with 0 additions and 11 deletions.
11 changes: 0 additions & 11 deletions packages/@aws-cdk/aws-msk-alpha/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,17 +485,6 @@ export class Cluster extends ClusterBase {
);
}

if (
!core.Token.isUnresolved(props.clusterName) &&
!/^[a-zA-Z0-9]+$/.test(props.clusterName) &&
props.clusterName.length > 64
) {
throw Error(
'The cluster name must only contain alphanumeric characters and have a maximum length of 64 characters.' +
`got: '${props.clusterName}. length: ${props.clusterName.length}'`,
);
}

if (
props.clientAuthentication?.saslProps?.iam &&
props.clientAuthentication?.saslProps?.scram
Expand Down

0 comments on commit 41ddd46

Please sign in to comment.