Skip to content

Commit

Permalink
[Cloud Security] [Alerts] Fix Misconfigurations Flyout navigation to …
Browse files Browse the repository at this point in the history
…detection rule (#164654)
  • Loading branch information
opauloh authored Aug 25, 2023
1 parent 16f7189 commit edca162
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ import type { HttpSetup } from '@kbn/core/public';
import React from 'react';
import { CspFinding } from '../../../../common/schemas/csp_finding';
import { DetectionRuleCounter } from '../../../components/detection_rule_counter';
import { createDetectionRuleFromFinding } from '../utils/create_detection_rule_from_finding';
import {
createDetectionRuleFromFinding,
getFindingsDetectionRuleSearchTags,
} from '../utils/create_detection_rule_from_finding';

export const FindingsDetectionRuleCounter = ({ finding }: { finding: CspFinding }) => {
const createMisconfigurationRuleFn = async (http: HttpSetup) =>
await createDetectionRuleFromFinding(http, finding);

return (
<DetectionRuleCounter tags={finding.rule.tags} createRuleFn={createMisconfigurationRuleFn} />
<DetectionRuleCounter
tags={getFindingsDetectionRuleSearchTags(finding)}
createRuleFn={createMisconfigurationRuleFn}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,23 @@ const CSP_RULE_TAG_DATA_SOURCE_PREFIX = 'Data Source: ';

const STATIC_RULE_TAGS = [CSP_RULE_TAG, CSP_RULE_TAG_USE_CASE];

/*
* Returns an array of CspFinding tags that can be used to search and filter a detection rule
*/
export const getFindingsDetectionRuleSearchTags = ({ rule }: CspFinding) => {
// ex: cis_gcp to ['CIS', 'GCP']
const benchmarkIdTags = rule.benchmark.id.split('_').map((tag) => tag.toUpperCase());
// ex: 'CIS GCP 1.1'
const benchmarkRuleNumberTag = `${rule.benchmark.id.replace('_', ' ').toUpperCase()} ${
rule.benchmark.rule_number
}`;

return benchmarkIdTags.concat([benchmarkRuleNumberTag]);
};

const generateFindingsTags = (finding: CspFinding) => {
return [STATIC_RULE_TAGS]
.concat(finding.rule.tags)
.concat(getFindingsDetectionRuleSearchTags(finding))
.concat(
finding.rule.benchmark.posture_type
? [
Expand Down

0 comments on commit edca162

Please sign in to comment.