[Security Solution][Entity Analytics][Risk Scoring] Add Risk Scoring Alert Filtering - Backend Implementation#235770
Merged
abhishekbhatia1710 merged 29 commits intoelastic:mainfrom Oct 29, 2025
Conversation
Contributor
|
Pinging @elastic/security-entity-analytics (Team:Entity Analytics) |
natasha-moore-elastic
approved these changes
Sep 26, 2025
jloleysens
approved these changes
Sep 29, 2025
61504ab to
858aead
Compare
Contributor
|
Pinging @elastic/fleet (Team:Fleet) |
Contributor
|
Pinging @elastic/obs-ux-management-team (Team:obs-ux-management) |
Contributor
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
CAWilson94
approved these changes
Oct 15, 2025
Contributor
CAWilson94
left a comment
There was a problem hiding this comment.
Code Review only: LGTM
Contributor
|
@elasticmachine merge upstream |
…com:abhishekbhatia1710/kibana into ea-13606-alert-filtering-risk-score-backend
Contributor
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Async chunks
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
|
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.
🎯 Summary
This PR implements the backend infrastructure for Risk Scoring Alert Filtering, enabling users to apply entity-specific KQL filters during risk score calculations. This enhancement allows for more targeted risk scoring by filtering alerts based on custom criteria.
🚀 What's New
Core Features
Technical Implementation
1. Saved Object Schema Enhancement
filtersfield torisk-engine-configurationsaved object2. Enhanced Risk Scoring Logic
buildFiltersForEntityTypehelper function for entity-specific filter construction@kbn/es-queryutilities3. API Endpoint Updates
🏗️ Architecture
graph TD A[User Configuration] --> B[Risk Engine Saved Object] B --> C[buildFiltersForEntityType] C --> D[KQL Parser] D --> E[Elasticsearch Query] E --> F[Risk Score Aggregation] F --> G[Filtered Results] H[API Request] --> I[Route Handler] I --> J[Risk Score Service] J --> K[calculateRiskScores] K --> C🔧 Filter Processing Flow
sequenceDiagram participant U as User participant API as API Endpoint participant S as Risk Score Service participant F as Filter Builder participant ES as Elasticsearch U->>API: POST /api/risk_scores/preview API->>S: calculateScores(filters) S->>F: buildFiltersForEntityType() F->>F: Parse KQL filters F->>F: Build ES queries F-->>S: Return filters array S->>ES: Execute aggregation with filters ES-->>S: Return filtered results S-->>API: Return risk scores API-->>U: Return response🧪 Testing
Unit Tests Added
buildFiltersForEntityTypefunction testsTest Coverage
📋 API Testing
1. Configure Risk Engine with Filters
Expected Response:
{ "risk_engine_saved_object_configured": true }Get risk engine saved object configuration:
Expected Response:
{ "page": 1, "per_page": 20, "total": 1, "saved_objects": [ { "type": "risk-engine-configuration", "id": "36e6f63d-e5d0-4919-8d41-4988dd708754", "namespaces": [ "default" ], "attributes": { "dataViewId": ".alerts-security.alerts-default", "enabled": false, "filter": {}, "interval": "1h", "pageSize": 3500, "range": { "start": "now-30d", "end": "now" }, "excludeAlertStatuses": [ "closed" ], "_meta": { "mappingsVersion": 5 }, "filters": [ { "entity_types": [ "host" ], "filter": "agent.type: filebeat" }, { "entity_types": [ "user" ], "filter": "user.name: ubuntu" } ] }, "references": [], "managed": false, "migrationVersion": { "risk-engine-configuration": "10.3.0" }, "updated_at": "2025-09-29T06:52:46.483Z", "created_at": "2025-09-26T08:42:58.037Z", "version": "WzExLDFd", "coreMigrationVersion": "8.8.0", "typeMigrationVersion": "10.3.0", "score": 0 } ] }2. Preview Risk Scores with and without Filters
I added 5 alerts for this test
host.name : "pessimistic-permafrost.name"
host.name : "yellowish-minority.info"
user.name : "Roscoe_Stehr-Murazik"
user.name : "Sheridan_MacGyver55"
user.name : "ubuntu"
Without filters
With user filter
With user and host filter
3. Test Invalid KQL Filter Handling
Expected Response: Should return results without the invalid filter applied (graceful degradation)
🔄 Migration Strategy
filtersarray🎯 User Experience Impact
Before
After
🔍 Key Technical Decisions
📝 Related Issues
🚧 Next Steps
This PR implements the backend infrastructure. The frontend UI implementation will follow in a separate PR to:
Note: This is a backend-only implementation. Frontend changes will be delivered in a subsequent PR.