-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[DO NOT MERGE][Security Solution][Attacks/Alerts] POC: Alerts/Attacks promotion #252977
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
Draft
e40pud
wants to merge
90
commits into
elastic:main
Choose a base branch
from
e40pud:security/attack-alerts-alignment/POC-attack-promotion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
90 commits
Select commit
Hold shift + click to select a range
21dde1a
[SecuritySolution] Alerts/Attacks promotion
e40pud 5a50530
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud c6ae75e
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 5a9bd61
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud c465a94
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 614f898
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud c03f6a5
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 1403fd2
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 0662084
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 5b8c68b
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud c2c6b33
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud e60c507
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud e2428b6
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud ed0d696
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 7df256a
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 36ee891
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 539b0ad
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 574b0c9
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 62b825a
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 4114c25
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 922b000
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 5e30fc5
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud e3b049c
POC 2
e40pud b053bb5
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud a62942d
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud a9167ed
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud f06a595
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 8341c57
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud ca75431
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 4fde6fb
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud c9e9c31
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud b526b02
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud f2369cb
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 06d782f
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud b7596b5
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 60665ed
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 1117f09
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud c9d5132
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 2cc4250
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 2628b58
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 22b3523
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 82b0bc5
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 908257d
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud f5d5cf6
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud b6bac52
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 8dae144
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 0ee6665
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 097cfbd
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 36fa2cd
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud f88d0b7
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 0565dc2
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 5c341b4
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud d4dfeb3
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 980ff1e
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 0f14755
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 184f013
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 97cdc8f
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 1cef865
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud e4d3c85
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 96ca61f
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud e60ffd4
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 81ac012
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud dddc2e0
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 1aa6027
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud bd78722
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud b91679b
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud a27e488
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 563801b
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 148da7d
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 1d7fc8e
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud bb90c3d
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 08f306f
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 3e74902
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 0cf1c5d
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 8ecb30f
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 4d084eb
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 08e2e45
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 8fe585b
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud fb57e87
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 4c516d2
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 9458a5e
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 5e454b2
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 4a42e33
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 731b208
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 1cd2544
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 4792581
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 217fde4
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud fc83431
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud df8f886
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 109ec28
Merge branch 'main' into security/attack-alerts-alignment/POC-attack-…
e40pud 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
24 changes: 24 additions & 0 deletions
24
...on/impl/schemas/attack_discovery/routes/internal/promote/post_attack_discovery_promote.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,24 @@ | ||
| /* | ||
| * 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'; | ||
|
|
||
| export const PostAttackDiscoveryPromoteRequestBody = z.object({ | ||
| attack_ids: z.array(z.string()).min(1), | ||
| }); | ||
|
|
||
| export type PostAttackDiscoveryPromoteRequestBody = z.infer< | ||
| typeof PostAttackDiscoveryPromoteRequestBody | ||
| >; | ||
|
|
||
| export const PostAttackDiscoveryPromoteResponse = z.object({ | ||
| success: z.boolean(), | ||
| execution_uuid: z.string().optional(), | ||
| error: z.string().optional(), | ||
| }); | ||
|
|
||
| export type PostAttackDiscoveryPromoteResponse = z.infer<typeof PostAttackDiscoveryPromoteResponse>; |
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
208 changes: 208 additions & 0 deletions
208
...latform/plugins/shared/alerting/server/ad_hoc_execution_client/ad_hoc_execution_client.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,208 @@ | ||
| /* | ||
| * 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 type { | ||
| ISavedObjectsRepository, | ||
| Logger, | ||
| SavedObjectReference, | ||
| SavedObjectsBulkCreateObject, | ||
| SavedObjectsClientContract, | ||
| } from '@kbn/core/server'; | ||
| import type { AuditLogger } from '@kbn/security-plugin/server'; | ||
| import type { | ||
| TaskInstance, | ||
| TaskManagerStartContract, | ||
| TaskManagerSetupContract, | ||
| RunContext, | ||
| } from '@kbn/task-manager-plugin/server'; | ||
| import { TaskPriority } from '@kbn/task-manager-plugin/server'; | ||
| import type { IEventLogger, IEventLogClient } from '@kbn/event-log-plugin/server'; | ||
| import type { | ||
| ExecutionError, | ||
| ScheduleExecutionParams, | ||
| ScheduleExecutionResults, | ||
| AdHocRunResult, | ||
| } from '../application/ad_hoc/types'; | ||
| import { | ||
| transformAdHocRunToBackfillResult, | ||
| transformBackfillParamToAdHocRun, | ||
| } from '../application/backfill/transforms'; | ||
| import type { RuleDomain } from '../application/rule/types'; | ||
| import type { AdHocRunSO } from '../data/ad_hoc_run/types'; | ||
| import { AdHocRunAuditAction, adHocRunAuditEvent } from '../rules_client/common/audit_events'; | ||
| import { AD_HOC_RUN_SAVED_OBJECT_TYPE } from '../saved_objects'; | ||
| import { createExecutionError } from '../application/ad_hoc/lib/create_execution_error'; | ||
| import type { TaskRunnerFactory } from '../task_runner'; | ||
|
|
||
| import { AD_HOC_TASK_TYPE } from '../application/ad_hoc/constants'; | ||
|
|
||
| interface ConstructorOpts { | ||
| logger: Logger; | ||
| taskManagerSetup: TaskManagerSetupContract; | ||
| taskManagerStartPromise: Promise<TaskManagerStartContract>; | ||
| taskRunnerFactory: TaskRunnerFactory; | ||
| } | ||
|
|
||
| interface QueueAdHocExecutionOpts { | ||
| auditLogger?: AuditLogger; | ||
| params: ScheduleExecutionParams; | ||
| rules: RuleDomain[]; | ||
| spaceId: string; | ||
| unsecuredSavedObjectsClient: SavedObjectsClientContract; | ||
| eventLogClient: IEventLogClient; | ||
| internalSavedObjectsRepository: ISavedObjectsRepository; | ||
| eventLogger: IEventLogger | undefined; | ||
| } | ||
|
|
||
| export class AdHocExecutionClient { | ||
| private logger: Logger; | ||
| private readonly taskManagerStartPromise: Promise<TaskManagerStartContract>; | ||
|
|
||
| constructor(opts: ConstructorOpts) { | ||
| this.logger = opts.logger; | ||
| this.taskManagerStartPromise = opts.taskManagerStartPromise; | ||
|
|
||
| opts.taskManagerSetup.registerTaskDefinitions({ | ||
| [AD_HOC_TASK_TYPE]: { | ||
| title: 'Alerting Ad-hoc Rule Run', | ||
| priority: TaskPriority.Low, | ||
| createTaskRunner: (context: RunContext) => opts.taskRunnerFactory.createAdHoc(context), | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| public async queueAdHocExecution({ | ||
| auditLogger, | ||
| params, | ||
| rules, | ||
| spaceId, | ||
| unsecuredSavedObjectsClient, | ||
| }: QueueAdHocExecutionOpts): Promise<ScheduleExecutionResults> { | ||
| const adHocSOsToCreate: Array<SavedObjectsBulkCreateObject<AdHocRunSO>> = []; | ||
| const soToCreateIndexOrErrorMap: Map<number, number | ExecutionError> = new Map(); | ||
|
|
||
| for (let ndx = 0; ndx < params.length; ndx++) { | ||
| const param = params[ndx]; | ||
| // simplified rule lookup - we expect the rule to be passed in rules array | ||
| const rule = rules.find((r) => r.id === param.ruleId); | ||
|
|
||
| if (rule) { | ||
| soToCreateIndexOrErrorMap.set(ndx, adHocSOsToCreate.length); | ||
|
|
||
| const references: SavedObjectReference[] = [ | ||
| { | ||
| name: 'rule', | ||
| type: 'rule', | ||
| id: rule.id, | ||
| }, | ||
| ]; | ||
|
|
||
| const start = param.start ?? new Date().toISOString(); | ||
| const end = param.end ?? new Date().toISOString(); | ||
|
|
||
| const attributes = transformBackfillParamToAdHocRun( | ||
| { | ||
| ruleId: rule.id, | ||
| ranges: [{ start, end }], | ||
| runActions: false, | ||
| initiator: param.initiator, | ||
| initiatorId: param.initiatorId, | ||
| }, | ||
| rule, | ||
| [], | ||
| spaceId | ||
| ); | ||
|
|
||
| adHocSOsToCreate.push({ | ||
| type: AD_HOC_RUN_SAVED_OBJECT_TYPE, | ||
| attributes, | ||
| references, | ||
| }); | ||
| } else { | ||
| const error = createExecutionError(`Rule not found for ID ${param.ruleId}`, param.ruleId); | ||
| soToCreateIndexOrErrorMap.set(ndx, error); | ||
| this.logger.warn( | ||
| `Error for ruleId ${param.ruleId} - not scheduling ad-hoc execution for ${JSON.stringify( | ||
| param | ||
| )}` | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| if (!adHocSOsToCreate.length) { | ||
| return params.map((_, ndx: number) => soToCreateIndexOrErrorMap.get(ndx) as ExecutionError); | ||
| } | ||
|
|
||
| // Create Saved Objects | ||
| const response = await unsecuredSavedObjectsClient.bulkCreate<AdHocRunSO>(adHocSOsToCreate); | ||
|
|
||
| // Process results | ||
| const createdSOs = response.saved_objects; | ||
|
|
||
| const transformedResponse: ScheduleExecutionResults = []; | ||
|
|
||
| // Map back to original order and transform | ||
| for (let ndx = 0; ndx < params.length; ndx++) { | ||
| const indexOrError = soToCreateIndexOrErrorMap.get(ndx); | ||
| if (typeof indexOrError === 'number') { | ||
| const so = createdSOs[indexOrError]; | ||
| if (so.error) { | ||
| auditLogger?.log( | ||
| adHocRunAuditEvent({ | ||
| action: AdHocRunAuditAction.CREATE, | ||
| error: new Error(so.error.message), | ||
| }) | ||
| ); | ||
| transformedResponse.push(createExecutionError(so.error.message, params[ndx].ruleId)); | ||
| } else { | ||
| auditLogger?.log( | ||
| adHocRunAuditEvent({ | ||
| action: AdHocRunAuditAction.CREATE, | ||
| savedObject: { type: AD_HOC_RUN_SAVED_OBJECT_TYPE, id: so.id }, | ||
| }) | ||
| ); | ||
|
|
||
| const result = transformAdHocRunToBackfillResult({ | ||
| adHocRunSO: so, | ||
| isSystemAction: (id: string) => true, // System action check not relevant here? Or pass dummy | ||
| originalSO: adHocSOsToCreate[indexOrError], | ||
| }); | ||
|
|
||
| transformedResponse.push(result); | ||
| } | ||
| } else { | ||
| transformedResponse.push(indexOrError as ExecutionError); | ||
| } | ||
| } | ||
|
|
||
| // Schedule Tasks | ||
| const adHocTasksToSchedule: TaskInstance[] = []; | ||
| transformedResponse.forEach((result) => { | ||
| if (!('error' in result)) { | ||
| const createdSO = result as AdHocRunResult; | ||
| // We don't have ruleTypeRegistry here easily to check timeout, | ||
| // but we can pass it or just default. | ||
| adHocTasksToSchedule.push({ | ||
| id: createdSO.id, | ||
| taskType: AD_HOC_TASK_TYPE, | ||
| state: {}, | ||
| params: { | ||
| adHocRunParamsId: createdSO.id, | ||
| spaceId, | ||
| }, | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| if (adHocTasksToSchedule.length > 0) { | ||
| const taskManager = await this.taskManagerStartPromise; | ||
| await taskManager.bulkSchedule(adHocTasksToSchedule); | ||
| } | ||
|
|
||
| return transformedResponse; | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.