Skip to content

Commit

Permalink
[8.x] [Security Solution] Add support for editing prebuilt rules to t…
Browse files Browse the repository at this point in the history
…he Rule Editing page (#199550) (#200106)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Solution] Add support for editing prebuilt rules to the
Rule Editing page
(#199550)](#199550)

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

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

<!--BACKPORT [{"author":{"name":"Davis
Plumlee","email":"56367316+dplumlee@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-11-13T23:04:38Z","message":"[Security
Solution] Add support for editing prebuilt rules to the Rule Editing
page (#199550)\n\n**Resolves:
https://github.com/elastic/kibana/issues/180172**\r\n\r\n##
Summary\r\n\r\n> [!NOTE] \r\n> Feature is behind the
`prebuiltRulesCustomizationEnabled` feature\r\nflag.\r\n\r\nRemoves the
logic gates preventing prebuilt rules from being edited via\r\nthe Rule
Edit page behind the `prebuiltRulesCustomizationEnabled`\r\nfeature
flag. This allows all rules types to be fully editable via
the\r\nUI.\r\n\r\nAlso removes the muting logic we had in place for
`Definition` tab\r\nwarnings
([implemented\r\nhere](https://github.com/elastic/kibana/pull/191487))\r\n\r\n###
Screenshots\r\n\r\n#### _Before_\r\n\r\n**Prebuilt rule only has the
\"Actions\" tab enabled, users cannot\r\ncustomize anything else in the
form**\r\n![Screenshot 2024-11-08 at 3
08\r\n15 PM](https://github.com/user-attachments/assets/b83836e6-f78f-4b3a-9fbc-55a5208250dd)\r\n\r\n\r\n####
_After_\r\n\r\n**Prebuilt rule now has all tabs/fields available for
editing and rule\r\ninfo is populated into the form**\r\n![Screenshot
2024-11-08 at 3
02\r\n43 PM](https://github.com/user-attachments/assets/184f6fc4-b64c-4e20-a987-76e460c61786)\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n\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:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"d6e6145dacf25bf3e900611425434b0713bce005","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","Feature:Prebuilt Detection
Rules","backport:version","v8.17.0"],"title":"[Security Solution] Add
support for editing prebuilt rules to the Rule Editing
page","number":199550,"url":"https://github.com/elastic/kibana/pull/199550","mergeCommit":{"message":"[Security
Solution] Add support for editing prebuilt rules to the Rule Editing
page (#199550)\n\n**Resolves:
https://github.com/elastic/kibana/issues/180172**\r\n\r\n##
Summary\r\n\r\n> [!NOTE] \r\n> Feature is behind the
`prebuiltRulesCustomizationEnabled` feature\r\nflag.\r\n\r\nRemoves the
logic gates preventing prebuilt rules from being edited via\r\nthe Rule
Edit page behind the `prebuiltRulesCustomizationEnabled`\r\nfeature
flag. This allows all rules types to be fully editable via
the\r\nUI.\r\n\r\nAlso removes the muting logic we had in place for
`Definition` tab\r\nwarnings
([implemented\r\nhere](https://github.com/elastic/kibana/pull/191487))\r\n\r\n###
Screenshots\r\n\r\n#### _Before_\r\n\r\n**Prebuilt rule only has the
\"Actions\" tab enabled, users cannot\r\ncustomize anything else in the
form**\r\n![Screenshot 2024-11-08 at 3
08\r\n15 PM](https://github.com/user-attachments/assets/b83836e6-f78f-4b3a-9fbc-55a5208250dd)\r\n\r\n\r\n####
_After_\r\n\r\n**Prebuilt rule now has all tabs/fields available for
editing and rule\r\ninfo is populated into the form**\r\n![Screenshot
2024-11-08 at 3
02\r\n43 PM](https://github.com/user-attachments/assets/184f6fc4-b64c-4e20-a987-76e460c61786)\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n\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:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"d6e6145dacf25bf3e900611425434b0713bce005"}},"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/199550","number":199550,"mergeCommit":{"message":"[Security
Solution] Add support for editing prebuilt rules to the Rule Editing
page (#199550)\n\n**Resolves:
https://github.com/elastic/kibana/issues/180172**\r\n\r\n##
Summary\r\n\r\n> [!NOTE] \r\n> Feature is behind the
`prebuiltRulesCustomizationEnabled` feature\r\nflag.\r\n\r\nRemoves the
logic gates preventing prebuilt rules from being edited via\r\nthe Rule
Edit page behind the `prebuiltRulesCustomizationEnabled`\r\nfeature
flag. This allows all rules types to be fully editable via
the\r\nUI.\r\n\r\nAlso removes the muting logic we had in place for
`Definition` tab\r\nwarnings
([implemented\r\nhere](https://github.com/elastic/kibana/pull/191487))\r\n\r\n###
Screenshots\r\n\r\n#### _Before_\r\n\r\n**Prebuilt rule only has the
\"Actions\" tab enabled, users cannot\r\ncustomize anything else in the
form**\r\n![Screenshot 2024-11-08 at 3
08\r\n15 PM](https://github.com/user-attachments/assets/b83836e6-f78f-4b3a-9fbc-55a5208250dd)\r\n\r\n\r\n####
_After_\r\n\r\n**Prebuilt rule now has all tabs/fields available for
editing and rule\r\ninfo is populated into the form**\r\n![Screenshot
2024-11-08 at 3
02\r\n43 PM](https://github.com/user-attachments/assets/184f6fc4-b64c-4e20-a987-76e460c61786)\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n\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:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"d6e6145dacf25bf3e900611425434b0713bce005"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Davis Plumlee <56367316+dplumlee@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 14, 2024
1 parent 1779727 commit 926a57d
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { useRuleForms, useRuleFormsErrors, useRuleIndexPattern } from '../form';
import { useEsqlIndex, useEsqlQueryForAboutStep } from '../../hooks';
import { CustomHeaderPageMemo } from '..';
import { SaveWithErrorsModal } from '../../components/save_with_errors_confirmation';
import { useIsPrebuiltRulesCustomizationEnabled } from '../../../rule_management/hooks/use_is_prebuilt_rules_customization_enabled';
import { ALERT_SUPPRESSION_FIELDS_FIELD_NAME } from '../../../rule_creation/components/alert_suppression_edit';

const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
Expand All @@ -86,11 +87,14 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
useListsConfig();
const { application, triggersActionsUi } = useKibana().services;
const { navigateToApp } = application;
const isPrebuiltRulesCustomizationEnabled = useIsPrebuiltRulesCustomizationEnabled();

const { detailName: ruleId } = useParams<{ detailName: string }>();

const [activeStep, setActiveStep] = useState<RuleStep>(
rule.immutable ? RuleStep.ruleActions : RuleStep.defineRule
!isPrebuiltRulesCustomizationEnabled && rule.immutable
? RuleStep.ruleActions
: RuleStep.defineRule
);
const { mutateAsync: updateRule, isLoading } = useUpdateRule();
const [isRulePreviewVisible, setIsRulePreviewVisible] = useState(true);
Expand Down Expand Up @@ -211,7 +215,7 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
'data-test-subj': 'edit-rule-define-tab',
id: RuleStep.defineRule,
name: ruleI18n.DEFINITION,
disabled: rule?.immutable,
disabled: !isPrebuiltRulesCustomizationEnabled && rule?.immutable,
content: (
<div
style={{
Expand Down Expand Up @@ -256,7 +260,7 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
'data-test-subj': 'edit-rule-about-tab',
id: RuleStep.aboutRule,
name: ruleI18n.ABOUT,
disabled: rule?.immutable,
disabled: !isPrebuiltRulesCustomizationEnabled && rule?.immutable,
content: (
<div
style={{
Expand Down Expand Up @@ -288,7 +292,7 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
'data-test-subj': 'edit-rule-schedule-tab',
id: RuleStep.scheduleRule,
name: ruleI18n.SCHEDULE,
disabled: rule?.immutable,
disabled: !isPrebuiltRulesCustomizationEnabled && rule?.immutable,
content: (
<div
style={{
Expand Down Expand Up @@ -340,6 +344,7 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
},
],
[
isPrebuiltRulesCustomizationEnabled,
rule?.immutable,
rule?.id,
activeStep,
Expand All @@ -356,15 +361,15 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
isIndexPatternLoading,
isQueryBarValid,
defineStepData,
memoizedIndex,
aboutStepData,
aboutStepForm,
esqlQueryForAboutStep,
scheduleStepData,
scheduleStepForm,
actionsStepData,
actionMessageParams,
actionsStepForm,
memoizedIndex,
esqlQueryForAboutStep,
]
);

Expand Down Expand Up @@ -414,7 +419,7 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
setNonBlockingRuleErrors([]);

const actionsStepFormValid = await actionsStepForm.validate();
if (rule.immutable) {
if (!isPrebuiltRulesCustomizationEnabled && rule.immutable) {
// Since users cannot edit Define, About and Schedule tabs of the rule, we skip validation of those to avoid
// user confusion of seeing that those tabs have error and not being able to see or do anything about that.
// We will need to remove this condition once rule customization work is done.
Expand Down Expand Up @@ -451,11 +456,12 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
showSaveWithErrorsModal();
}
}, [
actionsStepForm,
isPrebuiltRulesCustomizationEnabled,
rule.immutable,
defineStepForm,
aboutStepForm,
scheduleStepForm,
actionsStepForm,
getRuleFormsErrors,
saveChanges,
showSaveWithErrorsModal,
Expand Down

0 comments on commit 926a57d

Please sign in to comment.