fix(aws): order-independent CloudWatch metric filter pattern checks#11345
Open
sahil-sols wants to merge 2 commits into
Open
fix(aws): order-independent CloudWatch metric filter pattern checks#11345sahil-sols wants to merge 2 commits into
sahil-sols wants to merge 2 commits into
Conversation
Metric filter validation now uses per-clause lookahead substrings so combined filterPattern strings match regardless of clause order. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
|
✅ Conflict Markers Resolved All conflict markers have been successfully resolved in this pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Several AWS CIS-style CloudWatch log metric filter checks validate combined
filterPatternstrings that use CloudWatch’s{ (clause A) || (clause B) || ... }syntax. Each clause is a separate condition; AWS does not guarantee clause order in the stored pattern.Those checks previously used sequence-dependent regex (
clause1.+clause2.+...), so a correctly configured metric filter could be reported as FAIL when clauses appeared in a different order than the regex expected. This PR aligns validation with how AWS actually stores multi-clause patterns.This is not tied to an open GitHub issue; it improves check accuracy for real-world CloudTrail/CloudWatch configurations.
Description
Summary: Replaces sequential regex chaining with per-clause positive lookaheads (
(?=.*...)) in 13 AWS CloudWatch log metric filter checks so every required event/source clause must be present infilterPattern, regardless of order.Affected checks:
cloudwatch_changes_to_network_acls_alarm_configuredcloudwatch_changes_to_network_gateways_alarm_configuredcloudwatch_changes_to_network_route_tables_alarm_configuredcloudwatch_changes_to_vpcs_alarm_configuredcloudwatch_log_metric_filter_and_alarm_for_aws_config_configuration_changes_enabledcloudwatch_log_metric_filter_and_alarm_for_cloudtrail_configuration_changes_enabledcloudwatch_log_metric_filter_authentication_failurescloudwatch_log_metric_filter_aws_organizations_changescloudwatch_log_metric_filter_disable_or_scheduled_deletion_of_kms_cmkcloudwatch_log_metric_filter_for_s3_bucket_policy_changescloudwatch_log_metric_filter_policy_changescloudwatch_log_metric_filter_security_group_changescloudwatch_log_metric_filter_sign_in_without_mfaMatching still goes through
check_cloudwatch_log_metric_filter()inprowler/providers/aws/services/cloudwatch/lib/metric_filters.pyviare.search(..., flags=re.DOTALL).Changelog: Entry added under
### 🐞 Fixedinprowler/CHANGELOG.md.Dependencies: None.
Scope: SDK only — no new checks, no API/UI changes, no permission changes.
Steps to review
Pattern logic — In each updated check, confirm
patternuses independent(?=.*<clause>)lookaheads instead ofclause1.+clause2.+.... Each lookahead should match a single CIS/AWS requirement (event name or event source), not depend on position relative to other clauses.Helper unchanged — Skim
metric_filters.pyto confirm behavior is still “all lookaheads must match anywhere in the pattern string”; no change to alarm association logic.Sanity-check regex — Optionally run a quick Python check with sample
filterPatternstrings where clauses are reversed, e.g.:Tests — Run existing CloudWatch metric filter tests:
Or target only the 13 checks listed above.
CHANGELOG — Verify the
5.28.0/ Unreleased entry describes order-independent validation clearly.Checklist
Community Checklist
tests/providers/aws/services/cloudwatch/; no new test files in this PR.)SDK/CLI
UI
API
License
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.