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] host isolation exceptions add and edit exceptions by policy #119828

Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
904295c
Move effected policies component to common management components
Nov 17, 2021
df52a53
Allow description prop and use fallback generic copy
Nov 17, 2021
67be8ed
Style borders removing radius
Nov 17, 2021
3e4ac9f
Rename variable
Nov 17, 2021
2e1801c
Move policy ingest service to a common service
Nov 17, 2021
4e57894
Revert "Move policy ingest service to a common service"
Nov 18, 2021
e914304
Revert "Move policy ingest service to a common service"
Nov 18, 2021
a5da9b6
Merge remote-tracking branch 'upstream/main' into feature/host-isolat…
Nov 18, 2021
0dd114e
Move query to custom hook
Nov 18, 2021
3f6ee48
Merge remote-tracking branch 'upstream/main' into feature/host-isolat…
Nov 19, 2021
51e98f0
WIP: Add policies to host isolation exceptions
Nov 19, 2021
7aa40e7
Apply policies and submit
Nov 19, 2021
96922e0
Fetch policies inside the form flyout
Nov 19, 2021
0582054
Preserve previous policy selection
Nov 19, 2021
1d41e48
Show error for fetching policies
Nov 19, 2021
0f18595
Improve form render performance
Nov 19, 2021
9772deb
Merge remote-tracking branch 'upstream/main' into feature/host-isolat…
Nov 29, 2021
1cc62cb
Move policies specific hook to its own folder
Nov 29, 2021
de4db40
Fix existing form tests
Nov 29, 2021
9ee5593
Update tests for host isolation exceptions form
Nov 29, 2021
f399c1a
Fix form tests
Nov 29, 2021
985a84f
Move policies service to its own folder
Nov 29, 2021
270f54c
Display the name of policies on the artifact card
Nov 29, 2021
e247c3c
Merge remote-tracking branch 'upstream/main' into feature/host-isolat…
Nov 29, 2021
247948d
Merge remote-tracking branch 'upstream/main' into feature/host-isolat…
Nov 30, 2021
3aa2ef0
Show error if policies can't be loaded
Nov 30, 2021
e89b030
Merge remote-tracking branch 'upstream/main' into feature/host-isolat…
Dec 1, 2021
87aefd3
Use full width for effected policies selector
Dec 1, 2021
42eed2f
Merge remote-tracking branch 'upstream/main' into feature/host-isolat…
Dec 2, 2021
2d63d79
Add documentation
Dec 2, 2021
a24a200
Preserve previous tags
Dec 2, 2021
d1f505a
Remove duplicated logic for isGlobal
Dec 2, 2021
3833571
Merge remote-tracking branch 'upstream/main' into feature/host-isolat…
Dec 4, 2021
8a65219
Remove unused dependency
Dec 4, 2021
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
@@ -0,0 +1,38 @@
/*
* 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 { useMemo } from 'react';
import { MenuItemPropsByPolicyId } from '..';
import { PolicyData } from '../../../../../common/endpoint/types';
import { useAppUrl } from '../../../../common/lib/kibana';
import { getPolicyDetailPath } from '../../../common/routing';

/**
* Takes a list of EndpointPolicies (PolicyData) and turn them
* into MenuItemPropsByPolicyId required by the artifact card.
*
* The resulting menu will open the policies in a new tab
*
*/
export const useEndpointPoliciesToArtifactPolicies = (
academo marked this conversation as resolved.
Show resolved Hide resolved
policies: PolicyData[] = []
): MenuItemPropsByPolicyId => {
const { getAppUrl } = useAppUrl();
return useMemo(() => {
const data = policies.reduce<MenuItemPropsByPolicyId>((policiesMap, policy) => {
const policyId = policy.id;
const policyDetailsPath = getPolicyDetailPath(policyId);
policiesMap[policyId] = {
href: getAppUrl({ path: policyDetailsPath }),
children: policy.name ?? policyId,
target: '_blank',
};
return policiesMap;
}, {});
return data;
}, [getAppUrl, policies]);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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 { PolicyData } from '../../../../common/endpoint/types';
import { EffectedPolicySelection } from './effected_policy_select';

export const GLOBAL_POLICY_TAG = 'policy:all';

/**
* Given a list of artifact tags, returns the tags that are not policy tags
* policy tags follow the format: `policy:id`
*/
export function getArtifactTagsWithoutPolicies(tags?: string[]): string[] {
return tags?.filter((tag) => !tag.startsWith('policy:')) || [];
}

/**
* Return a list of artifact policy tags based on a current
* selection by the EffectedPolicySelection component.
*/
export function getArtifactTagsByEffectedPolicySelection(
academo marked this conversation as resolved.
Show resolved Hide resolved
selection: EffectedPolicySelection,
otherTags: string[] = []
): string[] {
if (selection.isGlobal) {
return [GLOBAL_POLICY_TAG, ...otherTags];
}
const newTags = selection.selected.map((policy) => {
return `policy:${policy.id}`;
});

return newTags.concat(otherTags);
}

/**
* Given a list of an Exception item tags it will return
* the parsed policies from it.
*
* Policy tags follow the pattern `policy:id`
* non policy tags will be ignored.
*/
export function getEffectedPolicySelectionByTags(
tags: string[],
policies: PolicyData[]
): EffectedPolicySelection {
if (tags.length === 0 || tags.find((tag) => tag === GLOBAL_POLICY_TAG)) {
return {
isGlobal: true,
selected: [],
};
}
const selected: PolicyData[] = tags.reduce((acc, tag) => {
// edge case: a left over tag with a non-existed policy
// will be removed by veryfing the policy exists
const id = tag.split(':')[1];
academo marked this conversation as resolved.
Show resolved Hide resolved
const foundPolicy = policies.find((policy) => policy.id === id);
if (foundPolicy !== undefined) {
academo marked this conversation as resolved.
Show resolved Hide resolved
acc.push(foundPolicy);
}
return acc;
}, [] as PolicyData[]);

return {
isGlobal: false,
selected,
};
}

export function isGlobalPolicyEffected(tags?: string[]): boolean {
return tags !== undefined && tags.find((tag) => tag === GLOBAL_POLICY_TAG) !== undefined;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@
* 2.0.
*/

import type { DataViewBase, Query } from '@kbn/es-query';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: all changes are merely re-organize imports and change some paths.

import { CoreStart, HttpStart } from 'kibana/public';
import { Dispatch } from 'redux';
import semverGte from 'semver/functions/gte';

import { CoreStart, HttpStart } from 'kibana/public';
import type { DataViewBase, Query } from '@kbn/es-query';
import { AGENT_POLICY_SAVED_OBJECT_TYPE } from '../../../../../../fleet/common';
import { METADATA_TRANSFORM_STATS_URL } from '../../../../../common/constants';
import {
BASE_POLICY_RESPONSE_ROUTE,
ENDPOINT_ACTION_LOG_ROUTE,
HOST_METADATA_GET_ROUTE,
HOST_METADATA_LIST_ROUTE,
metadataCurrentIndexPattern,
METADATA_UNITED_INDEX,
} from '../../../../../common/endpoint/constants';
import {
ActivityLog,
GetHostPolicyResponse,
Expand All @@ -21,67 +30,57 @@ import {
ImmutableObject,
MetadataListResponse,
} from '../../../../../common/endpoint/types';
import { GetPolicyListResponse } from '../../policy/types';
import { isolateHost, unIsolateHost } from '../../../../common/lib/endpoint_isolation';
import { fetchPendingActionsByAgentId } from '../../../../common/lib/endpoint_pending_actions';
import { ImmutableMiddlewareAPI, ImmutableMiddlewareFactory } from '../../../../common/store';
import { AppAction } from '../../../../common/store/actions';
import { resolvePathVariables } from '../../../../common/utils/resolve_path_variables';
import { sendGetEndpointSpecificPackagePolicies } from '../../../services/policies/policies';
import {
isOnEndpointPage,
hasSelectedEndpoint,
selectedAgent,
uiQueryParams,
listData,
asStaleResourceState,
createFailedResourceState,
createLoadedResourceState,
createLoadingResourceState,
} from '../../../state';
import {
sendGetAgentPolicyList,
sendGetEndpointSecurityPackage,
sendGetFleetAgentsWithEndpoint,
} from '../../policy/store/services/ingest';
import { GetPolicyListResponse } from '../../policy/types';
import {
AgentIdsPendingActions,
EndpointState,
PolicyIds,
TransformStats,
TransformStatsResponse,
} from '../types';
import { getIsInvalidDateRange } from '../utils';
import { EndpointPackageInfoStateChanged } from './action';
import {
detailsData,
endpointPackageInfo,
nonExistingPolicies,
patterns,
searchBarQuery,
getIsIsolationRequestPending,
getCurrentIsolationRequestState,
endpointPackageVersion,
getActivityLogData,
getActivityLogDataPaging,
getLastLoadedActivityLogData,
getActivityLogError,
detailsData,
getActivityLogIsUninitializedOrHasSubsequentAPIError,
getCurrentIsolationRequestState,
getIsEndpointPackageInfoUninitialized,
getIsIsolationRequestPending,
getIsOnEndpointDetailsActivityLog,
getLastLoadedActivityLogData,
getMetadataTransformStats,
hasSelectedEndpoint,
isMetadataTransformStatsLoading,
getActivityLogIsUninitializedOrHasSubsequentAPIError,
endpointPackageVersion,
isOnEndpointPage,
listData,
nonExistingPolicies,
patterns,
searchBarQuery,
selectedAgent,
uiQueryParams,
} from './selectors';
import {
AgentIdsPendingActions,
EndpointState,
PolicyIds,
TransformStats,
TransformStatsResponse,
} from '../types';
import {
sendGetEndpointSecurityPackage,
sendGetAgentPolicyList,
sendGetFleetAgentsWithEndpoint,
} from '../../policy/store/services/ingest';
import { AGENT_POLICY_SAVED_OBJECT_TYPE } from '../../../../../../fleet/common';
import {
ENDPOINT_ACTION_LOG_ROUTE,
HOST_METADATA_GET_ROUTE,
HOST_METADATA_LIST_ROUTE,
BASE_POLICY_RESPONSE_ROUTE,
metadataCurrentIndexPattern,
METADATA_UNITED_INDEX,
} from '../../../../../common/endpoint/constants';
import {
asStaleResourceState,
createFailedResourceState,
createLoadedResourceState,
createLoadingResourceState,
} from '../../../state';
import { isolateHost, unIsolateHost } from '../../../../common/lib/endpoint_isolation';
import { AppAction } from '../../../../common/store/actions';
import { resolvePathVariables } from '../../../../common/utils/resolve_path_variables';
import { EndpointPackageInfoStateChanged } from './action';
import { fetchPendingActionsByAgentId } from '../../../../common/lib/endpoint_pending_actions';
import { getIsInvalidDateRange } from '../utils';
import { METADATA_TRANSFORM_STATS_URL } from '../../../../../common/constants';
import { sendGetEndpointSpecificPackagePolicies } from '../../../services/policies';

type EndpointPageStore = ImmutableMiddlewareAPI<EndpointState, AppAction>;

Expand Down
Loading