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

[RAC][Security Solution] Pull Gap Remediation out of search_after_bulk_create #102104

Merged
merged 15 commits into from
Jun 16, 2021

Conversation

madirey
Copy link
Contributor

@madirey madirey commented Jun 14, 2021

Summary

Fixes #100181 (aside from Threat Match per-timerange bug where maxSignals can be exceeded)

NOTE: This branch includes commits from #101544, which will be removed once that PR is merged.

In order to ensure that maxSignals is enforced per time-range tuple, avoiding the potential silencing of signals when gap remediation is used, this PR modifies searchAfterAndBulkCreate so that it accepts only a single time-range tuple. Accordingly, the logic in signal_rule_alert_type was modified to loop over the tuples for each rule type and invoke N instances of the executor for N time ranges. This enforces maxSignals for each time range, with the exception of Threat Match rule invocations, which can still generate maxSignals * M signals per time range, where M is the number of parallel searches performed.

To address this, there is an optional commit that adds some synchronization code to searchAfterAndBulkCreate: 81105cf (removed in favor of a better solution, to come in a future PR if prioritized) @MikePaquette Is this something we want to fix for 7.14?

Checklist

Delete any items that are not applicable to this PR.

Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.

When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:

Risk Probability Severity Mitigation/Notes
Multiple Spaces—unexpected behavior in non-default Kibana Space. Low High Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces.
Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. High Low Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure.
Code should gracefully handle cases when feature X or plugin Y are disabled. Medium High Unit tests will verify that any feature flag or plugin combination still results in our service operational.
See more potential risk examples

For maintainers

@madirey madirey added release_note:skip Skip the PR/issue when compiling release notes v7.14.0 Theme: rac label obsolete labels Jun 14, 2021
@madirey madirey marked this pull request as ready for review June 14, 2021 21:09
@madirey madirey requested a review from a team as a code owner June 14, 2021 21:09
@madirey madirey changed the title [RAC][Security Solution] Pull Gap Remediation out of search_after_bulk_create and update Threat Match maxSignals calculation [RAC][Security Solution] Pull Gap Remediation out of search_after_bulk_create Jun 14, 2021
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@marshallmain marshallmain left a comment

Choose a reason for hiding this comment

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

LGTM, this is an exciting improvement - thanks!

@madirey madirey merged commit c5e74d8 into elastic:master Jun 16, 2021
@madirey madirey deleted the rac-gap-remediation branch June 16, 2021 15:35
majagrubic pushed a commit to majagrubic/kibana that referenced this pull request Jun 18, 2021
…k_create (elastic#102104)

* Modify threshold rules to receive a single date range tuple

* Modify threat match rules to receive a single date range tuple

* Modify custom query rules to receive a single date range tuple

* Fix up tests (partially)

* Change log message to indicate single tuple instead of array

* Bad test?

* Prevent max_signals from being exceeded on threat match rule executions

* Revert "Prevent max_signals from being exceeded on threat match rule executions"

This reverts commit ba3b2f7.

* Modify EQL rules to use date range tuple

* Modify ML rules to use date range tuple

* Fix ML/EQL tests

* Use dateMath to parse moments in ML/Threshold tests

* Add mocks for threshold test

* Use dateMath for eql tests
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 102104 or prevent reminders by adding the backport:skip label.

@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jun 18, 2021
madirey added a commit to madirey/kibana that referenced this pull request Jun 21, 2021
…k_create (elastic#102104)

* Modify threshold rules to receive a single date range tuple

* Modify threat match rules to receive a single date range tuple

* Modify custom query rules to receive a single date range tuple

* Fix up tests (partially)

* Change log message to indicate single tuple instead of array

* Bad test?

* Prevent max_signals from being exceeded on threat match rule executions

* Revert "Prevent max_signals from being exceeded on threat match rule executions"

This reverts commit ba3b2f7.

* Modify EQL rules to use date range tuple

* Modify ML rules to use date range tuple

* Fix ML/EQL tests

* Use dateMath to parse moments in ML/Threshold tests

* Add mocks for threshold test

* Use dateMath for eql tests
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jun 21, 2021
madirey added a commit that referenced this pull request Jun 21, 2021
…k_create (#102104) (#102739)

* Modify threshold rules to receive a single date range tuple

* Modify threat match rules to receive a single date range tuple

* Modify custom query rules to receive a single date range tuple

* Fix up tests (partially)

* Change log message to indicate single tuple instead of array

* Bad test?

* Prevent max_signals from being exceeded on threat match rule executions

* Revert "Prevent max_signals from being exceeded on threat match rule executions"

This reverts commit ba3b2f7.

* Modify EQL rules to use date range tuple

* Modify ML rules to use date range tuple

* Fix ML/EQL tests

* Use dateMath to parse moments in ML/Threshold tests

* Add mocks for threshold test

* Use dateMath for eql tests
},
references: [],
};
const tuple = {
from: dateMath.parse(params.from)!,
to: dateMath.parse(params.to)!,
Copy link
Contributor

@FrankHassanabad FrankHassanabad Jun 21, 2021

Choose a reason for hiding this comment

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

I know this is merged but instead of turning off the checks here can we do a small follow up where we do this similar pattern here that @marshallmain did a while back?

https://github.com/elastic/kibana/blob/master/x-pack/plugins/security_solution/server/lib/detection_engine/signals/utils.ts#L468

I think that would be good to intentionally throw if for some reason these aren't parseable rather than turning off the typescript check for it.

Later if refactoring or mistakes are made and we get an SDH or issue it would be easier to track down where and what happened from a custom error message than somewhere else where the from and to have become null/undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@FrankHassanabad Is this necessary in test files? Looks like we're only doing this in the test files... the code/test will fail when the check is done here, right? https://github.com/elastic/kibana/blob/master/x-pack/plugins/security_solution/server/lib/detection_engine/signals/search_after_bulk_create.ts#L52-L58

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I didn't see it was in a test file. For test files it's optional, I typically still avoid it if I can even in test files, but that's just me probably because I really don't like that TypeScript allows type assertions to be turned off compared to other languages with strict types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Theme: rac label obsolete v7.14.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Security Solution][Detections] Inconsistent handling of gap detection and max signals
4 participants