Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cloud Security] Misconfiguration preview & Refactor CSP Plugin to include new package PHASE 2 #190933

Merged
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f97c940
preliminary adding types to csp and csp-common packages
animehart Aug 20, 2024
5989868
moving types from csp plugin to csp packages + updating import and ex…
animehart Aug 21, 2024
6283bd4
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 21, 2024
7fafa52
attempt on fixing bundle size leak
animehart Aug 21, 2024
dad76fd
Merge branch 'misconfiguration-preview-refactor-phase-2' of github.co…
animehart Aug 21, 2024
72f00b0
change schema import to be from schema folder + updating index.ts exp…
animehart Aug 23, 2024
783626e
forgot to add index.ts in last commit
animehart Aug 23, 2024
a89617d
removed re export on csp plugin + updated imports to be directly from…
animehart Aug 23, 2024
6600a34
fix ci failure: forgot to edit some file
animehart Aug 23, 2024
19d7451
fix check types failure
animehart Aug 23, 2024
51b44b9
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 23, 2024
e2b8f48
fix failed FTR due to forgot updating imports on that file
animehart Aug 23, 2024
4496119
fix conflict merge
animehart Aug 23, 2024
9f2814e
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 23, 2024
113376a
remove re exports and update imports of csp_finding related types to …
animehart Aug 24, 2024
c1a3b6a
Merge branch 'misconfiguration-preview-refactor-phase-2' of github.co…
animehart Aug 24, 2024
3398ecf
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 24, 2024
8c69b3e
fix check types failure + removed re-export and update import stateme…
animehart Aug 24, 2024
0c1f750
Merge branch 'misconfiguration-preview-refactor-phase-2' of github.co…
animehart Aug 24, 2024
447c47b
updating CspStatusCode imports to be directly from csp common package
animehart Aug 24, 2024
feae686
Merge branch 'main' into misconfiguration-preview-refactor-phase-2
animehart Aug 26, 2024
ceafb0b
PR Comments: Updated type imports to explicitly use import type inste…
animehart Aug 26, 2024
6b8adb6
fix conflict
animehart Aug 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture-common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 const KSPM_POLICY_TEMPLATE = 'kspm';
export const CSPM_POLICY_TEMPLATE = 'cspm';
export const CDR_LATEST_NATIVE_MISCONFIGURATIONS_INDEX_PATTERN =
'logs-cloud_security_posture.findings_latest-default';
export const CDR_LATEST_THIRD_PARTY_MISCONFIGURATIONS_INDEX_PATTERN =
'logs-*_latest_misconfigurations_cdr';
export const CDR_MISCONFIGURATIONS_INDEX_PATTERN = `${CDR_LATEST_NATIVE_MISCONFIGURATIONS_INDEX_PATTERN},${CDR_LATEST_THIRD_PARTY_MISCONFIGURATIONS_INDEX_PATTERN}`;
export const LATEST_FINDINGS_RETENTION_POLICY = '26h';
export const MAX_FINDINGS_TO_LOAD = 500;
export const CSP_GET_BENCHMARK_RULES_STATE_ROUTE_PATH =
'/internal/cloud_security_posture/rules/_get_states';
export const CSP_GET_BENCHMARK_RULES_STATE_API_CURRENT_VERSION = '1';
export const STATUS_ROUTE_PATH = '/internal/cloud_security_posture/status';
export const STATUS_API_CURRENT_VERSION = '1';
22 changes: 22 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture-common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.
*/

// Careful of exporting anything from this file as any file(s) you export here will cause your page bundle size to increase.
// If you're using functions/types/etc... internally or within integration tests it's best to import directly from their paths
// than expose the functions/types/etc... here. You should _only_ expose functions/types/etc... that need to be shared with other plugins here.

export type {
CspStatusCode,
IndexStatus,
IndexDetails,
BaseCspSetupBothPolicy,
BaseCspSetupStatus,
CspSetupStatus,
} from './types';
export * from './constants';
export type { CspFinding } from './schema/csp_finding';
export type { CspBenchmarkRuleMetadata, CspBenchmarkRulesStates } from './schema/rules';
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

// TODO: this needs to be defined in a versioned schema
import type { EcsDataStream, EcsEvent } from '@elastic/ecs';
import { CspBenchmarkRuleMetadata } from '../types/latest';
import { CspBenchmarkRuleMetadata } from './rules';

