Skip to content

Commit

Permalink
[Cloud Security] handle both rule.references and rule.reference in mi…
Browse files Browse the repository at this point in the history
…sconfiguraiton flyout (#195932)

## Summary

Fixes:
- elastic/security-team#10793

(cherry picked from commit cc46549)
  • Loading branch information
maxcold committed Oct 14, 2024
1 parent 93e770c commit e2d2cbf
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? (
<RuleNameLink ruleFlyoutLink={ruleFlyoutLink} ruleName={rule.name} />
) : (
EMPTY_VALUE
),
},
{
title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.descriptionTitle', {
defaultMessage: 'Description',
}),
description: rule?.description ? (
<CspFlyoutMarkdown>{rule.description}</CspFlyoutMarkdown>
) : (
EMPTY_VALUE
),
},
{
title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.AlertsTitle', {
defaultMessage: 'Alerts',
}),
description:
ruleState === 'muted' ? (
<FormattedMessage
id="xpack.csp.findings.findingsFlyout.ruleTab.disabledRuleText"
defaultMessage="Disabled"
/>
) : rule?.benchmark?.name ? (
<RulesDetectionRuleCounter benchmarkRule={rule} />
) => {
const reference = getReferenceFromRule(rule);

return [
{
title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.nameTitle', {
defaultMessage: 'Name',
}),
description: rule?.name ? (
<RuleNameLink ruleFlyoutLink={ruleFlyoutLink} ruleName={rule.name} />
) : (
EMPTY_VALUE
),
},
{
title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.descriptionTitle', {
defaultMessage: 'Description',
}),
description: rule?.description ? (
<CspFlyoutMarkdown>{rule.description}</CspFlyoutMarkdown>
) : (
EMPTY_VALUE
),
},
{
title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.tagsTitle', {
defaultMessage: 'Tags',
}),
description: rule?.tags?.length ? (
<>
{rule.tags.map((tag) => (
<EuiBadge key={tag}>{tag}</EuiBadge>
))}
</>
) : (
EMPTY_VALUE
),
},
{
title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.frameworkSourcesTitle', {
defaultMessage: 'Framework Sources',
}),
description:
rule?.benchmark?.id && rule?.benchmark?.name ? (
<BenchmarkIcons benchmarkId={rule.benchmark.id} benchmarkName={rule.benchmark.name} />
},
{
title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.AlertsTitle', {
defaultMessage: 'Alerts',
}),
description:
ruleState === 'muted' ? (
<FormattedMessage
id="xpack.csp.findings.findingsFlyout.ruleTab.disabledRuleText"
defaultMessage="Disabled"
/>
) : rule?.benchmark?.name ? (
<RulesDetectionRuleCounter benchmarkRule={rule} />
) : (
EMPTY_VALUE
),
},
{
title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.tagsTitle', {
defaultMessage: 'Tags',
}),
description: rule?.tags?.length ? (
<>
{rule.tags.map((tag) => (
<EuiBadge key={tag}>{tag}</EuiBadge>
))}
</>
) : (
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 ? (
<CspFlyoutMarkdown>{rule.profile_applicability}</CspFlyoutMarkdown>
) : (
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 ? <CspFlyoutMarkdown>{rule.audit}</CspFlyoutMarkdown> : EMPTY_VALUE,
},
{
title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.referencesTitle', {
defaultMessage: 'References',
}),
description: rule?.references ? (
<CspFlyoutMarkdown>{rule.references}</CspFlyoutMarkdown>
) : (
EMPTY_VALUE
),
},
];
},
{
title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.frameworkSourcesTitle', {
defaultMessage: 'Framework Sources',
}),
description:
rule?.benchmark?.id && rule?.benchmark?.name ? (
<BenchmarkIcons benchmarkId={rule.benchmark.id} benchmarkName={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 ? (
<CspFlyoutMarkdown>{rule.profile_applicability}</CspFlyoutMarkdown>
) : (
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 ? <CspFlyoutMarkdown>{rule.audit}</CspFlyoutMarkdown> : EMPTY_VALUE,
},
{
title: i18n.translate('xpack.csp.findings.findingsFlyout.ruleTab.referencesTitle', {
defaultMessage: 'References',
}),
description: reference ? <CspFlyoutMarkdown>{reference}</CspFlyoutMarkdown> : EMPTY_VALUE,
},
];
};

export const RuleTab = ({
data,
Expand Down

0 comments on commit e2d2cbf

Please sign in to comment.