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] Create new events api #78326

Merged
merged 8 commits into from
Sep 24, 2020

Conversation

jonathan-buttner
Copy link
Contributor

This PR creates a new /resolver/events api that is not tied to an entity_id. Instead it can take a filter as a kql string to filter the results from ES. This will allow a request to retrieve events for a specific entity_id, event.id, or any other kql filter.

Once the frontend is switched over to use this route the older resolver/{id}/events route will be removed.

@jonathan-buttner jonathan-buttner added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes Team:Endpoint Data Visibility Team managing the endpoint resolver v7.10.0 labels Sep 23, 2020
await esArchiver.unload('endpoint/resolver/api_feature');
});
describe('event routes', () => {
describe('related events route', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look worse than they are. This block was wrapped in the above describe block and intended.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*indented

expect(body.events).be.empty();
expect(body.entityID).to.eql(entityID);
expect(body.nextEvent).to.eql(null);
describe('endpoint events', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, wrapped in the outer describe block and indented.

.expect(200);
expect(body.entityID).to.eql(entityID);
expect(body.nextEvent).to.eql(null);
describe('kql events route', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all new. Once the frontend is switched over to use this route the above tests will be removed.

@@ -0,0 +1,89 @@
/*
Copy link
Contributor Author

@jonathan-buttner jonathan-buttner Sep 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was really a move: event.ts -> related_events.ts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The files moved to their related_events.ts counterparts are essentially deprecated right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct. I wanted the events.ts file to have the new implementation since that name seemed most appropriate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, good to know. Thanks. We can probably @deprecated these files

@@ -4,86 +4,59 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { SearchResponse } from 'elasticsearch';
import { IScopedClusterClient } from 'kibana/server';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really a new file for the new /resolver/events route. It does not use the base class like the other queries that are tied to a particular entity_id.

): RequestHandler<
TypeOf<typeof validateEvents.params>,
unknown,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No params are used for the new events route.

@@ -0,0 +1,41 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was a move from resolver/events -> resolver/related_events

.set('kbn-xsrf', 'xxx')
.send({
filter: `event.id:"${tree.origin.relatedEvents[0]?.event?.id}"`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get a specific event using the event.id field.

{
term: { 'agent.id': endpointID },
},
...kqlQuery,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we prefer that this new /events route filters out event.category:process like the previous route or includes them by default and leaves it up to the passed in kql filter to do it?

In the current state, to find non-process events for a specific entity_id we'd pass something like this: process.entity_id:"1234" and not event.category:"process" as the filter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this. Better to surface everything and let the filtering logic be decided on the front end

@jonathan-buttner jonathan-buttner marked this pull request as ready for review September 23, 2020 17:57
@elasticmachine
Copy link
Contributor

Pinging @elastic/endpoint-data-visibility-team (Team:Endpoint Data Visibility)


export function registerResolverRoutes(router: IRouter, endpointAppContext: EndpointAppContext) {
const log = endpointAppContext.logFactory.get('resolver');

// this route will be removed in favor of the one below
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just tag all these as @deprecated. Easier to do a find all and remove later on

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good call 👍

@@ -276,6 +276,14 @@ export interface SafeResolverRelatedEvents {
nextEvent: string | null;
}

/**
* Response structure for the events route.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When nextEvent is null it means there are no more events, right? Maybe should add that to comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'll add it 👍

import { EndpointAppContext } from '../../types';
import { EventsQuery } from './queries/events';
import { createEvents } from './utils/node';
import { PaginationBuilder } from './utils/pagination';

export function handleEvents(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❔ Just noticed this needs a doc comment

@jonathan-buttner
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

distributable file count

id value diff baseline
default 45916 +2 45914

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@bkimmel bkimmel merged commit 8081a85 into elastic:master Sep 24, 2020
@jonathan-buttner jonathan-buttner deleted the refactor-event-api branch September 24, 2020 17:25
jonathan-buttner added a commit to jonathan-buttner/kibana that referenced this pull request Sep 24, 2020
* Creating new events route

* Trying to get github to recognize the indent change

* Using paginated name for events api return type

* Updating comment

* Updating comment

* Adding deprecated comments

* Adding more comments

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
jonathan-buttner added a commit that referenced this pull request Sep 24, 2020
* Creating new events route

* Trying to get github to recognize the indent change

* Using paginated name for events api return type

* Updating comment

* Updating comment

* Adding deprecated comments

* Adding more comments

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:Endpoint Data Visibility Team managing the endpoint resolver v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants