-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Prebuilt rules marked as customized after applying updates #201631
Comments
Pinging @elastic/security-solution (Team: SecuritySolution) |
Pinging @elastic/security-detections-response (Team:Detections and Resp) |
Pinging @elastic/security-detection-rule-management (Team:Detection Rule Management) |
@xcrzx Is it with the feature flag ON or OFF? |
This is with the feature flag enabled. Updated ticket description |
The bug caused the index 7caa0469eeb..ba23bff67be 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/prebuilt_rules/api/perform_rule_upgrade/diffable_rule_fields_mappings.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/prebuilt_rules/api/perform_rule_upgrade/diffable_rule_fields_mappings.ts
@@ -5,6 +5,7 @@
* 2.0.
*/
import { get, has } from 'lodash';
+import moment from 'moment';
import type {
RuleSchedule,
DataSourceIndexPatterns,
@@ -15,6 +16,7 @@ import type {
} from '../../../../../../common/api/detection_engine';
import { type AllFieldsDiff } from '../../../../../../common/api/detection_engine';
import type { PrebuiltRuleAsset } from '../../model/rule_assets/prebuilt_rule_asset';
+import { parseInterval } from '../../../rule_types/utils/utils';
/**
* Retrieves and transforms the value for a specific field from a DiffableRule group.
@@ -201,7 +203,11 @@ export const transformDiffableFieldValues = (
diffableFieldValue: RuleSchedule | InlineKqlQuery | unknown
): TransformValuesReturnType => {
if (fieldName === 'from' && isRuleSchedule(diffableFieldValue)) {
- return { type: 'TRANSFORMED_FIELD', value: `now-${diffableFieldValue.lookback}` };
+ const interval = parseInterval(diffableFieldValue.interval) ?? moment.duration(0);
+ const parsedFrom = parseInterval(diffableFieldValue.lookback) ?? moment.duration(0);
+
+ const from = parsedFrom.asSeconds() + interval.asSeconds();
+ return { type: 'TRANSFORMED_FIELD', value: `now-${from}s` };
} else if (fieldName === 'to') {
return { type: 'TRANSFORMED_FIELD', value: `now` };
} else if (fieldName === 'saved_id' && isInlineQuery(diffableFieldValue)) { |
…upgrade/_perform` route (elastic#202824) **Fixes: elastic#202575 **Fixes: elastic#201631 **Partially addresses: elastic#202715 ## Summary All bugs have the same source > [!NOTE] > This bug/related fix is only visible with the `prebuiltRulesCustomizationEnabled` feature flag turned on. Fixes an issue where unedited prebuilt rules were being marked as "Modified" when upgraded due to a bug in the `upgrade/_perform` endpoint where the `from` field was incorrectly calculated via the `lookback` field. Solves multiple bugs where prebuilt rules were marked as "Modified" incorrectly when they were upgraded See reproduce steps in related tickets ([example](elastic#202575 (comment))) ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [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 (cherry picked from commit 93112b9)
…upgrade/_perform` route (elastic#202824) **Fixes: elastic#202575 **Fixes: elastic#201631 **Partially addresses: elastic#202715 ## Summary All bugs have the same source > [!NOTE] > This bug/related fix is only visible with the `prebuiltRulesCustomizationEnabled` feature flag turned on. Fixes an issue where unedited prebuilt rules were being marked as "Modified" when upgraded due to a bug in the `upgrade/_perform` endpoint where the `from` field was incorrectly calculated via the `lookback` field. Solves multiple bugs where prebuilt rules were marked as "Modified" incorrectly when they were upgraded See reproduce steps in related tickets ([example](elastic#202575 (comment))) ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [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 (cherry picked from commit 93112b9)
…upgrade/_perform` route (elastic#202824) **Fixes: elastic#202575 **Fixes: elastic#201631 **Partially addresses: elastic#202715 ## Summary All bugs have the same source > [!NOTE] > This bug/related fix is only visible with the `prebuiltRulesCustomizationEnabled` feature flag turned on. Fixes an issue where unedited prebuilt rules were being marked as "Modified" when upgraded due to a bug in the `upgrade/_perform` endpoint where the `from` field was incorrectly calculated via the `lookback` field. Solves multiple bugs where prebuilt rules were marked as "Modified" incorrectly when they were upgraded See reproduce steps in related tickets ([example](elastic#202575 (comment))) ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [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
Summary
Non-customized rules are incorrectly marked as customized after applying an update.
Steps to Reproduce
Expected Result
The rule is upgraded and remains marked as non-customized.
Actual Result
The rule is upgraded but is incorrectly marked as customized.
Initial analysis shows a difference in the
lookback
field between the saved updated rule and the target version. The value changes from-60s
to240s
.The text was updated successfully, but these errors were encountered: