Skip to content

Commit e1789ad

Browse files
parkiinooatkiller
andcommitted
task/mac-eventing-form (#62999)
adds mac events form for endpoint policy details Co-authored-by: oatkiller <robert.austin@elastic.co>
1 parent 857e08c commit e1789ad

12 files changed

Lines changed: 325 additions & 133 deletions

File tree

x-pack/plugins/endpoint/public/applications/endpoint/models/policy.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export const generatePolicy = (): PolicyConfig => {
4242
mac: {
4343
events: {
4444
process: true,
45+
file: true,
46+
network: true,
4547
},
4648
malware: {
4749
mode: ProtectionModes.detect,
@@ -67,6 +69,8 @@ export const generatePolicy = (): PolicyConfig => {
6769
linux: {
6870
events: {
6971
process: true,
72+
file: true,
73+
network: true,
7074
},
7175
logging: {
7276
stdout: 'debug',

x-pack/plugins/endpoint/public/applications/endpoint/models/policy_details_config.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,33 @@ export function clone(policyDetailsConfig: UIPolicyConfig): UIPolicyConfig {
4343
*/
4444
return clonedConfig as UIPolicyConfig;
4545
}
46+
47+
/**
48+
* Returns value from `configuration`
49+
*/
50+
export const getIn = (a: UIPolicyConfig) => <Key extends keyof UIPolicyConfig>(key: Key) => <
51+
subKey extends keyof UIPolicyConfig[Key]
52+
>(
53+
subKey: subKey
54+
) => <LeafKey extends keyof UIPolicyConfig[Key][subKey]>(
55+
leafKey: LeafKey
56+
): UIPolicyConfig[Key][subKey][LeafKey] => {
57+
return a[key][subKey][leafKey];
58+
};
59+
60+
/**
61+
* Returns cloned `configuration` with `value` set by the `keyPath`.
62+
*/
63+
export const setIn = (a: UIPolicyConfig) => <Key extends keyof UIPolicyConfig>(key: Key) => <
64+
subKey extends keyof UIPolicyConfig[Key]
65+
>(
66+
subKey: subKey
67+
) => <LeafKey extends keyof UIPolicyConfig[Key][subKey]>(leafKey: LeafKey) => <
68+
V extends UIPolicyConfig[Key][subKey][LeafKey]
69+
>(
70+
v: V
71+
): UIPolicyConfig => {
72+
const c = clone(a);
73+
c[key][subKey][leafKey] = v;
74+
return c;
75+
};

x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/index.test.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { PolicyDetailsState } from '../../types';
88
import { createStore, Dispatch, Store } from 'redux';
99
import { policyDetailsReducer, PolicyDetailsAction } from './index';
10-
import { policyConfig, windowsEventing } from './selectors';
10+
import { policyConfig } from './selectors';
1111
import { clone } from '../../models/policy_details_config';
1212
import { generatePolicy } from '../../models/policy';
1313

@@ -55,7 +55,7 @@ describe('policy details: ', () => {
5555
});
5656
});
5757

58-
describe('when the user has enabled windows process eventing', () => {
58+
describe('when the user has enabled windows process events', () => {
5959
beforeEach(() => {
6060
const config = policyConfig(getState());
6161
if (!config) {
@@ -71,8 +71,31 @@ describe('policy details: ', () => {
7171
});
7272
});
7373

74-
it('windows process eventing is enabled', async () => {
75-
expect(windowsEventing(getState())!.process).toEqual(true);
74+
it('windows process events is enabled', () => {
75+
const config = policyConfig(getState());
76+
expect(config!.windows.events.process).toEqual(true);
77+
});
78+
});
79+
80+
describe('when the user has enabled mac file events', () => {
81+
beforeEach(() => {
82+
const config = policyConfig(getState());
83+
if (!config) {
84+
throw new Error();
85+
}
86+
87+
const newPayload1 = clone(config);
88+
newPayload1.mac.events.file = true;
89+
90+
dispatch({
91+
type: 'userChangedPolicyConfig',
92+
payload: { policyConfig: newPayload1 },
93+
});
94+
});
95+
96+
it('mac file events is enabled', () => {
97+
const config = policyConfig(getState());
98+
expect(config!.mac.events.file).toEqual(true);
7699
});
77100
});
78101
});

x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/reducer.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import { Reducer } from 'redux';
8-
import { PolicyData, PolicyDetailsState, UIPolicyConfig } from '../../types';
8+
import { PolicyDetailsState, UIPolicyConfig } from '../../types';
99
import { AppAction } from '../action';
1010
import { fullPolicy, isOnPolicyDetailsPage } from './selectors';
1111

@@ -89,10 +89,12 @@ export const policyDetailsReducer: Reducer<PolicyDetailsState, AppAction> = (
8989
}
9090

9191
if (action.type === 'userChangedPolicyConfig') {
92-
const newState = { ...state, policyItem: { ...(state.policyItem as PolicyData) } };
93-
const newPolicy = (newState.policyItem.inputs[0].config.policy.value = {
94-
...fullPolicy(state),
95-
});
92+
if (!state.policyItem) {
93+
return state;
94+
}
95+
const newState = { ...state, policyItem: { ...state.policyItem } };
96+
const newPolicy: any = { ...fullPolicy(state) };
97+
newState.policyItem.inputs[0].config.policy.value = newPolicy;
9698

9799
Object.entries(action.payload.policyConfig).forEach(([section, newSettings]) => {
98100
newPolicy[section as keyof UIPolicyConfig] = {

x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/selectors.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,8 @@ export const policyConfig: (s: PolicyDetailsState) => UIPolicyConfig = createSel
7979
}
8080
);
8181

82-
/** Returns an object of all the windows eventing configuration */
83-
export const windowsEventing = (state: PolicyDetailsState) => {
84-
const config = policyConfig(state);
85-
return config && config.windows.events;
86-
};
87-
8882
/** Returns the total number of possible windows eventing configurations */
89-
export const totalWindowsEventing = (state: PolicyDetailsState): number => {
83+
export const totalWindowsEvents = (state: PolicyDetailsState): number => {
9084
const config = policyConfig(state);
9185
if (config) {
9286
return Object.keys(config.windows.events).length;
@@ -95,7 +89,7 @@ export const totalWindowsEventing = (state: PolicyDetailsState): number => {
9589
};
9690

9791
/** Returns the number of selected windows eventing configurations */
98-
export const selectedWindowsEventing = (state: PolicyDetailsState): number => {
92+
export const selectedWindowsEvents = (state: PolicyDetailsState): number => {
9993
const config = policyConfig(state);
10094
if (config) {
10195
return Object.values(config.windows.events).reduce((count, event) => {
@@ -105,6 +99,26 @@ export const selectedWindowsEventing = (state: PolicyDetailsState): number => {
10599
return 0;
106100
};
107101

102+
/** Returns the total number of possible mac eventing configurations */
103+
export const totalMacEvents = (state: PolicyDetailsState): number => {
104+
const config = policyConfig(state);
105+
if (config) {
106+
return Object.keys(config.mac.events).length;
107+
}
108+
return 0;
109+
};
110+
111+
/** Returns the number of selected mac eventing configurations */
112+
export const selectedMacEvents = (state: PolicyDetailsState): number => {
113+
const config = policyConfig(state);
114+
if (config) {
115+
return Object.values(config.mac.events).reduce((count, event) => {
116+
return event === true ? count + 1 : count;
117+
}, 0);
118+
}
119+
return 0;
120+
};
121+
108122
/** is there an api call in flight */
109123
export const isLoading = (state: PolicyDetailsState) => state.isLoading;
110124

x-pack/plugins/endpoint/public/applications/endpoint/types.ts

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -118,34 +118,21 @@ export interface PolicyDetailsState {
118118
* Endpoint Policy configuration
119119
*/
120120
export interface PolicyConfig {
121-
windows: {
122-
events: {
123-
process: boolean;
124-
network: boolean;
125-
};
126-
/** malware mode can be off, detect, prevent or prevent and notify user */
127-
malware: MalwareFields;
121+
windows: UIPolicyConfig['windows'] & {
128122
logging: {
129123
stdout: string;
130124
file: string;
131125
};
132126
advanced: PolicyConfigAdvancedOptions;
133127
};
134-
mac: {
135-
events: {
136-
process: boolean;
137-
};
138-
malware: MalwareFields;
128+
mac: UIPolicyConfig['mac'] & {
139129
logging: {
140130
stdout: string;
141131
file: string;
142132
};
143133
advanced: PolicyConfigAdvancedOptions;
144134
};
145-
linux: {
146-
events: {
147-
process: boolean;
148-
};
135+
linux: UIPolicyConfig['linux'] & {
149136
logging: {
150137
stdout: string;
151138
file: string;
@@ -168,29 +155,39 @@ interface PolicyConfigAdvancedOptions {
168155
};
169156
}
170157

171-
/**
172-
* Windows-specific policy configuration that is supported via the UI
173-
*/
174-
type WindowsPolicyConfig = Pick<PolicyConfig['windows'], 'events' | 'malware'>;
175-
176-
/**
177-
* Mac-specific policy configuration that is supported via the UI
178-
*/
179-
type MacPolicyConfig = Pick<PolicyConfig['mac'], 'malware' | 'events'>;
180-
181-
/**
182-
* Linux-specific policy configuration that is supported via the UI
183-
*/
184-
type LinuxPolicyConfig = Pick<PolicyConfig['linux'], 'events'>;
185-
186158
/**
187159
* The set of Policy configuration settings that are show/edited via the UI
188160
*/
189-
export interface UIPolicyConfig {
190-
windows: WindowsPolicyConfig;
191-
mac: MacPolicyConfig;
192-
linux: LinuxPolicyConfig;
193-
}
161+
/* eslint-disable @typescript-eslint/consistent-type-definitions */
162+
export type UIPolicyConfig = {
163+
windows: {
164+
events: {
165+
process: boolean;
166+
network: boolean;
167+
};
168+
/** malware mode can be off, detect, prevent or prevent and notify user */
169+
malware: MalwareFields;
170+
};
171+
mac: {
172+
events: {
173+
file: boolean;
174+
process: boolean;
175+
network: boolean;
176+
};
177+
malware: MalwareFields;
178+
};
179+
180+
/**
181+
* Linux-specific policy configuration that is supported via the UI
182+
*/
183+
linux: {
184+
events: {
185+
file: boolean;
186+
process: boolean;
187+
network: boolean;
188+
};
189+
};
190+
};
194191

195192
/** OS used in Policy */
196193
export enum OS {
@@ -203,6 +200,7 @@ export enum OS {
203200
export enum EventingFields {
204201
process = 'process',
205202
network = 'network',
203+
file = 'file',
206204
}
207205

208206
/**

x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_details.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ import {
2929
isLoading,
3030
apiError,
3131
} from '../../store/policy_details/selectors';
32-
import { WindowsEventing } from './policy_forms/eventing/windows';
3332
import { PageView, PageViewHeaderTitle } from '../../components/page_view';
3433
import { AppAction } from '../../types';
3534
import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public';
3635
import { AgentsSummary } from './agents_summary';
3736
import { VerticalDivider } from './vertical_divider';
37+
import { WindowsEvents, MacEvents } from './policy_forms/events';
3838
import { MalwareProtections } from './policy_forms/protections/malware';
3939

4040
export const PolicyDetails = React.memo(() => {
@@ -206,7 +206,9 @@ export const PolicyDetails = React.memo(() => {
206206
</h4>
207207
</EuiText>
208208
<EuiSpacer size="xs" />
209-
<WindowsEventing />
209+
<WindowsEvents />
210+
<EuiSpacer size="l" />
211+
<MacEvents />
210212
</PageView>
211213
</>
212214
);

x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)