[Security Solution] Rule filters: saved object migrations #147441
Labels
Feature:Rule Management
Security Solution Detection Rule Management area
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.
technical debt
Improvement of the software architecture and operational architecture
Epic: #138606
Related to: #147438
Summary
Currently, query filters stored in rules of selected types are typed as an array of
t.unknown
values which allows a user to store anything in there via the API.kibana/x-pack/plugins/security_solution/common/detection_engine/rule_schema/model/common_attributes/misc_attributes.ts
Lines 100 to 105 in 47ad5ed
For example, for the Custom Query rules, filters are defined here:
kibana/x-pack/plugins/security_solution/common/detection_engine/rule_schema/model/rule_schemas.ts
Line 303 in 47ad5ed
kibana/x-pack/plugins/security_solution/server/lib/detection_engine/rule_schema/model/rule_schemas.ts
Line 175 in 47ad5ed
In the UI, filter objects are created by UI components we don't own. These components evolve over time and can change (see example PR), sometimes the model of the filters can change in a backward-incompatible way as well.
Since we store filters in detection rules but don't migrate them, there's a risk that a breaking change in the filters model can break existing rules that users already created, when they upgrade kibana to a new version. Both the UI and the rule executors could be affected by that.
We need to make sure that we migrate filters in rules every time their model changes.
To do
This has already been solved for Lens saved objects (ticket, PR) and we need to replicate this for rules in the Alerting Framework.
Lens is an object that contains filters in the
attributes.state.filters
field (just like rules contain them in theattributes.alert.params.filters
field). It is migrated here given a map of existing migrations for filters:kibana/x-pack/plugins/lens/server/migrations/common_migrations.ts
Lines 341 to 353 in 47ad5ed
The map of filter migrations is exposed from the
data
plugin:kibana/x-pack/plugins/lens/server/plugin.tsx
Lines 63 to 65 in 47ad5ed
Finally, own lens migrations are merged with external filter migrations here:
kibana/x-pack/plugins/lens/server/migrations/saved_object_migrations.ts
Lines 565 to 605 in 47ad5ed
We need to do something similar for rules migrations in the
alerting
plugin:kibana/x-pack/plugins/alerting/server/saved_objects/migrations/index.ts
Lines 38 to 83 in 47ad5ed
The text was updated successfully, but these errors were encountered: