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

[7.x] [SIEM][Detection Engine] Adds signal to ECS event.kind and fixes status in signals (#51772) #51786

Merged
merged 1 commit into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SignalSourceHit, SignalSearchResponse, RuleTypeParams } from '../types';
import {
SignalSourceHit,
SignalSearchResponse,
RuleTypeParams,
OutputRuleAlertRest,
} from '../types';

export const sampleRuleAlertParams = (
maxSignals: number | undefined,
maxSignals?: number | undefined,
riskScore?: number | undefined
): RuleTypeParams => ({
ruleId: 'rule-1',
Expand All @@ -32,7 +37,7 @@ export const sampleRuleAlertParams = (
meta: undefined,
});

export const sampleDocNoSortId = (someUuid: string): SignalSourceHit => ({
export const sampleDocNoSortId = (someUuid: string = sampleIdGuid): SignalSourceHit => ({
_index: 'myFakeSignalIndex',
_type: 'doc',
_score: 100,
Expand All @@ -44,7 +49,7 @@ export const sampleDocNoSortId = (someUuid: string): SignalSourceHit => ({
},
});

export const sampleDocNoSortIdNoVersion = (someUuid: string): SignalSourceHit => ({
export const sampleDocNoSortIdNoVersion = (someUuid: string = sampleIdGuid): SignalSourceHit => ({
_index: 'myFakeSignalIndex',
_type: 'doc',
_score: 100,
Expand All @@ -55,7 +60,7 @@ export const sampleDocNoSortIdNoVersion = (someUuid: string): SignalSourceHit =>
},
});

export const sampleDocWithSortId = (someUuid: string): SignalSourceHit => ({
export const sampleDocWithSortId = (someUuid: string = sampleIdGuid): SignalSourceHit => ({
_index: 'myFakeSignalIndex',
_type: 'doc',
_score: 100,
Expand Down Expand Up @@ -138,7 +143,9 @@ export const sampleBulkCreateDuplicateResult = {
],
};

export const sampleDocSearchResultsNoSortId = (someUuid: string): SignalSearchResponse => ({
export const sampleDocSearchResultsNoSortId = (
someUuid: string = sampleIdGuid
): SignalSearchResponse => ({
took: 10,
timed_out: false,
_shards: {
Expand All @@ -159,7 +166,7 @@ export const sampleDocSearchResultsNoSortId = (someUuid: string): SignalSearchRe
});

export const sampleDocSearchResultsNoSortIdNoVersion = (
someUuid: string
someUuid: string = sampleIdGuid
): SignalSearchResponse => ({
took: 10,
timed_out: false,
Expand All @@ -180,7 +187,9 @@ export const sampleDocSearchResultsNoSortIdNoVersion = (
},
});

export const sampleDocSearchResultsNoSortIdNoHits = (someUuid: string): SignalSearchResponse => ({
export const sampleDocSearchResultsNoSortIdNoHits = (
someUuid: string = sampleIdGuid
): SignalSearchResponse => ({
took: 10,
timed_out: false,
_shards: {
Expand Down Expand Up @@ -222,7 +231,9 @@ export const repeatedSearchResultsWithSortId = (
},
});

export const sampleDocSearchResultsWithSortId = (someUuid: string): SignalSearchResponse => ({
export const sampleDocSearchResultsWithSortId = (
someUuid: string = sampleIdGuid
): SignalSearchResponse => ({
took: 10,
timed_out: false,
_shards: {
Expand All @@ -243,3 +254,31 @@ export const sampleDocSearchResultsWithSortId = (someUuid: string): SignalSearch
});

export const sampleRuleGuid = '04128c15-0d1b-4716-a4c5-46997ac7f3bd';
export const sampleIdGuid = 'e1e08ddc-5e37-49ff-a258-5393aa44435a';

export const sampleRule = (): Partial<OutputRuleAlertRest> => {
return {
created_by: 'elastic',
description: 'Detecting root and admin users',
enabled: true,
false_positives: [],
from: 'now-6m',
id: '04128c15-0d1b-4716-a4c5-46997ac7f3bd',
immutable: false,
index: ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'],
interval: '5m',
risk_score: 50,
rule_id: 'rule-1',
language: 'kuery',
max_signals: 100,
name: 'Detect Root/Admin Users',
output_index: '.siem-signals',
query: 'user.name: root or user.name: admin',
references: ['http://www.example.com', 'https://ww.example.com'],
severity: 'high',
updated_by: 'elastic',
tags: [],
to: 'now',
type: 'query',
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { getQueryFilter, getFilter } from './get_filter';
import { savedObjectsClientMock } from 'src/core/server/mocks';
import { AlertServices } from '../../../../../alerting/server/types';
import { PartialFilter } from './types';

describe('get_filter', () => {
let savedObjectsClient = savedObjectsClientMock.create();
Expand Down Expand Up @@ -145,6 +146,103 @@ describe('get_filter', () => {
});
});

test('it should work with a simple filter as a kuery without meta information', () => {
const esQuery = getQueryFilter(
'host.name: windows',
'kuery',
[
{
query: {
match_phrase: {
'host.name': 'siem-windows',
},
},
},
],
['auditbeat-*']
);
expect(esQuery).toEqual({
bool: {
must: [],
filter: [
{
bool: {
should: [
{
match: {
'host.name': 'windows',
},
},
],
minimum_should_match: 1,
},
},
{
match_phrase: {
'host.name': 'siem-windows',
},
},
],
should: [],
must_not: [],
},
});
});

test('it should work with a simple filter as a kuery without meta information with an exists', () => {
const query: PartialFilter = {
query: {
match_phrase: {
'host.name': 'siem-windows',
},
},
} as PartialFilter;

const exists: PartialFilter = {
exists: {
field: 'host.hostname',
},
} as PartialFilter;

const esQuery = getQueryFilter(
'host.name: windows',
'kuery',
[query, exists],
['auditbeat-*']
);
expect(esQuery).toEqual({
bool: {
must: [],
filter: [
{
bool: {
should: [
{
match: {
'host.name': 'windows',
},
},
],
minimum_should_match: 1,
},
},
{
match_phrase: {
'host.name': 'siem-windows',
},
},
{
exists: {
field: 'host.hostname',
},
},
],
should: [],
must_not: [],
},
});
});

test('it should work with a simple filter that is disabled as a kuery', () => {
const esQuery = getQueryFilter(
'host.name: windows',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ export type OutputRuleAlertRest = RuleAlertParamsRest & {
updated_by: string | undefined | null;
};

export type OutputRuleES = OutputRuleAlertRest & {
status: 'open' | 'closed';
};

export type UpdateRuleAlertParamsRest = Partial<RuleAlertParamsRest> & {
id: string | undefined;
rule_id: RuleAlertParams['ruleId'] | undefined;
Expand Down
Loading