-
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] Alert Telemetry for the Security app (#77200)
This adds a `TelemetryEventsSender` component that can be used to publish Endpoint alerts to our Telemetry service. The alerts are filtered by a set of allowed fields (for PII) and batched in a queue to be sent once per minute. There is a cap of 100 alerts per minute to be sent. The component respects the telemetry opt-in status and enriches the alerts with the cluster ID and name. The Detection Engine is slightly modified to send endpoint telemetry events via the `TelemetryEventsSender`. Only the "custom query" rule type is modified because that's the only one that can create Endpoint Alerts. Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Garrett Spong <spong@users.noreply.github.com>
- Loading branch information
1 parent
935f634
commit 49c8ff3
Showing
14 changed files
with
787 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,8 @@ | |
"spaces", | ||
"usageCollection", | ||
"lists", | ||
"home" | ||
"home", | ||
"telemetry" | ||
], | ||
"server": true, | ||
"ui": true, | ||
|
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
78 changes: 78 additions & 0 deletions
78
...ugins/security_solution/server/lib/detection_engine/signals/send_telemetry_events.test.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,78 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { selectEvents } from './send_telemetry_events'; | ||
|
||
describe('sendAlertTelemetry', () => { | ||
it('selectEvents', () => { | ||
const filteredEvents = { | ||
took: 0, | ||
timed_out: false, | ||
_shards: { | ||
total: 1, | ||
successful: 1, | ||
failed: 0, | ||
skipped: 0, | ||
}, | ||
hits: { | ||
total: 2, | ||
max_score: 0, | ||
hits: [ | ||
{ | ||
_index: 'x', | ||
_type: 'x', | ||
_id: 'x', | ||
_score: 0, | ||
_source: { | ||
'@timestamp': 'x', | ||
key1: 'hello', | ||
data_stream: { | ||
dataset: 'endpoint.events', | ||
}, | ||
}, | ||
}, | ||
{ | ||
_index: 'x', | ||
_type: 'x', | ||
_id: 'x', | ||
_score: 0, | ||
_source: { | ||
'@timestamp': 'x', | ||
key2: 'hello', | ||
data_stream: { | ||
dataset: 'endpoint.alerts', | ||
other: 'x', | ||
}, | ||
}, | ||
}, | ||
{ | ||
_index: 'x', | ||
_type: 'x', | ||
_id: 'x', | ||
_score: 0, | ||
_source: { | ||
'@timestamp': 'x', | ||
key3: 'hello', | ||
data_stream: {}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const sources = selectEvents(filteredEvents); | ||
expect(sources).toStrictEqual([ | ||
{ | ||
'@timestamp': 'x', | ||
key2: 'hello', | ||
data_stream: { | ||
dataset: 'endpoint.alerts', | ||
other: 'x', | ||
}, | ||
}, | ||
]); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
...ck/plugins/security_solution/server/lib/detection_engine/signals/send_telemetry_events.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,46 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { TelemetryEventsSender, TelemetryEvent } from '../../telemetry/sender'; | ||
import { RuleTypeParams } from '../types'; | ||
import { BuildRuleMessage } from './rule_messages'; | ||
import { SignalSearchResponse, SignalSource } from './types'; | ||
import { Logger } from '../../../../../../../src/core/server'; | ||
|
||
export interface SearchResultWithSource { | ||
_source: SignalSource; | ||
} | ||
|
||
export function selectEvents(filteredEvents: SignalSearchResponse): TelemetryEvent[] { | ||
const sources = filteredEvents.hits.hits.map(function ( | ||
obj: SearchResultWithSource | ||
): TelemetryEvent { | ||
return obj._source; | ||
}); | ||
|
||
// Filter out non-endpoint alerts | ||
return sources.filter((obj: TelemetryEvent) => obj.data_stream?.dataset === 'endpoint.alerts'); | ||
} | ||
|
||
export function sendAlertTelemetryEvents( | ||
logger: Logger, | ||
eventsTelemetry: TelemetryEventsSender | undefined, | ||
filteredEvents: SignalSearchResponse, | ||
ruleParams: RuleTypeParams, | ||
buildRuleMessage: BuildRuleMessage | ||
) { | ||
if (eventsTelemetry === undefined) { | ||
return; | ||
} | ||
|
||
const sources = selectEvents(filteredEvents); | ||
|
||
try { | ||
eventsTelemetry.queueTelemetryEvents(sources); | ||
} catch (exc) { | ||
logger.error(buildRuleMessage(`[-] queing telemetry events failed ${exc}`)); | ||
} | ||
} |
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
Oops, something went wrong.