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

fix for detectors with sigma aggregation rules #1372

Merged
merged 2 commits into from
Oct 23, 2024

Conversation

sbcd90
Copy link
Collaborator

@sbcd90 sbcd90 commented Oct 22, 2024

Description

fix for detectors with sigma aggregation rules

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

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.

Signed-off-by: Subhobrata Dey <sbcd90@gmail.com>
@@ -2153,6 +2157,109 @@ public void testCreateDetectorWithCloudtrailAggrRuleWithEcsFields() throws IOExc
assertEquals(1, getFindingsBody.get("total_findings"));
}

@SuppressWarnings("unchecked")
public void testCreateDetectorWithCloudtrailAggrRuleWithRolloverIndexAliases() throws IOException, InterruptedException {
updateClusterSetting("plugins.security_analytics.enable_detectors_with_dedicated_query_indices", "false");
Copy link
Member

Choose a reason for hiding this comment

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

why do we turn off this setting?

Copy link
Member

Choose a reason for hiding this comment

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

plz change to true as that's the new default behaviour

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. sorry. leftover from some experiments.

assertEquals(1, getFindingsBody.get("total_findings"));

doRollover("ocsf_ct");
Thread.sleep(90000);
Copy link
Member

Choose a reason for hiding this comment

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

why should we do sleep?
after rollover is the template not applied to new index directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The Sigma Aggregation Rule we're using has timeframe set to 1m(

). So, the sleep ensures that the rule only considers docs from the rolled over new write index. If this fix is not present, the alerting workflow run doesn't generate the new finding.
executeAlertingWorkflow(workflowId, Collections.emptyMap());

doRollover("ocsf_ct");
Thread.sleep(90000);

indexDoc("ocsf_ct", "4", randomCloudtrailOcsfDoc());
Copy link
Member

Choose a reason for hiding this comment

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

before this should we not verify mappings of new write index?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

mappings of the first write index are verified with the first workflow run.

executeAlertingWorkflow(workflowId, Collections.emptyMap());
.If alias mappings are not applied, findings will not be generated.

Copy link
Member

Choose a reason for hiding this comment

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

But i thought the bug was that AFTER rollover the template is not getting applied?

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.

when is template applied? not at creation time? why is there sleep 90 s in test?

@sbcd90
Copy link
Collaborator Author

sbcd90 commented Oct 23, 2024

when is template applied? not at creation time? why is there sleep 90 s in test?

Yes. Template is applied at creation time with the Create Mapping api call.

Signed-off-by: Subhobrata Dey <sbcd90@gmail.com>
@@ -115,13 +115,22 @@ public void upsertIndexTemplateWithAliasMappings(

upsertComponentTemplateStepListener.whenComplete( acknowledgedResponse -> {

// Find template which matches input index best
// Find template which matches input index best. starts by directly matching with input index and
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's use doc comments for these lines instead -> https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will address this in a follow-up pr.

@sbcd90 sbcd90 merged commit 6f543b5 into opensearch-project:main Oct 23, 2024
8 of 12 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 23, 2024
Signed-off-by: Subhobrata Dey <sbcd90@gmail.com>
(cherry picked from commit 6f543b5)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 23, 2024
Signed-off-by: Subhobrata Dey <sbcd90@gmail.com>
(cherry picked from commit 6f543b5)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 23, 2024
Signed-off-by: Subhobrata Dey <sbcd90@gmail.com>
(cherry picked from commit 6f543b5)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
sbcd90 pushed a commit that referenced this pull request Oct 23, 2024
(cherry picked from commit 6f543b5)

Signed-off-by: Subhobrata Dey <sbcd90@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
sbcd90 pushed a commit that referenced this pull request Oct 23, 2024
(cherry picked from commit 6f543b5)

Signed-off-by: Subhobrata Dey <sbcd90@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
sbcd90 pushed a commit that referenced this pull request Oct 23, 2024
(cherry picked from commit 6f543b5)

Signed-off-by: Subhobrata Dey <sbcd90@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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