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][Endpoint][Admin] Malware user notification checkbox #78084

Merged
merged 20 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from 12 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 @@ -24,6 +24,12 @@ export const factory = (): PolicyConfig => {
malware: {
mode: ProtectionModes.prevent,
},
popup: {
malware: {
message: '',
enabled: true,
},
},
logging: {
file: 'info',
},
Expand All @@ -37,6 +43,12 @@ export const factory = (): PolicyConfig => {
malware: {
mode: ProtectionModes.prevent,
},
popup: {
malware: {
message: '',
enabled: true,
},
},
logging: {
file: 'info',
},
Expand Down
16 changes: 14 additions & 2 deletions x-pack/plugins/security_solution/common/endpoint/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,12 @@ export interface PolicyConfig {
logging: {
file: string;
};
popup: {
malware: {
message: string;
enabled: boolean;
};
};
};
mac: {
events: {
Expand All @@ -866,6 +872,12 @@ export interface PolicyConfig {
network: boolean;
};
malware: MalwareFields;
popup: {
malware: {
message: string;
enabled: boolean;
};
};
logging: {
file: string;
};
Expand All @@ -889,11 +901,11 @@ export interface UIPolicyConfig {
/**
* Windows-specific policy configuration that is supported via the UI
*/
windows: Pick<PolicyConfig['windows'], 'events' | 'malware'>;
windows: Pick<PolicyConfig['windows'], 'events' | 'malware' | 'popup'>;
/**
* Mac-specific policy configuration that is supported via the UI
*/
mac: Pick<PolicyConfig['mac'], 'malware' | 'events'>;
mac: Pick<PolicyConfig['mac'], 'malware' | 'events' | 'popup'>;
/**
* Linux-specific policy configuration that is supported via the UI
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,23 @@ describe('policy details: ', () => {
security: true,
},
malware: { mode: 'prevent' },
popup: {
malware: {
enabled: true,
message: '',
},
},
logging: { file: 'info' },
},
mac: {
events: { process: true, file: true, network: true },
malware: { mode: 'prevent' },
popup: {
malware: {
enabled: true,
message: '',
},
},
logging: { file: 'info' },
},
linux: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ export const policyConfig: (s: PolicyDetailsState) => UIPolicyConfig = createSel
windows: {
events: windows.events,
malware: windows.malware,
popup: windows.popup,
},
mac: {
events: mac.events,
malware: mac.malware,
popup: mac.popup,
},
linux: {
events: linux.events,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
EuiSpacer,
htmlIdGenerator,
EuiCallOut,
EuiCheckbox,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
Expand Down Expand Up @@ -50,6 +51,11 @@ const ProtectionRadio = React.memo(({ id, label }: { id: ProtectionModes; label:
const newPayload = clone(policyDetailsConfig);
for (const os of OSes) {
newPayload[os][protection].mode = id;
if (id === ProtectionModes.prevent) {
newPayload[os].popup[protection].enabled = true;
} else {
newPayload[os].popup[protection].enabled = false;
}
}
dispatch({
type: 'userChangedPolicyConfig',
Expand Down Expand Up @@ -85,6 +91,8 @@ export const MalwareProtections = React.memo(() => {
const dispatch = useDispatch();
// currently just taking windows.malware, but both windows.malware and mac.malware should be the same value
const selected = policyDetailsConfig && policyDetailsConfig.windows.malware.mode;
const userNotificationSelected =
policyDetailsConfig && policyDetailsConfig.windows.popup.malware.enabled;

const radios: Immutable<Array<{
id: ProtectionModes;
Expand Down Expand Up @@ -116,10 +124,12 @@ export const MalwareProtections = React.memo(() => {
if (event.target.checked === false) {
for (const os of OSes) {
newPayload[os][protection].mode = ProtectionModes.off;
newPayload[os].popup[protection].enabled = event.target.checked;
}
} else {
for (const os of OSes) {
newPayload[os][protection].mode = ProtectionModes.prevent;
newPayload[os].popup[protection].enabled = event.target.checked;
}
}
dispatch({
Expand All @@ -131,6 +141,22 @@ export const MalwareProtections = React.memo(() => {
[dispatch, policyDetailsConfig]
);

const handleUserNotificationCheckbox = useCallback(
(event) => {
if (policyDetailsConfig) {
const newPayload = clone(policyDetailsConfig);
for (const os of OSes) {
newPayload[os].popup[protection].enabled = event.target.checked;
}
dispatch({
type: 'userChangedPolicyConfig',
payload: { policyConfig: newPayload },
});
}
},
[policyDetailsConfig, dispatch]
);

const radioButtons = useMemo(() => {
return (
<>
Expand All @@ -154,9 +180,18 @@ export const MalwareProtections = React.memo(() => {
);
})}
</ProtectionRadioGroup>
<EuiCheckbox
id="xpack.securitySolution.endpoint.policyDetail.malware.userNotification"
onChange={handleUserNotificationCheckbox}
checked={userNotificationSelected}
label={i18n.translate(
'xpack.securitySolution.endpoint.policyDetail.malware.userNotification',
{ defaultMessage: 'User Notification' }
)}
/>
</>
);
}, [radios]);
}, [radios, handleUserNotificationCheckbox, userNotificationSelected]);

const protectionSwitch = useMemo(() => {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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 { SavedObjectsType } from '../../../../../../../src/core/server/types';
import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../../../../ingest_manager/common';
import { migratePackagePolicyToV7110 } from './to_v7_11.0';

export const packagePolicyType: SavedObjectsType = {
Copy link
Contributor

Choose a reason for hiding this comment

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

is it a problem that we define this here as well as in Ingest? If it is OK, should we import the mapping, clone it, and add our own migration? What happens if there are 2 migrations for 7.11? One in Ingest and one in Security?

cc @jfsiii @jen-huang

Copy link
Contributor

Choose a reason for hiding this comment

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

judging from the test failures, it certainly looks like this is an issue

https://kibana-ci.elastic.co/job/elastic+kibana+pipeline-pull-request/82038/execution/node/636/log/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmmm so then should i just have the code for the migration in endpoint, but then add our migration line to the one in ingest for package policy saved objects then?

Copy link
Contributor

Choose a reason for hiding this comment

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

hmmm so then should i just have the code for the migration in endpoint, but then add our migration line to the one in ingest for package policy saved objects then?

This seems like what needs to happen. We can't define a duplicate mapping for an existing SO. Unless there's a way that we import the SO mapping from ingest in our app and simply add another migration to it.

name: PACKAGE_POLICY_SAVED_OBJECT_TYPE,
hidden: false,
namespaceType: 'agnostic',
management: {
importableAndExportable: false,
},
mappings: {
properties: {
name: { type: 'keyword' },
description: { type: 'text' },
namespace: { type: 'keyword' },
enabled: { type: 'boolean' },
policy_id: { type: 'keyword' },
output_id: { type: 'keyword' },
package: {
properties: {
name: { type: 'keyword' },
title: { type: 'keyword' },
version: { type: 'keyword' },
},
},
inputs: {
type: 'nested',
enabled: false,
properties: {
type: { type: 'keyword' },
enabled: { type: 'boolean' },
vars: { type: 'flattened' },
config: { type: 'flattened' },
streams: {
type: 'nested',
properties: {
id: { type: 'keyword' },
enabled: { type: 'boolean' },
data_stream: {
properties: {
dataset: { type: 'keyword' },
type: { type: 'keyword' },
},
},
vars: { type: 'flattened' },
config: { type: 'flattened' },
compiled_stream: { type: 'flattened' },
},
},
},
},
revision: { type: 'integer' },
updated_at: { type: 'date' },
updated_by: { type: 'keyword' },
created_at: { type: 'date' },
created_by: { type: 'keyword' },
},
},
migrations: {
'7.11.0': migratePackagePolicyToV7110,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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 { SavedObjectMigrationContext, SavedObjectUnsanitizedDoc } from 'kibana/server';
import { PackagePolicy } from '../../../../../ingest_manager/common';
import { migratePackagePolicyToV7110 } from './to_v7_11.0';

describe('7.11.0 Endpoint Package Policy migration', () => {
const migration = migratePackagePolicyToV7110;
it('adds malware notification checkbox and optional message', () => {
const doc = {
attributes: {
name: 'endpoint',
id: 'endpoint',
policy_id: '',
enabled: true,
namespace: '',
output_id: '',
revision: 0,
updated_at: '',
updated_by: '',
created_at: '',
created_by: '',
inputs: [
{
type: 'endpoint',
enabled: true,
streams: [],
config: {
policy: {
value: {
windows: {},
mac: {},
},
},
},
},
],
},
type: ' nested',
};

expect(
migration(doc, {} as SavedObjectMigrationContext) as SavedObjectUnsanitizedDoc<PackagePolicy>
).toEqual({
attributes: {
name: 'endpoint',
id: 'endpoint',
policy_id: '',
enabled: true,
namespace: '',
output_id: '',
revision: 0,
updated_at: '',
updated_by: '',
created_at: '',
created_by: '',
inputs: [
{
type: 'endpoint',
enabled: true,
streams: [],
config: {
policy: {
value: {
windows: {
popup: {
malware: {
message: '',
enabled: false,
},
},
},
mac: {
popup: {
malware: {
message: '',
enabled: false,
},
},
},
},
},
},
},
],
},
type: ' nested',
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 { SavedObjectMigrationFn, SavedObjectUnsanitizedDoc } from 'kibana/server';
import { cloneDeep } from 'lodash';
import { PackagePolicy } from '../../types';

export const migratePackagePolicyToV7110: SavedObjectMigrationFn<PackagePolicy, PackagePolicy> = (
packagePolicyDoc
) => {
const updatedPackagePolicyDoc: SavedObjectUnsanitizedDoc<PackagePolicy> = cloneDeep(
packagePolicyDoc
);
if (packagePolicyDoc.attributes.name === 'endpoint') {
const input = updatedPackagePolicyDoc.attributes.inputs[0];
const popup = {
malware: {
message: '',
enabled: false,
},
};
if (input && input.config) {
input.config.policy.value.windows.popup = popup;
input.config.policy.value.mac.popup = popup;
}
}

return updatedPackagePolicyDoc;
};
Loading