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

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

Merged
merged 1 commit into from
Feb 20, 2024

Conversation

maximpn
Copy link
Contributor

@maximpn maximpn commented Feb 20, 2024

Backport

This will backport the following commits from main to 8.12:

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)

# 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
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

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

cc @maximpn

@maximpn maximpn merged commit a687b96 into elastic:8.12 Feb 20, 2024
30 checks passed
@maximpn maximpn deleted the backport/8.12/pr-176166 branch February 20, 2024 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants