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

get all findings as part of findings API enhancement #803

Conversation

riysaxen-amzn
Copy link
Collaborator

@riysaxen-amzn riysaxen-amzn commented Jan 16, 2024

Description

  • As part of the commit ->
  1. The query params detector_id and detectorType have become optional for the findings/_search API. As part of the enhancement, the API can now return all the findings for all the detectors.
  2. Added new params severity and detectionType in findings API
  3. Added corresponding integration tests for the above functionality

Corresponding Alerting and Common-Utils PRs

Issues Resolved

#795

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link

codecov bot commented Jan 16, 2024

Codecov Report

Attention: Patch coverage is 0% with 41 lines in your changes are missing coverage. Please review.

Project coverage is 24.76%. Comparing base (75c4429) to head (2ffe265).
Report is 1 commits behind head on main.

❗ Current head 2ffe265 differs from pull request most recent head e967376. Consider uploading reports for the commit e967376 to get more accurate results

Files Patch % Lines
...nalytics/transport/TransportGetFindingsAction.java 0.00% 40 Missing ⚠️
...h/securityanalytics/action/GetFindingsRequest.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #803      +/-   ##
============================================
- Coverage     24.97%   24.76%   -0.22%     
+ Complexity     1043     1027      -16     
============================================
  Files           277      277              
  Lines         12771    12722      -49     
  Branches       1391     1402      +11     
============================================
- Hits           3190     3150      -40     
  Misses         9307     9307              
+ Partials        274      265       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@eirsep
Copy link
Member

eirsep commented Jan 18, 2024

i am not sure this design is correct or maybe i have grossly misunderstood the approach.

Can you add a detailed approach of how findings from detectors of all log types are being fetched?

eirsep
eirsep previously requested changes Jan 18, 2024
Copy link
Member

@eirsep eirsep left a comment

Choose a reason for hiding this comment

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

i am not sure this design is correct or maybe i have grossly misunderstood the approach.

Can you add a detailed approach of how findings from detectors of all log types are being fetched?

@riysaxen-amzn
Copy link
Collaborator Author

riysaxen-amzn commented Jan 18, 2024

i am not sure this design is correct or maybe i have grossly misunderstood the approach.

Can you add a detailed approach of how findings from detectors of all log types are being fetched?

