Skip to content
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

Findings API Enhancements changes and integ tests fix #1464

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class RestGetFindingsAction : BaseRestHandler() {
val size = request.paramAsInt("size", 20)
val startIndex = request.paramAsInt("startIndex", 0)
val searchString = request.param("searchString", "")
val severity: String? = request.param("severity", "ALL")
val detectionType: String? = request.param("detectionType", "rules")

val table = Table(
sortOrder,
Expand All @@ -59,9 +57,7 @@ class RestGetFindingsAction : BaseRestHandler() {

val getFindingsSearchRequest = GetFindingsRequest(
findingID,
table,
severity,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we removing severity??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to change the behavior of existing Alerting Plugin API]. This was the part of prev commit which was merged.

detectionType
table
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we aren't resolving boolQueryBuilder param?

Copy link
Collaborator Author

@riysaxen-amzn riysaxen-amzn Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to

)
return RestChannelConsumer {
channel ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ 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
Expand Down Expand Up @@ -125,7 +123,8 @@ class TransportGetFindingsSearchAction @Inject constructor(
queryBuilder.filter(timeRangeQuery)
}

if (!detectionType.isNullOrBlank()) {
if (!getFindingsRequest.detectionType.isNullOrBlank()) {
Copy link
Member

@eirsep eirsep Mar 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is detectionType?
in alerting this has no meaning?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes In alerting it has no meannig but we need to filter the SA findings based on the detectionType [threat intel or rule based], this will query on .opensearch-sap-*-findings index to do that. I'm open to other suggestions if this is wrong or if we've a better way to do this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass querybuilder as param in findings request

val detectionType = getFindingsRequest.detectionType
val nestedQueryBuilder = QueryBuilders.nestedQuery(
"queries",
when {
Expand Down Expand Up @@ -161,7 +160,8 @@ class TransportGetFindingsSearchAction @Inject constructor(
.minimumShouldMatch(1)
}

if (!severity.isNullOrBlank()) {
if (!getFindingsRequest.severity.isNullOrBlank()) {
val severity = getFindingsRequest.severity
queryBuilder
.must(
QueryBuilders.nestedQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2119,8 +2119,10 @@ class DocumentMonitorRunnerIT : AlertingRestTestCase() {

val findings = searchFindings(monitor)
assertEquals("Findings saved for test monitor", 2, findings.size)
assertTrue("Findings saved for test monitor", findings[0].relatedDocIds.contains("1"))
assertTrue("Findings saved for test monitor", findings[1].relatedDocIds.contains("5"))
val findings0 = findings[0].relatedDocIds.contains("1") || findings[0].relatedDocIds.contains("5")
val findings1 = findings[1].relatedDocIds.contains("5") || findings[1].relatedDocIds.contains("1")
assertTrue("Findings saved for test monitor", findings0)
assertTrue("Findings saved for test monitor", findings1)
}

fun `test document-level monitor when index alias contain docs that do match a NOT EQUALS query and EXISTS query`() {
Expand Down
Loading