-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create workflow insight from defend insight
- Loading branch information
Showing
3 changed files
with
134 additions
and
2 deletions.
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
86 changes: 86 additions & 0 deletions
86
...rver/assistant/tools/defend_insights/workflow_insights_builders/incompatible_antivirus.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,86 @@ | ||
/* | ||
* 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 moment from 'moment'; | ||
|
||
import { DefendInsight } from '@kbn/elastic-assistant-common'; | ||
import { ENDPOINT_ARTIFACT_LISTS } from '@kbn/securitysolution-list-constants'; | ||
|
||
import type { SecurityWorkflowInsight } from '../../../../../common/endpoint/types/workflow_insights'; | ||
|
||
import { | ||
ActionType, | ||
Category, | ||
SourceType, | ||
TargetType, | ||
} from '../../../../../common/endpoint/types/workflow_insights'; | ||
import { BuildWorkflowInsightParams } from '.'; | ||
import { SUPPORTED_HOST_OS_TYPE } from '../../../../../common/endpoint/constants'; | ||
|
||
export function buildIncompatibleAntivirusWorkflowInsight( | ||
params: BuildWorkflowInsightParams | ||
): SecurityWorkflowInsight[] { | ||
const currentTime = moment(); | ||
const { defendInsights, request } = params; | ||
const { insightType, endpointIds, apiConfig } = request.body; | ||
return defendInsights.map((defendInsight: DefendInsight) => { | ||
const filePaths = (defendInsight.events ?? []).map((event) => event.value); | ||
return { | ||
'@timestamp': currentTime, | ||
// TODO add i18n support | ||
message: 'Incompatible antiviruses detected', | ||
category: Category.Endpoint, | ||
type: insightType, | ||
source: { | ||
type: SourceType.LlmConnector, | ||
id: apiConfig.connectorId, | ||
// TODO use actual time range when we add support | ||
data_range_start: currentTime, | ||
data_range_end: currentTime.clone().add(24, 'hours'), | ||
}, | ||
target: { | ||
type: TargetType.Endpoint, | ||
ids: endpointIds, | ||
}, | ||
action: { | ||
type: ActionType.Refreshed, | ||
timestamp: currentTime, | ||
}, | ||
value: defendInsight.group, | ||
remediation: { | ||
exception_list_items: [ | ||
{ | ||
list_id: ENDPOINT_ARTIFACT_LISTS.blocklists.id, | ||
name: defendInsight.group, | ||
description: 'Suggested by Security Workflow Insights', | ||
entries: [ | ||
{ | ||
field: 'file.path.caseless', | ||
operator: 'included', | ||
type: 'match_any', | ||
value: filePaths, | ||
}, | ||
], | ||
// TODO add per policy support | ||
tags: ['policy:all'], | ||
os_types: [ | ||
// TODO pick this based on endpointIds | ||
SUPPORTED_HOST_OS_TYPE[0], | ||
SUPPORTED_HOST_OS_TYPE[1], | ||
SUPPORTED_HOST_OS_TYPE[2], | ||
], | ||
}, | ||
], | ||
}, | ||
metadata: { | ||
notes: { | ||
llm_model: apiConfig.model ?? '', | ||
}, | ||
}, | ||
}; | ||
}); | ||
} |
31 changes: 31 additions & 0 deletions
31
...urity_solution/server/assistant/tools/defend_insights/workflow_insights_builders/index.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,31 @@ | ||
/* | ||
* 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 { KibanaRequest } from '@kbn/core/server'; | ||
import type { DefendInsightsPostRequestBody } from '@kbn/elastic-assistant-common'; | ||
|
||
import { DefendInsight, DefendInsightType } from '@kbn/elastic-assistant-common'; | ||
|
||
import type { SecurityWorkflowInsight } from '../../../../../common/endpoint/types/workflow_insights'; | ||
|
||
import { InvalidDefendInsightTypeError } from '../errors'; | ||
import { buildIncompatibleAntivirusWorkflowInsight } from './incompatible_antivirus'; | ||
|
||
export interface BuildWorkflowInsightParams { | ||
defendInsights: DefendInsight[]; | ||
request: KibanaRequest<unknown, unknown, DefendInsightsPostRequestBody>; | ||
} | ||
|
||
export function buildWorkflowInsights( | ||
params: BuildWorkflowInsightParams | ||
): SecurityWorkflowInsight[] { | ||
if (params.request.body.insightType == DefendInsightType.Enum.incompatible_antivirus) { | ||
return buildIncompatibleAntivirusWorkflowInsight(params); | ||
} | ||
|
||
throw new InvalidDefendInsightTypeError(); | ||
} |