-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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] Handle specific fields in /upgrade/_review
endpoint and refactor diff logic to use Zod
#186615
Conversation
/upgrade/_review
endpoint and refactor diff logic to use Zod
x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema/time_duration.ts
Show resolved
Hide resolved
330ba29
to
c3f7492
Compare
/ci |
/ci |
Pinging @elastic/security-detections-response (Team:Detections and Resp) |
Pinging @elastic/security-solution (Team: SecuritySolution) |
Pinging @elastic/security-detection-rule-management (Team:Detection Rule Management) |
1afbb00
to
9fefee6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for addressing the comments @jpdjere, the PR looks great! Approving it ✅
Let's chat about any follow-ups separately.
// `response_actions` is only part of the optional fields in QueryRuleCreateFields and SavedQueryRuleCreateFields | ||
const TYPE_SPECIFIC_PROPS_REMOVED_FROM_PREBUILT_RULE_ASSET = zodMaskFor< | ||
QueryRuleCreateFields | SavedQueryRuleCreateFields | ||
>()(['response_actions']); | ||
|
||
const QueryRuleAssetFields = QueryRuleCreateFields.omit( | ||
TYPE_SPECIFIC_PROPS_REMOVED_FROM_PREBUILT_RULE_ASSET | ||
); | ||
const SavedQueryRuleAssetFields = SavedQueryRuleCreateFields.omit( | ||
TYPE_SPECIFIC_PROPS_REMOVED_FROM_PREBUILT_RULE_ASSET | ||
); | ||
|
||
export const RuleAssetTypeSpecificCreateProps = z.discriminatedUnion('type', [ | ||
EqlRuleCreateFields, | ||
QueryRuleAssetFields, | ||
SavedQueryRuleAssetFields, | ||
ThresholdRuleCreateFields, | ||
ThreatMatchRuleCreateFields, | ||
MachineLearningRuleCreateFields, | ||
NewTermsRuleCreateFields, | ||
EsqlRuleCreateFields, | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The added complexity worries me a bit, + this is yet another place where we should add a new rule type once it is added to RuleResponse
. Let's chat over zoom.
Four pending follow-ups from this PR, as discussed with @banderror during sync review:
|
…h Zod transform (#188092) ## Summary Pending work from: #186615 - The previous implementation to create `PrebuiltRuleAsset` with some RuleResponse fields ommited from it had the disadvantage of being built with a discriminated union where all rule types had to be re-listed. If a new type was added, then it would have required manually adding the type to that union as well, which would have been surely forgotten. - This replaces that schema construction to use a Zod transform which simply eliminates the omitted fields using a Zod transform. ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
#188079) ## Summary Leftover work from #186615 - Removes remaining usage of `rule_schema_legacy` types. In this PR, simply inlines the last io-ts types used, to be able to get rid of the legacy folder. - The remaining files that need to be migrated to using Zod schema types are: - `x-pack/plugins/security_solution/common/api/detection_engine/rule_exceptions/find_exception_references/find_exception_references_route.ts` - `x-pack/plugins/security_solution/common/api/timeline/model/api.ts` ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: Georgii Gorbachev <georgii.gorbachev@elastic.co>
Fixes: #180393
Summary
Handles specific fields in
/upgrade/_review
endpoint upgrade workflow, as described in #180393.Achieves this with two mechanisms:
PrebuiltRuleAsset
schema, which excludes the field from the diff calculation completely./common/api/detection_engine/prebuilt_rules/model/diff/diffable_rule/diffable_rule.ts
Also, refactors a part of the codebase from its prior usage of
io-ts
schema types to use autogenerated Zod types.With this refactor, most of the
x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema_legacy
could be deleted. Unluckily some of the types manually created there are still used in some complex types elsewhere, so I added a note to that file indicating that those should be migrated to Zod, so that the legacy folder can finally be deleted.Checklist
Delete any items that are not applicable to this PR.
For maintainers