-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Security Solution][Detections] Allows rules to be updated from EPR #91949
Closed
Closed
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a80e67e
Retrieve rules from EPR instead of the filesystem
rw-access 57d2184
Restore prepackaged rules
rw-access e53c80c
Merge branch 'master' into epr-detection-rules
rw-access 0d88ccf
Merge remote-tracking branch 'origin/master' into epr-detection-rules
rw-access 638ecb5
Make upload resilient to offline and disconnects
rw-access cd38f85
Merge remote-tracking branch 'origin/master' into epr-detection-rules
rw-access 63154eb
Fix lint errors
rw-access a8f063c
Put EPR enabled rules behind a feature flag
rw-access a5153ec
Fix lint and empty rules response
rw-access 4311ef4
Compact map w/ Promises.all usage
rw-access b301d4a
Move package name to constants: DETECTION_RULES_PACAKGE_NAME
rw-access 0c60688
Fix packaged rules tests
rw-access bc57209
Loosen up API for backwards compatibility, and fix mocks
rw-access b4c2267
Fix type errors with an offering to the CI gods
rw-access 11a0e05
Fix fleet lint
rw-access 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 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
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
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 |
---|---|---|
|
@@ -12,6 +12,11 @@ import type { | |
} from '../../../../types'; | ||
|
||
import { validate } from '../../../../../common/validate'; | ||
import { buildRouteValidation } from '../../../../utils/build_validation/route_validation'; | ||
import { | ||
installPrepackagedRulesSchema, | ||
InstallPrepackagedRulesSchema, | ||
} from '../../../../../common/detection_engine/schemas/request/rule_schemas'; | ||
import { | ||
PrePackagedRulesAndTimelinesSchema, | ||
prePackagedRulesAndTimelinesSchema, | ||
|
@@ -25,7 +30,7 @@ import { buildFrameworkRequest } from '../../../timeline/routes/utils/common'; | |
import { installPrepackagedTimelines } from '../../../timeline/routes/utils/install_prepacked_timelines'; | ||
|
||
import { getIndexExists } from '../../index/get_index_exists'; | ||
import { getPrepackagedRules } from '../../rules/get_prepackaged_rules'; | ||
import { getRegistryOrFileSystemRules } from '../../rules/get_prepackaged_rules'; | ||
import { installPrepackagedRules } from '../../rules/install_prepacked_rules'; | ||
import { updatePrepackagedRules } from '../../rules/update_prepacked_rules'; | ||
import { getRulesToInstall } from '../../rules/get_rules_to_install'; | ||
|
@@ -46,14 +51,19 @@ export const addPrepackedRulesRoute = ( | |
router.put( | ||
{ | ||
path: DETECTION_ENGINE_PREPACKAGED_URL, | ||
validate: false, | ||
validate: { | ||
body: buildRouteValidation< | ||
typeof installPrepackagedRulesSchema, | ||
InstallPrepackagedRulesSchema | ||
>(installPrepackagedRulesSchema), | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll have to mess with these types and figure out how to make the body optional. I am pretty sure the way to do that is to make the type basically a union with null so that when you have |
||
options: { | ||
tags: ['access:securitySolution'], | ||
}, | ||
}, | ||
async (context, _, response) => { | ||
async (context, request, response) => { | ||
const siemResponse = buildSiemResponse(response); | ||
const frameworkRequest = await buildFrameworkRequest(context, security, _); | ||
const frameworkRequest = await buildFrameworkRequest(context, security, request); | ||
|
||
try { | ||
const alertsClient = context.alerting?.getAlertsClient(); | ||
|
@@ -68,7 +78,9 @@ export const addPrepackedRulesRoute = ( | |
siemClient, | ||
alertsClient, | ||
frameworkRequest, | ||
config.maxTimelineImportExportSize | ||
config.maxTimelineImportExportSize, | ||
undefined, | ||
request.body.rules_package_version | ||
); | ||
return response.ok({ body: validated ?? {} }); | ||
} catch (err) { | ||
|
@@ -96,7 +108,8 @@ export const createPrepackagedRules = async ( | |
alertsClient: AlertsClient, | ||
frameworkRequest: FrameworkRequest, | ||
maxTimelineImportExportSize: number, | ||
exceptionsClient?: ExceptionListClient | ||
exceptionsClient?: ExceptionListClient, | ||
rulesPackageVersion?: string | ||
): Promise<PrePackagedRulesAndTimelinesSchema | null> => { | ||
const clusterClient = context.core.elasticsearch.legacy.client; | ||
const savedObjectsClient = context.core.savedObjects.client; | ||
|
@@ -112,10 +125,10 @@ export const createPrepackagedRules = async ( | |
await exceptionsListClient.createEndpointList(); | ||
} | ||
|
||
const rulesFromFileSystem = getPrepackagedRules(); | ||
const prepackagedRules = await getExistingPrepackagedRules({ alertsClient }); | ||
const rulesToInstall = getRulesToInstall(rulesFromFileSystem, prepackagedRules); | ||
const rulesToUpdate = getRulesToUpdate(rulesFromFileSystem, prepackagedRules); | ||
const prepackagedRules = await getRegistryOrFileSystemRules(rulesPackageVersion); | ||
const existingPrepackagedRules = await getExistingPrepackagedRules({ alertsClient }); | ||
const rulesToInstall = getRulesToInstall(prepackagedRules, existingPrepackagedRules); | ||
const rulesToUpdate = getRulesToUpdate(prepackagedRules, existingPrepackagedRules); | ||
const signalsIndex = siemClient.getSignalsIndex(); | ||
if (rulesToInstall.length !== 0 || rulesToUpdate.length !== 0) { | ||
const signalsIndexExists = await getIndexExists(clusterClient.callAsCurrentUser, signalsIndex); | ||
|
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
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/security_solution/server/lib/detection_engine/rules/constants.ts
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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
const DETECTION_RULES_PACAKGE_NAME = 'detection_rules'; |
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.
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.
You'll probably have to get someone from the
epm
team to also give you a LGTM, but looking below I think they might want it like so (from their patterns):(caveat, I haven't tested that, just coming off the top of my head)