Skip to content

Conversation

@paul-tavares
Copy link
Contributor

Summary

Fixed Trusted Apps API implementation so that the it uses the ExceptionListClient scope to the API request handler context, which reflects the current user doing the API call.

With this in place, the EndpointAppContextService was adjusted and the prior changes that stored the ExceptionListClient from the .start() phase was removed (no longer used)

To Test

  • Login to kibana with a different user that has superuser role
  • issue create api against the Trusted Apps API:
await _core.http.post('/api/endpoint/trusted_apps', {
  body: JSON.stringify({
    name: 'new exception by user paul',
    os: 'windows',
    entries: [{ field: 'path', operator: 'included', type: 'match', value: 'one/two' }],
  }),
});
  • Retrieve the list of Trusted Apps items and note the value for created_by:
await _core.http.get('/api/endpoint/trusted_apps', { query: { page: 1 }})
{
  'data': [
    {
      'entries': [{ 'field': 'path', 'operator': 'included', 'type': 'match', 'value': 'one/two' }],
      'description': '',
      'created_at': '2020-09-02T18:51:45.797Z',
      'created_by': 'paul',
      'name': 'new exception by user paul',
      'os': 'windows',
      'id': '597efa60-ed4d-11ea-bad0-f3148524f4b0',
    }
  ], 'total': 1, 'page': 1, 'per_page': 20,
};

…ed-apps-create_by

# Conflicts:
#	x-pack/plugins/security_solution/server/endpoint/routes/trusted_apps/handlers.ts
#	x-pack/plugins/security_solution/server/endpoint/routes/trusted_apps/trusted_apps.test.ts
@paul-tavares paul-tavares added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes Team:Endpoint Management Feature:Endpoint Elastic Endpoint feature v7.10.0 labels Sep 2, 2020
@paul-tavares paul-tavares requested review from a team as code owners September 2, 2020 19:23
@paul-tavares paul-tavares self-assigned this Sep 2, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/endpoint-management (Team:Endpoint Management)

@elasticmachine
Copy link
Contributor

Pinging @elastic/endpoint-app-team (Feature:Endpoint)

import { getExceptionListItemSchemaMock } from '../../../../../lists/common/schemas/response/exception_list_item_schema.mock';

type RequestHandlerContextWithLists = ReturnType<typeof xpackMocks.createRequestHandlerContext> & {
lists?: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@madirey , @FrankHassanabad ,
I would like to define this lists type here by referencing a Type in Lists plugin. You currently have this type defined in server/types.ts:

export type ContextProviderReturn = Promise<{
getListClient: () => ListClient;
getExceptionListClient: () => ExceptionListClient;
}>;

Would you be ok if I break out the object that this Promise<> wraps into a separate interface so that I can reference it? so it would be something like:

export interface ListsRequestHandlerContext {
  getListClient: () => ListClient;
  getExceptionListClient: () => ExceptionListClient;
}

export type ContextProviderReturn = Promise<ListsRequestHandlerContext>;

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fine with me, but I'd get @FrankHassanabad or @yctercero to sign off...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback @madirey :)

If @FrankHassanabad does get some time to comment here 😬 , I have also been wondering the following:
I see that the context provided by Kibana server to each route handler some how "knows" about the lists namespace in it although the RequestHandler<> generic type does not have a way to set it. Is it because of this definition in the server/types:

declare module 'src/core/server' {
interface RequestHandlerContext {
lists?: {
getExceptionListClient: () => ExceptionListClient;
getListClient: () => ListClient;
};
}
}

@kevinlog
Copy link
Contributor

kevinlog commented Sep 3, 2020

👍 from me, but would like @madirey or @FrankHassanabad to also take a look

Copy link
Member

@pzl pzl left a comment

Choose a reason for hiding this comment

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

lgtm

@paul-tavares
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

✅ unchanged

History

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

@paul-tavares paul-tavares merged commit bb2aa42 into elastic:master Sep 8, 2020
@paul-tavares paul-tavares deleted the fix/EMT-197-trusted-apps-create_by branch September 8, 2020 19:48
paul-tavares added a commit to paul-tavares/kibana that referenced this pull request Sep 8, 2020
…e api to reflect current logged in user (elastic#76557)

* Fix: use exceptionLists client from route handler context
* Adjust test to use `listMock`
* Remove exceptionListClient service from `EndpointAppContextService`
* Added UT for Trusted Apps to validate that ExceptionListClient from context is used

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
paul-tavares added a commit that referenced this pull request Sep 9, 2020
…e api to reflect current logged in user (#76557) (#76974)

* Fix: use exceptionLists client from route handler context
* Adjust test to use `listMock`
* Remove exceptionListClient service from `EndpointAppContextService`
* Added UT for Trusted Apps to validate that ExceptionListClient from context is used

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

Feature:Endpoint Elastic Endpoint feature release_note:skip Skip the PR/issue when compiling release notes v7.10.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants