forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] Add UI incentivizers to upgrade prebuilt rules (e…
…lastic#211862) ## Summary Partially addresses elastic#210358 Adds all callouts and logic to incentivize users to upgrade their rules asap. These include: - [x] Showing a callout on the Rule Management page - [x] Showing a callout on the Rule Details page - [x] Letting users open the Rule Upgrade flyout from the Rule Details page - [x] Showing a callout on the Rule Editing page - [x] Showing a callout in the Rule Upgrade flyout if rule has missing base version This PR also adds related updates to the rule diff algorithms in order to facilitate an easier upgrade experience when rules have missing base versions. These include: - [x] When the rule has a missing base version and is NOT marked as customized: - [x] We should return all the target fields from the diff algorithm as NO_CONFLICT - [x] When the rule has a missing base version and is marked as customized: - [x] We should attempt to merge all non-functional mergeable fields (any field that doesn't have consequences with how the rule runs e.g. tags) and return them as `SOLVABLE_CONFLICT`. - **NOTE**: When base versions are missing and the rule is customized, we attempt to merge all mergable, non-functional rule fields. These include all fields covered by the scalar diff array (`tags`, `references`, `new_terms_fields`, `threat_index`). We typically also consider multi-line string fields as mergeable but without three versions of the string, we are currently unable to merge the strings together, so we just return target version. - [x] We should pick the target version for all functional mergeable fields (e.g. `index`) and non-mergeable fields and return them as `SOLVABLE_CONFLICT`. ### Screenshots **Callout on Rule details page w/ flyout button**  --- **Upgrade flyout now accessible from rule details page**  --- **Callout on rule editing page**  --- **Dismissible callout on rule management page**  --- **Callout in rule upgrade flyout when rule has missing base version**  ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [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) - [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 461787b)
- Loading branch information
Showing
56 changed files
with
2,051 additions
and
1,062 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...n/public/detection_engine/rule_management/components/rule_details/rule_update_callout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { EuiCallOut, EuiSpacer, EuiLink } from '@elastic/eui'; | ||
import React, { useMemo } from 'react'; | ||
import type { RuleResponse } from '../../../../../common/api/detection_engine'; | ||
import * as i18n from './translations'; | ||
import { usePrebuiltRulesUpgrade } from '../../hooks/use_prebuilt_rules_upgrade'; | ||
|
||
interface RuleUpdateCalloutProps { | ||
rule: RuleResponse; | ||
message: string; | ||
actionButton?: JSX.Element; | ||
onUpgrade?: () => void; | ||
} | ||
|
||
const RuleUpdateCalloutComponent = ({ | ||
rule, | ||
message, | ||
actionButton, | ||
onUpgrade, | ||
}: RuleUpdateCalloutProps): JSX.Element | null => { | ||
const { upgradeReviewResponse, rulePreviewFlyout, openRulePreview } = usePrebuiltRulesUpgrade({ | ||
pagination: { | ||
page: 1, // we only want to fetch one result | ||
perPage: 1, | ||
}, | ||
filter: { rule_ids: [rule.id] }, | ||
onUpgrade, | ||
}); | ||
|
||
const isRuleUpgradeable = useMemo( | ||
() => upgradeReviewResponse !== undefined && upgradeReviewResponse.total > 0, | ||
[upgradeReviewResponse] | ||
); | ||
|
||
const updateCallToActionButton = useMemo(() => { | ||
if (actionButton) { | ||
return actionButton; | ||
} | ||
return ( | ||
<EuiLink | ||
onClick={() => openRulePreview(rule.rule_id)} | ||
data-test-subj="ruleDetailsUpdateRuleCalloutButton" | ||
> | ||
{i18n.HAS_RULE_UPDATE_CALLOUT_BUTTON} | ||
</EuiLink> | ||
); | ||
}, [actionButton, openRulePreview, rule.rule_id]); | ||
|
||
if (!isRuleUpgradeable) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<EuiCallOut title={i18n.HAS_RULE_UPDATE_CALLOUT_TITLE} color="primary" iconType="gear"> | ||
<p>{message}</p> | ||
{updateCallToActionButton} | ||
</EuiCallOut> | ||
<EuiSpacer size="l" /> | ||
{rulePreviewFlyout} | ||
</> | ||
); | ||
}; | ||
|
||
export const RuleUpdateCallout = React.memo(RuleUpdateCalloutComponent); |
16 changes: 16 additions & 0 deletions
16
...ment/components/rule_details/three_way_diff/rule_upgrade/missing_base_version_callout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiCallOut } from '@elastic/eui'; | ||
import * as i18n from './translations'; | ||
|
||
export const RuleHasMissingBaseVersionCallout = () => ( | ||
<EuiCallOut color="warning" size="s"> | ||
<p>{i18n.RULE_BASE_VERSION_IS_MISSING_DESCRIPTION}</p> | ||
</EuiCallOut> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.