mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[SECURITY SOLUTION] add enableExperimental
plugin configuration setting (#94944)
* Added new setting (enableExperimental) to plugin configuration * Remove plugin config setting `fleetServerEnabled` and use instead `enableExperimental`
This commit is contained in:
parent
04e4661cbf
commit
e7bb8b7b8a
4 changed files with 85 additions and 4 deletions
|
@ -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];
|
|
@ -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 }),
|
||||
|
@ -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
|
||||
|
|
|
@ -21,7 +21,7 @@ export const createMockConfig = (): ConfigType => ({
|
|||
maxRuleImportPayloadBytes: 10485760,
|
||||
maxTimelineImportExportSize: 10000,
|
||||
maxTimelineImportPayloadBytes: 10485760,
|
||||
fleetServerEnabled: true,
|
||||
enableExperimental: [],
|
||||
endpointResultListDefaultFirstPageIndex: 0,
|
||||
endpointResultListDefaultPageSize: 10,
|
||||
alertResultListDefaultDateRange: {
|
||||
|
|
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue