Skip to content

Comments

[Security Solution] Adds ability to revert prebuilt rules to their base version#223301

Merged
maximpn merged 28 commits intoelastic:mainfrom
dplumlee:prebuilt-rule-reversion
Jun 26, 2025
Merged

[Security Solution] Adds ability to revert prebuilt rules to their base version#223301
maximpn merged 28 commits intoelastic:mainfrom
dplumlee:prebuilt-rule-reversion

Conversation

@dplumlee
Copy link
Contributor

@dplumlee dplumlee commented Jun 10, 2025

Summary

Ticket: #215506

Adds ability to revert prebuilt rules to their base version.

Implements following endpoints:

  • GET /internal/detection_engine/prebuilt_rules/base_version
  • POST /internal/detection_engine/prebuilt_rules/revert

Allows users to revert their customized prebuilt rules to the original Elastic versions. This also implements a rule diff flyout on the rule details page so users can see which fields are customized and would be changed on reversion.

Screenshots

Rule base version flyout

Screenshot 2025-06-12 at 2 54 05 PM

Disabled when cannot find base version

Screenshot 2025-06-12 at 2 53 15 PM

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

@dplumlee dplumlee self-assigned this Jun 10, 2025
@dplumlee dplumlee added release_note:enhancement Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Detection Rule Management Security Detection Rule Management Team Feature:Prebuilt Detection Rules Security Solution Prebuilt Detection Rules area backport:version Backport to applied version labels v9.1.0 v8.19.0 labels Jun 10, 2025
@kibanamachine
Copy link
Contributor

Cloud deployments require a Github label, please add ci:cloud-deploy or ci:cloud-redeploy and trigger the job through the checkbox again.

@dplumlee dplumlee added the ci:cloud-deploy Create or update a Cloud deployment label Jun 13, 2025
@dplumlee dplumlee added the ci:project-deploy-security Create a Security Serverless Project label Jun 16, 2025
<TabContentPadding>
<PerFieldRuleDiffTab
header={headerCallout}
ruleDiff={diff}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the reason I ended up returning the diff field in the GetPrebuiltRuleBaseVersionResponseBody type from the new /base_version endpoint. We can pass it directly to the existing <PerFieldRuleDiffTab /> component without any modification and have it work.

@dplumlee dplumlee marked this pull request as ready for review June 18, 2025 05:01
@dplumlee dplumlee requested review from a team as code owners June 18, 2025 05:01
@dplumlee dplumlee requested a review from nikitaindik June 18, 2025 05:01
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detections-response (Team:Detections and Resp)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detection-rule-management (Team:Detection Rule Management)

@dplumlee dplumlee requested review from xcrzx and removed request for nikitaindik June 18, 2025 05:02
@dplumlee dplumlee requested a review from maximpn June 25, 2025 04:18
current_version: RuleResponse;

