From e2906f6554846017c9146706c39144847be66464 Mon Sep 17 00:00:00 2001 From: Yarden Shalom Date: Sun, 15 Jan 2023 13:54:01 +0200 Subject: [PATCH 1/5] cspm dashboard changes --- .../public/components/cis_benchmark_icon.tsx | 2 + .../compliance_dashboard.tsx | 12 +++-- ...rks_section.tsx => benchmarks_section.tsx} | 48 +++++++++++++----- ...tion.test.tsx => summary_section.test.tsx} | 4 +- ...ummary_section.tsx => summary_section.tsx} | 50 +++++++++++++++---- .../server/lib/fleet_util.ts | 10 ++-- 6 files changed, 91 insertions(+), 35 deletions(-) rename x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/{cloud_benchmarks_section.tsx => benchmarks_section.tsx} (75%) rename x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/{cloud_summary_section.test.tsx => summary_section.test.tsx} (93%) rename x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/{cloud_summary_section.tsx => summary_section.tsx} (73%) diff --git a/x-pack/plugins/cloud_security_posture/public/components/cis_benchmark_icon.tsx b/x-pack/plugins/cloud_security_posture/public/components/cis_benchmark_icon.tsx index 88dd8ce14a9b8..4751335c3debd 100644 --- a/x-pack/plugins/cloud_security_posture/public/components/cis_benchmark_icon.tsx +++ b/x-pack/plugins/cloud_security_posture/public/components/cis_benchmark_icon.tsx @@ -21,6 +21,8 @@ const getBenchmarkIdIconType = (props: Props): string => { switch (props.type) { case 'cis_eks': return cisEksIcon; + case 'cis_aws': + return 'logoAWS'; case 'cis_k8s': default: return 'logoKubernetes'; 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 78ee59684896c..1132a45991d06 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 @@ -29,8 +29,8 @@ import { import { useCspmStatsApi, useKspmStatsApi } from '../../common/api'; import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api'; import { NoFindingsStates } from '../../components/no_findings_states'; -import { CloudSummarySection } from './dashboard_sections/cloud_summary_section'; -import { CloudBenchmarksSection } from './dashboard_sections/cloud_benchmarks_section'; +import { SummarySection } from './dashboard_sections/summary_section'; +import { BenchmarksSection } from './dashboard_sections/benchmarks_section'; import { CSPM_POLICY_TEMPLATE, KSPM_POLICY_TEMPLATE } from '../../../common/constants'; const noDataOptions: Record< @@ -113,10 +113,12 @@ const IntegrationPostureDashboard = ({ complianceData, notInstalledConfig, isIntegrationInstalled, + dashboardType, }: { complianceData: ComplianceDashboardData | undefined; notInstalledConfig: CspNoDataPageProps; isIntegrationInstalled?: boolean; + dashboardType: PosturePolicyTemplate; }) => { const noFindings = !complianceData || complianceData.stats.totalFindings === 0; @@ -164,9 +166,9 @@ const IntegrationPostureDashboard = ({ // there are findings, displays dashboard even if integration is not installed return ( <> - + - + ); @@ -232,6 +234,7 @@ export const ComplianceDashboard = () => {
{
{ const { euiTheme } = useEuiTheme(); const navToFindings = useNavigateFindings(); const handleEvalCounterClick = (clusterId: string, evaluation: Evaluation) => { - navToFindings({ cluster_id: clusterId, 'result.evaluation': evaluation }); + navToFindings({ + cluster_id: clusterId, + 'result.evaluation': evaluation, + ...getPolicyTemplateQuery(dashboardType), + }); }; const handleCellClick = (clusterId: string, ruleSection: string) => { @@ -34,11 +44,16 @@ export const CloudBenchmarksSection = ({ cluster_id: clusterId, 'rule.section': ruleSection, 'result.evaluation': RULE_FAILED, + ...getPolicyTemplateQuery(dashboardType), }); }; const handleViewAllClick = (clusterId: string) => { - navToFindings({ cluster_id: clusterId, 'result.evaluation': RULE_FAILED }); + navToFindings({ + cluster_id: clusterId, + 'result.evaluation': RULE_FAILED, + ...getPolicyTemplateQuery(dashboardType), + }); }; return ( @@ -55,10 +70,17 @@ export const CloudBenchmarksSection = ({
- + {dashboardType === KSPM_POLICY_TEMPLATE ? ( + + ) : ( + + )}
@@ -69,7 +91,7 @@ export const CloudBenchmarksSection = ({ >
@@ -82,7 +104,7 @@ export const CloudBenchmarksSection = ({ >
diff --git a/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/cloud_summary_section.test.tsx b/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/summary_section.test.tsx similarity index 93% rename from x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/cloud_summary_section.test.tsx rename to x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/summary_section.test.tsx index ea9175542471c..df54ac1e6889c 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/cloud_summary_section.test.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/summary_section.test.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { render } from '@testing-library/react'; import { expectIdsInDoc } from '../../../test/utils'; import { DASHBOARD_COUNTER_CARDS } from '../test_subjects'; -import { CloudSummarySection } from './cloud_summary_section'; +import { SummarySection } from './summary_section'; import { mockDashboardData } from '../compliance_dashboard.test'; import { TestProvider } from '../../../test/test_provider'; import { screen } from '@testing-library/react'; @@ -18,7 +18,7 @@ describe('', () => { const renderCloudSummarySection = (alterMockData = {}) => { render( - + ); }; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/cloud_summary_section.tsx b/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/summary_section.tsx similarity index 73% rename from x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/cloud_summary_section.tsx rename to x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/summary_section.tsx index 5c7bc96f798ac..f7ef39cb00f97 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/cloud_summary_section.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/summary_section.tsx @@ -14,13 +14,21 @@ import { CspCounterCard, CspCounterCardProps } from '../../../components/csp_cou import { CompactFormattedNumber } from '../../../components/compact_formatted_number'; import { ChartPanel } from '../../../components/chart_panel'; import { CloudPostureScoreChart } from '../compliance_charts/cloud_posture_score_chart'; -import type { ComplianceDashboardData, Evaluation } from '../../../../common/types'; +import type { + ComplianceDashboardData, + Evaluation, + PosturePolicyTemplate, +} from '../../../../common/types'; import { RisksTable } from '../compliance_charts/risks_table'; import { useNavigateFindings, useNavigateFindingsByResource, } from '../../../common/hooks/use_navigate_findings'; -import { RULE_FAILED } from '../../../../common/constants'; +import { + CSPM_POLICY_TEMPLATE, + KSPM_POLICY_TEMPLATE, + RULE_FAILED, +} from '../../../../common/constants'; export const dashboardColumnsGrow: Record = { first: 3, @@ -28,37 +36,53 @@ export const dashboardColumnsGrow: Record = { third: 8, }; -export const CloudSummarySection = ({ +// TODO: CIS AWS - replace query to use policy_template field when available +export const getPolicyTemplateQuery = (policyTemplate: PosturePolicyTemplate) => { + if (policyTemplate === CSPM_POLICY_TEMPLATE) return { 'rule.benchmark.id': 'cis_aws' }; + if (policyTemplate === KSPM_POLICY_TEMPLATE) return { 'rule.benchmark.id': 'cis_k8s' }; + return {}; +}; + +export const SummarySection = ({ + dashboardType, complianceData, }: { + dashboardType: PosturePolicyTemplate; complianceData: ComplianceDashboardData; }) => { const navToFindings = useNavigateFindings(); const navToFindingsByResource = useNavigateFindingsByResource(); const handleEvalCounterClick = (evaluation: Evaluation) => { - navToFindings({ 'result.evaluation': evaluation }); + navToFindings({ 'result.evaluation': evaluation, ...getPolicyTemplateQuery(dashboardType) }); }; const handleCellClick = (ruleSection: string) => { navToFindings({ 'rule.section': ruleSection, 'result.evaluation': RULE_FAILED, + ...getPolicyTemplateQuery(dashboardType), }); }; const handleViewAllClick = () => { - navToFindings({ 'result.evaluation': RULE_FAILED }); + navToFindings({ 'result.evaluation': RULE_FAILED, ...getPolicyTemplateQuery(dashboardType) }); }; const counters: CspCounterCardProps[] = useMemo( () => [ { id: DASHBOARD_COUNTER_CARDS.CLUSTERS_EVALUATED, - description: i18n.translate( - 'xpack.csp.dashboard.summarySection.counterCard.clustersEvaluatedDescription', - { defaultMessage: 'Clusters Evaluated' } - ), + description: + dashboardType === KSPM_POLICY_TEMPLATE + ? i18n.translate( + 'xpack.csp.dashboard.summarySection.counterCard.clustersEvaluatedDescription', + { defaultMessage: 'Clusters Evaluated' } + ) + : i18n.translate( + 'xpack.csp.dashboard.summarySection.counterCard.accountsEvaluatedDescription', + { defaultMessage: 'Accounts Evaluated' } + ), title: , }, { @@ -69,7 +93,7 @@ export const CloudSummarySection = ({ ), title: , onClick: () => { - navToFindingsByResource(); + navToFindingsByResource(getPolicyTemplateQuery(dashboardType)); }, }, { @@ -81,7 +105,10 @@ export const CloudSummarySection = ({ title: , titleColor: complianceData.stats.totalFailed > 0 ? statusColors.failed : 'text', onClick: () => { - navToFindings({ 'result.evaluation': RULE_FAILED }); + navToFindings({ + 'result.evaluation': RULE_FAILED, + ...getPolicyTemplateQuery(dashboardType), + }); }, }, ], @@ -89,6 +116,7 @@ export const CloudSummarySection = ({ complianceData.clusters.length, complianceData.stats.resourcesEvaluated, complianceData.stats.totalFailed, + dashboardType, navToFindings, navToFindingsByResource, ] diff --git a/x-pack/plugins/cloud_security_posture/server/lib/fleet_util.ts b/x-pack/plugins/cloud_security_posture/server/lib/fleet_util.ts index ada8548240ae9..0588a58b426d0 100644 --- a/x-pack/plugins/cloud_security_posture/server/lib/fleet_util.ts +++ b/x-pack/plugins/cloud_security_posture/server/lib/fleet_util.ts @@ -50,11 +50,11 @@ export const getAgentStatusesByAgentPolicies = async ( const internalAgentService = agentService.asInternalUser; const result: AgentStatusByAgentPolicyMap = {}; - for (const agentPolicy of agentPolicies) { - result[agentPolicy.id] = await internalAgentService.getAgentStatusForAgentPolicy( - agentPolicy.id - ); - } + // for (const agentPolicy of agentPolicies) { + // result[agentPolicy.id] = await internalAgentService.getAgentStatusForAgentPolicy( + // agentPolicy.id + // ); + // } return result; }; From bde3ee940da0a3c659ba2a9b9b4525fb1e0aa169 Mon Sep 17 00:00:00 2001 From: Yarden Shalom Date: Sun, 15 Jan 2023 14:00:13 +0200 Subject: [PATCH 2/5] comment --- .../cloud_security_posture/server/lib/fleet_util.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/cloud_security_posture/server/lib/fleet_util.ts b/x-pack/plugins/cloud_security_posture/server/lib/fleet_util.ts index 0588a58b426d0..ada8548240ae9 100644 --- a/x-pack/plugins/cloud_security_posture/server/lib/fleet_util.ts +++ b/x-pack/plugins/cloud_security_posture/server/lib/fleet_util.ts @@ -50,11 +50,11 @@ export const getAgentStatusesByAgentPolicies = async ( const internalAgentService = agentService.asInternalUser; const result: AgentStatusByAgentPolicyMap = {}; - // for (const agentPolicy of agentPolicies) { - // result[agentPolicy.id] = await internalAgentService.getAgentStatusForAgentPolicy( - // agentPolicy.id - // ); - // } + for (const agentPolicy of agentPolicies) { + result[agentPolicy.id] = await internalAgentService.getAgentStatusForAgentPolicy( + agentPolicy.id + ); + } return result; }; From 0f4eeb945939a17653bfb042511cc8e52825905b Mon Sep 17 00:00:00 2001 From: Yarden Shalom Date: Sun, 15 Jan 2023 14:02:10 +0200 Subject: [PATCH 3/5] i18n --- x-pack/plugins/translations/translations/fr-FR.json | 3 --- x-pack/plugins/translations/translations/ja-JP.json | 3 --- x-pack/plugins/translations/translations/zh-CN.json | 3 --- 3 files changed, 9 deletions(-) diff --git a/x-pack/plugins/translations/translations/fr-FR.json b/x-pack/plugins/translations/translations/fr-FR.json index 867cb5e8173da..b9e65ed7a3478 100644 --- a/x-pack/plugins/translations/translations/fr-FR.json +++ b/x-pack/plugins/translations/translations/fr-FR.json @@ -10191,9 +10191,6 @@ "xpack.csp.dashboard.benchmarkSection.clusterTitleTooltip.clusterPrefixTitle": "Afficher tous les résultats pour ", "xpack.csp.dashboard.benchmarkSection.defaultClusterTitle": "ID cluster", "xpack.csp.dashboard.benchmarkSection.manageRulesButton": "Gérer les règles", - "xpack.csp.dashboard.cloudBenchmarkSection.columnsHeader.clusterNameTitle": "Nom du cluster", - "xpack.csp.dashboard.cloudBenchmarkSection.columnsHeader.complianceByCisSectionTitle": "Conformité par section CIS", - "xpack.csp.dashboard.cloudBenchmarkSection.columnsHeader.complianceScoreTitle": "Score de conformité", "xpack.csp.dashboard.cspPageTemplate.pageTitle": "Niveau du cloud", "xpack.csp.dashboard.risksTable.cisSectionColumnLabel": "Section CIS", "xpack.csp.dashboard.risksTable.clusterCardViewAllButtonTitle": "Afficher tous les échecs des résultats pour ce cluster", diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index b8e2a0bfefff6..2b4749b32f295 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -10180,9 +10180,6 @@ "xpack.csp.dashboard.benchmarkSection.clusterTitleTooltip.clusterPrefixTitle": "すべての調査結果を表示 ", "xpack.csp.dashboard.benchmarkSection.defaultClusterTitle": "クラスターID", "xpack.csp.dashboard.benchmarkSection.manageRulesButton": "ルールの管理", - "xpack.csp.dashboard.cloudBenchmarkSection.columnsHeader.clusterNameTitle": "クラスター名", - "xpack.csp.dashboard.cloudBenchmarkSection.columnsHeader.complianceByCisSectionTitle": "CISセクション別のコンプライアンス", - "xpack.csp.dashboard.cloudBenchmarkSection.columnsHeader.complianceScoreTitle": "コンプライアンススコア", "xpack.csp.dashboard.cspPageTemplate.pageTitle": "クラウド態勢", "xpack.csp.dashboard.risksTable.cisSectionColumnLabel": "CISセクション", "xpack.csp.dashboard.risksTable.clusterCardViewAllButtonTitle": "このクラスターの失敗した調査結果をすべて表示", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index ea18240f0c2f8..3c5fecd339f7c 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -10195,9 +10195,6 @@ "xpack.csp.dashboard.benchmarkSection.clusterTitleTooltip.clusterPrefixTitle": "显示以下所有结果 ", "xpack.csp.dashboard.benchmarkSection.defaultClusterTitle": "集群 ID", "xpack.csp.dashboard.benchmarkSection.manageRulesButton": "管理规则", - "xpack.csp.dashboard.cloudBenchmarkSection.columnsHeader.clusterNameTitle": "集群名称", - "xpack.csp.dashboard.cloudBenchmarkSection.columnsHeader.complianceByCisSectionTitle": "合规性(按 CIS 部分)", - "xpack.csp.dashboard.cloudBenchmarkSection.columnsHeader.complianceScoreTitle": "合规性分数", "xpack.csp.dashboard.cspPageTemplate.pageTitle": "云态势", "xpack.csp.dashboard.risksTable.cisSectionColumnLabel": "CIS 部分", "xpack.csp.dashboard.risksTable.clusterCardViewAllButtonTitle": "查看此集群的所有失败结果", From 47eefad88a1d3f7ac9dcf6312ba2030da7de29ec Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Sun, 15 Jan 2023 12:08:19 +0000 Subject: [PATCH 4/5] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- .../security_solution/public/management/cypress/tsconfig.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json b/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json index af09fee04643f..a99e4af76fe2e 100644 --- a/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json +++ b/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json @@ -22,6 +22,8 @@ "path": "../../../tsconfig.json", "force": true }, - "@kbn/security-plugin" + "@kbn/security-plugin", + "@kbn/securitysolution-list-constants", + "@kbn/fleet-plugin" ] } From ba6b25ef15bcf7450392077ee9061514472fdf2d Mon Sep 17 00:00:00 2001 From: Yarden Shalom Date: Sun, 15 Jan 2023 14:39:02 +0200 Subject: [PATCH 5/5] fix lint --- .../dashboard_sections/summary_section.test.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/summary_section.test.tsx b/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/summary_section.test.tsx index df54ac1e6889c..09de7596f3792 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/summary_section.test.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/dashboard_sections/summary_section.test.tsx @@ -13,12 +13,16 @@ import { SummarySection } from './summary_section'; import { mockDashboardData } from '../compliance_dashboard.test'; import { TestProvider } from '../../../test/test_provider'; import { screen } from '@testing-library/react'; +import { KSPM_POLICY_TEMPLATE } from '../../../../common/constants'; describe('', () => { const renderCloudSummarySection = (alterMockData = {}) => { render( - + ); };