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

adds support for alerts and triggers on group by based sigma rules #545

Merged
merged 7 commits into from
Sep 8, 2023

Conversation

eirsep
Copy link
Member

@eirsep eirsep commented Sep 7, 2023

Description

  • For each group by rule a bucket level monitor is created.
  • Bucket level monitor doesn't support the current detector triggers which cater focussedly to per document alerting
  • This change uses workflow's chained monitor findings feature to feed findings generated by all bucket level monitors as source data to a match all doc level monitor. The chained findings monitor simply creates findings for all docs which match the bucket level monitor rule and honors the detector trigger condition creating alerts if there are any group by rules mentioned in the trigger.

Behaviour of non-group by rule matching is unaffected.

@codecov
Copy link

codecov bot commented Sep 7, 2023

Codecov Report

Merging #545 (3684997) into main (1003936) will decrease coverage by 0.13%.
Report is 1 commits behind head on main.
The diff coverage is 0.00%.

@@             Coverage Diff              @@
##               main     #545      +/-   ##
============================================
- Coverage     25.12%   24.99%   -0.13%     
- Complexity      942      943       +1     
============================================
  Files           255      255              
  Lines         11064    11125      +61     
  Branches       1231     1242      +11     
============================================
+ Hits           2780     2781       +1     
- Misses         8032     8093      +61     
+ Partials        252      251       -1     
Files Changed Coverage Δ
...earch/securityanalytics/model/DetectorTrigger.java 54.85% <0.00%> (-1.29%) ⬇️
...yanalytics/settings/SecurityAnalyticsSettings.java 96.00% <ø> (ø)
...lytics/transport/TransportIndexDetectorAction.java 0.00% <0.00%> (ø)
...ensearch/securityanalytics/util/DetectorUtils.java 0.00% <0.00%> (ø)
...search/securityanalytics/util/WorkflowService.java 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

