Skip to content

🔒 fix(collect): keep field values out of extraction errors - #391

Merged
konih merged 3 commits into
mainfrom
fix/extraction-error-leak
Oct 1, 2026
Merged

konih merged 3 commits into
mainfrom
fix/extraction-error-leak

Conversation

@konih

@konih konih commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

CEL and JSONPath evaluation errors echo the values they evaluate, and the extractor passed them through verbatim into KollectTarget.status.lastExtractionError, the Degraded condition, the ExtractionFailed Warning event, the engine log line and the pipeline ExtractionFailure reason. With a Secret holding data.pw=SUPERSECRETVALUE:

path before
cel:timestamp(object.data.pw) invalid RFC 3339 timestamp "SUPERSECRETVALUE"
cel:object.data[object.data.pw] no such key: SUPERSECRETVALUE
{.data[?(@.x>1)]} map[pw:SUPERSECRETVALUE] is not array or slice…

Anyone with get on the target could read it. Regex redaction downstream can't catch this, so the fix is at the source: internal/collect/extractor.go reduces every evaluation error to the attribute name plus a fixed class (attribute "pw": eval CEL: evaluation error: no such key). It does not wrap the raw error, so unwrapping can't recover it either. The Helm accessor error (which quoted release values) and the Helm JSON decode error get the same treatment. CEL compile and JSONPath parse errors depend only on the expression, so they keep their full detail.

The extractor is the only producer, so this one change covers every sink: status, condition, event, both log paths and the pipeline exit error. Metrics labels were already fixed constants, and matchPolicy eval errors are swallowed.

Risk

Low. Users lose the operand detail in evaluation errors, which was the leak. For debugging they get the attribute name and the class, and can test the expression against the object themselves. Errors that don't match a known class show as unclassified (details withheld…), so a new upstream message format fails closed. This doesn't touch internal/redact.

Testing

  • New tests, red before the fix: internal/collect/extraction_error_leak_test.go covers the extractor (the 3 reported probes plus regex, duration, index and the Helm accessor), the unwrap chain, engine ExtractFailures plus the captured log output, and the runner reason. internal/controller/kollecttarget_extraction_leak_test.go checks status, the Degraded message and events.
  • Compile and parse detail is kept, also covered by a test.
  • go build ./..., task lint, task verify, task scrub pass, and so does go test -race ./cmd/... ./internal/.... internal/sink hit the known ResetBreakersForTest race once and passed on rerun.

konih added 2 commits October 1, 2026 21:21
CEL and JSONPath evaluation errors interpolate the operands they were
evaluating: `no such key: <key>`, `invalid RFC 3339 timestamp "<value>"`,
`map[...] is not array or slice`. The extractor wrapped them verbatim, and
the result fed KollectTarget status.lastExtractionError, the Degraded
condition, the Warning event, the engine log line and the pipeline
ExtractionFailure reason. A profile over Secrets could therefore publish
Secret data to anyone allowed to get the target.

Evaluation errors are now reduced at the extractor to the attribute name
plus a fixed error class; the raw error is not wrapped, so no caller can
recover it by unwrapping. The Helm accessor and JSON decode errors get the
same treatment because they quote release payload. CEL compile and JSONPath
parse errors depend only on the expression and keep their detail.
@codecov

codecov Bot commented Oct 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/collect/extractor.go 91.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

JSONPath `incompatible types for comparison` and CEL `unsupported index
type` are static and data-free, but they fell through to the unclassified
fallback; give them their own class so users can act on them.

Also pin the Helm JSON decode message with a non-JSON release payload:
wrapping the encoding/json error again would quote a payload byte.
@sonarqubecloud

sonarqubecloud Bot commented Oct 1, 2026

Copy link
Copy Markdown

@konih
konih merged commit ebef8a5 into main Oct 1, 2026
41 checks passed
@konih
konih deleted the fix/extraction-error-leak branch October 1, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant