-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Security Solution][Detections] Server-side filtering and sorting POC #126450
Comments
Pinging @elastic/security-detections-response (Team:Detections and Resp) |
Pinging @elastic/security-solution (Team: SecuritySolution) |
✅ Checked rules filtering and sorting by curl --location --request GET 'http://localhost:5601/kbn/api/detection_engine/rules/_find?filter=alert.attributes.params.severity: medium or alert.attributes.params.severity: high' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' curl --location --request GET 'http://localhost:5601/kbn/api/detection_engine/rules/_find?sort_field=severity&sort_order=desc' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' |
✅ Checked rules filtering and sorting by curl --location --request GET 'http://localhost:5601/kbn/api/detection_engine/rules/_find?filter=alert.attributes.params.risk_score > 40 and alert.attributes.params.risk_score < 50' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' curl --location --request GET 'http://localhost:5601/kbn/api/detection_engine/rules/_find?sort_field=risk_score&sort_order=desc' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' |
With regards to filtering by curl --location --request GET 'http://localhost:5601/kbn/api/detection_engine/rules/_find?filter=alert.attributes.params.threat.tactic.name: Exfiltration' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' Gives the following response: {
"message": "This key 'alert.attributes.mapped_params.threat.tactic.name' does NOT exist in alert saved object index patterns: Bad Request",
"status_code": 400
} I checked the above request on a commit before the cc @XavierM Confirmed with @XavierM that it's a bug and converted to an issue: #127876 |
It should be fix!!! |
Checked diff --git a/x-pack/plugins/alerting/server/rules_client/rules_client.ts b/x-pack/plugins/alerting/server/rules_client/rules_client.ts
index 1512959384a..22249dafbc8 100644
--- a/x-pack/plugins/alerting/server/rules_client/rules_client.ts
+++ b/x-pack/plugins/alerting/server/rules_client/rules_client.ts
@@ -783,6 +783,9 @@ export class RulesClient {
muted: {
terms: { field: 'alert.attributes.muteAll' },
},
+ indices: {
+ terms: { field: 'alert.attributes.params.index' },
+ },
},
});
@@ -839,6 +842,11 @@ export class RulesClient {
unmuted: mutedBuckets.find((bucket) => bucket.key === 0)?.doc_count ?? 0,
};
+ ret.ruleIndices = resp.aggregations.indices.buckets.map((bucket) => ({
+ index: bucket.key,
+ rulesCount: bucket.doc_count,
+ }));
+
return ret;
} It allows us to retrieve a list of all index patterns used in detection rules: {
"ruleIndices": [
{
"index": "winlogbeat-*",
"rulesCount": 249
},
{
"index": "logs-windows.*",
"rulesCount": 239
},
{
"index": "logs-endpoint.events.*",
"rulesCount": 208
},
{
"index": "logs-system.*",
"rulesCount": 12
},
{
"index": "auditbeat-*",
"rulesCount": 7
},
{
"index": "filebeat-*",
"rulesCount": 4
},
{
"index": "logs-*",
"rulesCount": 4
},
{
"index": "packetbeat-*",
"rulesCount": 4
},
{
"index": "endgame-*",
"rulesCount": 3
},
{
"index": "apm-*-transaction*",
"rulesCount": 2
}
]
} |
✅ Filtering by curl 'http://localhost:5601/kbn/api/detection_engine/rules/_find?filter=alert.attributes.params.index: winlogbeat-*' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' curl 'http://localhost:5601/kbn/api/detection_engine/rules/_find?filter=alert.attributes.params.threat.tactic.name: Exfiltration' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' |
Epic: https://github.com/elastic/security-team/issues/1972
Summary
Create a POC to verify that we will be able to implement new filters and sorting in the Rules table in the server-side mode. No changes in the UI expected (like adding new filters). We just need some test code on the backend + some test Postman requests to the API to make sure it all works.
Fields we are interested in:
Todo
alert.params.severity
: filtering by a single and multiple values, sorting should sort by its severity level and not alphabeticallyalert.params.riskScore
: range filter, sortingalert.params.index
: filtering by a single and multiple values, aggregations (need to answer the questions "what index patterns do our rules have in the current space" and "how many rules have each given index pattern")alert.params.threat
: filtering by its propertiesThe text was updated successfully, but these errors were encountered: