-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Security Solution] Detection rule deprecation feature #259673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dplumlee
merged 21 commits into
elastic:main
from
dplumlee:detection-rule-deprecation-feature
Apr 3, 2026
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e1fa231
adds deprecated endpoint
dplumlee 3c3f3a9
adds UI elements
dplumlee 5845167
updates copy and adds delete all button to modal
dplumlee 2071df1
updates backend logic and adds timed dismissal
dplumlee 4e4fb6a
Merge remote-tracking branch 'upstream/main' into detection-rule-depr…
dplumlee f733bcb
adds duplicate and delete button
dplumlee 4351465
adds feature flag
dplumlee 271c1fd
Merge remote-tracking branch 'upstream/main' into detection-rule-depr…
dplumlee d54e103
adds extra delete button
dplumlee 3f97f7c
Merge remote-tracking branch 'upstream/main' into detection-rule-depr…
dplumlee d216184
adds unit tests for timed dismissal feature
dplumlee 53598d1
cleans up code for review
dplumlee 42d0048
adds deprecation reason ui
dplumlee c39622c
Merge remote-tracking branch 'upstream/main' into detection-rule-depr…
dplumlee 1dc1238
fix type
dplumlee 97b2fb3
Merge remote-tracking branch 'upstream/main' into detection-rule-depr…
dplumlee f4f93a1
fix spacing issue
dplumlee a2f40ec
Merge remote-tracking branch 'upstream/main' into detection-rule-depr…
dplumlee 41a4a2f
addresses review comments
dplumlee 8a7ccf6
Merge remote-tracking branch 'upstream/main' into detection-rule-depr…
dplumlee b5949c7
Merge branch 'main' into detection-rule-deprecation-feature
dplumlee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
39 changes: 39 additions & 0 deletions
39
.../detection_engine/prebuilt_rules/review_rule_deprecation/review_rule_deprecation_route.ts
This file contains hidden or 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,39 @@ | ||
| /* | ||
| * 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 { z } from '@kbn/zod/v4'; | ||
|
|
||
| /** | ||
| * Max number of deprecated rules returned per request. Conservative limit | ||
| * to protect against unexpected package size. | ||
| */ | ||
| export const MAX_DEPRECATED_RULES_TO_RETURN = 200; | ||
|
|
||
| export type ReviewRuleDeprecationRequestBody = z.infer<typeof ReviewRuleDeprecationRequestBody>; | ||
| export const ReviewRuleDeprecationRequestBody = z | ||
| .object({ | ||
| /** | ||
| * Optional list of saved-object IDs to filter by. | ||
| * Uses SO IDs instead of rule_ids to avoid ambiguity from duplicate rule_ids. | ||
| */ | ||
| ids: z.array(z.string()).optional(), | ||
| }) | ||
| .nullable(); | ||
|
|
||
| export interface DeprecatedRuleForReview { | ||
| /** Installed rule saved object ID */ | ||
| id: string; | ||
| /** Rule signature ID */ | ||
| rule_id: string; | ||
| /** Installed rule name */ | ||
| name: string; | ||
| deprecated_reason?: string; | ||
| } | ||
|
|
||
| export interface ReviewRuleDeprecationResponseBody { | ||
| rules: DeprecatedRuleForReview[]; | ||
| } | ||
This file contains hidden or 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 hidden or 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
53 changes: 53 additions & 0 deletions
53
...utions/security/plugins/security_solution/public/common/hooks/use_timed_dismissal.test.ts
This file contains hidden or 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,53 @@ | ||
| /* | ||
| * 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 { renderHook } from '@testing-library/react'; | ||
| import { useTimedDismissal } from './use_timed_dismissal'; | ||
|
|
||
| const STORAGE_KEY = 'test.dismissal'; | ||
|
|
||
| describe('useTimedDismissal', () => { | ||
| let getItemSpy: jest.SpyInstance; | ||
|
|
||
| beforeEach(() => { | ||
| localStorage.clear(); | ||
| getItemSpy = jest.spyOn(Storage.prototype, 'getItem'); | ||
| jest.useFakeTimers(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.useRealTimers(); | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it('returns not dismissed when nothing is in localStorage', () => { | ||
| const { result } = renderHook(() => useTimedDismissal(STORAGE_KEY)); | ||
|
|
||
| expect(result.current[0]).toBe(false); | ||
| expect(getItemSpy).toHaveBeenCalledWith(STORAGE_KEY); | ||
| }); | ||
|
|
||
| it('returns dismissed when the dismissal has not expired', () => { | ||
| const oneHourMs = 60 * 60 * 1000; | ||
| const fiftyMinutesAgo = Date.now() - 50 * 60 * 1000; | ||
| localStorage.setItem(STORAGE_KEY, String(fiftyMinutesAgo)); | ||
|
|
||
| const { result } = renderHook(() => useTimedDismissal(STORAGE_KEY, oneHourMs)); | ||
|
|
||
| expect(result.current[0]).toBe(true); | ||
| }); | ||
|
|
||
| it('returns not dismissed when the dismissal has expired', () => { | ||
| const oneHourMs = 60 * 60 * 1000; | ||
| const twoHoursAgo = Date.now() - 2 * oneHourMs; | ||
| localStorage.setItem(STORAGE_KEY, String(twoHoursAgo)); | ||
|
|
||
| const { result } = renderHook(() => useTimedDismissal(STORAGE_KEY, oneHourMs)); | ||
|
|
||
| expect(result.current[0]).toBe(false); | ||
| }); | ||
| }); |
47 changes: 47 additions & 0 deletions
47
...k/solutions/security/plugins/security_solution/public/common/hooks/use_timed_dismissal.ts
This file contains hidden or 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,47 @@ | ||
| /* | ||
| * 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 { useCallback, useState } from 'react'; | ||
|
|
||
| const SEVEN_DAYS_MS = 7 * 24 * 60 * 60 * 1000; | ||
|
|
||
| /** | ||
| * Hook that provides a dismissal state persisted to localStorage with an | ||
| * automatic reappearance after a configurable duration. Use for callouts | ||
| * or other components that need to reappear after a set amount of time. | ||
| * | ||
| * @param storageKey - Unique localStorage key for this dismissal | ||
| * @param reappearAfterMs - Duration in ms before the dismissal expires (default: 7 days) | ||
| * @returns A tuple of [isDismissed, dismiss] | ||
| */ | ||
| export const useTimedDismissal = ( | ||
| storageKey: string, | ||
| reappearAfterMs: number = SEVEN_DAYS_MS | ||
| ): [boolean, () => void] => { | ||
| const [isDismissed, setIsDismissed] = useState(() => { | ||
| try { | ||
| const dismissedAt = localStorage.getItem(storageKey); | ||
| if (!dismissedAt) { | ||
| return false; | ||
| } | ||
| return Date.now() - Number(dismissedAt) < reappearAfterMs; | ||
| } catch { | ||
| return false; | ||
| } | ||
| }); | ||
|
|
||
| const dismiss = useCallback(() => { | ||
| try { | ||
| localStorage.setItem(storageKey, String(Date.now())); | ||
| } catch { | ||
| // localStorage may be unavailable (e.g. private browsing quota exceeded) | ||
| } | ||
| setIsDismissed(true); | ||
| }, [storageKey]); | ||
|
|
||
| return [isDismissed, dismiss]; | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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
45 changes: 45 additions & 0 deletions
45
..._management/api/hooks/prebuilt_rules/use_fetch_prebuilt_rules_deprecation_review_query.ts
This file contains hidden or 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,45 @@ | ||
| /* | ||
| * 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 { useCallback } from 'react'; | ||
| import type { UseQueryOptions } from '@kbn/react-query'; | ||
| import { useQuery, useQueryClient } from '@kbn/react-query'; | ||
| import { reviewRuleDeprecation } from '../../api'; | ||
| import { REVIEW_RULE_DEPRECATION_URL } from '../../../../../../common/api/detection_engine/prebuilt_rules/urls'; | ||
| import type { | ||
| ReviewRuleDeprecationRequestBody, | ||
| ReviewRuleDeprecationResponseBody, | ||
| } from '../../../../../../common/api/detection_engine/prebuilt_rules'; | ||
| import { DEFAULT_QUERY_OPTIONS } from '../constants'; | ||
|
|
||
| export const REVIEW_RULE_DEPRECATION_QUERY_KEY = ['POST', REVIEW_RULE_DEPRECATION_URL]; | ||
|
|
||
| export const useFetchPrebuiltRulesDeprecationReviewQuery = ( | ||
| request: ReviewRuleDeprecationRequestBody, | ||
| options?: UseQueryOptions<ReviewRuleDeprecationResponseBody> | ||
| ) => { | ||
| return useQuery<ReviewRuleDeprecationResponseBody>( | ||
| [...REVIEW_RULE_DEPRECATION_QUERY_KEY, request], | ||
| async ({ signal }) => { | ||
| const response = await reviewRuleDeprecation({ signal, request }); | ||
| return response; | ||
| }, | ||
| { | ||
| ...DEFAULT_QUERY_OPTIONS, | ||
| ...options, | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| export const useInvalidateFetchPrebuiltRulesDeprecationReviewQuery = () => { | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| return useCallback(() => { | ||
| queryClient.invalidateQueries(REVIEW_RULE_DEPRECATION_QUERY_KEY, { | ||
| refetchType: 'active', | ||
| }); | ||
| }, [queryClient]); | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we'll need to get notified if we hit 200 prebuilt rules in the package? How realistic is this? The number can only grow, right? If it's realistic, we can update our OOM package tests later to fail if this limit is hit, so we can either bump the limit or investigate what's wrong with the package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless something happens like a malformed package, we shouldn't hit this number anytime soon. Right now we have 111 deprecated rule objects in total and that's accumulated over 5+ years. So at least a few years at the current pace, at which point this will be updated and in a more permanent location