-
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] host isolation exceptions add and edit exceptions…
… by policy (#119828)
- Loading branch information
Showing
16 changed files
with
569 additions
and
159 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...gement/components/artifact_entry_card/hooks/use_endpoint_policies_to_artifact_policies.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,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 = ( | ||
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]); | ||
}; |
75 changes: 75 additions & 0 deletions
75
...ck/plugins/security_solution/public/management/components/effected_policy_select/utils.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,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( | ||
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]; | ||
const foundPolicy = policies.find((policy) => policy.id === id); | ||
if (foundPolicy !== undefined) { | ||
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; | ||
} |
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.