Skip to content

[Security Solution] Support rule type change during upgrade#200199

Merged
xcrzx merged 5 commits intoelastic:mainfrom
xcrzx:rule-type-change
Nov 27, 2024
Merged

[Security Solution] Support rule type change during upgrade#200199
xcrzx merged 5 commits intoelastic:mainfrom
xcrzx:rule-type-change

Conversation

@xcrzx
Copy link
Copy Markdown
Contributor

@xcrzx xcrzx commented Nov 14, 2024

Resolves: #180395

Summary

Supports rule type change when upgrading a rule to a newer version, covering scenarios where the current version's rule type differs from the target version. Regardless of the feature flag, the rule should be updated to the target version.

Behavior with Rule Customization OFF

No changes expected. A rule with a rule type change can be updated through:

  • The single rule update option ✅
  • The bulk update option ✅
  • The Update All option ✅

Behavior with Rule Customization ON

Regardless of whether the rule has customizations:

  • The rule cannot be updated using the single update option ❌
  • The rule is excluded from bulk updates ❌
  • The rule is excluded from Update All ❌
  • The rule can only be updated after manually reviewing changes via the update flyout ✅

The update flyout includes a warning message, advising users to back up any customizations the rule may have. The flyout is in read-only mode:

image

@xcrzx xcrzx self-assigned this Nov 14, 2024
@xcrzx xcrzx added release_note:skip Skip the PR/issue when compiling release notes v9.0.0 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 backport:version Backport to applied version labels v8.17.0 labels Nov 14, 2024
@xcrzx xcrzx marked this pull request as ready for review November 14, 2024 15:14
@xcrzx xcrzx requested a review from a team as a code owner November 14, 2024 15:14
@xcrzx xcrzx requested a review from maximpn November 14, 2024 15:14
@elasticmachine
Copy link
Copy Markdown
Contributor

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

@elasticmachine
Copy link
Copy Markdown
Contributor

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

@elasticmachine
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
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.

@xcrzx thanks for addressing rule type change 👍

I don't any critical comments though some of them worth to be checked before approval. The only concern that I have is related to rules without customization. We still show a callout for such rules and users might be confused by the message

Screenshot 2024-11-18 at 11 08 26

Testing didn't reveal any issues. Rule upgrade works w/ and w/o feature flag enabled.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Shouldn't it be PerformUpgradeSpecificRulesRequest?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm curious on your thoughts on shouldn't we use translation keys like xpack.securitySolution.ruleManagement... or xpack.securitySolution.detectionEngine.ruleManagement...?

Rule management is considered a part of Detection Engine though Rule Management and Detection Engine are kind of independent things.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Maybe we could move out upgradeRulesToResolved and upgradeRulesToTarget to a separate hooks? This will make UpgradePrebuiltRulesTableContextProvider smaller and simpler to comprehend.

