Skip to content

fix: container/pod inequality filters should not exclude host events#5226

Draft
yanivagman wants to merge 1 commit into
mainfrom
cursor/tracee-issue-5224-cb7b
Draft

fix: container/pod inequality filters should not exclude host events#5226
yanivagman wants to merge 1 commit into
mainfrom
cursor/tracee-issue-5224-cb7b

Conversation

@yanivagman
Copy link
Copy Markdown
Collaborator

1. Explain what the PR does

Resolves #5224. Previously, container/pod-related filters using inequality operators (e.g., podNamespace!=kube-system) implicitly excluded host events. This PR modifies pkg/filters/scope.go::addContainer to only enforce container scope (i.e., require a non-empty container ID) when an equality operator (=) is used. For inequality operators (!=), host events are now correctly allowed to pass through, as their empty container/pod fields will not match the excluded values.

2. Explain how to test it

  1. Verify host events are included with != filter:

    sudo ./tracee --output json --scope podNamespace!=kube-system

    Expected: You should see both container events (from pods not in kube-system) and host events (events with empty Container.ID and Kubernetes fields).

  2. Verify host events are excluded with = filter (existing behavior):

    sudo ./tracee --output json --scope podNamespace=default

    Expected: You should only see container events from pods in the default namespace. Host events should be filtered out.

3. Other comments

Fixes: #5224


Open in Cursor Open in Web

… fields

This fixes an issue where container/pod filters with inequality operators
(!=) implicitly excluded host events.

Previously, when using a filter like 'podNamespace!=kube-system', the
addContainer() function would automatically set containerFilter to
require that events come from containers. This meant host events (which
have empty container/pod fields) would be filtered out.

Now, when using inequality operators (!=), the containerFilter is not
enabled, allowing host events to pass through. Host events have empty
values for container/pod fields, which correctly do not match the
excluded values (e.g., '' != 'kube-system' is true).

Equality operators (=) still require events to come from containers,
as users explicitly want to match specific container/pod values.

Fixes: #5224

Co-authored-by: yaniv <yaniv@aquasec.com>
@cursor
Copy link
Copy Markdown

cursor Bot commented Feb 1, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 1, 2026

Codecov Report

❌ Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 35.50%. Comparing base (235daa0) to head (5ec4035).
⚠️ Report is 179 commits behind head on main.

Files with missing lines Patch % Lines
pkg/filters/scope.go 40.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5226      +/-   ##
==========================================
+ Coverage   33.51%   35.50%   +1.99%     
==========================================
  Files         250      239      -11     
  Lines       28908    31488    +2580     
==========================================
+ Hits         9688    11181    +1493     
- Misses      18609    19591     +982     
- Partials      611      716     +105     
Flag Coverage Δ
unit 35.50% <40.00%> (+1.99%) ⬆️
Files with missing lines Coverage Δ
pkg/filters/scope.go 68.84% <40.00%> (+11.26%) ⬆️

... and 103 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yanivagman yanivagman closed this Feb 1, 2026
@yanivagman yanivagman reopened this Feb 1, 2026
@yanivagman yanivagman changed the title Tracee issue 5224 fix: container/pod inequality filters should not exclude host events Feb 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Container/pods filters implicitly exclude host events

3 participants