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(ec2): prevent deduplication of init command args #30821

Merged
merged 13 commits into from
Aug 8, 2024

Conversation

Leo10Gama
Copy link
Member

Issue # (if applicable)

Closes #26221

Reason for this change

Previously, using ec2.InitCommand.argvCommand() would remove some duplicate strings in the input array. This produces an incorrect command in the template, leading to unexpected behaviour.

Description of changes

An additional line was added to the deepMerge function that is called in the InitConfig.bindForType() method, which checks the key of the input array, preventing it from becoming a set (removing duplicates) if it is a list of commands.

Description of how you validated changes

A unit test was added to generate an AWS::CloudFormation::Init resource identical to the one reproduced in the issue. The test was run and failed before the changes were made, and following the changes in cfn-init.ts, the test passed.

Checklist


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

@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p1 labels Jul 10, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team July 10, 2024 17:39
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jul 10, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@Leo10Gama Leo10Gama changed the title fix(aws-ec2): Prevent deduplication of init command args fix(aws-ec2): prevent deduplication of init command args Jul 10, 2024
@Leo10Gama Leo10Gama changed the title fix(aws-ec2): prevent deduplication of init command args fix(ec2): prevent deduplication of init command args Jul 10, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review July 10, 2024 21:10

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jul 10, 2024
@shikha372 shikha372 self-assigned this Jul 12, 2024
Copy link
Contributor

@scanlonp scanlonp left a comment

Choose a reason for hiding this comment

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

Looking good with a couple small comments:

  1. Let's switch the logic flow. It will be easier to understand with the specific cases handled first.
  2. Do we have any current unit tests that test for de-duplication on non-command uses of the deep merge? If yes then we are all set. If not, we should probably put that case in to verify that this change stays scoped to the individual function we are targeting.

packages/aws-cdk-lib/aws-ec2/lib/cfn-init.ts Outdated Show resolved Hide resolved
@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jul 25, 2024
@shikha372 shikha372 removed their assignment Jul 26, 2024
@Leo10Gama
Copy link
Member Author

  1. Do we have any current unit tests that test for de-duplication on non-command uses of the deep merge? If yes then we are all set. If not, we should probably put that case in to verify that this change stays scoped to the individual function we are targeting.

From what it seems like, this specific deepMerge is only used in this file by the bind functions, and it doesn't seem like it's used outside of this context. The only other deepMerge tests I can find are for a separate util that doesn't have to do with this function. But that is a good catch, I'll include tests to make sure the de-duping stays consistent.

Copy link
Contributor

@scanlonp scanlonp left a comment

Choose a reason for hiding this comment

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

My comments are addressed. I am good with the PR. Going to wait for a second review for approval.

const config = new ec2.InitConfig([
ec2.InitSource.fromUrl('/tmp/foo', 'https://amazon.com/foo.zip'),
ec2.InitSource.fromUrl('/tmp/foo', 'https://amazon.com/foo.zip'),
ec2.InitSource.fromUrl('/tmp/foo', 'https://amazon.com/foo.zip'),
Copy link
Contributor

Choose a reason for hiding this comment

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

can you make this:

ec2.InitSource.fromUrl('/tmp/foo', 'https://amazon.com/foo.zip'),
ec2.InitSource.fromUrl('/tmp/foo', 'https://amazon.com/foo.zip'),
ec2.InitSource.fromUrl('/tmp/foo', 'https://amazon.com/bar.zip'),
ec2.InitSource.fromUrl('/tmp/foo', 'https://amazon.com/bar.zip'),
ec2.InitSource.fromUrl('/tmp/bar', 'https://amazon.com/bar.zip'),
ec2.InitSource.fromUrl('/tmp/bar', 'https://amazon.com/bar.zip'),
ec2.InitSource.fromUrl('/tmp/bar', 'https://amazon.com/foobar.zip'),
ec2.InitSource.fromUrl('/tmp/bar', 'https://amazon.com/foobar.zip'),

or something like this so we can see whether the dedeup logic applies to both the first parameter and the second, or if it's just the second?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, will include some more dedup test values.

Copy link
Contributor

@comcalvi comcalvi left a comment

Choose a reason for hiding this comment

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

I approve of the 👻

Copy link
Contributor

mergify bot commented Aug 8, 2024

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: ce048a0
  • 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 1e7c690 into aws:main Aug 8, 2024
10 checks passed
Copy link
Contributor

mergify bot commented Aug 8, 2024

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).

Copy link

github-actions bot commented Aug 8, 2024

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2024
@Leo10Gama Leo10Gama deleted the initcmd-dedup branch November 6, 2024 19:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. contribution/core This is a PR that came from AWS. effort/medium Medium work item – several days of effort p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ec2: InitCommand.argvCommand dedupes its args, causing the wrong command to be generated)
6 participants