-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(mixins-preview): improving delivery source and delivery destination creation #36314
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
base: main
Are you sure you want to change the base?
Conversation
|
||||||||||||||
|
||||||||||||||
| public bind(scope: IConstruct, deliverySource: logs.IDeliverySourceRef, _sourceResourceArn: string): ILogsDeliveryConfig { | ||
| const container = new Construct(scope, deliveryId('S3', scope, this.bucket)); | ||
| public bind(scope: IConstruct, logType: string, sourceResourceArn: string): ILogsDeliveryConfig { | ||
| const container = new Construct(scope, deliveryId('S3'.concat(logType.split('_').map(word => word.charAt(0) + word.slice(1).toLowerCase()).join('')), scope, this.bucket)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add this to the deliveryId function instead, less repeat.
| const deliveryDestination = new logs.CfnDeliveryDestination(container, 'Dest', { | ||
| destinationResourceArn: this.bucket.bucketRef.bucketArn, | ||
| name: deliveryDestName('s3', container), | ||
| name: deliveryDestName('s3'.concat(`-${logType.split('_').map(word => word.toLowerCase()).join('-')}`), container), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add this to the deliveryDestName function instead, less repeat.
| } | ||
|
|
||
| function getOrCreateDeliverySource(logType: string, resource: IConstruct, sourceArn: string) { | ||
| // the delivery source should always be a child of the Construct passed in by resource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually more behaving like the BucketPolicy where the Delivery Source could be anywhere in the tree and we are looking for one that matches the given resourceArn and logType?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in theory, yes, if the user already has some vended log configurations they set up without the Mixin
| public constructor(logType: string, destinationType: string, logDelivery: logsDelivery.ILogsDelivery) { | ||
| super(); | ||
| this.logType = logType; | ||
| this.destinationType = destinationType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be available on the logDelivery object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this was a relic of something else I was doing, we don't need it here any more
mrgrain
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments
Reason for this change
There were several issues with the initial release of Vended logs, primarily:
DeliverySourcenames are unique, while testing I noticed you cannot haveDeliverySourcesthat are identical aside from their name)Description of changes
Delivery Destination Names
Delivery destination names now depend on the logType as well as the destination type, the destination resource, and the source resource to come up with a unique name. This ensures we can no longer have naming conflicts if we set up 2 vended log mixin deliveries that only differ based on the type of log that is getting send through them.
Delivery Sources
Previously a new delivery source was created for every delivery. However, it seems like there is some kind of internal implementation that blocks new delivery sources from being created that share a
resourceArnandlogTypewith an existing delivery source even if the names are unique.Now only one
DeliverySourceis created perresourceArn + logTypepair and log deliveries look for an existingDeliverySourcethey can use before creating a new one.Unrelated to Mixins
Another PR introduced much stricter cfn-guard rules to the Security Guardian: #36110
This caused Security Guardian to start flagging some of the policies that the integ tests for the Vended Logs Mixin was using. Of the issues that were flagged, 2 of them were somewhat valid (encrypt s3 buckets and firehose data stream) and 2 of them were invalid (could not find relevant sections, even though they were there and threw error), updated the cfn guard rules for the invalid cases so they could properly validate the generated policies.
Updated the
IAM_NO_WILDCARD_ACTIONS_INLINEcfn guard rule so it could properly validate IAM Roles that have this kind of structureProperties.AssumeRolePolicyDocument.Statement[*]as well as the structure it was previously looking for.Excluded
AWS:Logs::ResourcePolicyfromNO_ROOT_PRINCIPALS_EXCEPT_KMS_SECRETScfn guard rule. Cloudwatch Logs resource policies take in normal strings as their Policy Document (unlike most other policies which use JSON strings), which makes them difficult to deal with when working with cfn guard. See: https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-logs-resourcepolicy.htmlDescribe any new or updated permissions being added
N/A
Description of how you validated changes
Added unit tests to ensure that delivery sources are getting created when we expect them to be and only one is getting created for each
resourceArn + logTypepair.Added and updated integration tests to test previously untested scenarios and switched the integration tests from using a Cloudfront Distribution as their log source or an EventBus so they spin up and tear down faster.
Removed some of the requirements that force our
Deliveriesto be created sequentially, but only from the tests that create differentDeliveryDestinations. When using the sameDeliveryDestinationfor differentDeliveries, they must deploy in sequence.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license