@@ -940,7 +941,7 @@ else if (ruleId == minRuleId) {
// Assert findings
assertNotNull(getFindingsBody);
// 8 findings from doc level rules, and 3 findings for aggregation (sum, max and min)
assertEquals(11, getFindingsBody.get("total_findings"));
assertEquals(19, getFindingsBody.get("total_findings"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we hide the findings generated by match of _id: * queries?

Copy link
Member Author

@eirsep eirsep Sep 7, 2023

Choose a reason for hiding this comment

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

been thinking about this
Need to add logic to avoid fetching findings from bucket level monitors which are feeding findings to chained findings doc monitor.

let's go with this for now
will do de-dupe in a quick follow up.

@@ -1409,7 +1410,7 @@ public void testCreateDetector_verifyWorkflowExecutionBucketLevelDocLevelMonitor
Map<String, Object> getFindingsBody = entityAsMap(getFindingsResponse);

assertNotNull(getFindingsBody);
assertEquals(6, getFindingsBody.get("total_findings"));
assertEquals(10, getFindingsBody.get("total_findings"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member Author

@eirsep eirsep Sep 7, 2023

Choose a reason for hiding this comment

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

let's go with this for now
will do de-dupe in a quick follow up.

Signed-off-by: Surya Sashank Nistala <[email protected]>
Signed-off-by: Surya Sashank Nistala <[email protected]>
Signed-off-by: Surya Sashank Nistala <[email protected]>
…mentioned in detector triggers

Signed-off-by: Surya Sashank Nistala <[email protected]>
@@ -785,7 +850,7 @@ private IndexMonitorRequest createBucketLevelMonitorRequest(
triggers.add(bucketLevelTrigger1);
} **/

Monitor monitor = new Monitor(monitorId, Monitor.NO_VERSION, detector.getName(), false, detector.getSchedule(), detector.getLastUpdateTime(), null,
Monitor monitor = new Monitor(monitorId, Monitor.NO_VERSION, detector.getName() + UUID.randomUUID(), false, detector.getSchedule(), detector.getLastUpdateTime(), null,
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this change needed? i reverted this & integ tests still work fine.

@eirsep
Copy link
Member Author

eirsep commented Sep 8, 2023

#558

@eirsep eirsep merged commit f4be879 into opensearch-project:main Sep 8, 2023
@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-545-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 f4be879cd1486329fac5f2df1e251d3b544cd48e
# Push it to GitHub
git push --set-upstream origin backport/backport-545-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-545-to-2.x.

@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.10 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.10 2.10
# Navigate to the new working tree
cd .worktrees/backport-2.10
# Create a new branch
git switch --create backport/backport-545-to-2.10
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 f4be879cd1486329fac5f2df1e251d3b544cd48e
# Push it to GitHub
git push --set-upstream origin backport/backport-545-to-2.10
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.10

Then, create a pull request where the base branch is 2.10 and the compare/head branch is backport/backport-545-to-2.10.

eirsep added a commit to eirsep/security-analytics that referenced this pull request Sep 8, 2023
…pensearch-project#545)

* fix test

Signed-off-by: Surya Sashank Nistala <[email protected]>

* adds support for alerts and triggers on group by based rules

Signed-off-by: Surya Sashank Nistala <[email protected]>

* change setting workflow usage enabled to true by default

Signed-off-by: Surya Sashank Nistala <[email protected]>

* turn off workflow setting for test

Signed-off-by: Surya Sashank Nistala <[email protected]>

* revert new line

Signed-off-by: Surya Sashank Nistala <[email protected]>

* support feeding findings to chained finding monitors ONLY from rules mentioned in detector triggers

Signed-off-by: Surya Sashank Nistala <[email protected]>

* revert naming convention change for bucket level monitors

Signed-off-by: Surya Sashank Nistala <[email protected]>

---------

Signed-off-by: Surya Sashank Nistala <[email protected]>
eirsep added a commit that referenced this pull request Sep 9, 2023
…igma rules (#545) (#559)

* adds support for alerts and triggers on group by based sigma rules  (#545)

* fix test

Signed-off-by: Surya Sashank Nistala <[email protected]>

* adds support for alerts and triggers on group by based rules

Signed-off-by: Surya Sashank Nistala <[email protected]>

* change setting workflow usage enabled to true by default

Signed-off-by: Surya Sashank Nistala <[email protected]>

* turn off workflow setting for test

Signed-off-by: Surya Sashank Nistala <[email protected]>

* revert new line

Signed-off-by: Surya Sashank Nistala <[email protected]>

* support feeding findings to chained finding monitors ONLY from rules mentioned in detector triggers

Signed-off-by: Surya Sashank Nistala <[email protected]>

* revert naming convention change for bucket level monitors

Signed-off-by: Surya Sashank Nistala <[email protected]>

---------

Signed-off-by: Surya Sashank Nistala <[email protected]>

* fix compile issue from main and 2.x dependency divergence

Signed-off-by: Surya Sashank Nistala <[email protected]>

---------

Signed-off-by: Surya Sashank Nistala <[email protected]>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Sep 9, 2023
…igma rules (#545) (#559)

* adds support for alerts and triggers on group by based sigma rules  (#545)

* fix test

Signed-off-by: Surya Sashank Nistala <[email protected]>

* adds support for alerts and triggers on group by based rules

Signed-off-by: Surya Sashank Nistala <[email protected]>

* change setting workflow usage enabled to true by default

Signed-off-by: Surya Sashank Nistala <[email protected]>

* turn off workflow setting for test

Signed-off-by: Surya Sashank Nistala <[email protected]>

* revert new line

Signed-off-by: Surya Sashank Nistala <[email protected]>

* support feeding findings to chained finding monitors ONLY from rules mentioned in detector triggers

Signed-off-by: Surya Sashank Nistala <[email protected]>

* revert naming convention change for bucket level monitors

Signed-off-by: Surya Sashank Nistala <[email protected]>

---------

Signed-off-by: Surya Sashank Nistala <[email protected]>

* fix compile issue from main and 2.x dependency divergence

Signed-off-by: Surya Sashank Nistala <[email protected]>

---------

Signed-off-by: Surya Sashank Nistala <[email protected]>
(cherry picked from commit 24fe8d4)
sbcd90 pushed a commit that referenced this pull request Sep 9, 2023
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.

3 participants