Skip to content

[8.13] [Security Solution] Fix not complete existing rule overwrite when importing rules (#176166)#177196

Merged
kibanamachine merged 1 commit intoelastic:8.13from
kibanamachine:backport/8.13/pr-176166
Feb 19, 2024
Merged

[8.13] [Security Solution] Fix not complete existing rule overwrite when importing rules (#176166)#177196
kibanamachine merged 1 commit intoelastic:8.13from
kibanamachine:backport/8.13/pr-176166

Conversation

@kibanamachine
Copy link
Copy Markdown
Contributor

Backport

This will backport the following commits from main to 8.13:

Questions ?

Please refer to the Backport tool documentation

…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)
@kibana-ci
Copy link
Copy Markdown

💚 Build Succeeded

Metrics [docs]

✅ unchanged

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

cc @maximpn

@kibanamachine kibanamachine merged commit 2bbf6c3 into elastic:8.13 Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants