Skip to content
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

fix(cli): add validation of --notification-arns structure #21270

Merged
merged 6 commits into from
Jul 23, 2022
Merged

fix(cli): add validation of --notification-arns structure #21270

merged 6 commits into from
Jul 23, 2022

Conversation

TrygviZL
Copy link
Contributor

When deploying using the --notification-arns argument, it's possible to pass in an invalid arn as an SNS topic arn, causing a change set to be uploaded with an invalid arn. This PR adds a check for the structure of the input ARN.

I was originally looking into possibly adding the check earlier in the process such as adding a .check() method to the yargs option in packages/aws-cdk/lib/cli.ts. But as I see it there are no tests for these, so it was difficult to validate the change.

closes #20806


All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Jul 21, 2022

@aws-cdk-automation aws-cdk-automation requested a review from a team July 21, 2022 21:23
@github-actions github-actions bot added bug This issue is a bug. effort/small Small work item – less than a day of effort p1 labels Jul 21, 2022
@@ -127,6 +128,14 @@ export class CdkToolkit {
return this.watch(options);
}

if (options.notificationArns) {
options.notificationArns.map( arn => {
if (!validateSnsTopicArn(arn)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!validateSnsTopicArn(arn)) {
if (!Token.unresolved(arn) && !validateSnsTopicArn(arn)) {

Also please add a test for this condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@otaviomacedo I have looked into it and can indeed add the !Token.isUnresolved(arn) condition to the check of notification arn. However, as this check happens prior to stack synthesis, it seems redundant to check if the token has been resolved.
Let me know if I am misunderstanding :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arn may be a "normal" string (in which case it makes sense to validate it) or it may a token, which is a special kind of string, that is a stand-in for something else (in which case it doesn't make sense to validate it because it will always fail). In the second case, Token isUnresolved() returns true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@otaviomacedo thanks for the reply! I do get that tokens can be passed around and are converted to strings during synthesis to CloudFormation templates.
What I am thinking is that the Arn in this specific case is passed as a parameter when using the CLI. for example:
cdk deploy --all --notification-arns arn:aws:sns:us-east-1::some-sns-topic
in which case the arn will never be a token as these only exist in a stack prior to synthesis.

Again, I might be wrong, but is there a case where the arn is passed to the CLI command as a token?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@otaviomacedo Readng around I found #8581 which does ask to implement a way to add the notification arn to the stack prior to synthesis. The issue has been open for a while, but would require the Token.isUnresolved() in the check.

What do you think? should we add it just in case?

merge main from aws/aws-cdk
@mergify mergify bot dismissed otaviomacedo’s stale review July 22, 2022 11:02

Pull request has been modified.

@mergify
Copy link
Contributor

mergify bot commented Jul 23, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 03a827e
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 6d157d1 into aws:main Jul 23, 2022
@mergify
Copy link
Contributor

mergify bot commented Jul 23, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

comcalvi pushed a commit to comcalvi/aws-cdk that referenced this pull request Jul 25, 2022
When deploying using the `--notification-arns` argument, it's possible to pass in an invalid arn as an SNS topic arn, causing a change set to be uploaded with an invalid arn. This PR adds a check for the structure of the input ARN.

I was originally looking into possibly adding the check earlier in the process such as adding a .check() method to the yargs option in [packages/aws-cdk/lib/cli.ts](https://github.com/aws/aws-cdk/blob/f66f94e9201b9c9d5e0f1b713a6f30194b323b28/packages/aws-cdk/lib/cli.ts). But as I see it there are no tests for these, so it was difficult to validate the change.

closes aws#20806 


----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
josephedward pushed a commit to josephedward/aws-cdk that referenced this pull request Aug 30, 2022
When deploying using the `--notification-arns` argument, it's possible to pass in an invalid arn as an SNS topic arn, causing a change set to be uploaded with an invalid arn. This PR adds a check for the structure of the input ARN.

I was originally looking into possibly adding the check earlier in the process such as adding a .check() method to the yargs option in [packages/aws-cdk/lib/cli.ts](https://github.com/aws/aws-cdk/blob/f66f94e9201b9c9d5e0f1b713a6f30194b323b28/packages/aws-cdk/lib/cli.ts). But as I see it there are no tests for these, so it was difficult to validate the change.

closes aws#20806 


----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(cli): --notification-arns not validated
3 participants