From d4af7e41da8736c348fbae6e3ec1f648fbac8c4b Mon Sep 17 00:00:00 2001 From: Paul Tavares Date: Mon, 3 Aug 2020 13:36:52 -0400 Subject: [PATCH 01/41] Create Policies for each generated host --- .../common/endpoint/generate_data.ts | 19 ++- .../common/endpoint/index_data.ts | 140 +++++++++++++++++- .../scripts/endpoint/resolver_generator.ts | 4 + 3 files changed, 152 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/security_solution/common/endpoint/generate_data.ts b/x-pack/plugins/security_solution/common/endpoint/generate_data.ts index aa3f0bf287fca..2bce2719ac6b6 100644 --- a/x-pack/plugins/security_solution/common/endpoint/generate_data.ts +++ b/x-pack/plugins/security_solution/common/endpoint/generate_data.ts @@ -104,6 +104,12 @@ const Mac: OSFields[] = []; const OS: OSFields[] = [...Windows, ...Mac, ...Linux]; +const POLICY_RESPONSE_STATUSES: HostPolicyResponseActionStatus[] = [ + HostPolicyResponseActionStatus.success, + HostPolicyResponseActionStatus.failure, + HostPolicyResponseActionStatus.warning, +]; + const APPLIED_POLICIES: Array<{ name: string; id: string; @@ -350,15 +356,12 @@ export class EndpointDocGenerator { } /** - * Creates new random policy id for the host to simulate new policy application + * Updates the current Host common record applied Policy to a different one from the list + * of random choices and gives it a random policy response status. */ - public updatePolicyId() { - this.commonInfo.Endpoint.policy.applied.id = this.randomChoice(APPLIED_POLICIES).id; - this.commonInfo.Endpoint.policy.applied.status = this.randomChoice([ - HostPolicyResponseActionStatus.success, - HostPolicyResponseActionStatus.failure, - HostPolicyResponseActionStatus.warning, - ]); + public updateHostPolicyData() { + this.commonInfo.Endpoint.policy.applied = this.randomChoice(APPLIED_POLICIES); + this.commonInfo.Endpoint.policy.applied.status = this.randomChoice(POLICY_RESPONSE_STATUSES); } private createHostData(): HostInfo { diff --git a/x-pack/plugins/security_solution/common/endpoint/index_data.ts b/x-pack/plugins/security_solution/common/endpoint/index_data.ts index 9a61738cd84b4..5c71c6b57d027 100644 --- a/x-pack/plugins/security_solution/common/endpoint/index_data.ts +++ b/x-pack/plugins/security_solution/common/endpoint/index_data.ts @@ -6,10 +6,26 @@ import { Client } from '@elastic/elasticsearch'; import seedrandom from 'seedrandom'; +import { KbnClient } from '@kbn/dev-utils'; +import { AxiosResponse } from 'axios'; import { EndpointDocGenerator, TreeOptions, Event } from './generate_data'; +import { + CreateAgentConfigRequest, + CreateAgentConfigResponse, + CreatePackageConfigRequest, + CreatePackageConfigResponse, + GetPackagesResponse, +} from '../../../ingest_manager/common/types/rest_spec'; +import { + AGENT_CONFIG_API_ROUTES, + EPM_API_ROUTES, + PACKAGE_CONFIG_API_ROUTES, +} from '../../../ingest_manager/common'; +import { factory as policyConfigFactory } from './models/policy_config'; export async function indexHostsAndAlerts( client: Client, + kbnClient: KbnClient, seed: string, numHosts: number, numDocs: number, @@ -21,9 +37,22 @@ export async function indexHostsAndAlerts( options: TreeOptions = {} ) { const random = seedrandom(seed); + const epmEndpointPackage = await getEndpointPackageInfo(kbnClient); + // Keep a map of host applied policy ids (fake) to real ingest package configs (policy record) + const realPolicies: Record = {}; + for (let i = 0; i < numHosts; i++) { const generator = new EndpointDocGenerator(random); - await indexHostDocs(numDocs, client, metadataIndex, policyIndex, generator); + await indexHostDocs( + numDocs, + client, + kbnClient, + realPolicies, + epmEndpointPackage, + metadataIndex, + policyIndex, + generator + ); await indexAlerts(client, eventIndex, alertIndex, generator, alertsPerHost, options); } await client.indices.refresh({ @@ -42,18 +71,55 @@ function delay(ms: number) { async function indexHostDocs( numDocs: number, client: Client, + kbnClient: KbnClient, + realPolicies: Record, + epmEndpointPackage: GetPackagesResponse['response'][0], metadataIndex: string, policyIndex: string, generator: EndpointDocGenerator ) { const timeBetweenDocs = 6 * 3600 * 1000; // 6 hours between metadata documents const timestamp = new Date().getTime(); + for (let j = 0; j < numDocs; j++) { generator.updateHostData(); - generator.updatePolicyId(); + generator.updateHostPolicyData(); + + let hostMetadata = generator.generateHostMetadata( + timestamp - timeBetweenDocs * (numDocs - j - 1) + ); + const { id: appliedPolicyId, name: appliedPolicyName } = hostMetadata.Endpoint.policy.applied; + + if (appliedPolicyId !== '00000000-0000-0000-0000-000000000000') { + // If we don't yet have a "real" policy record, then create it now in ingest (package config) + if (!realPolicies[appliedPolicyId]) { + // eslint-disable-next-line require-atomic-updates + realPolicies[appliedPolicyId] = await createPolicy( + kbnClient, + appliedPolicyName, + epmEndpointPackage.version + ); + } + + // Update the Host metadata record with the ID of the "real" policy + hostMetadata = { + ...hostMetadata, + Endpoint: { + ...hostMetadata.Endpoint, + policy: { + ...hostMetadata.Endpoint.policy, + applied: { + ...hostMetadata.Endpoint.policy.applied, + id: realPolicies[appliedPolicyId].id, + }, + }, + }, + }; + } + await client.index({ index: metadataIndex, - body: generator.generateHostMetadata(timestamp - timeBetweenDocs * (numDocs - j - 1)), + body: hostMetadata, op_type: 'create', }); await client.index({ @@ -97,3 +163,71 @@ async function indexAlerts( await client.bulk({ body, refresh: true }); } } + +const createPolicy = async ( + kbnClient: KbnClient, + policyName: string, + endpointPackageVersion: string +): Promise => { + // Create Agent Configuration first + const newAgentconfigData: CreateAgentConfigRequest['body'] = { + name: `Config for ${policyName}`, + description: '', + namespace: 'default', + }; + const agentConfig = (await kbnClient.request({ + path: AGENT_CONFIG_API_ROUTES.CREATE_PATTERN, + method: 'POST', + body: newAgentconfigData, + })) as AxiosResponse; + + // Create Package Configuration + const newPackageConfigData: CreatePackageConfigRequest['body'] = { + name: policyName, + description: 'Protect the worlds data', + config_id: agentConfig.data.item.id, + enabled: true, + output_id: '', + inputs: [ + { + type: 'endpoint', + enabled: true, + streams: [], + config: { + policy: { + value: policyConfigFactory(), + }, + }, + }, + ], + namespace: 'default', + package: { + name: 'endpoint', + title: 'endpoint', + version: endpointPackageVersion, + }, + }; + const packageConfig = (await kbnClient.request({ + path: PACKAGE_CONFIG_API_ROUTES.CREATE_PATTERN, + method: 'POST', + body: newPackageConfigData, + })) as AxiosResponse; + return packageConfig.data.item; +}; + +const getEndpointPackageInfo = async ( + kbnClient: KbnClient +): Promise => { + const endpointPackage = ((await kbnClient.request({ + path: `${EPM_API_ROUTES.LIST_PATTERN}?category=security`, + method: 'GET', + })) as AxiosResponse).data.response.find( + (epmPackage) => epmPackage.name === 'endpoint' + ); + + if (!endpointPackage) { + throw new Error('EPM Endpoint package was not found!'); + } + + return endpointPackage; +}; diff --git a/x-pack/plugins/security_solution/scripts/endpoint/resolver_generator.ts b/x-pack/plugins/security_solution/scripts/endpoint/resolver_generator.ts index cfe1c741ef3f1..7952ef0ecfb0f 100644 --- a/x-pack/plugins/security_solution/scripts/endpoint/resolver_generator.ts +++ b/x-pack/plugins/security_solution/scripts/endpoint/resolver_generator.ts @@ -10,6 +10,7 @@ import * as url from 'url'; import fetch from 'node-fetch'; import { Client, ClientOptions } from '@elastic/elasticsearch'; import { ResponseError } from '@elastic/elasticsearch/lib/errors'; +import { KbnClient, ToolingLog } from '@kbn/dev-utils'; import { indexHostsAndAlerts } from '../../common/endpoint/index_data'; import { ANCESTRY_LIMIT } from '../../common/endpoint/generate_data'; @@ -203,6 +204,8 @@ async function main() { node: argv.node, }; + const kibana = new KbnClient(new ToolingLog(), { url: argv.kibana }); + const client = new Client(clientOptions); if (argv.delete) { await deleteIndices( @@ -219,6 +222,7 @@ async function main() { const startTime = new Date().getTime(); await indexHostsAndAlerts( client, + kibana, seed, argv.numHosts, argv.numDocs, From 9b1ff8302c9d4869a61de734de108f1ce087eb3b Mon Sep 17 00:00:00 2001 From: Paul Tavares Date: Mon, 3 Aug 2020 14:08:54 -0400 Subject: [PATCH 02/41] Refactor Ingest setup to also setup Fleet --- .../common/endpoint/generate_data.ts | 5 ++ .../scripts/endpoint/resolver_generator.ts | 85 ++++++++++--------- 2 files changed, 48 insertions(+), 42 deletions(-) diff --git a/x-pack/plugins/security_solution/common/endpoint/generate_data.ts b/x-pack/plugins/security_solution/common/endpoint/generate_data.ts index 2bce2719ac6b6..dee87aaa90159 100644 --- a/x-pack/plugins/security_solution/common/endpoint/generate_data.ts +++ b/x-pack/plugins/security_solution/common/endpoint/generate_data.ts @@ -125,6 +125,11 @@ const APPLIED_POLICIES: Array<{ id: 'C2A9093E-E289-4C0A-AA44-8C32A414FA7A', status: HostPolicyResponseActionStatus.success, }, + { + name: 'Detect Malware Only', + id: '47d7965d-6869-478b-bd9c-fb0d2bb3959f', + status: HostPolicyResponseActionStatus.success, + }, ]; const FILE_OPERATIONS: string[] = ['creation', 'open', 'rename', 'execution', 'deletion']; diff --git a/x-pack/plugins/security_solution/scripts/endpoint/resolver_generator.ts b/x-pack/plugins/security_solution/scripts/endpoint/resolver_generator.ts index 7952ef0ecfb0f..c3afb38d04952 100644 --- a/x-pack/plugins/security_solution/scripts/endpoint/resolver_generator.ts +++ b/x-pack/plugins/security_solution/scripts/endpoint/resolver_generator.ts @@ -4,15 +4,18 @@ * you may not use this file except in compliance with the Elastic License. */ /* eslint-disable no-console */ -import * as path from 'path'; import yargs from 'yargs'; -import * as url from 'url'; -import fetch from 'node-fetch'; import { Client, ClientOptions } from '@elastic/elasticsearch'; import { ResponseError } from '@elastic/elasticsearch/lib/errors'; import { KbnClient, ToolingLog } from '@kbn/dev-utils'; +import { AxiosResponse } from 'axios'; import { indexHostsAndAlerts } from '../../common/endpoint/index_data'; import { ANCESTRY_LIMIT } from '../../common/endpoint/generate_data'; +import { FLEET_SETUP_API_ROUTES, SETUP_API_ROUTE } from '../../../ingest_manager/common/constants'; +import { + CreateFleetSetupResponse, + PostIngestSetupResponse, +} from '../../../ingest_manager/common/types/rest_spec'; main(); @@ -36,42 +39,37 @@ async function deleteIndices(indices: string[], client: Client) { } } -async function doIngestSetup(kibanaURL: string) { +async function doIngestSetup(kbnClient: KbnClient) { + // Setup Ingest try { - const kbURL = new url.URL(kibanaURL); - // this includes the base path that is randomly generated by Kibana - const pathname = path.posix.join(path.posix.sep, kbURL.pathname, 'api/ingest_manager/setup'); - const connectURL = new url.URL(pathname, kbURL); - console.log('Calling ingest manager setup at ', connectURL.toString()); - const response = await fetch( - // wrap base url in URL class because the kibana basepath will get removed otherwise - connectURL.toString(), - { - method: 'POST', - headers: { - 'kbn-xsrf': 'blah', - }, - } - ); - if (response.status !== 200) { - console.log('POST response ', response); - console.log( - 'Request failed please check that you have the correct base path and credentials for the kibana URL' - ); - // eslint-disable-next-line no-process-exit - process.exit(1); + const setupResponse = (await kbnClient.request({ + path: SETUP_API_ROUTE, + method: 'POST', + })) as AxiosResponse; + + if (!setupResponse.data.isInitialized) { + console.error(setupResponse.data); + throw new Error('Initializing the ingest manager failed, existing'); } - const setupResponse = await response.json(); - console.log('Ingest setup response ', setupResponse); - if (!setupResponse?.isInitialized) { - console.log('Initializing the ingest manager failed, existing'); - // eslint-disable-next-line no-process-exit - process.exit(1); + } catch (error) { + console.error(error); + throw error; + } + + // Setup Fleet + try { + const setupResponse = (await kbnClient.request({ + path: FLEET_SETUP_API_ROUTES.CREATE_PATTERN, + method: 'POST', + })) as AxiosResponse; + + if (!setupResponse.data.isInitialized) { + console.error(setupResponse.data); + throw new Error('Initializing Fleet failed, existing'); } } catch (error) { - console.log(JSON.stringify(error, null, 2)); - // eslint-disable-next-line no-process-exit - process.exit(1); + console.error(error); + throw error; } } @@ -198,15 +196,18 @@ async function main() { default: false, }, }).argv; - await doIngestSetup(argv.kibana); + const kbnClient = new KbnClient(new ToolingLog(), { url: argv.kibana }); - const clientOptions: ClientOptions = { - node: argv.node, - }; - - const kibana = new KbnClient(new ToolingLog(), { url: argv.kibana }); + try { + await doIngestSetup(kbnClient); + } catch (error) { + // eslint-disable-next-line no-process-exit + process.exit(1); + } + const clientOptions: ClientOptions = { node: argv.node }; const client = new Client(clientOptions); + if (argv.delete) { await deleteIndices( [argv.eventIndex, argv.metadataIndex, argv.policyIndex, argv.alertIndex], @@ -222,7 +223,7 @@ async function main() { const startTime = new Date().getTime(); await indexHostsAndAlerts( client, - kibana, + kbnClient, seed, argv.numHosts, argv.numDocs, From 915c910e32c52deef5448bd7f06ad61b93f0766f Mon Sep 17 00:00:00 2001 From: Paul Tavares Date: Mon, 3 Aug 2020 14:40:23 -0400 Subject: [PATCH 03/41] Rename prop name --- .../security_solution/common/endpoint/index_data.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/security_solution/common/endpoint/index_data.ts b/x-pack/plugins/security_solution/common/endpoint/index_data.ts index 5c71c6b57d027..e5fef7746fee5 100644 --- a/x-pack/plugins/security_solution/common/endpoint/index_data.ts +++ b/x-pack/plugins/security_solution/common/endpoint/index_data.ts @@ -30,7 +30,7 @@ export async function indexHostsAndAlerts( numHosts: number, numDocs: number, metadataIndex: string, - policyIndex: string, + policyResponseIndex: string, eventIndex: string, alertIndex: string, alertsPerHost: number, @@ -50,7 +50,7 @@ export async function indexHostsAndAlerts( realPolicies, epmEndpointPackage, metadataIndex, - policyIndex, + policyResponseIndex, generator ); await indexAlerts(client, eventIndex, alertIndex, generator, alertsPerHost, options); @@ -75,7 +75,7 @@ async function indexHostDocs( realPolicies: Record, epmEndpointPackage: GetPackagesResponse['response'][0], metadataIndex: string, - policyIndex: string, + policyResponseIndex: string, generator: EndpointDocGenerator ) { const timeBetweenDocs = 6 * 3600 * 1000; // 6 hours between metadata documents @@ -123,7 +123,7 @@ async function indexHostDocs( op_type: 'create', }); await client.index({ - index: policyIndex, + index: policyResponseIndex, body: generator.generatePolicyResponse(timestamp - timeBetweenDocs * (numDocs - j - 1)), op_type: 'create', }); From 9e53c3306783e7b094dbb5f63810ce90265dc8bb Mon Sep 17 00:00:00 2001 From: Paul Tavares Date: Mon, 3 Aug 2020 18:19:46 -0400 Subject: [PATCH 04/41] Add generic response type to KbnClient.request + support for headers --- packages/kbn-dev-utils/src/kbn_client/kbn_client.ts | 4 ++-- packages/kbn-dev-utils/src/kbn_client/kbn_client_requester.ts | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/kbn-dev-utils/src/kbn_client/kbn_client.ts b/packages/kbn-dev-utils/src/kbn_client/kbn_client.ts index 861ea0988692c..7184727fc53de 100644 --- a/packages/kbn-dev-utils/src/kbn_client/kbn_client.ts +++ b/packages/kbn-dev-utils/src/kbn_client/kbn_client.ts @@ -54,8 +54,8 @@ export class KbnClient { /** * Make a direct request to the Kibana server */ - async request(options: ReqOptions) { - return await this.requester.request(options); + async request(options: ReqOptions) { + return await this.requester.request(options); } resolveUrl(relativeUrl: string) { diff --git a/packages/kbn-dev-utils/src/kbn_client/kbn_client_requester.ts b/packages/kbn-dev-utils/src/kbn_client/kbn_client_requester.ts index 2aba2be56f277..f4d7c9b7f287d 100644 --- a/packages/kbn-dev-utils/src/kbn_client/kbn_client_requester.ts +++ b/packages/kbn-dev-utils/src/kbn_client/kbn_client_requester.ts @@ -60,6 +60,7 @@ export interface ReqOptions { path: string; query?: Record; method: 'GET' | 'POST' | 'PUT' | 'DELETE'; + headers?: Record; body?: any; retries?: number; } @@ -117,6 +118,7 @@ export class KbnClientRequester { params: options.query, headers: { 'kbn-xsrf': 'kbn-client', + ...options.headers, }, httpsAgent: this.httpsAgent, }); From 37979833536421d1165050eb25d1c73df696df56 Mon Sep 17 00:00:00 2001 From: Paul Tavares Date: Tue, 4 Aug 2020 07:32:31 -0400 Subject: [PATCH 05/41] first attempt at adding fleet agent registration --- .../common/endpoint/index_data.ts | 89 +++++++++++++++++-- 1 file changed, 84 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/security_solution/common/endpoint/index_data.ts b/x-pack/plugins/security_solution/common/endpoint/index_data.ts index e5fef7746fee5..2e76bea857d64 100644 --- a/x-pack/plugins/security_solution/common/endpoint/index_data.ts +++ b/x-pack/plugins/security_solution/common/endpoint/index_data.ts @@ -15,13 +15,19 @@ import { CreatePackageConfigRequest, CreatePackageConfigResponse, GetPackagesResponse, -} from '../../../ingest_manager/common/types/rest_spec'; -import { + PostAgentEnrollRequest, + AGENT_API_ROUTES, AGENT_CONFIG_API_ROUTES, EPM_API_ROUTES, PACKAGE_CONFIG_API_ROUTES, + ENROLLMENT_API_KEY_ROUTES, + GetEnrollmentAPIKeysResponse, + GetOnePackageConfigResponse, + GetOneEnrollmentAPIKeyResponse, + PostAgentEnrollResponse, } from '../../../ingest_manager/common'; import { factory as policyConfigFactory } from './models/policy_config'; +import { HostMetadata } from './types'; export async function indexHostsAndAlerts( client: Client, @@ -80,14 +86,13 @@ async function indexHostDocs( ) { const timeBetweenDocs = 6 * 3600 * 1000; // 6 hours between metadata documents const timestamp = new Date().getTime(); + let hostMetadata: HostMetadata; for (let j = 0; j < numDocs; j++) { generator.updateHostData(); generator.updateHostPolicyData(); - let hostMetadata = generator.generateHostMetadata( - timestamp - timeBetweenDocs * (numDocs - j - 1) - ); + hostMetadata = generator.generateHostMetadata(timestamp - timeBetweenDocs * (numDocs - j - 1)); const { id: appliedPolicyId, name: appliedPolicyName } = hostMetadata.Endpoint.policy.applied; if (appliedPolicyId !== '00000000-0000-0000-0000-000000000000') { @@ -128,6 +133,10 @@ async function indexHostDocs( op_type: 'create', }); } + + if (hostMetadata!.Endpoint.policy.applied.id !== '00000000-0000-0000-0000-000000000000') { + await fleetEnrollAgentForHost(kbnClient, hostMetadata!); + } } async function indexAlerts( @@ -231,3 +240,73 @@ const getEndpointPackageInfo = async ( return endpointPackage; }; + +const fleetEnrollAgentForHost = async (kbnClient: KbnClient, host: HostMetadata) => { + // Get Enrollement key for host's applied policy + const enrollmentApiKey = await kbnClient + .request({ + path: PACKAGE_CONFIG_API_ROUTES.INFO_PATTERN.replace( + '{packageConfigId}', + host.Endpoint.policy.applied.id + ), + method: 'GET', + }) + .then((packageConfigResponse) => { + return kbnClient.request({ + path: ENROLLMENT_API_KEY_ROUTES.LIST_PATTERN, + method: 'GET', + query: { + kuery: `fleet-enrollment-api-keys.config_id:"${packageConfigResponse.data.item.config_id}"`, + }, + }); + }) + .then((apiKeysResponse) => { + const apiKey = apiKeysResponse.data.list[0]; + + // TODO: Handle if it does not exist + + return kbnClient.request({ + path: ENROLLMENT_API_KEY_ROUTES.INFO_PATTERN.replace('{keyId}', apiKey.id), + method: 'GET', + }); + }) + .then((apiKeyDetailsResponse) => { + return apiKeyDetailsResponse.data.item.api_key; + }) + .catch(() => { + return ''; + }); + + if (enrollmentApiKey.length === 0) { + return; + } + + // Enroll an agent for the Host + const body: PostAgentEnrollRequest['body'] = { + type: 'PERMANENT', + shared_id: host.elastic.agent.id, + metadata: { + local: { + ...host.host, + }, + user_provided: { + dev_agent_version: '0.0.1', + region: 'us-east', + }, + }, + }; + + try { + await kbnClient.request({ + path: AGENT_API_ROUTES.ENROLL_PATTERN, + method: 'POST', + body, + headers: { + Authorization: `ApiKey ${enrollmentApiKey}`, + 'Content-Type': 'application/json', + }, + }); + } catch (error) { + // debugger; + } +}; From 67425be0b1cfb31d1845e7296071186873e600cd Mon Sep 17 00:00:00 2001 From: Paul Tavares Date: Tue, 4 Aug 2020 09:25:17 -0400 Subject: [PATCH 06/41] a little closer with fleet integration --- .../common/endpoint/index_data.ts | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/security_solution/common/endpoint/index_data.ts b/x-pack/plugins/security_solution/common/endpoint/index_data.ts index 2e76bea857d64..66ee539794425 100644 --- a/x-pack/plugins/security_solution/common/endpoint/index_data.ts +++ b/x-pack/plugins/security_solution/common/endpoint/index_data.ts @@ -8,6 +8,7 @@ import { Client } from '@elastic/elasticsearch'; import seedrandom from 'seedrandom'; import { KbnClient } from '@kbn/dev-utils'; import { AxiosResponse } from 'axios'; +import fetch from 'node-fetch'; import { EndpointDocGenerator, TreeOptions, Event } from './generate_data'; import { CreateAgentConfigRequest, @@ -287,7 +288,13 @@ const fleetEnrollAgentForHost = async (kbnClient: KbnClient, host: HostMetadata) shared_id: host.elastic.agent.id, metadata: { local: { - ...host.host, + host: host.host, + elastic: { + agent: { + ...host.agent, + version: '8.0.0', + }, + }, }, user_provided: { dev_agent_version: '0.0.1', @@ -297,16 +304,39 @@ const fleetEnrollAgentForHost = async (kbnClient: KbnClient, host: HostMetadata) }; try { - await kbnClient.request({ - path: AGENT_API_ROUTES.ENROLL_PATTERN, + // FIXME: should we use `fetch()` in this module? + // FIXME: need way to get kibana URL without auth in it + const res = await fetch(`http://localhost:5601${AGENT_API_ROUTES.ENROLL_PATTERN}`, { method: 'POST', - body, + body: JSON.stringify(body), headers: { + 'kbn-xsrf': 'xxx', Authorization: `ApiKey ${enrollmentApiKey}`, 'Content-Type': 'application/json', }, }); + + if (res) { + const obj: PostAgentEnrollResponse = await res.json(); + if (!obj.success) { + // eslint-disable-next-line no-console + console.error(obj); + } + } + + // THIS DOES NOT WORK because its sent with basic auth (Authorization header is stripped out) + // + // await kbnClient.request({ + // path: AGENT_API_ROUTES.ENROLL_PATTERN, + // method: 'POST', + // body, + // headers: { + // Authorization: `ApiKey ${enrollmentApiKey}`, + // 'Content-Type': 'application/json', + // }, + // }); } catch (error) { - // debugger; + // eslint-disable-next-line no-console + console.error(error); } }; From 3dc453c0918f692ac0ff1545268e4f05c767c947 Mon Sep 17 00:00:00 2001 From: Paul Tavares Date: Tue, 4 Aug 2020 17:37:49 -0400 Subject: [PATCH 07/41] SUCCESS. Able to enroll agent and set it to online --- .../common/endpoint/index_data.ts | 228 +++++++++++++----- 1 file changed, 165 insertions(+), 63 deletions(-) diff --git a/x-pack/plugins/security_solution/common/endpoint/index_data.ts b/x-pack/plugins/security_solution/common/endpoint/index_data.ts index 66ee539794425..8effd68c68119 100644 --- a/x-pack/plugins/security_solution/common/endpoint/index_data.ts +++ b/x-pack/plugins/security_solution/common/endpoint/index_data.ts @@ -23,9 +23,12 @@ import { PACKAGE_CONFIG_API_ROUTES, ENROLLMENT_API_KEY_ROUTES, GetEnrollmentAPIKeysResponse, - GetOnePackageConfigResponse, GetOneEnrollmentAPIKeyResponse, PostAgentEnrollResponse, + PostAgentCheckinRequest, + PostAgentCheckinResponse, + PostAgentAcksResponse, + PostAgentAcksRequest, } from '../../../ingest_manager/common'; import { factory as policyConfigFactory } from './models/policy_config'; import { HostMetadata } from './types'; @@ -88,6 +91,8 @@ async function indexHostDocs( const timeBetweenDocs = 6 * 3600 * 1000; // 6 hours between metadata documents const timestamp = new Date().getTime(); let hostMetadata: HostMetadata; + let wasAgentEnrolled = false; + let enrolledAgent: undefined | PostAgentEnrollResponse['item']; for (let j = 0; j < numDocs; j++) { generator.updateHostData(); @@ -96,32 +101,47 @@ async function indexHostDocs( hostMetadata = generator.generateHostMetadata(timestamp - timeBetweenDocs * (numDocs - j - 1)); const { id: appliedPolicyId, name: appliedPolicyName } = hostMetadata.Endpoint.policy.applied; - if (appliedPolicyId !== '00000000-0000-0000-0000-000000000000') { - // If we don't yet have a "real" policy record, then create it now in ingest (package config) - if (!realPolicies[appliedPolicyId]) { - // eslint-disable-next-line require-atomic-updates - realPolicies[appliedPolicyId] = await createPolicy( - kbnClient, - appliedPolicyName, - epmEndpointPackage.version - ); - } + // If we don't yet have a "real" policy record, then create it now in ingest (package config) + if (!realPolicies[appliedPolicyId]) { + // eslint-disable-next-line require-atomic-updates + realPolicies[appliedPolicyId] = await createPolicy( + kbnClient, + appliedPolicyName, + epmEndpointPackage.version + ); + } - // Update the Host metadata record with the ID of the "real" policy - hostMetadata = { - ...hostMetadata, - Endpoint: { - ...hostMetadata.Endpoint, - policy: { - ...hostMetadata.Endpoint.policy, - applied: { - ...hostMetadata.Endpoint.policy.applied, - id: realPolicies[appliedPolicyId].id, - }, + // If we did not yet enroll an agent for this Host, do it now that we have good policy id + if (!wasAgentEnrolled) { + wasAgentEnrolled = true; + enrolledAgent = await fleetEnrollAgentForHost( + kbnClient, + hostMetadata!, + realPolicies[appliedPolicyId].config_id + ); + } + + // Update the Host metadata record with the ID of the "real" policy along with the enrolled agent id + hostMetadata = { + ...hostMetadata, + elastic: { + ...hostMetadata.elastic, + agent: { + ...hostMetadata.elastic.agent, + id: enrolledAgent?.id ?? hostMetadata.elastic.agent.id, + }, + }, + Endpoint: { + ...hostMetadata.Endpoint, + policy: { + ...hostMetadata.Endpoint.policy, + applied: { + ...hostMetadata.Endpoint.policy.applied, + id: realPolicies[appliedPolicyId].id, }, }, - }; - } + }, + }; await client.index({ index: metadataIndex, @@ -134,10 +154,6 @@ async function indexHostDocs( op_type: 'create', }); } - - if (hostMetadata!.Endpoint.policy.applied.id !== '00000000-0000-0000-0000-000000000000') { - await fleetEnrollAgentForHost(kbnClient, hostMetadata!); - } } async function indexAlerts( @@ -242,29 +258,28 @@ const getEndpointPackageInfo = async ( return endpointPackage; }; -const fleetEnrollAgentForHost = async (kbnClient: KbnClient, host: HostMetadata) => { +const fleetEnrollAgentForHost = async ( + kbnClient: KbnClient, + endpointHost: HostMetadata, + agentConfigId: string +): Promise => { // Get Enrollement key for host's applied policy const enrollmentApiKey = await kbnClient - .request({ - path: PACKAGE_CONFIG_API_ROUTES.INFO_PATTERN.replace( - '{packageConfigId}', - host.Endpoint.policy.applied.id - ), + .request({ + path: ENROLLMENT_API_KEY_ROUTES.LIST_PATTERN, method: 'GET', - }) - .then((packageConfigResponse) => { - return kbnClient.request({ - path: ENROLLMENT_API_KEY_ROUTES.LIST_PATTERN, - method: 'GET', - query: { - kuery: `fleet-enrollment-api-keys.config_id:"${packageConfigResponse.data.item.config_id}"`, - }, - }); + query: { + kuery: `fleet-enrollment-api-keys.config_id:"${agentConfigId}"`, + }, }) .then((apiKeysResponse) => { const apiKey = apiKeysResponse.data.list[0]; - // TODO: Handle if it does not exist + if (!apiKey) { + return Promise.reject( + new Error(`no API enrolment key found for agent config id ${agentConfigId}`) + ); + } return kbnClient.request({ path: ENROLLMENT_API_KEY_ROUTES.INFO_PATTERN.replace('{keyId}', apiKey.id), @@ -274,7 +289,9 @@ const fleetEnrollAgentForHost = async (kbnClient: KbnClient, host: HostMetadata) .then((apiKeyDetailsResponse) => { return apiKeyDetailsResponse.data.item.api_key; }) - .catch(() => { + .catch((error) => { + // eslint-disable-next-line no-console + console.error(error); return ''; }); @@ -285,13 +302,11 @@ const fleetEnrollAgentForHost = async (kbnClient: KbnClient, host: HostMetadata) // Enroll an agent for the Host const body: PostAgentEnrollRequest['body'] = { type: 'PERMANENT', - shared_id: host.elastic.agent.id, metadata: { local: { - host: host.host, + host: endpointHost.host, elastic: { agent: { - ...host.agent, version: '8.0.0', }, }, @@ -306,6 +321,9 @@ const fleetEnrollAgentForHost = async (kbnClient: KbnClient, host: HostMetadata) try { // FIXME: should we use `fetch()` in this module? // FIXME: need way to get kibana URL without auth in it + + // ------------------------------------------------ + // First enroll the agent const res = await fetch(`http://localhost:5601${AGENT_API_ROUTES.ENROLL_PATTERN}`, { method: 'POST', body: JSON.stringify(body), @@ -317,24 +335,108 @@ const fleetEnrollAgentForHost = async (kbnClient: KbnClient, host: HostMetadata) }); if (res) { - const obj: PostAgentEnrollResponse = await res.json(); - if (!obj.success) { + const enrollObj: PostAgentEnrollResponse = await res.json(); + if (!enrollObj.success) { // eslint-disable-next-line no-console - console.error(obj); + console.error(enrollObj); + return; } - } - // THIS DOES NOT WORK because its sent with basic auth (Authorization header is stripped out) - // - // await kbnClient.request({ - // path: AGENT_API_ROUTES.ENROLL_PATTERN, - // method: 'POST', - // body, - // headers: { - // Authorization: `ApiKey ${enrollmentApiKey}`, - // 'Content-Type': 'application/json', - // }, - // }); + // ------------------------------------------------ + // now check the agent in so that it can complete enrollment + const checkinBody: PostAgentCheckinRequest['body'] = { + events: [ + { + type: 'STATE', + subtype: 'RUNNING', + message: 'state changed from STOPPED to RUNNING', + timestamp: new Date().toISOString(), + payload: { + random: 'data', + state: 'RUNNING', + previous_state: 'STOPPED', + }, + agent_id: enrollObj.item.id, + }, + ], + }; + const checkinRes = await fetch( + `http://localhost:5601${AGENT_API_ROUTES.CHECKIN_PATTERN.replace( + '{agentId}', + enrollObj.item.id + )}`, + { + method: 'POST', + body: JSON.stringify(checkinBody), + headers: { + 'kbn-xsrf': 'xxx', + Authorization: `ApiKey ${enrollObj.item.access_api_key}`, + 'Content-Type': 'application/json', + }, + } + ); + + // Agent unenrolling? + if (checkinRes.status === 403) { + return; + } + + const checkinObj: PostAgentCheckinResponse = await checkinRes.json(); + if (!checkinObj.success) { + // eslint-disable-next-line no-console + console.error( + `failed to checkin agent [${enrollObj.item.id}] for endpoint [${endpointHost.host.id}]` + ); + return enrollObj.item; + } + + // ------------------------------------------------ + // If we have an action to ack(), then do it now + if (checkinObj.actions.length) { + const ackActionBody: PostAgentAcksRequest['body'] = { + // @ts-ignore + events: checkinObj.actions.map((action) => { + return { + action_id: action.id, + type: 'ACTION_RESULT', + subtype: 'CONFIG', + timestamp: new Date().toISOString(), + agent_id: action.agent_id, + config_id: agentConfigId, + message: `endpoint generator: Endpoint Started`, + }; + }), + }; + const ackActionResp = await fetch( + `http://localhost:5601${AGENT_API_ROUTES.ACKS_PATTERN.replace( + '{agentId}', + enrollObj.item.id + )}`, + { + method: 'POST', + body: JSON.stringify(ackActionBody), + headers: { + 'kbn-xsrf': 'xxx', + Authorization: `ApiKey ${enrollObj.item.access_api_key}`, + 'Content-Type': 'application/json', + }, + } + ); + + const ackActionObj: PostAgentAcksResponse = await ackActionResp.json(); + if (!ackActionObj.success) { + // eslint-disable-next-line no-console + console.error( + `failed to ACK Actions provided to agent [${enrollObj.item.id}] for endpoint [${endpointHost.host.id}]` + ); + // eslint-disable-next-line no-console + console.error(JSON.stringify(ackActionObj, null, 2)); + return enrollObj.item; + } + } + + return enrollObj.item; + } } catch (error) { // eslint-disable-next-line no-console console.error(error); From 63f4d1ce7c0bc21f8a5e925837bb830f3a6d419a Mon Sep 17 00:00:00 2001 From: kevinlog Date: Sun, 23 Aug 2020 15:55:28 -0400 Subject: [PATCH 08/41] update names to be policy --- .../common/endpoint/index_data.ts | 63 ++++++++++--------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/x-pack/plugins/security_solution/common/endpoint/index_data.ts b/x-pack/plugins/security_solution/common/endpoint/index_data.ts index 8effd68c68119..632f5bf3cfcab 100644 --- a/x-pack/plugins/security_solution/common/endpoint/index_data.ts +++ b/x-pack/plugins/security_solution/common/endpoint/index_data.ts @@ -11,16 +11,16 @@ import { AxiosResponse } from 'axios'; import fetch from 'node-fetch'; import { EndpointDocGenerator, TreeOptions, Event } from './generate_data'; import { - CreateAgentConfigRequest, - CreateAgentConfigResponse, - CreatePackageConfigRequest, - CreatePackageConfigResponse, + CreateAgentPolicyRequest, + CreateAgentPolicyResponse, + CreatePackagePolicyRequest, + CreatePackagePolicyResponse, GetPackagesResponse, PostAgentEnrollRequest, AGENT_API_ROUTES, - AGENT_CONFIG_API_ROUTES, + AGENT_POLICY_API_ROUTES, EPM_API_ROUTES, - PACKAGE_CONFIG_API_ROUTES, + PACKAGE_POLICY_API_ROUTES, ENROLLMENT_API_KEY_ROUTES, GetEnrollmentAPIKeysResponse, GetOneEnrollmentAPIKeyResponse, @@ -49,7 +49,7 @@ export async function indexHostsAndAlerts( const random = seedrandom(seed); const epmEndpointPackage = await getEndpointPackageInfo(kbnClient); // Keep a map of host applied policy ids (fake) to real ingest package configs (policy record) - const realPolicies: Record = {}; + const realPolicies: Record = {}; for (let i = 0; i < numHosts; i++) { const generator = new EndpointDocGenerator(random); @@ -82,7 +82,7 @@ async function indexHostDocs( numDocs: number, client: Client, kbnClient: KbnClient, - realPolicies: Record, + realPolicies: Record, epmEndpointPackage: GetPackagesResponse['response'][0], metadataIndex: string, policyResponseIndex: string, @@ -117,7 +117,7 @@ async function indexHostDocs( enrolledAgent = await fleetEnrollAgentForHost( kbnClient, hostMetadata!, - realPolicies[appliedPolicyId].config_id + realPolicies[appliedPolicyId].policy_id ); } @@ -194,24 +194,29 @@ const createPolicy = async ( kbnClient: KbnClient, policyName: string, endpointPackageVersion: string -): Promise => { - // Create Agent Configuration first - const newAgentconfigData: CreateAgentConfigRequest['body'] = { - name: `Config for ${policyName}`, +): Promise => { + // Create Agent Policy first + const newAgentPolicyData: CreateAgentPolicyRequest['body'] = { + name: `Policy for ${policyName}`, description: '', namespace: 'default', }; - const agentConfig = (await kbnClient.request({ - path: AGENT_CONFIG_API_ROUTES.CREATE_PATTERN, - method: 'POST', - body: newAgentconfigData, - })) as AxiosResponse; + let agentPolicy; + try { + agentPolicy = (await kbnClient.request({ + path: AGENT_POLICY_API_ROUTES.CREATE_PATTERN, + method: 'POST', + body: newAgentPolicyData, + })) as AxiosResponse; + } catch (error) { + throw new Error(`create policy ${error}`); + } // Create Package Configuration - const newPackageConfigData: CreatePackageConfigRequest['body'] = { + const newPackagePolicyData: CreatePackagePolicyRequest['body'] = { name: policyName, description: 'Protect the worlds data', - config_id: agentConfig.data.item.id, + policy_id: agentPolicy.data.item.id, enabled: true, output_id: '', inputs: [ @@ -233,12 +238,12 @@ const createPolicy = async ( version: endpointPackageVersion, }, }; - const packageConfig = (await kbnClient.request({ - path: PACKAGE_CONFIG_API_ROUTES.CREATE_PATTERN, + const packagePolicy = (await kbnClient.request({ + path: PACKAGE_POLICY_API_ROUTES.CREATE_PATTERN, method: 'POST', - body: newPackageConfigData, - })) as AxiosResponse; - return packageConfig.data.item; + body: newPackagePolicyData, + })) as AxiosResponse; + return packagePolicy.data.item; }; const getEndpointPackageInfo = async ( @@ -261,7 +266,7 @@ const getEndpointPackageInfo = async ( const fleetEnrollAgentForHost = async ( kbnClient: KbnClient, endpointHost: HostMetadata, - agentConfigId: string + agentPolicyId: string ): Promise => { // Get Enrollement key for host's applied policy const enrollmentApiKey = await kbnClient @@ -269,7 +274,7 @@ const fleetEnrollAgentForHost = async ( path: ENROLLMENT_API_KEY_ROUTES.LIST_PATTERN, method: 'GET', query: { - kuery: `fleet-enrollment-api-keys.config_id:"${agentConfigId}"`, + kuery: `fleet-enrollment-api-keys.policy_id:"${agentPolicyId}"`, }, }) .then((apiKeysResponse) => { @@ -277,7 +282,7 @@ const fleetEnrollAgentForHost = async ( if (!apiKey) { return Promise.reject( - new Error(`no API enrolment key found for agent config id ${agentConfigId}`) + new Error(`no API enrolment key found for agent policy id ${agentPolicyId}`) ); } @@ -402,7 +407,7 @@ const fleetEnrollAgentForHost = async ( subtype: 'CONFIG', timestamp: new Date().toISOString(), agent_id: action.agent_id, - config_id: agentConfigId, + policy_id: agentPolicyId, message: `endpoint generator: Endpoint Started`, }; }), From a2297b3e6af774db804e739484bc8c510789af2c Mon Sep 17 00:00:00 2001 From: Candace Park Date: Mon, 31 Aug 2020 12:35:40 -0400 Subject: [PATCH 09/41] policy generator has advanced types in endpoint confit --- .../common/endpoint/models/policy_config.ts | 24 +++++++++++++++++++ .../common/endpoint/types.ts | 11 +++++++++ 2 files changed, 35 insertions(+) diff --git a/x-pack/plugins/security_solution/common/endpoint/models/policy_config.ts b/x-pack/plugins/security_solution/common/endpoint/models/policy_config.ts index 37b7308856196..a2a024e3e5c0c 100644 --- a/x-pack/plugins/security_solution/common/endpoint/models/policy_config.ts +++ b/x-pack/plugins/security_solution/common/endpoint/models/policy_config.ts @@ -12,6 +12,14 @@ import { PolicyConfig, ProtectionModes } from '../types'; export const factory = (): PolicyConfig => { return { windows: { + advanced: { + elasticsearch: { + tls: { + verify_hostname: 'false', + verify_peer: '', + }, + }, + }, events: { dll_and_driver_load: true, dns: true, @@ -29,6 +37,14 @@ export const factory = (): PolicyConfig => { }, }, mac: { + advanced: { + elasticsearch: { + tls: { + verify_hostname: '', + verify_peer: '', + }, + }, + }, events: { process: true, file: true, @@ -42,6 +58,14 @@ export const factory = (): PolicyConfig => { }, }, linux: { + advanced: { + elasticsearch: { + tls: { + verify_hostname: '', + verify_peer: '', + }, + }, + }, events: { process: true, file: true, diff --git a/x-pack/plugins/security_solution/common/endpoint/types.ts b/x-pack/plugins/security_solution/common/endpoint/types.ts index 2b8de7ed16b08..e73387294f908 100644 --- a/x-pack/plugins/security_solution/common/endpoint/types.ts +++ b/x-pack/plugins/security_solution/common/endpoint/types.ts @@ -763,6 +763,7 @@ type KbnConfigSchemaNonOptionalProps> = Pi */ export interface PolicyConfig { windows: { + advanced: AdvancedFields; events: { dll_and_driver_load: boolean; dns: boolean; @@ -778,6 +779,7 @@ export interface PolicyConfig { }; }; mac: { + advanced: AdvancedFields; events: { file: boolean; process: boolean; @@ -789,6 +791,7 @@ export interface PolicyConfig { }; }; linux: { + advanced: AdvancedFields; events: { file: boolean; process: boolean; @@ -800,6 +803,14 @@ export interface PolicyConfig { }; } +export interface AdvancedFields { + elasticsearch: { + tls: { + verify_hostname: string; + verify_peer: string; + }; + }; +} /** * The set of Policy configuration settings that are show/edited via the UI */ From 0889459b5c8f56f5b52f42fb110b0d52ad3a808c Mon Sep 17 00:00:00 2001 From: Jane Date: Mon, 31 Aug 2020 14:30:07 -0400 Subject: [PATCH 10/41] linting --- .../public/management/common/constants.ts | 1 + .../public/management/pages/policy/index.tsx | 8 ++++-- .../management/pages/policy/view/index.ts | 1 + .../pages/policy/view/policy_advanced.tsx | 25 +++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx diff --git a/x-pack/plugins/security_solution/public/management/common/constants.ts b/x-pack/plugins/security_solution/public/management/common/constants.ts index 06f0f09bcf54d..1a2b4ad6ee2ae 100644 --- a/x-pack/plugins/security_solution/public/management/common/constants.ts +++ b/x-pack/plugins/security_solution/public/management/common/constants.ts @@ -13,6 +13,7 @@ export const MANAGEMENT_ROUTING_ROOT_PATH = ''; export const MANAGEMENT_ROUTING_ENDPOINTS_PATH = `${MANAGEMENT_ROUTING_ROOT_PATH}/:tabName(${AdministrationSubTab.endpoints})`; export const MANAGEMENT_ROUTING_POLICIES_PATH = `${MANAGEMENT_ROUTING_ROOT_PATH}/:tabName(${AdministrationSubTab.policies})`; export const MANAGEMENT_ROUTING_POLICY_DETAILS_PATH = `${MANAGEMENT_ROUTING_ROOT_PATH}/:tabName(${AdministrationSubTab.policies})/:policyId`; +export const MANAGEMENT_ROUTING_POLICY_ADVANCED_PATH = `${MANAGEMENT_ROUTING_ROOT_PATH}/:tabName(${AdministrationSubTab.policies})/:policyId/advanced`; export const MANAGEMENT_ROUTING_TRUSTED_APPS_PATH = `${MANAGEMENT_ROUTING_ROOT_PATH}/:tabName(${AdministrationSubTab.trustedApps})`; // --[ STORE ]--------------------------------------------------------------------------- diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/index.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/index.tsx index 681f1f1430926..e47362d94bfe8 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/index.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/index.tsx @@ -6,14 +6,18 @@ import React, { memo } from 'react'; import { Route, Switch } from 'react-router-dom'; -import { PolicyDetails } from './view'; -import { MANAGEMENT_ROUTING_POLICY_DETAILS_PATH } from '../../common/constants'; +import { PolicyDetails, PolicyAdvanced } from './view'; +import { + MANAGEMENT_ROUTING_POLICY_DETAILS_PATH, + MANAGEMENT_ROUTING_POLICY_ADVANCED_PATH, +} from '../../common/constants'; import { NotFoundPage } from '../../../app/404'; export const PolicyContainer = memo(() => { return ( + ); diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/index.ts b/x-pack/plugins/security_solution/public/management/pages/policy/view/index.ts index 9c227ca81a426..ce942205b1620 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/index.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/index.ts @@ -6,3 +6,4 @@ export * from './policy_list'; export * from './policy_details'; +export * from './policy_advanced'; diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx new file mode 100644 index 0000000000000..e0b3933790608 --- /dev/null +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -0,0 +1,25 @@ +/* + * 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, { useCallback } from 'react'; +import { EuiFieldText, EuiText } from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { WrapperPage } from '../../../../common/components/wrapper_page'; + +export const PolicyAdvanced = React.memo(() => { + /* const onChange = useCallback((e) => {});*/ + return ( + + +

+ +

+
+ +
+ ); +}); +PolicyAdvanced.displayName = 'PolicyAdvanced'; From e868b25ff3f5c185ea286824c25eeeced8a331a7 Mon Sep 17 00:00:00 2001 From: Jane Date: Tue, 1 Sep 2020 10:42:08 -0400 Subject: [PATCH 11/41] flesh out callback --- .../common/endpoint/types.ts | 6 ++-- .../policy/store/policy_details/middleware.ts | 6 +++- .../policy/store/policy_details/selectors.ts | 20 ++++++++++-- .../public/management/pages/policy/types.ts | 3 ++ .../pages/policy/view/policy_advanced.tsx | 32 +++++++++++++++++-- 5 files changed, 59 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/security_solution/common/endpoint/types.ts b/x-pack/plugins/security_solution/common/endpoint/types.ts index e73387294f908..67b3ac84579a8 100644 --- a/x-pack/plugins/security_solution/common/endpoint/types.ts +++ b/x-pack/plugins/security_solution/common/endpoint/types.ts @@ -818,15 +818,15 @@ export interface UIPolicyConfig { /** * Windows-specific policy configuration that is supported via the UI */ - windows: Pick; + windows: Pick; /** * Mac-specific policy configuration that is supported via the UI */ - mac: Pick; + mac: Pick; /** * Linux-specific policy configuration that is supported via the UI */ - linux: Pick; + linux: Pick; } /** Policy: Malware protection fields */ diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/middleware.ts b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/middleware.ts index 250a5b25230f1..cad37cb6f0e00 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/middleware.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/middleware.ts @@ -12,6 +12,7 @@ import { policyDetails, policyDetailsForUpdate, getPolicyDataForUpdate, + isOnPolicyAdvancedPage, } from './selectors'; import { sendGetPackagePolicy, @@ -30,7 +31,10 @@ export const policyDetailsMiddlewareFactory: ImmutableMiddlewareFactory) => { ); }; +/** Returns a boolean of whether the user is on the advanced policy page or not */ +export const isOnPolicyAdvancedPage = (state: Immutable) => { + return ( + matchPath(state.location?.pathname ?? '', { + path: MANAGEMENT_ROUTING_POLICY_ADVANCED_PATH, + exact: true, + }) !== null + ); +}; + /** Returns the policyId from the url */ export const policyIdFromParams: (state: Immutable) => string = createSelector( (state) => state.location, (location: PolicyDetailsState['location']) => { return ( matchPath(location?.pathname ?? '', { - path: MANAGEMENT_ROUTING_POLICY_DETAILS_PATH, + path: [MANAGEMENT_ROUTING_POLICY_DETAILS_PATH, MANAGEMENT_ROUTING_POLICY_ADVANCED_PATH], exact: true, })?.params?.policyId ?? '' ); @@ -103,14 +116,17 @@ export const policyConfig: (s: PolicyDetailsState) => UIPolicyConfig = createSel (windows, mac, linux) => { return { windows: { + advanced: windows.advanced, events: windows.events, malware: windows.malware, }, mac: { + advanced: mac.advanced, events: mac.events, malware: mac.malware, }, linux: { + advanced: linux.advanced, events: linux.events, }, }; diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/types.ts b/x-pack/plugins/security_solution/public/management/pages/policy/types.ts index c7d426da05508..c8389f76a2a00 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/types.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/types.ts @@ -8,6 +8,7 @@ import { AppLocation, Immutable, MalwareFields, + AdvancedFields, PolicyData, UIPolicyConfig, } from '../../../../common/endpoint/types'; @@ -144,6 +145,8 @@ export enum OS { linux = 'linux', } +export type AdvancedOSes = KeysByValueCriteria; + /** * Returns the keys of an object whose values meet a criteria. * Ex) interface largeNestedObject = { diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index e0b3933790608..5487dd8c80700 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -5,12 +5,40 @@ */ import React, { useCallback } from 'react'; +import { useDispatch } from 'react-redux'; import { EuiFieldText, EuiText } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; +import { Immutable } from '../../../../../common/endpoint/types'; import { WrapperPage } from '../../../../common/components/wrapper_page'; +import { policyConfig } from '../store/policy_details/selectors'; +import { usePolicyDetailsSelector } from './policy_hooks'; +import { clone } from '../models/policy_details_config'; +import { AdvancedOSes, OS } from '../types'; export const PolicyAdvanced = React.memo(() => { - /* const onChange = useCallback((e) => {});*/ + const dispatch = useDispatch(); + // debugger; + const policyDetailsConfig = usePolicyDetailsSelector(policyConfig); + // console.log(policyDetailsConfig); + const OSes: Immutable = [OS.windows, OS.linux, OS.mac]; + const onChange = useCallback( + (event) => { + if (policyDetailsConfig) { + const newPayload = clone(policyDetailsConfig); + for (const os of OSes) { + newPayload[os].advanced.elasticsearch.tls.verify_peer = event.target.value; + } + dispatch({ + type: 'userChangedPolicyConfig', + payload: { policyConfig: newPayload }, + }); + } + }, + [dispatch, OSes, policyDetailsConfig] + ); + + const value = + policyDetailsConfig && policyDetailsConfig.windows.advanced.elasticsearch.tls.verify_peer; return ( @@ -18,7 +46,7 @@ export const PolicyAdvanced = React.memo(() => { - + ); }); From 41cfac00edc6046c62265377880e996cbb5abae6 Mon Sep 17 00:00:00 2001 From: Jane Date: Tue, 1 Sep 2020 14:55:19 -0400 Subject: [PATCH 12/41] add submit button for verify_peer --- .../policy/models/policy_details_config.ts | 41 +------------------ .../policy/store/policy_details/index.test.ts | 8 ++-- .../pages/policy/view/policy_advanced.tsx | 17 ++++++-- .../view/policy_forms/protections/malware.tsx | 6 +-- 4 files changed, 23 insertions(+), 49 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/models/policy_details_config.ts b/x-pack/plugins/security_solution/public/management/pages/policy/models/policy_details_config.ts index 4d32a9fbec694..8d5c19a9e489a 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/models/policy_details_config.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/models/policy_details_config.ts @@ -4,46 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ +import { cloneDeep } from 'lodash'; import { UIPolicyConfig } from '../../../../../common/endpoint/types'; -/** - * A typed Object.entries() function where the keys and values are typed based on the given object - */ -const entries = (o: T): Array<[keyof T, T[keyof T]]> => - Object.entries(o) as Array<[keyof T, T[keyof T]]>; -type DeepPartial = { [K in keyof T]?: DeepPartial }; - -/** - * Returns a deep copy of `UIPolicyConfig` object - */ -export function clone(policyDetailsConfig: UIPolicyConfig): UIPolicyConfig { - const clonedConfig: DeepPartial = {}; - for (const [key, val] of entries(policyDetailsConfig)) { - if (typeof val === 'object') { - const valClone: Partial = {}; - clonedConfig[key] = valClone; - for (const [key2, val2] of entries(val)) { - if (typeof val2 === 'object') { - valClone[key2] = { - ...val2, - }; - } else { - clonedConfig[key] = { - ...val, - }; - } - } - } else { - clonedConfig[key] = val; - } - } - - /** - * clonedConfig is typed as DeepPartial so we can construct the copy from an empty object - */ - return clonedConfig as UIPolicyConfig; -} - /** * Returns value from `configuration` */ @@ -69,7 +32,7 @@ export const setIn = (a: UIPolicyConfig) => (k >( v: V ): UIPolicyConfig => { - const c = clone(a); + const c = cloneDeep(a); c[key][subKey][leafKey] = v; return c; }; diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/index.test.ts b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/index.test.ts index 0eedecef22170..d5253f0b476c2 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/index.test.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/index.test.ts @@ -8,7 +8,6 @@ import { PolicyDetailsState } from '../../types'; import { applyMiddleware, createStore, Dispatch, Store } from 'redux'; import { policyDetailsReducer, PolicyDetailsAction, policyDetailsMiddlewareFactory } from './index'; import { policyConfig } from './selectors'; -import { clone } from '../../models/policy_details_config'; import { factory as policyConfigFactory } from '../../../../../../common/endpoint/models/policy_config'; import { PolicyData } from '../../../../../../common/endpoint/types'; import { @@ -20,6 +19,7 @@ import { createAppRootMockRenderer, } from '../../../../../common/mock/endpoint'; import { HttpFetchOptions } from 'kibana/public'; +import { cloneDeep } from 'lodash'; describe('policy details: ', () => { let store: Store; @@ -93,7 +93,7 @@ describe('policy details: ', () => { throw new Error(); } - const newPayload1 = clone(config); + const newPayload1 = cloneDeep(config); newPayload1.windows.events.process = true; dispatch({ @@ -115,7 +115,7 @@ describe('policy details: ', () => { throw new Error(); } - const newPayload1 = clone(config); + const newPayload1 = cloneDeep(config); newPayload1.mac.events.file = true; dispatch({ @@ -137,7 +137,7 @@ describe('policy details: ', () => { throw new Error(); } - const newPayload1 = clone(config); + const newPayload1 = cloneDeep(config); newPayload1.linux.events.file = true; dispatch({ diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index 5487dd8c80700..af972c5c2b62d 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -6,13 +6,13 @@ import React, { useCallback } from 'react'; import { useDispatch } from 'react-redux'; -import { EuiFieldText, EuiText } from '@elastic/eui'; +import { EuiButton, EuiFieldText, EuiText } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; +import { cloneDeep } from 'lodash'; import { Immutable } from '../../../../../common/endpoint/types'; import { WrapperPage } from '../../../../common/components/wrapper_page'; import { policyConfig } from '../store/policy_details/selectors'; import { usePolicyDetailsSelector } from './policy_hooks'; -import { clone } from '../models/policy_details_config'; import { AdvancedOSes, OS } from '../types'; export const PolicyAdvanced = React.memo(() => { @@ -24,7 +24,7 @@ export const PolicyAdvanced = React.memo(() => { const onChange = useCallback( (event) => { if (policyDetailsConfig) { - const newPayload = clone(policyDetailsConfig); + const newPayload = cloneDeep(policyDetailsConfig); for (const os of OSes) { newPayload[os].advanced.elasticsearch.tls.verify_peer = event.target.value; } @@ -39,6 +39,11 @@ export const PolicyAdvanced = React.memo(() => { const value = policyDetailsConfig && policyDetailsConfig.windows.advanced.elasticsearch.tls.verify_peer; + const onClick = useCallback(() => { + dispatch({ + type: 'userClickedPolicyDetailsSaveButton', + }); + }, [dispatch]); return ( @@ -47,6 +52,12 @@ export const PolicyAdvanced = React.memo(() => { + + + ); }); diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_forms/protections/malware.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_forms/protections/malware.tsx index 1698f5bc3fd0c..40b994cb30afd 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_forms/protections/malware.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_forms/protections/malware.tsx @@ -17,6 +17,7 @@ import { } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; +import { cloneDeep } from 'lodash'; import { APP_ID } from '../../../../../../../common/constants'; import { SecurityPageName } from '../../../../../../app/types'; @@ -25,7 +26,6 @@ import { OS, MalwareProtectionOSes } from '../../../types'; import { ConfigForm } from '../config_form'; import { policyConfig } from '../../../store/policy_details/selectors'; import { usePolicyDetailsSelector } from '../../policy_hooks'; -import { clone } from '../../../models/policy_details_config'; import { LinkToApp } from '../../../../../../common/components/endpoint/link_to_app'; const ProtectionRadioGroup = styled.div` @@ -47,7 +47,7 @@ const ProtectionRadio = React.memo(({ id, label }: { id: ProtectionModes; label: const handleRadioChange = useCallback(() => { if (policyDetailsConfig) { - const newPayload = clone(policyDetailsConfig); + const newPayload = cloneDeep(policyDetailsConfig); for (const os of OSes) { newPayload[os][protection].mode = id; } @@ -112,7 +112,7 @@ export const MalwareProtections = React.memo(() => { const handleSwitchChange = useCallback( (event) => { if (policyDetailsConfig) { - const newPayload = clone(policyDetailsConfig); + const newPayload = cloneDeep(policyDetailsConfig); if (event.target.checked === false) { for (const os of OSes) { newPayload[os][protection].mode = ProtectionModes.off; From 67b12d2fb3fed4dffb8fb9183921f8108254a165 Mon Sep 17 00:00:00 2001 From: Jane Date: Thu, 3 Sep 2020 16:50:07 -0400 Subject: [PATCH 13/41] add verify hostname field --- .../pages/policy/view/policy_advanced.tsx | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index af972c5c2b62d..f2f1427a9df95 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -21,7 +21,7 @@ export const PolicyAdvanced = React.memo(() => { const policyDetailsConfig = usePolicyDetailsSelector(policyConfig); // console.log(policyDetailsConfig); const OSes: Immutable = [OS.windows, OS.linux, OS.mac]; - const onChange = useCallback( + const onVerifyPeerChange = useCallback( (event) => { if (policyDetailsConfig) { const newPayload = cloneDeep(policyDetailsConfig); @@ -37,8 +37,26 @@ export const PolicyAdvanced = React.memo(() => { [dispatch, OSes, policyDetailsConfig] ); - const value = + const onVerifyHostnameChange = useCallback( + (event) => { + if (policyDetailsConfig) { + const newPayload = cloneDeep(policyDetailsConfig); + for (const os of OSes) { + newPayload[os].advanced.elasticsearch.tls.verify_hostname = event.target.value; + } + dispatch({ + type: 'userChangedPolicyConfig', + payload: { policyConfig: newPayload }, + }); + } + }, + [dispatch, OSes, policyDetailsConfig] + ); + + const verifyPeerValue = policyDetailsConfig && policyDetailsConfig.windows.advanced.elasticsearch.tls.verify_peer; + const verifyHostnameValue = + policyDetailsConfig && policyDetailsConfig.windows.advanced.elasticsearch.tls.verify_hostname; const onClick = useCallback(() => { dispatch({ type: 'userClickedPolicyDetailsSaveButton', @@ -51,7 +69,8 @@ export const PolicyAdvanced = React.memo(() => { - + + Date: Thu, 10 Sep 2020 16:23:45 -0400 Subject: [PATCH 14/41] 145 generalize cb --- .../public/management/pages/policy/index.tsx | 8 +- .../policy/models/advanced_policy_schema.json | 11 +++ .../pages/policy/view/policy_advanced.tsx | 78 ++++++++++--------- .../pages/policy/view/policy_details.tsx | 5 ++ 4 files changed, 58 insertions(+), 44 deletions(-) create mode 100644 x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.json diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/index.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/index.tsx index e47362d94bfe8..681f1f1430926 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/index.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/index.tsx @@ -6,18 +6,14 @@ import React, { memo } from 'react'; import { Route, Switch } from 'react-router-dom'; -import { PolicyDetails, PolicyAdvanced } from './view'; -import { - MANAGEMENT_ROUTING_POLICY_DETAILS_PATH, - MANAGEMENT_ROUTING_POLICY_ADVANCED_PATH, -} from '../../common/constants'; +import { PolicyDetails } from './view'; +import { MANAGEMENT_ROUTING_POLICY_DETAILS_PATH } from '../../common/constants'; import { NotFoundPage } from '../../../app/404'; export const PolicyContainer = memo(() => { return ( - ); diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.json b/x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.json new file mode 100644 index 0000000000000..db3fbe4134e02 --- /dev/null +++ b/x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.json @@ -0,0 +1,11 @@ +[ + { + "key": "windows.advanced.elasticsearch.tls.verify_peer", + "first_supported_version": "7.10", + "last_supported_version": "7.13" + }, + { + "key": "windows.advanced.elasticsearch.tls.verify_hostname", + "first_supported_version": "7.10" + } +] \ No newline at end of file diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index f2f1427a9df95..5865cde97e4c7 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -15,34 +15,48 @@ import { policyConfig } from '../store/policy_details/selectors'; import { usePolicyDetailsSelector } from './policy_hooks'; import { AdvancedOSes, OS } from '../types'; -export const PolicyAdvanced = React.memo(() => { +// function set(obj: Record, value: unknown, firstPathPart: string, secondPathPart?: string, ...rest: string[]) { +// if (secondPathPart === undefined) { +// obj[firstPathPart] = value +// } else { +// set(obj[firstPathPart] as Record, value, secondPathPart, ...rest) +// } +// } + +function setAgain(obj: Record, value: string, path: string[]) { + // console.log("path.length: ", path.length); + let whatever = obj; + while (path.length > 1) { + whatever = whatever[path.shift()!] as Record; + // console.log("whatever: ", whatever); + } + whatever[path[0]] = value; +} + +function getValue(obj: Record, path: string[]) { + let whatever = obj; + while (path.length > 1) { + whatever = whatever[path.shift()!] as Record; + } + return whatever[path[0]]; +} + +export const PolicyAdvanced = React.memo(({ configPath }: { configPath: string[] }) => { const dispatch = useDispatch(); // debugger; const policyDetailsConfig = usePolicyDetailsSelector(policyConfig); // console.log(policyDetailsConfig); const OSes: Immutable = [OS.windows, OS.linux, OS.mac]; - const onVerifyPeerChange = useCallback( - (event) => { - if (policyDetailsConfig) { - const newPayload = cloneDeep(policyDetailsConfig); - for (const os of OSes) { - newPayload[os].advanced.elasticsearch.tls.verify_peer = event.target.value; - } - dispatch({ - type: 'userChangedPolicyConfig', - payload: { policyConfig: newPayload }, - }); - } - }, - [dispatch, OSes, policyDetailsConfig] - ); - const onVerifyHostnameChange = useCallback( + const onChange = useCallback( (event) => { + // console.log(event.target.value) if (policyDetailsConfig) { const newPayload = cloneDeep(policyDetailsConfig); + for (const os of OSes) { - newPayload[os].advanced.elasticsearch.tls.verify_hostname = event.target.value; + // console.log("configPath: ", configPath); + setAgain(newPayload[os], event.target.value, configPath); } dispatch({ type: 'userChangedPolicyConfig', @@ -50,34 +64,22 @@ export const PolicyAdvanced = React.memo(() => { }); } }, - [dispatch, OSes, policyDetailsConfig] + [dispatch, OSes, policyDetailsConfig, configPath] ); - const verifyPeerValue = - policyDetailsConfig && policyDetailsConfig.windows.advanced.elasticsearch.tls.verify_peer; - const verifyHostnameValue = - policyDetailsConfig && policyDetailsConfig.windows.advanced.elasticsearch.tls.verify_hostname; - const onClick = useCallback(() => { - dispatch({ - type: 'userClickedPolicyDetailsSaveButton', - }); - }, [dispatch]); + const value = policyDetailsConfig && getValue(policyDetailsConfig.windows, configPath); + // console.log(policyDetailsConfig); + // console.log(configPath, value); + return ( - + <>

- - - - - -
+ + ); }); PolicyAdvanced.displayName = 'PolicyAdvanced'; diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx index 235f150637116..70b6084bf0f36 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx @@ -47,6 +47,7 @@ import { MANAGEMENT_APP_ID } from '../../../common/constants'; import { PolicyDetailsRouteState } from '../../../../../common/endpoint/types'; import { WrapperPage } from '../../../../common/components/wrapper_page'; import { HeaderPage } from '../../../../common/components/header_page'; +import { PolicyAdvanced } from './policy_advanced'; export const PolicyDetails = React.memo(() => { const dispatch = useDispatch<(action: AppAction) => void>(); @@ -244,6 +245,10 @@ export const PolicyDetails = React.memo(() => { + + + + {/* */} From 59c81702c101a2d30571437b12dd4887c8844e72 Mon Sep 17 00:00:00 2001 From: Jane Date: Thu, 10 Sep 2020 17:04:59 -0400 Subject: [PATCH 15/41] 145 fix setAgain and getValue --- .../pages/policy/view/policy_advanced.tsx | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index 5865cde97e4c7..31caa285b762e 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -26,19 +26,19 @@ import { AdvancedOSes, OS } from '../types'; function setAgain(obj: Record, value: string, path: string[]) { // console.log("path.length: ", path.length); let whatever = obj; - while (path.length > 1) { - whatever = whatever[path.shift()!] as Record; - // console.log("whatever: ", whatever); + for (let i = 0; i < path.length - 1; i++) { + whatever = whatever[path[i]] as Record; } - whatever[path[0]] = value; + whatever[path[path.length - 1]] = value; } function getValue(obj: Record, path: string[]) { let whatever = obj; - while (path.length > 1) { - whatever = whatever[path.shift()!] as Record; + + for (let i = 0; i < path.length - 1; i++) { + whatever = whatever[path[i]] as Record; } - return whatever[path[0]]; + return whatever[path[path.length - 1]]; } export const PolicyAdvanced = React.memo(({ configPath }: { configPath: string[] }) => { @@ -47,7 +47,7 @@ export const PolicyAdvanced = React.memo(({ configPath }: { configPath: string[] const policyDetailsConfig = usePolicyDetailsSelector(policyConfig); // console.log(policyDetailsConfig); const OSes: Immutable = [OS.windows, OS.linux, OS.mac]; - + // console.log("configPath: ", configPath); const onChange = useCallback( (event) => { // console.log(event.target.value) @@ -75,7 +75,10 @@ export const PolicyAdvanced = React.memo(({ configPath }: { configPath: string[] <>

- +

From ff425c82611f0e0c27798d38f1695f1c69132d0a Mon Sep 17 00:00:00 2001 From: Jane Date: Wed, 23 Sep 2020 11:54:18 -0400 Subject: [PATCH 16/41] 145 merge conflict --- .../common/endpoint/models/policy_config.ts | 2 +- .../common/endpoint/types/index.ts | 7 +++--- .../policy/store/policy_details/index.test.ts | 24 +++++++++++++++++++ .../apps/endpoint/policy_details.ts | 24 +++++++++++++++++++ 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/security_solution/common/endpoint/models/policy_config.ts b/x-pack/plugins/security_solution/common/endpoint/models/policy_config.ts index a2a024e3e5c0c..e6d21485fa5e9 100644 --- a/x-pack/plugins/security_solution/common/endpoint/models/policy_config.ts +++ b/x-pack/plugins/security_solution/common/endpoint/models/policy_config.ts @@ -15,7 +15,7 @@ export const factory = (): PolicyConfig => { advanced: { elasticsearch: { tls: { - verify_hostname: 'false', + verify_hostname: '', verify_peer: '', }, }, diff --git a/x-pack/plugins/security_solution/common/endpoint/types/index.ts b/x-pack/plugins/security_solution/common/endpoint/types/index.ts index 135c94a055d43..a29ee0c9fc868 100644 --- a/x-pack/plugins/security_solution/common/endpoint/types/index.ts +++ b/x-pack/plugins/security_solution/common/endpoint/types/index.ts @@ -843,7 +843,7 @@ type KbnConfigSchemaNonOptionalProps> = Pi */ export interface PolicyConfig { windows: { - advanced: AdvancedFields; + advanced?: AdvancedFields; // will be introduced in 7.11+ events: { dll_and_driver_load: boolean; dns: boolean; @@ -859,7 +859,7 @@ export interface PolicyConfig { }; }; mac: { - advanced: AdvancedFields; + advanced?: AdvancedFields; events: { file: boolean; process: boolean; @@ -871,7 +871,7 @@ export interface PolicyConfig { }; }; linux: { - advanced: AdvancedFields; + advanced?: AdvancedFields; events: { file: boolean; process: boolean; @@ -891,6 +891,7 @@ export interface AdvancedFields { }; }; } + /** * The set of Policy configuration settings that are show/edited via the UI */ diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/index.test.ts b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/index.test.ts index d5253f0b476c2..e6b8f0043c2ef 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/index.test.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/index.test.ts @@ -228,6 +228,14 @@ describe('policy details: ', () => { policy: { value: { windows: { + advanced: { + elasticsearch: { + tls: { + verify_hostname: '', + verify_peer: '', + }, + }, + }, events: { dll_and_driver_load: true, dns: false, @@ -241,11 +249,27 @@ describe('policy details: ', () => { logging: { file: 'info' }, }, mac: { + advanced: { + elasticsearch: { + tls: { + verify_hostname: '', + verify_peer: '', + }, + }, + }, events: { process: true, file: true, network: true }, malware: { mode: 'prevent' }, logging: { file: 'info' }, }, linux: { + advanced: { + elasticsearch: { + tls: { + verify_hostname: '', + verify_peer: '', + }, + }, + }, events: { process: true, file: true, network: true }, logging: { file: 'info' }, }, diff --git a/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts b/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts index 9610144d3846d..972531ce54992 100644 --- a/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts +++ b/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts @@ -200,15 +200,39 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { }, policy: { linux: { + advanced: { + elasticsearch: { + tls: { + verify_hostname: '', + verify_peer: '', + }, + }, + }, events: { file: false, network: true, process: true }, logging: { file: 'info' }, }, mac: { + advanced: { + elasticsearch: { + tls: { + verify_hostname: '', + verify_peer: '', + }, + }, + }, events: { file: false, network: true, process: true }, logging: { file: 'info' }, malware: { mode: 'prevent' }, }, windows: { + advanced: { + elasticsearch: { + tls: { + verify_hostname: '', + verify_peer: '', + }, + }, + }, events: { dll_and_driver_load: true, dns: true, From 3726588cd3e1afb00f30c72c0dad348568d0a694 Mon Sep 17 00:00:00 2001 From: Jane Date: Wed, 23 Sep 2020 17:23:01 -0400 Subject: [PATCH 17/41] 145 add verify_hostname back, start loop for form --- .../pages/policy/view/policy_details.tsx | 14 +++++++++++++- x-pack/plugins/security_solution/schema.json | 13 +++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugins/security_solution/schema.json diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx index 70b6084bf0f36..7d6d771b3a03d 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx @@ -48,6 +48,18 @@ import { PolicyDetailsRouteState } from '../../../../../common/endpoint/types'; import { WrapperPage } from '../../../../common/components/wrapper_page'; import { HeaderPage } from '../../../../common/components/header_page'; import { PolicyAdvanced } from './policy_advanced'; +import * as AdvancedPolicySchema from '../../../../../schema.json'; + +type AdvancedPolicySchemaType = {key: string, first_supported_version: string, last_supported_version: string}; + +const AdvancedPolicyForms = React.memo(() => { + ((AdvancedPolicySchema as unknown) as AdvancedPolicySchemaType[]).map((advancedKey, index) => { + const configPath = advancedKey.key.split('.'); + configPath.shift(); // removes the os - need to change later + console.log(configPath); + return (); + }) +}); export const PolicyDetails = React.memo(() => { const dispatch = useDispatch<(action: AppAction) => void>(); @@ -248,7 +260,7 @@ export const PolicyDetails = React.memo(() => { - {/* */} + diff --git a/x-pack/plugins/security_solution/schema.json b/x-pack/plugins/security_solution/schema.json new file mode 100644 index 0000000000000..025b4901a3160 --- /dev/null +++ b/x-pack/plugins/security_solution/schema.json @@ -0,0 +1,13 @@ +[ + { + "key": "windows.advanced.elasticsearch.tls.verify_peer", + "first_supported_version": "7.10", + "last_supported_version": "7.13", + "documentation": "whether to verify tls peer" + }, + { + "key": "windows.advanced.elasticsearch.tls.verify_hostname", + "first_supported_version": "7.10", + "documentation": "whether to verify tls hostname" + }, +] \ No newline at end of file From 0b98114890bdce6d9a9fa3f8db3262c688eda791 Mon Sep 17 00:00:00 2001 From: Jane Date: Mon, 28 Sep 2020 15:13:04 -0400 Subject: [PATCH 18/41] 145 remove OS trick --- .../pages/policy/view/policy_advanced.tsx | 122 +++++++++--------- .../pages/policy/view/policy_details.tsx | 35 +++-- x-pack/plugins/security_solution/schema.json | 2 +- 3 files changed, 86 insertions(+), 73 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index 31caa285b762e..da188a4086317 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -6,83 +6,85 @@ import React, { useCallback } from 'react'; import { useDispatch } from 'react-redux'; -import { EuiButton, EuiFieldText, EuiText } from '@elastic/eui'; +import { EuiFieldText, EuiText, EuiIconTip } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { cloneDeep } from 'lodash'; -import { Immutable } from '../../../../../common/endpoint/types'; -import { WrapperPage } from '../../../../common/components/wrapper_page'; import { policyConfig } from '../store/policy_details/selectors'; import { usePolicyDetailsSelector } from './policy_hooks'; -import { AdvancedOSes, OS } from '../types'; -// function set(obj: Record, value: unknown, firstPathPart: string, secondPathPart?: string, ...rest: string[]) { -// if (secondPathPart === undefined) { -// obj[firstPathPart] = value -// } else { -// set(obj[firstPathPart] as Record, value, secondPathPart, ...rest) -// } -// } - -function setAgain(obj: Record, value: string, path: string[]) { - // console.log("path.length: ", path.length); - let whatever = obj; +function setValue(obj: Record, value: string, path: string[]) { + let newPolicyConfig = obj; for (let i = 0; i < path.length - 1; i++) { - whatever = whatever[path[i]] as Record; + newPolicyConfig = newPolicyConfig[path[i]] as Record; } - whatever[path[path.length - 1]] = value; + newPolicyConfig[path[path.length - 1]] = value; } function getValue(obj: Record, path: string[]) { - let whatever = obj; + let currentPolicyConfig = obj; for (let i = 0; i < path.length - 1; i++) { - whatever = whatever[path[i]] as Record; + currentPolicyConfig = currentPolicyConfig[path[i]] as Record; } - return whatever[path[path.length - 1]]; + return currentPolicyConfig[path[path.length - 1]]; } -export const PolicyAdvanced = React.memo(({ configPath }: { configPath: string[] }) => { - const dispatch = useDispatch(); - // debugger; - const policyDetailsConfig = usePolicyDetailsSelector(policyConfig); - // console.log(policyDetailsConfig); - const OSes: Immutable = [OS.windows, OS.linux, OS.mac]; - // console.log("configPath: ", configPath); - const onChange = useCallback( - (event) => { - // console.log(event.target.value) - if (policyDetailsConfig) { - const newPayload = cloneDeep(policyDetailsConfig); +export const PolicyAdvanced = React.memo( + ({ + configPath, + firstSupportedVersion, + lastSupportedVersion, + }: { + configPath: string[]; + firstSupportedVersion: string; + lastSupportedVersion?: string; + }) => { + const dispatch = useDispatch(); + const policyDetailsConfig = usePolicyDetailsSelector(policyConfig); + const onChange = useCallback( + (event) => { + if (policyDetailsConfig) { + const newPayload = cloneDeep(policyDetailsConfig); - for (const os of OSes) { - // console.log("configPath: ", configPath); - setAgain(newPayload[os], event.target.value, configPath); + setValue( + (newPayload as unknown) as Record, + event.target.value, + configPath + ); + dispatch({ + type: 'userChangedPolicyConfig', + payload: { policyConfig: newPayload }, + }); } - dispatch({ - type: 'userChangedPolicyConfig', - payload: { policyConfig: newPayload }, - }); - } - }, - [dispatch, OSes, policyDetailsConfig, configPath] - ); + }, + [dispatch, policyDetailsConfig, configPath] + ); - const value = policyDetailsConfig && getValue(policyDetailsConfig.windows, configPath); - // console.log(policyDetailsConfig); - // console.log(configPath, value); + const value = + policyDetailsConfig && + getValue((policyDetailsConfig as unknown) as Record, configPath); - return ( - <> - -

- -

-
- - - ); -}); + return ( + <> + +

+ +

+
+ + + + ); + } +); PolicyAdvanced.displayName = 'PolicyAdvanced'; diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx index 7d6d771b3a03d..76cc3265b8b69 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx @@ -50,16 +50,11 @@ import { HeaderPage } from '../../../../common/components/header_page'; import { PolicyAdvanced } from './policy_advanced'; import * as AdvancedPolicySchema from '../../../../../schema.json'; -type AdvancedPolicySchemaType = {key: string, first_supported_version: string, last_supported_version: string}; - -const AdvancedPolicyForms = React.memo(() => { - ((AdvancedPolicySchema as unknown) as AdvancedPolicySchemaType[]).map((advancedKey, index) => { - const configPath = advancedKey.key.split('.'); - configPath.shift(); // removes the os - need to change later - console.log(configPath); - return (); - }) -}); +interface AdvancedPolicySchemaType { + key: string; + first_supported_version: string; + last_supported_version: string; +} export const PolicyDetails = React.memo(() => { const dispatch = useDispatch<(action: AppAction) => void>(); @@ -85,6 +80,22 @@ export const PolicyDetails = React.memo(() => { const policyName = policyItem?.name ?? ''; const hostListRouterPath = getEndpointListPath({ name: 'endpointList' }); + const AdvancedPolicyForms = () => { + return ((AdvancedPolicySchema as unknown) as AdvancedPolicySchemaType[]).map( + (advancedField, index) => { + const configPath = advancedField.key.split('.'); + return ( + + ); + } + ); + }; + // Handle showing update statuses useEffect(() => { if (policyUpdateStatus) { @@ -259,8 +270,8 @@ export const PolicyDetails = React.memo(() => { - - + + diff --git a/x-pack/plugins/security_solution/schema.json b/x-pack/plugins/security_solution/schema.json index 025b4901a3160..747016373afa8 100644 --- a/x-pack/plugins/security_solution/schema.json +++ b/x-pack/plugins/security_solution/schema.json @@ -9,5 +9,5 @@ "key": "windows.advanced.elasticsearch.tls.verify_hostname", "first_supported_version": "7.10", "documentation": "whether to verify tls hostname" - }, + } ] \ No newline at end of file From 201f43390acaa15275e71f14d5d4e7cc8c6d3825 Mon Sep 17 00:00:00 2001 From: Jane Date: Tue, 29 Sep 2020 10:20:02 -0400 Subject: [PATCH 19/41] 145 make AdvancedPolicyForms its own component --- .../pages/policy/view/policy_details.tsx | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx index 76cc3265b8b69..12e78e29899ce 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx @@ -56,6 +56,28 @@ interface AdvancedPolicySchemaType { last_supported_version: string; } +const AdvancedPolicyForms = React.memo(() => { + return ( + <> + {((AdvancedPolicySchema as unknown) as AdvancedPolicySchemaType[]).map( + (advancedField, index) => { + const configPath = advancedField.key.split('.'); + return ( + + ); + } + )} + + ); +}); + +AdvancedPolicyForms.displayName = 'AdvancedPolicyForms'; + export const PolicyDetails = React.memo(() => { const dispatch = useDispatch<(action: AppAction) => void>(); const { @@ -80,22 +102,6 @@ export const PolicyDetails = React.memo(() => { const policyName = policyItem?.name ?? ''; const hostListRouterPath = getEndpointListPath({ name: 'endpointList' }); - const AdvancedPolicyForms = () => { - return ((AdvancedPolicySchema as unknown) as AdvancedPolicySchemaType[]).map( - (advancedField, index) => { - const configPath = advancedField.key.split('.'); - return ( - - ); - } - ); - }; - // Handle showing update statuses useEffect(() => { if (policyUpdateStatus) { From e534356653a6e1e902f485d94347c58b7d736c8a Mon Sep 17 00:00:00 2001 From: Jane Date: Thu, 1 Oct 2020 14:13:46 -0400 Subject: [PATCH 20/41] 145 grid partially working --- .../pages/policy/view/policy_advanced.tsx | 160 ++++++++++++------ .../pages/policy/view/policy_details.tsx | 31 +--- 2 files changed, 105 insertions(+), 86 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index da188a4086317..16b69fddb715a 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -4,13 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { useCallback } from 'react'; +import React, { useCallback, useState, useMemo, useEffect } from 'react'; import { useDispatch } from 'react-redux'; -import { EuiFieldText, EuiText, EuiIconTip } from '@elastic/eui'; -import { FormattedMessage } from '@kbn/i18n/react'; +import { EuiFieldText, EuiDataGrid } from '@elastic/eui'; import { cloneDeep } from 'lodash'; import { policyConfig } from '../store/policy_details/selectors'; import { usePolicyDetailsSelector } from './policy_hooks'; +import * as AdvancedPolicySchema from '../../../../../schema.json'; function setValue(obj: Record, value: string, path: string[]) { let newPolicyConfig = obj; @@ -29,62 +29,110 @@ function getValue(obj: Record, path: string[]) { return currentPolicyConfig[path[path.length - 1]]; } -export const PolicyAdvanced = React.memo( - ({ - configPath, - firstSupportedVersion, - lastSupportedVersion, - }: { - configPath: string[]; - firstSupportedVersion: string; - lastSupportedVersion?: string; - }) => { - const dispatch = useDispatch(); - const policyDetailsConfig = usePolicyDetailsSelector(policyConfig); - const onChange = useCallback( - (event) => { - if (policyDetailsConfig) { - const newPayload = cloneDeep(policyDetailsConfig); - - setValue( - (newPayload as unknown) as Record, - event.target.value, - configPath - ); - dispatch({ - type: 'userChangedPolicyConfig', - payload: { policyConfig: newPayload }, - }); - } - }, - [dispatch, policyDetailsConfig, configPath] - ); +interface AdvancedPolicySchemaType { + key: string; + first_supported_version: string; + last_supported_version: string; +} + +export const PolicyAdvanced = React.memo(() => { + const dispatch = useDispatch(); + const policyDetailsConfig = usePolicyDetailsSelector(policyConfig); + + const onChange = useCallback( + (configPath: string[]) => (event) => { + if (policyDetailsConfig) { + const newPayload = cloneDeep(policyDetailsConfig); + + setValue( + (newPayload as unknown) as Record, + event.target.value, + configPath + ); + dispatch({ + type: 'userChangedPolicyConfig', + payload: { policyConfig: newPayload }, + }); + } + }, + [dispatch, policyDetailsConfig] + ); + + const rawData = []; + const columns = [ + { + id: 'Field name', + }, + { + id: 'Supported endpoint version', + }, + { + id: 'Value', + }, + ]; + + ((AdvancedPolicySchema as unknown) as AdvancedPolicySchemaType[]).map((advancedField, index) => { + const configPath = advancedField.key.split('.'); const value = policyDetailsConfig && getValue((policyDetailsConfig as unknown) as Record, configPath); - return ( - <> - -

- -

-
- - - - ); - } -); + // console.log(configPath, value); + return rawData.push({ + 'Field name': advancedField.key, + 'Supported endpoint version': advancedField.last_supported_version + ? `${advancedField.first_supported_version}-${advancedField.last_supported_version}` + : `${advancedField.first_supported_version}+`, + Value: , + }); + }); + + // Column visibility + const [visibleColumns, setVisibleColumns] = useState(() => columns.map(({ id }) => id)); // initialize to the full set of columns + + const renderCellValue = useMemo(() => { + return ({ rowIndex, columnId, setCellProps }) => { + // eslint-disable-next-line react-hooks/rules-of-hooks + useEffect(() => { + if (columnId === 'Value') { + // if (rawData.hasOwnProperty(rowIndex)) { + setCellProps({ + style: { + backgroundColor: '#fffcdd', + }, + }); + // } + } + }, [rowIndex, columnId, setCellProps]); + + return Object.prototype.hasOwnProperty.call(rawData, rowIndex) + ? rawData[rowIndex][columnId] + : null; + }; + }, [rawData]); + + return ( + { + // console.log(eventData); + }} + /> + ); +}); + PolicyAdvanced.displayName = 'PolicyAdvanced'; diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx index df6ae19afcf55..0dbbd1034fe5a 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx @@ -48,35 +48,6 @@ import { PolicyDetailsRouteState } from '../../../../../common/endpoint/types'; import { WrapperPage } from '../../../../common/components/wrapper_page'; import { HeaderPage } from '../../../../common/components/header_page'; import { PolicyAdvanced } from './policy_advanced'; -import * as AdvancedPolicySchema from '../../../../../schema.json'; - -interface AdvancedPolicySchemaType { - key: string; - first_supported_version: string; - last_supported_version: string; -} - -const AdvancedPolicyForms = React.memo(() => { - return ( - <> - {((AdvancedPolicySchema as unknown) as AdvancedPolicySchemaType[]).map( - (advancedField, index) => { - const configPath = advancedField.key.split('.'); - return ( - - ); - } - )} - - ); -}); - -AdvancedPolicyForms.displayName = 'AdvancedPolicyForms'; export const PolicyDetails = React.memo(() => { const dispatch = useDispatch<(action: AppAction) => void>(); @@ -278,7 +249,7 @@ export const PolicyDetails = React.memo(() => { - + From aa94cda327268dd16392e2802bdab771d1e832f3 Mon Sep 17 00:00:00 2001 From: Jane Date: Thu, 8 Oct 2020 14:17:51 -0400 Subject: [PATCH 21/41] 145 back to basics --- .../pages/policy/view/policy_advanced.tsx | 280 +++++++++++------- .../pages/policy/view/policy_details.tsx | 32 +- 2 files changed, 211 insertions(+), 101 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index 16b69fddb715a..c2f85f716eaf2 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -6,11 +6,11 @@ import React, { useCallback, useState, useMemo, useEffect } from 'react'; import { useDispatch } from 'react-redux'; -import { EuiFieldText, EuiDataGrid } from '@elastic/eui'; +import { EuiFieldText, EuiText, FormattedMessage, EuiIconTip/*, EuiDataGrid, EuiPopover, EuiButtonIcon*/ } from '@elastic/eui'; import { cloneDeep } from 'lodash'; import { policyConfig } from '../store/policy_details/selectors'; import { usePolicyDetailsSelector } from './policy_hooks'; -import * as AdvancedPolicySchema from '../../../../../schema.json'; +//import * as AdvancedPolicySchema from '../../../../../schema.json'; function setValue(obj: Record, value: string, path: string[]) { let newPolicyConfig = obj; @@ -29,110 +29,190 @@ function getValue(obj: Record, path: string[]) { return currentPolicyConfig[path[path.length - 1]]; } -interface AdvancedPolicySchemaType { - key: string; - first_supported_version: string; - last_supported_version: string; -} - -export const PolicyAdvanced = React.memo(() => { - const dispatch = useDispatch(); - const policyDetailsConfig = usePolicyDetailsSelector(policyConfig); - - const onChange = useCallback( - (configPath: string[]) => (event) => { - if (policyDetailsConfig) { - const newPayload = cloneDeep(policyDetailsConfig); - - setValue( - (newPayload as unknown) as Record, - event.target.value, - configPath - ); - dispatch({ - type: 'userChangedPolicyConfig', - payload: { policyConfig: newPayload }, - }); - } - }, - [dispatch, policyDetailsConfig] - ); - - const rawData = []; - const columns = [ - { - id: 'Field name', - }, - { - id: 'Supported endpoint version', - }, - { - id: 'Value', - }, - ]; - - ((AdvancedPolicySchema as unknown) as AdvancedPolicySchemaType[]).map((advancedField, index) => { - const configPath = advancedField.key.split('.'); +export const PolicyAdvanced = React.memo( + ({ + configPath, + firstSupportedVersion, + lastSupportedVersion, + }: { + configPath: string[]; + firstSupportedVersion: string; + lastSupportedVersion?: string; + }) => { + const dispatch = useDispatch(); + const policyDetailsConfig = usePolicyDetailsSelector(policyConfig); + const onChange = useCallback( + (event) => { + if (policyDetailsConfig) { + const newPayload = cloneDeep(policyDetailsConfig); + + setValue( + (newPayload as unknown) as Record, + event.target.value, + configPath + ); + dispatch({ + type: 'userChangedPolicyConfig', + payload: { policyConfig: newPayload }, + }); + } + }, + [dispatch, policyDetailsConfig, configPath] + ); const value = policyDetailsConfig && getValue((policyDetailsConfig as unknown) as Record, configPath); - // console.log(configPath, value); - return rawData.push({ - 'Field name': advancedField.key, - 'Supported endpoint version': advancedField.last_supported_version - ? `${advancedField.first_supported_version}-${advancedField.last_supported_version}` - : `${advancedField.first_supported_version}+`, - Value: , - }); - }); + // console.log(configPath.join('.')); + // console.log(firstSupportedVersion); + // console.log(lastSupportedVersion); + // console.log(value as string); + return ( + <> + +

+ +

+
+ + + + ); + } +); + +// export const PolicyAdvanced = React.memo(() => { +// const dispatch = useDispatch(); +// const policyDetailsConfig = usePolicyDetailsSelector(policyConfig); + +// const onChange = useCallback( +// (configPath: string[]) => (event) => { +// if (policyDetailsConfig) { +// const newPayload = cloneDeep(policyDetailsConfig); + +// setValue( +// (newPayload as unknown) as Record, +// event.target.value, +// configPath +// ); +// dispatch({ +// type: 'userChangedPolicyConfig', +// payload: { policyConfig: newPayload }, +// }); +// //event.target.focus(); +// } +// }, +// [dispatch, policyDetailsConfig] +// ); + + // const rawData = []; + // const columns = [ + // { + // id: 'Field name', + // }, + // { + // id: 'Supported endpoint version', + // }, + // { + // id: 'Value', + // // rowCellRender: function RowCellRender() { + // // const [isPopoverOpen, setIsPopoverOpen] = useState(false); + // // return ( + + // // ); + // // }, + // }, + // ]; + + // ((AdvancedPolicySchema as unknown) as AdvancedPolicySchemaType[]).map((advancedField, index) => { + // const configPath = advancedField.key.split('.'); + + // const value = + // policyDetailsConfig && + // getValue((policyDetailsConfig as unknown) as Record, configPath); + + // const [isPopoverOpen, setIsPopoverOpen] = useState(false); + // // console.log(configPath, value); + // return rawData.push({ + // 'Field name': advancedField.key, + // 'Supported endpoint version': advancedField.last_supported_version + // ? `${advancedField.first_supported_version}-${advancedField.last_supported_version}` + // : `${advancedField.first_supported_version}+`, + // Value: /*,*/ + // setIsPopoverOpen(!isPopoverOpen)} + // /> + // } + // closePopover={() => setIsPopoverOpen(false)} + // ownFocus={true}> + // + // + // }); + // }); // Column visibility - const [visibleColumns, setVisibleColumns] = useState(() => columns.map(({ id }) => id)); // initialize to the full set of columns - - const renderCellValue = useMemo(() => { - return ({ rowIndex, columnId, setCellProps }) => { - // eslint-disable-next-line react-hooks/rules-of-hooks - useEffect(() => { - if (columnId === 'Value') { - // if (rawData.hasOwnProperty(rowIndex)) { - setCellProps({ - style: { - backgroundColor: '#fffcdd', - }, - }); - // } - } - }, [rowIndex, columnId, setCellProps]); - - return Object.prototype.hasOwnProperty.call(rawData, rowIndex) - ? rawData[rowIndex][columnId] - : null; - }; - }, [rawData]); - - return ( - { - // console.log(eventData); - }} - /> - ); -}); + // const [visibleColumns, setVisibleColumns] = useState(() => columns.map(({ id }) => id)); // initialize to the full set of columns + + // const renderCellValue = useMemo(() => { + // return ({ rowIndex, columnId, setCellProps }) => { + // // eslint-disable-next-line react-hooks/rules-of-hooks + // useEffect(() => { + // if (columnId === 'Value') { + // // if (rawData.hasOwnProperty(rowIndex)) { + // setCellProps({ + // style: { + // backgroundColor: '#fffcdd', + // }, + // }); + // // } + // } + // }, [rowIndex, columnId, setCellProps]); + + // return Object.prototype.hasOwnProperty.call(rawData, rowIndex) + // ? rawData[rowIndex][columnId] + // : null; + // }; + // }, [rawData]); + +// return ( +// { +// // console.log(eventData); +// }} +// /> +// ); +// }); PolicyAdvanced.displayName = 'PolicyAdvanced'; diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx index 0dbbd1034fe5a..4b1b097f8a723 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx @@ -48,6 +48,36 @@ import { PolicyDetailsRouteState } from '../../../../../common/endpoint/types'; import { WrapperPage } from '../../../../common/components/wrapper_page'; import { HeaderPage } from '../../../../common/components/header_page'; import { PolicyAdvanced } from './policy_advanced'; +import * as AdvancedPolicySchema from '../../../../../schema.json'; + +interface AdvancedPolicySchemaType { + key: string; + first_supported_version: string; + last_supported_version: string; +} + +const AdvancedPolicyForms = React.memo(() => { + return ( + <> + {((AdvancedPolicySchema as unknown) as AdvancedPolicySchemaType[]).map( + (advancedField, index) => { + const configPath = advancedField.key.split('.'); + console.log(advancedField.key); + console.log(advancedField.first_supported_version); + console.log(advancedField.last_supported_version); + return ( + + ); + } + )} + + ); +}); export const PolicyDetails = React.memo(() => { const dispatch = useDispatch<(action: AppAction) => void>(); @@ -249,7 +279,7 @@ export const PolicyDetails = React.memo(() => { - + From 6074d8244fbd58e10f3950b79885b49c57c843f9 Mon Sep 17 00:00:00 2001 From: Jane Date: Thu, 8 Oct 2020 14:18:31 -0400 Subject: [PATCH 22/41] 145 back to basics --- .../pages/policy/view/policy_advanced.tsx | 159 +++++++++--------- .../pages/policy/view/policy_details.tsx | 5 +- 2 files changed, 84 insertions(+), 80 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index c2f85f716eaf2..4a2d78aa2087f 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -6,11 +6,16 @@ import React, { useCallback, useState, useMemo, useEffect } from 'react'; import { useDispatch } from 'react-redux'; -import { EuiFieldText, EuiText, FormattedMessage, EuiIconTip/*, EuiDataGrid, EuiPopover, EuiButtonIcon*/ } from '@elastic/eui'; +import { + EuiFieldText, + EuiText, + FormattedMessage, + EuiIconTip /* , EuiDataGrid, EuiPopover, EuiButtonIcon*/, +} from '@elastic/eui'; import { cloneDeep } from 'lodash'; import { policyConfig } from '../store/policy_details/selectors'; import { usePolicyDetailsSelector } from './policy_hooks'; -//import * as AdvancedPolicySchema from '../../../../../schema.json'; +// import * as AdvancedPolicySchema from '../../../../../schema.json'; function setValue(obj: Record, value: string, path: string[]) { let newPolicyConfig = obj; @@ -116,81 +121,81 @@ export const PolicyAdvanced = React.memo( // [dispatch, policyDetailsConfig] // ); - // const rawData = []; - // const columns = [ - // { - // id: 'Field name', - // }, - // { - // id: 'Supported endpoint version', - // }, - // { - // id: 'Value', - // // rowCellRender: function RowCellRender() { - // // const [isPopoverOpen, setIsPopoverOpen] = useState(false); - // // return ( - - // // ); - // // }, - // }, - // ]; - - // ((AdvancedPolicySchema as unknown) as AdvancedPolicySchemaType[]).map((advancedField, index) => { - // const configPath = advancedField.key.split('.'); - - // const value = - // policyDetailsConfig && - // getValue((policyDetailsConfig as unknown) as Record, configPath); - - // const [isPopoverOpen, setIsPopoverOpen] = useState(false); - // // console.log(configPath, value); - // return rawData.push({ - // 'Field name': advancedField.key, - // 'Supported endpoint version': advancedField.last_supported_version - // ? `${advancedField.first_supported_version}-${advancedField.last_supported_version}` - // : `${advancedField.first_supported_version}+`, - // Value: /*,*/ - // setIsPopoverOpen(!isPopoverOpen)} - // /> - // } - // closePopover={() => setIsPopoverOpen(false)} - // ownFocus={true}> - // - // - // }); - // }); - - // Column visibility - // const [visibleColumns, setVisibleColumns] = useState(() => columns.map(({ id }) => id)); // initialize to the full set of columns - - // const renderCellValue = useMemo(() => { - // return ({ rowIndex, columnId, setCellProps }) => { - // // eslint-disable-next-line react-hooks/rules-of-hooks - // useEffect(() => { - // if (columnId === 'Value') { - // // if (rawData.hasOwnProperty(rowIndex)) { - // setCellProps({ - // style: { - // backgroundColor: '#fffcdd', - // }, - // }); - // // } - // } - // }, [rowIndex, columnId, setCellProps]); - - // return Object.prototype.hasOwnProperty.call(rawData, rowIndex) - // ? rawData[rowIndex][columnId] - // : null; - // }; - // }, [rawData]); +// const rawData = []; +// const columns = [ +// { +// id: 'Field name', +// }, +// { +// id: 'Supported endpoint version', +// }, +// { +// id: 'Value', +// // rowCellRender: function RowCellRender() { +// // const [isPopoverOpen, setIsPopoverOpen] = useState(false); +// // return ( + +// // ); +// // }, +// }, +// ]; + +// ((AdvancedPolicySchema as unknown) as AdvancedPolicySchemaType[]).map((advancedField, index) => { +// const configPath = advancedField.key.split('.'); + +// const value = +// policyDetailsConfig && +// getValue((policyDetailsConfig as unknown) as Record, configPath); + +// const [isPopoverOpen, setIsPopoverOpen] = useState(false); +// // console.log(configPath, value); +// return rawData.push({ +// 'Field name': advancedField.key, +// 'Supported endpoint version': advancedField.last_supported_version +// ? `${advancedField.first_supported_version}-${advancedField.last_supported_version}` +// : `${advancedField.first_supported_version}+`, +// Value: /*,*/ +// setIsPopoverOpen(!isPopoverOpen)} +// /> +// } +// closePopover={() => setIsPopoverOpen(false)} +// ownFocus={true}> +// +// +// }); +// }); + +// Column visibility +// const [visibleColumns, setVisibleColumns] = useState(() => columns.map(({ id }) => id)); // initialize to the full set of columns + +// const renderCellValue = useMemo(() => { +// return ({ rowIndex, columnId, setCellProps }) => { +// // eslint-disable-next-line react-hooks/rules-of-hooks +// useEffect(() => { +// if (columnId === 'Value') { +// // if (rawData.hasOwnProperty(rowIndex)) { +// setCellProps({ +// style: { +// backgroundColor: '#fffcdd', +// }, +// }); +// // } +// } +// }, [rowIndex, columnId, setCellProps]); + +// return Object.prototype.hasOwnProperty.call(rawData, rowIndex) +// ? rawData[rowIndex][columnId] +// : null; +// }; +// }, [rawData]); // return ( // { {((AdvancedPolicySchema as unknown) as AdvancedPolicySchemaType[]).map( (advancedField, index) => { const configPath = advancedField.key.split('.'); - console.log(advancedField.key); - console.log(advancedField.first_supported_version); - console.log(advancedField.last_supported_version); return ( { ); }); +AdvancedPolicyForms.displayName = 'AdvancedPolicyForms'; + export const PolicyDetails = React.memo(() => { const dispatch = useDispatch<(action: AppAction) => void>(); const { From 9a1a2da3afeefa720adbd426e6c6618d7601bda8 Mon Sep 17 00:00:00 2001 From: Jane Date: Mon, 12 Oct 2020 13:42:33 -0400 Subject: [PATCH 23/41] 145 rolled back grid --- .../pages/policy/view/policy_advanced.tsx | 13 ++----------- .../management/pages/policy/view/policy_details.tsx | 1 - 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index 4a2d78aa2087f..6c763a6c5f93a 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -6,16 +6,11 @@ import React, { useCallback, useState, useMemo, useEffect } from 'react'; import { useDispatch } from 'react-redux'; -import { - EuiFieldText, - EuiText, - FormattedMessage, - EuiIconTip /* , EuiDataGrid, EuiPopover, EuiButtonIcon*/, -} from '@elastic/eui'; +import { EuiFieldText, EuiText, EuiIconTip } from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n/react'; import { cloneDeep } from 'lodash'; import { policyConfig } from '../store/policy_details/selectors'; import { usePolicyDetailsSelector } from './policy_hooks'; -// import * as AdvancedPolicySchema from '../../../../../schema.json'; function setValue(obj: Record, value: string, path: string[]) { let newPolicyConfig = obj; @@ -69,10 +64,6 @@ export const PolicyAdvanced = React.memo( policyDetailsConfig && getValue((policyDetailsConfig as unknown) as Record, configPath); - // console.log(configPath.join('.')); - // console.log(firstSupportedVersion); - // console.log(lastSupportedVersion); - // console.log(value as string); return ( <> diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx index df6ae19afcf55..ac066bc43d275 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx @@ -277,7 +277,6 @@ export const PolicyDetails = React.memo(() => { - From 9d36541c9178b4d41ce8d113b6fab1484c2a35c6 Mon Sep 17 00:00:00 2001 From: Jane Date: Tue, 13 Oct 2020 11:44:47 -0400 Subject: [PATCH 24/41] 145 flex table working --- .../pages/policy/view/policy_advanced.tsx | 37 +++++++++++++------ .../pages/policy/view/policy_details.tsx | 14 ++++++- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index 6c763a6c5f93a..e8a5e993bd5d8 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -6,7 +6,14 @@ import React, { useCallback, useState, useMemo, useEffect } from 'react'; import { useDispatch } from 'react-redux'; -import { EuiFieldText, EuiText, EuiIconTip } from '@elastic/eui'; +import { + EuiFieldText, + EuiText, + EuiIconTip, + EuiFlexGroup, + EuiFlexItem, + EuiSpacer, +} from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { cloneDeep } from 'lodash'; import { policyConfig } from '../store/policy_details/selectors'; @@ -66,23 +73,29 @@ export const PolicyAdvanced = React.memo( return ( <> - +

-
- - + + +

+ +

+
+ + + ); } diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx index ac066bc43d275..d40f71166916d 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx @@ -6,6 +6,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { + EuiFlexGrid, EuiFlexGroup, EuiFlexItem, EuiButton, @@ -58,7 +59,16 @@ interface AdvancedPolicySchemaType { const AdvancedPolicyForms = React.memo(() => { return ( - <> + + +

{'Field name'}

+
+ +

{'Supported endpoint version'}

+
+ +

{'Value'}

+
{((AdvancedPolicySchema as unknown) as AdvancedPolicySchemaType[]).map( (advancedField, index) => { const configPath = advancedField.key.split('.'); @@ -72,7 +82,7 @@ const AdvancedPolicyForms = React.memo(() => { ); } )} - +
); }); From 5ecd799fb658140193a1119b568a2addd0b47529 Mon Sep 17 00:00:00 2001 From: Jane Date: Tue, 13 Oct 2020 13:17:29 -0400 Subject: [PATCH 25/41] 145 undo accidental change --- packages/kbn-dev-utils/src/kbn_client/kbn_client_requester.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/kbn-dev-utils/src/kbn_client/kbn_client_requester.ts b/packages/kbn-dev-utils/src/kbn_client/kbn_client_requester.ts index f4d7c9b7f287d..2aba2be56f277 100644 --- a/packages/kbn-dev-utils/src/kbn_client/kbn_client_requester.ts +++ b/packages/kbn-dev-utils/src/kbn_client/kbn_client_requester.ts @@ -60,7 +60,6 @@ export interface ReqOptions { path: string; query?: Record; method: 'GET' | 'POST' | 'PUT' | 'DELETE'; - headers?: Record; body?: any; retries?: number; } @@ -118,7 +117,6 @@ export class KbnClientRequester { params: options.query, headers: { 'kbn-xsrf': 'kbn-client', - ...options.headers, }, httpsAgent: this.httpsAgent, }); From 00dedbb1b3c772c36293bf776187772032758659 Mon Sep 17 00:00:00 2001 From: Jane Date: Tue, 13 Oct 2020 13:29:28 -0400 Subject: [PATCH 26/41] 145 remove extra schema file --- .../policy/models/advanced_policy_schema.json | 20 ++++++++++--------- .../pages/policy/view/policy_details.tsx | 2 +- x-pack/plugins/security_solution/schema.json | 13 ------------ 3 files changed, 12 insertions(+), 23 deletions(-) delete mode 100644 x-pack/plugins/security_solution/schema.json diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.json b/x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.json index db3fbe4134e02..747016373afa8 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.json +++ b/x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.json @@ -1,11 +1,13 @@ [ - { - "key": "windows.advanced.elasticsearch.tls.verify_peer", - "first_supported_version": "7.10", - "last_supported_version": "7.13" - }, - { - "key": "windows.advanced.elasticsearch.tls.verify_hostname", - "first_supported_version": "7.10" - } + { + "key": "windows.advanced.elasticsearch.tls.verify_peer", + "first_supported_version": "7.10", + "last_supported_version": "7.13", + "documentation": "whether to verify tls peer" + }, + { + "key": "windows.advanced.elasticsearch.tls.verify_hostname", + "first_supported_version": "7.10", + "documentation": "whether to verify tls hostname" + } ] \ No newline at end of file diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx index d40f71166916d..ee959c3c50353 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx @@ -49,7 +49,7 @@ import { PolicyDetailsRouteState } from '../../../../../common/endpoint/types'; import { WrapperPage } from '../../../../common/components/wrapper_page'; import { HeaderPage } from '../../../../common/components/header_page'; import { PolicyAdvanced } from './policy_advanced'; -import * as AdvancedPolicySchema from '../../../../../schema.json'; +import * as AdvancedPolicySchema from '../models/advanced_policy_schema.json'; interface AdvancedPolicySchemaType { key: string; diff --git a/x-pack/plugins/security_solution/schema.json b/x-pack/plugins/security_solution/schema.json deleted file mode 100644 index 747016373afa8..0000000000000 --- a/x-pack/plugins/security_solution/schema.json +++ /dev/null @@ -1,13 +0,0 @@ -[ - { - "key": "windows.advanced.elasticsearch.tls.verify_peer", - "first_supported_version": "7.10", - "last_supported_version": "7.13", - "documentation": "whether to verify tls peer" - }, - { - "key": "windows.advanced.elasticsearch.tls.verify_hostname", - "first_supported_version": "7.10", - "documentation": "whether to verify tls hostname" - } -] \ No newline at end of file From afe40b72a2be5bf256c338918bfa7aa21f6a626a Mon Sep 17 00:00:00 2001 From: Jane Date: Tue, 13 Oct 2020 14:07:03 -0400 Subject: [PATCH 27/41] 145 remove unused variable --- .../security_solution/public/management/pages/policy/types.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/types.ts b/x-pack/plugins/security_solution/public/management/pages/policy/types.ts index c8389f76a2a00..229d817abf9c9 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/types.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/types.ts @@ -145,8 +145,6 @@ export enum OS { linux = 'linux', } -export type AdvancedOSes = KeysByValueCriteria; - /** * Returns the keys of an object whose values meet a criteria. * Ex) interface largeNestedObject = { From 23238e9d29504f34a9e774cad99443b830951c52 Mon Sep 17 00:00:00 2001 From: Jane Date: Thu, 15 Oct 2020 17:47:41 -0400 Subject: [PATCH 28/41] 145 kevin's PR feedback --- .../common/endpoint/models/policy_config.ts | 24 -- .../policy/models/advanced_policy_schema.json | 299 +++++++++++++++++- .../policy/store/policy_details/index.test.ts | 24 -- .../pages/policy/view/policy_advanced.tsx | 40 +-- .../pages/policy/view/policy_details.tsx | 12 +- 5 files changed, 317 insertions(+), 82 deletions(-) diff --git a/x-pack/plugins/security_solution/common/endpoint/models/policy_config.ts b/x-pack/plugins/security_solution/common/endpoint/models/policy_config.ts index e6d21485fa5e9..37b7308856196 100644 --- a/x-pack/plugins/security_solution/common/endpoint/models/policy_config.ts +++ b/x-pack/plugins/security_solution/common/endpoint/models/policy_config.ts @@ -12,14 +12,6 @@ import { PolicyConfig, ProtectionModes } from '../types'; export const factory = (): PolicyConfig => { return { windows: { - advanced: { - elasticsearch: { - tls: { - verify_hostname: '', - verify_peer: '', - }, - }, - }, events: { dll_and_driver_load: true, dns: true, @@ -37,14 +29,6 @@ export const factory = (): PolicyConfig => { }, }, mac: { - advanced: { - elasticsearch: { - tls: { - verify_hostname: '', - verify_peer: '', - }, - }, - }, events: { process: true, file: true, @@ -58,14 +42,6 @@ export const factory = (): PolicyConfig => { }, }, linux: { - advanced: { - elasticsearch: { - tls: { - verify_hostname: '', - verify_peer: '', - }, - }, - }, events: { process: true, file: true, diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.json b/x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.json index 747016373afa8..007fc6d99313b 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.json +++ b/x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.json @@ -1,13 +1,302 @@ [ + { + "key": "linux.advanced.agent.connection_delay", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "linux.advanced.artifacts.global.base_url", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "linux.advanced.artifacts.global.manifest_relative_url", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "linux.advanced.artifacts.global.ca_cert", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "linux.advanced.artifacts.global.public_key", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "linux.advanced.artifacts.global.interval", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "linux.advanced.artifacts.user.base_url", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "linux.advanced.artifacts.user.ca_cert", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "linux.advanced.artifacts.user.public_key", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "linux.advanced.artifacts.user.interval", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "linux.advanced.elasticsearch.delay", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "linux.advanced.elasticsearch.tls.verify_peer", + "first_supported_version": "7.11", + "documentation": "default is true" + }, + { + "key": "linux.advanced.elasticsearch.tls.verify_hostname", + "first_supported_version": "7.11", + "documentation": "default is true" + }, + { + "key": "linux.advanced.elasticsearch.tls.ca_cert", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.agent.connection_delay", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.artifacts.global.base_url", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.artifacts.global.manifest_relative_url", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.artifacts.global.ca_cert", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.artifacts.global.public_key", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.artifacts.global.interval", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.artifacts.user.base_url", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.artifacts.user.ca_cert", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.artifacts.user.public_key", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.artifacts.user.interval", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.elasticsearch.delay", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.elasticsearch.tls.verify_peer", + "first_supported_version": "7.11", + "documentation": "default is true" + }, + { + "key": "mac.advanced.elasticsearch.tls.verify_hostname", + "first_supported_version": "7.11", + "documentation": "default is true" + }, + { + "key": "mac.advanced.elasticsearch.tls.ca_cert", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.malware.quarantine", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.kernel.connect", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.kernel.harden", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.kernel.process", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.kernel.filewrite", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "mac.advanced.kernel.network", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.agent.connection_delay", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.artifacts.global.base_url", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.artifacts.global.manifest_relative_url", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.artifacts.global.ca_cert", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.artifacts.global.public_key", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.artifacts.global.interval", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.artifacts.user.base_url", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.artifacts.user.ca_cert", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.artifacts.user.public_key", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.artifacts.user.interval", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.elasticsearch.delay", + "first_supported_version": "7.11", + "documentation": "" +}, { "key": "windows.advanced.elasticsearch.tls.verify_peer", - "first_supported_version": "7.10", - "last_supported_version": "7.13", - "documentation": "whether to verify tls peer" + "first_supported_version": "7.11", + "documentation": "default is true" }, { "key": "windows.advanced.elasticsearch.tls.verify_hostname", - "first_supported_version": "7.10", - "documentation": "whether to verify tls hostname" + "first_supported_version": "7.11", + "documentation": "default is true" + }, + { + "key": "windows.advanced.elasticsearch.tls.ca_cert", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.malware.quarantine", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.ransomware.mbr", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.ransomware.canary", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.kernel.connect", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.kernel.harden", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.kernel.process", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.kernel.filewrite", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.kernel.network", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.kernel.fileopen", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.kernel.asyncimageload", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.kernel.syncimageload", + "first_supported_version": "7.11", + "documentation": "" + }, + { + "key": "windows.advanced.kernel.registry", + "first_supported_version": "7.11", + "documentation": "" } ] \ No newline at end of file diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/index.test.ts b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/index.test.ts index e6b8f0043c2ef..d5253f0b476c2 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/index.test.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/index.test.ts @@ -228,14 +228,6 @@ describe('policy details: ', () => { policy: { value: { windows: { - advanced: { - elasticsearch: { - tls: { - verify_hostname: '', - verify_peer: '', - }, - }, - }, events: { dll_and_driver_load: true, dns: false, @@ -249,27 +241,11 @@ describe('policy details: ', () => { logging: { file: 'info' }, }, mac: { - advanced: { - elasticsearch: { - tls: { - verify_hostname: '', - verify_peer: '', - }, - }, - }, events: { process: true, file: true, network: true }, malware: { mode: 'prevent' }, logging: { file: 'info' }, }, linux: { - advanced: { - elasticsearch: { - tls: { - verify_hostname: '', - verify_peer: '', - }, - }, - }, events: { process: true, file: true, network: true }, logging: { file: 'info' }, }, diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index e8a5e993bd5d8..1968c4ebb9bd9 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -4,17 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { useCallback, useState, useMemo, useEffect } from 'react'; +import React, { useCallback } from 'react'; import { useDispatch } from 'react-redux'; -import { - EuiFieldText, - EuiText, - EuiIconTip, - EuiFlexGroup, - EuiFlexItem, - EuiSpacer, -} from '@elastic/eui'; -import { FormattedMessage } from '@kbn/i18n/react'; +import { EuiFieldText, EuiFlexItem } from '@elastic/eui'; import { cloneDeep } from 'lodash'; import { policyConfig } from '../store/policy_details/selectors'; import { usePolicyDetailsSelector } from './policy_hooks'; @@ -22,6 +14,9 @@ import { usePolicyDetailsSelector } from './policy_hooks'; function setValue(obj: Record, value: string, path: string[]) { let newPolicyConfig = obj; for (let i = 0; i < path.length - 1; i++) { + if (!newPolicyConfig[path[i]]) { + newPolicyConfig[path[i]] = {} as Record; + } newPolicyConfig = newPolicyConfig[path[i]] as Record; } newPolicyConfig[path[path.length - 1]] = value; @@ -31,7 +26,11 @@ function getValue(obj: Record, path: string[]) { let currentPolicyConfig = obj; for (let i = 0; i < path.length - 1; i++) { - currentPolicyConfig = currentPolicyConfig[path[i]] as Record; + if (currentPolicyConfig[path[i]]) { + currentPolicyConfig = currentPolicyConfig[path[i]] as Record; + } else { + return undefined; + } } return currentPolicyConfig[path[path.length - 1]]; } @@ -52,7 +51,6 @@ export const PolicyAdvanced = React.memo( (event) => { if (policyDetailsConfig) { const newPayload = cloneDeep(policyDetailsConfig); - setValue( (newPayload as unknown) as Record, event.target.value, @@ -74,23 +72,13 @@ export const PolicyAdvanced = React.memo( return ( <> -

- -

+

{configPath.join('.')}

- + {lastSupportedVersion + ? `${firstSupportedVersion}-${lastSupportedVersion}` + : `${firstSupportedVersion}+`}

diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx index ee959c3c50353..4cee68b8f2945 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx @@ -61,13 +61,19 @@ const AdvancedPolicyForms = React.memo(() => { return ( -

{'Field name'}

+
-

{'Supported endpoint version'}

+
-

{'Value'}

+
{((AdvancedPolicySchema as unknown) as AdvancedPolicySchemaType[]).map( (advancedField, index) => { From 0c5a577178692c96c7600b70a36ed66f9b7b8d2f Mon Sep 17 00:00:00 2001 From: Jane Date: Mon, 19 Oct 2020 17:24:30 -0400 Subject: [PATCH 29/41] 145 fix type check and jest --- .../policy/models/advanced_policy_schema.json | 302 ----------------- .../policy/models/advanced_policy_schema.ts | 315 ++++++++++++++++++ .../public/management/pages/policy/types.ts | 1 - .../pages/policy/view/policy_details.tsx | 32 +- 4 files changed, 327 insertions(+), 323 deletions(-) delete mode 100644 x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.json create mode 100644 x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.ts diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.json b/x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.json deleted file mode 100644 index 007fc6d99313b..0000000000000 --- a/x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.json +++ /dev/null @@ -1,302 +0,0 @@ -[ - { - "key": "linux.advanced.agent.connection_delay", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "linux.advanced.artifacts.global.base_url", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "linux.advanced.artifacts.global.manifest_relative_url", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "linux.advanced.artifacts.global.ca_cert", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "linux.advanced.artifacts.global.public_key", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "linux.advanced.artifacts.global.interval", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "linux.advanced.artifacts.user.base_url", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "linux.advanced.artifacts.user.ca_cert", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "linux.advanced.artifacts.user.public_key", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "linux.advanced.artifacts.user.interval", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "linux.advanced.elasticsearch.delay", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "linux.advanced.elasticsearch.tls.verify_peer", - "first_supported_version": "7.11", - "documentation": "default is true" - }, - { - "key": "linux.advanced.elasticsearch.tls.verify_hostname", - "first_supported_version": "7.11", - "documentation": "default is true" - }, - { - "key": "linux.advanced.elasticsearch.tls.ca_cert", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.agent.connection_delay", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.artifacts.global.base_url", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.artifacts.global.manifest_relative_url", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.artifacts.global.ca_cert", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.artifacts.global.public_key", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.artifacts.global.interval", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.artifacts.user.base_url", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.artifacts.user.ca_cert", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.artifacts.user.public_key", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.artifacts.user.interval", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.elasticsearch.delay", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.elasticsearch.tls.verify_peer", - "first_supported_version": "7.11", - "documentation": "default is true" - }, - { - "key": "mac.advanced.elasticsearch.tls.verify_hostname", - "first_supported_version": "7.11", - "documentation": "default is true" - }, - { - "key": "mac.advanced.elasticsearch.tls.ca_cert", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.malware.quarantine", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.kernel.connect", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.kernel.harden", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.kernel.process", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.kernel.filewrite", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "mac.advanced.kernel.network", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.agent.connection_delay", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.artifacts.global.base_url", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.artifacts.global.manifest_relative_url", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.artifacts.global.ca_cert", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.artifacts.global.public_key", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.artifacts.global.interval", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.artifacts.user.base_url", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.artifacts.user.ca_cert", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.artifacts.user.public_key", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.artifacts.user.interval", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.elasticsearch.delay", - "first_supported_version": "7.11", - "documentation": "" -}, - { - "key": "windows.advanced.elasticsearch.tls.verify_peer", - "first_supported_version": "7.11", - "documentation": "default is true" - }, - { - "key": "windows.advanced.elasticsearch.tls.verify_hostname", - "first_supported_version": "7.11", - "documentation": "default is true" - }, - { - "key": "windows.advanced.elasticsearch.tls.ca_cert", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.malware.quarantine", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.ransomware.mbr", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.ransomware.canary", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.kernel.connect", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.kernel.harden", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.kernel.process", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.kernel.filewrite", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.kernel.network", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.kernel.fileopen", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.kernel.asyncimageload", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.kernel.syncimageload", - "first_supported_version": "7.11", - "documentation": "" - }, - { - "key": "windows.advanced.kernel.registry", - "first_supported_version": "7.11", - "documentation": "" - } -] \ No newline at end of file diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.ts b/x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.ts new file mode 100644 index 0000000000000..d25588dabedc6 --- /dev/null +++ b/x-pack/plugins/security_solution/public/management/pages/policy/models/advanced_policy_schema.ts @@ -0,0 +1,315 @@ +/* + * 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. + */ + +interface AdvancedPolicySchemaType { + key: string; + first_supported_version: string; + last_supported_version?: string; + documentation: string; +} + +export const AdvancedPolicySchema: AdvancedPolicySchemaType[] = [ + { + key: 'linux.advanced.agent.connection_delay', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'linux.advanced.artifacts.global.base_url', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'linux.advanced.artifacts.global.manifest_relative_url', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'linux.advanced.artifacts.global.ca_cert', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'linux.advanced.artifacts.global.public_key', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'linux.advanced.artifacts.global.interval', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'linux.advanced.artifacts.user.base_url', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'linux.advanced.artifacts.user.ca_cert', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'linux.advanced.artifacts.user.public_key', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'linux.advanced.artifacts.user.interval', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'linux.advanced.elasticsearch.delay', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'linux.advanced.elasticsearch.tls.verify_peer', + first_supported_version: '7.11', + documentation: 'default is true', + }, + { + key: 'linux.advanced.elasticsearch.tls.verify_hostname', + first_supported_version: '7.11', + documentation: 'default is true', + }, + { + key: 'linux.advanced.elasticsearch.tls.ca_cert', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.agent.connection_delay', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.artifacts.global.base_url', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.artifacts.global.manifest_relative_url', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.artifacts.global.ca_cert', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.artifacts.global.public_key', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.artifacts.global.interval', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.artifacts.user.base_url', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.artifacts.user.ca_cert', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.artifacts.user.public_key', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.artifacts.user.interval', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.elasticsearch.delay', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.elasticsearch.tls.verify_peer', + first_supported_version: '7.11', + documentation: 'default is true', + }, + { + key: 'mac.advanced.elasticsearch.tls.verify_hostname', + first_supported_version: '7.11', + documentation: 'default is true', + }, + { + key: 'mac.advanced.elasticsearch.tls.ca_cert', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.malware.quarantine', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.kernel.connect', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.kernel.harden', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.kernel.process', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.kernel.filewrite', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'mac.advanced.kernel.network', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.agent.connection_delay', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.artifacts.global.base_url', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.artifacts.global.manifest_relative_url', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.artifacts.global.ca_cert', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.artifacts.global.public_key', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.artifacts.global.interval', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.artifacts.user.base_url', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.artifacts.user.ca_cert', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.artifacts.user.public_key', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.artifacts.user.interval', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.elasticsearch.delay', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.elasticsearch.tls.verify_peer', + first_supported_version: '7.11', + documentation: 'default is true', + }, + { + key: 'windows.advanced.elasticsearch.tls.verify_hostname', + first_supported_version: '7.11', + documentation: 'default is true', + }, + { + key: 'windows.advanced.elasticsearch.tls.ca_cert', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.malware.quarantine', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.ransomware.mbr', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.ransomware.canary', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.kernel.connect', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.kernel.harden', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.kernel.process', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.kernel.filewrite', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.kernel.network', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.kernel.fileopen', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.kernel.asyncimageload', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.kernel.syncimageload', + first_supported_version: '7.11', + documentation: '', + }, + { + key: 'windows.advanced.kernel.registry', + first_supported_version: '7.11', + documentation: '', + }, +]; diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/types.ts b/x-pack/plugins/security_solution/public/management/pages/policy/types.ts index 229d817abf9c9..c7d426da05508 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/types.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/types.ts @@ -8,7 +8,6 @@ import { AppLocation, Immutable, MalwareFields, - AdvancedFields, PolicyData, UIPolicyConfig, } from '../../../../common/endpoint/types'; diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx index 4cee68b8f2945..477ce4e278680 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx @@ -49,13 +49,7 @@ import { PolicyDetailsRouteState } from '../../../../../common/endpoint/types'; import { WrapperPage } from '../../../../common/components/wrapper_page'; import { HeaderPage } from '../../../../common/components/header_page'; import { PolicyAdvanced } from './policy_advanced'; -import * as AdvancedPolicySchema from '../models/advanced_policy_schema.json'; - -interface AdvancedPolicySchemaType { - key: string; - first_supported_version: string; - last_supported_version: string; -} +import { AdvancedPolicySchema } from '../models/advanced_policy_schema'; const AdvancedPolicyForms = React.memo(() => { return ( @@ -75,19 +69,17 @@ const AdvancedPolicyForms = React.memo(() => { - {((AdvancedPolicySchema as unknown) as AdvancedPolicySchemaType[]).map( - (advancedField, index) => { - const configPath = advancedField.key.split('.'); - return ( - - ); - } - )} + {AdvancedPolicySchema.map((advancedField, index) => { + const configPath = advancedField.key.split('.'); + return ( + + ); + })}
); }); From 5546c25093b14e46ac9519955a6861d15d5880de Mon Sep 17 00:00:00 2001 From: Jane Date: Tue, 20 Oct 2020 13:44:34 -0400 Subject: [PATCH 30/41] 145 EuiFlexGroups --- .../pages/policy/view/policy_advanced.tsx | 30 +++++++------- .../pages/policy/view/policy_details.tsx | 41 +++++++++++-------- 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index 1968c4ebb9bd9..d3c3c388bba25 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -6,7 +6,7 @@ import React, { useCallback } from 'react'; import { useDispatch } from 'react-redux'; -import { EuiFieldText, EuiFlexItem } from '@elastic/eui'; +import { EuiFieldText, EuiFlexItem, EuiFlexGroup } from '@elastic/eui'; import { cloneDeep } from 'lodash'; import { policyConfig } from '../store/policy_details/selectors'; import { usePolicyDetailsSelector } from './policy_hooks'; @@ -71,19 +71,21 @@ export const PolicyAdvanced = React.memo( return ( <> - -

{configPath.join('.')}

-
- -

- {lastSupportedVersion - ? `${firstSupportedVersion}-${lastSupportedVersion}` - : `${firstSupportedVersion}+`} -

-
- - - + + +

{configPath.join('.')}

+
+ +

+ {lastSupportedVersion + ? `${firstSupportedVersion}-${lastSupportedVersion}` + : `${firstSupportedVersion}+`} +

+
+ + + +
); } diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx index 477ce4e278680..1257d56d75ce5 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx @@ -53,22 +53,31 @@ import { AdvancedPolicySchema } from '../models/advanced_policy_schema'; const AdvancedPolicyForms = React.memo(() => { return ( - - - - - - - - - - + // + + + + + + + + + + + + + + + {AdvancedPolicySchema.map((advancedField, index) => { const configPath = advancedField.key.split('.'); return ( From 7c79ecec15b75b825c5f60d6e1ca8b13fb700007 Mon Sep 17 00:00:00 2001 From: Jane Date: Wed, 21 Oct 2020 10:09:44 -0400 Subject: [PATCH 31/41] 145 use simple EuiFormRow and add show/hide buttons --- .../pages/policy/view/policy_advanced.tsx | 147 ++---------------- .../pages/policy/view/policy_details.tsx | 64 ++++---- 2 files changed, 47 insertions(+), 164 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index d3c3c388bba25..2cc18aa696450 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -6,7 +6,7 @@ import React, { useCallback } from 'react'; import { useDispatch } from 'react-redux'; -import { EuiFieldText, EuiFlexItem, EuiFlexGroup } from '@elastic/eui'; +import { EuiFieldText, EuiFormRow, EuiText } from '@elastic/eui'; import { cloneDeep } from 'lodash'; import { policyConfig } from '../store/policy_details/selectors'; import { usePolicyDetailsSelector } from './policy_hooks'; @@ -71,147 +71,22 @@ export const PolicyAdvanced = React.memo( return ( <> - - -

{configPath.join('.')}

-
- -

+ {lastSupportedVersion ? `${firstSupportedVersion}-${lastSupportedVersion}` : `${firstSupportedVersion}+`} -

-
- - - -
+
+ } + > + + ); } ); -// export const PolicyAdvanced = React.memo(() => { -// const dispatch = useDispatch(); -// const policyDetailsConfig = usePolicyDetailsSelector(policyConfig); - -// const onChange = useCallback( -// (configPath: string[]) => (event) => { -// if (policyDetailsConfig) { -// const newPayload = cloneDeep(policyDetailsConfig); - -// setValue( -// (newPayload as unknown) as Record, -// event.target.value, -// configPath -// ); -// dispatch({ -// type: 'userChangedPolicyConfig', -// payload: { policyConfig: newPayload }, -// }); -// //event.target.focus(); -// } -// }, -// [dispatch, policyDetailsConfig] -// ); - -// const rawData = []; -// const columns = [ -// { -// id: 'Field name', -// }, -// { -// id: 'Supported endpoint version', -// }, -// { -// id: 'Value', -// // rowCellRender: function RowCellRender() { -// // const [isPopoverOpen, setIsPopoverOpen] = useState(false); -// // return ( - -// // ); -// // }, -// }, -// ]; - -// ((AdvancedPolicySchema as unknown) as AdvancedPolicySchemaType[]).map((advancedField, index) => { -// const configPath = advancedField.key.split('.'); - -// const value = -// policyDetailsConfig && -// getValue((policyDetailsConfig as unknown) as Record, configPath); - -// const [isPopoverOpen, setIsPopoverOpen] = useState(false); -// // console.log(configPath, value); -// return rawData.push({ -// 'Field name': advancedField.key, -// 'Supported endpoint version': advancedField.last_supported_version -// ? `${advancedField.first_supported_version}-${advancedField.last_supported_version}` -// : `${advancedField.first_supported_version}+`, -// Value: /*,*/ -// setIsPopoverOpen(!isPopoverOpen)} -// /> -// } -// closePopover={() => setIsPopoverOpen(false)} -// ownFocus={true}> -// -// -// }); -// }); - -// Column visibility -// const [visibleColumns, setVisibleColumns] = useState(() => columns.map(({ id }) => id)); // initialize to the full set of columns - -// const renderCellValue = useMemo(() => { -// return ({ rowIndex, columnId, setCellProps }) => { -// // eslint-disable-next-line react-hooks/rules-of-hooks -// useEffect(() => { -// if (columnId === 'Value') { -// // if (rawData.hasOwnProperty(rowIndex)) { -// setCellProps({ -// style: { -// backgroundColor: '#fffcdd', -// }, -// }); -// // } -// } -// }, [rowIndex, columnId, setCellProps]); - -// return Object.prototype.hasOwnProperty.call(rawData, rowIndex) -// ? rawData[rowIndex][columnId] -// : null; -// }; -// }, [rawData]); - -// return ( -// { -// // console.log(eventData); -// }} -// /> -// ); -// }); - PolicyAdvanced.displayName = 'PolicyAdvanced'; diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx index 1257d56d75ce5..fa8d591ed08e7 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx @@ -6,7 +6,6 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { - EuiFlexGrid, EuiFlexGroup, EuiFlexItem, EuiButton, @@ -53,31 +52,7 @@ import { AdvancedPolicySchema } from '../models/advanced_policy_schema'; const AdvancedPolicyForms = React.memo(() => { return ( - // - - - - - - - - - - - - - - - + <> {AdvancedPolicySchema.map((advancedField, index) => { const configPath = advancedField.key.split('.'); return ( @@ -89,7 +64,7 @@ const AdvancedPolicyForms = React.memo(() => { /> ); })} - + ); }); @@ -116,6 +91,7 @@ export const PolicyDetails = React.memo(() => { // Local state const [showConfirm, setShowConfirm] = useState(false); const [routeState, setRouteState] = useState(); + const [showAdvancedPolicy, setShowAdvancedPolicy] = useState(false); const policyName = policyItem?.name ?? ''; const hostListRouterPath = getEndpointListPath({ name: 'endpointList' }); @@ -175,6 +151,14 @@ export const PolicyDetails = React.memo(() => { setShowConfirm(false); }, []); + const handleShowAdvancedPolicyClick = useCallback(() => { + setShowAdvancedPolicy(true); + }, []); + + const handleHideAdvancedPolicyClick = useCallback(() => { + setShowAdvancedPolicy(false); + }, []); + useEffect(() => { if (!routeState && locationRouteState) { setRouteState(locationRouteState); @@ -293,8 +277,32 @@ export const PolicyDetails = React.memo(() => { + {showAdvancedPolicy && ( + + + + )} + + {!showAdvancedPolicy && ( + + + + )} + - + {showAdvancedPolicy && } From f44601c417470f867e7aff2f38871e449f948725 Mon Sep 17 00:00:00 2001 From: Jane Date: Wed, 21 Oct 2020 17:05:25 -0400 Subject: [PATCH 32/41] 145 move all advanced policy code to advanced file; remove unnec test code --- .../pages/policy/view/policy_advanced.tsx | 36 ++++++++++- .../pages/policy/view/policy_details.tsx | 63 ++++--------------- .../apps/endpoint/policy_details.ts | 24 ------- 3 files changed, 45 insertions(+), 78 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index 2cc18aa696450..b4b82b7f692b9 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -6,10 +6,12 @@ import React, { useCallback } from 'react'; import { useDispatch } from 'react-redux'; -import { EuiFieldText, EuiFormRow, EuiText } from '@elastic/eui'; +import { EuiFieldText, EuiFormRow, EuiPanel, EuiText } from '@elastic/eui'; import { cloneDeep } from 'lodash'; +import { FormattedMessage } from '@kbn/i18n/react'; import { policyConfig } from '../store/policy_details/selectors'; import { usePolicyDetailsSelector } from './policy_hooks'; +import { AdvancedPolicySchema } from '../models/advanced_policy_schema'; function setValue(obj: Record, value: string, path: string[]) { let newPolicyConfig = obj; @@ -35,7 +37,37 @@ function getValue(obj: Record, path: string[]) { return currentPolicyConfig[path[path.length - 1]]; } -export const PolicyAdvanced = React.memo( +export const AdvancedPolicyForms = React.memo(() => { + return ( + <> + +

+ +

+
+ + {AdvancedPolicySchema.map((advancedField, index) => { + const configPath = advancedField.key.split('.'); + return ( + + ); + })} + + + ); +}); + +AdvancedPolicyForms.displayName = 'AdvancedPolicyForms'; + +const PolicyAdvanced = React.memo( ({ configPath, firstSupportedVersion, diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx index fa8d591ed08e7..6722dfd46dac7 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx @@ -47,28 +47,7 @@ import { MANAGEMENT_APP_ID } from '../../../common/constants'; import { PolicyDetailsRouteState } from '../../../../../common/endpoint/types'; import { WrapperPage } from '../../../../common/components/wrapper_page'; import { HeaderPage } from '../../../../common/components/header_page'; -import { PolicyAdvanced } from './policy_advanced'; -import { AdvancedPolicySchema } from '../models/advanced_policy_schema'; - -const AdvancedPolicyForms = React.memo(() => { - return ( - <> - {AdvancedPolicySchema.map((advancedField, index) => { - const configPath = advancedField.key.split('.'); - return ( - - ); - })} - - ); -}); - -AdvancedPolicyForms.displayName = 'AdvancedPolicyForms'; +import { AdvancedPolicyForms } from './policy_advanced'; export const PolicyDetails = React.memo(() => { const dispatch = useDispatch<(action: AppAction) => void>(); @@ -151,13 +130,9 @@ export const PolicyDetails = React.memo(() => { setShowConfirm(false); }, []); - const handleShowAdvancedPolicyClick = useCallback(() => { - setShowAdvancedPolicy(true); - }, []); - - const handleHideAdvancedPolicyClick = useCallback(() => { - setShowAdvancedPolicy(false); - }, []); + const handleAdvancedPolicyClick = useCallback(() => { + setShowAdvancedPolicy(!showAdvancedPolicy); + }, [showAdvancedPolicy]); useEffect(() => { if (!routeState && locationRouteState) { @@ -277,29 +252,13 @@ export const PolicyDetails = React.memo(() => { - {showAdvancedPolicy && ( - - - - )} - - {!showAdvancedPolicy && ( - - - - )} + + + {showAdvancedPolicy && } diff --git a/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts b/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts index 07b488a1a288b..1f6973ae0f988 100644 --- a/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts +++ b/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts @@ -199,26 +199,10 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { }, policy: { linux: { - advanced: { - elasticsearch: { - tls: { - verify_hostname: '', - verify_peer: '', - }, - }, - }, events: { file: false, network: true, process: true }, logging: { file: 'info' }, }, mac: { - advanced: { - elasticsearch: { - tls: { - verify_hostname: '', - verify_peer: '', - }, - }, - }, events: { file: false, network: true, process: true }, logging: { file: 'info' }, malware: { mode: 'prevent' }, @@ -230,14 +214,6 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { }, }, windows: { - advanced: { - elasticsearch: { - tls: { - verify_hostname: '', - verify_peer: '', - }, - }, - }, events: { dll_and_driver_load: true, dns: true, From 50d799b052dfa9f632a0b333c35e70783fc2fc0a Mon Sep 17 00:00:00 2001 From: Jane Date: Wed, 21 Oct 2020 17:23:45 -0400 Subject: [PATCH 33/41] 145 fix IDs --- .../public/management/pages/policy/view/policy_details.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx index 6722dfd46dac7..ee13459841656 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx @@ -254,7 +254,7 @@ export const PolicyDetails = React.memo(() => { From 8bd1ef6aa8d107a6ff50d944c52e5c007da83415 Mon Sep 17 00:00:00 2001 From: Jane Date: Thu, 22 Oct 2020 10:26:52 -0400 Subject: [PATCH 34/41] 145 take out unnecessary stuff --- .../common/endpoint/types/index.ts | 18 +++--------------- .../public/management/common/constants.ts | 1 - .../policy/store/policy_details/middleware.ts | 6 +----- .../policy/store/policy_details/selectors.ts | 17 ++--------------- .../pages/policy/view/policy_details.tsx | 4 ++-- 5 files changed, 8 insertions(+), 38 deletions(-) diff --git a/x-pack/plugins/security_solution/common/endpoint/types/index.ts b/x-pack/plugins/security_solution/common/endpoint/types/index.ts index 7784d5a07da7d..882b3e5182bf3 100644 --- a/x-pack/plugins/security_solution/common/endpoint/types/index.ts +++ b/x-pack/plugins/security_solution/common/endpoint/types/index.ts @@ -860,7 +860,6 @@ type KbnConfigSchemaNonOptionalProps> = Pi */ export interface PolicyConfig { windows: { - advanced?: AdvancedFields; // will be introduced in 7.11+ events: { dll_and_driver_load: boolean; dns: boolean; @@ -882,7 +881,6 @@ export interface PolicyConfig { }; }; mac: { - advanced?: AdvancedFields; events: { file: boolean; process: boolean; @@ -900,7 +898,6 @@ export interface PolicyConfig { }; }; linux: { - advanced?: AdvancedFields; events: { file: boolean; process: boolean; @@ -912,15 +909,6 @@ export interface PolicyConfig { }; } -export interface AdvancedFields { - elasticsearch: { - tls: { - verify_hostname: string; - verify_peer: string; - }; - }; -} - /** * The set of Policy configuration settings that are show/edited via the UI */ @@ -928,15 +916,15 @@ export interface UIPolicyConfig { /** * Windows-specific policy configuration that is supported via the UI */ - windows: Pick; + windows: Pick; /** * Mac-specific policy configuration that is supported via the UI */ - mac: Pick; + mac: Pick; /** * Linux-specific policy configuration that is supported via the UI */ - linux: Pick; + linux: Pick; } /** Policy: Malware protection fields */ diff --git a/x-pack/plugins/security_solution/public/management/common/constants.ts b/x-pack/plugins/security_solution/public/management/common/constants.ts index 4264b4ab9d88a..cd4ce743bb701 100644 --- a/x-pack/plugins/security_solution/public/management/common/constants.ts +++ b/x-pack/plugins/security_solution/public/management/common/constants.ts @@ -13,7 +13,6 @@ export const MANAGEMENT_ROUTING_ROOT_PATH = ''; export const MANAGEMENT_ROUTING_ENDPOINTS_PATH = `${MANAGEMENT_ROUTING_ROOT_PATH}/:tabName(${AdministrationSubTab.endpoints})`; export const MANAGEMENT_ROUTING_POLICIES_PATH = `${MANAGEMENT_ROUTING_ROOT_PATH}/:tabName(${AdministrationSubTab.policies})`; export const MANAGEMENT_ROUTING_POLICY_DETAILS_PATH = `${MANAGEMENT_ROUTING_ROOT_PATH}/:tabName(${AdministrationSubTab.policies})/:policyId`; -export const MANAGEMENT_ROUTING_POLICY_ADVANCED_PATH = `${MANAGEMENT_ROUTING_ROOT_PATH}/:tabName(${AdministrationSubTab.policies})/:policyId/advanced`; export const MANAGEMENT_ROUTING_TRUSTED_APPS_PATH = `${MANAGEMENT_ROUTING_ROOT_PATH}/:tabName(${AdministrationSubTab.trustedApps})`; // --[ STORE ]--------------------------------------------------------------------------- diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/middleware.ts b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/middleware.ts index cad37cb6f0e00..250a5b25230f1 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/middleware.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/middleware.ts @@ -12,7 +12,6 @@ import { policyDetails, policyDetailsForUpdate, getPolicyDataForUpdate, - isOnPolicyAdvancedPage, } from './selectors'; import { sendGetPackagePolicy, @@ -31,10 +30,7 @@ export const policyDetailsMiddlewareFactory: ImmutableMiddlewareFactory) => { ); }; -/** Returns a boolean of whether the user is on the advanced policy page or not */ -export const isOnPolicyAdvancedPage = (state: Immutable) => { - return ( - matchPath(state.location?.pathname ?? '', { - path: MANAGEMENT_ROUTING_POLICY_ADVANCED_PATH, - exact: true, - }) !== null - ); -}; - /** Returns the policyId from the url */ export const policyIdFromParams: (state: Immutable) => string = createSelector( (state) => state.location, (location: PolicyDetailsState['location']) => { return ( matchPath(location?.pathname ?? '', { - path: [MANAGEMENT_ROUTING_POLICY_DETAILS_PATH, MANAGEMENT_ROUTING_POLICY_ADVANCED_PATH], + path: MANAGEMENT_ROUTING_POLICY_DETAILS_PATH, exact: true, })?.params?.policyId ?? '' ); diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx index ee13459841656..dd025ae111772 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx @@ -255,8 +255,8 @@ export const PolicyDetails = React.memo(() => { From 06c3b4d50659470bc8feab4b9be9840abc626967 Mon Sep 17 00:00:00 2001 From: Jane Date: Thu, 22 Oct 2020 11:41:32 -0400 Subject: [PATCH 35/41] 145 removed a couple more lines --- .../management/pages/policy/store/policy_details/selectors.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/selectors.ts b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/selectors.ts index f275124a73527..953438526b87e 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/selectors.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/selectors.ts @@ -103,19 +103,16 @@ export const policyConfig: (s: PolicyDetailsState) => UIPolicyConfig = createSel (windows, mac, linux) => { return { windows: { - advanced: windows.advanced, events: windows.events, malware: windows.malware, popup: windows.popup, }, mac: { - advanced: mac.advanced, events: mac.events, malware: mac.malware, popup: mac.popup, }, linux: { - advanced: linux.advanced, events: linux.events, }, }; From 37cc6a40944a7aae1ea25e17524f1ae7cbfff85a Mon Sep 17 00:00:00 2001 From: Jane Date: Thu, 22 Oct 2020 12:18:35 -0400 Subject: [PATCH 36/41] 145 add some fields back in --- .../security_solution/common/endpoint/types/index.ts | 9 ++++++--- .../pages/policy/store/policy_details/selectors.ts | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/security_solution/common/endpoint/types/index.ts b/x-pack/plugins/security_solution/common/endpoint/types/index.ts index 882b3e5182bf3..79157018c315a 100644 --- a/x-pack/plugins/security_solution/common/endpoint/types/index.ts +++ b/x-pack/plugins/security_solution/common/endpoint/types/index.ts @@ -860,6 +860,7 @@ type KbnConfigSchemaNonOptionalProps> = Pi */ export interface PolicyConfig { windows: { + advanced?: {}; events: { dll_and_driver_load: boolean; dns: boolean; @@ -881,6 +882,7 @@ export interface PolicyConfig { }; }; mac: { + advanced?: {}; events: { file: boolean; process: boolean; @@ -898,6 +900,7 @@ export interface PolicyConfig { }; }; linux: { + advanced?: {}; events: { file: boolean; process: boolean; @@ -916,15 +919,15 @@ export interface UIPolicyConfig { /** * Windows-specific policy configuration that is supported via the UI */ - windows: Pick; + windows: Pick; /** * Mac-specific policy configuration that is supported via the UI */ - mac: Pick; + mac: Pick; /** * Linux-specific policy configuration that is supported via the UI */ - linux: Pick; + linux: Pick; } /** Policy: Malware protection fields */ diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/selectors.ts b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/selectors.ts index 953438526b87e..f275124a73527 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/selectors.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/selectors.ts @@ -103,16 +103,19 @@ export const policyConfig: (s: PolicyDetailsState) => UIPolicyConfig = createSel (windows, mac, linux) => { return { windows: { + advanced: windows.advanced, events: windows.events, malware: windows.malware, popup: windows.popup, }, mac: { + advanced: mac.advanced, events: mac.events, malware: mac.malware, popup: mac.popup, }, linux: { + advanced: linux.advanced, events: linux.events, }, }; From c7054c6fba0392e309a80f9ccde2823183ea8412 Mon Sep 17 00:00:00 2001 From: Jane Date: Thu, 22 Oct 2020 17:26:39 -0400 Subject: [PATCH 37/41] 145 add spacer --- .../public/management/pages/policy/view/policy_details.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx index dd025ae111772..8fc5de48f36db 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.tsx @@ -252,6 +252,7 @@ export const PolicyDetails = React.memo(() => { + Date: Tue, 3 Nov 2020 09:35:03 -0500 Subject: [PATCH 38/41] 145 start tests --- .../management/pages/policy/view/policy_advanced.tsx | 2 +- .../apps/endpoint/policy_details.ts | 12 ++++++++++++ .../page_objects/page_utils.ts | 4 ++++ .../page_objects/policy_page.ts | 8 ++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index b4b82b7f692b9..d1b924715edac 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -48,7 +48,7 @@ export const AdvancedPolicyForms = React.memo(() => { /> - + {AdvancedPolicySchema.map((advancedField, index) => { const configPath = advancedField.key.split('.'); return ( diff --git a/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts b/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts index 1f6973ae0f988..2a0605fbe8665 100644 --- a/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts +++ b/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts @@ -61,6 +61,18 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { policyInfo.packagePolicy.name ); }); + + it('and the show advanced settings button is clicked', async () => { + await testSubjects.missingOrFail('advancedPolicyPanel'); + + const advancedPolicyButton = await pageObjects.policy.findAdvancedPolicyButton(); + await advancedPolicyButton.click(); + + await testSubjects.existOrFail('advancedPolicyPanel'); + + await advancedPolicyButton.click(); + await testSubjects.missingOrFail('advancedPolicyPanel'); + }); }); describe('and the save button is clicked', () => { diff --git a/x-pack/test/security_solution_endpoint/page_objects/page_utils.ts b/x-pack/test/security_solution_endpoint/page_objects/page_utils.ts index 810bddc6a48c4..32544e04ad940 100644 --- a/x-pack/test/security_solution_endpoint/page_objects/page_utils.ts +++ b/x-pack/test/security_solution_endpoint/page_objects/page_utils.ts @@ -29,6 +29,10 @@ export function EndpointPageUtils({ getService }: FtrProviderContext) { await euiCheckboxLabelElement.click(); }, + // async addTextToForm(testId: string) { + // const form = await () + // }, + /** * Finds the Table with the given `selector` (test subject) and returns * back an array containing the table's header column text diff --git a/x-pack/test/security_solution_endpoint/page_objects/policy_page.ts b/x-pack/test/security_solution_endpoint/page_objects/policy_page.ts index 92571e5c27566..8f4a4bce961dd 100644 --- a/x-pack/test/security_solution_endpoint/page_objects/policy_page.ts +++ b/x-pack/test/security_solution_endpoint/page_objects/policy_page.ts @@ -77,6 +77,14 @@ export function EndpointPolicyPageProvider({ getService, getPageObjects }: FtrPr return await testSubjects.find('policyDetailsCancelButton'); }, + /** + * Finds and returns the Advanced Policy Show/Hide Button + */ + async findAdvancedPolicyButton() { + await this.ensureIsOnDetailsPage(); + return await testSubjects.find('advancedPolicyButton'); + }, + /** * ensures that the Details Page is the currently display view */ From 8839e5f17406f3a9b054e3adc034efcdd328830b Mon Sep 17 00:00:00 2001 From: Jane Date: Thu, 5 Nov 2020 17:50:20 -0500 Subject: [PATCH 39/41] 145 add findAdvancedPolicyButton --- .../management/pages/policy/view/policy_advanced.tsx | 1 + .../apps/endpoint/policy_details.ts | 9 ++++++++- .../page_objects/policy_page.ts | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index d1b924715edac..fc80d931697e4 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -53,6 +53,7 @@ export const AdvancedPolicyForms = React.memo(() => { const configPath = advancedField.key.split('.'); return ( { await testSubjects.missingOrFail('advancedPolicyPanel'); - const advancedPolicyButton = await pageObjects.policy.findAdvancedPolicyButton(); + let advancedPolicyButton = await pageObjects.policy.findAdvancedPolicyButton(); await advancedPolicyButton.click(); await testSubjects.existOrFail('advancedPolicyPanel'); + advancedPolicyButton = await pageObjects.policy.findAdvancedPolicyButton(); await advancedPolicyButton.click(); await testSubjects.missingOrFail('advancedPolicyPanel'); }); @@ -110,7 +111,13 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { pageObjects.endpointPageUtils.clickOnEuiCheckbox('policyLinuxEvent_file'), pageObjects.endpointPageUtils.clickOnEuiCheckbox('policyMacEvent_file'), ]); + + // const advancedPolicyField = await pageObjects.policy.findAdvancedPolicyField(); + // await advancedPolicyField.clearValue(); + // await advancedPolicyField.click(); + // await advancedPolicyField.type('true'); await pageObjects.policy.confirmAndSave(); + await testSubjects.existOrFail('policyDetailsSuccessMessage'); const agentFullPolicy = await policyTestResources.getFullAgentPolicy( diff --git a/x-pack/test/security_solution_endpoint/page_objects/policy_page.ts b/x-pack/test/security_solution_endpoint/page_objects/policy_page.ts index 8f4a4bce961dd..8bfbdc32452ee 100644 --- a/x-pack/test/security_solution_endpoint/page_objects/policy_page.ts +++ b/x-pack/test/security_solution_endpoint/page_objects/policy_page.ts @@ -85,6 +85,14 @@ export function EndpointPolicyPageProvider({ getService, getPageObjects }: FtrPr return await testSubjects.find('advancedPolicyButton'); }, + /** + * Finds and returns the linux connection_delay Advanced Policy field + */ + async findAdvancedPolicyField() { + await this.ensureIsOnDetailsPage(); + return await testSubjects.find('linux.advanced.agent.connection_delay'); + }, + /** * ensures that the Details Page is the currently display view */ From 6382a30ab9450a3435a9025016bf66281167d188 Mon Sep 17 00:00:00 2001 From: Jane Date: Fri, 6 Nov 2020 17:03:20 -0500 Subject: [PATCH 40/41] 145 test passing --- .../management/pages/policy/view/policy_advanced.tsx | 8 ++++++-- .../apps/endpoint/policy_details.ts | 12 ++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx index fc80d931697e4..e4e03e9453f7a 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_advanced.tsx @@ -53,7 +53,6 @@ export const AdvancedPolicyForms = React.memo(() => { const configPath = advancedField.key.split('.'); return ( } > - + ); diff --git a/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts b/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts index b263151a2f838..849283f7476ec 100644 --- a/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts +++ b/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts @@ -112,10 +112,13 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { pageObjects.endpointPageUtils.clickOnEuiCheckbox('policyMacEvent_file'), ]); - // const advancedPolicyField = await pageObjects.policy.findAdvancedPolicyField(); - // await advancedPolicyField.clearValue(); - // await advancedPolicyField.click(); - // await advancedPolicyField.type('true'); + const advancedPolicyButton = await pageObjects.policy.findAdvancedPolicyButton(); + await advancedPolicyButton.click(); + + const advancedPolicyField = await pageObjects.policy.findAdvancedPolicyField(); + await advancedPolicyField.clearValue(); + await advancedPolicyField.click(); + await advancedPolicyField.type('true'); await pageObjects.policy.confirmAndSave(); await testSubjects.existOrFail('policyDetailsSuccessMessage'); @@ -210,6 +213,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { linux: { events: { file: false, network: true, process: true }, logging: { file: 'info' }, + advanced: { agent: { connection_delay: 'true' } }, }, mac: { events: { file: false, network: true, process: true }, From 75df3ee60fd9e777948997182397bbe521104f84 Mon Sep 17 00:00:00 2001 From: Jane Date: Fri, 6 Nov 2020 17:07:47 -0500 Subject: [PATCH 41/41] 145 remove comment --- .../security_solution_endpoint/page_objects/page_utils.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/x-pack/test/security_solution_endpoint/page_objects/page_utils.ts b/x-pack/test/security_solution_endpoint/page_objects/page_utils.ts index 32544e04ad940..810bddc6a48c4 100644 --- a/x-pack/test/security_solution_endpoint/page_objects/page_utils.ts +++ b/x-pack/test/security_solution_endpoint/page_objects/page_utils.ts @@ -29,10 +29,6 @@ export function EndpointPageUtils({ getService }: FtrProviderContext) { await euiCheckboxLabelElement.click(); }, - // async addTextToForm(testId: string) { - // const form = await () - // }, - /** * Finds the Table with the given `selector` (test subject) and returns * back an array containing the table's header column text