From 0716332459c3760bd7f8d57e8b25f4b4108862db Mon Sep 17 00:00:00 2001 From: CohenIdo <90558359+CohenIdo@users.noreply.github.com> Date: Sun, 1 May 2022 18:07:44 +0300 Subject: [PATCH] [Cloud Security]Update package name (#131137) --- .../common/constants.ts | 20 +++++++++---------- .../api/use_cis_kubernetes_integration.tsx | 4 ++-- .../create_transforms_indices.ts | 10 +++++----- .../benchmark_score_transform.ts | 8 ++++---- .../latest_findings_transform.ts | 4 ++-- .../fleet_integration.test.ts | 4 ++-- .../fleet_integration/fleet_integration.ts | 4 ++-- .../server/plugin.test.ts | 4 ++-- .../cloud_security_posture/server/plugin.ts | 8 ++++---- .../server/routes/benchmarks/benchmarks.ts | 7 +++++-- .../compliance_dashboard.ts | 4 ++-- .../routes/compliance_dashboard/get_trends.ts | 4 ++-- .../update_rules_configuration.ts | 4 ++-- 13 files changed, 43 insertions(+), 42 deletions(-) diff --git a/x-pack/plugins/cloud_security_posture/common/constants.ts b/x-pack/plugins/cloud_security_posture/common/constants.ts index cbb283d73137b..a64a2604609ff 100644 --- a/x-pack/plugins/cloud_security_posture/common/constants.ts +++ b/x-pack/plugins/cloud_security_posture/common/constants.ts @@ -11,19 +11,17 @@ export const BENCHMARKS_ROUTE_PATH = '/internal/cloud_security_posture/benchmark export const UPDATE_RULES_CONFIG_ROUTE_PATH = '/internal/cloud_security_posture/update_rules_config'; -export const CSP_FINDINGS_INDEX_NAME = 'findings'; -export const CIS_KUBERNETES_PACKAGE_NAME = 'cis_kubernetes_benchmark'; -export const FINDINGS_DATA_STREAM_NAME = - // Currently 'cis_kubernetes_benchmark.findings', To be refactored to 'cloud_security_posture.findings' - CIS_KUBERNETES_PACKAGE_NAME + '.' + CSP_FINDINGS_INDEX_NAME; -export const LATEST_FINDINGS_INDEX_NAME = 'cloud_security_posture.findings_latest'; -export const BENCHMARK_SCORE_INDEX_NAME = 'cloud_security_posture.scores'; +export const CLOUD_SECURITY_POSTURE_PACKAGE_NAME = 'cloud_security_posture'; -export const AGENT_LOGS_INDEX_PATTERN = '.logs-cis_kubernetes_benchmark.metadata*'; +export const AGENT_LOGS_INDEX_PATTERN = '.logs-cloud_security_posture.metadata*'; export const CSP_LATEST_FINDINGS_DATA_VIEW = 'logs-cloud_security_posture.findings_latest-*'; -export const FINDINGS_INDEX_PATTERN = 'logs-' + FINDINGS_DATA_STREAM_NAME + '-default*'; -export const LATEST_FINDINGS_INDEX_PATTERN = 'logs-' + LATEST_FINDINGS_INDEX_NAME + '-default'; -export const BENCHMARK_SCORE_INDEX_PATTERN = 'logs-' + BENCHMARK_SCORE_INDEX_NAME + '-default'; +export const FINDINGS_INDEX_PATTERN = 'logs-cloud_security_posture.findings-default*'; + +export const LATEST_FINDINGS_INDEX_NAME = 'cloud_security_posture.findings_latest'; +export const LATEST_FINDINGS_INDEX_DEFAULT_NS = 'logs-' + LATEST_FINDINGS_INDEX_NAME + '-default'; + +export const BENCHMARK_SCORE_INDEX_NAME = 'cloud_security_posture.scores'; +export const BENCHMARK_SCORE_INDEX_DEFAULT_NS = 'logs-' + BENCHMARK_SCORE_INDEX_NAME + '-default'; export const RULE_PASSED = `passed`; export const RULE_FAILED = `failed`; diff --git a/x-pack/plugins/cloud_security_posture/public/common/api/use_cis_kubernetes_integration.tsx b/x-pack/plugins/cloud_security_posture/public/common/api/use_cis_kubernetes_integration.tsx index 0a9f2c2134a6e..5660080cb0a43 100644 --- a/x-pack/plugins/cloud_security_posture/public/common/api/use_cis_kubernetes_integration.tsx +++ b/x-pack/plugins/cloud_security_posture/public/common/api/use_cis_kubernetes_integration.tsx @@ -11,7 +11,7 @@ import { type GetInfoResponse, type DefaultPackagesInstallationError, } from '@kbn/fleet-plugin/common'; -import { CIS_KUBERNETES_PACKAGE_NAME } from '../../../common/constants'; +import { CLOUD_SECURITY_POSTURE_PACKAGE_NAME } from '../../../common/constants'; import { useKibana } from '../hooks/use_kibana'; /** @@ -21,7 +21,7 @@ export const useCisKubernetesIntegration = () => { const { http } = useKibana().services; return useQuery(['integrations'], () => - http.get(epmRouteService.getInfoPath(CIS_KUBERNETES_PACKAGE_NAME), { + http.get(epmRouteService.getInfoPath(CLOUD_SECURITY_POSTURE_PACKAGE_NAME), { query: { experimental: true }, }) ); diff --git a/x-pack/plugins/cloud_security_posture/server/create_indices/create_transforms_indices.ts b/x-pack/plugins/cloud_security_posture/server/create_indices/create_transforms_indices.ts index c30bf09a60e0f..32d53b0a89695 100644 --- a/x-pack/plugins/cloud_security_posture/server/create_indices/create_transforms_indices.ts +++ b/x-pack/plugins/cloud_security_posture/server/create_indices/create_transforms_indices.ts @@ -10,9 +10,9 @@ import type { ElasticsearchClient, Logger } from '@kbn/core/server'; import { benchmarkScoreMapping } from './benchmark_score_mapping'; import { latestFindingsMapping } from './latest_findings_mapping'; import { - LATEST_FINDINGS_INDEX_PATTERN, + LATEST_FINDINGS_INDEX_DEFAULT_NS, LATEST_FINDINGS_INDEX_NAME, - BENCHMARK_SCORE_INDEX_PATTERN, + BENCHMARK_SCORE_INDEX_DEFAULT_NS, BENCHMARK_SCORE_INDEX_NAME, } from '../../common/constants'; @@ -25,14 +25,14 @@ export const initializeCspTransformsIndices = async ( createIndexIfNotExists( esClient, LATEST_FINDINGS_INDEX_NAME, - LATEST_FINDINGS_INDEX_PATTERN, + LATEST_FINDINGS_INDEX_DEFAULT_NS, latestFindingsMapping, logger ), createIndexIfNotExists( esClient, BENCHMARK_SCORE_INDEX_NAME, - BENCHMARK_SCORE_INDEX_PATTERN, + BENCHMARK_SCORE_INDEX_DEFAULT_NS, benchmarkScoreMapping, logger ), @@ -65,7 +65,7 @@ export const createIndexIfNotExists = async ( } } catch (err) { const error = transformError(err); - logger.error(`Failed to create ${LATEST_FINDINGS_INDEX_PATTERN}`); + logger.error(`Failed to create ${LATEST_FINDINGS_INDEX_DEFAULT_NS}`); logger.error(error.message); } }; diff --git a/x-pack/plugins/cloud_security_posture/server/create_transforms/benchmark_score_transform.ts b/x-pack/plugins/cloud_security_posture/server/create_transforms/benchmark_score_transform.ts index 8837fea0fa183..19528d42f09af 100644 --- a/x-pack/plugins/cloud_security_posture/server/create_transforms/benchmark_score_transform.ts +++ b/x-pack/plugins/cloud_security_posture/server/create_transforms/benchmark_score_transform.ts @@ -7,18 +7,18 @@ import type { TransformPutTransformRequest } from '@elastic/elasticsearch/lib/api/types'; import { - LATEST_FINDINGS_INDEX_PATTERN, - BENCHMARK_SCORE_INDEX_PATTERN, + LATEST_FINDINGS_INDEX_DEFAULT_NS, + BENCHMARK_SCORE_INDEX_DEFAULT_NS, } from '../../common/constants'; export const benchmarkScoreTransform: TransformPutTransformRequest = { transform_id: 'cloud_security_posture.score-default-0.0.1', description: 'Calculate latest findings score', source: { - index: LATEST_FINDINGS_INDEX_PATTERN, + index: LATEST_FINDINGS_INDEX_DEFAULT_NS, }, dest: { - index: BENCHMARK_SCORE_INDEX_PATTERN, + index: BENCHMARK_SCORE_INDEX_DEFAULT_NS, }, frequency: '30m', sync: { diff --git a/x-pack/plugins/cloud_security_posture/server/create_transforms/latest_findings_transform.ts b/x-pack/plugins/cloud_security_posture/server/create_transforms/latest_findings_transform.ts index fc042149f3193..fb8027a7675d2 100644 --- a/x-pack/plugins/cloud_security_posture/server/create_transforms/latest_findings_transform.ts +++ b/x-pack/plugins/cloud_security_posture/server/create_transforms/latest_findings_transform.ts @@ -5,7 +5,7 @@ * 2.0. */ import type { TransformPutTransformRequest } from '@elastic/elasticsearch/lib/api/types'; -import { FINDINGS_INDEX_PATTERN, LATEST_FINDINGS_INDEX_PATTERN } from '../../common/constants'; +import { FINDINGS_INDEX_PATTERN, LATEST_FINDINGS_INDEX_DEFAULT_NS } from '../../common/constants'; export const latestFindingsTransform: TransformPutTransformRequest = { transform_id: 'cloud_security_posture.findings_latest-default-0.0.1', @@ -14,7 +14,7 @@ export const latestFindingsTransform: TransformPutTransformRequest = { index: FINDINGS_INDEX_PATTERN, }, dest: { - index: LATEST_FINDINGS_INDEX_PATTERN, + index: LATEST_FINDINGS_INDEX_DEFAULT_NS, }, frequency: '5m', sync: { diff --git a/x-pack/plugins/cloud_security_posture/server/fleet_integration/fleet_integration.test.ts b/x-pack/plugins/cloud_security_posture/server/fleet_integration/fleet_integration.test.ts index 8872c359fc770..69e13ab8c5065 100644 --- a/x-pack/plugins/cloud_security_posture/server/fleet_integration/fleet_integration.test.ts +++ b/x-pack/plugins/cloud_security_posture/server/fleet_integration/fleet_integration.test.ts @@ -8,7 +8,7 @@ import { loggingSystemMock, savedObjectsClientMock } from '@kbn/core/server/mocks'; import { SavedObjectsClientContract, SavedObjectsFindResponse } from '@kbn/core/server'; import { createPackagePolicyMock } from '@kbn/fleet-plugin/common/mocks'; -import { CIS_KUBERNETES_PACKAGE_NAME } from '../../common/constants'; +import { CLOUD_SECURITY_POSTURE_PACKAGE_NAME } from '../../common/constants'; import { onPackagePolicyPostCreateCallback } from './fleet_integration'; describe('create CSP rules with post package create callback', () => { @@ -40,7 +40,7 @@ describe('create CSP rules with post package create callback', () => { }); it('should create stateful rules based on rule template', async () => { const mockPackagePolicy = createPackagePolicyMock(); - mockPackagePolicy.package!.name = CIS_KUBERNETES_PACKAGE_NAME; + mockPackagePolicy.package!.name = CLOUD_SECURITY_POSTURE_PACKAGE_NAME; mockSoClient.find.mockResolvedValueOnce({ saved_objects: [ { diff --git a/x-pack/plugins/cloud_security_posture/server/fleet_integration/fleet_integration.ts b/x-pack/plugins/cloud_security_posture/server/fleet_integration/fleet_integration.ts index 4693a3e55337b..da45a53256bde 100644 --- a/x-pack/plugins/cloud_security_posture/server/fleet_integration/fleet_integration.ts +++ b/x-pack/plugins/cloud_security_posture/server/fleet_integration/fleet_integration.ts @@ -17,7 +17,7 @@ import { cloudSecurityPostureRuleTemplateSavedObjectType, CloudSecurityPostureRuleTemplateSchema, } from '../../common/schemas/csp_rule_template'; -import { CIS_KUBERNETES_PACKAGE_NAME } from '../../common/constants'; +import { CLOUD_SECURITY_POSTURE_PACKAGE_NAME } from '../../common/constants'; import { CspRuleSchema, cspRuleAssetSavedObjectType } from '../../common/schemas/csp_rule'; type ArrayElement = ArrayType extends ReadonlyArray< @@ -29,7 +29,7 @@ type ArrayElement = ArrayType extends Read const isCspPackagePolicy = ( packagePolicy: T ): boolean => { - return packagePolicy.package?.name === CIS_KUBERNETES_PACKAGE_NAME; + return packagePolicy.package?.name === CLOUD_SECURITY_POSTURE_PACKAGE_NAME; }; /** diff --git a/x-pack/plugins/cloud_security_posture/server/plugin.test.ts b/x-pack/plugins/cloud_security_posture/server/plugin.test.ts index 79ff710fd5c2c..43dc550a677a9 100644 --- a/x-pack/plugins/cloud_security_posture/server/plugin.test.ts +++ b/x-pack/plugins/cloud_security_posture/server/plugin.test.ts @@ -24,7 +24,7 @@ import { FleetStartContract, PostPackagePolicyPostCreateCallback, } from '@kbn/fleet-plugin/server'; -import { CIS_KUBERNETES_PACKAGE_NAME } from '../common/constants'; +import { CLOUD_SECURITY_POSTURE_PACKAGE_NAME } from '../common/constants'; import Chance from 'chance'; import type { AwaitedProperties } from '@kbn/utility-types'; import type { DeeplyMockedKeys } from '@kbn/utility-types/jest'; @@ -131,7 +131,7 @@ describe('Cloud Security Posture Plugin', () => { ); const packageMock = createPackagePolicyMock(); - packageMock.package!.name = CIS_KUBERNETES_PACKAGE_NAME; + packageMock.package!.name = CLOUD_SECURITY_POSTURE_PACKAGE_NAME; const packagePolicyPostCreateCallbacks: PostPackagePolicyPostCreateCallback[] = []; fleetMock.registerExternalCallback.mockImplementation((...args) => { diff --git a/x-pack/plugins/cloud_security_posture/server/plugin.ts b/x-pack/plugins/cloud_security_posture/server/plugin.ts index 5647a9adcd0cc..d9fdea9488036 100755 --- a/x-pack/plugins/cloud_security_posture/server/plugin.ts +++ b/x-pack/plugins/cloud_security_posture/server/plugin.ts @@ -33,7 +33,7 @@ import { onPackagePolicyPostCreateCallback, onPackagePolicyDeleteCallback, } from './fleet_integration/fleet_integration'; -import { CIS_KUBERNETES_PACKAGE_NAME } from '../common/constants'; +import { CLOUD_SECURITY_POSTURE_PACKAGE_NAME } from '../common/constants'; export interface CspAppContext { logger: Logger; @@ -84,7 +84,7 @@ export class CspPlugin plugins.fleet.fleetSetupCompleted().then(async () => { const packageInfo = await plugins.fleet.packageService.asInternalUser.getInstallation( - CIS_KUBERNETES_PACKAGE_NAME + CLOUD_SECURITY_POSTURE_PACKAGE_NAME ); // If package is installed we want to make sure all needed assets are installed @@ -100,7 +100,7 @@ export class CspPlugin context: RequestHandlerContext, _: KibanaRequest ): Promise => { - if (packagePolicy.package?.name === CIS_KUBERNETES_PACKAGE_NAME) { + if (packagePolicy.package?.name === CLOUD_SECURITY_POSTURE_PACKAGE_NAME) { await this.initialize(core); const soClient = (await context.core).savedObjects.client; await onPackagePolicyPostCreateCallback(this.logger, packagePolicy, soClient); @@ -114,7 +114,7 @@ export class CspPlugin 'postPackagePolicyDelete', async (deletedPackagePolicies: DeepReadonly) => { for (const deletedPackagePolicy of deletedPackagePolicies) { - if (deletedPackagePolicy.package?.name === CIS_KUBERNETES_PACKAGE_NAME) { + if (deletedPackagePolicy.package?.name === CLOUD_SECURITY_POSTURE_PACKAGE_NAME) { await onPackagePolicyDeleteCallback( this.logger, deletedPackagePolicy, diff --git a/x-pack/plugins/cloud_security_posture/server/routes/benchmarks/benchmarks.ts b/x-pack/plugins/cloud_security_posture/server/routes/benchmarks/benchmarks.ts index 2112701f42d4a..a2cb7d06f1f58 100644 --- a/x-pack/plugins/cloud_security_posture/server/routes/benchmarks/benchmarks.ts +++ b/x-pack/plugins/cloud_security_posture/server/routes/benchmarks/benchmarks.ts @@ -19,7 +19,10 @@ import type { AgentPolicy, ListResult, } from '@kbn/fleet-plugin/common'; -import { BENCHMARKS_ROUTE_PATH, CIS_KUBERNETES_PACKAGE_NAME } from '../../../common/constants'; +import { + BENCHMARKS_ROUTE_PATH, + CLOUD_SECURITY_POSTURE_PACKAGE_NAME, +} from '../../../common/constants'; import { BENCHMARK_PACKAGE_POLICY_PREFIX, benchmarksInputSchema, @@ -165,7 +168,7 @@ export const defineGetBenchmarksRoute = (router: CspRouter, cspContext: CspAppCo const packagePolicies = await getPackagePolicies( soClient, packagePolicyService, - CIS_KUBERNETES_PACKAGE_NAME, + CLOUD_SECURITY_POSTURE_PACKAGE_NAME, query ); diff --git a/x-pack/plugins/cloud_security_posture/server/routes/compliance_dashboard/compliance_dashboard.ts b/x-pack/plugins/cloud_security_posture/server/routes/compliance_dashboard/compliance_dashboard.ts index 9fdea8e97938f..1a95737df0ad9 100644 --- a/x-pack/plugins/cloud_security_posture/server/routes/compliance_dashboard/compliance_dashboard.ts +++ b/x-pack/plugins/cloud_security_posture/server/routes/compliance_dashboard/compliance_dashboard.ts @@ -8,7 +8,7 @@ import { transformError } from '@kbn/securitysolution-es-utils'; import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types'; import type { ComplianceDashboardData } from '../../../common/types'; -import { LATEST_FINDINGS_INDEX_PATTERN, STATS_ROUTE_PATH } from '../../../common/constants'; +import { LATEST_FINDINGS_INDEX_DEFAULT_NS, STATS_ROUTE_PATH } from '../../../common/constants'; import { CspAppContext } from '../../plugin'; import { getGroupedFindingsEvaluation } from './get_grouped_findings_evaluation'; import { ClusterWithoutTrend, getClusters } from './get_clusters'; @@ -47,7 +47,7 @@ export const defineGetComplianceDashboardRoute = ( const esClient = (await context.core).elasticsearch.client.asCurrentUser; const { id: pitId } = await esClient.openPointInTime({ - index: LATEST_FINDINGS_INDEX_PATTERN, + index: LATEST_FINDINGS_INDEX_DEFAULT_NS, keep_alive: '30s', }); diff --git a/x-pack/plugins/cloud_security_posture/server/routes/compliance_dashboard/get_trends.ts b/x-pack/plugins/cloud_security_posture/server/routes/compliance_dashboard/get_trends.ts index eba14cb8215c2..08d8cd3553fe2 100644 --- a/x-pack/plugins/cloud_security_posture/server/routes/compliance_dashboard/get_trends.ts +++ b/x-pack/plugins/cloud_security_posture/server/routes/compliance_dashboard/get_trends.ts @@ -6,7 +6,7 @@ */ import { ElasticsearchClient } from '@kbn/core/server'; -import { BENCHMARK_SCORE_INDEX_PATTERN } from '../../../common/constants'; +import { BENCHMARK_SCORE_INDEX_DEFAULT_NS } from '../../../common/constants'; import { Stats } from '../../../common/types'; import { calculatePostureScore } from './get_stats'; @@ -26,7 +26,7 @@ export interface ScoreTrendDoc { } export const getTrendsQuery = () => ({ - index: BENCHMARK_SCORE_INDEX_PATTERN, + index: BENCHMARK_SCORE_INDEX_DEFAULT_NS, size: 5, sort: '@timestamp:desc', }); diff --git a/x-pack/plugins/cloud_security_posture/server/routes/configuration/update_rules_configuration.ts b/x-pack/plugins/cloud_security_posture/server/routes/configuration/update_rules_configuration.ts index 7b9e63f8bd69e..ae43443f1571b 100644 --- a/x-pack/plugins/cloud_security_posture/server/routes/configuration/update_rules_configuration.ts +++ b/x-pack/plugins/cloud_security_posture/server/routes/configuration/update_rules_configuration.ts @@ -22,7 +22,7 @@ import { CspAppContext } from '../../plugin'; import { CspRulesConfigSchema } from '../../../common/schemas/csp_configuration'; import { CspRuleSchema, cspRuleAssetSavedObjectType } from '../../../common/schemas/csp_rule'; import { UPDATE_RULES_CONFIG_ROUTE_PATH } from '../../../common/constants'; -import { CIS_KUBERNETES_PACKAGE_NAME } from '../../../common/constants'; +import { CLOUD_SECURITY_POSTURE_PACKAGE_NAME } from '../../../common/constants'; import { CspRouter } from '../../types'; export const getPackagePolicy = async ( @@ -36,7 +36,7 @@ export const getPackagePolicy = async ( if (!packagePolicies || !packagePolicies[0].version) { throw new Error(`package policy Id '${packagePolicyId}' is not exist`); } - if (packagePolicies[0].package?.name !== CIS_KUBERNETES_PACKAGE_NAME) { + if (packagePolicies[0].package?.name !== CLOUD_SECURITY_POSTURE_PACKAGE_NAME) { // TODO: improve this validator to support any future CSP package throw new Error(`Package Policy Id '${packagePolicyId}' is not CSP package`); }