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

[SIEM] [Detection Engine] Adds stable alerting ids, more scripting for product testing, and more unit tests #48471

Merged
merged 31 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8c9a5fc
Added API endpoints and more scripts
FrankHassanabad Oct 8, 2019
3b56b4c
Merge branch 'master' into add-get-delete-api
FrankHassanabad Oct 8, 2019
91953a1
Added the update endpoint and scripts for the support of it. Changed …
FrankHassanabad Oct 9, 2019
84739d4
put back the require statement for the builds to work correctly
FrankHassanabad Oct 9, 2019
91f2797
Added casting magic with a TODO block
FrankHassanabad Oct 9, 2019
ee7c2c3
cleaned up more types
FrankHassanabad Oct 9, 2019
d136c3b
Merge branch 'master' into add-get-delete-api
FrankHassanabad Oct 9, 2019
5fe3a77
Updated per code review
FrankHassanabad Oct 9, 2019
42fbb44
Changed per code review
FrankHassanabad Oct 9, 2019
a5f5448
Updated per code review
FrankHassanabad Oct 9, 2019
aa7108b
Added optional id parameter in the URL that can be sent
FrankHassanabad Oct 10, 2019
eadac5d
added some unit tests
FrankHassanabad Oct 10, 2019
9a90e47
Merge branch 'master' into add-get-delete-api
FrankHassanabad Oct 10, 2019
9a3c036
Does all crud through a request params called alert_id instead of the…
FrankHassanabad Oct 10, 2019
5ab372a
Removed weird wording from a function
FrankHassanabad Oct 10, 2019
ee06ed0
Merge branch 'master' into add-get-delete-api
FrankHassanabad Oct 11, 2019
a236065
Merge branch 'add-get-delete-api' into add-stable-id-option
FrankHassanabad Oct 11, 2019
acd9ff0
Added scripts to convert from saved objects to signals for posting
FrankHassanabad Oct 12, 2019
93e888e
Remove echo statement
FrankHassanabad Oct 12, 2019
e5cb35f
Merge branch 'master' into add-get-delete-api
FrankHassanabad Oct 14, 2019
a5eaab1
Merge branch 'master' into add-get-delete-api
FrankHassanabad Oct 14, 2019
688da79
Merge branch 'add-get-delete-api' into add-stable-id-option
FrankHassanabad Oct 14, 2019
31b8add
Merge branch 'master' into add-stable-id-option
FrankHassanabad Oct 14, 2019
009010a
Merge branch 'master' into add-stable-id-option
FrankHassanabad Oct 15, 2019
17394a2
Fix minor wording
FrankHassanabad Oct 15, 2019
6319638
beginning of route unit tests added
FrankHassanabad Oct 16, 2019
4ac7fd1
reduced code by using more mock folders
FrankHassanabad Oct 16, 2019
fb58fc3
Consolidated types
FrankHassanabad Oct 16, 2019
29b82b6
Fixed more types that were any and bugs associated with it
FrankHassanabad Oct 16, 2019
6cf8a42
Merge branch 'master' into add-stable-id-option
FrankHassanabad Oct 17, 2019
a971358
Merge branch 'add-stable-id-option' into change-ecs-schema
FrankHassanabad Oct 17, 2019
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
10 changes: 7 additions & 3 deletions x-pack/legacy/plugins/siem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
} from './common/constants';
import { signalsAlertType } from './server/lib/detection_engine/alerts/signals_alert_type';
import { defaultIndexPattern } from './default_index_pattern';
import { isAlertExecutor } from './server/lib/detection_engine/alerts/types';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function siem(kibana: any) {
Expand Down Expand Up @@ -126,9 +127,12 @@ export function siem(kibana: any) {
init(server: Server) {
const newPlatform = ((server as unknown) as KbnServer).newPlatform;
if (server.plugins.alerting != null) {
server.plugins.alerting.setup.registerType(
signalsAlertType({ logger: newPlatform.coreContext.logger.get('plugins', APP_ID) })
);
const type = signalsAlertType({
logger: newPlatform.coreContext.logger.get('plugins', APP_ID),
});
if (isAlertExecutor(type)) {
server.plugins.alerting.setup.registerType(type);
}
}
server.injectUiAppVars('siem', async () => server.getInjectedUiAppVars('kibana'));
initServerWithKibana(server);
Expand Down
114 changes: 114 additions & 0 deletions x-pack/legacy/plugins/siem/scripts/convert_saved_search_to_signals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* 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.
*/

require('../../../../../src/setup_node_env');

const fs = require('fs');
const path = require('path');

/*
* This script is used to parse a set of saved searches on a file system
* and output signal data compatible json files.
* Example:
* node saved_query_to_signals.js ${HOME}/saved_searches ${HOME}/saved_signals
*
* After editing any changes in the files of ${HOME}/saved_signals/*.json
* you can then post the signals with a CURL post script such as:
*
* ./post_signal.sh ${HOME}/saved_signals/*.json
*
* Note: This script is recursive and but does not preserve folder structure
* when it outputs the saved signals.
*/

// Defaults of the outputted signals since the saved KQL searches do not have
// this type of information. You usually will want to make any hand edits after
// doing a search to KQL conversion before posting it as a signal or checking it
// into another repository.
const INTERVAL = '24h';
const SEVERITY = 1;
const TYPE = 'kql';
const FROM = 'now-24h';
const TO = 'now';
const INDEX = ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'];

const walk = dir => {
const list = fs.readdirSync(dir);
return list.reduce((accum, file) => {
const fileWithDir = dir + '/' + file;
const stat = fs.statSync(fileWithDir);
if (stat && stat.isDirectory()) {
return [...accum, ...walk(fileWithDir)];
} else {
return [...accum, fileWithDir];
}
}, []);
};

//clean up the file system characters
const cleanupFileName = file => {
return path
.basename(file, path.extname(file))
.replace(/\s+/g, '_')
.replace(/,/g, '')
.replace(/\+s/g, '')
.replace(/-/g, '')
.replace(/__/g, '_')
.toLowerCase();
};

async function main() {
if (process.argv.length !== 4) {
throw new Error(
'usage: saved_query_to_signals [input directory with saved searches] [output directory]'
);
}

const files = process.argv[2];
const outputDir = process.argv[3];

const savedSearchesJson = walk(files).filter(file => file.endsWith('.ndjson'));

const savedSearchesParsed = savedSearchesJson.reduce((accum, json) => {
const jsonFile = fs.readFileSync(json, 'utf8');
try {
const parsedFile = JSON.parse(jsonFile);
parsedFile._file = json;
parsedFile.attributes.kibanaSavedObjectMeta.searchSourceJSON = JSON.parse(
parsedFile.attributes.kibanaSavedObjectMeta.searchSourceJSON
);
return [...accum, parsedFile];
} catch (err) {
return accum;
}
}, []);

savedSearchesParsed.forEach(savedSearch => {
const fileToWrite = cleanupFileName(savedSearch._file);

const query = savedSearch.attributes.kibanaSavedObjectMeta.searchSourceJSON.query.query;
if (query != null && query.trim() !== '') {
const outputMessage = {
id: fileToWrite,
description: savedSearch.attributes.description || savedSearch.attributes.title,
index: INDEX,
interval: INTERVAL,
name: savedSearch.attributes.title,
severity: SEVERITY,
type: TYPE,
from: FROM,
to: TO,
kql: savedSearch.attributes.kibanaSavedObjectMeta.searchSourceJSON.query.query,
};

fs.writeFileSync(`${outputDir}/${fileToWrite}.json`, JSON.stringify(outputMessage, null, 2));
}
});
}

if (require.main === module) {
main();
}
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/siem/server/kibana.index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { createSignalsRoute } from './lib/detection_engine/routes/create_signals
import { readSignalsRoute } from './lib/detection_engine/routes/read_signals_route';
import { findSignalsRoute } from './lib/detection_engine/routes/find_signals_route';
import { deleteSignalsRoute } from './lib/detection_engine/routes/delete_signals_route';
import { updateSignalsRoute } from './lib/detection_engine/routes/updated_signals_route';
import { updateSignalsRoute } from './lib/detection_engine/routes/update_signals_route';

const APP_ID = 'siem';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';

interface BuildEventsScrollQuery {
index: string[];
from: number;
to: number;
from: string;
to: string;
kql: string | undefined;
filter: Record<string, {}> | undefined;
size: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
interface BuildEventsReIndexParams {
description: string;
index: string[];
from: number;
to: number;
from: string;
to: string;
signalsIndex: string;
maxDocs: number;
maxDocs: string;
filter: Record<string, {}> | undefined;
kql: string | undefined;
severity: number;
Expand Down

This file was deleted.

Loading