-
Notifications
You must be signed in to change notification settings - Fork 103
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
Feature findings enhancemnt #1427
Changes from all commits
0d24cb4
ee792d6
40be752
a360cc7
b9d9211
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,9 @@ class TransportGetFindingsSearchAction @Inject constructor( | |
val getFindingsRequest = request as? GetFindingsRequest | ||
?: recreateObject(request) { GetFindingsRequest(it) } | ||
val tableProp = getFindingsRequest.table | ||
val severity = getFindingsRequest.severity | ||
val detectionType = getFindingsRequest.detectionType | ||
val searchString = tableProp.searchString | ||
|
||
val sortBuilder = SortBuilders | ||
.fieldSort(tableProp.sortString) | ||
|
@@ -103,12 +106,74 @@ class TransportGetFindingsSearchAction @Inject constructor( | |
if (!getFindingsRequest.findingId.isNullOrBlank()) | ||
queryBuilder.filter(QueryBuilders.termQuery("_id", getFindingsRequest.findingId)) | ||
|
||
if (!getFindingsRequest.findingIds.isNullOrEmpty()) { | ||
queryBuilder.filter(QueryBuilders.termsQuery("id", getFindingsRequest.findingIds)) | ||
} | ||
|
||
if (getFindingsRequest.monitorId != null) { | ||
queryBuilder.filter(QueryBuilders.termQuery("monitor_id", getFindingsRequest.monitorId)) | ||
} else if (getFindingsRequest.monitorIds.isNullOrEmpty() == false) { | ||
queryBuilder.filter(QueryBuilders.termsQuery("monitor_id", getFindingsRequest.monitorIds)) | ||
} | ||
|
||
if (getFindingsRequest.startTime != null && getFindingsRequest.endTime != null) { | ||
val startTime = getFindingsRequest.startTime!!.toEpochMilli() | ||
val endTime = getFindingsRequest.endTime!!.toEpochMilli() | ||
val timeRangeQuery = QueryBuilders.rangeQuery("timestamp") | ||
.from(startTime) // Greater than or equal to start time | ||
.to(endTime) // Less than or equal to end time | ||
queryBuilder.filter(timeRangeQuery) | ||
} | ||
|
||
if (!detectionType.isNullOrBlank()) { | ||
val nestedQueryBuilder = QueryBuilders.nestedQuery( | ||
"queries", | ||
when { | ||
detectionType.equals("threat", ignoreCase = true) -> { | ||
QueryBuilders.boolQuery().filter( | ||
QueryBuilders.prefixQuery("queries.id", "threat_intel_") | ||
) | ||
} | ||
else -> { | ||
QueryBuilders.boolQuery().mustNot( | ||
QueryBuilders.prefixQuery("queries.id", "threat_intel_") | ||
Comment on lines
+138
to
+139
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason to filter out the threat intel queries here? As a user I would expect the filter to be based on the provided There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I have categorized the detectionType parameter into two types: "threat" and normal rule based. If the frontend API calls the findings API with detectionType set to "threat," all threat intel-related findings will be generated with this query. I'm open to considering alternative solutions for this categorization. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the enum comment I had on the other CR makes this a bit more clear. Having the arbitrary text input + looking for exactly 2 cases seems like it should be enum-based. If we don't expect the detectionType options to expand, then having a boolean field seems more user-friendly to me. Something like Or maybe a new API, say GetThreatIntelFindings, would also make sense to me. Another thought on this - this change is arguably a breaking one. We are changing the default behavior of an existing API to now filter out the threat intel findings. If a user has a system that relies on this API already and they are expecting threat intel findings, then it would break their use case. Is there a way we can explore doing the filtering on the frontend, or at least leaving the default behavior as-is? I'm a bit concerned with merging this at the moment, but open to others' thoughts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missed line 128.. not a breaking change or change to default behavior since filtering is only applied if a detectionType is supplied |
||
) | ||
} | ||
}, | ||
ScoreMode.None | ||
) | ||
|
||
// Add the nestedQueryBuilder to the main queryBuilder | ||
queryBuilder.must(nestedQueryBuilder) | ||
} | ||
|
||
if (!searchString.isNullOrBlank()) { | ||
queryBuilder | ||
.should(QueryBuilders.matchQuery("index", searchString)) | ||
.should( | ||
QueryBuilders.nestedQuery( | ||
"queries", | ||
QueryBuilders.matchQuery("queries.tags", searchString), | ||
ScoreMode.None | ||
) | ||
) | ||
.should(QueryBuilders.regexpQuery("monitor_name", searchString + ".*")) | ||
.minimumShouldMatch(1) | ||
} | ||
|
||
if (!severity.isNullOrBlank()) { | ||
queryBuilder | ||
.must( | ||
QueryBuilders.nestedQuery( | ||
"queries", | ||
QueryBuilders.boolQuery().should( | ||
QueryBuilders.matchQuery("queries.tags", severity) | ||
), | ||
ScoreMode.None | ||
) | ||
) | ||
} | ||
|
||
if (!tableProp.searchString.isNullOrBlank()) { | ||
queryBuilder | ||
.should( | ||
|
@@ -130,7 +195,6 @@ class TransportGetFindingsSearchAction @Inject constructor( | |
) | ||
) | ||
} | ||
|
||
searchSourceBuilder.query(queryBuilder) | ||
|
||
client.threadPool().threadContext.stashContext().use { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is detectionType??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't use this variable .. this is not a keyword in alerting domain.. if it's for security analytics we need to translate it into a jargon or query searchString which is generalized to Alerting plugin?