Skip to content

Commit

Permalink
Task/malware protections (#62326)
Browse files Browse the repository at this point in the history
Malware Protections form for endpoint policy details
  • Loading branch information
parkiino committed Apr 3, 2020
1 parent cb9d263 commit a44b020
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { PolicyConfig } from '../types';
import { PolicyConfig, ProtectionModes } from '../types';

/**
* Generate a new Policy model.
Expand All @@ -19,7 +19,7 @@ export const generatePolicy = (): PolicyConfig => {
network: true,
},
malware: {
mode: 'prevent',
mode: ProtectionModes.prevent,
},
logging: {
stdout: 'debug',
Expand All @@ -44,7 +44,7 @@ export const generatePolicy = (): PolicyConfig => {
process: true,
},
malware: {
mode: 'detect',
mode: ProtectionModes.detect,
},
logging: {
stdout: 'debug',
Expand Down
48 changes: 41 additions & 7 deletions x-pack/plugins/endpoint/public/applications/endpoint/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,8 @@ export interface PolicyConfig {
process: boolean;
network: boolean;
};
/** malware mode can be detect, prevent or prevent and notify user */
malware: {
mode: string;
};
/** malware mode can be off, detect, prevent or prevent and notify user */
malware: MalwareFields;
logging: {
stdout: string;
file: string;
Expand All @@ -137,9 +135,7 @@ export interface PolicyConfig {
events: {
process: boolean;
};
malware: {
mode: string;
};
malware: MalwareFields;
logging: {
stdout: string;
file: string;
Expand Down Expand Up @@ -209,6 +205,44 @@ export enum EventingFields {
network = 'network',
}

/**
* Returns the keys of an object whose values meet a criteria.
* Ex) interface largeNestedObject = {
* a: {
* food: Foods;
* toiletPaper: true;
* };
* b: {
* food: Foods;
* streamingServices: Streams;
* };
* c: {};
* }
*
* type hasFoods = KeysByValueCriteria<largeNestedObject, { food: Foods }>;
* The above type will be: [a, b] only, and will not include c.
*
*/
export type KeysByValueCriteria<O, Criteria> = {
[K in keyof O]: O[K] extends Criteria ? K : never;
}[keyof O];

/** Returns an array of the policy OSes that have a malware protection field */

export type MalwareProtectionOSes = KeysByValueCriteria<UIPolicyConfig, { malware: MalwareFields }>;
/** Policy: Malware protection fields */
export interface MalwareFields {
mode: ProtectionModes;
}

/** Policy protection mode options */
export enum ProtectionModes {
detect = 'detect',
prevent = 'prevent',
preventNotify = 'preventNotify',
off = 'off',
}

export interface GlobalState {
readonly hostList: HostListState;
readonly alertList: AlertListState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { AppAction } from '../../types';
import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public';
import { AgentsSummary } from './agents_summary';
import { VerticalDivider } from './vertical_divider';
import { MalwareProtections } from './policy_forms/protections/malware';

export const PolicyDetails = React.memo(() => {
const dispatch = useDispatch<(action: AppAction) => void>();
Expand Down Expand Up @@ -181,6 +182,17 @@ export const PolicyDetails = React.memo(() => {
headerLeft={headerLeftContent}
headerRight={headerRightContent}
>
<EuiText size="xs" color="subdued">
<h4>
<FormattedMessage
id="xpack.endpoint.policy.details.protections"
defaultMessage="Protections"
/>
</h4>
</EuiText>
<EuiSpacer size="xs" />
<MalwareProtections />
<EuiSpacer size="l" />
<EuiText size="xs" color="subdued">
<h4>
<FormattedMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
EuiFlexItem,
EuiTitle,
EuiHorizontalRule,
EuiSpacer,
EuiText,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
Expand All @@ -30,9 +29,9 @@ export const ConfigForm: React.FC<{
supportedOss: string[];
children: React.ReactNode;
id: string;
selectedEventing: number;
totalEventing: number;
}> = React.memo(({ type, supportedOss, children, id, selectedEventing, totalEventing }) => {
/** Takes a react component to be put on the right corner of the card */
rightCorner: React.ReactNode;
}> = React.memo(({ type, supportedOss, children, id, rightCorner }) => {
const typeTitle = () => {
return (
<EuiFlexGroup direction="row" gutterSize="none" alignItems="center">
Expand Down Expand Up @@ -63,32 +62,11 @@ export const ConfigForm: React.FC<{
<EuiText>{supportedOss.join(', ')}</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiText size="s" color="subdued">
<FormattedMessage
id="xpack.endpoint.policy.details.eventCollectionsEnabled"
defaultMessage="{selectedEventing} / {totalEventing} event collections enabled"
values={{ selectedEventing, totalEventing }}
/>
</EuiText>
</EuiFlexItem>
<EuiFlexItem grow={false}>{rightCorner}</EuiFlexItem>
</EuiFlexGroup>
);
};

const events = () => {
return (
<EuiTitle size="xxs">
<h5>
<FormattedMessage
id="xpack.endpoint.policyDetailsConfig.eventingEvents"
defaultMessage="Events"
/>
</h5>
</EuiTitle>
);
};

return (
<PolicyDetailCard>
<EuiCard
Expand All @@ -99,8 +77,6 @@ export const ConfigForm: React.FC<{
children={
<>
<EuiHorizontalRule margin="m" />
{events()}
<EuiSpacer size="s" />
{children}
</>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import React, { useMemo } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiTitle, EuiText, EuiSpacer } from '@elastic/eui';
import { EventingCheckbox } from './checkbox';
import { OS, EventingFields } from '../../../../types';
import { usePolicyDetailsSelector } from '../../policy_hooks';
Expand All @@ -16,6 +18,9 @@ import {
import { ConfigForm } from '../config_form';

export const WindowsEventing = React.memo(() => {
const selected = usePolicyDetailsSelector(selectedWindowsEventing);
const total = usePolicyDetailsSelector(totalWindowsEventing);

const checkboxes = useMemo(
() => [
{
Expand All @@ -37,21 +42,43 @@ export const WindowsEventing = React.memo(() => {
);

const renderCheckboxes = () => {
return checkboxes.map((item, index) => {
return (
<EventingCheckbox
id={`eventing${item.name}`}
name={item.name}
key={index}
os={item.os}
protectionField={item.protectionField}
/>
);
});
return (
<>
<EuiTitle size="xxs">
<h5>
<FormattedMessage
id="xpack.endpoint.policyDetailsConfig.eventingEvents"
defaultMessage="Events"
/>
</h5>
</EuiTitle>
<EuiSpacer size="s" />
{checkboxes.map((item, index) => {
return (
<EventingCheckbox
id={`eventing${item.name}`}
name={item.name}
key={index}
os={item.os}
protectionField={item.protectionField}
/>
);
})}
</>
);
};

const selected = usePolicyDetailsSelector(selectedWindowsEventing);
const total = usePolicyDetailsSelector(totalWindowsEventing);
const collectionsEnabled = () => {
return (
<EuiText size="s" color="subdued">
<FormattedMessage
id="xpack.endpoint.policy.details.eventCollectionsEnabled"
defaultMessage="{selected} / {total} event collections enabled"
values={{ selected, total }}
/>
</EuiText>
);
};

return (
<ConfigForm
Expand All @@ -62,9 +89,8 @@ export const WindowsEventing = React.memo(() => {
i18n.translate('xpack.endpoint.policy.details.windows', { defaultMessage: 'Windows' }),
]}
id="windowsEventingForm"
rightCorner={collectionsEnabled()}
children={renderCheckboxes()}
selectedEventing={selected}
totalEventing={total}
/>
);
});
Loading

0 comments on commit a44b020

Please sign in to comment.