Skip to content

Commit

Permalink
[Cloud Security] Temporarily disabled rule creation for 3P findings (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanSh authored Oct 15, 2024
1 parent b93d3c2 commit 3034dc8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { METRIC_TYPE } from '@kbn/analytics';
import { useHistory } from 'react-router-dom';
import useSessionStorage from 'react-use/lib/useSessionStorage';
import { useQueryClient } from '@tanstack/react-query';
import { i18n as kbnI18n } from '@kbn/i18n';
import { useFetchDetectionRulesAlertsStatus } from '../common/api/use_fetch_detection_rules_alerts_status';
import { useFetchDetectionRulesByTags } from '../common/api/use_fetch_detection_rules_by_tags';
import { RuleResponse } from '../common/types';
Expand Down Expand Up @@ -67,15 +68,30 @@ export const DetectionRuleCounter = ({ tags, createRuleFn }: DetectionRuleCounte
}, [history]);

const createDetectionRuleOnClick = useCallback(async () => {
uiMetricService.trackUiMetric(METRIC_TYPE.CLICK, CREATE_DETECTION_RULE_FROM_FLYOUT);
const startServices = { analytics, notifications, i18n, theme };
setIsCreateRuleLoading(true);
const ruleResponse = await createRuleFn(http);
setIsCreateRuleLoading(false);
showCreateDetectionRuleSuccessToast(startServices, http, ruleResponse);
// Triggering a refetch of rules and alerts to update the UI
queryClient.invalidateQueries([DETECTION_ENGINE_RULES_KEY]);
queryClient.invalidateQueries([DETECTION_ENGINE_ALERTS_KEY]);

try {
setIsCreateRuleLoading(true);
uiMetricService.trackUiMetric(METRIC_TYPE.CLICK, CREATE_DETECTION_RULE_FROM_FLYOUT);

const ruleResponse = await createRuleFn(http);

setIsCreateRuleLoading(false);
showCreateDetectionRuleSuccessToast(startServices, http, ruleResponse);

// Triggering a refetch of rules and alerts to update the UI
queryClient.invalidateQueries([DETECTION_ENGINE_RULES_KEY]);
queryClient.invalidateQueries([DETECTION_ENGINE_ALERTS_KEY]);
} catch (e) {
setIsCreateRuleLoading(false);

notifications.toasts.addWarning({
title: kbnI18n.translate('xpack.csp.detectionRuleCounter.alerts.createRuleErrorTitle', {
defaultMessage: 'Coming Soon',
}),
text: e.message,
});
}
}, [createRuleFn, http, analytics, notifications, i18n, theme, queryClient]);

if (alertsIsError) return <>{'-'}</>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import { HttpSetup } from '@kbn/core/public';
import { LATEST_FINDINGS_RETENTION_POLICY } from '@kbn/cloud-security-posture-common';
import type { CspBenchmarkRule } from '@kbn/cloud-security-posture-common/schema/rules/latest';
import { i18n } from '@kbn/i18n';
import { FINDINGS_INDEX_PATTERN } from '../../../../common/constants';

import { createDetectionRule } from '../../../common/api/create_detection_rule';
import { generateBenchmarkRuleTags } from '../../../../common/utils/detection_rules';

Expand Down Expand Up @@ -63,6 +63,14 @@ export const createDetectionRuleFromBenchmarkRule = async (
http: HttpSetup,
benchmarkRule: CspBenchmarkRule['metadata']
) => {
if (!benchmarkRule.benchmark?.posture_type) {
throw new Error(
i18n.translate('xpack.csp.createDetectionRuleFromBenchmarkRule.createRuleErrorMessage', {
defaultMessage: 'Rule creation is currently only available for Elastic findings',
})
);
}

return await createDetectionRule({
http,
rule: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jest.mock('../../../common/utils/is_native_csp_finding', () => ({
isNativeCspFinding: jest.fn(),
}));

describe('CreateDetectionRuleFromVulnerability', () => {
describe.skip('CreateDetectionRuleFromVulnerability', () => {
describe('getVulnerabilityTags', () => {
it('should return tags with CSP_RULE_TAG and vulnerability id', () => {
const mockVulnerability = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
VULNERABILITIES_SEVERITY,
} from '@kbn/cloud-security-posture-common';
import type { Vulnerability } from '@kbn/cloud-security-posture-common/schema/vulnerabilities/latest';
import { CSP_VULN_DATASET } from '../../../common/utils/get_vendor_name';
import { isNativeCspFinding } from '../../../common/utils/is_native_csp_finding';
import { VULNERABILITIES_INDEX_PATTERN } from '../../../../common/constants';
import { createDetectionRule } from '../../../common/api/create_detection_rule';
Expand Down Expand Up @@ -87,6 +88,15 @@ export const createDetectionRuleFromVulnerabilityFinding = async (
http: HttpSetup,
vulnerabilityFinding: CspVulnerabilityFinding
) => {
if (vulnerabilityFinding.data_stream?.dataset !== CSP_VULN_DATASET) {
throw new Error(
i18n.translate(
'xpack.csp.createDetectionRuleFromVulnerabilityFinding.createRuleErrorMessage',
{ defaultMessage: 'Rule creation is currently only available for Elastic findings' }
)
);
}

const tags = getVulnerabilityTags(vulnerabilityFinding);
const vulnerability = vulnerabilityFinding.vulnerability;

Expand Down

0 comments on commit 3034dc8

Please sign in to comment.