Skip to content

Commit

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

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Cloud Security] handle both rule.references and rule.reference in
misconfiguraiton flyout
(#195932)](#195932)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Maxim
Kholod","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-14T11:31:59Z","message":"[Cloud
Security] handle both rule.references and rule.reference in
misconfiguraiton flyout (#195932)\n\n## Summary\r\n\r\nFixes:\r\n-
https://github.com/elastic/security-team/issues/10793","sha":"cc46549c2f293bed7d24d8b1abf02c4d65db7bcb","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Cloud
Security","backport:prev-minor","Feature:Cloud-Security","v8.16.0"],"title":"[Cloud
Security] handle both rule.references and rule.reference in
misconfiguraiton
flyout","number":195932,"url":"https://github.com/elastic/kibana/pull/195932","mergeCommit":{"message":"[Cloud
Security] handle both rule.references and rule.reference in
misconfiguraiton flyout (#195932)\n\n## Summary\r\n\r\nFixes:\r\n-
https://github.com/elastic/security-team/issues/10793","sha":"cc46549c2f293bed7d24d8b1abf02c4d65db7bcb"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195932","number":195932,"mergeCommit":{"message":"[Cloud
Security] handle both rule.references and rule.reference in
misconfiguraiton flyout (#195932)\n\n## Summary\r\n\r\nFixes:\r\n-
https://github.com/elastic/security-team/issues/10793","sha":"cc46549c2f293bed7d24d8b1abf02c4d65db7bcb"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Maxim Kholod <[email protected]>
  • Loading branch information
kibanamachine and maxcold authored Oct 14, 2024
1 parent 3bc6814 commit 98c93aa
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 98c93aa

Please sign in to comment.