So, the idea is first to get all the detectors using matchAllQuery [TransportGetFindingsAction.java#L190]. Now to get the findings for all these detectors for all the logTypes, we can search query on index-pattern .opensearch-sap-*-findings, this will give us all the findings for all the LogTypes [TransportGetFindingsAction.java#L143]

public void onFailure(Exception e) {
findingsService.getFindings(
detectors,
request.getLogType() == null ? "*" : request.getLogType(),
Copy link
Member

Choose a reason for hiding this comment

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

how is findings service already handling "*"? I don't see a change in FIndingsService class in this PR

@eirsep
Copy link
Member

eirsep commented Jan 18, 2024

i am not sure this design is correct or maybe i have grossly misunderstood the approach.
Can you add a detailed approach of how findings from detectors of all log types are being fetched?

So, the idea is first to get all the detectors using matchAllQuery [TransportGetFindingsAction.java#L190]. Now to get the findings for all these detectors for all the logTypes, we can search query on index-pattern .opensearch-sap-*-findings, this will give us all the findings for all the LogTypes [TransportGetFindingsAction.java#L143]

Gotcha! thank you. I wasn't aware that we already are searching on the "all finding indices pattern"

Can you create 2 detectors for different log types and test fetching findings for only one of the log types and verify that behaviour is correct?

@riysaxen-amzn
Copy link
Collaborator Author

i am not sure this design is correct or maybe i have grossly misunderstood the approach.
Can you add a detailed approach of how findings from detectors of all log types are being fetched?

So, the idea is first to get all the detectors using matchAllQuery [TransportGetFindingsAction.java#L190]. Now to get the findings for all these detectors for all the logTypes, we can search query on index-pattern .opensearch-sap-*-findings, this will give us all the findings for all the LogTypes [TransportGetFindingsAction.java#L143]

Gotcha! thank you. I wasn't aware that we already are searching on the "all finding indices pattern"

Can you create 2 detectors for different log types and test fetching findings for only one of the log types and verify that behaviour is correct?

this test is creating detectors of two different logTypes and verifying the behavior -> https://github.com/opensearch-project/security-analytics/pull/803/files#diff-d37f0c96e5ab58c9a80449652179f36f9696044aa275fc7c7f33ce2677fa6793

engechas
engechas previously approved these changes Mar 6, 2024
Comment on lines +55 to +63
if (startTimeParam != null && !startTimeParam.isEmpty()) {
try {
startTime = Instant.ofEpochMilli(Long.parseLong(startTimeParam));
} catch (NumberFormatException | NullPointerException | DateTimeException e) {
// Handle the parsing error
// For example, log the error or provide a default value
startTime = Instant.now(); // Default value or fallback
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor - could create a private method for this to avoid the duplication with the endTime parsing

jowg-amazon
jowg-amazon previously approved these changes Mar 9, 2024
Copy link
Collaborator

@jowg-amazon jowg-amazon left a comment

Choose a reason for hiding this comment

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

LGTM

@jowg-amazon
Copy link
Collaborator

Fix merge conflicts + make sure CI's pass

@riysaxen-amzn riysaxen-amzn dismissed stale reviews from jowg-amazon and engechas via 5a80380 March 9, 2024 01:08
sbcd90
sbcd90 previously approved these changes Mar 10, 2024
@riysaxen-amzn riysaxen-amzn dismissed stale reviews from sbcd90 and praveensameneni via 8a7c3d8 March 11, 2024 04:04
sbcd90 and others added 2 commits March 11, 2024 05:15
@riysaxen-amzn riysaxen-amzn merged commit 0d1d599 into opensearch-project:main Mar 11, 2024
3 of 16 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-803-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 0d1d599fea536ee2afe088f70ee1980a0ec572fe
# Push it to GitHub
git push --set-upstream origin backport/backport-803-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-803-to-2.x.

@jowg-amazon jowg-amazon mentioned this pull request Mar 13, 2024
5 tasks
jowg-amazon pushed a commit to jowg-amazon/security-analytics that referenced this pull request Mar 14, 2024
…ect#803)

* get all findings as part of findings API enhancement

Signed-off-by: Riya Saxena <[email protected]>

* findingsAPI feature enhancements (address comments to prev PR)

Signed-off-by: Riya Saxena <[email protected]>

* findingsAPI feature enhancements (address comments to prev PR)

Signed-off-by: Riya Saxena <[email protected]>

* added support for  param in Finding API

Signed-off-by: Riya Saxena <[email protected]>

* added detectionType as param for Findings API enhancements

Signed-off-by: Riya Saxena <[email protected]>

* added few tests to validate findings by params

Signed-off-by: Riya Saxena <[email protected]>

* added test for searchString param in FindingsAPI

Signed-off-by: Riya Saxena <[email protected]>

* adding addiional params findingIds, startTime and endTime as findings API enhancement

Signed-off-by: Riya Saxena <[email protected]>

* added params in getFindingsByDetectorId func

* changed the startTime and endTime req input format

* fix merge conflixt

* fix integ test failures in findings API

* fix integ tests

* fix integ tests for findings

Signed-off-by: Subhobrata Dey <[email protected]>

---------

Signed-off-by: Riya Saxena <[email protected]>
Signed-off-by: Riya <[email protected]>
Signed-off-by: Subhobrata Dey <[email protected]>
Co-authored-by: Subhobrata Dey <[email protected]>
jowg-amazon added a commit that referenced this pull request Mar 15, 2024
* get all findings as part of findings API enhancement (#803)

* get all findings as part of findings API enhancement

Signed-off-by: Riya Saxena <[email protected]>

* findingsAPI feature enhancements (address comments to prev PR)

Signed-off-by: Riya Saxena <[email protected]>

* findingsAPI feature enhancements (address comments to prev PR)

Signed-off-by: Riya Saxena <[email protected]>

* added support for  param in Finding API

Signed-off-by: Riya Saxena <[email protected]>

* added detectionType as param for Findings API enhancements

Signed-off-by: Riya Saxena <[email protected]>

* added few tests to validate findings by params

Signed-off-by: Riya Saxena <[email protected]>

* added test for searchString param in FindingsAPI

Signed-off-by: Riya Saxena <[email protected]>

* adding addiional params findingIds, startTime and endTime as findings API enhancement

Signed-off-by: Riya Saxena <[email protected]>

* added params in getFindingsByDetectorId func

* changed the startTime and endTime req input format

* fix merge conflixt

* fix integ test failures in findings API

* fix integ tests

* fix integ tests for findings

Signed-off-by: Subhobrata Dey <[email protected]>

---------

Signed-off-by: Riya Saxena <[email protected]>
Signed-off-by: Riya <[email protected]>
Signed-off-by: Subhobrata Dey <[email protected]>
Co-authored-by: Subhobrata Dey <[email protected]>

* fix integ test (#918)

Signed-off-by: Joanne Wang <[email protected]>

* Feature findings api enhancements (#914)

* get all findings as part of findings API enhancement

Signed-off-by: Riya Saxena <[email protected]>

* findingsAPI feature enhancements (address comments to prev PR)

Signed-off-by: Riya Saxena <[email protected]>

* findingsAPI feature enhancements (address comments to prev PR)

Signed-off-by: Riya Saxena <[email protected]>

* added support for  param in Finding API

Signed-off-by: Riya Saxena <[email protected]>

* added detectionType as param for Findings API enhancements

Signed-off-by: Riya Saxena <[email protected]>

* added few tests to validate findings by params

Signed-off-by: Riya Saxena <[email protected]>

* added test for searchString param in FindingsAPI

Signed-off-by: Riya Saxena <[email protected]>

* adding addiional params findingIds, startTime and endTime as findings API enhancement

Signed-off-by: Riya Saxena <[email protected]>

* added params in getFindingsByDetectorId func

* changed the startTime and endTime req input format

* fix merge conflixt

* fix integ test failures in findings API

* fix integ tests

* refactored the logic

Signed-off-by: Riya Saxena <[email protected]>

* remove unused imports

* address the pr comments

Signed-off-by: Riya Saxena <[email protected]>

* address pr comments

Signed-off-by: Riya Saxena <[email protected]>

* SA integ tests fix

* SA integ tests fix

* fix integ tests for findings

Signed-off-by: Subhobrata Dey <[email protected]>

* fix conflixt errors

Signed-off-by: Riya Saxena <[email protected]>

* fix conflixt errors

Signed-off-by: Riya Saxena <[email protected]>

* fix conflixt errors

Signed-off-by: Riya Saxena <[email protected]>

* fix conflixt errors

Signed-off-by: Riya Saxena <[email protected]>

* fix integ tests

Signed-off-by: Riya Saxena <[email protected]>

* fix integ tests

Signed-off-by: Riya Saxena <[email protected]>

* fix integ tests

Signed-off-by: Riya Saxena <[email protected]>

* fix flaky integ tests

Signed-off-by: Riya Saxena <[email protected]>

* address pr comments

Signed-off-by: Riya Saxena <[email protected]>

---------

Signed-off-by: Riya Saxena <[email protected]>
Signed-off-by: Riya <[email protected]>
Signed-off-by: Subhobrata Dey <[email protected]>
Co-authored-by: Subhobrata Dey <[email protected]>

---------

Signed-off-by: Riya Saxena <[email protected]>
Signed-off-by: Riya <[email protected]>
Signed-off-by: Subhobrata Dey <[email protected]>
Signed-off-by: Joanne Wang <[email protected]>
Co-authored-by: Riya <[email protected]>
Co-authored-by: Subhobrata Dey <[email protected]>
jowg-amazon pushed a commit to jowg-amazon/security-analytics that referenced this pull request Mar 15, 2024
…ect#803)

* get all findings as part of findings API enhancement

Signed-off-by: Riya Saxena <[email protected]>

* findingsAPI feature enhancements (address comments to prev PR)

Signed-off-by: Riya Saxena <[email protected]>

* findingsAPI feature enhancements (address comments to prev PR)

Signed-off-by: Riya Saxena <[email protected]>

* added support for  param in Finding API

Signed-off-by: Riya Saxena <[email protected]>

* added detectionType as param for Findings API enhancements

Signed-off-by: Riya Saxena <[email protected]>

* added few tests to validate findings by params

Signed-off-by: Riya Saxena <[email protected]>

* added test for searchString param in FindingsAPI

Signed-off-by: Riya Saxena <[email protected]>

* adding addiional params findingIds, startTime and endTime as findings API enhancement

Signed-off-by: Riya Saxena <[email protected]>

* added params in getFindingsByDetectorId func

* changed the startTime and endTime req input format

* fix merge conflixt

* fix integ test failures in findings API

* fix integ tests

* fix integ tests for findings

Signed-off-by: Subhobrata Dey <[email protected]>

---------

Signed-off-by: Riya Saxena <[email protected]>
Signed-off-by: Riya <[email protected]>
Signed-off-by: Subhobrata Dey <[email protected]>
Co-authored-by: Subhobrata Dey <[email protected]>
jowg-amazon added a commit that referenced this pull request Mar 15, 2024
* support object fields in aggregation based sigma rules (#789)

Signed-off-by: Subhobrata Dey <[email protected]>

* Fix duplicate ecs mappings which returns incorrect log index field in mapping view API (#786) (#788)

* field mapping changes

Signed-off-by: Joanne Wang <[email protected]>

* add integ test

Signed-off-by: Joanne Wang <[email protected]>

* turn unmappedfieldaliases as set and add integ test

Signed-off-by: Joanne Wang <[email protected]>

* add comments

Signed-off-by: Joanne Wang <[email protected]>

* fix integ tests

Signed-off-by: Joanne Wang <[email protected]>

* moved logic to method for better readability

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>

* Fix get mappings view API incorrectly returning ecs path (#867)

* add logic and integ tests to not add duplicate to log-types-config index

Signed-off-by: Joanne Wang <[email protected]>

* change naming for existingFieldMapping and change contains to equals

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>

* fix integ test (#918)

Signed-off-by: Joanne Wang <[email protected]>

* get all findings as part of findings API enhancement (#803)

* get all findings as part of findings API enhancement

Signed-off-by: Riya Saxena <[email protected]>

* findingsAPI feature enhancements (address comments to prev PR)

Signed-off-by: Riya Saxena <[email protected]>

* findingsAPI feature enhancements (address comments to prev PR)

Signed-off-by: Riya Saxena <[email protected]>

* added support for  param in Finding API

Signed-off-by: Riya Saxena <[email protected]>

* added detectionType as param for Findings API enhancements

Signed-off-by: Riya Saxena <[email protected]>

* added few tests to validate findings by params

Signed-off-by: Riya Saxena <[email protected]>

* added test for searchString param in FindingsAPI

Signed-off-by: Riya Saxena <[email protected]>

* adding addiional params findingIds, startTime and endTime as findings API enhancement

Signed-off-by: Riya Saxena <[email protected]>

* added params in getFindingsByDetectorId func

* changed the startTime and endTime req input format

* fix merge conflixt

* fix integ test failures in findings API

* fix integ tests

* fix integ tests for findings

Signed-off-by: Subhobrata Dey <[email protected]>

---------

Signed-off-by: Riya Saxena <[email protected]>
Signed-off-by: Riya <[email protected]>
Signed-off-by: Subhobrata Dey <[email protected]>
Co-authored-by: Subhobrata Dey <[email protected]>

* Feature findings api enhancements (#914)

* get all findings as part of findings API enhancement

Signed-off-by: Riya Saxena <[email protected]>

* findingsAPI feature enhancements (address comments to prev PR)

Signed-off-by: Riya Saxena <[email protected]>

* findingsAPI feature enhancements (address comments to prev PR)

Signed-off-by: Riya Saxena <[email protected]>

* added support for  param in Finding API

Signed-off-by: Riya Saxena <[email protected]>

* added detectionType as param for Findings API enhancements

Signed-off-by: Riya Saxena <[email protected]>

* added few tests to validate findings by params

Signed-off-by: Riya Saxena <[email protected]>

* added test for searchString param in FindingsAPI

Signed-off-by: Riya Saxena <[email protected]>

* adding addiional params findingIds, startTime and endTime as findings API enhancement

Signed-off-by: Riya Saxena <[email protected]>

* added params in getFindingsByDetectorId func

* changed the startTime and endTime req input format

* fix merge conflixt

* fix integ test failures in findings API

* fix integ tests

* refactored the logic

Signed-off-by: Riya Saxena <[email protected]>

* remove unused imports

* address the pr comments

Signed-off-by: Riya Saxena <[email protected]>

* address pr comments

Signed-off-by: Riya Saxena <[email protected]>

* SA integ tests fix

* SA integ tests fix

* fix integ tests for findings

Signed-off-by: Subhobrata Dey <[email protected]>

* fix conflixt errors

Signed-off-by: Riya Saxena <[email protected]>

* fix conflixt errors

Signed-off-by: Riya Saxena <[email protected]>

* fix conflixt errors

Signed-off-by: Riya Saxena <[email protected]>

* fix conflixt errors

Signed-off-by: Riya Saxena <[email protected]>

* fix integ tests

Signed-off-by: Riya Saxena <[email protected]>

* fix integ tests

Signed-off-by: Riya Saxena <[email protected]>

* fix integ tests

Signed-off-by: Riya Saxena <[email protected]>

* fix flaky integ tests

Signed-off-by: Riya Saxena <[email protected]>

* address pr comments

Signed-off-by: Riya Saxena <[email protected]>

---------

Signed-off-by: Riya Saxena <[email protected]>
Signed-off-by: Riya <[email protected]>
Signed-off-by: Subhobrata Dey <[email protected]>
Co-authored-by: Subhobrata Dey <[email protected]>

* fix findings api integ tests

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Subhobrata Dey <[email protected]>
Signed-off-by: Joanne Wang <[email protected]>
Signed-off-by: Riya Saxena <[email protected]>
Signed-off-by: Riya <[email protected]>
Co-authored-by: Subhobrata Dey <[email protected]>
Co-authored-by: Riya <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants