ROX-33034: Track xattr changes#790
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds end-to-end tracking of ChangesXattr tracking feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #790 +/- ##
==========================================
- Coverage 32.72% 32.23% -0.50%
==========================================
Files 21 21
Lines 2695 2736 +41
Branches 2695 2736 +41
==========================================
Hits 882 882
- Misses 1810 1851 +41
Partials 3 3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@fact-ebpf/src/bpf/main.c`:
- Around line 434-443: The trace_inode_removexattr function has an unreachable
return statement. After the return handle_xattr(...) call on line 441, there is
a duplicate return 0; statement that serves as dead code. Remove the duplicate
return 0; statement that appears after the handle_xattr return, keeping only the
return handle_xattr(...) line to ensure the function properly returns the result
of the xattr handler call.
🪄 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: Path: .coderabbit.yml
Review profile: CHILL
Plan: Enterprise
Run ID: 461c91e6-bfc7-42e7-97f6-99a4157926c8
📒 Files selected for processing (8)
fact-ebpf/src/bpf/events.hfact-ebpf/src/bpf/main.cfact-ebpf/src/bpf/types.hfact-ebpf/src/lib.rsfact/src/event/mod.rsfact/src/host_scanner.rsfact/src/metrics/kernel_metrics.rstests/test_inode_xattr.py
Molter73
left a comment
There was a problem hiding this comment.
As discussed offline, we should make the protobuf changes for supporting xattr as part of these changes, so I expect some changes incoming.
There are also 2 small comments on the eBPF code.
7e93fef to
dd9da9b
Compare
Molter73
left a comment
There was a problem hiding this comment.
Overall looks good. There's a small comment on the operation field which shouldn't be there, that kind of information should be encoded in the type system.
The integration tests need a bit of work.
| # In strict mode, fail when the event type matches but | ||
| # the content differs. Events of a different type are | ||
| # skipped since they may be system noise that the test | ||
| # cannot predict (e.g. SELinux xattr changes). | ||
| if 'event_type' not in diff: | ||
| raise ValueError(json.dumps(diff, indent=4)) |
There was a problem hiding this comment.
Does this mean that now any test can just have random noise from xattr changes? Why is that? Are we certain it is random or is it that there already were xattr changes we were not seeing when the original tests were written and are now being emitted? Since the tests limit themselves to monitoring a single empty directory I find it very hard to believe events emitted are random.
In any case, we need to either:
- Check what the new events in tests are, whether they truly are random and, if they are not, add any missing events to the sequence of events on the existing tests.
- If the events truly are random, double check if we are not emitting events that we shouldn't be emitting and figure out a way to disable xattr events for tests to reduce noise.
As is, this check will probably lead to some hard to understand errors due to events being skipped when they shouldn't. strict mode means STRICT MODE, there should be no room for speculation when using this.
There was a problem hiding this comment.
I have reverted the change to strict mode, but I have added the option to skip xattr events.
There was a problem hiding this comment.
I will write a more complete response later.
There was a problem hiding this comment.
These events are not random. It is dockerd adding the xattr security.selinux to monitored files and directories. Previously we did not see these events and now they are seen. Looking for these events may be flaky since it depends upon the environment. dockerd does not set this xattr when I run locally. I have a PR where all xattr events are expected and the tests pass in my local environment where they do not occur. The tests check if docker reports that SELinux is enabled and adjusts expected events accordingly. #864
Let me know if you prefer the method here or in the other PR.
4770b44 to
5291250
Compare
217813a to
e49f9f7
Compare
516b9ce Added tests 14b3c0e Added tracking for xattr changes 66b12e6 Combined calls to BPF_CORE_READ 57d9c33 Clarified comment that the path is not available. Also clarified relevant code 8adfb4a Added helper to reduce dry a5aef53 Added events.h which had been forgotten c2c57ad Fix format 8303156 Removed unreachable return 02e93c0 Fixed format again 57d2c15 Renamed test_inode_xattr.py to test_xattr.py 40577b5 Tests now check gRPC messages instead of metrics c619cab Fact now sends xattr events as gRPC messages c00d7a0 Added parameterized UTF-8 tests 456765d Test are more forgiving of extra node events fcfeb36 Validating the path in __submit_event instead of setting it in xattr LSM hooks 6dee60f Added link to XATTR_NAME_MAX 9b43401 Tests ignore events of unexpected type e35705d Updated protobuf definitions cc396b5 Reverted changes to strict event comparison mode 0234c34 Added xattr changes e96c4c6 Undid changes to tests/test_path_rename.py 28573a3 Optionally skipping xattr events 8b078be make format f10ed18 Add os.removexattr to test_setxattr_multiple dfbb920 Extended test_setxattr_ignored with removexattr and renamed it 61e6e06 Added os.removexattr to test_setxattr_new_file test_xattr_utf8_filenames and renamed them 5291250 Added a test that paramertizes the xattr name 217813a Updated stackrox
a4a89b3 to
24c4c6a
Compare
Description
Adds tracking for setting and removing xattr. For now this only adds metrics for xattr events. In the future gRPC messages will be sent to sensor when these event occur. Sending gRPC messages to sensor will require changes to the stackrox/stackrox protobuf definitions and will be done later. The added integration tests rely on metrics. Once gRPC messages are sent the integration tests will not check the metrics and will instead check the gRPC messages.
A change was made to relax the success criteria of
_wait_eventsused by the integration tests. Events of unexpected type are now ignored. This change was needed, because xattr changes are made by SELinux in many of the tests.Protobuf changes are made at stackrox/stackrox#21148
Checklist
Automated testing
If any of these don't apply, please comment below.
Testing Performed
CI is sufficient
Summary by CodeRabbit
Release Notes
New Features
Tests