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

[Security Solution][Detections][7.12] Critical Threshold Rule Fixes #92667

Merged
merged 25 commits into from
Mar 1, 2021

Conversation

madirey
Copy link
Contributor

@madirey madirey commented Feb 24, 2021

Summary

This PR addresses critical issues identified in https://github.com/elastic/security-team/issues/839

Additionally, it adds several new unit tests to cover these cases.

We wanted to avoid a rule migration, so we've introduced a new type ThresholdNormalized which will be used for all internal calls from the detection engine. The threshold field will remain stored as a string for legacy threshold rules, but will be an array for all rules created through the UI. The cardinality field has been normalized to be an array to avoid a future migration when we support multiple cardinality fields.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@madirey madirey added release_note:enhancement v7.12.0 Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Feature:Detection Alerts Security Solution Detection Alerts Feature documentation docs needs_docs labels Feb 24, 2021
@madirey madirey marked this pull request as ready for review February 28, 2021 02:04
@madirey madirey requested a review from a team as a code owner February 28, 2021 02:04
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detections-response (Team:Detections and Resp)

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.

great improvements overall, just a couple more questions

.field,
field: (((hit._source.signal?.rule as RulesSchema).threshold as unknown) as {
field: string;
}).field,
Copy link
Contributor

Choose a reason for hiding this comment

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

might be easier to use lodash get here and then check if we got the value successfully rather than triple casting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You don't like my triple cast? 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Propose we leave this for now and I can update in a follow-up... just want to focus on getting the fixes in for BC3.

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. I was able to create a threshold rules that use cardinality with and without Group by fields.

One more thing we may want to address in a follow up is some weirdness around how we exclude documents that were part of previous threshold alerts. When building the filters, we sort of mix the current state of the rule with the alerts that the rule already generated (e.g. here we use bucketByFields from the current state of the rule, but also check if the current fields are in the existing alerts). This can create some duplicate alerts if the rule is edited. I think we want to rely only on the alert documents to create the filters so that the filters will be consistent even if the rule is edited.

@@ -146,13 +107,11 @@ const getTransformedHits = (
field,
value: bucket.key,
},
],
cardinality: !isEmpty(threshold.cardinality_field)
].filter((term) => term.field != null),
Copy link
Contributor

Choose a reason for hiding this comment

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

for follow up: field is typed as string in the function definition but used as string | null - looks like aggParts is being typed as any so we're losing type checking there

@madirey
Copy link
Contributor Author

madirey commented Mar 1, 2021

Thanks @marshallmain ... the bucketByFields fix is on the list, but didn't make this PR. Want to get this merged to address the upgrade issue and then I'll have yet another PR with the other fixes. :D

@marshallmain
Copy link
Contributor

@madirey sounds good!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 7.8MB 7.8MB +1.2KB
triggersActionsUi 1.6MB 1.5MB -23.9KB
total -22.7KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
securitySolution 235.8KB 236.5KB +766.0B
triggersActionsUi 104.0KB 104.1KB +82.0B
total +848.0B
Unknown metric groups

async chunk count

id before after diff
triggersActionsUi 41 42 +1

History

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

@madirey madirey merged commit cb053f4 into elastic:master Mar 1, 2021
madirey added a commit to madirey/kibana that referenced this pull request Mar 1, 2021
…lastic#92667)

* Threshold cardinality validation

* Remove comments

* Fix legacy threshold signal dupe mitigation

* Add find_threshold_signals tests

* remove comment

* bug fixes

* Fix edit form value initialization for cardinality_value

* Fix test

* Type and test fixes

* Tests/types

* Reenable threshold cypress test

* Schema fixes

* Types and tests, normalize threshold field util

* Continue cleaning up types

* Some more pre-7.12 tests

* Limit cardinality_field to length 1 for now

* Cardinality to array

* Cardinality to array

* Tests/types

* cardinality can be null

* Handle empty threshold field in bulk_create_threshold_signals

* Remove cardinality_field, cardinality_value
madirey added a commit that referenced this pull request Mar 2, 2021
…92667) (#93140)

* Threshold cardinality validation

* Remove comments

* Fix legacy threshold signal dupe mitigation

* Add find_threshold_signals tests

* remove comment

* bug fixes

* Fix edit form value initialization for cardinality_value

* Fix test

* Type and test fixes

* Tests/types

* Reenable threshold cypress test

* Schema fixes

* Types and tests, normalize threshold field util

* Continue cleaning up types

* Some more pre-7.12 tests

* Limit cardinality_field to length 1 for now

* Cardinality to array

* Cardinality to array

* Tests/types

* cardinality can be null

* Handle empty threshold field in bulk_create_threshold_signals

* Remove cardinality_field, cardinality_value
madirey added a commit that referenced this pull request Mar 2, 2021
…92667) (#93141)

* Threshold cardinality validation

* Remove comments

* Fix legacy threshold signal dupe mitigation

* Add find_threshold_signals tests

* remove comment

* bug fixes

* Fix edit form value initialization for cardinality_value

* Fix test

* Type and test fixes

* Tests/types

* Reenable threshold cypress test

* Schema fixes

* Types and tests, normalize threshold field util

* Continue cleaning up types

* Some more pre-7.12 tests

* Limit cardinality_field to length 1 for now

* Cardinality to array

* Cardinality to array

* Tests/types

* cardinality can be null

* Handle empty threshold field in bulk_create_threshold_signals

* Remove cardinality_field, cardinality_value

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
gmmorris added a commit to gmmorris/kibana that referenced this pull request Mar 2, 2021
* master: (42 commits)
  [Lens] Introduces new chart switcher (elastic#91844)
  [Lens] fix selection when dragging (elastic#93034)
  Converts usage collection README to .mdx (elastic#92982)
  Fix expanding document when using saved search data grid (elastic#92999)
  [SECURITY SOLUTIONS] Bug case connector (elastic#93104)
  [Security Solution] [Timeline] Bugfix to include unmapped fields in the timeline event details JSON (elastic#92025)
  [Alerting][Docs] Changed alerting documentation to point to a single source of explaining the configurations. (elastic#92942)
  [APM] Fix hidden search bar in error pages while loading (elastic#84476) (elastic#93139)
  [DOCS] Fixes links for machine learning alerts (elastic#92744)
  [Security Solution][Detections] -Fixes rule edit flow bug with max_signals (elastic#92748)
  [SecuritySolution][Case] Disable cases on detections in read-only mode (elastic#93010)
  [Security Solution][Case][Bug] Prevent closing collection when pushing (elastic#93095)
  [Security Solution][Detections][7.12] Critical Threshold Rule Fixes (elastic#92667)
  Bump ems landing page to 7.12 (elastic#93065)
  [App Search] Implement various Relevance Tuning states and form actions (elastic#92644)
  [actions] for simplistic email servers, set rejectUnauthorized to false (elastic#91760)
  [Security Solution][Case] Migrate category & subcategory fields of ServiceNow ITSM connector (elastic#93092)
  Hide instances latency distribution chart (elastic#92869)
  [Maps] fix MapboxDraw import from pointing to dist just pointing to folder (elastic#93087)
  [Maps] fix results trimmed tooltip message doubles feature count for line and polygon features (elastic#92932)
  ...
v1v added a commit to shahzad31/kibana that referenced this pull request Mar 2, 2021
… playwright-ftr-e2e

* 'playwright-ftr-e2e' of github.com:shahzad31/kibana: (38 commits)
  [chore] Enable core's eslint rule: `@ts-expect-error` (elastic#93086)
  [Lens] Introduces new chart switcher (elastic#91844)
  [Lens] fix selection when dragging (elastic#93034)
  Converts usage collection README to .mdx (elastic#92982)
  Fix expanding document when using saved search data grid (elastic#92999)
  [SECURITY SOLUTIONS] Bug case connector (elastic#93104)
  [Security Solution] [Timeline] Bugfix to include unmapped fields in the timeline event details JSON (elastic#92025)
  [Alerting][Docs] Changed alerting documentation to point to a single source of explaining the configurations. (elastic#92942)
  [APM] Fix hidden search bar in error pages while loading (elastic#84476) (elastic#93139)
  [DOCS] Fixes links for machine learning alerts (elastic#92744)
  [Security Solution][Detections] -Fixes rule edit flow bug with max_signals (elastic#92748)
  [SecuritySolution][Case] Disable cases on detections in read-only mode (elastic#93010)
  [Security Solution][Case][Bug] Prevent closing collection when pushing (elastic#93095)
  [Security Solution][Detections][7.12] Critical Threshold Rule Fixes (elastic#92667)
  Bump ems landing page to 7.12 (elastic#93065)
  [App Search] Implement various Relevance Tuning states and form actions (elastic#92644)
  [actions] for simplistic email servers, set rejectUnauthorized to false (elastic#91760)
  [Security Solution][Case] Migrate category & subcategory fields of ServiceNow ITSM connector (elastic#93092)
  Hide instances latency distribution chart (elastic#92869)
  [Maps] fix MapboxDraw import from pointing to dist just pointing to folder (elastic#93087)
  ...
jloleysens added a commit that referenced this pull request Mar 3, 2021
… ilm/rollup-v2-action

* 'ilm/rollup-v2-action' of github.com:elastic/kibana: (30 commits)
  Fix expanding document when using saved search data grid (#92999)
  [SECURITY SOLUTIONS] Bug case connector (#93104)
  [Security Solution] [Timeline] Bugfix to include unmapped fields in the timeline event details JSON (#92025)
  [Alerting][Docs] Changed alerting documentation to point to a single source of explaining the configurations. (#92942)
  [APM] Fix hidden search bar in error pages while loading (#84476) (#93139)
  [DOCS] Fixes links for machine learning alerts (#92744)
  [Security Solution][Detections] -Fixes rule edit flow bug with max_signals (#92748)
  [SecuritySolution][Case] Disable cases on detections in read-only mode (#93010)
  [Security Solution][Case][Bug] Prevent closing collection when pushing (#93095)
  [Security Solution][Detections][7.12] Critical Threshold Rule Fixes (#92667)
  Bump ems landing page to 7.12 (#93065)
  [App Search] Implement various Relevance Tuning states and form actions (#92644)
  [actions] for simplistic email servers, set rejectUnauthorized to false (#91760)
  [Security Solution][Case] Migrate category & subcategory fields of ServiceNow ITSM connector (#93092)
  Hide instances latency distribution chart (#92869)
  [Maps] fix MapboxDraw import from pointing to dist just pointing to folder (#93087)
  [Maps] fix results trimmed tooltip message doubles feature count for line and polygon features (#92932)
  [Security Solution][Detecttions] Indicator enrichment tweaks (#92989)
  [Maps] fix fit to data on heatmap not working (#92697)
  [Security Solution][Endpoint][Admin] Fixes policy sticky footer save test (#92919)
  ...
@madirey madirey deleted the threshold-7.12.-fixes branch March 7, 2021 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs documentation Feature:Detection Alerts Security Solution Detection Alerts Feature needs_docs release_note:enhancement Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v7.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants