-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Endpoint] Add host isolation action to the endpoi…
…nt list (#100240) * Refactor TableRowAction into separate component and enable menu close on item click * add `show=isolate` to valid url param string for details panel * Reusable BackToEndpointDetailsFlyoutSubHeader component * new FlyoutBodyNoTopPadding compoent + refactor Policy response to use it * Endpoint Isolate flyout panel * New Service for doing isolate/unisolate of hosts * Refactor detection isolate API call to use common method from new service
- Loading branch information
1 parent
21820e9
commit 093044f
Showing
26 changed files
with
1,031 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
x-pack/plugins/security_solution/public/common/lib/host_isolation/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { KibanaServices } from '../kibana'; | ||
import { coreMock } from '../../../../../../../src/core/public/mocks'; | ||
import { isolateHost, unIsolateHost } from './index'; | ||
import { ISOLATE_HOST_ROUTE, UNISOLATE_HOST_ROUTE } from '../../../../common/endpoint/constants'; | ||
import { hostIsolationRequestBodyMock } from './mocks'; | ||
|
||
jest.mock('../kibana'); | ||
|
||
describe('When using Host Isolation library', () => { | ||
const mockKibanaServices = KibanaServices.get as jest.Mock; | ||
|
||
beforeEach(() => { | ||
mockKibanaServices.mockReturnValue(coreMock.createStart({ basePath: '/mock' })); | ||
}); | ||
|
||
it('should send an isolate POST request', async () => { | ||
const requestBody = hostIsolationRequestBodyMock(); | ||
await isolateHost(requestBody); | ||
|
||
expect(mockKibanaServices().http.post).toHaveBeenCalledWith(ISOLATE_HOST_ROUTE, { | ||
body: JSON.stringify(requestBody), | ||
}); | ||
}); | ||
|
||
it('should send an un-isolate POST request', async () => { | ||
const requestBody = hostIsolationRequestBodyMock(); | ||
await unIsolateHost(requestBody); | ||
|
||
expect(mockKibanaServices().http.post).toHaveBeenCalledWith(UNISOLATE_HOST_ROUTE, { | ||
body: JSON.stringify(requestBody), | ||
}); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
x-pack/plugins/security_solution/public/common/lib/host_isolation/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { HostIsolationRequestBody, HostIsolationResponse } from '../../../../common/endpoint/types'; | ||
import { KibanaServices } from '../kibana'; | ||
import { ISOLATE_HOST_ROUTE, UNISOLATE_HOST_ROUTE } from '../../../../common/endpoint/constants'; | ||
|
||
/** Isolates a Host running either elastic endpoint or fleet agent */ | ||
export const isolateHost = async ( | ||
params: HostIsolationRequestBody | ||
): Promise<HostIsolationResponse> => { | ||
return KibanaServices.get().http.post<HostIsolationResponse>(ISOLATE_HOST_ROUTE, { | ||
body: JSON.stringify(params), | ||
}); | ||
}; | ||
|
||
/** Un-isolates a Host running either elastic endpoint or fleet agent */ | ||
export const unIsolateHost = async ( | ||
params: HostIsolationRequestBody | ||
): Promise<HostIsolationResponse> => { | ||
return KibanaServices.get().http.post<HostIsolationResponse>(UNISOLATE_HOST_ROUTE, { | ||
body: JSON.stringify(params), | ||
}); | ||
}; |
49 changes: 49 additions & 0 deletions
49
x-pack/plugins/security_solution/public/common/lib/host_isolation/mocks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { HostIsolationRequestBody, HostIsolationResponse } from '../../../../common/endpoint/types'; | ||
import { | ||
httpHandlerMockFactory, | ||
ResponseProvidersInterface, | ||
} from '../../mock/endpoint/http_handler_mock_factory'; | ||
import { ISOLATE_HOST_ROUTE, UNISOLATE_HOST_ROUTE } from '../../../../common/endpoint/constants'; | ||
|
||
export const hostIsolationRequestBodyMock = (): HostIsolationRequestBody => { | ||
return { | ||
agent_ids: ['fd8a122b-4c54-4c05-b295-111'], | ||
endpoint_ids: ['88c04a90-b19c-11eb-b838-222'], | ||
alert_ids: ['88c04a90-b19c-11eb-b838-333'], | ||
case_ids: ['88c04a90-b19c-11eb-b838-444'], | ||
comment: 'Lock it', | ||
}; | ||
}; | ||
|
||
export const hostIsolationResponseMock = (): HostIsolationResponse => { | ||
return { | ||
action: '111-222-333-444', | ||
}; | ||
}; | ||
|
||
export type HostIsolationHttpMockProviders = ResponseProvidersInterface<{ | ||
isolateHost: () => HostIsolationResponse; | ||
unIsolateHost: () => HostIsolationResponse; | ||
}>; | ||
|
||
export const hostIsolationHttpMocks = httpHandlerMockFactory<HostIsolationHttpMockProviders>([ | ||
{ | ||
id: 'isolateHost', | ||
method: 'post', | ||
path: ISOLATE_HOST_ROUTE, | ||
handler: () => hostIsolationResponseMock(), | ||
}, | ||
{ | ||
id: 'unIsolateHost', | ||
method: 'post', | ||
path: UNISOLATE_HOST_ROUTE, | ||
handler: () => hostIsolationResponseMock(), | ||
}, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.