export interface CspFinding {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file doesn't contain schema anymore, only CspFinding interface , maybe make sense to move the code to types.ts?

'@timestamp': string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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 { ruleStateAttributes, cspBenchmarkRuleMetadataSchema, rulesStates } from './rules';
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.
*/
import { TypeOf, schema } from '@kbn/config-schema';
import { CSPM_POLICY_TEMPLATE, KSPM_POLICY_TEMPLATE } from '../constants';

export type CspBenchmarkRuleMetadata = TypeOf<typeof cspBenchmarkRuleMetadataSchema>;

export const cspBenchmarkRuleMetadataSchema = schema.object({
audit: schema.string(),
benchmark: schema.object({
name: schema.string(),
posture_type: schema.maybe(
schema.oneOf([schema.literal(CSPM_POLICY_TEMPLATE), schema.literal(KSPM_POLICY_TEMPLATE)])
),
id: schema.string(),
version: schema.string(),
rule_number: schema.maybe(schema.string()),
}),
default_value: schema.maybe(schema.string()),
description: schema.string(),
id: schema.string(),
impact: schema.maybe(schema.string()),
name: schema.string(),
profile_applicability: schema.string(),
rationale: schema.string(),
references: schema.maybe(schema.string()),
rego_rule_id: schema.string(),
remediation: schema.string(),
section: schema.string(),
tags: schema.arrayOf(schema.string()),
version: schema.string(),
});

export const ruleStateAttributes = schema.object({
muted: schema.boolean(),
benchmark_id: schema.string(),
benchmark_version: schema.string(),
rule_number: schema.string(),
rule_id: schema.string(),
});

export const rulesStates = schema.recordOf(schema.string(), ruleStateAttributes);

export type CspBenchmarkRulesStates = TypeOf<typeof rulesStates>;
20 changes: 20 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture-common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/config-schema",
]
}
44 changes: 44 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture-common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 CspStatusCode =
| 'indexed' // latest findings index exists and has results
| 'indexing' // index timeout was not surpassed since installation, assumes data is being indexed
| 'unprivileged' // user lacks privileges for the latest findings index
| 'index-timeout' // index timeout was surpassed since installation
| 'not-deployed' // no healthy agents were deployed
| 'not-installed' // number of installed csp integrations is 0;
| 'waiting_for_results'; // have healthy agents but no findings at all, assumes data is being indexed for the 1st time

export type IndexStatus =
| 'not-empty' // Index contains documents
| 'empty' // Index doesn't contain documents (or doesn't exist)
| 'unprivileged'; // User doesn't have access to query the index

export interface IndexDetails {
index: string;
status: IndexStatus;
}

export interface BaseCspSetupBothPolicy {
status: CspStatusCode;
installedPackagePolicies: number;
healthyAgents: number;
}

export interface BaseCspSetupStatus {
indicesDetails: IndexDetails[];
latestPackageVersion: string;
cspm: BaseCspSetupBothPolicy;
kspm: BaseCspSetupBothPolicy;
vuln_mgmt: BaseCspSetupBothPolicy;
isPluginInitialized: boolean;
installedPackageVersion?: string | undefined;
hasMisconfigurationsFindings?: boolean;
}

export type CspSetupStatus = BaseCspSetupStatus;
8 changes: 8 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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 * from './type';
37 changes: 37 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react"
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/core",
"@kbn/licensing-plugin",
"@kbn/data-views-plugin",
"@kbn/unified-search-plugin",
"@kbn/ui-actions-plugin",
"@kbn/field-formats-plugin",
"@kbn/data-view-field-editor-plugin",
"@kbn/data-plugin",
"@kbn/kibana-utils-plugin",
"@kbn/charts-plugin",
"@kbn/discover-plugin",
"@kbn/fleet-plugin",
"@kbn/usage-collection-plugin",
"@kbn/share-plugin",
"@kbn/es-query",
"@kbn/cloud-plugin",
"@kbn/spaces-plugin",
]
}
53 changes: 53 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.
*/

import type { CloudSetup } from '@kbn/cloud-plugin/public';
import type { LicensingPluginStart } from '@kbn/licensing-plugin/public';
import { DataViewsServicePublic } from '@kbn/data-views-plugin/public';
import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public';
import { UiActionsStart } from '@kbn/ui-actions-plugin/public';
import { FieldFormatsStart } from '@kbn/field-formats-plugin/public';
import { IndexPatternFieldEditorStart } from '@kbn/data-view-field-editor-plugin/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { ToastsStart } from '@kbn/core/public';
import { Storage } from '@kbn/kibana-utils-plugin/public';

import type { ChartsPluginStart } from '@kbn/charts-plugin/public';
import type { DiscoverStart } from '@kbn/discover-plugin/public';
import type { FleetStart } from '@kbn/fleet-plugin/public';
import type { UsageCollectionStart } from '@kbn/usage-collection-plugin/public';
import { SharePluginStart } from '@kbn/share-plugin/public';
import { SpacesPluginStart } from '@kbn/spaces-plugin/public';

import type { BoolQuery } from '@kbn/es-query';
export interface FindingsBaseEsQuery {
query?: {
bool: BoolQuery;
};
}

export interface CspClientPluginStartDeps {
// required
data: DataPublicPluginStart;
dataViews: DataViewsServicePublic;
dataViewFieldEditor: IndexPatternFieldEditorStart;
unifiedSearch: UnifiedSearchPublicPluginStart;
uiActions: UiActionsStart;
fieldFormats: FieldFormatsStart;
toastNotifications: ToastsStart;
charts: ChartsPluginStart;
discover: DiscoverStart;
fleet: FleetStart;
licensing: LicensingPluginStart;
share: SharePluginStart;
storage: Storage;
spaces: SpacesPluginStart;
cloud: CloudSetup;

// optional
usageCollection?: UsageCollectionStart;
}
16 changes: 1 addition & 15 deletions x-pack/plugins/cloud_security_posture/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { KSPM_POLICY_TEMPLATE, CSPM_POLICY_TEMPLATE } from '@kbn/cloud-security-posture-common';
import {
AwsCredentialsTypeFieldMap,
GcpCredentialsTypeFieldMap,
Expand All @@ -13,8 +14,6 @@ import {
} from './types_old';

export const CLOUD_SECURITY_INTERTAL_PREFIX_ROUTE_PATH = '/internal/cloud_security_posture/';
export const STATUS_ROUTE_PATH = '/internal/cloud_security_posture/status';
export const STATUS_API_CURRENT_VERSION = '1';

export const STATS_ROUTE_PATH = '/internal/cloud_security_posture/stats/{policy_template}';

Expand All @@ -31,10 +30,6 @@ export const CSP_BENCHMARK_RULES_BULK_ACTION_ROUTE_PATH =
'/internal/cloud_security_posture/rules/_bulk_action';
export const CSP_BENCHMARK_RULES_BULK_ACTION_API_CURRENT_VERSION = '1';

export const CSP_GET_BENCHMARK_RULES_STATE_ROUTE_PATH =
'/internal/cloud_security_posture/rules/_get_states';
export const CSP_GET_BENCHMARK_RULES_STATE_API_CURRENT_VERSION = '1';

export const GET_DETECTION_RULE_ALERTS_STATUS_PATH =
'/internal/cloud_security_posture/detection_engine_rules/alerts/_status';
export const DETECTION_RULE_ALERTS_STATUS_API_CURRENT_VERSION = '1';
Expand All @@ -45,11 +40,6 @@ export const CLOUD_SECURITY_POSTURE_PACKAGE_NAME = 'cloud_security_posture';
export const CDR_MISCONFIGURATIONS_DATA_VIEW_NAME = 'Latest Cloud Security Misconfigurations';
export const CDR_MISCONFIGURATIONS_DATA_VIEW_ID_PREFIX =
'security_solution_cdr_latest_misconfigurations';
export const CDR_LATEST_NATIVE_MISCONFIGURATIONS_INDEX_PATTERN =
'logs-cloud_security_posture.findings_latest-default';
export const CDR_LATEST_THIRD_PARTY_MISCONFIGURATIONS_INDEX_PATTERN =
'logs-*_latest_misconfigurations_cdr';
export const CDR_MISCONFIGURATIONS_INDEX_PATTERN = `${CDR_LATEST_NATIVE_MISCONFIGURATIONS_INDEX_PATTERN},${CDR_LATEST_THIRD_PARTY_MISCONFIGURATIONS_INDEX_PATTERN}`;

export const CDR_VULNERABILITIES_DATA_VIEW_NAME = 'Latest Cloud Security Vulnerabilities';
export const CDR_VULNERABILITIES_DATA_VIEW_ID_PREFIX =
Expand All @@ -65,8 +55,6 @@ export const LATEST_FINDINGS_INDEX_TEMPLATE_NAME = 'logs-cloud_security_posture.
export const LATEST_FINDINGS_INDEX_DEFAULT_NS =
'logs-cloud_security_posture.findings_latest-default';

export const LATEST_FINDINGS_RETENTION_POLICY = '26h';

export const BENCHMARK_SCORE_INDEX_TEMPLATE_NAME = 'logs-cloud_security_posture.scores';
export const BENCHMARK_SCORE_INDEX_PATTERN = 'logs-cloud_security_posture.scores-*';
export const BENCHMARK_SCORE_INDEX_DEFAULT_NS = 'logs-cloud_security_posture.scores-default';
Expand Down Expand Up @@ -127,8 +115,6 @@ export const CIS_GCP = 'cis_gcp';
export const CIS_K8S = 'cis_k8s';
export const CIS_EKS = 'cis_eks';
export const CIS_AZURE = 'cis_azure';
export const KSPM_POLICY_TEMPLATE = 'kspm';
export const CSPM_POLICY_TEMPLATE = 'cspm';
export const VULN_MGMT_POLICY_TEMPLATE = 'vuln_mgmt';
export const CNVM_POLICY_TEMPLATE = 'cnvm';
export const SUPPORTED_POLICY_TEMPLATES = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { CSPM_POLICY_TEMPLATE, KSPM_POLICY_TEMPLATE } from '../constants';
import { CSPM_POLICY_TEMPLATE, KSPM_POLICY_TEMPLATE } from '@kbn/cloud-security-posture-common';

// this pages follows versioning interface strategy https://docs.elastic.dev/kibana-dev-docs/versioning-interfaces

Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/cloud_security_posture/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export * as benchmarkV2 from './benchmarks/v2';

// Explicit export of everything from latest
export type {
cspBenchmarkRuleMetadataSchema,
CspBenchmarkRuleMetadata,
CspBenchmarkRule,
FindCspBenchmarkRuleRequest,
FindCspBenchmarkRuleResponse,
Expand Down
Loading