From e2d2cbfd3232c72853a074c52b336a5ebc5634d3 Mon Sep 17 00:00:00 2001 From: Maxim Kholod Date: Mon, 14 Oct 2024 13:31:59 +0200 Subject: [PATCH] [Cloud Security] handle both rule.references and rule.reference in misconfiguraiton flyout (#195932) ## Summary Fixes: - https://github.com/elastic/security-team/issues/10793 (cherry picked from commit cc46549c2f293bed7d24d8b1abf02c4d65db7bcb) --- .../schema/rules/v3.ts | 1 + .../findings_flyout/rule_tab.tsx | 194 +++++++++--------- 2 files changed, 100 insertions(+), 95 deletions(-) diff --git a/x-pack/packages/kbn-cloud-security-posture-common/schema/rules/v3.ts b/x-pack/packages/kbn-cloud-security-posture-common/schema/rules/v3.ts index a00bf1a8077e6..353fe093d64a1 100644 --- a/x-pack/packages/kbn-cloud-security-posture-common/schema/rules/v3.ts +++ b/x-pack/packages/kbn-cloud-security-posture-common/schema/rules/v3.ts @@ -37,6 +37,7 @@ export const cspBenchmarkRuleMetadataSchema = schema.object({ profile_applicability: schema.string(), rationale: schema.string(), references: schema.maybe(schema.string()), + reference: schema.maybe(schema.string()), rego_rule_id: schema.string(), remediation: schema.string(), section: schema.string(), 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 2dcca4932935c..a64ac099df14a 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 @@ -13,111 +13,115 @@ import type { CspFinding } from '@kbn/cloud-security-posture-common'; import { RulesDetectionRuleCounter } from '../../rules/rules_detection_rule_counter'; import { BenchmarkIcons, CspFlyoutMarkdown, EMPTY_VALUE, RuleNameLink } from './findings_flyout'; +const getReferenceFromRule = (rule?: CspFinding['rule']) => { + return rule?.reference || rule?.references; +}; + export const getRuleList = ( rule?: CspFinding['rule'], ruleState = 'unmuted', ruleFlyoutLink?: string -) => [ - { - title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.nameTitle', { - defaultMessage: 'Name', - }), - description: rule?.name ? ( - - ) : ( - EMPTY_VALUE - ), - }, - { - title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.descriptionTitle', { - defaultMessage: 'Description', - }), - description: rule?.description ? ( - {rule.description} - ) : ( - EMPTY_VALUE - ), - }, - { - title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.AlertsTitle', { - defaultMessage: 'Alerts', - }), - description: - ruleState === 'muted' ? ( - - ) : rule?.benchmark?.name ? ( - +) => { + const reference = getReferenceFromRule(rule); + + return [ + { + title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.nameTitle', { + defaultMessage: 'Name', + }), + description: rule?.name ? ( + + ) : ( + EMPTY_VALUE + ), + }, + { + title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.descriptionTitle', { + defaultMessage: 'Description', + }), + description: rule?.description ? ( + {rule.description} ) : ( EMPTY_VALUE ), - }, - { - title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.tagsTitle', { - defaultMessage: 'Tags', - }), - description: rule?.tags?.length ? ( - <> - {rule.tags.map((tag) => ( - {tag} - ))} - - ) : ( - EMPTY_VALUE - ), - }, - { - title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.frameworkSourcesTitle', { - defaultMessage: 'Framework Sources', - }), - description: - rule?.benchmark?.id && rule?.benchmark?.name ? ( - + }, + { + title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.AlertsTitle', { + defaultMessage: 'Alerts', + }), + description: + ruleState === 'muted' ? ( + + ) : rule?.benchmark?.name ? ( + + ) : ( + EMPTY_VALUE + ), + }, + { + title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.tagsTitle', { + defaultMessage: 'Tags', + }), + description: rule?.tags?.length ? ( + <> + {rule.tags.map((tag) => ( + {tag} + ))} + ) : ( EMPTY_VALUE ), - }, - { - title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.cisSectionTitle', { - defaultMessage: 'Framework Section', - }), - description: rule?.section || EMPTY_VALUE, - }, - { - title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.profileApplicabilityTitle', { - defaultMessage: 'Profile Applicability', - }), - description: rule?.profile_applicability ? ( - {rule.profile_applicability} - ) : ( - EMPTY_VALUE - ), - }, - { - title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.benchmarkTitle', { - defaultMessage: 'Benchmark', - }), - description: rule?.benchmark?.name || EMPTY_VALUE, - }, - { - title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.auditTitle', { - defaultMessage: 'Audit', - }), - description: rule?.audit ? {rule.audit} : EMPTY_VALUE, - }, - { - title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.referencesTitle', { - defaultMessage: 'References', - }), - description: rule?.references ? ( - {rule.references} - ) : ( - EMPTY_VALUE - ), - }, -]; + }, + { + title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.frameworkSourcesTitle', { + defaultMessage: 'Framework Sources', + }), + description: + rule?.benchmark?.id && rule?.benchmark?.name ? ( + + ) : ( + EMPTY_VALUE + ), + }, + { + title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.cisSectionTitle', { + defaultMessage: 'Framework Section', + }), + description: rule?.section || EMPTY_VALUE, + }, + { + title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.profileApplicabilityTitle', { + defaultMessage: 'Profile Applicability', + }), + description: rule?.profile_applicability ? ( + {rule.profile_applicability} + ) : ( + EMPTY_VALUE + ), + }, + { + title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.benchmarkTitle', { + defaultMessage: 'Benchmark', + }), + description: rule?.benchmark?.name || EMPTY_VALUE, + }, + { + title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.auditTitle', { + defaultMessage: 'Audit', + }), + description: rule?.audit ? {rule.audit} : EMPTY_VALUE, + }, + { + title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.referencesTitle', { + defaultMessage: 'References', + }), + description: reference ? {reference} : EMPTY_VALUE, + }, + ]; +}; export const RuleTab = ({ data,