Skip to content

Commit

Permalink
[SECURITY SOLUTION] add enableExperimental plugin configuration set…
Browse files Browse the repository at this point in the history
…ting (#94944) (#95071)

* Added new setting (enableExperimental) to plugin configuration
* Remove plugin config setting `fleetServerEnabled` and use instead `enableExperimental`
  • Loading branch information
paul-tavares authored Mar 22, 2021
1 parent 36f9bc3 commit eb6df37
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 4 deletions.
52 changes: 52 additions & 0 deletions x-pack/plugins/security_solution/common/experimental_features.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export type ExperimentalFeatures = typeof allowedExperimentalValues;

/**
* A list of allowed values that can be used in `xpack.securitySolution.enableExperimental`.
* This object is then used to validate and parse the value entered.
*/
const allowedExperimentalValues = Object.freeze({
fleetServerEnabled: false,
});

type ExperimentalConfigKeys = Array<keyof ExperimentalFeatures>;
type Mutable<T> = { -readonly [P in keyof T]: T[P] };

const SecuritySolutionInvalidExperimentalValue = class extends Error {};
const allowedKeys = Object.keys(allowedExperimentalValues) as Readonly<ExperimentalConfigKeys>;

/**
* Parses the string value used in `xpack.securitySolution.enableExperimental` kibana configuration,
* which should be a string of values delimited by a comma (`,`)
*
* @param configValue
* @throws SecuritySolutionInvalidExperimentalValue
*/
export const parseExperimentalConfigValue = (configValue: string[]): ExperimentalFeatures => {
const enabledFeatures: Mutable<Partial<ExperimentalFeatures>> = {};

for (const value of configValue) {
if (!isValidExperimentalValue(value)) {
throw new SecuritySolutionInvalidExperimentalValue(`[${value}] is not valid.`);
}

enabledFeatures[value as keyof ExperimentalFeatures] = true;
}

return {
...allowedExperimentalValues,
...enabledFeatures,
};
};

export const isValidExperimentalValue = (value: string): boolean => {
return allowedKeys.includes(value as keyof ExperimentalFeatures);
};

export const getExperimentalAllowedValues = (): string[] => [...allowedKeys];
32 changes: 30 additions & 2 deletions x-pack/plugins/security_solution/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
import { schema, TypeOf } from '@kbn/config-schema';
import { PluginInitializerContext } from '../../../../src/core/server';
import { SIGNALS_INDEX_KEY, DEFAULT_SIGNALS_INDEX } from '../common/constants';
import {
getExperimentalAllowedValues,
isValidExperimentalValue,
} from '../common/experimental_features';

const allowedExperimentalValues = getExperimentalAllowedValues();

export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
Expand All @@ -17,8 +23,30 @@ export const configSchema = schema.object({
maxTimelineImportPayloadBytes: schema.number({ defaultValue: 10485760 }),
[SIGNALS_INDEX_KEY]: schema.string({ defaultValue: DEFAULT_SIGNALS_INDEX }),

/** Fleet server integration */
fleetServerEnabled: schema.boolean({ defaultValue: false }),
/**
* For internal use. A list of string values (comma delimited) that will enable experimental
* type of functionality that is not yet released. Valid values for this settings need to
* be defined in:
* `x-pack/plugins/security_solution/common/experimental_features.ts`
* under the `allowedExperimentalValues` object
*
* @example
* xpack.securitySolution.enableExperimental:
* - fleetServerEnabled
* - trustedAppsByPolicyEnabled
*/
enableExperimental: schema.arrayOf(schema.string(), {
defaultValue: () => [],
validate(list) {
for (const key of list) {
if (!isValidExperimentalValue(key)) {
return `[${key}] is not allowed. Allowed values are: ${allowedExperimentalValues.join(
', '
)}`;
}
}
},
}),

/**
* Host Endpoint Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const createMockConfig = (): ConfigType => ({
maxRuleImportPayloadBytes: 10485760,
maxTimelineImportExportSize: 10000,
maxTimelineImportPayloadBytes: 10485760,
fleetServerEnabled: true,
enableExperimental: [],
endpointResultListDefaultFirstPageIndex: 0,
endpointResultListDefaultPageSize: 10,
alertResultListDefaultDateRange: {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/security_solution/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import {
import { licenseService } from './lib/license/license';
import { PolicyWatcher } from './endpoint/lib/policy/license_watch';
import { securitySolutionTimelineEqlSearchStrategyProvider } from './search_strategy/timeline/eql';
import { parseExperimentalConfigValue } from '../common/experimental_features';

export interface SetupPlugins {
alerting: AlertingSetup;
Expand Down Expand Up @@ -357,7 +358,7 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
logger: this.logger,
cache: this.artifactsCache,
},
this.config.fleetServerEnabled
parseExperimentalConfigValue(this.config.enableExperimental).fleetServerEnabled
);

if (this.manifestTask) {
Expand Down

0 comments on commit eb6df37

Please sign in to comment.