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] FinalEdit: Add fields that are common for all rule types #196642

Merged
merged 34 commits into from
Nov 12, 2024

Conversation

nikitaindik
Copy link
Contributor

@nikitaindik nikitaindik commented Oct 17, 2024

Partially addresses: #171520
Is a follow-up to: #196326

This PR enables editing of common fields in the new "Updates" tab of the rule upgrade flyout. The common fields are fields applicable to all rule types.

Summary

These fields are editable now:

  • building_block
  • description
  • false_positives
  • investigation_fields
  • max_signals
  • note
  • references
  • related_integrations
  • required_fields
  • risk_score
  • risk_score_mapping
  • rule_name_override
  • rule_schedule
  • setup
  • severity
  • severity_mapping
  • tags
  • threat
  • timeline_template
  • timestamp_override
Scherm­afbeelding 2024-10-16 om 17 32 06

Testing

  • Ensure the prebuiltRulesCustomizationEnabled feature flag is enabled.
  • To simulate the availability of prebuilt rule upgrades, downgrade a currently installed prebuilt rule using the PATCH api/detection_engine/rules API.
    • Set version: 1 in the request body to downgrade it to version 1.
    • Modify other rule fields in the request body as needed to test the changes.

@nikitaindik nikitaindik added release_note:skip Skip the PR/issue when compiling release notes Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Detection Rule Management Security Detection Rule Management Team Feature:Prebuilt Detection Rules Security Solution Prebuilt Detection Rules area backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) labels Oct 17, 2024
@nikitaindik nikitaindik self-assigned this Oct 17, 2024
@nikitaindik nikitaindik force-pushed the editable-common-fields-2 branch from cfacec3 to 19ddb83 Compare October 17, 2024 11:57
@nikitaindik nikitaindik force-pushed the editable-common-fields-2 branch from 0f789a4 to 6377545 Compare October 23, 2024 13:27
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

@nikitaindik nikitaindik removed the request for review from dplumlee November 8, 2024 15:14
@nikitaindik
Copy link
Contributor Author

@maximpn UPD

These two issues are not easy to fix due to the way the dropdown component is built. Let's discuss how we should approach this offline.

I've used the approach that we discussed offline and fixed these two as well in 66afe18

@nikitaindik nikitaindik requested a review from maximpn November 10, 2024 15:39
Copy link
Contributor

@maximpn maximpn left a comment

Choose a reason for hiding this comment

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

@nikitaindik I had a look at the recent changes and left comments. I think we should make slight improvements before merging it back.

const { selectedField, indexPattern } = useMemo(() => {
/* eslint-disable @typescript-eslint/no-shadow */
/* If the field is not found in the indices, we still want to show it in the dropdown */
const selectedField = foundField || { name: field.value, type: fieldType };
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to use a different name inside useMemo and remove eslint-disable.

);
return newSelectedField;
}, [field.value, indices]);
const foundField = field.value && indices.fields.find(({ name }) => name === field.value);
Copy link
Contributor

Choose a reason for hiding this comment

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

This line should be inside useMemo()'s callback.

Comment on lines 45 to 55
const { selectedField, indexPattern } = useMemo(() => {
/* eslint-disable @typescript-eslint/no-shadow */
/* If the field is not found in the indices, we still want to show it in the dropdown */
const selectedField = foundField || { name: field.value, type: fieldType };
const indexPattern = foundField
? indices
: { ...indices, fields: [...indices.fields, selectedField] };

return { selectedField, indexPattern };
/* eslint-enable @typescript-eslint/no-shadow */
}, [field.value, indices, foundField, fieldType]);
Copy link
Contributor

Choose a reason for hiding this comment

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

For better readability this logic could be moved to an "internal" hook named like useSelectedField() and placed under the component in the file.

Though it might be better to have this logic in FieldComponent.

@nikitaindik
Copy link
Contributor Author

@maximpn Thanks for taking another look Maxim and discussing it with me over Zoom. I've pushed a commit that addresses your feedback and also:

  • Renames AutocompleteField to EsFieldSelectorField
  • Renames FieldComponent to EsFieldSelector
  • Renames useField to useEsField

Please take a look.

@nikitaindik nikitaindik requested a review from maximpn November 11, 2024 12:47
Copy link
Contributor

@nkhristinin nkhristinin left a comment

Choose a reason for hiding this comment

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

I tested locally, updated flow and create/edit rule. LGTM

