feat: Add matchScript option to matchBinaries selector for shebang script filtering #4602
+973
−12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add support for matching against script paths instead of interpreter paths when filtering shebang scripts. When a script with a shebang (e.g., /path/script.py with #!/usr/bin/python3) is executed, matchBinaries normally matches against the interpreter (/usr/bin/python3). The new matchScript option allows matching against the script path instead.
In this PR you will see two commits:
feat: Add matchScript to matchBinaries for shebang scripts -> Implementation files
chore: Regenerate files -> FIle generated after $ make generate command line
Evidence of the implementation:
1️⃣ Tracing-policy with matchScript: true (new matchBinaries feature added)
Script to run some events:
Tetragon log
🚀 process 9447eedcf851 /tmp/test_script.sh /tmp/test_script.sh 📝 write 9447eedcf851 /tmp/test_script.sh 💥 exit 9447eedcf851 /tmp/test_script.sh /tmp/test_script.sh 02️⃣ Check if the previos implementation with interpreter continue working.
Tracing-policy using matchBinaries
/usr/bin/bashScript to run some events:
Tetragon log:
3️⃣ Test without
matchScriptin the tracingpolicyScript to run some events:
Tetragon log:
4️⃣ Test with
matchScript: falseScript to run some events:
Tetragon log:
Unit test:
Please check the unit test created in this path: pkg/sensors/tracing/matchbinaries_script_test.go