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(cloudtrail): Trail fails during resource creation due to invalid template properties when management events are 'None' #23569

Merged
merged 4 commits into from
Jan 12, 2023

Conversation

4naesthetic
Copy link
Contributor

Overview

Currently CDK produces invalid CloudFormation that fails validation by the CloudTrail API upon deployment when setting the managementEvents parameter to ReadWriteType.NONE.

Although this is a contribution to a stable module, I consider this change to not have breaking changes as the original implementation generates CloudFormation that would result in stack deployment failure so is currently broken.

Behaviour changes

Setting managementEvents to ReadWriteType.NONE

Old behaviour: Successfully synthesises but produces CloudFormation that fails to deploy.
New behaviour: Fails synthesis with a validation error if no additional event selectors are added to the trail, as the default behaviour of CloudTrail is to enable management events if no event selectors are provided. Sets includeManagementEvents to false by default when new event selectors are added unless overridden explicitly by the user.

Other options considered

The previous PR had a suggestion to just always set includeManagementEvents to false when adding additional event selectors rather than only setting it to false when the Trail was created with ReadWriteType.NONE. However, this would break backwards compatibility for some scenarios (such as where users don't set managementEvents when creating the trail and later add an event selector, as well as a bunch of other esoteric edge cases).

Related

Previous PR that was closed for staleness (#16387).

Closes #15488


All Submissions:

Adding new Construct Runtime Dependencies:

  • This PR adds new construct runtime 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 Jan 5, 2023

@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/small Small work item – less than a day of effort p1 labels Jan 5, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team January 5, 2023 05:40
@HBobertz HBobertz self-assigned this Jan 6, 2023
Copy link
Contributor

@HBobertz HBobertz left a comment

Choose a reason for hiding this comment

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

looks good overall. I'd just like to see a minor change to a test

@@ -403,7 +403,7 @@ export class Trail extends Resource {
}

/**
* Log all Lamda data events for all lambda functions the account.
* Log all Lambda data events for all lambda functions the account.
Copy link
Contributor

Choose a reason for hiding this comment

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

good catch

@@ -625,19 +625,77 @@ describe('cloudtrail', () => {
});
});

test('managementEvents set to None correctly turns off management events', () => {
test('not provided and managementEvents set to None throws', () => {
Copy link
Contributor

@HBobertz HBobertz Jan 6, 2023

Choose a reason for hiding this comment

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

For this test can we specify the error instead of just "throws", i.e. using toThrowError() and then specify the exception in the test description here. I think the exception is InvalidEventSelectorsException, but whatever the error we expect is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it just the description you want updated? As far as I understand, exceptions thrown using node.addValidation(...) use a generic throw new Error(...) rather than a custom exception class.

@mergify mergify bot dismissed HBobertz’s stale review January 9, 2023 00:09

Pull request has been modified.

HBobertz
HBobertz previously approved these changes Jan 12, 2023
Copy link
Contributor

@HBobertz HBobertz left a comment

Choose a reason for hiding this comment

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

Gotcha I think I misunderstood exactly what toThrow and what toThrowError did. I just wanted to ensure it wouldn't just capture any error, and it would look for that specific one. But it may have been doing that with toThrow anyway. Title is also more descriptive which always helps. Looks good to me

@mergify
Copy link
Contributor

mergify bot commented Jan 12, 2023

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

@mergify mergify bot dismissed HBobertz’s stale review January 12, 2023 22:03

Pull request has been modified.

Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Mergify's gonna Mergify. Not sure why it's not working right now but I'm re-approving after manually updating.

@mergify
Copy link
Contributor

mergify bot commented Jan 12, 2023

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: 5c26a9e
  • 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 15ced88 into aws:main Jan 12, 2023
@mergify
Copy link
Contributor

mergify bot commented Jan 12, 2023

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

@4naesthetic 4naesthetic deleted the fix/cloudtrail-data-events-only branch January 13, 2023 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK 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.

(aws-cloudtrail): incorrect Trail synthesis when management_events is False
4 participants