Skip to content
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] Alert Telemetry for the Security app #77200

Merged
merged 27 commits into from
Sep 30, 2020
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e2250a9
Empty recurring task
tsg Aug 17, 2020
da753fe
Added processEvents with tests
tsg Aug 18, 2020
6335857
SendIfDue + tests
tsg Aug 19, 2020
c302fdd
Connect telemetry in the detection engine
tsg Sep 7, 2020
5e14df8
Respect opt-in status
tsg Sep 10, 2020
7bcf141
test fixes + test for telemetry disabled
tsg Sep 10, 2020
483e3cf
Various type fixes
tsg Sep 18, 2020
0cd31af
Merge branch 'master' into telemetry_events
elasticmachine Sep 18, 2020
65a5078
Add cluster_uuid and cluster_name
tsg Sep 21, 2020
fb6b3ea
Filter by endpoint alerts
tsg Sep 22, 2020
2fdc70c
type fixes + tests
tsg Sep 23, 2020
725fc54
mege master
tsg Sep 23, 2020
069147f
fix types
tsg Sep 23, 2020
896ca96
merge master
tsg Sep 28, 2020
0ae4046
Refactor processEvents
tsg Sep 28, 2020
2f31f49
Send events to the telemetry server
tsg Sep 29, 2020
f8309c9
Small refactoring
tsg Sep 29, 2020
b2df3a8
Add license fields
tsg Sep 29, 2020
e6a2d71
Update x-pack/plugins/security_solution/server/lib/detection_engine/s…
tsg Sep 29, 2020
722e68d
Move undefined check in the function to simplify top level code
tsg Sep 29, 2020
5f25435
Correct datastream to data_stream
tsg Sep 29, 2020
1a29cbd
Incorporated Xavier's feedback + add license header
tsg Sep 30, 2020
0dda88c
Test fix + minor changes
tsg Sep 30, 2020
23fbe32
Commented out verbose debug logs
tsg Sep 30, 2020
52390cf
Merge branch 'master' into telemetry_events
elasticmachine Sep 30, 2020
d0d52f4
Merge branch 'master' into telemetry_events
elasticmachine Sep 30, 2020
e8b364d
Merge branch 'master' into telemetry_events
elasticmachine Sep 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add license fields
  • Loading branch information
tsg committed Sep 29, 2020
commit b2df3a8733ca0425d206428fe3c94d7921a37d07
63 changes: 62 additions & 1 deletion x-pack/plugins/security_solution/server/lib/telemetry/sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface TelemetryEvent {
[key: string]: SearchTypes;
};
};
license?: ESLicense;
}

export class TelemetryEventsSender {
Expand Down Expand Up @@ -139,12 +140,15 @@ export class TelemetryEventsSender {
`cluster_uuid: ${clusterInfo?.cluster_uuid} cluster_name: ${clusterInfo?.cluster_name}`
);

const licenseInfo = await this.fetchLicenseInfo();

const toSend: TelemetryEvent[] = cloneDeep(this.queue);
this.queue = [];

toSend.forEach((event) => {
event.cluster_uuid = clusterInfo.cluster_uuid;
event.cluster_name = clusterInfo.cluster_name;
this.copyLicenseFields(event, licenseInfo);
});

await this.sendEvents(toSend, telemetryUrl, clusterInfo.cluster_uuid);
Expand Down Expand Up @@ -172,6 +176,36 @@ export class TelemetryEventsSender {
return getV3UrlFromV2(telemetryUrl.toString(), 'alerts-debug'); // TODO: update
}

private async fetchLicenseInfo(): Promise<ESLicense | undefined> {
if (!this.core) {
return undefined;
}
try {
const callCluster = this.core.elasticsearch.legacy.client.callAsInternalUser;
const ret = await getLicense(callCluster, true);
return ret.license;
} catch (err) {
this.logger.warn(`Error retrieving license: ${err}`);
return undefined;
}
}

private copyLicenseFields(event: TelemetryEvent, lic: ESLicense | undefined) {
if (lic) {
event.license = {
uid: lic.uid,
status: lic.status,
type: lic.type,
};
if (lic.issued_to) {
event.license.issued_to = lic.issued_to;
}
if (lic.issuer) {
event.license.issuer = lic.issuer;
}
}
}

private async sendEvents(events: unknown[], telemetryUrl: string, clusterUuid: string) {
// this.logger.debug(`Sending events: ${JSON.stringify(events, null, 2)}`);
const ndjson = transformDataToNdjson(events);
Expand Down Expand Up @@ -305,6 +339,33 @@ export interface ESClusterInfo {
*
* @param {function} callCluster The callWithInternalUser handler (exposed for testing)
*/
export function getClusterInfo(callCluster: LegacyAPICaller) {
function getClusterInfo(callCluster: LegacyAPICaller) {
return callCluster<ESClusterInfo>('info');
}

// From https://www.elastic.co/guide/en/elasticsearch/reference/current/get-license.html
export interface ESLicense {
status: string;
uid: string;
type: string;
issue_date?: string;
issue_date_in_millis?: number;
expiry_date?: string;
expirty_date_in_millis?: number;
max_nodes?: number;
issued_to?: string;
issuer?: string;
start_date_in_millis?: number;
}

function getLicense(callCluster: LegacyAPICaller, local: boolean) {
return callCluster<{ license: ESLicense }>('transport.request', {
method: 'GET',
path: '/_license',
query: {
local,
// For versions >= 7.6 and < 8.0, this flag is needed otherwise 'platinum' is returned for 'enterprise' license.
accept_enterprise: 'true',
},
});
}