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

[7.x] [Security Solution][Endpoint][Host Isolation] Fixes bug where host isolation/unisolation works from alert details (#102581) #102649

Merged
merged 1 commit into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -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 };
};