-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Add Threat Match rule specific editable fields #200308
base: main
Are you sure you want to change the base?
[Security Solution] Add Threat Match rule specific editable fields #200308
Conversation
018a0c9
to
9b576a1
Compare
Pinging @elastic/security-detections-response (Team:Detections and Resp) |
Pinging @elastic/security-solution (Team: SecuritySolution) |
Pinging @elastic/security-detection-rule-management (Team:Detection Rule Management) |
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.
I have found few issues and left some comments, mostly questions and suggestions.
Will continue testing
...tection_engine/rule_creation/components/threat_match_index_edit/threat_match_index_field.tsx
Outdated
Show resolved
Hide resolved
...rity_solution/public/detection_engine/rule_creation_ui/components/step_define_rule/index.tsx
Outdated
Show resolved
Hide resolved
...ion_engine/rule_creation_ui/components/step_define_rule/use_persistent_threat_match_state.ts
Outdated
Show resolved
Hide resolved
...etection_engine/rule_creation/components/threat_match_index_edit/threat_match_index_edit.tsx
Outdated
Show resolved
Hide resolved
...rity_solution/public/detection_engine/rule_creation_ui/components/description_step/index.tsx
Outdated
Show resolved
Hide resolved
...olution/common/api/detection_engine/prebuilt_rules/model/diff/diffable_rule/diffable_rule.ts
Outdated
Show resolved
Hide resolved
...olution/common/api/detection_engine/prebuilt_rules/model/diff/diffable_rule/diffable_rule.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/security_solution/public/common/components/threat_match/index.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/security_solution/public/common/components/threat_match/index.tsx
Outdated
Show resolved
Hide resolved
...olution/common/api/detection_engine/prebuilt_rules/model/diff/diffable_rule/diffable_rule.ts
Outdated
Show resolved
Hide resolved
I don’t have any changes in the filters field, but the diff shows some empty What is the cc @dplumlee This seems similar to the issue we recently had with the schedule and threat fields. |
e0ff1dd
to
f9e8e69
Compare
1ab0f3c
to
5ed85f5
Compare
// We have to make sure validation runs against the latest source events index patterns | ||
// and threat match index patterns. | ||
// Form lib's `fieldsToValidateOnChange` on the corresponding index patterns edit fields | ||
// doesn't help here. It leads to running threat match mapping validation before render | ||
// of this component happens. In the end validation runs against previous index patterns | ||
// producing invalid validation results. | ||
// | ||
// Validating the field imperatively here fixes this issue. | ||
// | ||
// Additional pitfall here is `validate` function changing its reference every render. Including it | ||
// in useEffect's deps leads to infinite re-render. | ||
useEffect(() => { | ||
validate(); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [indexPatterns, threatIndexPatterns]); |
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.
This part looks sub-optimal but it's the best I was able to make to re-run threat match mapping validation upon index pattern changes. An alternative is using formData
in validation to read index patterns/data source, transform them to data view asynchronously and then validate fields against known fields. Alternative's drawback is difficulty to reuse it in rule upgrade workflow.
Any bright ideas are welcome.
import { useFormData } from '../../../../shared_imports'; | ||
|
||
interface UsePersistentThreatMatchStateParams { | ||
form: FormHook; |
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.
some of the comments still not addressed: #200308 (comment)
export function usePersistentThreatMatchState({ form }: UsePersistentThreatMatchStateParams): void { | ||
const lastThreatMatchState = useRef<LastThreatMatchState | undefined>(); | ||
const [{ ruleType, threatIndex: threatIndexPatterns, threatQueryBar, threatMapping }] = | ||
useFormData({ form, watch: ['ruleType', 'threatIndex', 'threatQueryBar', 'threatMapping'] }); |
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.
some of the comments still not addressed: #200308 (comment)
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.
There are few minor comments and mostly discussion over #200308 (comment)
I would like to be addressed before merge
About
#200308 (comment)
I think the proper solution should involve async validation.
At the same time, in alternative approach, are multiple requests to get index fields sent? (from created data view in validator and data views from parent component)
They might be very heavy, so ideally if we want to do them once.
'xpack.securitySolution.detectionEngine.ruleManagement.threatMappingField.unknownFields', | ||
{ | ||
defaultMessage: | ||
'Indicator mapping has unknown fields. {unknownSourceIndicesFields} field(s) not found in the source events indices and {unknownThreatMatchIndicesFields} field(s) not found in the indicator indices.', |
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.
we should use plurals instead of field(s)
'xpack.securitySolution.detectionEngine.ruleManagement.threatMappingField.unknownSourceIndicesFields', | ||
{ | ||
defaultMessage: | ||
'Indicator mapping has unknown fields. {unknownSourceIndicesFields} field(s) not found in the source events indices.', |
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.
we should use plurals instead of field(s)
'xpack.securitySolution.detectionEngine.ruleManagement.threatMappingField.unknownIndicatorIndicesFields', | ||
{ | ||
defaultMessage: | ||
'Indicator mapping has unknown fields. {unknownThreatMatchIndicesFields} field(s) not found in the indicator indices.', |
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.
we should use plurals instead of field(s)
💔 Build Failed
Failed CI StepsHistory
cc @maximpn |
Partially addresses: #171520
Summary
This PR adds is built on top of #193828 and #196948 and adds the following editable components for Threat Match rule type
threat_languagethreat_language
was merged withthreat_query
Details
This PR make a set of changes to make existing Threat Match form fields easily reusable as editable components and type safe when used in forms. In particular the following was done
threat_index
,threat_query
,threat_mapping
andthreat_indicator_path
rule fieldsthreat_language
was removed since query type is included inthreat_query
field and can be edited with Query BarThreatMatchComponent
was refactored to be a controlled component instead of uncontrolledThreatMatchComponent
has a feature preventing users removing the single last entry. Instead deleting the last entry the delete button clears inputs. That functionality didn't work properly in Prebuilt Rule Customization workflow and rule creation/editing forms after creating a reusableThreatMappingEdit
component. Instead of trying to find a tricky fixThreatMatchComponent
was refactored to remove internal state. The feature preventing users removing the single last entry was reimplemented inThreatMappingEdit
component.main
where validation errors duplicated described in a commentmain
allowing to save unknown source indices or indicator indices fields described in a commentHow to test
prebuiltRulesCustomizationEnabled
feature flag is enabledserver.restrictInternalApis: false
tokibana.dev.yaml
security_detection_engine
Fleet packageOpen a
threat_match
rule for editing. For exampleThreat Intel Hash Indicator Match
with rule_idaab184d3-72b3-4639-b242-6597c99d8bca
.Edit
Indicator index patterns
,Indicator index query
and/orIndicator filters
,Indicator mapping
andIndicator prefix override
fieldsOpen
Detection Rules (SIEM)
Page ->Rule Updates
-> click onThreat Intel Hash Indicator Match
rule -> expand each Threat Match rule type specific field -> pressEdit
buttonScreenshots
Threat Match Query edit component
Threat Match Index edit component
Threat Match Mapping edit component
Threat Match Indicator Path edit component
Threat Match Mapping unknown field names validation warnings