Skip to content

Commit

Permalink
Btsymbala/registered av (#81910) (#83475)
Browse files Browse the repository at this point in the history
* Moved out type for OperatingSystem and moved OS translations one level higher.

* Changed the translation to be consistent between trusted apps and policy.

* Unified translations of OS types between trusted apps and policy.

* Removed unused types.

* Added registered AV form section.

* Changed the property structure to match the format expected by endpoint.

* Fixed the visual alignment of titles in the form and added responsiveness.

* Updated snapshots.

* Moved out type for OperatingSystem and moved OS translations one level higher.

* Added config form heading component.

* Cleaned up translations.

* Fixed type error with initialization.

* Fixed error in trusted app creation form test.

* Removed the guard for now in favour of better initialization.

* Fixed the store test.

* Fixing functional test data.

* Added functional test config option to account for a custom header within security app.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
efreeti and kibanamachine authored Nov 17, 2020
1 parent 03f9837 commit 80e0153
Show file tree
Hide file tree
Showing 29 changed files with 447 additions and 335 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export const factory = (): PolicyConfig => {
logging: {
file: 'info',
},
antivirus_registration: {
enabled: false,
},
},
mac: {
events: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ApplicationStart } from 'kibana/public';
import { NewPackagePolicy, PackagePolicy } from '../../../../fleet/common';
import { ManifestSchema } from '../schema/manifest';

export * from './os';
export * from './trusted_apps';

/**
Expand Down Expand Up @@ -880,6 +881,9 @@ export interface PolicyConfig {
enabled: boolean;
};
};
antivirus_registration: {
enabled: boolean;
};
};
mac: {
advanced?: {};
Expand Down Expand Up @@ -919,7 +923,10 @@ export interface UIPolicyConfig {
/**
* Windows-specific policy configuration that is supported via the UI
*/
windows: Pick<PolicyConfig['windows'], 'events' | 'malware' | 'popup' | 'advanced'>;
windows: Pick<
PolicyConfig['windows'],
'events' | 'malware' | 'popup' | 'antivirus_registration' | 'advanced'
>;
/**
* Mac-specific policy configuration that is supported via the UI
*/
Expand Down
10 changes: 10 additions & 0 deletions x-pack/plugins/security_solution/common/endpoint/types/os.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export type Linux = 'linux';
export type MacOS = 'macos';
export type Windows = 'windows';
export type OperatingSystem = Linux | MacOS | Windows;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
GetTrustedAppsRequestSchema,
PostTrustedAppCreateRequestSchema,
} from '../schema/trusted_apps';
import { Linux, MacOS, Windows } from './os';