Comment on lines 318 to 335
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
let updateTabContent = (
<PerFieldRuleDiffTab
header={hasRuleTypeChange ? <RuleTypeChangeCallout /> : null}
ruleDiff={ruleUpgradeState.diff}
/>
);
// Show the resolver tab only if rule customization is enabled and there
// is no rule type change. In case of rule type change users can't resolve
// conflicts, only accept the target rule.
if (isPrebuiltRulesCustomizationEnabled && !hasRuleTypeChange) {
updateTabContent = (
<RuleUpgradeConflictsResolverTab
ruleUpgradeState={ruleUpgradeState}
setRuleFieldResolvedValue={setRuleFieldResolvedValue}
/>
);
}
// Show the resolver tab only if rule customization is enabled and there
// is no rule type change. In case of rule type change users can't resolve
// conflicts, only accept the target rule.
const updateTabContent =
isPrebuiltRulesCustomizationEnabled && !hasRuleTypeChange ? (
<RuleUpgradeConflictsResolverTab
ruleUpgradeState={ruleUpgradeState}
setRuleFieldResolvedValue={setRuleFieldResolvedValue}
/>
) : (
<PerFieldRuleDiffTab
header={hasRuleTypeChange ? <RuleTypeChangeCallout /> : null}
ruleDiff={ruleUpgradeState.diff}
/>
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Technically it's not a header according to the use case scenario. Semantically headers should be wrapped in h1-6 tags. In fact we display a warning here. On top of that the component already has a header RuleDiffHeaderBar. Maybe we could use standard children prop or just rename it to headerAppend?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think you are confusing heading elements with headers.

Comment on lines 228 to 230
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Using diff.fields.version?.target_version or rulesUpgradeState[ruleId].current_rule.version looks weird or I miss something here.

The logic is straightforward. There is a diff if we have some fields changed in a new prebuilt rules package version. When one or more fields changed it's expected to have version bumped. This way version will always be in the diff and it equals to target_rule.version.

Could we use version: rulesUpgradeState[ruleId].target_rule.version here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't know why this logic was written in this specific way, but using version: rulesUpgradeState[ruleId].target_rule.version seems more straightforward to me

@xcrzx
Copy link
Copy Markdown
Contributor Author

xcrzx commented Nov 18, 2024

The only concern that I have is related to rules without customization. We still show a callout for such rules and users might be confused by the message

As discussed during demo, I'll add a separate task to introduce a better handling of the situation when rules are not customized. But currently, it is not a priority

@banderror banderror added v8.18.0 and removed v8.17.0 labels Nov 23, 2024
@xcrzx xcrzx requested a review from maximpn November 26, 2024 10:33
Copy link
Copy Markdown
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.

@xcrzx thanks for addressing my comments 🙏

I retested the PR w/ and w/o prebuiltRulesCustomizationEnabled feature flag enabled and it works as expected.

@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Nov 27, 2024

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #12 / AgentStatusFilter Shows tour and inactive count if first time seeing newly inactive agents
  • [job] [logs] FTR Configs #28 / management Index patterns on aliases discover verify hits should be able to discover and verify no of hits for alias2
  • [job] [logs] FTR Configs #28 / management Index patterns on aliases discover verify hits should be able to discover and verify no of hits for alias2

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 6264 6265 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 13.4MB 13.4MB +939.0B

History

cc @xcrzx

@xcrzx xcrzx merged commit 1dd2400 into elastic:main Nov 27, 2024
@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 8.x

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

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Nov 27, 2024
@kibanamachine
Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
8.x

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

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Nov 27, 2024
…00199) (#202048)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Solution] Support rule type change during upgrade
(#200199)](#200199)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Dmitrii
Shevchenko","email":"dmitrii.shevchenko@elastic.co"},"sourceCommit":{"committedDate":"2024-11-27T17:59:42Z","message":"[Security
Solution] Support rule type change during upgrade
(#200199)","sha":"1dd2400642cbd764963da13713e6cd0aac890300","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Detections
and Resp","Team: SecuritySolution","Team:Detection Rule
Management","backport:version","v8.18.0"],"title":"[Security Solution]
Support rule type change during
upgrade","number":200199,"url":"https://github.com/elastic/kibana/pull/200199","mergeCommit":{"message":"[Security
Solution] Support rule type change during upgrade
(#200199)","sha":"1dd2400642cbd764963da13713e6cd0aac890300"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200199","number":200199,"mergeCommit":{"message":"[Security
Solution] Support rule type change during upgrade
(#200199)","sha":"1dd2400642cbd764963da13713e6cd0aac890300"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Dmitrii Shevchenko <dmitrii.shevchenko@elastic.co>
@xcrzx xcrzx deleted the rule-type-change branch November 28, 2024 09:51
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 12, 2024
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 release_note:skip Skip the PR/issue when compiling release notes 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.18.0 v9.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security Solution] Implement UI for updating prebuilt rule to a new rule type (MVP)

5 participants