Skip to content

Commit

Permalink
[Security Solution][Endpoint][Host Isolation] Fixes bug where host is…
Browse files Browse the repository at this point in the history
…olation/unisolation works from alert details (elastic#102581)
  • Loading branch information
parkiino committed Jun 18, 2021
1 parent 013e6b4 commit 04e6054
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export const HostIsolationPanel = React.memo(
cancelCallback: () => void;
isolateAction: string;
}) => {
const agentId = useMemo(() => {
const findAgentId = find({ category: 'agent', field: 'agent.id' }, details)?.values;
return findAgentId ? findAgentId[0] : '';
const endpointId = useMemo(() => {
const findEndpointId = find({ category: 'agent', field: 'agent.id' }, details)?.values;
return findEndpointId ? findEndpointId[0] : '';
}, [details]);

const hostName = useMemo(() => {
Expand Down Expand Up @@ -87,15 +87,15 @@ export const HostIsolationPanel = React.memo(

return isolateAction === 'isolateHost' ? (
<IsolateHost
agentId={agentId}
endpointId={endpointId}
hostName={hostName}
cases={associatedCases}
caseIds={caseIds}
cancelCallback={cancelCallback}
/>
) : (
<UnisolateHost
agentId={agentId}
endpointId={endpointId}
hostName={hostName}
cases={associatedCases}
caseIds={caseIds}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import {

export const IsolateHost = React.memo(
({
agentId,
endpointId,
hostName,
cases,
caseIds,
cancelCallback,
}: {
agentId: string;
endpointId: string;
hostName: string;
cases: ReactNode;
caseIds: string[];
Expand All @@ -33,7 +33,7 @@ export const IsolateHost = React.memo(
const [comment, setComment] = useState('');
const [isIsolated, setIsIsolated] = useState(false);

const { loading, isolateHost } = useHostIsolation({ agentId, comment, caseIds });
const { loading, isolateHost } = useHostIsolation({ endpointId, comment, caseIds });

const confirmHostIsolation = useCallback(async () => {
const hostIsolated = await isolateHost();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import { useHostUnisolation } from '../../containers/detection_engine/alerts/use

export const UnisolateHost = React.memo(
({
agentId,
endpointId,
hostName,
cases,
caseIds,
cancelCallback,
}: {
agentId: string;
endpointId: string;
hostName: string;
cases: ReactNode;
caseIds: string[];
Expand All @@ -33,7 +33,7 @@ export const UnisolateHost = React.memo(
const [comment, setComment] = useState('');
const [isUnIsolated, setIsUnIsolated] = useState(false);

const { loading, unIsolateHost } = useHostUnisolation({ agentId, comment, caseIds });
const { loading, unIsolateHost } = useHostUnisolation({ endpointId, comment, caseIds });

const confirmHostUnIsolation = useCallback(async () => {
const hostIsolated = await unIsolateHost();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,19 @@ describe('Detections Alerts API', () => {

test('check parameter url', async () => {
await createHostIsolation({
agentId: 'fd8a122b-4c54-4c05-b295-e5f8381fc59d',
endpointId: 'fd8a122b-4c54-4c05-b295-e5f8381fc59d',
comment: 'commento',
caseIds: ['88c04a90-b19c-11eb-b838-bf3c7840b969'],
});
expect(postMock).toHaveBeenCalledWith('/api/endpoint/isolate', {
body:
'{"agent_ids":["fd8a122b-4c54-4c05-b295-e5f8381fc59d"],"comment":"commento","case_ids":["88c04a90-b19c-11eb-b838-bf3c7840b969"]}',
'{"endpoint_ids":["fd8a122b-4c54-4c05-b295-e5f8381fc59d"],"comment":"commento","case_ids":["88c04a90-b19c-11eb-b838-bf3c7840b969"]}',
});
});

test('happy path', async () => {
const hostIsolationResponse = await createHostIsolation({
agentId: 'fd8a122b-4c54-4c05-b295-e5f8381fc59d',
endpointId: 'fd8a122b-4c54-4c05-b295-e5f8381fc59d',
comment: 'commento',
caseIds: ['88c04a90-b19c-11eb-b838-bf3c7840b969'],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@ export const createSignalIndex = async ({ signal }: BasicSignals): Promise<Alert
* @throws An error if response is not OK
*/
export const createHostIsolation = async ({
agentId,
endpointId,
comment = '',
caseIds,
}: {
agentId: string;
endpointId: string;
comment?: string;
caseIds?: string[];
}): Promise<HostIsolationResponse> =>
isolateHost({
agent_ids: [agentId],
endpoint_ids: [endpointId],
comment,
case_ids: caseIds,
});
Expand All @@ -142,16 +142,16 @@ export const createHostIsolation = async ({
* @throws An error if response is not OK
*/
export const createHostUnIsolation = async ({
agentId,
endpointId,
comment = '',
caseIds,
}: {
agentId: string;
endpointId: string;
comment?: string;
caseIds?: string[];
}): Promise<HostIsolationResponse> =>
unIsolateHost({
agent_ids: [agentId],
endpoint_ids: [endpointId],
comment,
case_ids: caseIds,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ interface HostIsolationStatus {
}

interface UseHostIsolationProps {
agentId: string;
endpointId: string;
comment: string;
caseIds?: string[];
}

export const useHostIsolation = ({
agentId,
endpointId,
comment,
caseIds,
}: UseHostIsolationProps): HostIsolationStatus => {
Expand All @@ -32,14 +32,14 @@ export const useHostIsolation = ({
const isolateHost = useCallback(async () => {
try {
setLoading(true);
const isolationStatus = await createHostIsolation({ agentId, comment, caseIds });
const isolationStatus = await createHostIsolation({ endpointId, comment, caseIds });
setLoading(false);
return isolationStatus.action ? true : false;
} catch (error) {
setLoading(false);
addError(error.message, { title: HOST_ISOLATION_FAILURE });
return false;
}
}, [agentId, comment, caseIds, addError]);
}, [endpointId, comment, caseIds, addError]);
return { loading, isolateHost };
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ interface HostUnisolationStatus {
}

interface UseHostIsolationProps {
agentId: string;
endpointId: string;
comment: string;
caseIds?: string[];
}

export const useHostUnisolation = ({
agentId,
endpointId,
comment,
caseIds,
}: UseHostIsolationProps): HostUnisolationStatus => {
Expand All @@ -32,14 +32,14 @@ export const useHostUnisolation = ({
const unIsolateHost = useCallback(async () => {
try {
setLoading(true);
const isolationStatus = await createHostUnIsolation({ agentId, comment, caseIds });
const isolationStatus = await createHostUnIsolation({ endpointId, comment, caseIds });
setLoading(false);
return isolationStatus.action ? true : false;
} catch (error) {
setLoading(false);
addError(error.message, { title: HOST_ISOLATION_FAILURE });
return false;
}
}, [agentId, comment, caseIds, addError]);
}, [endpointId, comment, caseIds, addError]);
return { loading, unIsolateHost };
};

0 comments on commit 04e6054

Please sign in to comment.