Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Cloud Posture] CIS AWS - Multi-dashboards links and labels #148941

Merged
merged 7 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -164,9 +166,9 @@ const IntegrationPostureDashboard = ({
// there are findings, displays dashboard even if integration is not installed
return (
<>
<CloudSummarySection complianceData={complianceData} />
<SummarySection complianceData={complianceData} dashboardType={dashboardType} />
<EuiSpacer />
<CloudBenchmarksSection complianceData={complianceData} />
<BenchmarksSection complianceData={complianceData} dashboardType={dashboardType} />
<EuiSpacer />
</>
);
Expand Down Expand Up @@ -232,6 +234,7 @@ export const ComplianceDashboard = () => {
<CloudPosturePage query={getCspmDashboardData}>
<div data-test-subj={CLOUD_DASHBOARD_CONTAINER}>
<IntegrationPostureDashboard
dashboardType={CSPM_POLICY_TEMPLATE}
complianceData={getCspmDashboardData.data}
notInstalledConfig={getNotInstalledConfig(
CSPM_POLICY_TEMPLATE,
Expand All @@ -255,6 +258,7 @@ export const ComplianceDashboard = () => {
<CloudPosturePage query={getKspmDashboardData}>
<div data-test-subj={KUBERNETES_DASHBOARD_CONTAINER}>
<IntegrationPostureDashboard
dashboardType={KSPM_POLICY_TEMPLATE}
complianceData={getKspmDashboardData.data}
notInstalledConfig={getNotInstalledConfig(
KSPM_POLICY_TEMPLATE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,54 @@
*/

import React from 'react';
import { EuiFlexItem, EuiFlexGroup, useEuiTheme, EuiTitle } from '@elastic/eui';
import { EuiFlexGroup, EuiFlexItem, EuiTitle, useEuiTheme } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
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 { RULE_FAILED } from '../../../../common/constants';
import { KSPM_POLICY_TEMPLATE, RULE_FAILED } from '../../../../common/constants';
import { useNavigateFindings } from '../../../common/hooks/use_navigate_findings';
import { ClusterDetailsBox } from './cluster_details_box';
import { dashboardColumnsGrow } from './cloud_summary_section';
import { dashboardColumnsGrow, getPolicyTemplateQuery } from './summary_section';

export const CloudBenchmarksSection = ({
export const BenchmarksSection = ({
complianceData,
dashboardType,
}: {
complianceData: ComplianceDashboardData;
dashboardType: PosturePolicyTemplate;
}) => {
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) => {
navToFindings({
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,
Copy link
Contributor

Choose a reason for hiding this comment

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

is cluster_id relevant for CSPM? @CohenIdo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there will be cluster ids and account ids in cspm, but until we actually know whats going on here, we rely on cluster id for now

'result.evaluation': RULE_FAILED,
...getPolicyTemplateQuery(dashboardType),
});
};

return (
Expand All @@ -55,10 +70,17 @@ export const CloudBenchmarksSection = ({
<EuiFlexItem grow={dashboardColumnsGrow.first}>
<EuiTitle size="xxs" css={{ fontWeight: euiTheme.font.weight.semiBold }}>
<h5>
<FormattedMessage
id="xpack.csp.dashboard.cloudBenchmarkSection.columnsHeader.clusterNameTitle"
defaultMessage="Cluster Name"
/>
{dashboardType === KSPM_POLICY_TEMPLATE ? (
<FormattedMessage
id="xpack.csp.dashboard.benchmarkSection.columnsHeader.clusterNameTitle"
defaultMessage="Cluster Name"
/>
) : (
<FormattedMessage
id="xpack.csp.dashboard.benchmarkSection.columnsHeader.accountNameTitle"
defaultMessage="Account Name"
/>
)}
</h5>
</EuiTitle>
</EuiFlexItem>
Expand All @@ -69,7 +91,7 @@ export const CloudBenchmarksSection = ({
>
<h5>
<FormattedMessage
id="xpack.csp.dashboard.cloudBenchmarkSection.columnsHeader.complianceScoreTitle"
id="xpack.csp.dashboard.benchmarkSection.columnsHeader.complianceScoreTitle"
defaultMessage="Compliance Score"
/>
</h5>
Expand All @@ -82,7 +104,7 @@ export const CloudBenchmarksSection = ({
>
<h5>
<FormattedMessage
id="xpack.csp.dashboard.cloudBenchmarkSection.columnsHeader.complianceByCisSectionTitle"
id="xpack.csp.dashboard.benchmarkSection.columnsHeader.complianceByCisSectionTitle"
defaultMessage="Compliance by CIS Section"
/>
</h5>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -18,7 +18,7 @@ describe('<CloudSummarySection />', () => {
const renderCloudSummarySection = (alterMockData = {}) => {
render(
<TestProvider>
<CloudSummarySection complianceData={{ ...mockDashboardData, ...alterMockData }} />
<SummarySection complianceData={{ ...mockDashboardData, ...alterMockData }} />
</TestProvider>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,75 @@ 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<string, EuiFlexItemProps['grow']> = {
first: 3,
second: 8,
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 {};
};
orouz marked this conversation as resolved.
Show resolved Hide resolved

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: <CompactFormattedNumber number={complianceData.clusters.length} />,
},
{
Expand All @@ -69,7 +93,7 @@ export const CloudSummarySection = ({
),
title: <CompactFormattedNumber number={complianceData.stats.resourcesEvaluated || 0} />,
onClick: () => {
navToFindingsByResource();
navToFindingsByResource(getPolicyTemplateQuery(dashboardType));
},
},
{
Expand All @@ -81,14 +105,18 @@ export const CloudSummarySection = ({
title: <CompactFormattedNumber number={complianceData.stats.totalFailed} />,
titleColor: complianceData.stats.totalFailed > 0 ? statusColors.failed : 'text',
onClick: () => {
navToFindings({ 'result.evaluation': RULE_FAILED });
navToFindings({
'result.evaluation': RULE_FAILED,
...getPolicyTemplateQuery(dashboardType),
});
},
},
],
[
complianceData.clusters.length,
complianceData.stats.resourcesEvaluated,
complianceData.stats.totalFailed,
dashboardType,
navToFindings,
navToFindingsByResource,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"path": "../../../tsconfig.json",
"force": true
},
"@kbn/security-plugin"
"@kbn/security-plugin",
"@kbn/securitysolution-list-constants",
"@kbn/fleet-plugin"
]
}
3 changes: 0 additions & 3 deletions x-pack/plugins/translations/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "このクラスターの失敗した調査結果をすべて表示",
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "查看此集群的所有失败结果",
Expand Down