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_Solution][Endpoint] Leveraging msearch and ancestry array for resolver #70134

Merged
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1f0e448
Refactor generator for ancestry support
jonathan-buttner Jun 26, 2020
f0ee76a
Adding optional ancestry array
jonathan-buttner Jun 26, 2020
c95132f
Refactor the pagination since the totals are not used anymore
jonathan-buttner Jun 26, 2020
e4b8a13
Updating the queries to not use aggregations for determining the totals
jonathan-buttner Jun 26, 2020
407db62
Refactoring the children helper to handle pagination without totals
jonathan-buttner Jun 26, 2020
8947b43
Pinning the seed for the resolver tree generator service
jonathan-buttner Jun 26, 2020
1287379
Splitting the fetcher into multiple classes for msearch
jonathan-buttner Jun 26, 2020
54f1a3f
Updating tests and api for ancestry array and msearch
jonathan-buttner Jun 26, 2020
92005dd
Adding more comments and fixing type errors
jonathan-buttner Jun 26, 2020
6cdf961
Fixing resolver test import
jonathan-buttner Jun 26, 2020
40f5537
Fixing tests and type errors
jonathan-buttner Jun 29, 2020
f54a462
Fixing merge conflicts
jonathan-buttner Jun 29, 2020
1eac63f
Fixing type errors and tests
jonathan-buttner Jun 29, 2020
79464ed
Merge branch 'master' of github.com:elastic/kibana into msearch-ances…
jonathan-buttner Jun 29, 2020
5a872da
Merge branch 'master' of github.com:elastic/kibana into generator-ref…
jonathan-buttner Jun 29, 2020
99acb58
Removing useAncestry field
jonathan-buttner Jun 29, 2020
3f9f3eb
Fixing test
jonathan-buttner Jun 29, 2020
e75f7bf
Merge branch 'generator-refactor' into msearch-ancestry-array
jonathan-buttner Jun 29, 2020
caa8f8f
Removing useAncestry field from tests
jonathan-buttner Jun 29, 2020
544e1f3
An empty array will be returned because that's how ES will do it too
jonathan-buttner Jun 29, 2020
c99773b
Merge branch 'generator-refactor' into msearch-ancestry-array
jonathan-buttner Jun 29, 2020
d274a07
Resolving conflicts
jonathan-buttner Jun 29, 2020
200ce25
Resolving conflicts
jonathan-buttner Jul 1, 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
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,30 @@ describe('data generator', () => {
expect(processEvent.process.name).not.toBeNull();
});

describe('creates events with an empty ancestry array', () => {
let tree: Tree;
beforeEach(() => {
tree = generator.generateTree({
alwaysGenMaxChildrenPerNode: true,
ancestors: 3,
children: 3,
generations: 3,
percentTerminated: 100,
percentWithRelated: 100,
relatedEvents: 0,
relatedAlerts: 0,
ancestryArraySize: 0,
});
tree.ancestry.delete(tree.origin.id);
});

it('creates all events with an empty ancestry array', () => {
for (const event of tree.allEvents) {
expect(event.process.Ext.ancestry.length).toEqual(0);
}
});
});

describe('creates an origin alert when no related alerts are requested', () => {
let tree: Tree;
beforeEach(() => {
Expand All @@ -113,6 +137,7 @@ describe('data generator', () => {
percentWithRelated: 100,
relatedEvents: 0,
relatedAlerts: 0,
ancestryArraySize: ANCESTRY_LIMIT,
});
tree.ancestry.delete(tree.origin.id);
});
Expand Down Expand Up @@ -150,6 +175,7 @@ describe('data generator', () => {
{ category: RelatedEventCategory.Network, count: 1 },
],
relatedAlerts,
ancestryArraySize: ANCESTRY_LIMIT,
});
});

Expand All @@ -162,29 +188,46 @@ describe('data generator', () => {
};

const verifyAncestry = (event: Event, genTree: Tree) => {
if (event.process.Ext.ancestry.length > 0) {
expect(event.process.parent?.entity_id).toBe(event.process.Ext.ancestry[0]);
if (event.process.Ext.ancestry!.length > 0) {
expect(event.process.parent?.entity_id).toBe(event.process.Ext.ancestry![0]);
}
for (let i = 0; i < event.process.Ext.ancestry.length; i++) {
const ancestor = event.process.Ext.ancestry[i];
for (let i = 0; i < event.process.Ext.ancestry!.length; i++) {
const ancestor = event.process.Ext.ancestry![i];
const parent = genTree.children.get(ancestor) || genTree.ancestry.get(ancestor);
expect(ancestor).toBe(parent?.lifecycle[0].process.entity_id);

// the next ancestor should be the grandparent
if (i + 1 < event.process.Ext.ancestry.length) {
const grandparent = event.process.Ext.ancestry[i + 1];
if (i + 1 < event.process.Ext.ancestry!.length) {
const grandparent = event.process.Ext.ancestry![i + 1];
expect(grandparent).toBe(parent?.lifecycle[0].process.parent?.entity_id);
}
}
};

it('has ancestry array defined', () => {
expect(tree.origin.lifecycle[0].process.Ext.ancestry.length).toBe(ANCESTRY_LIMIT);
expect(tree.origin.lifecycle[0].process.Ext.ancestry!.length).toBe(ANCESTRY_LIMIT);
for (const event of tree.allEvents) {
verifyAncestry(event, tree);
}
});

it('creates the right number childrenLevels', () => {
let totalChildren = 0;
for (const level of tree.childrenLevels) {
totalChildren += level.size;
}
expect(totalChildren).toEqual(tree.children.size);
expect(tree.childrenLevels.length).toEqual(generations);
});

it('has the right nodes in both the childrenLevels and children map', () => {
for (const level of tree.childrenLevels) {
for (const node of level.values()) {
expect(tree.children.get(node.id)).toEqual(node);
}
}
});

it('has the right related events for each node', () => {
const checkRelatedEvents = (node: TreeNode) => {
expect(node.relatedEvents.length).toEqual(4);
Expand Down Expand Up @@ -290,7 +333,11 @@ describe('data generator', () => {
let events: Event[];

beforeEach(() => {
events = generator.createAlertEventAncestry(3, 0, 0, 0, 0);
events = generator.createAlertEventAncestry({
ancestors: 3,
percentTerminated: 0,
percentWithRelated: 0,
});
});

it('with n-1 process events', () => {
Expand Down Expand Up @@ -375,7 +422,7 @@ describe('data generator', () => {
const timestamp = new Date().getTime();
const root = generator.generateEvent({ timestamp });
const generations = 2;
const events = [root, ...generator.descendantsTreeGenerator(root, generations)];
const events = [root, ...generator.descendantsTreeGenerator(root, { generations })];
const rootNode = buildResolverTree(events);
const visitedEvents = countResolverEvents(rootNode, generations);
expect(visitedEvents).toEqual(events.length);
Expand Down
Loading