/** API request params for deleting Trusted App entry */
export type DeleteTrustedAppsRequestParams = TypeOf<typeof DeleteTrustedAppsRequestSchema.params>;
Expand Down Expand Up @@ -51,11 +52,11 @@ export type NewTrustedApp = {
description?: string;
} & (
| {
os: 'linux' | 'macos';
os: Linux | MacOS;
entries: MacosLinuxConditionEntry[];
}
| {
os: 'windows';
os: Windows;
entries: WindowsConditionEntry[];
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import { i18n } from '@kbn/i18n';

import { OperatingSystem } from '../../../common/endpoint/types';

export const ENDPOINTS_TAB = i18n.translate('xpack.securitySolution.endpointsTab', {
defaultMessage: 'Endpoints',
});
Expand All @@ -21,3 +23,15 @@ export const TRUSTED_APPS_TAB = i18n.translate('xpack.securitySolution.trustedAp
export const BETA_BADGE_LABEL = i18n.translate('xpack.securitySolution.administration.list.beta', {
defaultMessage: 'Beta',
});

export const OS_TITLES: Readonly<{ [K in OperatingSystem]: string }> = {
windows: i18n.translate('xpack.securitySolution.administration.os.windows', {
defaultMessage: 'Windows',
}),
macos: i18n.translate('xpack.securitySolution.administration.os.macos', {
defaultMessage: 'Mac',
}),
linux: i18n.translate('xpack.securitySolution.administration.os.linux', {
defaultMessage: 'Linux',
}),
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ interface UserChangedPolicyConfig {
};
}

interface UserChangedAntivirusRegistration {
type: 'userChangedAntivirusRegistration';
payload: {
enabled: boolean;
};
}

interface ServerReturnedPolicyDetailsAgentSummaryData {
type: 'serverReturnedPolicyDetailsAgentSummaryData';
payload: {
Expand Down Expand Up @@ -62,4 +69,5 @@ export type PolicyDetailsAction =
| ServerReturnedPolicyDetailsUpdateFailure
| ServerReturnedUpdatedPolicyDetailsData
| ServerFailedToReturnPolicyDetailsData
| UserChangedPolicyConfig;
| UserChangedPolicyConfig
| UserChangedAntivirusRegistration;
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ describe('policy details: ', () => {
},
},
logging: { file: 'info' },
antivirus_registration: {
enabled: false,
},
},
mac: {
events: { process: true, file: true, network: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,33 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { fullPolicy, isOnPolicyDetailsPage } from './selectors';
import { Immutable, PolicyConfig, UIPolicyConfig } from '../../../../../../common/endpoint/types';
import {
Immutable,
PolicyConfig,
UIPolicyConfig,
PolicyData,
} from '../../../../../../common/endpoint/types';
import { ImmutableReducer } from '../../../../../common/store';
import { AppAction } from '../../../../../common/store/actions';
import { PolicyDetailsState } from '../../types';

const updatePolicyConfigInPolicyData = (
policyData: Immutable<PolicyData>,
policyConfig: Immutable<PolicyConfig>
) => ({
...policyData,
inputs: policyData.inputs.map((input) => ({
...input,
config: input.config && {
...input.config,
policy: {
...input.config.policy,
value: policyConfig,
},
},
})),
});

/**
* Return a fresh copy of initial state, since we mutate state in the reducer.
*/
Expand Down Expand Up @@ -126,5 +148,26 @@ export const policyDetailsReducer: ImmutableReducer<PolicyDetailsState, AppActio
return newState;
}

if (action.type === 'userChangedAntivirusRegistration') {
if (state.policyItem) {
const policyConfig = fullPolicy(state);

return {
...state,
policyItem: updatePolicyConfigInPolicyData(state.policyItem, {
...policyConfig,
windows: {
...policyConfig.windows,
antivirus_registration: {
enabled: action.payload.enabled,
},
},
}),
};
} else {
return state;
}
}

return state;
};
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export const policyConfig: (s: PolicyDetailsState) => UIPolicyConfig = createSel
events: windows.events,
malware: windows.malware,
popup: windows.popup,
antivirus_registration: windows.antivirus_registration,
},
mac: {
advanced: mac.advanced,
Expand All @@ -122,6 +123,10 @@ export const policyConfig: (s: PolicyDetailsState) => UIPolicyConfig = createSel
}
);

export const isAntivirusRegistrationEnabled = createSelector(policyConfig, (uiPolicyConfig) => {
return uiPolicyConfig.windows.antivirus_registration.enabled;
});

/** Returns the total number of possible windows eventing configurations */
export const totalWindowsEvents = (state: PolicyDetailsState): number => {
const config = policyConfig(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,68 +76,6 @@ export interface PolicyListUrlSearchParams {
page_size: number;
}

/**
* Endpoint Policy configuration
*/
export interface PolicyConfig {
windows: {
events: {
dll_and_driver_load: boolean;
dns: boolean;
file: boolean;
network: boolean;
process: boolean;
registry: boolean;
security: boolean;
};
malware: MalwareFields;
logging: {
stdout: string;
file: string;
};
advanced: PolicyConfigAdvancedOptions;
};
mac: {
events: {
file: boolean;
process: boolean;
network: boolean;
};
malware: MalwareFields;
logging: {
stdout: string;
file: string;
};
advanced: PolicyConfigAdvancedOptions;
};
linux: {
events: {
file: boolean;
process: boolean;
network: boolean;
};
logging: {
stdout: string;
file: string;
};
advanced: PolicyConfigAdvancedOptions;
};
}

interface PolicyConfigAdvancedOptions {
elasticsearch: {
indices: {
control: string;
event: string;
logging: string;
};
kernel: {
connect: boolean;
process: boolean;
};
};
}

export enum OS {
windows = 'windows',
mac = 'mac',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import React from 'react';
import { ThemeProvider } from 'styled-components';
import { storiesOf, addDecorator } from '@storybook/react';
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json';
import { EuiCheckbox, EuiSpacer, EuiSwitch, EuiText } from '@elastic/eui';

import { ConfigForm } from '.';

addDecorator((storyFn) => (
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>{storyFn()}</ThemeProvider>
));

storiesOf('PolicyDetails/ConfigForm', module)
.add('One OS', () => {
return (
<ConfigForm type="Type 1" supportedOss={['windows']}>
{'Some content'}
</ConfigForm>
);
})
.add('Multiple OSs', () => {
return (
<ConfigForm type="Type 1" supportedOss={['windows', 'macos', 'linux']}>
{'Some content'}
</ConfigForm>
);
})
.add('Complex content', () => {
return (
<ConfigForm type="Type 1" supportedOss={['macos', 'linux']}>
<EuiText>
{'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore ' +
'et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut ' +
'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum ' +
'dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia ' +
'deserunt mollit anim id est laborum.'}
</EuiText>
<EuiSpacer size="s" />
<EuiSwitch label={'Switch'} checked={true} onChange={() => {}} />
<EuiSpacer size="s" />
<EuiCheckbox id="1" label={'Checkbox 1'} checked={false} onChange={() => {}} />
<EuiCheckbox id="2" label={'Checkbox 2'} checked={true} onChange={() => {}} />
<EuiCheckbox id="3" label={'Checkbox 3'} checked={true} onChange={() => {}} />
</ConfigForm>
);
})
.add('Right corner content', () => {
const toggle = <EuiSwitch label={'Switch'} checked={true} onChange={() => {}} />;

return (
<ConfigForm type="Type 1" supportedOss={['linux']} rightCorner={toggle}>
{'Some content'}
</ConfigForm>
);
});
Loading

0 comments on commit 80e0153

Please sign in to comment.