Skip to content

Commit

Permalink
[8.x] [Security Solution] Rule Updates in bulk with conflicts (#196776)…
Browse files Browse the repository at this point in the history
… (#199649)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Solution] Rule Updates in bulk with conflicts
(#196776)](#196776)

<!--- Backport version: 8.9.8 -->

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

<!--BACKPORT [{"author":{"name":"Juan Pablo
Djeredjian","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-11T12:29:21Z","message":"[Security
Solution] Rule Updates in bulk with conflicts (#196776)\n\nResolves:
https://github.com/elastic/kibana/issues/180589\r\n\r\n##
Summary\r\n\r\n- Handles bulk updating of rules with conflicts in the
Rule Upgrades\r\ntable. See detailed requirements implemented in ticket
linked above.\r\n- Changes default `pick_version` of both the
`/upgrade/_perform`\r\nendpoint, and of the request payloads for that
endpoint from the\r\nfrontend, from `TARGET` to `MERGED`, when
the\r\n`isPrebuiltRulesCustomizationEnabled` is `true`.\r\n- **Also:**
handles issue in `/upgrade/_perform` endpoint with the\r\n`index` and
`data_view_id` fields. See
file:\r\n`x-pack/plugins/security_solution/server/lib/detection_engine/prebuilt_rules/api/perform_rule_upgrade/diffable_rule_fields_mappings.ts`.\r\n\r\n**See
demo
video:**\r\nhttps://www.loom.com/share/90d94d2a8f16442b9a43a425eeab6697\r\n\r\n**New
copy in warning modal**\r\n<img width=\"1660\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/85632192-142a-4e12-b396-1eb2320ca3f4\">\r\n\r\n**Newly
added tooltips:**
\r\n\r\n\r\n![image](https://github.com/user-attachments/assets/7ada117e-57a7-4699-ad08-312c734586d9)\r\n\r\n![image](https://github.com/user-attachments/assets/c8ed80ac-c1c3-48f1-8f8e-2433415a6772)\r\n\r\n![image](https://github.com/user-attachments/assets/d77ed6f0-5d65-4933-9012-f6cd153a9350)\r\n\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\r\n-
[ ] This will appear in the **Release Notes** and follow
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Nastasha Solomon
<[email protected]>\r\nCo-authored-by:
Dmitrii
<[email protected]>","sha":"99160f52d6a2e0ad4698ca8e5ac40316ebb733c9","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.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","ui-copy","Feature:Prebuilt Detection
Rules","backport:version","v8.17.0"],"number":196776,"url":"https://github.com/elastic/kibana/pull/196776","mergeCommit":{"message":"[Security
Solution] Rule Updates in bulk with conflicts (#196776)\n\nResolves:
https://github.com/elastic/kibana/issues/180589\r\n\r\n##
Summary\r\n\r\n- Handles bulk updating of rules with conflicts in the
Rule Upgrades\r\ntable. See detailed requirements implemented in ticket
linked above.\r\n- Changes default `pick_version` of both the
`/upgrade/_perform`\r\nendpoint, and of the request payloads for that
endpoint from the\r\nfrontend, from `TARGET` to `MERGED`, when
the\r\n`isPrebuiltRulesCustomizationEnabled` is `true`.\r\n- **Also:**
handles issue in `/upgrade/_perform` endpoint with the\r\n`index` and
`data_view_id` fields. See
file:\r\n`x-pack/plugins/security_solution/server/lib/detection_engine/prebuilt_rules/api/perform_rule_upgrade/diffable_rule_fields_mappings.ts`.\r\n\r\n**See
demo
video:**\r\nhttps://www.loom.com/share/90d94d2a8f16442b9a43a425eeab6697\r\n\r\n**New
copy in warning modal**\r\n<img width=\"1660\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/85632192-142a-4e12-b396-1eb2320ca3f4\">\r\n\r\n**Newly
added tooltips:**
\r\n\r\n\r\n![image](https://github.com/user-attachments/assets/7ada117e-57a7-4699-ad08-312c734586d9)\r\n\r\n![image](https://github.com/user-attachments/assets/c8ed80ac-c1c3-48f1-8f8e-2433415a6772)\r\n\r\n![image](https://github.com/user-attachments/assets/d77ed6f0-5d65-4933-9012-f6cd153a9350)\r\n\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\r\n-
[ ] This will appear in the **Release Notes** and follow
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Nastasha Solomon
<[email protected]>\r\nCo-authored-by:
Dmitrii
<[email protected]>","sha":"99160f52d6a2e0ad4698ca8e5ac40316ebb733c9"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/196776","number":196776,"mergeCommit":{"message":"[Security
Solution] Rule Updates in bulk with conflicts (#196776)\n\nResolves:
https://github.com/elastic/kibana/issues/180589\r\n\r\n##
Summary\r\n\r\n- Handles bulk updating of rules with conflicts in the
Rule Upgrades\r\ntable. See detailed requirements implemented in ticket
linked above.\r\n- Changes default `pick_version` of both the
`/upgrade/_perform`\r\nendpoint, and of the request payloads for that
endpoint from the\r\nfrontend, from `TARGET` to `MERGED`, when
the\r\n`isPrebuiltRulesCustomizationEnabled` is `true`.\r\n- **Also:**
handles issue in `/upgrade/_perform` endpoint with the\r\n`index` and
`data_view_id` fields. See
file:\r\n`x-pack/plugins/security_solution/server/lib/detection_engine/prebuilt_rules/api/perform_rule_upgrade/diffable_rule_fields_mappings.ts`.\r\n\r\n**See
demo
video:**\r\nhttps://www.loom.com/share/90d94d2a8f16442b9a43a425eeab6697\r\n\r\n**New
copy in warning modal**\r\n<img width=\"1660\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/85632192-142a-4e12-b396-1eb2320ca3f4\">\r\n\r\n**Newly
added tooltips:**
\r\n\r\n\r\n![image](https://github.com/user-attachments/assets/7ada117e-57a7-4699-ad08-312c734586d9)\r\n\r\n![image](https://github.com/user-attachments/assets/c8ed80ac-c1c3-48f1-8f8e-2433415a6772)\r\n\r\n![image](https://github.com/user-attachments/assets/d77ed6f0-5d65-4933-9012-f6cd153a9350)\r\n\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\r\n-
[ ] This will appear in the **Release Notes** and follow
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Nastasha Solomon
<[email protected]>\r\nCo-authored-by:
Dmitrii
<[email protected]>","sha":"99160f52d6a2e0ad4698ca8e5ac40316ebb733c9"}},{"branch":"8.x","label":"v8.17.0","labelRegex":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Juan Pablo Djeredjian <[email protected]>
  • Loading branch information
xcrzx and jpdjere authored Nov 11, 2024
1 parent 8dfe8f5 commit dc44d7c
Show file tree
Hide file tree
Showing 23 changed files with 555 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type { ActionResult } from '@kbn/actions-plugin/server';
import { convertRulesFilterToKQL } from '../../../../common/detection_engine/rule_management/rule_filtering';
import type {
UpgradeSpecificRulesRequest,
PickVersionValues,
PerformRuleUpgradeResponseBody,
InstallSpecificRulesRequest,
PerformRuleInstallationResponseBody,
Expand Down Expand Up @@ -678,26 +679,17 @@ export const performInstallSpecificRules = async (
}),
});

export const performUpgradeAllRules = async (): Promise<PerformRuleUpgradeResponseBody> =>
KibanaServices.get().http.fetch(PERFORM_RULE_UPGRADE_URL, {
method: 'POST',
version: '1',
body: JSON.stringify({
mode: 'ALL_RULES',
pick_version: 'TARGET',
}),
});

export const performUpgradeSpecificRules = async (
rules: UpgradeSpecificRulesRequest['rules']
rules: UpgradeSpecificRulesRequest['rules'],
pickVersion: PickVersionValues
): Promise<PerformRuleUpgradeResponseBody> =>
KibanaServices.get().http.fetch(PERFORM_RULE_UPGRADE_URL, {
method: 'POST',
version: '1',
body: JSON.stringify({
mode: 'SPECIFIC_RULES',
rules,
pick_version: 'TARGET', // Setting fixed 'TARGET' temporarily for Milestone 2
pick_version: pickVersion,
}),
});

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { UseMutationOptions } from '@tanstack/react-query';
import { useMutation } from '@tanstack/react-query';
import type {
PerformRuleUpgradeResponseBody,
PickVersionValues,
UpgradeSpecificRulesRequest,
} from '../../../../../../common/api/detection_engine/prebuilt_rules';
import { PERFORM_RULE_UPGRADE_URL } from '../../../../../../common/api/detection_engine/prebuilt_rules/urls';
Expand All @@ -26,6 +27,7 @@ export const PERFORM_SPECIFIC_RULES_UPGRADE_KEY = [
];

export const usePerformSpecificRulesUpgradeMutation = (
pickVersion: PickVersionValues,
options?: UseMutationOptions<
PerformRuleUpgradeResponseBody,
Error,
Expand All @@ -43,7 +45,7 @@ export const usePerformSpecificRulesUpgradeMutation = (

return useMutation<PerformRuleUpgradeResponseBody, Error, UpgradeSpecificRulesRequest['rules']>(
(rulesToUpgrade: UpgradeSpecificRulesRequest['rules']) => {
return performUpgradeSpecificRules(rulesToUpgrade);
return performUpgradeSpecificRules(rulesToUpgrade, pickVersion);
},
{
...options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,20 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { PickVersionValues } from '../../../../../common/api/detection_engine';
import { useAppToasts } from '../../../../common/hooks/use_app_toasts';
import { usePerformAllRulesUpgradeMutation } from '../../api/hooks/prebuilt_rules/use_perform_all_rules_upgrade_mutation';
import { usePerformSpecificRulesUpgradeMutation } from '../../api/hooks/prebuilt_rules/use_perform_specific_rules_upgrade_mutation';

import * as i18n from './translations';

export const usePerformUpgradeAllRules = () => {
const { addError, addSuccess } = useAppToasts();

return usePerformAllRulesUpgradeMutation({
onError: (err) => {
addError(err, { title: i18n.RULE_UPGRADE_FAILED });
},
onSuccess: (result) => {
addSuccess(getSuccessToastMessage(result));
},
});
};

export const usePerformUpgradeSpecificRules = () => {
export const usePerformUpgradeSpecificRules = ({
pickVersion,
}: {
pickVersion: PickVersionValues;
}) => {
const { addError, addSuccess } = useAppToasts();

return usePerformSpecificRulesUpgradeMutation({
return usePerformSpecificRulesUpgradeMutation(pickVersion, {
onError: (err) => {
addError(err, { title: i18n.RULE_UPGRADE_FAILED });
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { MlJobCompatibilityLink } from '../../../../common/components/links_to_docs';
import { MlJobCompatibilityLink } from '../../../../../../../common/components/links_to_docs';

export const ML_JOB_UPGRADE_MODAL_TITLE = i18n.translate(
'xpack.securitySolution.detectionEngine.mlJobUpgradeModal.messageTitle',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 { EuiConfirmModal, EuiText } from '@elastic/eui';
import React, { memo } from 'react';
import * as i18n from './translations';

export interface UpgradeConflictsModalProps {
onCancel: (
event?: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLButtonElement>
) => void;
onConfirm?: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
}

const UpgradeConflictsModalComponent = ({ onCancel, onConfirm }: UpgradeConflictsModalProps) => {
return (
<EuiConfirmModal
title={i18n.UPGRADE_CONFLICTS_MODAL_TITLE}
onCancel={onCancel}
onConfirm={onConfirm}
cancelButtonText={i18n.UPGRADE_CONFLICTS_MODAL_CANCEL}
confirmButtonText={i18n.UPGRADE_CONFLICTS_MODAL_CONFIRM}
buttonColor="primary"
defaultFocusedButton="confirm"
data-test-subj="upgradeConflictsModal"
>
<EuiText>{i18n.UPGRADE_CONFLICTS_MODAL_BODY}</EuiText>
</EuiConfirmModal>
);
};

export const UpgradeConflictsModal = memo(UpgradeConflictsModalComponent);
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 { i18n } from '@kbn/i18n';

export const UPGRADE_CONFLICTS_MODAL_TITLE = i18n.translate(
'xpack.securitySolution.detectionEngine.upgradeConflictsModal.messageTitle',
{
defaultMessage: 'Update rules without conflicts?',
}
);

export const UPGRADE_CONFLICTS_MODAL_CANCEL = i18n.translate(
'xpack.securitySolution.detectionEngine.upgradeConflictsModal.cancelTitle',
{
defaultMessage: 'Cancel',
}
);

export const UPGRADE_CONFLICTS_MODAL_CONFIRM = i18n.translate(
'xpack.securitySolution.detectionEngine.upgradeConflictsModal.confirmTitle',
{
defaultMessage: 'Update rules without conflicts',
}
);

export const UPGRADE_CONFLICTS_MODAL_BODY = i18n.translate(
'xpack.securitySolution.detectionEngine.upgradeConflictsModal.affectedJobsTitle',
{
defaultMessage:
"Some of the selected rules have conflicts and, for that reason, won't be updated. Resolve the conflicts to properly update the rules.",
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ export const UPDATE_SELECTED_RULES = (numberOfSelectedRules: number) => {
);
};

export const BULK_UPDATE_BUTTON_TOOLTIP_NO_PERMISSIONS = i18n.translate(
'xpack.securitySolution.detectionEngine.rules.upgradeRules.bulkButtons.noPermissions',
{
defaultMessage: "You don't have permissions to update rules",
}
);

export const BULK_UPDATE_ALL_RULES_BUTTON_TOOLTIP_CONFLICTS = i18n.translate(
'xpack.securitySolution.detectionEngine.rules.upgradeRules.bulkButtons.allRules.conflicts',
{
defaultMessage: 'All rules have conflicts. Update them individually.',
}
);

export const BULK_UPDATE_SELECTED_RULES_BUTTON_TOOLTIP_CONFLICTS = i18n.translate(
'xpack.securitySolution.detectionEngine.rules.upgradeRules.bulkButtons.selectedRules.conflicts',
{
defaultMessage: 'All selected rules have conflicts. Update them individually.',
}
);

export const SEARCH_PLACEHOLDER = i18n.translate(
'xpack.securitySolution.detectionEngine.rules.upgradeRules.searchBarPlaceholder',
{
Expand All @@ -37,6 +58,12 @@ export const UPDATE_BUTTON_LABEL = i18n.translate(
defaultMessage: 'Update',
}
);
export const UPDATE_ERROR = i18n.translate(
'xpack.securitySolution.detectionEngine.ruleDetails.updateError',
{
defaultMessage: 'Update error',
}
);

export const UPDATE_FLYOUT_PER_FIELD_TOOLTIP_DESCRIPTION = i18n.translate(
'xpack.securitySolution.detectionEngine.ruleDetails.perFieldTooltip',
Expand Down
Loading

0 comments on commit dc44d7c

Please sign in to comment.