From 4a026eeec1424cf74ec2b9c09a2453dc54eefa0d Mon Sep 17 00:00:00 2001 From: Ievgen Sorokopud Date: Thu, 17 Oct 2024 20:31:53 +0200 Subject: [PATCH 1/6] Hide assistant's knowledge base UI when `assistantKnowledgeBaseByDefault` feature flag is disabled --- .../features/src/assistant/index.ts | 9 ++++-- .../src/assistant/kibana_sub_features.ts | 30 +++++++++++++++---- .../product_features_service.ts | 5 +++- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/x-pack/packages/security-solution/features/src/assistant/index.ts b/x-pack/packages/security-solution/features/src/assistant/index.ts index eaca4b4913ee2..2f7447a53efbe 100644 --- a/x-pack/packages/security-solution/features/src/assistant/index.ts +++ b/x-pack/packages/security-solution/features/src/assistant/index.ts @@ -5,15 +5,18 @@ * 2.0. */ import type { AssistantSubFeatureId } from '../product_features_keys'; +import type { SecurityFeatureParams } from '../security/types'; import type { ProductFeatureParams } from '../types'; import { getAssistantBaseKibanaFeature } from './kibana_features'; import { getAssistantBaseKibanaSubFeatureIds, - assistantSubFeaturesMap, + getAssistantSubFeaturesMap, } from './kibana_sub_features'; -export const getAssistantFeature = (): ProductFeatureParams => ({ +export const getAssistantFeature = ( + params: SecurityFeatureParams +): ProductFeatureParams => ({ baseKibanaFeature: getAssistantBaseKibanaFeature(), baseKibanaSubFeatureIds: getAssistantBaseKibanaSubFeatureIds(), - subFeaturesMap: assistantSubFeaturesMap, + subFeaturesMap: getAssistantSubFeaturesMap(params), }); diff --git a/x-pack/packages/security-solution/features/src/assistant/kibana_sub_features.ts b/x-pack/packages/security-solution/features/src/assistant/kibana_sub_features.ts index d116aa36d21f0..49548a0ed40a2 100644 --- a/x-pack/packages/security-solution/features/src/assistant/kibana_sub_features.ts +++ b/x-pack/packages/security-solution/features/src/assistant/kibana_sub_features.ts @@ -8,6 +8,7 @@ import { i18n } from '@kbn/i18n'; import type { SubFeatureConfig } from '@kbn/features-plugin/common'; import { APP_ID } from '../constants'; +import type { SecurityFeatureParams } from '../security/types'; const updateAnonymizationSubFeature: SubFeatureConfig = { name: i18n.translate( @@ -102,9 +103,28 @@ export const getAssistantBaseKibanaSubFeatureIds = (): AssistantSubFeatureId[] = * Defines all the Security Assistant subFeatures available. * The order of the subFeatures is the order they will be displayed */ -export const assistantSubFeaturesMap = Object.freeze( - new Map([ +export const getAssistantSubFeaturesMap = ({ + experimentalFeatures, +}: SecurityFeatureParams): Map => { + const assistantSubFeaturesList: Array<[AssistantSubFeatureId, SubFeatureConfig]> = [ [AssistantSubFeatureId.updateAnonymization, updateAnonymizationSubFeature], - [AssistantSubFeatureId.manageGlobalKnowledgeBase, manageGlobalKnowledgeBaseSubFeature], - ]) -); + ]; + + // Use the following code to add feature based on feature flag + // if (experimentalFeatures.featureFlagName) { + // assistantSubFeaturesList.push([AssistantSubFeatureId.featureId, featureSubFeature]); + // } + + if (experimentalFeatures.assistantKnowledgeBaseByDefault) { + assistantSubFeaturesList.push([ + AssistantSubFeatureId.manageGlobalKnowledgeBase, + manageGlobalKnowledgeBaseSubFeature, + ]); + } + + const assistantSubFeaturesMap = new Map( + assistantSubFeaturesList + ); + + return Object.freeze(assistantSubFeaturesMap); +}; diff --git a/x-pack/plugins/security_solution/server/lib/product_features_service/product_features_service.ts b/x-pack/plugins/security_solution/server/lib/product_features_service/product_features_service.ts index e30c067a0d4a4..0af21e2b2f656 100644 --- a/x-pack/plugins/security_solution/server/lib/product_features_service/product_features_service.ts +++ b/x-pack/plugins/security_solution/server/lib/product_features_service/product_features_service.ts @@ -62,7 +62,10 @@ export class ProductFeaturesService { casesFeature.baseKibanaSubFeatureIds ); - const assistantFeature = getAssistantFeature(); + const assistantFeature = getAssistantFeature({ + savedObjects: securityDefaultSavedObjects, + experimentalFeatures: this.experimentalFeatures, + }); this.securityAssistantProductFeatures = new ProductFeatures( this.logger, assistantFeature.subFeaturesMap, From 950680b5b9bd2302ebe8d8efd1b5f8692589422b Mon Sep 17 00:00:00 2001 From: Ievgen Sorokopud Date: Thu, 17 Oct 2024 21:06:22 +0200 Subject: [PATCH 2/6] Review feedback: redundant params --- .../security-solution/features/src/assistant/index.ts | 5 ++--- .../features/src/assistant/kibana_sub_features.ts | 7 +++---- .../product_features_service/product_features_service.ts | 5 +---- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/x-pack/packages/security-solution/features/src/assistant/index.ts b/x-pack/packages/security-solution/features/src/assistant/index.ts index 2f7447a53efbe..ea0658d795455 100644 --- a/x-pack/packages/security-solution/features/src/assistant/index.ts +++ b/x-pack/packages/security-solution/features/src/assistant/index.ts @@ -5,7 +5,6 @@ * 2.0. */ import type { AssistantSubFeatureId } from '../product_features_keys'; -import type { SecurityFeatureParams } from '../security/types'; import type { ProductFeatureParams } from '../types'; import { getAssistantBaseKibanaFeature } from './kibana_features'; import { @@ -14,9 +13,9 @@ import { } from './kibana_sub_features'; export const getAssistantFeature = ( - params: SecurityFeatureParams + experimentalFeatures: Record ): ProductFeatureParams => ({ baseKibanaFeature: getAssistantBaseKibanaFeature(), baseKibanaSubFeatureIds: getAssistantBaseKibanaSubFeatureIds(), - subFeaturesMap: getAssistantSubFeaturesMap(params), + subFeaturesMap: getAssistantSubFeaturesMap(experimentalFeatures), }); diff --git a/x-pack/packages/security-solution/features/src/assistant/kibana_sub_features.ts b/x-pack/packages/security-solution/features/src/assistant/kibana_sub_features.ts index 49548a0ed40a2..dbf9505193ecf 100644 --- a/x-pack/packages/security-solution/features/src/assistant/kibana_sub_features.ts +++ b/x-pack/packages/security-solution/features/src/assistant/kibana_sub_features.ts @@ -8,7 +8,6 @@ import { i18n } from '@kbn/i18n'; import type { SubFeatureConfig } from '@kbn/features-plugin/common'; import { APP_ID } from '../constants'; -import type { SecurityFeatureParams } from '../security/types'; const updateAnonymizationSubFeature: SubFeatureConfig = { name: i18n.translate( @@ -103,9 +102,9 @@ export const getAssistantBaseKibanaSubFeatureIds = (): AssistantSubFeatureId[] = * Defines all the Security Assistant subFeatures available. * The order of the subFeatures is the order they will be displayed */ -export const getAssistantSubFeaturesMap = ({ - experimentalFeatures, -}: SecurityFeatureParams): Map => { +export const getAssistantSubFeaturesMap = ( + experimentalFeatures: Record +): Map => { const assistantSubFeaturesList: Array<[AssistantSubFeatureId, SubFeatureConfig]> = [ [AssistantSubFeatureId.updateAnonymization, updateAnonymizationSubFeature], ]; diff --git a/x-pack/plugins/security_solution/server/lib/product_features_service/product_features_service.ts b/x-pack/plugins/security_solution/server/lib/product_features_service/product_features_service.ts index 0af21e2b2f656..29ef513b40bb3 100644 --- a/x-pack/plugins/security_solution/server/lib/product_features_service/product_features_service.ts +++ b/x-pack/plugins/security_solution/server/lib/product_features_service/product_features_service.ts @@ -62,10 +62,7 @@ export class ProductFeaturesService { casesFeature.baseKibanaSubFeatureIds ); - const assistantFeature = getAssistantFeature({ - savedObjects: securityDefaultSavedObjects, - experimentalFeatures: this.experimentalFeatures, - }); + const assistantFeature = getAssistantFeature(this.experimentalFeatures); this.securityAssistantProductFeatures = new ProductFeatures( this.logger, assistantFeature.subFeaturesMap, From 52d18dae4e9210c3db5b64ebeed604bce26d1087 Mon Sep 17 00:00:00 2001 From: Ievgen Sorokopud Date: Thu, 17 Oct 2024 22:43:54 +0200 Subject: [PATCH 3/6] Fix FTR tests --- x-pack/test/api_integration/apis/security/privileges.ts | 1 - x-pack/test/api_integration/apis/security/privileges_basic.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/x-pack/test/api_integration/apis/security/privileges.ts b/x-pack/test/api_integration/apis/security/privileges.ts index 1ff986829415b..8c95f39fd6e3e 100644 --- a/x-pack/test/api_integration/apis/security/privileges.ts +++ b/x-pack/test/api_integration/apis/security/privileges.ts @@ -78,7 +78,6 @@ export default function ({ getService }: FtrProviderContext) { 'minimal_all', 'minimal_read', 'update_anonymization', - 'manage_global_knowledge_base', ], securitySolutionAttackDiscovery: ['all', 'read', 'minimal_all', 'minimal_read'], securitySolutionCases: [ diff --git a/x-pack/test/api_integration/apis/security/privileges_basic.ts b/x-pack/test/api_integration/apis/security/privileges_basic.ts index 57a166ef4be9d..41fe1e79b7f12 100644 --- a/x-pack/test/api_integration/apis/security/privileges_basic.ts +++ b/x-pack/test/api_integration/apis/security/privileges_basic.ts @@ -166,7 +166,6 @@ export default function ({ getService }: FtrProviderContext) { 'minimal_all', 'minimal_read', 'update_anonymization', - 'manage_global_knowledge_base', ], securitySolutionAttackDiscovery: ['all', 'read', 'minimal_all', 'minimal_read'], securitySolutionCases: [ From ad464937592b6c2f64b168143b51fae459fa8d3a Mon Sep 17 00:00:00 2001 From: Ievgen Sorokopud Date: Thu, 17 Oct 2024 23:04:11 +0200 Subject: [PATCH 4/6] Revert "Fix FTR tests" This reverts commit 52d18dae4e9210c3db5b64ebeed604bce26d1087. --- x-pack/test/api_integration/apis/security/privileges.ts | 1 + x-pack/test/api_integration/apis/security/privileges_basic.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/x-pack/test/api_integration/apis/security/privileges.ts b/x-pack/test/api_integration/apis/security/privileges.ts index 8c95f39fd6e3e..1ff986829415b 100644 --- a/x-pack/test/api_integration/apis/security/privileges.ts +++ b/x-pack/test/api_integration/apis/security/privileges.ts @@ -78,6 +78,7 @@ export default function ({ getService }: FtrProviderContext) { 'minimal_all', 'minimal_read', 'update_anonymization', + 'manage_global_knowledge_base', ], securitySolutionAttackDiscovery: ['all', 'read', 'minimal_all', 'minimal_read'], securitySolutionCases: [ diff --git a/x-pack/test/api_integration/apis/security/privileges_basic.ts b/x-pack/test/api_integration/apis/security/privileges_basic.ts index 41fe1e79b7f12..57a166ef4be9d 100644 --- a/x-pack/test/api_integration/apis/security/privileges_basic.ts +++ b/x-pack/test/api_integration/apis/security/privileges_basic.ts @@ -166,6 +166,7 @@ export default function ({ getService }: FtrProviderContext) { 'minimal_all', 'minimal_read', 'update_anonymization', + 'manage_global_knowledge_base', ], securitySolutionAttackDiscovery: ['all', 'read', 'minimal_all', 'minimal_read'], securitySolutionCases: [ From 04d0ae23605ea4bb3987daf858a359c479970b4a Mon Sep 17 00:00:00 2001 From: Ievgen Sorokopud Date: Fri, 18 Oct 2024 10:08:34 +0200 Subject: [PATCH 5/6] Fix FTR tests --- x-pack/test/api_integration/config.ts | 3 +++ x-pack/test/api_integration/config_security_basic.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/x-pack/test/api_integration/config.ts b/x-pack/test/api_integration/config.ts index e43c76d42adfa..9cb5a134681a9 100644 --- a/x-pack/test/api_integration/config.ts +++ b/x-pack/test/api_integration/config.ts @@ -30,6 +30,9 @@ export async function getApiIntegrationConfig({ readConfigFile }: FtrConfigProvi '--xpack.ruleRegistry.write.enabled=true', '--xpack.ruleRegistry.write.enabled=true', '--xpack.ruleRegistry.write.cache.enabled=false', + `--xpack.securitySolution.enableExperimental=${JSON.stringify([ + 'assistantKnowledgeBaseByDefault', + ])}`, '--monitoring_collection.opentelemetry.metrics.prometheus.enabled=true', ], }, diff --git a/x-pack/test/api_integration/config_security_basic.ts b/x-pack/test/api_integration/config_security_basic.ts index 0164e8f54f822..f7fe695da397d 100644 --- a/x-pack/test/api_integration/config_security_basic.ts +++ b/x-pack/test/api_integration/config_security_basic.ts @@ -23,6 +23,9 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { 'xpack.license.self_generated.type=basic', 'xpack.security.enabled=true', 'xpack.security.authc.api_key.enabled=true', + `--xpack.securitySolution.enableExperimental=${JSON.stringify([ + 'assistantKnowledgeBaseByDefault', + ])}`, ], }, junit: { From 0380c1180d2f4cbf26b56882b143b0a901b53d21 Mon Sep 17 00:00:00 2001 From: Ievgen Sorokopud Date: Fri, 18 Oct 2024 11:43:21 +0200 Subject: [PATCH 6/6] Fix FTR tests --- x-pack/test/api_integration/config_security_basic.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/x-pack/test/api_integration/config_security_basic.ts b/x-pack/test/api_integration/config_security_basic.ts index f7fe695da397d..0164e8f54f822 100644 --- a/x-pack/test/api_integration/config_security_basic.ts +++ b/x-pack/test/api_integration/config_security_basic.ts @@ -23,9 +23,6 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { 'xpack.license.self_generated.type=basic', 'xpack.security.enabled=true', 'xpack.security.authc.api_key.enabled=true', - `--xpack.securitySolution.enableExperimental=${JSON.stringify([ - 'assistantKnowledgeBaseByDefault', - ])}`, ], }, junit: {