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] Fix not complete existing rule overwrite when importing rules #176166

Merged
merged 10 commits into from
Feb 19, 2024

Conversation

maximpn
Copy link
Contributor

@maximpn maximpn commented Feb 2, 2024

Fixes: #93342
Fixes: #118166

Summary

This PR fixes not complete existing rule overwrite when importing rules.

Details

When importing a rule and attempting to overwrite an existing rule, if the new rule does not define a field that the existing rule did define then the newly imported rule will include the field from the existing rule. This can cause issues if we want to overwrite a rule with a rule of a different type, e.g. going from saved_query to query we would provide a new rule that doesn't have a saved_id but since saved_id was defined on the old saved_query rule it will be included in the new query rule.

The fix simply swaps out the patchRules() for updateRules(). Patching rules preserves previous field values if an incoming update doesn't have such fields while updating doesn't do that. The diff in import_rules_utils.test.ts looks bigger due to removing unnecessary else clause.

Checklist

@maximpn maximpn added bug Fixes for quality problems that affect the customer experience release_note:fix impact:medium Addressing this issue will have a medium level of impact on the quality/strength of our product. 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 area Team:Detection Rule Management Security Detection Rule Management Team Feature:Rule Import/Export Security Solution Detection Rule Import & Export workflow v8.13.0 labels Feb 2, 2024
@maximpn maximpn self-assigned this Feb 2, 2024
@maximpn maximpn changed the title [Security Solution] Fix automatic rule overwrite during import [Security Solution] Fix not complete existing rule overwrite when importing rules Feb 2, 2024
@maximpn maximpn added the v8.12.2 label Feb 3, 2024
@maximpn maximpn marked this pull request as ready for review February 3, 2024 08:25
@maximpn maximpn requested review from a team as code owners February 3, 2024 08:25
@maximpn maximpn requested review from jpdjere and vitaliidm February 3, 2024 08:25
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

@maximpn maximpn force-pushed the fix-rule-override-at-import branch from 42e5816 to 42e2dfb Compare February 3, 2024 08:25
@maximpn maximpn marked this pull request as draft February 5, 2024 07:58
@maximpn maximpn force-pushed the fix-rule-override-at-import branch from 42e2dfb to 60bb17c Compare February 5, 2024 08:27
@maximpn
Copy link
Contributor Author

maximpn commented Feb 5, 2024

/ci

@maximpn maximpn force-pushed the fix-rule-override-at-import branch from 60bb17c to 92f3d75 Compare February 13, 2024 22:06
@maximpn
Copy link
Contributor Author

maximpn commented Feb 13, 2024

/ci

@maximpn maximpn force-pushed the fix-rule-override-at-import branch from 92f3d75 to 7760aac Compare February 14, 2024 07:47
@maximpn
Copy link
Contributor Author

maximpn commented Feb 14, 2024

/ci

@maximpn maximpn marked this pull request as ready for review February 14, 2024 09:27
@maximpn maximpn force-pushed the fix-rule-override-at-import branch from 7760aac to af64d04 Compare February 15, 2024 12:53
@maximpn maximpn force-pushed the fix-rule-override-at-import branch from af64d04 to d6c5566 Compare February 19, 2024 10:18
Copy link
Contributor

@vitaliidm vitaliidm left a comment

Choose a reason for hiding this comment

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

detection engine area LGTM

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

✅ unchanged

History

  • 💛 Build #193810 was flaky af64d046885cb9c6f3238eefd7e3187b37980035
  • 💛 Build #193529 was flaky 7760aac196e0544a8a2634529e39098174cbbf34
  • 💔 Build #193465 failed 92f3d75115b243695240045deea8b4e6259418bc
  • 💔 Build #191256 failed 60bb17c3dd9931b0d29ef72fdc896eedb3f2531c
  • 💔 Build #191209 failed 42e2dfb4d20d765b2d7a22e2156bb4c5cf29c6b5

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

cc @maximpn

