-
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.
[Security Solutions] Adds a security solutions experimental telemetry…
… preview endpoint and e2e tests (#123989) ## Summary For e2e testing to be possible we have to enable an experimental preview endpoint: ```ts GET /internal/security_solution/telemetry ``` You can only enable this endpoint if you edit your `kibana.dev.yml` and add this line: ```yml xpack.securitySolution.enableExperimental: ['previewTelemetryUrlEnabled'] ``` This PR adds the following: * Pulls up an interface from both `TelemetryEventsSender` and `TelemetryReceiver` * Issue in the e2e FTR where we weren't removing lists from agnostic and regular space * Adds preview capabilities for `DetectionRules`, `SecurityLists`, `Endpoint`, and `Diagnostics` * 19 FTR e2e tests for `DetectionRules` and `SecurityLists`. But does _NOT_ add any for `Endpoint` or `Diagnostics` * Fixes a dangling promise that makes the preview deterministic * Fixes a small issue seen with the trusted applications and endpoint application createLists To run the test server and runner for FTR: Start the FTR server and wait for it to be initialized first: ```sh cd kibana/x-pack node scripts/functional_tests_server.js --config test/detection_engine_api_integration/security_and_spaces/config.ts ``` In a seperate terminal run: ```sh cd kibana/x-pack node scripts/functional_test_runner.js --config test/detection_engine_api_integration/security_and_spaces/config.ts --include test/detection_engine_api_integration/security_and_spaces/tests/telemetry/index.ts ``` ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- Loading branch information
1 parent
6846622
commit ac7745e
Showing
35 changed files
with
2,083 additions
and
103 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
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
68 changes: 68 additions & 0 deletions
68
...n/server/lib/detection_engine/routes/telemetry/telemetry_detection_rules_preview_route.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,68 @@ | ||
/* | ||
* 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 { Logger } from 'src/core/server'; | ||
|
||
import { SECURITY_TELEMETRY_URL } from '../../../../../common/constants'; | ||
import type { SecuritySolutionPluginRouter } from '../../../../types'; | ||
import { ITelemetryReceiver } from '../../../telemetry/receiver'; | ||
import { ITelemetryEventsSender } from '../../../telemetry/sender'; | ||
import { getDetectionRulesPreview } from './utils/get_detecton_rules_preview'; | ||
import { getSecurityListsPreview } from './utils/get_security_lists_preview'; | ||
import { getEndpointPreview } from './utils/get_endpoint_preview'; | ||
import { getDiagnosticsPreview } from './utils/get_diagnostics_preview'; | ||
|
||
export const telemetryDetectionRulesPreviewRoute = ( | ||
router: SecuritySolutionPluginRouter, | ||
logger: Logger, | ||
telemetryReceiver: ITelemetryReceiver, | ||
telemetrySender: ITelemetryEventsSender | ||
) => { | ||
router.get( | ||
{ | ||
path: SECURITY_TELEMETRY_URL, | ||
validate: false, | ||
options: { | ||
tags: ['access:securitySolution'], | ||
}, | ||
}, | ||
async (context, request, response) => { | ||
const detectionRules = await getDetectionRulesPreview({ | ||
logger, | ||
telemetryReceiver, | ||
telemetrySender, | ||
}); | ||
|
||
const securityLists = await getSecurityListsPreview({ | ||
logger, | ||
telemetryReceiver, | ||
telemetrySender, | ||
}); | ||
|
||
const endpoints = await getEndpointPreview({ | ||
logger, | ||
telemetryReceiver, | ||
telemetrySender, | ||
}); | ||
|
||
const diagnostics = await getDiagnosticsPreview({ | ||
logger, | ||
telemetryReceiver, | ||
telemetrySender, | ||
}); | ||
|
||
return response.ok({ | ||
body: { | ||
detection_rules: detectionRules, | ||
security_lists: securityLists, | ||
endpoints, | ||
diagnostics, | ||
}, | ||
}); | ||
} | ||
); | ||
}; |
41 changes: 41 additions & 0 deletions
41
...solution/server/lib/detection_engine/routes/telemetry/utils/get_detecton_rules_preview.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,41 @@ | ||
/* | ||
* 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 { Logger } from 'src/core/server'; | ||
|
||
import { PreviewTelemetryEventsSender } from '../../../../telemetry/preview_sender'; | ||
import { ITelemetryReceiver } from '../../../../telemetry/receiver'; | ||
import { ITelemetryEventsSender } from '../../../../telemetry/sender'; | ||
import { createTelemetryDetectionRuleListsTaskConfig } from '../../../../telemetry/tasks/detection_rule'; | ||
import { parseNdjson } from './parse_ndjson'; | ||
|
||
export const getDetectionRulesPreview = async ({ | ||
logger, | ||
telemetryReceiver, | ||
telemetrySender, | ||
}: { | ||
logger: Logger; | ||
telemetryReceiver: ITelemetryReceiver; | ||
telemetrySender: ITelemetryEventsSender; | ||
}): Promise<object[][]> => { | ||
const taskExecutionPeriod = { | ||
last: new Date(0).toISOString(), | ||
current: new Date().toISOString(), | ||
}; | ||
|
||
const taskSender = new PreviewTelemetryEventsSender(logger, telemetrySender); | ||
const task = createTelemetryDetectionRuleListsTaskConfig(1000); | ||
await task.runTask( | ||
'detection-rules-preview', | ||
logger, | ||
telemetryReceiver, | ||
taskSender, | ||
taskExecutionPeriod | ||
); | ||
const messages = taskSender.getSentMessages(); | ||
return parseNdjson(messages); | ||
}; |
41 changes: 41 additions & 0 deletions
41
...ty_solution/server/lib/detection_engine/routes/telemetry/utils/get_diagnostics_preview.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,41 @@ | ||
/* | ||
* 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 { Logger } from 'src/core/server'; | ||
|
||
import { PreviewTelemetryEventsSender } from '../../../../telemetry/preview_sender'; | ||
import { ITelemetryReceiver } from '../../../../telemetry/receiver'; | ||
import { ITelemetryEventsSender } from '../../../../telemetry/sender'; | ||
import { createTelemetryDiagnosticsTaskConfig } from '../../../../telemetry/tasks/diagnostic'; | ||
import { parseNdjson } from './parse_ndjson'; | ||
|
||
export const getDiagnosticsPreview = async ({ | ||
logger, | ||
telemetryReceiver, | ||
telemetrySender, | ||
}: { | ||
logger: Logger; | ||
telemetryReceiver: ITelemetryReceiver; | ||
telemetrySender: ITelemetryEventsSender; | ||
}): Promise<object[][]> => { | ||
const taskExecutionPeriod = { | ||
last: new Date(0).toISOString(), | ||
current: new Date().toISOString(), | ||
}; | ||
|
||
const taskSender = new PreviewTelemetryEventsSender(logger, telemetrySender); | ||
const task = createTelemetryDiagnosticsTaskConfig(); | ||
await task.runTask( | ||
'diagnostics-preview', | ||
logger, | ||
telemetryReceiver, | ||
taskSender, | ||
taskExecutionPeriod | ||
); | ||
const messages = taskSender.getSentMessages(); | ||
return parseNdjson(messages); | ||
}; |
41 changes: 41 additions & 0 deletions
41
...urity_solution/server/lib/detection_engine/routes/telemetry/utils/get_endpoint_preview.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,41 @@ | ||
/* | ||
* 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 { Logger } from 'src/core/server'; | ||
|
||
import { PreviewTelemetryEventsSender } from '../../../../telemetry/preview_sender'; | ||
import { ITelemetryReceiver } from '../../../../telemetry/receiver'; | ||
import { ITelemetryEventsSender } from '../../../../telemetry/sender'; | ||
import { createTelemetryEndpointTaskConfig } from '../../../../telemetry/tasks/endpoint'; | ||
import { parseNdjson } from './parse_ndjson'; | ||
|
||
export const getEndpointPreview = async ({ | ||
logger, | ||
telemetryReceiver, | ||
telemetrySender, | ||
}: { | ||
logger: Logger; | ||
telemetryReceiver: ITelemetryReceiver; | ||
telemetrySender: ITelemetryEventsSender; | ||
}): Promise<object[][]> => { | ||
const taskExecutionPeriod = { | ||
last: new Date(0).toISOString(), | ||
current: new Date().toISOString(), | ||
}; | ||
|
||
const taskSender = new PreviewTelemetryEventsSender(logger, telemetrySender); | ||
const task = createTelemetryEndpointTaskConfig(1000); | ||
await task.runTask( | ||
'endpoint-preview', | ||
logger, | ||
telemetryReceiver, | ||
taskSender, | ||
taskExecutionPeriod | ||
); | ||
const messages = taskSender.getSentMessages(); | ||
return parseNdjson(messages); | ||
}; |
41 changes: 41 additions & 0 deletions
41
...solution/server/lib/detection_engine/routes/telemetry/utils/get_security_lists_preview.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,41 @@ | ||
/* | ||
* 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 { Logger } from 'src/core/server'; | ||
|
||
import { PreviewTelemetryEventsSender } from '../../../../telemetry/preview_sender'; | ||
import { ITelemetryReceiver } from '../../../../telemetry/receiver'; | ||
import { ITelemetryEventsSender } from '../../../../telemetry/sender'; | ||
import { createTelemetrySecurityListTaskConfig } from '../../../../telemetry/tasks/security_lists'; | ||
import { parseNdjson } from './parse_ndjson'; | ||
|
||
export const getSecurityListsPreview = async ({ | ||
logger, | ||
telemetryReceiver, | ||
telemetrySender, | ||
}: { | ||
logger: Logger; | ||
telemetryReceiver: ITelemetryReceiver; | ||
telemetrySender: ITelemetryEventsSender; | ||
}): Promise<object[][]> => { | ||
const taskExecutionPeriod = { | ||
last: new Date(0).toISOString(), | ||
current: new Date().toISOString(), | ||
}; | ||
|
||
const taskSender = new PreviewTelemetryEventsSender(logger, telemetrySender); | ||
const task = createTelemetrySecurityListTaskConfig(1000); | ||
await task.runTask( | ||
'security-lists-preview', | ||
logger, | ||
telemetryReceiver, | ||
taskSender, | ||
taskExecutionPeriod | ||
); | ||
const messages = taskSender.getSentMessages(); | ||
return parseNdjson(messages); | ||
}; |
20 changes: 20 additions & 0 deletions
20
...gins/security_solution/server/lib/detection_engine/routes/telemetry/utils/parse_ndjson.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,20 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export const parseNdjson = (messages: string[]): object[][] => { | ||
return messages.map((message) => { | ||
const splitByNewLine = message.split('\n'); | ||
const linesParsed = splitByNewLine.flatMap<object>((line) => { | ||
try { | ||
return JSON.parse(line); | ||
} catch (error) { | ||
return []; | ||
} | ||
}); | ||
return linesParsed; | ||
}); | ||
}; |
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
Oops, something went wrong.