/** The resulting diff between the base and current versions of the rule */
diff: PartialRuleDiff;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an improvement you could return fieldsDiff: Partial<RuleFieldsDiff> and add the necessary fallback fields for example in x-pack/solutions/security/plugins/security_solution/public/detection_engine/rule_management/components/rule_details/base_version_diff/base_version_flyout.tsx or in the upstream data fetching hook.

} catch {
// Error is handled by the mutation's onError callback, so no need to do anything here
} finally {
closeFlyout();
Copy link
Contributor

@maximpn maximpn Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having closeFlyout(); closes the flyout upon errors but it's also a suboptimal UX in case of concurrency control.

The flyout should be closed automatically only in the following cases

  • successful prebuilt rule customizations reverting
  • base version has disappeared after installing a new prebuilt rules package (the best approach is showing a warning message and disabling the Revert button)

In case either revision or version or both don't match to the expected values users should see a warning message but the flyout shouldn't be closed automatically.

On top of that the diff may update after React query cache expires and it fetches the fresh base version. That base version may be a new one so the diff will be updated. The same happens when someone else edits the rule concurrently.

Implementation like in prebuilt rules upgrade workflow could be used as the reference https://github.com/elastic/kibana/blob/main/x-pack/solutions/security/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/upgrade_prebuilt_rules_table/use_prebuilt_rules_upgrade_state.ts#L74-L120.

Copy link
Contributor

@maximpn maximpn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dplumlee I tested the PR using multiple scenarios

  • ✅ reverting prebuilt rule customizations
  • ✅ exception lists, actions, non-customizable and runtime fields stay unchanged after customizations have been reverted
  • ✅ reverting prebuilt rule customizations works after upgrading the rule
  • ✅ "Revert rule" button isn't shown after successful reverting
  • ✅ reverting under low-tier license where Prebuilt Rules Customiation is disabled
  • ⚠️ concurrency control
    • flyout closes automatically after an attempt to revert the customizations when a new prebuilt rules package was installed concurrently
    • flyout closes automatically after an attempt to revert the customizations when revision doesn't match
    • flyout closes automatically after an attempt to revert the customizations when version doesn't match
    • flyout diff updates happen silently, no notifications are shown

Besides that I left a few comments.

Let's fix the concurrency UI issues then this PR should be good to go.

@dplumlee dplumlee requested a review from maximpn June 25, 2025 19:34
@dplumlee
Copy link
Contributor Author

@maximpn pushed up the changes, I think in the #207172 implementation follow-up, I might switch to a static viewing experience to simplify some of these concurrency edge cases. Loading in the initial data and then displaying that it's outdated and letting the user refresh the page themselves seems like a good way to handle it, similar to how its done in github's ui

Copy link
Contributor

@maximpn maximpn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dplumlee Thanks for diligently addressing my comments 🙏

As we agreed some of the comments will be addressed in a follow up PR.

I've retested the PR and pushed a little change to auto-close the flyout upon base version disappearing. React Query retains stale data in case of failed requests. Besides that the functionality works fine.

@elasticmachine
Copy link
Contributor

elasticmachine commented Jun 26, 2025

⏳ Build in-progress

History

cc @dplumlee

@maximpn maximpn merged commit d532ff4 into elastic:main Jun 26, 2025
10 checks passed
@maximpn maximpn removed the request for review from xcrzx June 26, 2025 11:48
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19

https://github.com/elastic/kibana/actions/runs/15901009398

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.19 Backport failed because of merge conflicts

You might need to backport the following PRs to 8.19:
- Remapping iInCircle and questionInCircle and deprecating help icon (#223142)
- [Lens] Add internal CRUD api routes (#223296)
- [Query Rules] Query rules telemetry (#225146)
- [ska] relocate x-pack/test/cases_api_integration (#225056)
- [Discover][Oblt] Enable Attributes tab by default (#224894)
- [follow up] small ui refactoring (#225234)
- Adds missing model Claude 3.7 to accepted models (#224943)

Manual backport

To create the backport manually run:

node scripts/backport --pr 223301

Questions ?

Please refer to the Backport tool documentation

@dplumlee
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.19

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

@dplumlee dplumlee deleted the prebuilt-rule-reversion branch June 27, 2025 15:08
dplumlee added a commit that referenced this pull request Jun 28, 2025
…heir base version (#223301) (#225666)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[Security Solution] Adds ability to revert prebuilt rules to their
base version (#223301)](#223301)

<!--- Backport version: 10.0.1 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Davis
Plumlee","email":"56367316+dplumlee@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-06-26T11:48:37Z","message":"[Security
Solution] Adds ability to revert prebuilt rules to their base version
(#223301)\n\n## Summary\n\nTicket:
https://github.com/elastic/kibana/issues/215506\n\nAdds ability to
revert prebuilt rules to their base version. \n\nImplements following
endpoints:\n\n- `GET
/internal/detection_engine/prebuilt_rules/base_version`\n- `POST
/internal/detection_engine/prebuilt_rules/revert`\n\nAllows users to
revert their customized prebuilt rules to the original Elastic versions.
This also implements a rule diff flyout on the rule details page so
users can see which fields are customized and would be changed on
reversion.\n\n### Screenshots\n\n#### Rule base version
flyout\n![Screenshot 2025-06-12 at 2 54
05 PM](https://github.com/user-attachments/assets/1b1cb544-80f7-4914-ba06-d94d6a673b8d)\n\n\n####
Disabled when cannot find base version\n![Screenshot 2025-06-12 at 2 53
15 PM](https://github.com/user-attachments/assets/e22b0ccc-ddd2-4dd3-b2e9-9c7077c00700)\n\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers
should verify this PR satisfies this list as well.\n\n- [x] Any text
added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials\n- [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","sha":"d532ff490aeb4f3b27f0cb733841f195b08696c2","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","Team:Detections
and Resp","Team: SecuritySolution","Team:Detection Rule
Management","Feature:Prebuilt Detection
Rules","ci:cloud-deploy","ci:project-deploy-security","backport:version","v9.1.0","v8.19.0"],"title":"[Security
Solution] Adds ability to revert prebuilt rules to their base
version","number":223301,"url":"https://github.com/elastic/kibana/pull/223301","mergeCommit":{"message":"[Security
Solution] Adds ability to revert prebuilt rules to their base version
(#223301)\n\n## Summary\n\nTicket:
https://github.com/elastic/kibana/issues/215506\n\nAdds ability to
revert prebuilt rules to their base version. \n\nImplements following
endpoints:\n\n- `GET
/internal/detection_engine/prebuilt_rules/base_version`\n- `POST
/internal/detection_engine/prebuilt_rules/revert`\n\nAllows users to
revert their customized prebuilt rules to the original Elastic versions.
This also implements a rule diff flyout on the rule details page so
users can see which fields are customized and would be changed on
reversion.\n\n### Screenshots\n\n#### Rule base version
flyout\n![Screenshot 2025-06-12 at 2 54
05 PM](https://github.com/user-attachments/assets/1b1cb544-80f7-4914-ba06-d94d6a673b8d)\n\n\n####
Disabled when cannot find base version\n![Screenshot 2025-06-12 at 2 53
15 PM](https://github.com/user-attachments/assets/e22b0ccc-ddd2-4dd3-b2e9-9c7077c00700)\n\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers
should verify this PR satisfies this list as well.\n\n- [x] Any text
added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials\n- [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","sha":"d532ff490aeb4f3b27f0cb733841f195b08696c2"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/223301","number":223301,"mergeCommit":{"message":"[Security
Solution] Adds ability to revert prebuilt rules to their base version
(#223301)\n\n## Summary\n\nTicket:
https://github.com/elastic/kibana/issues/215506\n\nAdds ability to
revert prebuilt rules to their base version. \n\nImplements following
endpoints:\n\n- `GET
/internal/detection_engine/prebuilt_rules/base_version`\n- `POST
/internal/detection_engine/prebuilt_rules/revert`\n\nAllows users to
revert their customized prebuilt rules to the original Elastic versions.
This also implements a rule diff flyout on the rule details page so
users can see which fields are customized and would be changed on
reversion.\n\n### Screenshots\n\n#### Rule base version
flyout\n![Screenshot 2025-06-12 at 2 54
05 PM](https://github.com/user-attachments/assets/1b1cb544-80f7-4914-ba06-d94d6a673b8d)\n\n\n####
Disabled when cannot find base version\n![Screenshot 2025-06-12 at 2 53
15 PM](https://github.com/user-attachments/assets/e22b0ccc-ddd2-4dd3-b2e9-9c7077c00700)\n\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers
should verify this PR satisfies this list as well.\n\n- [x] Any text
added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials\n- [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","sha":"d532ff490aeb4f3b27f0cb733841f195b08696c2"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19, 9.1

https://github.com/elastic/kibana/actions/runs/16021022490

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.19 Backport failed because of merge conflicts
9.1 Cherrypick failed because the selected commit (d532ff4) is empty. Did you already backport this commit?

Manual backport

To create the backport manually run:

node scripts/backport --pr 223301

Questions ?

Please refer to the Backport tool documentation

@maximpn maximpn removed ci:cloud-deploy Create or update a Cloud deployment ci:project-deploy-security Create a Security Serverless Project labels Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels Feature:Prebuilt Detection Rules Security Solution Prebuilt Detection Rules area release_note:enhancement 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. v8.19.0 v9.1.0 v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants