Skip to content

fix(cloud-security): make CloudWatch metric-filter auto-fix reliable#3050

Merged
tofikwest merged 1 commit into
mainfrom
tofik/aws-metric-filter-autofix
Jun 5, 2026
Merged

fix(cloud-security): make CloudWatch metric-filter auto-fix reliable#3050
tofikwest merged 1 commit into
mainfrom
tofik/aws-metric-filter-autofix

Conversation

@tofikwest
Copy link
Copy Markdown
Contributor

@tofikwest tofikwest commented Jun 5, 2026

Summary

Customer (aymenrc) reported AWS auto-fix falling back to manual steps with "required parameters were not properly provided… metric transformations were not properly provided to the CloudWatch Logs API" on the CIS CloudWatch metric-filter checks (e.g. "CloudTrail config changes — metric filter missing").

That finding is meant to be auto-fixable — the fix is three standard API calls (logs:PutMetricFilter + sns:CreateTopic + cloudwatch:PutMetricAlarm, cloudwatch.adapter.ts:155), not [MANUAL]. So this is a bug, not an inherently-manual finding.

Root cause

PutMetricFilterCommand was not in the executor's REQUIRED_PARAMS, so a step with a missing or mis-shaped metricTransformations wasn't caught before execution — it went to AWS, got rejected, and the system fell back to manual steps. The model commonly emits metricTransformations as a single object instead of an array, or metricValue as the number 1 instead of "1" — both of which AWS rejects.

Fix

  • aws-command-executor.ts
    • Add PutMetricFilterCommand to REQUIRED_PARAMS (logGroupName, filterName, filterPattern, metricTransformations) → a missing field now fails fast and triggers the existing AI repair pass instead of dumping to manual steps.
    • Add normalizeMetricFilterTransformations (Rule 5 in normaliseInputParams): wrap a single transformation object in an array, and coerce metricValue to a string. Deterministic guardrail before the SDK call (mirrors the Config-recorder guardrail).
  • ai-remediation.prompt.ts: explicit PutMetricFilter shape guidance — metricTransformations as an array, string metricValue, real logGroupName from the read step.
  • Tests: REQUIRED_PARAMS enforcement + normalizer cases (object→array, number→string, well-formed untouched, absent no-op).

Notes / caveats

  • It's auto-fixable in principle; this makes it reliable instead of an intermittent coin-flip.
  • Not yet verified against a live failing finding (no server-side failed-plan for the customer's org) — this addresses the whole failure class, which covers the reported symptom. The exact malformation would be confirmable from his remediation logs.
  • Edge case worth knowing: if a trail has no CloudWatch Logs group at all, there's nothing to attach a metric filter to — that's a genuine setup prerequisite, separate from this bug.

Full cloud-security suite green (310 passing); changed files typecheck clean.

🤖 Generated with Claude Code


Summary by cubic

Fixes unreliable auto-fix for CloudWatch Logs metric filters by validating required params and normalizing metricTransformations, preventing fallbacks to manual steps on CIS checks.

  • Bug Fixes
    • Add PutMetricFilterCommand to REQUIRED_PARAMS (logGroupName, filterName, filterPattern, metricTransformations) to fail early and trigger the repair pass.
    • Add normalizeMetricFilterTransformations to wrap a single object into an array and coerce metricValue to a string.
    • Update ai-remediation.prompt.ts with explicit PutMetricFilter shape guidance and using the real logGroupName from the read step.
    • Add tests for required params and normalization (object→array, number→string, pass-through, absent no-op).

Written for commit 837ecde. Summary will update on new commits.

Review in cubic

Customer (aymenrc) reported AWS auto-fix falling back to manual steps with
"required parameters were not properly provided… metric transformations were
not properly provided to the CloudWatch Logs API" on the CIS CloudWatch
metric-filter checks. That finding IS meant to be auto-fixable (PutMetricFilter
+ CreateTopic + PutMetricAlarm — all standard API calls), so this is a bug, not
an inherently-manual finding.

Root cause: PutMetricFilterCommand was absent from REQUIRED_PARAMS, so a step
with a missing/mis-shaped `metricTransformations` wasn't caught before
execution — it went to AWS, got rejected, and fell back to manual steps. The
model commonly emits metricTransformations as a single object instead of an
array, or metricValue as the number 1 instead of "1", both of which AWS rejects.

- aws-command-executor: add PutMetricFilterCommand to REQUIRED_PARAMS
  (logGroupName, filterName, filterPattern, metricTransformations) so a missing
  field fails fast and triggers the existing AI repair pass; and add a
  deterministic normalizer (normalizeMetricFilterTransformations) that wraps a
  single transformation object in an array and coerces metricValue to a string.
- ai-remediation.prompt: explicit PutMetricFilter shape guidance
  (metricTransformations array, string metricValue, real logGroupName).
- Tests: REQUIRED_PARAMS enforcement + normalizer cases.

Full cloud-security suite green (310 passing); changed files typecheck clean.
Not yet verified against a live failing finding — covers the failure class.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
comp-framework-editor Ready Ready Preview, Comment Jun 5, 2026 9:46pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
app Skipped Skipped Jun 5, 2026 9:46pm
portal Skipped Skipped Jun 5, 2026 9:46pm

Request Review

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@tofikwest tofikwest merged commit e9c201f into main Jun 5, 2026
11 checks passed
@tofikwest tofikwest deleted the tofik/aws-metric-filter-autofix branch June 5, 2026 22:10
@claudfuen
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.73.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants