-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Security Solutions][Detection Engine] Adds threat matching API and rule type #77395
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
Merged
FrankHassanabad
merged 30 commits into
elastic:master
from
FrankHassanabad:add-threat-match
Sep 20, 2020
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
ce14648
Simple type change for Type to reduce multiple touch points when addi…
FrankHassanabad 01c8c88
Merge branch 'master' into make-type-common
FrankHassanabad b49a549
Fixes the cycle deps issue by breaking out a file from utils
FrankHassanabad 048c2d9
Fixed missing jest.mock call
FrankHassanabad 298806c
Merge branch 'master' into add-threat-match
FrankHassanabad 6af9d85
Initial threat_mapping implementation
FrankHassanabad 83d398e
Merge branch 'master' into add-threat-match
FrankHassanabad 4f6ad76
Broke out the schema into a types file for better organization and te…
FrankHassanabad 84f11a7
More unit tests added
FrankHassanabad 0f5496d
Adds more unit tests
FrankHassanabad 581c663
More unit tests added
FrankHassanabad 2aa838e
More unit tests
FrankHassanabad fea347c
Adds more unit tests
FrankHassanabad da7b89c
Fixes unit test
FrankHassanabad 0a51480
Added more unit tests
FrankHassanabad fbab786
Merge branch 'master' into add-threat-match
FrankHassanabad b992338
Fixed front end type issues after merge from master
FrankHassanabad d36e090
Added more tests and made the filters quicker and more resliant again…
FrankHassanabad f32eb78
Merge branch 'master' into add-threat-match
FrankHassanabad 575eecf
More unit tests
FrankHassanabad 68599a9
Adds more unit tests
FrankHassanabad 604c893
Merge branch 'master' into add-threat-match
FrankHassanabad f3eaff0
Merge branch 'master' into add-threat-match
FrankHassanabad 404fee3
Merge branch 'master' into add-threat-match
FrankHassanabad 3a97f89
Merge branch 'master' into add-threat-match
FrankHassanabad cf9502e
Fixed type issues from lastest merge from master
FrankHassanabad 680150a
Merge branch 'master' into add-threat-match
FrankHassanabad 903ff63
Fixes from really really good code review of it.
FrankHassanabad b43f302
Merge branch 'master' into add-threat-match
FrankHassanabad 7bfb649
Updated from master, merged in and implemented error messages from ot…
FrankHassanabad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,10 @@ | |
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { getCreateRulesSchemaMock } from './create_rules_schema.mock'; | ||
| import { | ||
| getCreateRulesSchemaMock, | ||
| getCreateThreatMatchRulesSchemaMock, | ||
| } from './create_rules_schema.mock'; | ||
| import { CreateRulesSchema } from './create_rules_schema'; | ||
| import { createRuleValidateTypeDependents } from './create_rules_type_dependents'; | ||
|
|
||
|
|
@@ -87,4 +90,39 @@ describe('create_rules_type_dependents', () => { | |
| const errors = createRuleValidateTypeDependents(schema); | ||
| expect(errors).toEqual(['"threshold.value" has to be bigger than 0']); | ||
| }); | ||
|
|
||
| test('threat_index, threat_query, and threat_mapping are required when type is "threat_match" and validates with it', () => { | ||
| const schema: CreateRulesSchema = { | ||
| ...getCreateRulesSchemaMock(), | ||
| type: 'threat_match', | ||
| }; | ||
| const errors = createRuleValidateTypeDependents(schema); | ||
| expect(errors).toEqual([ | ||
| 'when "type" is "threat_match", "threat_index" is required', | ||
| 'when "type" is "threat_match", "threat_query" is required', | ||
| 'when "type" is "threat_match", "threat_mapping" is required', | ||
| ]); | ||
| }); | ||
|
|
||
| test('validates with threat_index, threat_query, and threat_mapping when type is "threat_match"', () => { | ||
| const schema = getCreateThreatMatchRulesSchemaMock(); | ||
| const { threat_filters: threatFilters, ...noThreatFilters } = schema; | ||
| const errors = createRuleValidateTypeDependents(noThreatFilters); | ||
| expect(errors).toEqual([]); | ||
| }); | ||
|
|
||
| test('does NOT validate when threat_mapping is an empty array', () => { | ||
| const schema: CreateRulesSchema = { | ||
| ...getCreateThreatMatchRulesSchemaMock(), | ||
| threat_mapping: [], | ||
| }; | ||
| const errors = createRuleValidateTypeDependents(schema); | ||
| expect(errors).toEqual(['threat_mapping" must have at least one element']); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahhh, I see now here why this value defaults to |
||
| }); | ||
|
|
||
| test('validates with threat_index, threat_query, threat_mapping, and an optional threat_filters, when type is "threat_match"', () => { | ||
| const schema = getCreateThreatMatchRulesSchemaMock(); | ||
| const errors = createRuleValidateTypeDependents(schema); | ||
| expect(errors).toEqual([]); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: For fields that are arrays, do we want to default them to empty arrays? Or did you choose to default them to "undefined" to be more explicit about like if a rule is not of type "threat_match" these fields should not be there (as opposed to them being there and being [])?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you answered the question below so I think we're good here 👍