fix: remove syscalls from isEmpty() to prevent 0-CVE overwrites#757
fix: remove syscalls from isEmpty() to prevent 0-CVE overwrites#757
Conversation
PR #745 added `cd.syscalls != nil` to isEmpty(), which caused container profile snapshots to be saved whenever new syscalls accumulated — even with no new file opens. These syscall-only snapshots produce 0 relevant CVEs when scanned by kubevuln (which matches file opens, not syscalls), and the 0-CVE result overwrites the previously-correct filtered VulnerabilityManifest. Syscalls are still saved when other events (opens, execs, etc.) trigger a save, so no syscall data is lost. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Ben <ben@armosec.io>
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pkg/containerprofilemanager/v1/container_data_test.go`:
- Around line 106-108: Update the stale test comment in
TestIsEmpty_StatusChangeTriggersFirstSave to reflect the actual values used in
the test (status/completion are set to Ready/Full), not "" to "Learning"; locate
the comment immediately above the TestIsEmpty_StatusChangeTriggersFirstSave
function and change its description to state that the status/completion changes
to Ready/Full and that this triggers the first profile save, so the comment
matches the test behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d0778482-398c-4e2a-ba1b-02188347e263
📒 Files selected for processing (2)
pkg/containerprofilemanager/v1/container_data.gopkg/containerprofilemanager/v1/container_data_test.go
💤 Files with no reviewable changes (1)
- pkg/containerprofilemanager/v1/container_data.go
| // TestIsEmpty_StatusChangeTriggersFirstSave verifies that a status change | ||
| // (from "" to "Learning") correctly triggers the first profile save. | ||
| func TestIsEmpty_StatusChangeTriggersFirstSave(t *testing.T) { |
There was a problem hiding this comment.
Update stale test comment to match actual status values
The comment says the status changes from "" to "Learning", but the test sets status/completion to Ready/Full. Please align the comment text to avoid confusion.
✏️ Suggested comment fix
-// TestIsEmpty_StatusChangeTriggersFirstSave verifies that a status change
-// (from "" to "Learning") correctly triggers the first profile save.
+// TestIsEmpty_StatusChangeTriggersFirstSave verifies that a status/completion
+// change (from empty last-reported values to current Ready/Full) triggers
+// the first profile save.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // TestIsEmpty_StatusChangeTriggersFirstSave verifies that a status change | |
| // (from "" to "Learning") correctly triggers the first profile save. | |
| func TestIsEmpty_StatusChangeTriggersFirstSave(t *testing.T) { | |
| // TestIsEmpty_StatusChangeTriggersFirstSave verifies that a status/completion | |
| // change (from empty last-reported values to current Ready/Full) triggers | |
| // the first profile save. | |
| func TestIsEmpty_StatusChangeTriggersFirstSave(t *testing.T) { |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@pkg/containerprofilemanager/v1/container_data_test.go` around lines 106 -
108, Update the stale test comment in TestIsEmpty_StatusChangeTriggersFirstSave
to reflect the actual values used in the test (status/completion are set to
Ready/Full), not "" to "Learning"; locate the comment immediately above the
TestIsEmpty_StatusChangeTriggersFirstSave function and change its description to
state that the status/completion changes to Ready/Full and that this triggers
the first profile save, so the comment matches the test behavior.
|
fixed with kubescape/operator#362 |
Summary
cd.syscalls != niltoisEmpty(), causing syscall-only container profile snapshots to be saved. These snapshots have no file opens, so kubevuln finds 0 relevant CVEs and overwrites the filtered VulnerabilityManifest — destroying previously-correct results.cd.syscallsfromisEmpty(). Syscalls are still saved when other events (opens, execs, etc.) trigger a save, so no data is lost.Root cause
After
emptyEvents()clears all data on save, running processes regenerate syscalls within milliseconds (read,write,epoll_wait, etc.). With the PR #745 change,isEmpty()returnsfalse→ profile saved withopens=nil→ kubevuln matches 0 files → overwrites filtered VM with 0 CVEs.This caused the
relevant_data_is_appendedE2E test to fail 5/5 times (redis-sleep test: CVEs drop from 57 to 0 after redis-server starts generating steady-state syscalls).Test plan
go test ./pkg/containerprofilemanager/v1/ -run TestIsEmpty -v— all 4 new tests passgo test ./pkg/containerprofilemanager/... -v -count=1— all existing tests pass (no regression)relevant_data_is_appendedshould pass with this fix🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests