ROX-34071: Add Evaluation Filter to Policy Engine#20760
Open
c-du wants to merge 11 commits into
Open
Conversation
|
Skipping CI for Draft Pull Request. |
Contributor
🚀 Build Images ReadyImages are ready for commit 648fb7b. To use with deploy scripts: export MAIN_IMAGE_TAG=4.12.x-87-g648fb7b1be |
Contributor
🚥 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 docstrings
🧪 Generate unit tests (beta)
Comment |
Contributor
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@pkg/booleanpolicy/filter/filter.go`:
- Around line 19-20: The Apply method should guard against a nil callback to
avoid panics: in EvaluationFilter.Apply, check if f.apply is nil and if so
return the original dep and imgs unchanged; otherwise call and return
f.apply(dep, imgs). Update the Apply implementation (referencing
EvaluationFilter.Apply and the underlying f.apply callback) so a
zero-value/partially built filter becomes a no-op instead of panicking.
In `@pkg/detection/compiled_policy.go`:
- Around line 311-332: applyFilters currently returns changed=true whenever
cp.filters is non-empty; change it to compute whether outputs actually differ by
comparing the resulting dep and imgs to the inputs (e.g., check pointer/identity
or deep-equality on deployment and images slice contents) and only return true
when dep or imgs differ; in applyImageFilters, when ed.Images is empty treat
that as the image being removed and return (nil, true) instead of returning the
original image so image-exclusion filters are honored; keep
NetworkPoliciesApplied copied from the original ed and ensure equality
comparison logic handles both length and element differences so cache
invalidation only happens on real changes.
🪄 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: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: 0683b4b2-39db-4e59-a567-a286a0e5800b
⛔ Files ignored due to path filters (7)
central/graphql/resolvers/gen/main.gois excluded by!**/gen/**generated/api/v1/alert_service.swagger.jsonis excluded by!**/generated/**generated/api/v1/detection_service.swagger.jsonis excluded by!**/generated/**generated/api/v1/policy_service.swagger.jsonis excluded by!**/generated/**generated/storage/policy.pb.gois excluded by!**/*.pb.go,!**/generated/**generated/storage/policy_vtproto.pb.gois excluded by!**/*.pb.go,!**/generated/**proto/storage/proto.lockis excluded by!**/*.lock
📒 Files selected for processing (17)
central/policy/customresource/policy.gocentral/policy/handlers/handler.gocentral/policy/service/service_impl.gopkg/booleanpolicy/filter/compile.gopkg/booleanpolicy/filter/compile_test.gopkg/booleanpolicy/filter/filter.gopkg/booleanpolicy/filter/filter_test.gopkg/booleanpolicy/filter/testutils.gopkg/booleanpolicy/image_criteria_test.gopkg/booleanpolicy/matcher.gopkg/booleanpolicy/matcher_impl.gopkg/booleanpolicy/runtime_criteria_test.gopkg/booleanpolicy/workload_criteria_test.gopkg/detection/compiled_policy.gopkg/detection/runtime/detector.gopkg/features/list.goproto/storage/policy.proto
AlexVulaj
approved these changes
Jun 8, 2026
dashrews78
reviewed
Jun 8, 2026
| import "github.com/stackrox/rox/generated/storage" | ||
|
|
||
| // NewTestFilter creates an EvaluationFilter from a callback for use in tests. | ||
| func NewTestFilter(fn func(*storage.Deployment, []*storage.Image) (*storage.Deployment, []*storage.Image)) EvaluationFilter { |
Contributor
There was a problem hiding this comment.
Should we require a test context? Or move it to a test package?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Adds EvaluationFilter to policy engine that allows policies to pre-filter entities before policy evaluation.
This PR introduces the policy engine change only — concrete filter implementations will follow in a separate PR.
Key decisions:
EvaluationFilterfor each feature which is a struct withisNonDefaultandapplyfunction fields, composed via slices. TCompileEvaluationFilteris calledin
newCompiledPolicyand the result is stored oncompiledPolicy.Matchers are filter-unaware — filtering happens in
MatchAgainst*methods beforedelegating.
ROX_EVALUATION_FILTER(disabled bydefault).
EvaluationFiltermessage has no fields yet.Fields for base image and container types will be added in the
follow-up PR.
User-facing documentation
Testing and quality
GA, or
otherwise the functionality is gated by a [feature flag](https://github.
com/stackrox/stackrox/blob/master/pkg/features/README.md)
[inspected](https://docs.google.com/document/d/1d5ga073jkv4CO1kAJqp8MPGp
C6E1bwyrCGZ7S5wKg3w/edit?tab=t.0#heading=h.w4ercgtcg0xp)
Automated testing
Testing and quality
How I validated my change
pkg/booleanpolicy/filter/pkg/booleanpolicy/exercise filters end-to-end throughthe matcher
runtime_criteria_test.goupdated forMatchKubeEventsignature changechange me!