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] Rule Diff Phase 2 components #174564

Merged
merged 27 commits into from
Feb 12, 2024

Conversation

dplumlee
Copy link
Contributor

@dplumlee dplumlee commented Jan 10, 2024

Summary

Addresses #166489
Docs issue: elastic/security-docs#4783

Adds per-field diffs for the rule upgrade flyout

Acceptance Criteria

  • The tab with per-field diffs is hidden behind a new feature flag. When the flag is off, the tab does not appear in the flyout. The tab should work regardless of the value of jsonPrebuiltRulesDiffingEnabled.
  • Per-field diffs are read-only components. We don't need to let the user "merge" differences using these components.
  • Diffs for complex fields are rendered as JSON diffs using the same component used for rendering the JSON diff for the whole rule. This means this component should be abstracted away and should accept unknown values in props instead of RuleResponse.
  • Diffs for related fields are grouped or rendered close to each other. For example:
    • Index patterns + Data view id
    • Custom query + Filters + Language + Saved query id
  • The tab uses the response from the upgrade/_review API endpoint and doesn't need any other API calls to render itself.
  • The tab renders itself under 150ms.

Manual testing

We are currently going over every field returned by the rule diff api to locate any issues (either in the UI or endpoint) that occur when certain fields are added/deleted/modified

To test certain fields:

Use either a PATCH or PUT method on the /api/detection_engine/rules endpoint route with a rule object that contains at least a rule_id (not id) and a lower version number than the current rule's version. This will allow you to see the prebuilt package update in the Rule Updates tab on the rules overview page

Example

{
  "rule_id": "some_rule_id_12345",
  "version": 1,
  "test_field": "test value",
  ...
}
Manually tested fields
Field name Has been verified Endpoint issue
version ✔️
name ✔️
description ✔️
author ✔️
building_block ✔️
severity ✔️
severity_mapping ✔️
risk_score ✔️
risk_score_mapping ✔️
references ✔️
false_positives ✔️
investigation_fields ✔️
license ✔️
rule_name_override ✔️
threat ✔️
threat_indicator_path ✔️
timestamp_override ✔️
tags ✔️
data_source ✔️
type ✔️
kql_query ✔️
eql_query ✔️
event_category_override ✔️
timestamp_field ✔️
tiebreaker_field ✔️
esql_query ✔️
anomaly_threshold ✔️
machine_learning_job_id ✔️
related_integrations ✔️
required_fields ✔️
timeline_template ✔️
threshold ✔️
threat_index ✔️
threat_mapping ✔️
threat_filters ✔️
threat_query ✔️
threat_indicator_path ✔️
concurrent_searches ✔️
items_per_search ✔️
alert_suppression ✔️
new_terms_fields ✔️
history_window_start ✔️
rule_schedule ✔️
setup ✔️
note ✔️
max_signals ✔️

Screenshots

Screenshot 2024-02-07 at 1 36 34 AM Screenshot 2024-02-07 at 1 36 52 AM

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@dplumlee dplumlee added release_note:enhancement Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Feature:Rule Management Security Solution Detection Rule Management Team:Detection Rule Management Security Detection Rule Management Team v8.13.0 labels Jan 10, 2024
@dplumlee dplumlee self-assigned this Jan 10, 2024
if (Object.hasOwn(ruleDiff.fields, field)) {
const typedField = field as keyof RuleFieldsDiff;
const formattedDiffs = getFormattedFieldDiff(typedField, ruleDiff.fields);
fields.push({ formattedDiffs, fieldName: typedField });
Copy link
Contributor

Choose a reason for hiding this comment

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

We're going to need a dictionary to translate field names as they exist in the rule schema to their UI-version. For example, note is actually Investigation guide. I guess we can create a dictionary only for the one that are completely different, and for the others, not found in the dict, just take the field name and camel case it as you are doing now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Started in x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_details/diff_components/translations.ts

@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detection-rule-management (Team:Detection Rule Management)

@dplumlee
Copy link
Contributor Author

dplumlee commented Feb 7, 2024

buildkite test this

@jpdjere
Copy link
Contributor

jpdjere commented Feb 8, 2024

This one is an interesting one:

Change of Rule Type: Query ---> ESQL

image
image

@jpdjere
Copy link
Contributor

jpdjere commented Feb 8, 2024

Threat Indicator match changes:

image
image

Additional data_source change

image

Concurrent items_per_search and concurrent_searches

image

@jpdjere
Copy link
Contributor

jpdjere commented Feb 8, 2024

Threshold rules

image

@jpdjere
Copy link
Contributor

jpdjere commented Feb 8, 2024

Machine Learning rule

image

image

Copy link
Contributor

@jpdjere jpdjere left a comment

Choose a reason for hiding this comment

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

Tested all types, looking good! LGTM ✅

@banderror banderror added Feature:Prebuilt Detection Rules Security Solution Prebuilt Detection Rules release_note:feature Makes this part of the condensed release notes and removed Feature:Rule Management Security Solution Detection Rule Management release_note:enhancement labels Feb 9, 2024
Copy link
Contributor

@banderror banderror left a comment

Choose a reason for hiding this comment

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

@dplumlee Reviewed changes in the code and left a few suggestions, most of them for further improvements in follow-up PRs.

But overall it looks great: components are clean and separated into logical pieces, the implementation is easy to comprehend. LGTM 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I get the current folder structure and where what components are supposed to be kept:

/rule_management/components/rule_details
  /diff_components/*
  /json_diff/*
  /per_field_diff/*
  /per_field_rule_diff_tab.tsx
  /rule_diff_tab.tsx

I'd like to propose a structure that would represent the actual components' hierarchy. Something like that:

/rule_management/components/rule_details
  /sections
    /rule_about_section.tsx
    /rule_definition_section.tsx
    /etc
  /flyout
    /rule_details_flyout.tsx
    /use_rule_details_flyout.tsx
    /diffs
      /common diff components and utils go here
    /tabs
      /json_diff_tab
      /per_field_diff_tab
      /overview_tab

If that makes sense, I'd suggest to do it in a separate PR.

Comment on lines +174 to +200
export const getFieldDiffsForEqlQuery = (eqlQuery: AllFieldsDiff['eql_query']): FieldDiff[] => {
const currentQuery = sortAndStringifyJson(eqlQuery.current_version?.query);
const targetQuery = sortAndStringifyJson(eqlQuery.target_version?.query);

const currentFilters = sortAndStringifyJson(eqlQuery.current_version?.filters);
const targetFilters = sortAndStringifyJson(eqlQuery.target_version?.filters);
return [
...(currentQuery !== targetQuery
? [
{
fieldName: 'query',
currentVersion: currentQuery,
targetVersion: targetQuery,
},
]
: []),
...(currentFilters !== targetFilters
? [
{
fieldName: 'filters',
currentVersion: currentFilters,
targetVersion: targetFilters,
},
]
: []),
];
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This file contains a lot of code (461 lines) and most of it looks very repetitive. If you take a closer look, most of the functions take some object in parameters, and for each of its properties yield either a FieldDiff or nothing. I feel like we could replace most of the code in this file with some kind of generic implementation for calculating a FieldDiff[] for a given ThreeWayDiff input.

Again, I'd suggest trying to tackle this in a separate PR with refactoring and probably after covering the current implementation with tests.

@dplumlee dplumlee enabled auto-merge (squash) February 12, 2024 06:04
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 4960 4970 +10

Async chunks

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

id before after diff
securitySolution 11.4MB 11.4MB +16.4KB

Page load bundle

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

id before after diff
securitySolution 70.6KB 70.7KB +39.0B

History

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

cc @dplumlee

@dplumlee dplumlee merged commit d9bc1a4 into elastic:main Feb 12, 2024
34 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Feb 12, 2024
@dplumlee dplumlee deleted the rule-upgrade-diff-phase-2 branch February 12, 2024 15:26
CoenWarmer pushed a commit to CoenWarmer/kibana that referenced this pull request Feb 15, 2024
## Summary

Addresses elastic#166489
Docs issue: elastic/security-docs#4783

Adds per-field diffs for the rule upgrade flyout 

### Acceptance Criteria

- [x] The tab with per-field diffs is hidden behind a new feature flag.
When the flag is off, the tab does not appear in the flyout. The tab
should work regardless of the value of
`jsonPrebuiltRulesDiffingEnabled`.
- [x] Per-field diffs are read-only components. We don't need to let the
user "merge" differences using these components.
- [x] Diffs for complex fields are rendered as JSON diffs using the same
component used for rendering the JSON diff for the whole rule. This
means this component should be abstracted away and should accept
`unknown` values in props instead of `RuleResponse`.
- [x] Diffs for related fields are grouped or rendered close to each
other. For example:
  - [x] Index patterns + Data view id
  - [x] Custom query + Filters + Language + Saved query id
- [x] The tab uses the response from the `upgrade/_review` API endpoint
and doesn't need any other API calls to render itself.
- [x] The tab renders itself under 150ms.

### Screenshots

<img width="1587" alt="Screenshot 2024-02-07 at 1 36 34 AM"
src="https://github.com/elastic/kibana/assets/56367316/85dce529-064e-4025-b82c-2e89f6ec800b">
<img width="994" alt="Screenshot 2024-02-07 at 1 36 52 AM"
src="https://github.com/elastic/kibana/assets/56367316/c226973f-ad46-4565-90c0-437316b138b4">

### Checklist

Delete any items that are not applicable to this PR.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: jpdjere <[email protected]>
fkanout pushed a commit to fkanout/kibana that referenced this pull request Mar 4, 2024
## Summary

Addresses elastic#166489
Docs issue: elastic/security-docs#4783

Adds per-field diffs for the rule upgrade flyout 

### Acceptance Criteria

- [x] The tab with per-field diffs is hidden behind a new feature flag.
When the flag is off, the tab does not appear in the flyout. The tab
should work regardless of the value of
`jsonPrebuiltRulesDiffingEnabled`.
- [x] Per-field diffs are read-only components. We don't need to let the
user "merge" differences using these components.
- [x] Diffs for complex fields are rendered as JSON diffs using the same
component used for rendering the JSON diff for the whole rule. This
means this component should be abstracted away and should accept
`unknown` values in props instead of `RuleResponse`.
- [x] Diffs for related fields are grouped or rendered close to each
other. For example:
  - [x] Index patterns + Data view id
  - [x] Custom query + Filters + Language + Saved query id
- [x] The tab uses the response from the `upgrade/_review` API endpoint
and doesn't need any other API calls to render itself.
- [x] The tab renders itself under 150ms.

### Screenshots

<img width="1587" alt="Screenshot 2024-02-07 at 1 36 34 AM"
src="https://github.com/elastic/kibana/assets/56367316/85dce529-064e-4025-b82c-2e89f6ec800b">
<img width="994" alt="Screenshot 2024-02-07 at 1 36 52 AM"
src="https://github.com/elastic/kibana/assets/56367316/c226973f-ad46-4565-90c0-437316b138b4">

### Checklist

Delete any items that are not applicable to this PR.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: jpdjere <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Prebuilt Detection Rules Security Solution Prebuilt Detection Rules release_note:feature Makes this part of the condensed release notes Team:Detection Rule Management Security Detection Rule Management Team Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants