diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index fcdfaf1fe4ef8b..7884277ae7d104 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -87,6 +87,8 @@ x-pack/plugins/cloud_integrations/cloud_full_story @elastic/kibana-core x-pack/test/cloud_integration/plugins/saml_provider @elastic/kibana-core x-pack/plugins/cloud_integrations/cloud_links @elastic/kibana-core x-pack/plugins/cloud @elastic/kibana-core +x-pack/packages/kbn-cloud-security-posture @elastic/kibana-cloud-security-posture +x-pack/packages/kbn-cloud-security-posture-common @elastic/kibana-cloud-security-posture x-pack/plugins/cloud_security_posture @elastic/kibana-cloud-security-posture packages/shared-ux/code_editor/impl @elastic/appex-sharedux packages/shared-ux/code_editor/mocks @elastic/appex-sharedux @@ -1426,6 +1428,7 @@ x-pack/plugins/cloud_integrations/cloud_full_story/server/config.ts @elastic/kib /x-pack/test/security_solution_cypress/cypress/screens/common @elastic/security-detections-response @elastic/security-threat-hunting /x-pack/test/security_solution_cypress/cypress/support @elastic/security-detections-response @elastic/security-threat-hunting /x-pack/test/security_solution_cypress/cypress/urls @elastic/security-threat-hunting-investigations @elastic/security-detection-engine +/x-pack/test/security_solution_cypress/cypress/e2e/cloud_security_posture @elastic/kibana-cloud-security-posture /x-pack/plugins/security_solution/common/ecs @elastic/security-threat-hunting-investigations /x-pack/plugins/security_solution/common/test @elastic/security-detections-response @elastic/security-threat-hunting diff --git a/package.json b/package.json index 90f91cf7d98e61..86cfa3b7e65815 100644 --- a/package.json +++ b/package.json @@ -210,6 +210,8 @@ "@kbn/cloud-integration-saml-provider-plugin": "link:x-pack/test/cloud_integration/plugins/saml_provider", "@kbn/cloud-links-plugin": "link:x-pack/plugins/cloud_integrations/cloud_links", "@kbn/cloud-plugin": "link:x-pack/plugins/cloud", + "@kbn/cloud-security-posture": "link:x-pack/packages/kbn-cloud-security-posture", + "@kbn/cloud-security-posture-common": "link:x-pack/packages/kbn-cloud-security-posture-common", "@kbn/cloud-security-posture-plugin": "link:x-pack/plugins/cloud_security_posture", "@kbn/code-editor": "link:packages/shared-ux/code_editor/impl", "@kbn/code-editor-mock": "link:packages/shared-ux/code_editor/mocks", diff --git a/tsconfig.base.json b/tsconfig.base.json index 4fb1008c3b79bb..9eb83d2ea315bf 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -168,6 +168,10 @@ "@kbn/cloud-links-plugin/*": ["x-pack/plugins/cloud_integrations/cloud_links/*"], "@kbn/cloud-plugin": ["x-pack/plugins/cloud"], "@kbn/cloud-plugin/*": ["x-pack/plugins/cloud/*"], + "@kbn/cloud-security-posture": ["x-pack/packages/kbn-cloud-security-posture"], + "@kbn/cloud-security-posture/*": ["x-pack/packages/kbn-cloud-security-posture/*"], + "@kbn/cloud-security-posture-common": ["x-pack/packages/kbn-cloud-security-posture-common"], + "@kbn/cloud-security-posture-common/*": ["x-pack/packages/kbn-cloud-security-posture-common/*"], "@kbn/cloud-security-posture-plugin": ["x-pack/plugins/cloud_security_posture"], "@kbn/cloud-security-posture-plugin/*": ["x-pack/plugins/cloud_security_posture/*"], "@kbn/code-editor": ["packages/shared-ux/code_editor/impl"], diff --git a/x-pack/.i18nrc.json b/x-pack/.i18nrc.json index 7ff0f3e3ef7667..97a7a92c93b5af 100644 --- a/x-pack/.i18nrc.json +++ b/x-pack/.i18nrc.json @@ -22,7 +22,11 @@ "xpack.cloudDefend": "plugins/cloud_defend", "xpack.cloudLinks": "plugins/cloud_integrations/cloud_links", "xpack.cloudDataMigration": "plugins/cloud_integrations/cloud_data_migration", - "xpack.csp": "plugins/cloud_security_posture", + "xpack.csp": [ + "plugins/cloud_security_posture", + "packages/kbn-cloud-security-posture-common", + "packages/kbn-cloud-security-posture" + ], "xpack.customBranding": "plugins/custom_branding", "xpack.dashboard": "plugins/dashboard_enhanced", "xpack.dataQuality": "plugins/data_quality", diff --git a/x-pack/packages/kbn-cloud-security-posture-common/README.md b/x-pack/packages/kbn-cloud-security-posture-common/README.md new file mode 100644 index 00000000000000..2fc159d9c4cac5 --- /dev/null +++ b/x-pack/packages/kbn-cloud-security-posture-common/README.md @@ -0,0 +1,9 @@ +# @kbn/cloud-security-posture-common + +This package provides common code consumed in both the browser, i.e. the +`packages/cloud-security-posture` package and `plugins/cloud_security_posture` plugin, and on the server, i.e. the +`plugins/cloud_security_posture` plugin. + +## Maintainers + +Maintained by the Cloud Security Posture Team \ No newline at end of file diff --git a/x-pack/packages/kbn-cloud-security-posture-common/constants.ts b/x-pack/packages/kbn-cloud-security-posture-common/constants.ts new file mode 100644 index 00000000000000..935e747b20fa82 --- /dev/null +++ b/x-pack/packages/kbn-cloud-security-posture-common/constants.ts @@ -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'; diff --git a/x-pack/packages/kbn-cloud-security-posture-common/index.ts b/x-pack/packages/kbn-cloud-security-posture-common/index.ts new file mode 100644 index 00000000000000..9aa5a782af8494 --- /dev/null +++ b/x-pack/packages/kbn-cloud-security-posture-common/index.ts @@ -0,0 +1,13 @@ +/* + * 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 './types'; +export * from './constants'; +export * from './schema/csp_finding'; +export type { CspBenchmarkRulesStates } from './types/latest'; +export { showErrorToast } from './utils/show_error_toast'; +export { buildMutedRulesFilter } from './utils/helpers'; diff --git a/x-pack/packages/kbn-cloud-security-posture-common/kibana.jsonc b/x-pack/packages/kbn-cloud-security-posture-common/kibana.jsonc new file mode 100644 index 00000000000000..21721cfb69f448 --- /dev/null +++ b/x-pack/packages/kbn-cloud-security-posture-common/kibana.jsonc @@ -0,0 +1,6 @@ + +{ + "id": "@kbn/cloud-security-posture-common", + "owner": "@elastic/kibana-cloud-security-posture", + "type": "shared-common" + } \ No newline at end of file diff --git a/x-pack/packages/kbn-cloud-security-posture-common/package.json b/x-pack/packages/kbn-cloud-security-posture-common/package.json new file mode 100644 index 00000000000000..9010e267fe5d05 --- /dev/null +++ b/x-pack/packages/kbn-cloud-security-posture-common/package.json @@ -0,0 +1,7 @@ +{ + "name": "@kbn/cloud-security-posture-common", + "private": true, + "version": "1.0.0", + "license": "Elastic License 2.0", + "description": "Shared components for cloud security posture, both client and server side" + } \ No newline at end of file diff --git a/x-pack/plugins/cloud_security_posture/common/schemas/csp_finding.ts b/x-pack/packages/kbn-cloud-security-posture-common/schema/csp_finding.ts similarity index 61% rename from x-pack/plugins/cloud_security_posture/common/schemas/csp_finding.ts rename to x-pack/packages/kbn-cloud-security-posture-common/schema/csp_finding.ts index 7ac4e79393f016..a2d5e6d6256564 100644 --- a/x-pack/plugins/cloud_security_posture/common/schemas/csp_finding.ts +++ b/x-pack/packages/kbn-cloud-security-posture-common/schema/csp_finding.ts @@ -4,10 +4,37 @@ * 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 { TypeOf, schema } from '@kbn/config-schema'; +import { CSPM_POLICY_TEMPLATE, KSPM_POLICY_TEMPLATE } from '../constants'; + +export type CspBenchmarkRuleMetadata = TypeOf; + +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 interface CspFinding { '@timestamp': string; diff --git a/x-pack/packages/kbn-cloud-security-posture-common/tsconfig.json b/x-pack/packages/kbn-cloud-security-posture-common/tsconfig.json new file mode 100644 index 00000000000000..64faae7a2ff717 --- /dev/null +++ b/x-pack/packages/kbn-cloud-security-posture-common/tsconfig.json @@ -0,0 +1,23 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "target/types", + "types": [ + "jest", + "node", + ] + }, + "include": [ + "**/*.ts", + "**/*.tsx", + ], + "exclude": [ + "target/**/*" + ], + "kbn_references": [ + "@kbn/config-schema", + "@kbn/data-views-plugin", + "@kbn/core", + "@kbn/i18n", + ] +} diff --git a/x-pack/packages/kbn-cloud-security-posture-common/types.ts b/x-pack/packages/kbn-cloud-security-posture-common/types.ts new file mode 100644 index 00000000000000..1a48a7bb41f2a4 --- /dev/null +++ b/x-pack/packages/kbn-cloud-security-posture-common/types.ts @@ -0,0 +1,43 @@ +/* + * 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; +} + +export type CspSetupStatus = BaseCspSetupStatus; diff --git a/x-pack/packages/kbn-cloud-security-posture-common/types/latest.ts b/x-pack/packages/kbn-cloud-security-posture-common/types/latest.ts new file mode 100644 index 00000000000000..63f93ed47734bb --- /dev/null +++ b/x-pack/packages/kbn-cloud-security-posture-common/types/latest.ts @@ -0,0 +1,18 @@ +/* + * 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 { schema, TypeOf } from '@kbn/config-schema'; + +export type CspBenchmarkRulesStates = TypeOf; +const ruleStateAttributes = schema.object({ + muted: schema.boolean(), + benchmark_id: schema.string(), + benchmark_version: schema.string(), + rule_number: schema.string(), + rule_id: schema.string(), +}); + +const rulesStates = schema.recordOf(schema.string(), ruleStateAttributes); diff --git a/x-pack/packages/kbn-cloud-security-posture-common/utils/helpers.ts b/x-pack/packages/kbn-cloud-security-posture-common/utils/helpers.ts new file mode 100644 index 00000000000000..be97ef8947b8f0 --- /dev/null +++ b/x-pack/packages/kbn-cloud-security-posture-common/utils/helpers.ts @@ -0,0 +1,41 @@ +/* + * 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 { QueryDslQueryContainer } from '@kbn/data-views-plugin/common/types'; +import { i18n } from '@kbn/i18n'; +import { CspBenchmarkRulesStates } from '../types/latest'; + +export const extractErrorMessage = (e: unknown, defaultMessage = 'Unknown Error'): string => { + if (e instanceof Error) return e.message; + if (typeof e === 'string') return e; + + return i18n.translate('xpack.csp.findings.errorMessage.default', { + defaultMessage, + }); +}; + +export const buildMutedRulesFilter = ( + rulesStates: CspBenchmarkRulesStates +): QueryDslQueryContainer[] => { + const mutedRules = Object.fromEntries( + Object.entries(rulesStates).filter(([key, value]) => value.muted === true) + ); + + const mutedRulesFilterQuery = Object.keys(mutedRules).map((key) => { + const rule = mutedRules[key]; + return { + bool: { + must: [ + { term: { 'rule.benchmark.id': rule.benchmark_id } }, + { term: { 'rule.benchmark.version': rule.benchmark_version } }, + { term: { 'rule.benchmark.rule_number': rule.rule_number } }, + ], + }, + }; + }); + + return mutedRulesFilterQuery; +}; diff --git a/x-pack/plugins/cloud_security_posture/public/common/utils/show_error_toast.ts b/x-pack/packages/kbn-cloud-security-posture-common/utils/show_error_toast.ts similarity index 91% rename from x-pack/plugins/cloud_security_posture/public/common/utils/show_error_toast.ts rename to x-pack/packages/kbn-cloud-security-posture-common/utils/show_error_toast.ts index 75316d9495b269..90a154774c0c86 100644 --- a/x-pack/plugins/cloud_security_posture/public/common/utils/show_error_toast.ts +++ b/x-pack/packages/kbn-cloud-security-posture-common/utils/show_error_toast.ts @@ -6,7 +6,7 @@ */ import type { CoreStart } from '@kbn/core/public'; import { i18n } from '@kbn/i18n'; -import { extractErrorMessage } from '../../../common/utils/helpers'; +import { extractErrorMessage } from './helpers'; const SEARCH_FAILED_TEXT = i18n.translate( 'xpack.csp.findings.findingsErrorToast.searchFailedTitle', diff --git a/x-pack/packages/kbn-cloud-security-posture/README.md b/x-pack/packages/kbn-cloud-security-posture/README.md new file mode 100644 index 00000000000000..38a875dda54abf --- /dev/null +++ b/x-pack/packages/kbn-cloud-security-posture/README.md @@ -0,0 +1,9 @@ +# @kbn/cloud-security-posture + +This package includes +- Hooks that's used on Flyout component that's used in Alerts page on Security Solution Plugins as well as components on CSP plugin +- Utilities and types thats used for the Hooks above as well as in CSP plugins + +## Maintainers + +Maintained by the Cloud Security Posture Team \ No newline at end of file diff --git a/x-pack/packages/kbn-cloud-security-posture/index.ts b/x-pack/packages/kbn-cloud-security-posture/index.ts new file mode 100644 index 00000000000000..e038f3f7c3d261 --- /dev/null +++ b/x-pack/packages/kbn-cloud-security-posture/index.ts @@ -0,0 +1,16 @@ +/* + * 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'; +export { useMisconfigurationPreview } from './src/hooks/use_misconfiguration_preview'; +export { useGetCspBenchmarkRulesStatesApi } from './src/hooks/use_get_benchmark_rules_state_api'; +export { useCspSetupStatusApi } from './src/hooks/use_csp_setup_status_api'; +export { + getAggregationCount, + getFindingsCountAggQuery, + isIndexWithDocsAvailable, +} from './src/utils/utils'; diff --git a/x-pack/packages/kbn-cloud-security-posture/kibana.jsonc b/x-pack/packages/kbn-cloud-security-posture/kibana.jsonc new file mode 100644 index 00000000000000..4c5a4f1f0165df --- /dev/null +++ b/x-pack/packages/kbn-cloud-security-posture/kibana.jsonc @@ -0,0 +1,5 @@ +{ + "id": "@kbn/cloud-security-posture", + "owner": "@elastic/kibana-cloud-security-posture", + "type": "shared-browser" +} \ No newline at end of file diff --git a/x-pack/packages/kbn-cloud-security-posture/package.json b/x-pack/packages/kbn-cloud-security-posture/package.json new file mode 100644 index 00000000000000..b0b48d2fb9a177 --- /dev/null +++ b/x-pack/packages/kbn-cloud-security-posture/package.json @@ -0,0 +1,7 @@ +{ + "name": "@kbn/cloud-security-posture", + "private": true, + "version": "1.0.0", + "license": "Elastic License 2.0", + "description": "Shared components for cloud security posture, client side" + } \ No newline at end of file diff --git a/x-pack/plugins/cloud_security_posture/public/common/api/use_setup_status_api.ts b/x-pack/packages/kbn-cloud-security-posture/src/hooks/use_csp_setup_status_api.ts similarity index 62% rename from x-pack/plugins/cloud_security_posture/public/common/api/use_setup_status_api.ts rename to x-pack/packages/kbn-cloud-security-posture/src/hooks/use_csp_setup_status_api.ts index 35f49282a475e0..1da7f9e9050650 100644 --- a/x-pack/plugins/cloud_security_posture/public/common/api/use_setup_status_api.ts +++ b/x-pack/packages/kbn-cloud-security-posture/src/hooks/use_csp_setup_status_api.ts @@ -6,16 +6,18 @@ */ import { useQuery, type UseQueryOptions } from '@tanstack/react-query'; -import { useKibana } from '../hooks/use_kibana'; -import { type CspSetupStatus } from '../../../common/types_old'; -import { STATUS_API_CURRENT_VERSION, STATUS_ROUTE_PATH } from '../../../common/constants'; +import { useKibana } from '@kbn/kibana-react-plugin/public'; +import type { CoreStart } from '@kbn/core/public'; +import { STATUS_API_CURRENT_VERSION, STATUS_ROUTE_PATH } from '@kbn/cloud-security-posture-common'; +import type { CspSetupStatus } from '@kbn/cloud-security-posture-common'; +import type { CspClientPluginStartDeps } from '../../type'; const getCspSetupStatusQueryKey = 'csp_status_key'; export const useCspSetupStatusApi = ( options?: UseQueryOptions ) => { - const { http } = useKibana().services; + const { http } = useKibana().services; return useQuery( [getCspSetupStatusQueryKey], () => http.get(STATUS_ROUTE_PATH, { version: STATUS_API_CURRENT_VERSION }), diff --git a/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/use_get_benchmark_rules_state_api.ts b/x-pack/packages/kbn-cloud-security-posture/src/hooks/use_get_benchmark_rules_state_api.ts similarity index 70% rename from x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/use_get_benchmark_rules_state_api.ts rename to x-pack/packages/kbn-cloud-security-posture/src/hooks/use_get_benchmark_rules_state_api.ts index ceada5c3148ebc..cbc6b8408f3f15 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/use_get_benchmark_rules_state_api.ts +++ b/x-pack/packages/kbn-cloud-security-posture/src/hooks/use_get_benchmark_rules_state_api.ts @@ -6,17 +6,19 @@ */ import { useQuery } from '@tanstack/react-query'; -import { CspBenchmarkRulesStates } from '../../../../common/types/latest'; import { CSP_GET_BENCHMARK_RULES_STATE_API_CURRENT_VERSION, CSP_GET_BENCHMARK_RULES_STATE_ROUTE_PATH, -} from '../../../../common/constants'; -import { useKibana } from '../../../common/hooks/use_kibana'; + CspBenchmarkRulesStates, +} from '@kbn/cloud-security-posture-common'; +import { useKibana } from '@kbn/kibana-react-plugin/public'; +import type { CoreStart } from '@kbn/core/public'; +import type { CspClientPluginStartDeps } from '../../type'; export const getRuleStatesKey = ['get_rules_state_key']; export const useGetCspBenchmarkRulesStatesApi = () => { - const { http } = useKibana().services; + const { http } = useKibana().services; return useQuery(getRuleStatesKey, () => http.get(CSP_GET_BENCHMARK_RULES_STATE_ROUTE_PATH, { version: CSP_GET_BENCHMARK_RULES_STATE_API_CURRENT_VERSION, diff --git a/x-pack/packages/kbn-cloud-security-posture/src/hooks/use_misconfiguration_preview.ts b/x-pack/packages/kbn-cloud-security-posture/src/hooks/use_misconfiguration_preview.ts new file mode 100644 index 00000000000000..3a3b3e83d300e6 --- /dev/null +++ b/x-pack/packages/kbn-cloud-security-posture/src/hooks/use_misconfiguration_preview.ts @@ -0,0 +1,112 @@ +/* + * 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 { useQuery } from '@tanstack/react-query'; +import { lastValueFrom } from 'rxjs'; +import type { IKibanaSearchResponse, IKibanaSearchRequest } from '@kbn/search-types'; +import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import { + CDR_MISCONFIGURATIONS_INDEX_PATTERN, + LATEST_FINDINGS_RETENTION_POLICY, + MAX_FINDINGS_TO_LOAD, + CspBenchmarkRulesStates, + CspFinding, +} from '@kbn/cloud-security-posture-common'; +import { showErrorToast, buildMutedRulesFilter } from '@kbn/cloud-security-posture-common'; +import { useKibana } from '@kbn/kibana-react-plugin/public'; +import type { CoreStart } from '@kbn/core/public'; +import type { CspClientPluginStartDeps } from '../../type'; +import type { FindingsBaseEsQuery } from '../../type'; +import { + getFindingsCountAggQueryMisconfigurationPreview, + getMisconfigurationAggregationCount, +} from '../utils/utils'; +import { useGetCspBenchmarkRulesStatesApi } from './use_get_benchmark_rules_state_api'; + +interface UseFindingsOptions extends FindingsBaseEsQuery { + sort: string[][]; + enabled: boolean; + pageSize: number; +} + +type LatestFindingsRequest = IKibanaSearchRequest; +type LatestFindingsResponse = IKibanaSearchResponse< + estypes.SearchResponse +>; + +interface FindingsAggs { + count: estypes.AggregationsMultiBucketAggregateBase; +} + +export const getFindingsQuery = ( + { query, sort }: UseFindingsOptions, + rulesStates: CspBenchmarkRulesStates, + pageParam: any +) => { + const mutedRulesFilterQuery = buildMutedRulesFilter(rulesStates); + + return { + index: CDR_MISCONFIGURATIONS_INDEX_PATTERN, + size: MAX_FINDINGS_TO_LOAD, + aggs: getFindingsCountAggQueryMisconfigurationPreview(), + ignore_unavailable: false, + query: { + ...query, + bool: { + ...query?.bool, + filter: [ + ...(query?.bool?.filter ?? []), + { + range: { + '@timestamp': { + gte: `now-${LATEST_FINDINGS_RETENTION_POLICY}`, + lte: 'now', + }, + }, + }, + ], + must_not: [...(query?.bool?.must_not ?? []), ...mutedRulesFilterQuery], + }, + }, + ...(pageParam ? { from: pageParam } : {}), + }; +}; + +export const useMisconfigurationPreview = (options: UseFindingsOptions) => { + const { + data, + notifications: { toasts }, + } = useKibana().services; + const { data: rulesStates } = useGetCspBenchmarkRulesStatesApi(); + + return useQuery( + ['csp_findings', { params: options }, rulesStates], + async ({ pageParam }) => { + const { + rawResponse: { aggregations }, + } = await lastValueFrom( + data.search.search({ + params: getFindingsQuery(options, rulesStates!, pageParam), + }) + ); + if (!aggregations) throw new Error('expected aggregations to be defined'); + + return { + count: getMisconfigurationAggregationCount( + Object.entries(aggregations.count.buckets).map(([key, value]) => ({ + key, + doc_count: value.doc_count || 0, + })) + ), + }; + }, + { + enabled: options.enabled && !!rulesStates, + keepPreviousData: true, + onError: (err: Error) => showErrorToast(toasts, err), + } + ); +}; diff --git a/x-pack/packages/kbn-cloud-security-posture/src/utils/utils.ts b/x-pack/packages/kbn-cloud-security-posture/src/utils/utils.ts new file mode 100644 index 00000000000000..528209d9bd9618 --- /dev/null +++ b/x-pack/packages/kbn-cloud-security-posture/src/utils/utils.ts @@ -0,0 +1,54 @@ +/* + * 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 { estypes } from '@elastic/elasticsearch'; +import { IndexDetails } from '@kbn/cloud-security-posture-common'; + +export const getFindingsCountAggQuery = () => ({ + count: { terms: { field: 'result.evaluation' } }, +}); + +export const getFindingsCountAggQueryMisconfigurationPreview = () => ({ + count: { + filters: { + other_bucket_key: 'other_messages', + filters: { + passed: { match: { 'result.evaluation': 'passed' } }, + failed: { match: { 'result.evaluation': 'failed' } }, + }, + }, + }, +}); + +export const getAggregationCount = ( + buckets: Array +) => { + const passed = buckets.find((bucket) => bucket?.key === 'passed'); + const failed = buckets.find((bucket) => bucket?.key === 'failed'); + + return { + passed: passed?.doc_count || 0, + failed: failed?.doc_count || 0, + }; +}; + +export const getMisconfigurationAggregationCount = ( + buckets: Array +) => { + const passed = buckets.find((bucket) => bucket?.key === 'passed'); + const failed = buckets.find((bucket) => bucket?.key === 'failed'); + const noStatus = buckets.find((bucket) => bucket?.key === 'other_messages'); + + return { + passed: passed?.doc_count || 0, + failed: failed?.doc_count || 0, + no_status: noStatus?.doc_count || 0, + }; +}; + +export const isIndexWithDocsAvailable = (indices: Array) => { + return indices.some((indice) => indice?.status !== 'empty'); +}; diff --git a/x-pack/packages/kbn-cloud-security-posture/tsconfig.json b/x-pack/packages/kbn-cloud-security-posture/tsconfig.json new file mode 100644 index 00000000000000..5d1aaa8774d15e --- /dev/null +++ b/x-pack/packages/kbn-cloud-security-posture/tsconfig.json @@ -0,0 +1,38 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "target/types", + "types": [ + "jest", + "node", + "react" + ] + }, + "include": [ + "**/*.ts", + "**/*.tsx", + ], + "exclude": [ + "target/**/*" + ], + "kbn_references": [ + "@kbn/kibana-react-plugin", + "@kbn/core", + "@kbn/cloud-security-posture-common", + "@kbn/search-types", + "@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", + ] +} diff --git a/x-pack/packages/kbn-cloud-security-posture/type.ts b/x-pack/packages/kbn-cloud-security-posture/type.ts new file mode 100644 index 00000000000000..5a5f507effe96b --- /dev/null +++ b/x-pack/packages/kbn-cloud-security-posture/type.ts @@ -0,0 +1,47 @@ +/* + * 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 { 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 type { BoolQuery } from '@kbn/es-query'; +export interface FindingsBaseEsQuery { + query?: { + bool: BoolQuery; + }; +} + +export interface CspClientPluginStartDeps { + 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; + + usageCollection?: UsageCollectionStart; +} diff --git a/x-pack/plugins/cloud_security_posture/common/constants.ts b/x-pack/plugins/cloud_security_posture/common/constants.ts index 720251dee5a77a..a61918e8b55869 100644 --- a/x-pack/plugins/cloud_security_posture/common/constants.ts +++ b/x-pack/plugins/cloud_security_posture/common/constants.ts @@ -65,8 +65,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'; diff --git a/x-pack/plugins/cloud_security_posture/common/types/rules/v4.ts b/x-pack/plugins/cloud_security_posture/common/types/rules/v4.ts index 33134eed32e38e..c44534ef9bd061 100644 --- a/x-pack/plugins/cloud_security_posture/common/types/rules/v4.ts +++ b/x-pack/plugins/cloud_security_posture/common/types/rules/v4.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common'; import { schema, TypeOf } from '@kbn/config-schema'; import { BenchmarksCisId } from '../latest'; import { DEFAULT_BENCHMARK_RULES_PER_PAGE } from './v3'; @@ -26,8 +27,6 @@ export type CspBenchmarkRulesBulkActionRequestSchema = TypeOf< export type RuleStateAttributes = TypeOf; -export type CspBenchmarkRulesStates = TypeOf; - export type CspSettings = TypeOf; export const findCspBenchmarkRuleRequestSchema = schema.object({ diff --git a/x-pack/plugins/cloud_security_posture/common/types/rules/v5.ts b/x-pack/plugins/cloud_security_posture/common/types/rules/v5.ts index 6f30ed446531aa..461afbcc397b81 100644 --- a/x-pack/plugins/cloud_security_posture/common/types/rules/v5.ts +++ b/x-pack/plugins/cloud_security_posture/common/types/rules/v5.ts @@ -20,12 +20,11 @@ export type { CspBenchmarkRulesBulkActionRequestSchema, CspBenchmarkRulesBulkActionResponse, RuleStateAttributes, - CspBenchmarkRulesStates, cspSettingsSchema, CspSettings, BulkActionBenchmarkRulesResponse, } from './v4'; - +export type { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common'; export type FindCspBenchmarkRuleRequest = TypeOf; export const findCspBenchmarkRuleRequestSchema = schema.object({ diff --git a/x-pack/plugins/cloud_security_posture/common/types_old.ts b/x-pack/plugins/cloud_security_posture/common/types_old.ts index f77ac4678a526a..526b6536ba94da 100644 --- a/x-pack/plugins/cloud_security_posture/common/types_old.ts +++ b/x-pack/plugins/cloud_security_posture/common/types_old.ts @@ -5,12 +5,21 @@ * 2.0. */ import { type TypeOf } from '@kbn/config-schema'; -import { CspFinding } from './schemas/csp_finding'; +import { CspFinding } from '@kbn/cloud-security-posture-common'; import { SUPPORTED_CLOUDBEAT_INPUTS, SUPPORTED_POLICY_TEMPLATES } from './constants'; import { getComplianceDashboardSchema } from './schemas/stats'; import type { CspBenchmarkRuleMetadata } from './types/latest'; +export type { + CspFinding, + IndexStatus, + IndexDetails, + BaseCspSetupBothPolicy, + BaseCspSetupStatus, + CspSetupStatus, +} from '@kbn/cloud-security-posture-common'; + export type AwsCredentialsType = | 'assume_role' | 'direct_access_keys' @@ -100,43 +109,6 @@ export interface ComplianceDashboardDataV2 { benchmarks: BenchmarkData[]; } -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; -} - -export type CspSetupStatus = BaseCspSetupStatus; - export type BenchmarkId = CspBenchmarkRuleMetadata['benchmark']['id']; export type BenchmarkName = CspBenchmarkRuleMetadata['benchmark']['name']; export type RuleSection = CspBenchmarkRuleMetadata['section']; @@ -230,3 +202,12 @@ export interface AggFieldBucket { doc_count?: string; }>; } + +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 diff --git a/x-pack/plugins/cloud_security_posture/common/utils/rules_states.ts b/x-pack/plugins/cloud_security_posture/common/utils/rules_states.ts index a343c91af91f92..e2351d3ddcaa97 100644 --- a/x-pack/plugins/cloud_security_posture/common/utils/rules_states.ts +++ b/x-pack/plugins/cloud_security_posture/common/utils/rules_states.ts @@ -4,31 +4,6 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { QueryDslQueryContainer } from '@kbn/data-views-plugin/common/types'; -import { CspBenchmarkRulesStates } from '../types/latest'; - -export const buildMutedRulesFilter = ( - rulesStates: CspBenchmarkRulesStates -): QueryDslQueryContainer[] => { - const mutedRules = Object.fromEntries( - Object.entries(rulesStates).filter(([key, value]) => value.muted === true) - ); - - const mutedRulesFilterQuery = Object.keys(mutedRules).map((key) => { - const rule = mutedRules[key]; - return { - bool: { - must: [ - { term: { 'rule.benchmark.id': rule.benchmark_id } }, - { term: { 'rule.benchmark.version': rule.benchmark_version } }, - { term: { 'rule.benchmark.rule_number': rule.rule_number } }, - ], - }, - }; - }); - - return mutedRulesFilterQuery; -}; export const buildRuleKey = (benchmarkId: string, benchmarkVersion: string, ruleNumber: string) => { return `${benchmarkId};${benchmarkVersion};${ruleNumber}`; diff --git a/x-pack/plugins/cloud_security_posture/public/common/api/use_stats_api.ts b/x-pack/plugins/cloud_security_posture/public/common/api/use_stats_api.ts index e973633210d9c5..a22ad450896b4c 100644 --- a/x-pack/plugins/cloud_security_posture/public/common/api/use_stats_api.ts +++ b/x-pack/plugins/cloud_security_posture/public/common/api/use_stats_api.ts @@ -6,13 +6,13 @@ */ import { useQuery, UseQueryOptions } from '@tanstack/react-query'; -import { useKibana } from '../hooks/use_kibana'; import { ComplianceDashboardDataV2, PosturePolicyTemplate } from '../../../common/types_old'; import { CSPM_POLICY_TEMPLATE, KSPM_POLICY_TEMPLATE, STATS_ROUTE_PATH, } from '../../../common/constants'; +import { useKibana } from '../hooks/use_kibana'; // TODO: consolidate both hooks into one hook with a dynamic key export const CSPM_STATS_QUERY_KEY = ['csp_cspm_dashboard_stats']; diff --git a/x-pack/plugins/cloud_security_posture/public/common/api/use_vulnerability_dashboard_api.ts b/x-pack/plugins/cloud_security_posture/public/common/api/use_vulnerability_dashboard_api.ts index 4114a49cdf1818..0c8dfda27f84fe 100644 --- a/x-pack/plugins/cloud_security_posture/public/common/api/use_vulnerability_dashboard_api.ts +++ b/x-pack/plugins/cloud_security_posture/public/common/api/use_vulnerability_dashboard_api.ts @@ -7,8 +7,8 @@ import { useQuery, UseQueryOptions } from '@tanstack/react-query'; import { CnvmDashboardData } from '../../../common/types_old'; -import { useKibana } from '../hooks/use_kibana'; import { VULNERABILITIES_DASHBOARD_ROUTE_PATH } from '../../../common/constants'; +import { useKibana } from '../hooks/use_kibana'; const cnvmKey = 'use-vulnerability-dashboard-api-key'; diff --git a/x-pack/plugins/cloud_security_posture/public/common/constants.ts b/x-pack/plugins/cloud_security_posture/public/common/constants.ts index 8054917ba7462a..234e5e16ae3c54 100644 --- a/x-pack/plugins/cloud_security_posture/public/common/constants.ts +++ b/x-pack/plugins/cloud_security_posture/public/common/constants.ts @@ -35,7 +35,6 @@ export const statusColors = { }; export const CSP_MOMENT_FORMAT = 'MMMM D, YYYY @ HH:mm:ss.SSS'; -export const MAX_FINDINGS_TO_LOAD = 500; export const DEFAULT_VISIBLE_ROWS_PER_PAGE = 25; export const LOCAL_STORAGE_DATA_TABLE_PAGE_SIZE_KEY = 'cloudPosture:dataTable:pageSize'; diff --git a/x-pack/plugins/cloud_security_posture/public/common/navigation/use_navigate_to_cis_integration_policies.ts b/x-pack/plugins/cloud_security_posture/public/common/navigation/use_navigate_to_cis_integration_policies.ts index 85e4796743cf36..3949eda397b0d0 100644 --- a/x-pack/plugins/cloud_security_posture/public/common/navigation/use_navigate_to_cis_integration_policies.ts +++ b/x-pack/plugins/cloud_security_posture/public/common/navigation/use_navigate_to_cis_integration_policies.ts @@ -7,9 +7,9 @@ import { pagePathGetters, pkgKeyFromPackageInfo } from '@kbn/fleet-plugin/public'; import { useCisKubernetesIntegration } from '../api/use_cis_kubernetes_integration'; -import { useKibana } from '../hooks/use_kibana'; import { useCspBenchmarkIntegrationsV1 } from '../../pages/benchmarks/use_csp_benchmark_integrations'; import { PostureTypes } from '../../../common/types_old'; +import { useKibana } from '../hooks/use_kibana'; export const useCISIntegrationPoliciesLink = ({ postureType, diff --git a/x-pack/plugins/cloud_security_posture/public/common/types.ts b/x-pack/plugins/cloud_security_posture/public/common/types.ts index d0d491c256e0e1..6a82d3073fe3b0 100644 --- a/x-pack/plugins/cloud_security_posture/public/common/types.ts +++ b/x-pack/plugins/cloud_security_posture/public/common/types.ts @@ -5,7 +5,9 @@ * 2.0. */ import type { Criteria } from '@elastic/eui'; -import type { BoolQuery, Filter, Query, EsQueryConfig } from '@kbn/es-query'; +import type { Filter, Query, EsQueryConfig } from '@kbn/es-query'; + +export type FindingsGroupByKind = 'default' | 'resource'; export interface FindingsBaseURLQuery { query: Query; @@ -24,12 +26,6 @@ export interface FindingsBaseESQueryConfig { config: EsQueryConfig; } -export interface FindingsBaseEsQuery { - query?: { - bool: BoolQuery; - }; -} - export type Sort = NonNullable['sort']>; interface RuleSeverityMapping { diff --git a/x-pack/plugins/cloud_security_posture/public/common/utils/get_limit_properties.ts b/x-pack/plugins/cloud_security_posture/public/common/utils/get_limit_properties.ts new file mode 100644 index 00000000000000..12cce0034b4e53 --- /dev/null +++ b/x-pack/plugins/cloud_security_posture/public/common/utils/get_limit_properties.ts @@ -0,0 +1,38 @@ +/* + * 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 { useMemo } from 'react'; +import { MAX_FINDINGS_TO_LOAD } from '@kbn/cloud-security-posture-common'; + +export const getLimitProperties = ( + totalItems: number, + maxItems: number, + pageSize: number, + pageIndex: number +): { isLastLimitedPage: boolean; limitedTotalItemCount: number } => { + const limitItems = totalItems > maxItems; + const limitedTotalItemCount = limitItems ? maxItems : totalItems; + const lastLimitedPage = Math.ceil(limitedTotalItemCount / pageSize); + const isLastPage = lastLimitedPage === pageIndex + 1; + const isLastLimitedPage = limitItems && isLastPage; + + return { isLastLimitedPage, limitedTotalItemCount }; +}; + +export const useLimitProperties = ({ + total, + pageIndex, + pageSize, +}: { + total?: number; + pageSize: number; + pageIndex: number; +}) => + useMemo( + () => getLimitProperties(total || 0, MAX_FINDINGS_TO_LOAD, pageSize, pageIndex), + [total, pageIndex, pageSize] + ); diff --git a/x-pack/plugins/cloud_security_posture/public/components/cloud_posture_page.test.tsx b/x-pack/plugins/cloud_security_posture/public/components/cloud_posture_page.test.tsx index 05fedd4d8adec5..4c341dea206f14 100644 --- a/x-pack/plugins/cloud_security_posture/public/components/cloud_posture_page.test.tsx +++ b/x-pack/plugins/cloud_security_posture/public/components/cloud_posture_page.test.tsx @@ -27,7 +27,7 @@ import { useLicenseManagementLocatorApi } from '../common/api/use_license_manage const chance = new Chance(); -jest.mock('../common/api/use_setup_status_api'); +jest.mock('@kbn/cloud-security-posture'); // Mock use_setup_status_api jest.mock('../common/api/use_license_management_locator_api'); jest.mock('../common/hooks/use_subscription_status'); jest.mock('../common/navigation/use_csp_integration_link'); diff --git a/x-pack/plugins/cloud_security_posture/public/components/cloud_security_data_table/cloud_security_data_table.tsx b/x-pack/plugins/cloud_security_posture/public/components/cloud_security_data_table/cloud_security_data_table.tsx index 5c0cbd048f9d12..771702bceed94a 100644 --- a/x-pack/plugins/cloud_security_posture/public/components/cloud_security_data_table/cloud_security_data_table.tsx +++ b/x-pack/plugins/cloud_security_posture/public/components/cloud_security_data_table/cloud_security_data_table.tsx @@ -26,16 +26,16 @@ import { AddFieldFilterHandler } from '@kbn/unified-field-list'; import { generateFilters } from '@kbn/data-plugin/public'; import { DocViewFilterFn } from '@kbn/unified-doc-viewer/types'; import useLocalStorage from 'react-use/lib/useLocalStorage'; -import { useKibana } from '../../common/hooks/use_kibana'; +import { MAX_FINDINGS_TO_LOAD } from '@kbn/cloud-security-posture-common'; import { CloudPostureDataTableResult } from '../../common/hooks/use_cloud_posture_data_table'; import { EmptyState } from '../empty_state'; -import { MAX_FINDINGS_TO_LOAD } from '../../common/constants'; import { useStyles } from './use_styles'; import { AdditionalControls } from './additional_controls'; import { useDataViewContext } from '../../common/contexts/data_view_context'; import { TakeAction } from '../take_action'; import { RuleResponse } from '../../common/types'; +import { useKibana } from '../../common/hooks/use_kibana'; export interface CloudSecurityDefaultColumn { id: string; width?: number; diff --git a/x-pack/plugins/cloud_security_posture/public/components/detection_rule_counter.tsx b/x-pack/plugins/cloud_security_posture/public/components/detection_rule_counter.tsx index 5465c144b6772d..743e5fcb1069da 100644 --- a/x-pack/plugins/cloud_security_posture/public/components/detection_rule_counter.tsx +++ b/x-pack/plugins/cloud_security_posture/public/components/detection_rule_counter.tsx @@ -15,9 +15,9 @@ import { useQueryClient } from '@tanstack/react-query'; import { useFetchDetectionRulesAlertsStatus } from '../common/api/use_fetch_detection_rules_alerts_status'; import { useFetchDetectionRulesByTags } from '../common/api/use_fetch_detection_rules_by_tags'; import { RuleResponse } from '../common/types'; -import { useKibana } from '../common/hooks/use_kibana'; import { showCreateDetectionRuleSuccessToast } from './take_action'; import { DETECTION_ENGINE_ALERTS_KEY, DETECTION_ENGINE_RULES_KEY } from '../common/constants'; +import { useKibana } from '../common/hooks/use_kibana'; const RULES_PAGE_PATH = '/rules/management'; const ALERTS_PAGE_PATH = '/alerts'; diff --git a/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/custom_assets_extension.tsx b/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/custom_assets_extension.tsx index c7708cba837cc7..6d471788e5b857 100644 --- a/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/custom_assets_extension.tsx +++ b/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/custom_assets_extension.tsx @@ -12,8 +12,8 @@ import { useParams } from 'react-router-dom'; import { EuiSpacer } from '@elastic/eui'; import { CloudSecurityPolicyTemplate } from '../../../common/types_old'; import { VULN_MGMT_POLICY_TEMPLATE } from '../../../common/constants'; -import { useKibana } from '../../common/hooks/use_kibana'; import { benchmarksNavigation, cloudPosturePages } from '../../common/navigation/constants'; +import { useKibana } from '../../common/hooks/use_kibana'; const SECURITY_APP_NAME = 'securitySolutionUI'; diff --git a/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/policy_template_form.test.tsx b/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/policy_template_form.test.tsx index 116170b2ac29c9..d47a0740339e0d 100644 --- a/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/policy_template_form.test.tsx +++ b/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/policy_template_form.test.tsx @@ -39,7 +39,7 @@ import { } from '../../../common/constants'; import { useParams } from 'react-router-dom'; import { createReactQueryResponse } from '../../test/fixtures/react_query'; -import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api'; +import { useCspSetupStatusApi } from '@kbn/cloud-security-posture'; import { usePackagePolicyList } from '../../common/api/use_package_policy_list'; import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl'; import { @@ -64,7 +64,7 @@ jest.mock('react-router-dom', () => ({ integration: undefined, }), })); -jest.mock('../../common/api/use_setup_status_api'); +jest.mock('@kbn/cloud-security-posture'); // Mock use_setup_status_api jest.mock('../../common/api/use_package_policy_list'); jest.mock('@kbn/fleet-plugin/public/services/experimental_features'); diff --git a/x-pack/plugins/cloud_security_posture/public/components/no_findings_states/no_findings_states.tsx b/x-pack/plugins/cloud_security_posture/public/components/no_findings_states/no_findings_states.tsx index 97dfce7b84c1ec..9f2639c958001a 100644 --- a/x-pack/plugins/cloud_security_posture/public/components/no_findings_states/no_findings_states.tsx +++ b/x-pack/plugins/cloud_security_posture/public/components/no_findings_states/no_findings_states.tsx @@ -20,6 +20,7 @@ import { import { FormattedMessage } from '@kbn/i18n-react'; import { i18n } from '@kbn/i18n'; import { css } from '@emotion/react'; +import { useCspSetupStatusApi } from '@kbn/cloud-security-posture'; import { CSPM_POLICY_TEMPLATE, KSPM_POLICY_TEMPLATE } from '../../../common/constants'; import { FullSizeCenteredPage } from '../full_size_centered_page'; import { useCISIntegrationPoliciesLink } from '../../common/navigation/use_navigate_to_cis_integration_policies'; @@ -29,7 +30,6 @@ import { NO_FINDINGS_STATUS_TEST_SUBJ, } from '../test_subjects'; import { CloudPosturePage, PACKAGE_NOT_INSTALLED_TEST_SUBJECT } from '../cloud_posture_page'; -import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api'; import type { IndexDetails, PostureTypes, CspStatusCode } from '../../../common/types_old'; import noDataIllustration from '../../assets/illustrations/no_data_illustration.svg'; import { useCspIntegrationLink } from '../../common/navigation/use_csp_integration_link'; diff --git a/x-pack/plugins/cloud_security_posture/public/components/no_vulnerabilities_states.tsx b/x-pack/plugins/cloud_security_posture/public/components/no_vulnerabilities_states.tsx index a2b1aa1d0d8315..c5195c56702528 100644 --- a/x-pack/plugins/cloud_security_posture/public/components/no_vulnerabilities_states.tsx +++ b/x-pack/plugins/cloud_security_posture/public/components/no_vulnerabilities_states.tsx @@ -21,10 +21,10 @@ import { import { FormattedMessage } from '@kbn/i18n-react'; import { i18n } from '@kbn/i18n'; import { css } from '@emotion/react'; +import { useCspSetupStatusApi } from '@kbn/cloud-security-posture'; import { VULN_MGMT_POLICY_TEMPLATE } from '../../common/constants'; import { FullSizeCenteredPage } from './full_size_centered_page'; import { CloudPosturePage } from './cloud_posture_page'; -import { useCspSetupStatusApi } from '../common/api/use_setup_status_api'; import type { IndexDetails } from '../../common/types_old'; import { NO_VULNERABILITIES_STATUS_TEST_SUBJ, diff --git a/x-pack/plugins/cloud_security_posture/public/components/take_action.tsx b/x-pack/plugins/cloud_security_posture/public/components/take_action.tsx index 87d6d109b7db09..46a04b8e49858c 100644 --- a/x-pack/plugins/cloud_security_posture/public/components/take_action.tsx +++ b/x-pack/plugins/cloud_security_posture/public/components/take_action.tsx @@ -24,9 +24,9 @@ import { i18n as kbnI18n } from '@kbn/i18n'; import { QueryClient, useQueryClient } from '@tanstack/react-query'; import type { RuleResponse } from '../common/types'; import { CREATE_RULE_ACTION_SUBJ, TAKE_ACTION_SUBJ } from './test_subjects'; -import { useKibana } from '../common/hooks/use_kibana'; import { DETECTION_ENGINE_ALERTS_KEY, DETECTION_ENGINE_RULES_KEY } from '../common/constants'; import { CloudSecurityPostureStartServices } from '../types'; +import { useKibana } from '../common/hooks/use_kibana'; const RULE_PAGE_PATH = '/app/security/rules/id/'; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/benchmarks.test.tsx b/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/benchmarks.test.tsx index e5fed03fc96767..6b278ec01cdabf 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/benchmarks.test.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/benchmarks.test.tsx @@ -14,14 +14,14 @@ import { TestProvider } from '../../test/test_provider'; import { Benchmarks } from './benchmarks'; import * as TEST_SUBJ from './test_subjects'; import { useCspBenchmarkIntegrationsV2 } from './use_csp_benchmark_integrations'; -import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api'; +import { useCspSetupStatusApi } from '@kbn/cloud-security-posture'; import { useSubscriptionStatus } from '../../common/hooks/use_subscription_status'; import { useCspIntegrationLink } from '../../common/navigation/use_csp_integration_link'; import { ERROR_STATE_TEST_SUBJECT } from './benchmarks_table'; import { useLicenseManagementLocatorApi } from '../../common/api/use_license_management_locator_api'; jest.mock('./use_csp_benchmark_integrations'); -jest.mock('../../common/api/use_setup_status_api'); +jest.mock('@kbn/cloud-security-posture'); // Mock use_setup_status_api jest.mock('../../common/api/use_license_management_locator_api'); jest.mock('../../common/hooks/use_subscription_status'); jest.mock('../../common/navigation/use_csp_integration_link'); diff --git a/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/benchmarks.tsx b/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/benchmarks.tsx index 13b4750317810c..15ceca2c73d811 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/benchmarks.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/benchmarks.tsx @@ -21,6 +21,7 @@ import { FormattedMessage } from '@kbn/i18n-react'; import useDebounce from 'react-use/lib/useDebounce'; import { i18n } from '@kbn/i18n'; import { pagePathGetters } from '@kbn/fleet-plugin/public'; +import { useCspSetupStatusApi } from '@kbn/cloud-security-posture'; import { CLOUD_SECURITY_POSTURE_PACKAGE_NAME } from '../../../common/constants'; import { CloudPosturePageTitle } from '../../components/cloud_posture_page_title'; import { CloudPosturePage } from '../../components/cloud_posture_page'; @@ -36,9 +37,8 @@ import { NO_FINDINGS_STATUS_REFRESH_INTERVAL_MS, } from '../../common/constants'; import { usePageSize } from '../../common/hooks/use_page_size'; -import { useKibana } from '../../common/hooks/use_kibana'; -import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api'; import { NoFindingsStates } from '../../components/no_findings_states'; +import { useKibana } from '../../common/hooks/use_kibana'; const SEARCH_DEBOUNCE_MS = 300; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/use_csp_benchmark_integrations.ts b/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/use_csp_benchmark_integrations.ts index 3b21e7978e8390..a45745ea7d416b 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/use_csp_benchmark_integrations.ts +++ b/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/use_csp_benchmark_integrations.ts @@ -8,9 +8,9 @@ import { useQuery } from '@tanstack/react-query'; import { BENCHMARKS_ROUTE_PATH } from '../../../common/constants'; import type { BenchmarksQueryParams } from '../../../common/types/benchmarks/v1'; -import { useKibana } from '../../common/hooks/use_kibana'; import type { GetBenchmarkResponse } from '../../../common/types/latest'; import type { GetBenchmarkResponse as GetBenchmarkResponseV1 } from '../../../common/types/benchmarks/v1'; +import { useKibana } from '../../common/hooks/use_kibana'; const BENCHMARK_INTEGRATION_QUERY_KEY_V1 = 'csp_benchmark_integrations_v1'; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_dashboard.test.tsx b/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_dashboard.test.tsx index b3ed9cff8dc094..7795f67aed9a8f 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_dashboard.test.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_dashboard.test.tsx @@ -11,7 +11,7 @@ import { coreMock } from '@kbn/core/public/mocks'; import { render, screen } from '@testing-library/react'; import { TestProvider } from '../../test/test_provider'; import { ComplianceDashboard, getDefaultTab } from '.'; -import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api'; +import { useCspSetupStatusApi } from '@kbn/cloud-security-posture'; import { useLicenseManagementLocatorApi } from '../../common/api/use_license_management_locator_api'; import { useSubscriptionStatus } from '../../common/hooks/use_subscription_status'; import { useKspmStatsApi, useCspmStatsApi } from '../../common/api/use_stats_api'; @@ -40,7 +40,7 @@ import { import { cloudPosturePages } from '../../common/navigation/constants'; import { MemoryRouter } from 'react-router-dom'; -jest.mock('../../common/api/use_setup_status_api'); +jest.mock('@kbn/cloud-security-posture'); // Mock use_setup_status_api jest.mock('../../common/api/use_stats_api'); jest.mock('../../common/api/use_license_management_locator_api'); jest.mock('../../common/hooks/use_subscription_status'); diff --git a/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_dashboard.tsx b/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_dashboard.tsx index af341d5c04606f..11e3272245937a 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_dashboard.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_dashboard.tsx @@ -13,6 +13,7 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import { Route, Routes } from '@kbn/shared-ux-router'; import { Redirect, useHistory, useLocation } from 'react-router-dom'; +import { useCspSetupStatusApi } from '@kbn/cloud-security-posture'; import { NO_FINDINGS_STATUS_TEST_SUBJ } from '../../components/test_subjects'; import { useCspIntegrationLink } from '../../common/navigation/use_csp_integration_link'; import type { @@ -37,7 +38,6 @@ import { CLOUD_POSTURE_DASHBOARD_PAGE_HEADER, } from './test_subjects'; import { useCspmStatsApi, useKspmStatsApi } from '../../common/api/use_stats_api'; -import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api'; import { NoFindingsStates } from '../../components/no_findings_states'; import { SummarySection } from './dashboard_sections/summary_section'; import { BenchmarksSection } from './dashboard_sections/benchmarks_section'; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/configurations/__mocks__/findings.ts b/x-pack/plugins/cloud_security_posture/public/pages/configurations/__mocks__/findings.ts index 4b01603b4c03b0..296310f5c0d0bb 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/configurations/__mocks__/findings.ts +++ b/x-pack/plugins/cloud_security_posture/public/pages/configurations/__mocks__/findings.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { CspFinding } from '../../../../common/schemas/csp_finding'; +import { CspFinding } from '@kbn/cloud-security-posture-common'; export const mockFindingsHit: CspFinding = { result: { diff --git a/x-pack/plugins/cloud_security_posture/public/pages/configurations/configurations.handlers.mock.ts b/x-pack/plugins/cloud_security_posture/public/pages/configurations/configurations.handlers.mock.ts index e79f737b11a3ca..475763db96147b 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/configurations/configurations.handlers.mock.ts +++ b/x-pack/plugins/cloud_security_posture/public/pages/configurations/configurations.handlers.mock.ts @@ -6,7 +6,7 @@ */ import { estypes } from '@elastic/elasticsearch'; -import { CspFinding } from '../../../common/schemas/csp_finding'; +import { CspFinding } from '@kbn/cloud-security-posture-common'; import { isArray } from 'lodash'; import { http, HttpResponse } from 'msw'; import { v4 as uuidV4 } from 'uuid'; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/configurations/configurations.tsx b/x-pack/plugins/cloud_security_posture/public/pages/configurations/configurations.tsx index dc5cc9b4fd4a56..62c122694f193e 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/configurations/configurations.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/configurations/configurations.tsx @@ -8,8 +8,8 @@ import React from 'react'; import { Redirect, useLocation } from 'react-router-dom'; import { Routes, Route } from '@kbn/shared-ux-router'; import { TrackApplicationView } from '@kbn/usage-collection-plugin/public'; +import { useCspSetupStatusApi } from '@kbn/cloud-security-posture'; import { CDR_MISCONFIGURATIONS_DATA_VIEW_ID_PREFIX } from '../../../common/constants'; -import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api'; import { NoFindingsStates } from '../../components/no_findings_states'; import { CloudPosturePage, defaultLoadingRenderer } from '../../components/cloud_posture_page'; import { useDataView } from '../../common/api/use_data_view'; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/findings_detection_rule_counter.tsx b/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/findings_detection_rule_counter.tsx index 0ab35a37c8ee48..56a69154867b37 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/findings_detection_rule_counter.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/findings_detection_rule_counter.tsx @@ -7,7 +7,7 @@ import type { HttpSetup } from '@kbn/core/public'; import React from 'react'; -import { CspFinding } from '../../../../common/schemas/csp_finding'; +import { CspFinding } from '@kbn/cloud-security-posture-common'; import { DetectionRuleCounter } from '../../../components/detection_rule_counter'; import { getFindingsDetectionRuleSearchTags } from '../../../../common/utils/detection_rules'; import { createDetectionRuleFromBenchmarkRule } from '../utils/create_detection_rule_from_benchmark'; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/findings_flyout.tsx b/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/findings_flyout.tsx index 4d8c5b6569efdd..5ba0d9ce6d3922 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/findings_flyout.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/findings_flyout.tsx @@ -35,11 +35,11 @@ import type { HttpSetup } from '@kbn/core/public'; import { generatePath } from 'react-router-dom'; import { css } from '@emotion/react'; import { euiThemeVars } from '@kbn/ui-theme'; +import { CspFinding } from '@kbn/cloud-security-posture-common'; import { CSP_DATASET, getDatasetDisplayName } from '../../../common/utils/get_dataset_display_name'; import { truthy } from '../../../../common/utils/helpers'; import { benchmarksNavigation } from '../../../common/navigation/constants'; import cisLogoIcon from '../../../assets/icons/cis_logo.svg'; -import { CspFinding } from '../../../../common/schemas/csp_finding'; import { CspEvaluationBadge } from '../../../components/csp_evaluation_badge'; import { TakeAction } from '../../../components/take_action'; import { TableTab } from './table_tab'; @@ -50,9 +50,9 @@ import type { BenchmarkId } from '../../../../common/types_old'; import { CISBenchmarkIcon } from '../../../components/cis_benchmark_icon'; import { BenchmarkName } from '../../../../common/types_old'; import { FINDINGS_FLYOUT, FINDINGS_MISCONFIGS_FLYOUT_DESCRIPTION_LIST } from '../test_subjects'; -import { useKibana } from '../../../common/hooks/use_kibana'; import { createDetectionRuleFromBenchmarkRule } from '../utils/create_detection_rule_from_benchmark'; import { CspInlineDescriptionList } from '../../../components/csp_inline_description_list'; +import { useKibana } from '../../../common/hooks/use_kibana'; const tabs = [ { diff --git a/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/json_tab.tsx b/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/json_tab.tsx index 30f8237de91b05..df0e4cda904b78 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/json_tab.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/json_tab.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { CodeEditor } from '@kbn/code-editor'; import { XJsonLang } from '@kbn/monaco'; -import { CspFinding } from '../../../../common/schemas/csp_finding'; +import { CspFinding } from '@kbn/cloud-security-posture-common'; export const JsonTab = ({ data }: { data: CspFinding }) => (
diff --git a/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/overview_tab.tsx b/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/overview_tab.tsx index 38c526df1e7584..059d46c0c2864d 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/overview_tab.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/overview_tab.tsx @@ -20,6 +20,7 @@ import type { EuiDescriptionListProps, EuiAccordionProps } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import { isEmpty } from 'lodash'; +import { CspFinding } from '@kbn/cloud-security-posture-common'; import { getDatasetDisplayName } from '../../../common/utils/get_dataset_display_name'; import { truthy } from '../../../../common/utils/helpers'; import { CSP_MOMENT_FORMAT } from '../../../common/constants'; @@ -29,8 +30,6 @@ import { CDR_MISCONFIGURATIONS_INDEX_PATTERN, } from '../../../../common/constants'; import { useDataView } from '../../../common/api/use_data_view'; -import { useKibana } from '../../../common/hooks/use_kibana'; -import { CspFinding } from '../../../../common/schemas/csp_finding'; import { BenchmarkIcons, CodeBlock, @@ -39,6 +38,7 @@ import { RuleNameLink, } from './findings_flyout'; import { FindingsDetectionRuleCounter } from './findings_detection_rule_counter'; +import { useKibana } from '../../../common/hooks/use_kibana'; type Accordion = Pick & Pick; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/rule_tab.tsx b/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/rule_tab.tsx index 6a7eea41410e91..6d1f9fe164df76 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/rule_tab.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/rule_tab.tsx @@ -9,7 +9,7 @@ import { EuiBadge, EuiDescriptionList } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import React from 'react'; import { FormattedMessage } from '@kbn/i18n-react'; -import { CspFinding } from '../../../../common/schemas/csp_finding'; +import { CspFinding } from '@kbn/cloud-security-posture-common'; import { RulesDetectionRuleCounter } from '../../rules/rules_detection_rule_counter'; import { BenchmarkIcons, CspFlyoutMarkdown, EMPTY_VALUE, RuleNameLink } from './findings_flyout'; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/table_tab.tsx b/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/table_tab.tsx index 075291c434592e..1beeb8b662d7a0 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/table_tab.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/configurations/findings_flyout/table_tab.tsx @@ -15,7 +15,7 @@ import { import React from 'react'; import { getFlattenedObject } from '@kbn/std'; import { i18n } from '@kbn/i18n'; -import { CspFinding } from '../../../../common/schemas/csp_finding'; +import { CspFinding } from '@kbn/cloud-security-posture-common'; interface FlattenedItem { key: string; // flattened dot notation object path for CspFinding; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/latest_findings_table.tsx b/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/latest_findings_table.tsx index 2d9e1c3f25ae1e..6641fcfbc980cd 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/latest_findings_table.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/latest_findings_table.tsx @@ -11,7 +11,7 @@ import { DataTableRecord } from '@kbn/discover-utils/types'; import { HttpSetup } from '@kbn/core-http-browser'; import { i18n } from '@kbn/i18n'; import { EuiDataGridCellValueElementProps, EuiFlexItem, EuiSpacer } from '@elastic/eui'; -import { CspFinding } from '../../../../common/schemas/csp_finding'; +import { CspFinding } from '@kbn/cloud-security-posture-common'; import { getDatasetDisplayName } from '../../../common/utils/get_dataset_display_name'; import * as TEST_SUBJECTS from '../test_subjects'; import { FindingsDistributionBar } from '../layout/findings_distribution_bar'; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/use_grouped_findings.tsx b/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/use_grouped_findings.tsx index 9c1125257520e6..341485008e6e3c 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/use_grouped_findings.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/use_grouped_findings.tsx @@ -10,9 +10,11 @@ import type { IKibanaSearchResponse } from '@kbn/search-types'; import { GenericBuckets, GroupingQuery, RootAggregation } from '@kbn/grouping/src'; import { useQuery } from '@tanstack/react-query'; import { lastValueFrom } from 'rxjs'; -import { CDR_MISCONFIGURATIONS_INDEX_PATTERN } from '../../../../common/constants'; +import { + CDR_MISCONFIGURATIONS_INDEX_PATTERN, + showErrorToast, +} from '@kbn/cloud-security-posture-common'; import { useKibana } from '../../../common/hooks/use_kibana'; -import { showErrorToast } from '../../../common/utils/show_error_toast'; // Elasticsearch returns `null` when a sub-aggregation cannot be computed type NumberOrNull = number | null; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/use_latest_findings.ts b/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/use_latest_findings.ts index 3af41c5921416a..c47071cb734fd2 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/use_latest_findings.ts +++ b/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/use_latest_findings.ts @@ -11,19 +11,23 @@ import type { IKibanaSearchResponse, IKibanaSearchRequest } from '@kbn/search-ty import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { buildDataTableRecord } from '@kbn/discover-utils'; import { EsHitRecord } from '@kbn/discover-utils/types'; -import { CspFinding } from '../../../../common/schemas/csp_finding'; -import { useKibana } from '../../../common/hooks/use_kibana'; -import type { FindingsBaseEsQuery } from '../../../common/types'; -import { getAggregationCount, getFindingsCountAggQuery } from '../utils/utils'; import { + buildMutedRulesFilter, + showErrorToast, CDR_MISCONFIGURATIONS_INDEX_PATTERN, LATEST_FINDINGS_RETENTION_POLICY, -} from '../../../../common/constants'; -import { MAX_FINDINGS_TO_LOAD } from '../../../common/constants'; -import { showErrorToast } from '../../../common/utils/show_error_toast'; -import { useGetCspBenchmarkRulesStatesApi } from './use_get_benchmark_rules_state_api'; -import { CspBenchmarkRulesStates } from '../../../../common/types/latest'; -import { buildMutedRulesFilter } from '../../../../common/utils/rules_states'; + MAX_FINDINGS_TO_LOAD, + CspBenchmarkRulesStates, + CspFinding, +} from '@kbn/cloud-security-posture-common'; +import type { FindingsBaseEsQuery } from '@kbn/cloud-security-posture'; +import { + getAggregationCount, + getFindingsCountAggQuery, + useGetCspBenchmarkRulesStatesApi, + // useKibana, +} from '@kbn/cloud-security-posture'; +import { useKibana } from '../../../common/hooks/use_kibana'; interface UseFindingsOptions extends FindingsBaseEsQuery { sort: string[][]; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/use_latest_findings_grouping.tsx b/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/use_latest_findings_grouping.tsx index 0235960207e27d..c8c073d84b3033 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/use_latest_findings_grouping.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/configurations/latest_findings/use_latest_findings_grouping.tsx @@ -15,13 +15,17 @@ import { } from '@kbn/grouping/src'; import { useMemo } from 'react'; import { buildEsQuery, Filter } from '@kbn/es-query'; +import { useGetCspBenchmarkRulesStatesApi } from '@kbn/cloud-security-posture'; +import { + LATEST_FINDINGS_RETENTION_POLICY, + buildMutedRulesFilter, +} from '@kbn/cloud-security-posture-common'; import { FINDINGS_GROUPING_OPTIONS, LOCAL_STORAGE_FINDINGS_GROUPING_KEY, } from '../../../common/constants'; import { useDataViewContext } from '../../../common/contexts/data_view_context'; import { Evaluation } from '../../../../common/types_old'; -import { LATEST_FINDINGS_RETENTION_POLICY } from '../../../../common/constants'; import { FindingsGroupingAggregation, FindingsRootGroupingAggregation, @@ -36,8 +40,6 @@ import { } from './constants'; import { useCloudSecurityGrouping } from '../../../components/cloud_security_grouping'; import { getFilters } from '../utils/get_filters'; -import { useGetCspBenchmarkRulesStatesApi } from './use_get_benchmark_rules_state_api'; -import { buildMutedRulesFilter } from '../../../../common/utils/rules_states'; const getTermAggregation = (key: keyof FindingsGroupingAggregation, field: string) => ({ [key]: { diff --git a/x-pack/plugins/cloud_security_posture/public/pages/configurations/utils/create_detection_rule_from_benchmark.ts b/x-pack/plugins/cloud_security_posture/public/pages/configurations/utils/create_detection_rule_from_benchmark.ts index d77e6ddf6389ce..7b1ddf57184895 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/configurations/utils/create_detection_rule_from_benchmark.ts +++ b/x-pack/plugins/cloud_security_posture/public/pages/configurations/utils/create_detection_rule_from_benchmark.ts @@ -6,11 +6,9 @@ */ import { HttpSetup } from '@kbn/core/public'; +import { LATEST_FINDINGS_RETENTION_POLICY } from '@kbn/cloud-security-posture-common'; import { CspBenchmarkRule } from '../../../../common/types/latest'; -import { - FINDINGS_INDEX_PATTERN, - LATEST_FINDINGS_RETENTION_POLICY, -} from '../../../../common/constants'; +import { FINDINGS_INDEX_PATTERN } from '../../../../common/constants'; import { createDetectionRule } from '../../../common/api/create_detection_rule'; import { generateBenchmarkRuleTags } from '../../../../common/utils/detection_rules'; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/configurations/utils/generate_findings_tags.ts b/x-pack/plugins/cloud_security_posture/public/pages/configurations/utils/generate_findings_tags.ts new file mode 100644 index 00000000000000..d35c45e67fa4da --- /dev/null +++ b/x-pack/plugins/cloud_security_posture/public/pages/configurations/utils/generate_findings_tags.ts @@ -0,0 +1,30 @@ +/* + * 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 { CspFinding } from '@kbn/cloud-security-posture-common'; + +const CSP_RULE_TAG = 'Cloud Security'; +const CNVM_RULE_TAG_USE_CASE = 'Use Case: Configuration Audit'; +const CNVM_RULE_TAG_DATA_SOURCE_PREFIX = 'Data Source: '; + +const STATIC_RULE_TAGS = [CSP_RULE_TAG, CNVM_RULE_TAG_USE_CASE]; + +export const generateFindingsTags = (finding: CspFinding) => { + return [STATIC_RULE_TAGS] + .concat(finding.rule.tags) + .concat( + finding.rule.benchmark.posture_type + ? [ + `${CNVM_RULE_TAG_DATA_SOURCE_PREFIX}${finding.rule.benchmark.posture_type.toUpperCase()}`, + ] + : [] + ) + .concat( + finding.rule.benchmark.posture_type === 'cspm' ? ['Domain: Cloud'] : ['Domain: Container'] + ) + .flat(); +}; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/configurations/utils/utils.ts b/x-pack/plugins/cloud_security_posture/public/pages/configurations/utils/utils.ts deleted file mode 100644 index 67b37ad1001fdf..00000000000000 --- a/x-pack/plugins/cloud_security_posture/public/pages/configurations/utils/utils.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 { estypes } from '@elastic/elasticsearch'; -export { getFilters } from './get_filters'; - -export const getFindingsCountAggQuery = () => ({ - count: { terms: { field: 'result.evaluation' } }, -}); - -export const getAggregationCount = ( - buckets: Array -) => { - const passed = buckets.find((bucket) => bucket?.key === 'passed'); - const failed = buckets.find((bucket) => bucket?.key === 'failed'); - - return { - passed: passed?.doc_count || 0, - failed: failed?.doc_count || 0, - }; -}; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/findings/findings.tsx b/x-pack/plugins/cloud_security_posture/public/pages/findings/findings.tsx index f8d91d52502342..2bce21e36741ef 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/findings/findings.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/findings/findings.tsx @@ -10,11 +10,11 @@ import { EuiSpacer, EuiTab, EuiTabs, EuiTitle } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; import { Redirect, useHistory, useLocation, matchPath } from 'react-router-dom'; import { Routes, Route } from '@kbn/shared-ux-router'; +import { useCspSetupStatusApi } from '@kbn/cloud-security-posture'; import { Configurations } from '../configurations'; import { cloudPosturePages, findingsNavigation } from '../../common/navigation/constants'; import { LOCAL_STORAGE_FINDINGS_LAST_SELECTED_TAB_KEY } from '../../common/constants'; import { VULNERABILITIES_INDEX_NAME, FINDINGS_INDEX_NAME } from '../../../common/constants'; -import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api'; import { getStatusForIndexName } from '../../../common/utils/helpers'; import { Vulnerabilities } from '../vulnerabilities'; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/rules/rules.test.tsx b/x-pack/plugins/cloud_security_posture/public/pages/rules/rules.test.tsx index 66829ee739010e..848e2343e05014 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/rules/rules.test.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/rules/rules.test.tsx @@ -10,19 +10,19 @@ import Chance from 'chance'; import { Rules } from '.'; import { render, screen } from '@testing-library/react'; import { QueryClient } from '@tanstack/react-query'; +import { useCspSetupStatusApi } from '@kbn/cloud-security-posture'; import { TestProvider } from '../../test/test_provider'; import { type RouteComponentProps } from 'react-router-dom'; import { PageUrlParams } from '../../../common/types/latest'; import { createReactQueryResponse } from '../../test/fixtures/react_query'; import { coreMock } from '@kbn/core/public/mocks'; -import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api'; import { useSubscriptionStatus } from '../../common/hooks/use_subscription_status'; import { useCspIntegrationLink } from '../../common/navigation/use_csp_integration_link'; import { useLicenseManagementLocatorApi } from '../../common/api/use_license_management_locator_api'; import { useCspBenchmarkIntegrationsV2 } from '../benchmarks/use_csp_benchmark_integrations'; import * as TEST_SUBJECTS from './test_subjects'; -jest.mock('../../common/api/use_setup_status_api'); +jest.mock('@kbn/cloud-security-posture'); // Mock use_setup_status_api jest.mock('../../common/api/use_license_management_locator_api'); jest.mock('../../common/hooks/use_subscription_status'); jest.mock('../../common/navigation/use_csp_integration_link'); diff --git a/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_flyout.tsx b/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_flyout.tsx index 264a8229d11a33..f77506eec3edfc 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_flyout.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_flyout.tsx @@ -23,7 +23,6 @@ import { import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import { HttpSetup } from '@kbn/core/public'; -import { useKibana } from '../../common/hooks/use_kibana'; import { getFindingsDetectionRuleSearchTags } from '../../../common/utils/detection_rules'; import { CspBenchmarkRuleMetadata } from '../../../common/types/latest'; import { getRuleList } from '../configurations/findings_flyout/rule_tab'; @@ -37,6 +36,7 @@ import { } from '../../components/take_action'; import { useFetchDetectionRulesByTags } from '../../common/api/use_fetch_detection_rules_by_tags'; import { createDetectionRuleFromBenchmarkRule } from '../configurations/utils/create_detection_rule_from_benchmark'; +import { useKibana } from '../../common/hooks/use_kibana'; export const RULES_FLYOUT_SWITCH_BUTTON = 'rule-flyout-switch-button'; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_table.tsx b/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_table.tsx index 05bed9ce85cd30..ddd5437b13841f 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_table.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_table.tsx @@ -22,7 +22,6 @@ import { i18n } from '@kbn/i18n'; import { uniqBy } from 'lodash'; import { HttpSetup } from '@kbn/core/public'; import { CloudSecurityPostureStartServices } from '../../types'; -import { useKibana } from '../../common/hooks/use_kibana'; import { getFindingsDetectionRuleSearchTags } from '../../../common/utils/detection_rules'; import { ColumnNameWithTooltip } from '../../components/column_name_with_tooltip'; import type { CspBenchmarkRulesWithStates, RulesState } from './rules_container'; @@ -30,6 +29,7 @@ import * as TEST_SUBJECTS from './test_subjects'; import { RuleStateUpdateRequest, useChangeCspRuleState } from './use_change_csp_rule_state'; import { showChangeBenchmarkRuleStatesSuccessToast } from '../../components/take_action'; import { fetchDetectionRulesByTags } from '../../common/api/use_fetch_detection_rules_by_tags'; +import { useKibana } from '../../common/hooks/use_kibana'; export const RULES_ROWS_ENABLE_SWITCH_BUTTON = 'rules-row-enable-switch-button'; export const RULES_ROW_SELECT_ALL_CURRENT_PAGE = 'cloud-security-fields-selector-item-all'; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_table_header.tsx b/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_table_header.tsx index fc714263f38be7..fa954774615c44 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_table_header.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_table_header.tsx @@ -24,7 +24,6 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import { css } from '@emotion/react'; import { euiThemeVars } from '@kbn/ui-theme'; -import { useKibana } from '../../common/hooks/use_kibana'; import { getFindingsDetectionRuleSearchTagsFromArrayOfRules } from '../../../common/utils/detection_rules'; import { RuleStateAttributesWithoutStates, @@ -34,6 +33,7 @@ import { CspBenchmarkRulesWithStates } from './rules_container'; import { MultiSelectFilter } from '../../common/component/multi_select_filter'; import { showChangeBenchmarkRuleStatesSuccessToast } from '../../components/take_action'; import { useFetchDetectionRulesByTags } from '../../common/api/use_fetch_detection_rules_by_tags'; +import { useKibana } from '../../common/hooks/use_kibana'; export const RULES_BULK_ACTION_BUTTON = 'bulk-action-button'; export const RULES_BULK_ACTION_OPTION_ENABLE = 'bulk-action-option-enable'; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/rules/use_csp_rules_state.ts b/x-pack/plugins/cloud_security_posture/public/pages/rules/use_csp_rules_state.ts index e712b130e16514..00c7ae507f2260 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/rules/use_csp_rules_state.ts +++ b/x-pack/plugins/cloud_security_posture/public/pages/rules/use_csp_rules_state.ts @@ -6,7 +6,7 @@ */ import { useQuery } from '@tanstack/react-query'; -import { CspBenchmarkRulesStates } from '../../../common/types/latest'; +import { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common'; import { CSP_GET_BENCHMARK_RULES_STATE_ROUTE_PATH } from '../../../common/constants'; import { useKibana } from '../../common/hooks/use_kibana'; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/vulnerabilities/hooks/use_grouped_vulnerabilities.tsx b/x-pack/plugins/cloud_security_posture/public/pages/vulnerabilities/hooks/use_grouped_vulnerabilities.tsx index 79cb2aad7e60e4..29fe801f68f4e8 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/vulnerabilities/hooks/use_grouped_vulnerabilities.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/vulnerabilities/hooks/use_grouped_vulnerabilities.tsx @@ -10,9 +10,9 @@ import type { IKibanaSearchResponse } from '@kbn/search-types'; import { GenericBuckets, GroupingQuery, RootAggregation } from '@kbn/grouping/src'; import { useQuery } from '@tanstack/react-query'; import { lastValueFrom } from 'rxjs'; +import { showErrorToast } from '@kbn/cloud-security-posture-common'; import { LATEST_VULNERABILITIES_INDEX_PATTERN } from '../../../../common/constants'; import { useKibana } from '../../../common/hooks/use_kibana'; -import { showErrorToast } from '../../../common/utils/show_error_toast'; // Elasticsearch returns `null` when a sub-aggregation cannot be computed type NumberOrNull = number | null; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/vulnerabilities/hooks/use_latest_vulnerabilities.tsx b/x-pack/plugins/cloud_security_posture/public/pages/vulnerabilities/hooks/use_latest_vulnerabilities.tsx index 15760e80ad7c29..259055fd909d9c 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/vulnerabilities/hooks/use_latest_vulnerabilities.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/vulnerabilities/hooks/use_latest_vulnerabilities.tsx @@ -16,16 +16,16 @@ import { } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { buildDataTableRecord } from '@kbn/discover-utils'; import { EsHitRecord } from '@kbn/discover-utils/types'; -import { MAX_FINDINGS_TO_LOAD, VULNERABILITY_FIELDS } from '../../../common/constants'; +import { FindingsBaseEsQuery } from '@kbn/cloud-security-posture'; +import { MAX_FINDINGS_TO_LOAD, showErrorToast } from '@kbn/cloud-security-posture-common'; +import { VULNERABILITY_FIELDS } from '../../../common/constants'; import { CspVulnerabilityFinding } from '../../../../common/schemas'; import { LATEST_VULNERABILITIES_INDEX_PATTERN, LATEST_VULNERABILITIES_RETENTION_POLICY, } from '../../../../common/constants'; -import { useKibana } from '../../../common/hooks/use_kibana'; -import { showErrorToast } from '../../../common/utils/show_error_toast'; -import { FindingsBaseEsQuery } from '../../../common/types'; import { getCaseInsensitiveSortScript } from '../utils/custom_sort_script'; +import { useKibana } from '../../../common/hooks/use_kibana'; type LatestFindingsRequest = IKibanaSearchRequest; type LatestFindingsResponse = IKibanaSearchResponse< SearchResponse diff --git a/x-pack/plugins/cloud_security_posture/public/pages/vulnerabilities/vulnerabilities.tsx b/x-pack/plugins/cloud_security_posture/public/pages/vulnerabilities/vulnerabilities.tsx index 5940b022a0b90d..a43e008bbe57c6 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/vulnerabilities/vulnerabilities.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/vulnerabilities/vulnerabilities.tsx @@ -6,9 +6,9 @@ */ import React from 'react'; import { Routes, Route } from '@kbn/shared-ux-router'; +import { useCspSetupStatusApi } from '@kbn/cloud-security-posture'; import { CDR_VULNERABILITIES_DATA_VIEW_ID_PREFIX } from '../../../common/constants'; import { NoVulnerabilitiesStates } from '../../components/no_vulnerabilities_states'; -import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api'; import { CloudPosturePage } from '../../components/cloud_posture_page'; import { findingsNavigation } from '../../common/navigation/constants'; import { useDataView } from '../../common/api/use_data_view'; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/vulnerabilities/vulnerabilties.test.tsx b/x-pack/plugins/cloud_security_posture/public/pages/vulnerabilities/vulnerabilties.test.tsx index cb975088c5c8e3..0b120e595f4634 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/vulnerabilities/vulnerabilties.test.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/vulnerabilities/vulnerabilties.test.tsx @@ -7,12 +7,12 @@ import React from 'react'; import Chance from 'chance'; import { Vulnerabilities } from './vulnerabilities'; +import { useCspSetupStatusApi } from '@kbn/cloud-security-posture'; import { CDR_MISCONFIGURATIONS_DATA_VIEW_ID_PREFIX, LATEST_VULNERABILITIES_INDEX_DEFAULT_NS, VULN_MGMT_POLICY_TEMPLATE, } from '../../../common/constants'; -import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api'; import { useDataView } from '../../common/api/use_data_view'; import { useSubscriptionStatus } from '../../common/hooks/use_subscription_status'; import { createReactQueryResponse } from '../../test/fixtures/react_query'; @@ -29,7 +29,7 @@ import { useLicenseManagementLocatorApi } from '../../common/api/use_license_man import { createStubDataView } from '@kbn/data-views-plugin/common/stubs'; jest.mock('../../common/api/use_data_view'); -jest.mock('../../common/api/use_setup_status_api'); +jest.mock('@kbn/cloud-security-posture'); // Mock use_setup_status_api jest.mock('../../common/api/use_license_management_locator_api'); jest.mock('../../common/hooks/use_subscription_status'); jest.mock('../../common/navigation/use_navigate_to_cis_integration_policies'); diff --git a/x-pack/plugins/cloud_security_posture/public/pages/vulnerability_dashboard/vulnerability_dashboard.test.tsx b/x-pack/plugins/cloud_security_posture/public/pages/vulnerability_dashboard/vulnerability_dashboard.test.tsx index 9e68d5d051c6b2..eec172e1c01ff6 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/vulnerability_dashboard/vulnerability_dashboard.test.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/vulnerability_dashboard/vulnerability_dashboard.test.tsx @@ -8,13 +8,13 @@ import React from 'react'; import Chance from 'chance'; import { dataPluginMock } from '@kbn/data-plugin/public/mocks'; import { unifiedSearchPluginMock } from '@kbn/unified-search-plugin/public/mocks'; +import { useCspSetupStatusApi } from '@kbn/cloud-security-posture'; import { LATEST_VULNERABILITIES_INDEX_DEFAULT_NS, VULN_MGMT_POLICY_TEMPLATE, } from '../../../common/constants'; import { chartPluginMock } from '@kbn/charts-plugin/public/mocks'; import { discoverPluginMock } from '@kbn/discover-plugin/public/mocks'; -import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api'; import { useSubscriptionStatus } from '../../common/hooks/use_subscription_status'; import { createReactQueryResponse } from '../../test/fixtures/react_query'; import { useCISIntegrationPoliciesLink } from '../../common/navigation/use_navigate_to_cis_integration_policies'; @@ -33,7 +33,7 @@ import { useVulnerabilityDashboardApi } from '../../common/api/use_vulnerability import { mockCnvmDashboardData } from './_mocks_/vulnerability_dashboard.mock'; jest.mock('../../common/api/use_data_view'); -jest.mock('../../common/api/use_setup_status_api'); +jest.mock('@kbn/cloud-security-posture'); // Mock use_setup_status_api jest.mock('../../common/api/use_license_management_locator_api'); jest.mock('../../common/hooks/use_subscription_status'); jest.mock('../../common/navigation/use_navigate_to_cis_integration_policies'); diff --git a/x-pack/plugins/cloud_security_posture/public/pages/vulnerability_dashboard/vulnerability_dashboard.tsx b/x-pack/plugins/cloud_security_posture/public/pages/vulnerability_dashboard/vulnerability_dashboard.tsx index 33c1a5fdad4d7b..0a0a0ff21749a6 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/vulnerability_dashboard/vulnerability_dashboard.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/vulnerability_dashboard/vulnerability_dashboard.tsx @@ -7,9 +7,9 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; import { EuiPageHeader, EuiSpacer } from '@elastic/eui'; +import { useCspSetupStatusApi } from '@kbn/cloud-security-posture'; import { useVulnerabilityDashboardApi } from '../../common/api/use_vulnerability_dashboard_api'; import { VulnerabilityTrendGraph } from './vulnerability_trend_graph'; -import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api'; import { NoVulnerabilitiesStates } from '../../components/no_vulnerabilities_states'; import { VULNERABILITY_DASHBOARD_CONTAINER, 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 556ab0c7c830c9..aa428c7083eca4 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,11 +5,11 @@ * 2.0. */ import type { TransformPutTransformRequest } from '@elastic/elasticsearch/lib/api/types'; +import { LATEST_FINDINGS_RETENTION_POLICY } from '@kbn/cloud-security-posture-common'; import { CLOUD_SECURITY_POSTURE_PACKAGE_NAME, FINDINGS_INDEX_PATTERN, LATEST_FINDINGS_INDEX_DEFAULT_NS, - LATEST_FINDINGS_RETENTION_POLICY, } from '../../common/constants'; const LATEST_FINDINGS_TRANSFORM_V830 = 'cloud_security_posture.findings_latest-default-0.0.1'; diff --git a/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/bulk_action/utils.ts b/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/bulk_action/utils.ts index df5db4cb2e1ab1..7b4732eee4fc2c 100644 --- a/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/bulk_action/utils.ts +++ b/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/bulk_action/utils.ts @@ -8,10 +8,10 @@ import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; import type { FindResult, RulesClient } from '@kbn/alerting-plugin/server'; import type { RuleParams } from '@kbn/alerting-plugin/server/application/rule/types'; +import { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common'; import type { CspBenchmarkRule, RulesToUpdate, - CspBenchmarkRulesStates, CspSettings, } from '../../../../common/types/rules/v4'; import { diff --git a/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/get_states/get_states.ts b/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/get_states/get_states.ts index a55bcd92ab3c81..76b3b3b53a6954 100644 --- a/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/get_states/get_states.ts +++ b/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/get_states/get_states.ts @@ -6,9 +6,9 @@ */ import { transformError } from '@kbn/securitysolution-es-utils'; +import { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common'; import { CspRouter } from '../../../types'; import { CSP_GET_BENCHMARK_RULES_STATE_ROUTE_PATH } from '../../../../common/constants'; -import { CspBenchmarkRulesStates } from '../../../../common/types/rules/v4'; import { getCspBenchmarkRulesStatesHandler } from './v1'; export const defineGetCspBenchmarkRulesStatesRoute = (router: CspRouter) => diff --git a/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/get_states/v1.ts b/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/get_states/v1.ts index 4d28b995cbdaf9..7fcce039368ea4 100644 --- a/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/get_states/v1.ts +++ b/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/get_states/v1.ts @@ -10,12 +10,13 @@ import { } from '@kbn/core-saved-objects-api-server'; import { transformError } from '@kbn/securitysolution-es-utils'; import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; -import { CspBenchmarkRulesStates, CspSettings } from '../../../../common/types/rules/v4'; +import { buildMutedRulesFilter } from '@kbn/cloud-security-posture-common'; +import { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common'; +import { CspSettings } from '../../../../common/types/rules/v4'; import { INTERNAL_CSP_SETTINGS_SAVED_OBJECT_ID, INTERNAL_CSP_SETTINGS_SAVED_OBJECT_TYPE, } from '../../../../common/constants'; -import { buildMutedRulesFilter } from '../../../../common/utils/rules_states'; export const createCspSettingObject = async (soClient: SavedObjectsClientContract) => { return soClient.create( diff --git a/x-pack/plugins/cloud_security_posture/server/routes/compliance_dashboard/get_clusters.ts b/x-pack/plugins/cloud_security_posture/server/routes/compliance_dashboard/get_clusters.ts index e7938636213409..f38e00d3df304e 100644 --- a/x-pack/plugins/cloud_security_posture/server/routes/compliance_dashboard/get_clusters.ts +++ b/x-pack/plugins/cloud_security_posture/server/routes/compliance_dashboard/get_clusters.ts @@ -15,7 +15,8 @@ import type { } from '@elastic/elasticsearch/lib/api/types'; import type { Logger } from '@kbn/core/server'; import { MappingRuntimeFields } from '@elastic/elasticsearch/lib/api/types'; -import { CspFinding } from '../../../common/schemas/csp_finding'; + +import { CspFinding } from '@kbn/cloud-security-posture-common'; import type { Cluster } from '../../../common/types_old'; import { getPostureStatsFromAggs, failedFindingsAggQuery } from './get_grouped_findings_evaluation'; import type { FailedFindingsQueryResult } from './get_grouped_findings_evaluation'; diff --git a/x-pack/plugins/cloud_security_posture/server/routes/status/status.ts b/x-pack/plugins/cloud_security_posture/server/routes/status/status.ts index df2fc0d36fc63f..4c9f7aa96c06d7 100644 --- a/x-pack/plugins/cloud_security_posture/server/routes/status/status.ts +++ b/x-pack/plugins/cloud_security_posture/server/routes/status/status.ts @@ -17,6 +17,7 @@ import moment from 'moment'; import { Installation, PackagePolicy } from '@kbn/fleet-plugin/common'; import { schema } from '@kbn/config-schema'; import { VersionedRoute } from '@kbn/core-http-server/src/versioning/types'; +import { LATEST_FINDINGS_RETENTION_POLICY } from '@kbn/cloud-security-posture-common'; import { CLOUD_SECURITY_POSTURE_PACKAGE_NAME, STATUS_ROUTE_PATH, @@ -31,7 +32,6 @@ import { VULN_MGMT_POLICY_TEMPLATE, POSTURE_TYPE_ALL, LATEST_VULNERABILITIES_RETENTION_POLICY, - LATEST_FINDINGS_RETENTION_POLICY, } from '../../../common/constants'; import type { CspApiRequestHandlerContext, diff --git a/x-pack/plugins/cloud_security_posture/tsconfig.json b/x-pack/plugins/cloud_security_posture/tsconfig.json index 83891e3269eca4..f6404b9fb07104 100755 --- a/x-pack/plugins/cloud_security_posture/tsconfig.json +++ b/x-pack/plugins/cloud_security_posture/tsconfig.json @@ -65,7 +65,9 @@ "@kbn/code-editor-mock", "@kbn/search-types", "@kbn/react-kibana-mount", - "@kbn/spaces-plugin" + "@kbn/cloud-security-posture-common", + "@kbn/cloud-security-posture", + "@kbn/spaces-plugin", ], "exclude": ["target/**/*"] } diff --git a/x-pack/plugins/security_solution/public/flyout/entity_details/host_right/content.tsx b/x-pack/plugins/security_solution/public/flyout/entity_details/host_right/content.tsx index af3eae38fc1f8c..8af3c7c78f6f6a 100644 --- a/x-pack/plugins/security_solution/public/flyout/entity_details/host_right/content.tsx +++ b/x-pack/plugins/security_solution/public/flyout/entity_details/host_right/content.tsx @@ -5,8 +5,9 @@ * 2.0. */ -import React from 'react'; +import React, { useMemo } from 'react'; import { EuiHorizontalRule } from '@elastic/eui'; +import { useCspSetupStatusApi, isIndexWithDocsAvailable } from '@kbn/cloud-security-posture'; import { AssetCriticalityAccordion } from '../../../entity_analytics/components/asset_criticality/asset_criticality_selector'; import { FlyoutRiskSummary } from '../../../entity_analytics/components/risk_summary_flyout/risk_summary'; import type { RiskScoreState } from '../../../entity_analytics/api/hooks/use_risk_score'; @@ -17,6 +18,7 @@ import { HOST_PANEL_OBSERVED_HOST_QUERY_ID, HOST_PANEL_RISK_SCORE_QUERY_ID } fro import type { ObservedEntityData } from '../shared/components/observed_entity/types'; import { useObservedHostFields } from './hooks/use_observed_host_fields'; import type { EntityDetailsLeftPanelTab } from '../shared/components/left_panel/left_panel_header'; +import { InsightEntity } from '../shared/components/insight_entity'; interface HostPanelContentProps { observedHost: ObservedEntityData; @@ -44,7 +46,12 @@ export const HostPanelContent = ({ isPreviewMode, }: HostPanelContentProps) => { const observedFields = useObservedHostFields(observedHost); - + const getSetupStatus = useCspSetupStatusApi({ + refetchInterval: 10000, + }); + const notEmptyIndices = useMemo(() => { + return isIndexWithDocsAvailable(getSetupStatus.data?.indicesDetails || []); + }, [getSetupStatus.data?.indicesDetails]); return ( {riskScoreState.isModuleEnabled && riskScoreState.data?.length !== 0 && ( @@ -71,6 +78,8 @@ export const HostPanelContent = ({ observedFields={observedFields} queryId={HOST_PANEL_OBSERVED_HOST_QUERY_ID} /> + + {notEmptyIndices && } ); }; diff --git a/x-pack/plugins/security_solution/public/flyout/entity_details/shared/components/insight_entity/index.test.tsx b/x-pack/plugins/security_solution/public/flyout/entity_details/shared/components/insight_entity/index.test.tsx new file mode 100644 index 00000000000000..7fd73b6b618cfb --- /dev/null +++ b/x-pack/plugins/security_solution/public/flyout/entity_details/shared/components/insight_entity/index.test.tsx @@ -0,0 +1,26 @@ +/* + * 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. + */ + +// Add stuff here +import { render } from '@testing-library/react'; +import React from 'react'; +import { TestProviders } from '../../../../../common/mock'; +import { InsightEntity } from '.'; + +const mockProps = { + hostName: 'testContextID', +}; + +describe('InsightEntity', () => { + it('renders', () => { + const { queryByTestId } = render(, { + wrapper: TestProviders, + }); + + expect(queryByTestId('insightEntityTestSubj')).toBeInTheDocument(); + }); +}); diff --git a/x-pack/plugins/security_solution/public/flyout/entity_details/shared/components/insight_entity/index.tsx b/x-pack/plugins/security_solution/public/flyout/entity_details/shared/components/insight_entity/index.tsx new file mode 100644 index 00000000000000..660be72a2edfbd --- /dev/null +++ b/x-pack/plugins/security_solution/public/flyout/entity_details/shared/components/insight_entity/index.tsx @@ -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. + */ + +import { EuiAccordion, EuiSpacer, EuiTitle, useEuiTheme } from '@elastic/eui'; + +import React from 'react'; +import { css } from '@emotion/react'; +import { FormattedMessage } from '@kbn/i18n-react'; +import { MisconfigurationsOverview } from './misconfigurations_overview'; + +export const InsightEntity = ({ hostName }: { hostName: string }) => { + const { euiTheme } = useEuiTheme(); + + return ( + <> + +

+ +

+ + } + css={css` + .euiAccordion__optionalAction { + margin-left: auto; + } + `} + > + + + +
+ + ); +}; diff --git a/x-pack/plugins/security_solution/public/flyout/entity_details/shared/components/insight_entity/misconfigurations_overview.test.tsx b/x-pack/plugins/security_solution/public/flyout/entity_details/shared/components/insight_entity/misconfigurations_overview.test.tsx new file mode 100644 index 00000000000000..4e351dc1fa42a8 --- /dev/null +++ b/x-pack/plugins/security_solution/public/flyout/entity_details/shared/components/insight_entity/misconfigurations_overview.test.tsx @@ -0,0 +1,28 @@ +/* + * 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. + */ + +// Add stuff here +import { render } from '@testing-library/react'; +import React from 'react'; +import { TestProviders } from '../../../../../common/mock'; +import { MisconfigurationsOverview } from './misconfigurations_overview'; + +const mockProps = { + hostName: 'testContextID', +}; + +describe('MisconfigurationsOverview', () => { + it('renders', () => { + const { queryByTestId } = render(, { + wrapper: TestProviders, + }); + expect( + queryByTestId('securitySolutionFlyoutInsightsMisconfigurationsContent') + ).toBeInTheDocument(); + expect(queryByTestId('noFindingsDataTestSubj')).toBeInTheDocument(); + }); +}); diff --git a/x-pack/plugins/security_solution/public/flyout/entity_details/shared/components/insight_entity/misconfigurations_overview.tsx b/x-pack/plugins/security_solution/public/flyout/entity_details/shared/components/insight_entity/misconfigurations_overview.tsx new file mode 100644 index 00000000000000..2c533971fcb75f --- /dev/null +++ b/x-pack/plugins/security_solution/public/flyout/entity_details/shared/components/insight_entity/misconfigurations_overview.tsx @@ -0,0 +1,178 @@ +/* + * 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 React, { useCallback } from 'react'; +import { css } from '@emotion/react'; +import { EuiFlexGroup, EuiFlexItem, EuiText, useEuiTheme } from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n-react'; +import { DistributionBar } from '@kbn/security-solution-distribution-bar'; +import { useMisconfigurationPreview } from '@kbn/cloud-security-posture'; +import { euiThemeVars } from '@kbn/ui-theme'; +import { i18n } from '@kbn/i18n'; +import { ExpandablePanel } from '../../../../shared/components/expandable_panel'; + +export const MisconfigurationsOverview = ({ hostName }: { hostName: string }) => { + const queryHostName = useCallback(() => { + return { + bool: { + must: [], + filter: [ + { + bool: { + should: [{ term: { 'host.name': { value: `${hostName}` } } }], + minimum_should_match: 1, + }, + }, + ], + should: [], + must_not: [], + }, + }; + }, [hostName]); + + const { data } = useMisconfigurationPreview({ + query: queryHostName(), + sort: [], + enabled: true, + pageSize: 1, + }); + + const passedFindings = data?.count.passed || 0; + const failedFindings = data?.count.failed || 0; + const { euiTheme } = useEuiTheme(); + const getFindingsStats = (passedFindingsStats: number, failedFindingsStats: number) => { + if (passedFindingsStats === 0 && failedFindingsStats === 0) return []; + return [ + { + key: i18n.translate( + 'xpack.securitySolution.flyout.right.insights.misconfigurations.passedFindingsText', + { + defaultMessage: 'Passed findings', + } + ), + count: passedFindingsStats, + color: euiThemeVars.euiColorSuccess, + }, + { + key: i18n.translate( + 'xpack.securitySolution.flyout.right.insights.misconfigurations.failedFindingsText', + { + defaultMessage: 'Failed findings', + } + ), + count: failedFindingsStats, + color: euiThemeVars.euiColorVis9, + }, + ]; + }; + + const MisconfigurationEmptyState = () => { + return ( + + + + + + + + + + + + + ); + }; + + const MisconfigurationPreviewScore = () => { + return ( + + + + + {`${Math.round((passedFindings / (passedFindings + failedFindings)) * 100)}%`} + + + + + + + + + + ); + }; + + return ( + + + + ), + // TODO: Uncomment when we have the expanded flyout + // iconType: 'arrowStart', + }} + data-test-subj={'securitySolutionFlyoutInsightsMisconfigurations'} + > + + {passedFindings === 0 && failedFindings === 0 ? ( + + ) : ( + + )} + + + + + + + + + + + ); +}; diff --git a/x-pack/plugins/security_solution/tsconfig.json b/x-pack/plugins/security_solution/tsconfig.json index bdaf656b9c9862..90570fcc499398 100644 --- a/x-pack/plugins/security_solution/tsconfig.json +++ b/x-pack/plugins/security_solution/tsconfig.json @@ -208,6 +208,8 @@ "@kbn/core-theme-browser", "@kbn/integration-assistant-plugin", "@kbn/avc-banner", + "@kbn/security-solution-distribution-bar", + "@kbn/cloud-security-posture", "@kbn/esql-ast", "@kbn/esql-validation-autocomplete", "@kbn/config", diff --git a/x-pack/test/security_solution_cypress/cypress/e2e/cloud_security_posture/misconfiguration/host_details_insight_accordion.cy.ts b/x-pack/test/security_solution_cypress/cypress/e2e/cloud_security_posture/misconfiguration/host_details_insight_accordion.cy.ts new file mode 100644 index 00000000000000..d18eeea37c5cdd --- /dev/null +++ b/x-pack/test/security_solution_cypress/cypress/e2e/cloud_security_posture/misconfiguration/host_details_insight_accordion.cy.ts @@ -0,0 +1,41 @@ +/* + * 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 { getDataTestSubjectSelector } from '../../../helpers/common'; +import { expandFirstAlertHostFlyout } from '../../../tasks/asset_criticality/common'; +import { deleteAlertsAndRules } from '../../../tasks/api_calls/common'; +import { login } from '../../../tasks/login'; +import { visit } from '../../../tasks/navigation'; +import { createRule } from '../../../tasks/api_calls/rules'; +import { getNewRule } from '../../../objects/rule'; +import { ALERTS_URL } from '../../../urls/navigation'; +import { waitForAlertsToPopulate } from '../../../tasks/create_new_rule'; + +const HOST_INSIGHT_MISCONFIGURATION = getDataTestSubjectSelector( + 'securitySolutionFlyoutInsightsMisconfigurationsLeftSection' +); +const HOST_INSIGHT_MISCONFIGURATION_TITLE = getDataTestSubjectSelector( + 'securitySolutionFlyoutInsightsMisconfigurationsTitleText' +); + +describe('Alert Host details expandable flyout', { tags: ['@ess', '@serverless'] }, () => { + beforeEach(() => { + deleteAlertsAndRules(); + login(); + createRule(getNewRule()); + visit(ALERTS_URL); + waitForAlertsToPopulate(); + expandFirstAlertHostFlyout(); + }); + + it('should not display Misconfiguration preview under Insights Entities when all Indices is empty', () => { + cy.log('check if Misconfiguration preview section is not rendered'); + cy.get(HOST_INSIGHT_MISCONFIGURATION).should('not.exist'); + + cy.log('check if Misconfiguration preview title is not shown'); + cy.get(HOST_INSIGHT_MISCONFIGURATION_TITLE).should('not.exist'); + }); +}); diff --git a/yarn.lock b/yarn.lock index 1ffccfe9744d47..3dac216d247b35 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3612,10 +3612,18 @@ version "0.0.0" uid "" +"@kbn/cloud-security-posture-common@link:x-pack/packages/kbn-cloud-security-posture-common": + version "0.0.0" + uid "" + "@kbn/cloud-security-posture-plugin@link:x-pack/plugins/cloud_security_posture": version "0.0.0" uid "" +"@kbn/cloud-security-posture@link:x-pack/packages/kbn-cloud-security-posture": + version "0.0.0" + uid "" + "@kbn/cloud@link:packages/cloud": version "0.0.0" uid ""