@maximpn maximpn merged commit 53aaab4 into elastic:main Feb 19, 2024
36 checks passed
@maximpn maximpn deleted the fix-rule-override-at-import branch February 19, 2024 13:35
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Feb 19, 2024
…orting rules (elastic#176166)

**Fixes: elastic#93342
**Fixes: elastic#118166

## Summary

This PR fixes not complete existing rule overwrite when importing rules.

## Details

When importing a rule and attempting to overwrite an existing rule, if the new rule does not define a field that the existing rule did define then the newly imported rule will include the field from the existing rule. This can cause issues if we want to overwrite a rule with a rule of a different type, e.g. going from saved_query to query we would provide a new rule that doesn't have a saved_id but since saved_id was defined on the old saved_query rule it will be included in the new query rule.

The fix simply swaps out the `patchRules()` for `updateRules()`. Patching rules preserves previous field values if an incoming update doesn't have such fields while updating doesn't do that. The diff in `import_rules_utils.test.ts` looks bigger due to removing unnecessary `else` clause.

### Checklist

- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- [x] Ran successfully in Flaky test runner ([basic/essentials license FTR tests](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5166) and [trial/complete tier license FTR tests](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5167))

(cherry picked from commit 53aaab4)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
8.12 Backport failed because of merge conflicts

You might need to backport the following PRs to 8.12:
- [Detections Response][FTR] FTR migration cleanup (#173403)
8.13

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

Manual backport

To create the backport manually run:

node scripts/backport --pr 176166

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Feb 19, 2024
…hen importing rules (#176166) (#177196)

# Backport

This will backport the following commits from `main` to `8.13`:
- [[Security Solution] Fix not complete existing rule overwrite when
importing rules
(#176166)](#176166)

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

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

<!--BACKPORT [{"author":{"name":"Maxim
Palenov","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-02-19T13:35:32Z","message":"[Security
Solution] Fix not complete existing rule overwrite when importing rules
(#176166)\n\n**Fixes:
https://github.com/elastic/kibana/issues/93342**\r\n**Fixes:
https://github.com/elastic/kibana/issues/118166**\r\n\r\n##
Summary\r\n\r\nThis PR fixes not complete existing rule overwrite when
importing rules.\r\n\r\n## Details\r\n\r\nWhen importing a rule and
attempting to overwrite an existing rule, if the new rule does not
define a field that the existing rule did define then the newly imported
rule will include the field from the existing rule. This can cause
issues if we want to overwrite a rule with a rule of a different type,
e.g. going from saved_query to query we would provide a new rule that
doesn't have a saved_id but since saved_id was defined on the old
saved_query rule it will be included in the new query rule.\r\n\r\nThe
fix simply swaps out the `patchRules()` for `updateRules()`. Patching
rules preserves previous field values if an incoming update doesn't have
such fields while updating doesn't do that. The diff in
`import_rules_utils.test.ts` looks bigger due to removing unnecessary
`else` clause.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios\r\n- [x] Ran
successfully in Flaky test runner ([basic/essentials license FTR
tests](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5166)
and [trial/complete tier license FTR
tests](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5167))","sha":"53aaab47322fd15ad232d71a1749fd2df8a5dde4","branchLabelMapping":{"^v8.14.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","impact:medium","Team:Detections
and Resp","Team: SecuritySolution","Feature:Rule
Management","Team:Detection Rule Management","Feature:Rule
Import/Export","v8.13.0","v8.12.2","v8.14.0"],"title":"[Security
Solution] Fix not complete existing rule overwrite when importing
rules","number":176166,"url":"https://github.com/elastic/kibana/pull/176166","mergeCommit":{"message":"[Security
Solution] Fix not complete existing rule overwrite when importing rules
(#176166)\n\n**Fixes:
https://github.com/elastic/kibana/issues/93342**\r\n**Fixes:
https://github.com/elastic/kibana/issues/118166**\r\n\r\n##
Summary\r\n\r\nThis PR fixes not complete existing rule overwrite when
importing rules.\r\n\r\n## Details\r\n\r\nWhen importing a rule and
attempting to overwrite an existing rule, if the new rule does not
define a field that the existing rule did define then the newly imported
rule will include the field from the existing rule. This can cause
issues if we want to overwrite a rule with a rule of a different type,
e.g. going from saved_query to query we would provide a new rule that
doesn't have a saved_id but since saved_id was defined on the old
saved_query rule it will be included in the new query rule.\r\n\r\nThe
fix simply swaps out the `patchRules()` for `updateRules()`. Patching
rules preserves previous field values if an incoming update doesn't have
such fields while updating doesn't do that. The diff in
`import_rules_utils.test.ts` looks bigger due to removing unnecessary
`else` clause.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios\r\n- [x] Ran
successfully in Flaky test runner ([basic/essentials license FTR
tests](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5166)
and [trial/complete tier license FTR
tests](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5167))","sha":"53aaab47322fd15ad232d71a1749fd2df8a5dde4"}},"sourceBranch":"main","suggestedTargetBranches":["8.13","8.12"],"targetPullRequestStates":[{"branch":"8.13","label":"v8.13.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.12","label":"v8.12.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.14.0","branchLabelMappingKey":"^v8.14.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/176166","number":176166,"mergeCommit":{"message":"[Security
Solution] Fix not complete existing rule overwrite when importing rules
(#176166)\n\n**Fixes:
https://github.com/elastic/kibana/issues/93342**\r\n**Fixes:
https://github.com/elastic/kibana/issues/118166**\r\n\r\n##
Summary\r\n\r\nThis PR fixes not complete existing rule overwrite when
importing rules.\r\n\r\n## Details\r\n\r\nWhen importing a rule and
attempting to overwrite an existing rule, if the new rule does not
define a field that the existing rule did define then the newly imported
rule will include the field from the existing rule. This can cause
issues if we want to overwrite a rule with a rule of a different type,
e.g. going from saved_query to query we would provide a new rule that
doesn't have a saved_id but since saved_id was defined on the old
saved_query rule it will be included in the new query rule.\r\n\r\nThe
fix simply swaps out the `patchRules()` for `updateRules()`. Patching
rules preserves previous field values if an incoming update doesn't have
such fields while updating doesn't do that. The diff in
`import_rules_utils.test.ts` looks bigger due to removing unnecessary
`else` clause.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios\r\n- [x] Ran
successfully in Flaky test runner ([basic/essentials license FTR
tests](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5166)
and [trial/complete tier license FTR
tests](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5167))","sha":"53aaab47322fd15ad232d71a1749fd2df8a5dde4"}}]}]
BACKPORT-->

Co-authored-by: Maxim Palenov <[email protected]>
@banderror banderror removed the v8.12.2 label Feb 19, 2024
@maximpn
Copy link
Contributor Author

maximpn commented Feb 20, 2024

💚 All backports created successfully

Status Branch Result
8.12

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

Questions ?

Please refer to the Backport tool documentation

maximpn added a commit to maximpn/kibana that referenced this pull request Feb 20, 2024
…orting rules (elastic#176166)

**Fixes: elastic#93342
**Fixes: elastic#118166

## Summary

This PR fixes not complete existing rule overwrite when importing rules.

## Details

When importing a rule and attempting to overwrite an existing rule, if the new rule does not define a field that the existing rule did define then the newly imported rule will include the field from the existing rule. This can cause issues if we want to overwrite a rule with a rule of a different type, e.g. going from saved_query to query we would provide a new rule that doesn't have a saved_id but since saved_id was defined on the old saved_query rule it will be included in the new query rule.

The fix simply swaps out the `patchRules()` for `updateRules()`. Patching rules preserves previous field values if an incoming update doesn't have such fields while updating doesn't do that. The diff in `import_rules_utils.test.ts` looks bigger due to removing unnecessary `else` clause.

### Checklist

- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- [x] Ran successfully in Flaky test runner ([basic/essentials license FTR tests](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5166) and [trial/complete tier license FTR tests](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5167))

(cherry picked from commit 53aaab4)

# Conflicts:
#	x-pack/test/detection_engine_api_integration/basic/tests/export_rules.ts
#	x-pack/test/detection_engine_api_integration/basic/tests/import_rules.ts
#	x-pack/test/detection_engine_api_integration/basic/tests/import_rules_with_overwrite.ts
#	x-pack/test/detection_engine_api_integration/security_and_spaces/group1/export_rules.ts
#	x-pack/test/detection_engine_api_integration/security_and_spaces/group10/import_connectors.ts
#	x-pack/test/detection_engine_api_integration/security_and_spaces/group10/import_export_rules.ts
#	x-pack/test/detection_engine_api_integration/security_and_spaces/group10/import_rules.ts
#	x-pack/test/detection_engine_api_integration/security_and_spaces/group10/import_rules_with_overwrite.ts
#	x-pack/test/detection_engine_api_integration/utils/get_rules_as_ndjson.ts
#	x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/alerts/assignments/index.ts
#	x-pack/test/security_solution_api_integration/test_suites/detections_response/rules_management/rule_import_export/trial_license_complete_tier/export_rules.ts
#	x-pack/test/security_solution_api_integration/test_suites/detections_response/rules_management/rule_import_export/trial_license_complete_tier/import_rules_ess.ts
#	x-pack/test/security_solution_api_integration/test_suites/detections_response/rules_management/rule_import_export/trial_license_complete_tier/index.ts
#	x-pack/test/security_solution_api_integration/test_suites/detections_response/utils/rules/index.ts
maximpn added a commit that referenced this pull request Feb 20, 2024
…hen importing rules (#176166) (#177270)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[Security Solution] Fix not complete existing rule overwrite when
importing rules
(#176166)](#176166)

<!--- Backport version: 8.9.8 -->

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

mistic commented Feb 22, 2024

This PR didn't landed on time to be included on v8.12.2. Updating the labels.

@mistic mistic added the v8.12.3 label Feb 22, 2024
fkanout pushed a commit to fkanout/kibana that referenced this pull request Mar 4, 2024
…orting rules (elastic#176166)

**Fixes: elastic#93342
**Fixes: elastic#118166

## Summary

This PR fixes not complete existing rule overwrite when importing rules.

## Details

When importing a rule and attempting to overwrite an existing rule, if the new rule does not define a field that the existing rule did define then the newly imported rule will include the field from the existing rule. This can cause issues if we want to overwrite a rule with a rule of a different type, e.g. going from saved_query to query we would provide a new rule that doesn't have a saved_id but since saved_id was defined on the old saved_query rule it will be included in the new query rule.

The fix simply swaps out the `patchRules()` for `updateRules()`. Patching rules preserves previous field values if an incoming update doesn't have such fields while updating doesn't do that. The diff in `import_rules_utils.test.ts` looks bigger due to removing unnecessary `else` clause.

### Checklist

- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- [x] Ran successfully in Flaky test runner ([basic/essentials license FTR tests](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5166) and [trial/complete tier license FTR tests](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5167))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Rule Import/Export Security Solution Detection Rule Import & Export workflow Feature:Rule Management Security Solution Detection Rule Management area impact:medium Addressing this issue will have a medium level of impact on the quality/strength of our product. release_note:fix 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.12.3 v8.13.0 v8.14.0
Projects
None yet
8 participants