Left some question about implementations

) {
/*
Getting values for required fields via flattened fields instead of using `getFormData`.
This is because `getFormData` applies a serializer function to field values, which might update values.
Copy link
Contributor

@nkhristinin nkhristinin Nov 11, 2024

Choose a reason for hiding this comment

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

How exactly serializer update values? Or, why it's a problem for our case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Serializer is a function you can pass to the form library. It converts form data from an internal format to an output format when you click Submit.

To get the form data for validation, we normally use form.getFormData(). However, this method internally calls the serializer. In this case, we need the form data in its internal format, before it is serialized, because the returned value would be different if you pass a different serialzers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In our case we have no serializer on the Rule Editing page, but we do have one in the flyout

@@ -26,3 +28,13 @@ export function pickTypeForName({ name, type, typesByFieldName = {} }: PickTypeF
*/
return typesAvailableForName[0] ?? type;
}

export function getFlattenedArrayFieldNames(
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 that commment, is enough. We rely on internal implmenatin, and if it chanes, we don't have ability to notice that our function don't work.

Ar least we should have a tests for his function, which use real form implmentaion

But can we maybe use getInternalArrayFieldPath function from the forms?

@@ -44,14 +44,6 @@ export const RequiredFieldRow = ({
const rowFieldConfig: FieldConfig<RequiredField | RequiredFieldInput, {}, RequiredFieldInput> =
useMemo(
() => ({
deserializer: (value) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we removing that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was needed to convert the type from RequiredField to RequiredFieldInput, but I've modified the component to use RequiredField, so this conversion is no longer needed.

@@ -26,3 +28,13 @@ export function pickTypeForName({ name, type, typesByFieldName = {} }: PickTypeF
*/
return typesAvailableForName[0] ?? type;
}

export function getFlattenedArrayFieldNames(
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I see that you didn't add this code, it was already there.

Still if possible add tests, or reuse getInternalArrayFieldPath will be great

const fieldTypeFilter = useMemo(() => [fieldType], [fieldType]);
const { selectedField, indexPattern } = useMemo(() => {
/* eslint-disable @typescript-eslint/no-shadow */
/* If the field is not found in the indices, we still want to show it in the dropdown */
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure what we want to show it in dropdown?

Will be ther any error or message that field not in index?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I ended up removing this part and reverting to previous behaviour. It turned out we already handle such case in a nested component.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 6135 6163 +28

Async chunks

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

id before after diff
lists 144.9KB 144.9KB -15.0B
securitySolution 13.4MB 13.4MB +13.7KB
total +13.6KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
@kbn/securitysolution-autocomplete 1 0 -1
Unknown metric groups

ESLint disabled line counts

id before after diff
securitySolution 553 554 +1

Total ESLint disabled count

id before after diff
securitySolution 639 640 +1

History

cc @nikitaindik

Copy link
Contributor

@maximpn maximpn left a comment

Choose a reason for hiding this comment

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

@nikitaindik Thanks for addressing my comments 🙏

I tested the PR on the latest commit and editable components work as expected 👍

@maximpn
Copy link
Contributor

maximpn commented Nov 11, 2024

@nkhristinin There is time constrain on Prebuilt Rule Customization readiness. Do you think there is something critical in you comments and should be addressed in this PR? I created a ticket for rule creation/editing forms improvements. Let's add any desired enhancements/improvements to that ticket.

@nkhristinin
Copy link
Contributor

@maximpn I think we can add tests for this function later #196642 (comment)

Other comments, not blocking, more requesting reason for those changes

@nkhristinin nkhristinin self-requested a review November 12, 2024 08:44
@maximpn maximpn merged commit 3d3b32f into elastic:main Nov 12, 2024
43 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/11794964800

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Nov 12, 2024
…ule types (elastic#196642)

**Partially addresses: elastic#171520
**Is a follow-up to: elastic#196326

This PR enables editing of common fields in the new "Updates" tab of the rule upgrade flyout. The common fields are fields applicable to all rule types.

## Summary
These fields are editable now:
 - `building_block`
 - `description`
 - `false_positives`
 - `investigation_fields`
 - `max_signals`
 - `note`
 - `references`
 - `related_integrations`
 - `required_fields`
 - `risk_score`
 - `risk_score_mapping`
 - `rule_name_override`
 - `rule_schedule`
 - `setup`
 - `severity`
 - `severity_mapping`
 - `tags`
 - `threat`
 - `timeline_template`
 - `timestamp_override`

<img width="2672" alt="Scherm­afbeelding 2024-10-16 om 17 32 06" src="https://github.com/user-attachments/assets/6dd615e2-6e84-4e1f-b674-f42d03f575e7">

### Testing
 - Ensure the `prebuiltRulesCustomizationEnabled` feature flag is enabled.
 - To simulate the availability of prebuilt rule upgrades, downgrade a currently installed prebuilt rule using the `PATCH api/detection_engine/rules` API.
   - Set `version: 1` in the request body to downgrade it to version 1.
   - Modify other rule fields in the request body as needed to test the changes.

(cherry picked from commit 3d3b32f)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Nov 12, 2024
…common for all rule types (#196642) (#199743)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Solution] &#x60;FinalEdit&#x60;: Add fields that are common
for all rule types
(#196642)](#196642)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Nikita
Indik","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-12T10:04:10Z","message":"[Security
Solution] `FinalEdit`: Add fields that are common for all rule types
(#196642)\n\n**Partially addresses:
https://github.com/elastic/kibana/issues/171520**\r\n**Is a follow-up
to: https://github.com/elastic/kibana/pull/196326**\r\n\r\nThis PR
enables editing of common fields in the new \"Updates\" tab of the rule
upgrade flyout. The common fields are fields applicable to all rule
types.\r\n\r\n## Summary\r\nThese fields are editable now:\r\n -
`building_block`\r\n - `description`\r\n - `false_positives`\r\n -
`investigation_fields`\r\n - `max_signals`\r\n - `note`\r\n -
`references`\r\n - `related_integrations`\r\n - `required_fields`\r\n -
`risk_score`\r\n - `risk_score_mapping`\r\n - `rule_name_override`\r\n -
`rule_schedule`\r\n - `setup`\r\n - `severity`\r\n -
`severity_mapping`\r\n - `tags`\r\n - `threat`\r\n -
`timeline_template`\r\n - `timestamp_override`\r\n\r\n<img
width=\"2672\" alt=\"Scherm­afbeelding 2024-10-16 om 17 32 06\"
src=\"https://github.com/user-attachments/assets/6dd615e2-6e84-4e1f-b674-f42d03f575e7\">\r\n\r\n###
Testing\r\n - Ensure the `prebuiltRulesCustomizationEnabled` feature
flag is enabled.\r\n - To simulate the availability of prebuilt rule
upgrades, downgrade a currently installed prebuilt rule using the `PATCH
api/detection_engine/rules` API. \r\n - Set `version: 1` in the request
body to downgrade it to version 1.\r\n - Modify other rule fields in the
request body as needed to test the
changes.","sha":"3d3b32faf6992f95805a37230e7e7e552e19a801","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Detections
and Resp","Team: SecuritySolution","Team:Detection Rule
Management","Feature:Prebuilt Detection
Rules","backport:prev-minor"],"title":"[Security Solution] `FinalEdit`:
Add fields that are common for all rule
types","number":196642,"url":"https://github.com/elastic/kibana/pull/196642","mergeCommit":{"message":"[Security
Solution] `FinalEdit`: Add fields that are common for all rule types
(#196642)\n\n**Partially addresses:
https://github.com/elastic/kibana/issues/171520**\r\n**Is a follow-up
to: https://github.com/elastic/kibana/pull/196326**\r\n\r\nThis PR
enables editing of common fields in the new \"Updates\" tab of the rule
upgrade flyout. The common fields are fields applicable to all rule
types.\r\n\r\n## Summary\r\nThese fields are editable now:\r\n -
`building_block`\r\n - `description`\r\n - `false_positives`\r\n -
`investigation_fields`\r\n - `max_signals`\r\n - `note`\r\n -
`references`\r\n - `related_integrations`\r\n - `required_fields`\r\n -
`risk_score`\r\n - `risk_score_mapping`\r\n - `rule_name_override`\r\n -
`rule_schedule`\r\n - `setup`\r\n - `severity`\r\n -
`severity_mapping`\r\n - `tags`\r\n - `threat`\r\n -
`timeline_template`\r\n - `timestamp_override`\r\n\r\n<img
width=\"2672\" alt=\"Scherm­afbeelding 2024-10-16 om 17 32 06\"
src=\"https://github.com/user-attachments/assets/6dd615e2-6e84-4e1f-b674-f42d03f575e7\">\r\n\r\n###
Testing\r\n - Ensure the `prebuiltRulesCustomizationEnabled` feature
flag is enabled.\r\n - To simulate the availability of prebuilt rule
upgrades, downgrade a currently installed prebuilt rule using the `PATCH
api/detection_engine/rules` API. \r\n - Set `version: 1` in the request
body to downgrade it to version 1.\r\n - Modify other rule fields in the
request body as needed to test the
changes.","sha":"3d3b32faf6992f95805a37230e7e7e552e19a801"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/196642","number":196642,"mergeCommit":{"message":"[Security
Solution] `FinalEdit`: Add fields that are common for all rule types
(#196642)\n\n**Partially addresses:
https://github.com/elastic/kibana/issues/171520**\r\n**Is a follow-up
to: https://github.com/elastic/kibana/pull/196326**\r\n\r\nThis PR
enables editing of common fields in the new \"Updates\" tab of the rule
upgrade flyout. The common fields are fields applicable to all rule
types.\r\n\r\n## Summary\r\nThese fields are editable now:\r\n -
`building_block`\r\n - `description`\r\n - `false_positives`\r\n -
`investigation_fields`\r\n - `max_signals`\r\n - `note`\r\n -
`references`\r\n - `related_integrations`\r\n - `required_fields`\r\n -
`risk_score`\r\n - `risk_score_mapping`\r\n - `rule_name_override`\r\n -
`rule_schedule`\r\n - `setup`\r\n - `severity`\r\n -
`severity_mapping`\r\n - `tags`\r\n - `threat`\r\n -
`timeline_template`\r\n - `timestamp_override`\r\n\r\n<img
width=\"2672\" alt=\"Scherm­afbeelding 2024-10-16 om 17 32 06\"
src=\"https://github.com/user-attachments/assets/6dd615e2-6e84-4e1f-b674-f42d03f575e7\">\r\n\r\n###
Testing\r\n - Ensure the `prebuiltRulesCustomizationEnabled` feature
flag is enabled.\r\n - To simulate the availability of prebuilt rule
upgrades, downgrade a currently installed prebuilt rule using the `PATCH
api/detection_engine/rules` API. \r\n - Set `version: 1` in the request
body to downgrade it to version 1.\r\n - Modify other rule fields in the
request body as needed to test the
changes.","sha":"3d3b32faf6992f95805a37230e7e7e552e19a801"}}]}]
BACKPORT-->

Co-authored-by: Nikita Indik <[email protected]>
tkajtoch pushed a commit to tkajtoch/kibana that referenced this pull request Nov 12, 2024
…ule types (elastic#196642)

**Partially addresses: elastic#171520
**Is a follow-up to: elastic#196326

This PR enables editing of common fields in the new "Updates" tab of the rule upgrade flyout. The common fields are fields applicable to all rule types.

## Summary
These fields are editable now:
 - `building_block`
 - `description`
 - `false_positives`
 - `investigation_fields`
 - `max_signals`
 - `note`
 - `references`
 - `related_integrations`
 - `required_fields`
 - `risk_score`
 - `risk_score_mapping`
 - `rule_name_override`
 - `rule_schedule`
 - `setup`
 - `severity`
 - `severity_mapping`
 - `tags`
 - `threat`
 - `timeline_template`
 - `timestamp_override`

<img width="2672" alt="Scherm­afbeelding 2024-10-16 om 17 32 06" src="https://github.com/user-attachments/assets/6dd615e2-6e84-4e1f-b674-f42d03f575e7">

### Testing
 - Ensure the `prebuiltRulesCustomizationEnabled` feature flag is enabled.
 - To simulate the availability of prebuilt rule upgrades, downgrade a currently installed prebuilt rule using the `PATCH api/detection_engine/rules` API. 
   - Set `version: 1` in the request body to downgrade it to version 1.
   - Modify other rule fields in the request body as needed to test the changes.
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Nov 18, 2024
…ule types (elastic#196642)

**Partially addresses: elastic#171520
**Is a follow-up to: elastic#196326

This PR enables editing of common fields in the new "Updates" tab of the rule upgrade flyout. The common fields are fields applicable to all rule types.

## Summary
These fields are editable now:
 - `building_block`
 - `description`
 - `false_positives`
 - `investigation_fields`
 - `max_signals`
 - `note`
 - `references`
 - `related_integrations`
 - `required_fields`
 - `risk_score`
 - `risk_score_mapping`
 - `rule_name_override`
 - `rule_schedule`
 - `setup`
 - `severity`
 - `severity_mapping`
 - `tags`
 - `threat`
 - `timeline_template`
 - `timestamp_override`

<img width="2672" alt="Scherm­afbeelding 2024-10-16 om 17 32 06" src="https://github.com/user-attachments/assets/6dd615e2-6e84-4e1f-b674-f42d03f575e7">

### Testing
 - Ensure the `prebuiltRulesCustomizationEnabled` feature flag is enabled.
 - To simulate the availability of prebuilt rule upgrades, downgrade a currently installed prebuilt rule using the `PATCH api/detection_engine/rules` API. 
   - Set `version: 1` in the request body to downgrade it to version 1.
   - Modify other rule fields in the request body as needed to test the changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Feature:Prebuilt Detection Rules Security Solution Prebuilt Detection Rules area release_note:skip Skip the PR/issue when compiling 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.17.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants