mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Cloud Security] Misconfiguration preview & Refactor CSP Plugin to include new package PHASE 3 (#191317)
The previous https://github.com/elastic/kibana/pull/190105 was way too big and made it hard to review without missing any bugs or potential bugs, Thus we decided we are going to make series of smaller PR to make things more manageable We will be splitting it into 4 PR Phase 1: Creating empty packages for csp and csp-common Phase 2: Move Types from CSP plugin to the Package + Deleting duplicates in the CSP plugin where possible Phase 3: Move Functions, Utils or Helpers, Hooks to Package Phase 4: Misconfiguration Preview feature (with Cypress test and other required test) This is **Phase 3** of the Process, This also includes moving rule versions type This PR is the continuation of this PR https://github.com/elastic/kibana/pull/190933 NOTE: Merge phase 2 first before this --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
6bb38c82db
commit
a78c69b273
89 changed files with 471 additions and 270 deletions
|
@ -16,7 +16,8 @@ export type {
|
|||
BaseCspSetupBothPolicy,
|
||||
BaseCspSetupStatus,
|
||||
CspSetupStatus,
|
||||
CspFinding,
|
||||
} from './types';
|
||||
} from './types/status';
|
||||
export type { CspFinding } from './types/findings';
|
||||
export type { BenchmarksCisId } from './types/benchmark';
|
||||
export * from './constants';
|
||||
export type { CspBenchmarkRuleMetadata, CspBenchmarkRulesStates } from './schema/rules';
|
||||
export { extractErrorMessage, buildMutedRulesFilter } from './utils/helpers';
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
preset: '@kbn/test',
|
||||
rootDir: '../../..',
|
||||
roots: ['<rootDir>/x-pack/packages/kbn-cloud-security-posture-common'],
|
||||
};
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
import { TypeOf, schema } from '@kbn/config-schema';
|
||||
import { CSPM_POLICY_TEMPLATE, KSPM_POLICY_TEMPLATE } from '../constants';
|
||||
|
||||
export type CspBenchmarkRuleMetadata = TypeOf<typeof cspBenchmarkRuleMetadataSchema>;
|
||||
|
||||
export const cspBenchmarkRuleMetadataSchema = schema.object({
|
||||
audit: schema.string(),
|
||||
benchmark: schema.object({
|
||||
name: schema.string(),
|
||||
posture_type: schema.maybe(
|
||||
schema.oneOf([schema.literal(CSPM_POLICY_TEMPLATE), schema.literal(KSPM_POLICY_TEMPLATE)])
|
||||
),
|
||||
id: schema.string(),
|
||||
version: schema.string(),
|
||||
rule_number: schema.maybe(schema.string()),
|
||||
}),
|
||||
default_value: schema.maybe(schema.string()),
|
||||
description: schema.string(),
|
||||
id: schema.string(),
|
||||
impact: schema.maybe(schema.string()),
|
||||
name: schema.string(),
|
||||
profile_applicability: schema.string(),
|
||||
rationale: schema.string(),
|
||||
references: schema.maybe(schema.string()),
|
||||
rego_rule_id: schema.string(),
|
||||
remediation: schema.string(),
|
||||
section: schema.string(),
|
||||
tags: schema.arrayOf(schema.string()),
|
||||
version: schema.string(),
|
||||
});
|
||||
|
||||
export const ruleStateAttributes = schema.object({
|
||||
muted: schema.boolean(),
|
||||
benchmark_id: schema.string(),
|
||||
benchmark_version: schema.string(),
|
||||
rule_number: schema.string(),
|
||||
rule_id: schema.string(),
|
||||
});
|
||||
|
||||
export const rulesStates = schema.recordOf(schema.string(), ruleStateAttributes);
|
||||
|
||||
export type CspBenchmarkRulesStates = TypeOf<typeof rulesStates>;
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
export * as rulesV1 from './v1';
|
||||
export * as rulesV2 from './v2';
|
||||
export * as rulesV3 from './v3';
|
||||
export * as rulesV4 from './v4';
|
||||
export * as rulesV5 from './v5';
|
|
@ -5,4 +5,4 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
export { ruleStateAttributes, cspBenchmarkRuleMetadataSchema, rulesStates } from './rules';
|
||||
export * from './v5';
|
|
@ -6,8 +6,7 @@
|
|||
*/
|
||||
|
||||
import { schema, TypeOf } from '@kbn/config-schema';
|
||||
|
||||
import { cspBenchmarkRuleMetadataSchema } from '@kbn/cloud-security-posture-common/schema';
|
||||
import { CSPM_POLICY_TEMPLATE, KSPM_POLICY_TEMPLATE } from '../../constants';
|
||||
|
||||
export const DEFAULT_BENCHMARK_RULES_PER_PAGE = 25;
|
||||
|
||||
|
@ -15,8 +14,36 @@ export const DEFAULT_BENCHMARK_RULES_PER_PAGE = 25;
|
|||
|
||||
export type FindCspBenchmarkRuleRequest = TypeOf<typeof findCspBenchmarkRuleRequestSchema>;
|
||||
|
||||
export type CspBenchmarkRuleMetadata = TypeOf<typeof cspBenchmarkRuleMetadataSchema>;
|
||||
|
||||
export type CspBenchmarkRule = TypeOf<typeof cspBenchmarkRuleSchema>;
|
||||
|
||||
export const cspBenchmarkRuleMetadataSchema = schema.object({
|
||||
audit: schema.string(),
|
||||
benchmark: schema.object({
|
||||
name: schema.string(),
|
||||
posture_type: schema.maybe(
|
||||
schema.oneOf([schema.literal(CSPM_POLICY_TEMPLATE), schema.literal(KSPM_POLICY_TEMPLATE)])
|
||||
),
|
||||
id: schema.string(),
|
||||
version: schema.string(),
|
||||
rule_number: schema.maybe(schema.string()),
|
||||
}),
|
||||
default_value: schema.maybe(schema.string()),
|
||||
description: schema.string(),
|
||||
id: schema.string(),
|
||||
impact: schema.maybe(schema.string()),
|
||||
name: schema.string(),
|
||||
profile_applicability: schema.string(),
|
||||
rationale: schema.string(),
|
||||
references: schema.maybe(schema.string()),
|
||||
rego_rule_id: schema.string(),
|
||||
remediation: schema.string(),
|
||||
section: schema.string(),
|
||||
tags: schema.arrayOf(schema.string()),
|
||||
version: schema.string(),
|
||||
});
|
||||
|
||||
export const cspBenchmarkRuleSchema = schema.object({
|
||||
metadata: cspBenchmarkRuleMetadataSchema,
|
||||
});
|
|
@ -6,11 +6,15 @@
|
|||
*/
|
||||
|
||||
import { schema, TypeOf } from '@kbn/config-schema';
|
||||
import type { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common';
|
||||
import { ruleStateAttributes, rulesStates } from '@kbn/cloud-security-posture-common/schema';
|
||||
import { BenchmarksCisId } from '../latest';
|
||||
import { BenchmarksCisId } from '../../types/benchmark';
|
||||
import { DEFAULT_BENCHMARK_RULES_PER_PAGE } from './v3';
|
||||
export type { cspBenchmarkRuleSchema, CspBenchmarkRule, FindCspBenchmarkRuleResponse } from './v3';
|
||||
export type {
|
||||
cspBenchmarkRuleMetadataSchema,
|
||||
CspBenchmarkRuleMetadata,
|
||||
cspBenchmarkRuleSchema,
|
||||
CspBenchmarkRule,
|
||||
FindCspBenchmarkRuleResponse,
|
||||
} from './v3';
|
||||
|
||||
export type FindCspBenchmarkRuleRequest = TypeOf<typeof findCspBenchmarkRuleRequestSchema>;
|
||||
|
||||
|
@ -22,6 +26,8 @@ export type CspBenchmarkRulesBulkActionRequestSchema = TypeOf<
|
|||
|
||||
export type RuleStateAttributes = TypeOf<typeof ruleStateAttributes>;
|
||||
|
||||
export type CspBenchmarkRulesStates = TypeOf<typeof rulesStates>;
|
||||
|
||||
export type CspSettings = TypeOf<typeof cspSettingsSchema>;
|
||||
|
||||
export const findCspBenchmarkRuleRequestSchema = schema.object({
|
||||
|
@ -137,6 +143,16 @@ export interface CspBenchmarkRulesBulkActionResponse {
|
|||
message: string;
|
||||
}
|
||||
|
||||
const ruleStateAttributes = schema.object({
|
||||
muted: schema.boolean(),
|
||||
benchmark_id: schema.string(),
|
||||
benchmark_version: schema.string(),
|
||||
rule_number: schema.string(),
|
||||
rule_id: schema.string(),
|
||||
});
|
||||
|
||||
const rulesStates = schema.recordOf(schema.string(), ruleStateAttributes);
|
||||
|
||||
export const cspSettingsSchema = schema.object({
|
||||
rules: rulesStates,
|
||||
});
|
|
@ -7,13 +7,20 @@
|
|||
import { schema, TypeOf } from '@kbn/config-schema';
|
||||
import { DEFAULT_BENCHMARK_RULES_PER_PAGE } from './v3';
|
||||
|
||||
export type { cspBenchmarkRuleSchema, CspBenchmarkRule, FindCspBenchmarkRuleResponse } from './v3';
|
||||
export type {
|
||||
cspBenchmarkRuleMetadataSchema,
|
||||
CspBenchmarkRuleMetadata,
|
||||
cspBenchmarkRuleSchema,
|
||||
CspBenchmarkRule,
|
||||
FindCspBenchmarkRuleResponse,
|
||||
} from './v3';
|
||||
export type {
|
||||
PageUrlParams,
|
||||
rulesToUpdate,
|
||||
CspBenchmarkRulesBulkActionRequestSchema,
|
||||
CspBenchmarkRulesBulkActionResponse,
|
||||
RuleStateAttributes,
|
||||
CspBenchmarkRulesStates,
|
||||
cspSettingsSchema,
|
||||
CspSettings,
|
||||
BulkActionBenchmarkRulesResponse,
|
|
@ -16,5 +16,7 @@
|
|||
],
|
||||
"kbn_references": [
|
||||
"@kbn/config-schema",
|
||||
"@kbn/data-views-plugin",
|
||||
"@kbn/i18n",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
export type BenchmarksCisId = 'cis_k8s' | 'cis_azure' | 'cis_aws' | 'cis_eks' | 'cis_gcp';
|
|
@ -1,3 +1,10 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
|
@ -5,45 +12,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
import type { EcsDataStream, EcsEvent } from '@elastic/ecs';
|
||||
import type { CspBenchmarkRuleMetadata } from './schema/rules';
|
||||
|
||||
export type CspStatusCode =
|
||||
| 'indexed' // latest findings index exists and has results
|
||||
| 'indexing' // index timeout was not surpassed since installation, assumes data is being indexed
|
||||
| 'unprivileged' // user lacks privileges for the latest findings index
|
||||
| 'index-timeout' // index timeout was surpassed since installation
|
||||
| 'not-deployed' // no healthy agents were deployed
|
||||
| 'not-installed' // number of installed csp integrations is 0;
|
||||
| 'waiting_for_results'; // have healthy agents but no findings at all, assumes data is being indexed for the 1st time
|
||||
|
||||
export type IndexStatus =
|
||||
| 'not-empty' // Index contains documents
|
||||
| 'empty' // Index doesn't contain documents (or doesn't exist)
|
||||
| 'unprivileged'; // User doesn't have access to query the index
|
||||
|
||||
export interface IndexDetails {
|
||||
index: string;
|
||||
status: IndexStatus;
|
||||
}
|
||||
|
||||
export interface BaseCspSetupBothPolicy {
|
||||
status: CspStatusCode;
|
||||
installedPackagePolicies: number;
|
||||
healthyAgents: number;
|
||||
}
|
||||
|
||||
export interface BaseCspSetupStatus {
|
||||
indicesDetails: IndexDetails[];
|
||||
latestPackageVersion: string;
|
||||
cspm: BaseCspSetupBothPolicy;
|
||||
kspm: BaseCspSetupBothPolicy;
|
||||
vuln_mgmt: BaseCspSetupBothPolicy;
|
||||
isPluginInitialized: boolean;
|
||||
installedPackageVersion?: string | undefined;
|
||||
hasMisconfigurationsFindings?: boolean;
|
||||
}
|
||||
|
||||
export type CspSetupStatus = BaseCspSetupStatus;
|
||||
import type { CspBenchmarkRuleMetadata } from '../schema/rules/latest';
|
||||
|
||||
export interface CspFinding {
|
||||
'@timestamp': string;
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
export type CspStatusCode =
|
||||
| 'indexed' // latest findings index exists and has results
|
||||
| 'indexing' // index timeout was not surpassed since installation, assumes data is being indexed
|
||||
| 'unprivileged' // user lacks privileges for the latest findings index
|
||||
| 'index-timeout' // index timeout was surpassed since installation
|
||||
| 'not-deployed' // no healthy agents were deployed
|
||||
| 'not-installed' // number of installed csp integrations is 0;
|
||||
| 'waiting_for_results'; // have healthy agents but no findings at all, assumes data is being indexed for the 1st time
|
||||
|
||||
export type IndexStatus =
|
||||
| 'not-empty' // Index contains documents
|
||||
| 'empty' // Index doesn't contain documents (or doesn't exist)
|
||||
| 'unprivileged'; // User doesn't have access to query the index
|
||||
|
||||
export interface IndexDetails {
|
||||
index: string;
|
||||
status: IndexStatus;
|
||||
}
|
||||
|
||||
export interface BaseCspSetupBothPolicy {
|
||||
status: CspStatusCode;
|
||||
installedPackagePolicies: number;
|
||||
healthyAgents: number;
|
||||
}
|
||||
|
||||
export interface BaseCspSetupStatus {
|
||||
indicesDetails: IndexDetails[];
|
||||
latestPackageVersion: string;
|
||||
cspm: BaseCspSetupBothPolicy;
|
||||
kspm: BaseCspSetupBothPolicy;
|
||||
vuln_mgmt: BaseCspSetupBothPolicy;
|
||||
isPluginInitialized: boolean;
|
||||
installedPackageVersion?: string | undefined;
|
||||
hasMisconfigurationsFindings?: boolean;
|
||||
}
|
||||
|
||||
export type CspSetupStatus = BaseCspSetupStatus;
|
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { extractErrorMessage, defaultErrorMessage, buildMutedRulesFilter } from './helpers';
|
||||
|
||||
const fallbackMessage = 'thisIsAFallBackMessage';
|
||||
|
||||
describe('test helper methods', () => {
|
||||
describe('extractErrorMessage Test', () => {
|
||||
it('should return error message if input is instance of Error', () => {
|
||||
const errorMessage = 'thisIsInstanceOfErrorMessage';
|
||||
const error = new Error(errorMessage);
|
||||
const extractedErrorMessage = extractErrorMessage(error, fallbackMessage);
|
||||
|
||||
expect(extractedErrorMessage).toMatch(errorMessage);
|
||||
});
|
||||
|
||||
it('should return string if input is string', () => {
|
||||
const error: string = 'thisIsAString';
|
||||
const extractedErrorMessage = extractErrorMessage(error, fallbackMessage);
|
||||
|
||||
expect(extractedErrorMessage).toMatch(error);
|
||||
});
|
||||
|
||||
it('should return fallbackMessage is input is not string nor instance of Error', () => {
|
||||
const error: number = 12345;
|
||||
const extractedErrorMessage = extractErrorMessage(error, fallbackMessage);
|
||||
|
||||
expect(extractedErrorMessage).toMatch(fallbackMessage);
|
||||
});
|
||||
|
||||
it('should return default message when input is not string nor instance of Error and fallbackMessage is not provided', () => {
|
||||
const error: number = 12345;
|
||||
const extractedErrorMessage = extractErrorMessage(error);
|
||||
|
||||
expect(extractedErrorMessage).toMatch(defaultErrorMessage);
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildMutedRulesFilter Test', () => {
|
||||
it('should return an empty array if no rules are muted', () => {
|
||||
const rulesStates = {
|
||||
rule1: {
|
||||
muted: false,
|
||||
benchmark_id: '1',
|
||||
benchmark_version: '1.0',
|
||||
rule_number: '1',
|
||||
rule_id: '11',
|
||||
},
|
||||
rule2: {
|
||||
muted: false,
|
||||
benchmark_id: '2',
|
||||
benchmark_version: '1.0',
|
||||
rule_number: '2',
|
||||
rule_id: '22',
|
||||
},
|
||||
};
|
||||
|
||||
expect(buildMutedRulesFilter(rulesStates)).toEqual([]);
|
||||
});
|
||||
|
||||
it('should return the correct query for a single muted rule', () => {
|
||||
const rulesStates = {
|
||||
rule1: {
|
||||
muted: true,
|
||||
benchmark_id: '1',
|
||||
benchmark_version: '1.0',
|
||||
rule_number: '1',
|
||||
rule_id: '11',
|
||||
},
|
||||
rule2: {
|
||||
muted: false,
|
||||
benchmark_id: '2',
|
||||
benchmark_version: '1.0',
|
||||
rule_number: '2',
|
||||
rule_id: '22',
|
||||
},
|
||||
};
|
||||
|
||||
const expectedQuery = [
|
||||
{
|
||||
bool: {
|
||||
must: [
|
||||
{ term: { 'rule.benchmark.id': '1' } },
|
||||
{ term: { 'rule.benchmark.version': '1.0' } },
|
||||
{ term: { 'rule.benchmark.rule_number': '1' } },
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
expect(buildMutedRulesFilter(rulesStates)).toEqual(expectedQuery);
|
||||
});
|
||||
|
||||
it('should return the correct queries for multiple muted rules', () => {
|
||||
const rulesStates = {
|
||||
rule1: {
|
||||
muted: true,
|
||||
benchmark_id: '1',
|
||||
benchmark_version: '1.0',
|
||||
rule_number: '1',
|
||||
rule_id: '11',
|
||||
},
|
||||
rule2: {
|
||||
muted: true,
|
||||
benchmark_id: '2',
|
||||
benchmark_version: '1.0',
|
||||
rule_number: '2',
|
||||
rule_id: '22',
|
||||
},
|
||||
};
|
||||
|
||||
const expectedQuery = [
|
||||
{
|
||||
bool: {
|
||||
must: [
|
||||
{ term: { 'rule.benchmark.id': '1' } },
|
||||
{ term: { 'rule.benchmark.version': '1.0' } },
|
||||
{ term: { 'rule.benchmark.rule_number': '1' } },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
bool: {
|
||||
must: [
|
||||
{ term: { 'rule.benchmark.id': '2' } },
|
||||
{ term: { 'rule.benchmark.version': '1.0' } },
|
||||
{ term: { 'rule.benchmark.rule_number': '2' } },
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
expect(buildMutedRulesFilter(rulesStates)).toEqual(expectedQuery);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
import { QueryDslQueryContainer } from '@kbn/data-views-plugin/common/types';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import type { CspBenchmarkRulesStates } from '../schema/rules/latest';
|
||||
|
||||
export const defaultErrorMessage = i18n.translate('xpack.csp.common.utils.helpers.unknownError', {
|
||||
defaultMessage: 'Unknown Error',
|
||||
});
|
||||
|
||||
export const extractErrorMessage = (e: unknown, fallbackMessage?: string): string => {
|
||||
if (e instanceof Error) return e.message;
|
||||
if (typeof e === 'string') return e;
|
||||
|
||||
return fallbackMessage ?? defaultErrorMessage;
|
||||
};
|
||||
|
||||
export const buildMutedRulesFilter = (
|
||||
rulesStates: CspBenchmarkRulesStates
|
||||
): QueryDslQueryContainer[] => {
|
||||
const mutedRules = Object.fromEntries(
|
||||
Object.entries(rulesStates).filter(([key, value]) => value.muted === true)
|
||||
);
|
||||
|
||||
const mutedRulesFilterQuery = Object.keys(mutedRules).map((key) => {
|
||||
const rule = mutedRules[key];
|
||||
return {
|
||||
bool: {
|
||||
must: [
|
||||
{ term: { 'rule.benchmark.id': rule.benchmark_id } },
|
||||
{ term: { 'rule.benchmark.version': rule.benchmark_version } },
|
||||
{ term: { 'rule.benchmark.rule_number': rule.rule_number } },
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
return mutedRulesFilterQuery;
|
||||
};
|
|
@ -6,3 +6,4 @@
|
|||
*/
|
||||
|
||||
export * from './type';
|
||||
export { showErrorToast } from './src/utils/show_error_toast';
|
||||
|
|
|
@ -6,16 +6,17 @@
|
|||
*/
|
||||
|
||||
import { useQuery, type UseQueryOptions } from '@tanstack/react-query';
|
||||
import { useKibana } from '@kbn/kibana-react-plugin/public';
|
||||
import type { CoreStart } from '@kbn/core/public';
|
||||
import { STATUS_API_CURRENT_VERSION, STATUS_ROUTE_PATH } from '@kbn/cloud-security-posture-common';
|
||||
import type { CspSetupStatus } from '@kbn/cloud-security-posture-common';
|
||||
import { useKibana } from '../hooks/use_kibana';
|
||||
|
||||
const getCspSetupStatusQueryKey = 'csp_status_key';
|
||||
|
||||
export const useCspSetupStatusApi = (
|
||||
options?: UseQueryOptions<CspSetupStatus, unknown, CspSetupStatus>
|
||||
) => {
|
||||
const { http } = useKibana().services;
|
||||
const { http } = useKibana<CoreStart>().services;
|
||||
return useQuery<CspSetupStatus, unknown, CspSetupStatus>(
|
||||
[getCspSetupStatusQueryKey],
|
||||
() => http.get<CspSetupStatus>(STATUS_ROUTE_PATH, { version: STATUS_API_CURRENT_VERSION }),
|
|
@ -10,13 +10,14 @@ import {
|
|||
CSP_GET_BENCHMARK_RULES_STATE_API_CURRENT_VERSION,
|
||||
CSP_GET_BENCHMARK_RULES_STATE_ROUTE_PATH,
|
||||
} from '@kbn/cloud-security-posture-common';
|
||||
import type { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common';
|
||||
import { useKibana } from '../../../common/hooks/use_kibana';
|
||||
import type { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { useKibana } from '@kbn/kibana-react-plugin/public';
|
||||
import type { CoreStart } from '@kbn/core/public';
|
||||
|
||||
export const getRuleStatesKey = ['get_rules_state_key'];
|
||||
|
||||
export const useGetCspBenchmarkRulesStatesApi = () => {
|
||||
const { http } = useKibana().services;
|
||||
const { http } = useKibana<CoreStart>().services;
|
||||
return useQuery<CspBenchmarkRulesStates, unknown, CspBenchmarkRulesStates>(getRuleStatesKey, () =>
|
||||
http.get<CspBenchmarkRulesStates>(CSP_GET_BENCHMARK_RULES_STATE_ROUTE_PATH, {
|
||||
version: CSP_GET_BENCHMARK_RULES_STATE_API_CURRENT_VERSION,
|
|
@ -4,9 +4,10 @@
|
|||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { CoreStart } from '@kbn/core/public';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { extractErrorMessage } from '../../../common/utils/helpers';
|
||||
import { extractErrorMessage } from '@kbn/cloud-security-posture-common';
|
||||
|
||||
const SEARCH_FAILED_TEXT = i18n.translate(
|
||||
'xpack.csp.findings.findingsErrorToast.searchFailedTitle',
|
|
@ -33,5 +33,8 @@
|
|||
"@kbn/es-query",
|
||||
"@kbn/cloud-plugin",
|
||||
"@kbn/spaces-plugin",
|
||||
"@kbn/kibana-react-plugin",
|
||||
"@kbn/cloud-security-posture-common",
|
||||
"@kbn/i18n",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -7,12 +7,11 @@
|
|||
|
||||
// Optionally, re-export the entire set of types. Interfaces and types declared after this will override v1 declarations.
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import type { BenchmarksCisId } from '@kbn/cloud-security-posture-common';
|
||||
import type { BenchmarkScore } from './v1';
|
||||
|
||||
export type { BenchmarkScore } from './v1';
|
||||
|
||||
export type BenchmarksCisId = 'cis_k8s' | 'cis_azure' | 'cis_aws' | 'cis_eks' | 'cis_gcp';
|
||||
|
||||
export interface Benchmark {
|
||||
id: BenchmarksCisId;
|
||||
name: string;
|
||||
|
|
|
@ -5,22 +5,8 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
export * as rulesV1 from './rules/v1';
|
||||
export * as rulesV2 from './rules/v2';
|
||||
export * as rulesV3 from './rules/v3';
|
||||
export * as rulesV4 from './rules/v4';
|
||||
export * as rulesV5 from './rules/v5';
|
||||
|
||||
export * as benchmarkV1 from './benchmarks/v1';
|
||||
export * as benchmarkV2 from './benchmarks/v2';
|
||||
|
||||
// Explicit export of everything from latest
|
||||
export type {
|
||||
CspBenchmarkRule,
|
||||
FindCspBenchmarkRuleRequest,
|
||||
FindCspBenchmarkRuleResponse,
|
||||
BenchmarkScore,
|
||||
Benchmark,
|
||||
GetBenchmarkResponse,
|
||||
BenchmarkRuleSelectParams,
|
||||
} from './latest';
|
||||
export type { BenchmarkScore, Benchmark, GetBenchmarkResponse } from './latest';
|
||||
|
|
|
@ -5,5 +5,4 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
export * from './rules/v5';
|
||||
export * from './benchmarks/v2';
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
import { type TypeOf } from '@kbn/config-schema';
|
||||
import type { CspBenchmarkRuleMetadata } from '@kbn/cloud-security-posture-common';
|
||||
import type { CspBenchmarkRuleMetadata } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import type { CspFinding } from '@kbn/cloud-security-posture-common';
|
||||
import { SUPPORTED_CLOUDBEAT_INPUTS, SUPPORTED_POLICY_TEMPLATES } from './constants';
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { CspBenchmarkRuleMetadata } from '@kbn/cloud-security-posture-common';
|
||||
import type { CspBenchmarkRuleMetadata } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import {
|
||||
convertRuleTagsToMatchAllKQL,
|
||||
convertRuleTagsToMatchAnyKQL,
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { CspBenchmarkRuleMetadata } from '@kbn/cloud-security-posture-common';
|
||||
import type { CspBenchmarkRuleMetadata } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
|
||||
const CSP_RULE_TAG = 'Cloud Security';
|
||||
const CSP_RULE_TAG_USE_CASE = 'Use Case: Configuration Audit';
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import { Truthy } from 'lodash';
|
||||
import type { BaseCspSetupStatus } from '@kbn/cloud-security-posture-common';
|
||||
import type { BaseCspSetupStatus, BenchmarksCisId } from '@kbn/cloud-security-posture-common';
|
||||
import {
|
||||
NewPackagePolicy,
|
||||
NewPackagePolicyInput,
|
||||
|
@ -15,6 +15,8 @@ import {
|
|||
PackagePolicyInput,
|
||||
UpdatePackagePolicy,
|
||||
} from '@kbn/fleet-plugin/common';
|
||||
import type { BenchmarkRuleSelectParams } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import type { BenchmarkRuleSelectParams as BenchmarkRuleSelectParamsV4 } from '@kbn/cloud-security-posture-common/schema/rules/v4';
|
||||
import {
|
||||
CLOUD_SECURITY_POSTURE_PACKAGE_NAME,
|
||||
CLOUDBEAT_VANILLA,
|
||||
|
@ -31,8 +33,6 @@ import type {
|
|||
AzureCredentialsType,
|
||||
RuleSection,
|
||||
} from '../types_old';
|
||||
import type { BenchmarkRuleSelectParams, BenchmarksCisId } from '../types/latest';
|
||||
import type { BenchmarkRuleSelectParams as BenchmarkRuleSelectParamsV1 } from '../types/rules/v4';
|
||||
|
||||
/**
|
||||
* @example
|
||||
|
@ -44,13 +44,6 @@ export const isNonNullable = <T extends unknown>(v: T): v is NonNullable<T> =>
|
|||
|
||||
export const truthy = <T>(value: T): value is Truthy<T> => !!value;
|
||||
|
||||
export const extractErrorMessage = (e: unknown, defaultMessage = 'Unknown Error'): string => {
|
||||
if (e instanceof Error) return e.message;
|
||||
if (typeof e === 'string') return e;
|
||||
|
||||
return defaultMessage; // TODO: i18n
|
||||
};
|
||||
|
||||
export const getBenchmarkFilter = (type: BenchmarkId, section?: RuleSection): string =>
|
||||
`${CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE}.attributes.metadata.benchmark.id: "${type}"${
|
||||
section
|
||||
|
@ -236,7 +229,7 @@ export const getCloudProviderNameFromAbbreviation = (cloudProvider: string) => {
|
|||
export const getBenchmarkFilterQuery = (
|
||||
benchmarkId: BenchmarkId,
|
||||
benchmarkVersion?: string,
|
||||
selectParams?: BenchmarkRuleSelectParamsV1
|
||||
selectParams?: BenchmarkRuleSelectParamsV4
|
||||
): string => {
|
||||
const baseQuery = `${CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE}.attributes.metadata.benchmark.id:${benchmarkId} AND ${CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE}.attributes.metadata.benchmark.version:"v${benchmarkVersion}"`;
|
||||
const sectionQuery = selectParams?.section
|
||||
|
|
|
@ -4,31 +4,6 @@
|
|||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
import { QueryDslQueryContainer } from '@kbn/data-views-plugin/common/types';
|
||||
import type { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common';
|
||||
|
||||
export const buildMutedRulesFilter = (
|
||||
rulesStates: CspBenchmarkRulesStates
|
||||
): QueryDslQueryContainer[] => {
|
||||
const mutedRules = Object.fromEntries(
|
||||
Object.entries(rulesStates).filter(([key, value]) => value.muted === true)
|
||||
);
|
||||
|
||||
const mutedRulesFilterQuery = Object.keys(mutedRules).map((key) => {
|
||||
const rule = mutedRules[key];
|
||||
return {
|
||||
bool: {
|
||||
must: [
|
||||
{ term: { 'rule.benchmark.id': rule.benchmark_id } },
|
||||
{ term: { 'rule.benchmark.version': rule.benchmark_version } },
|
||||
{ term: { 'rule.benchmark.rule_number': rule.rule_number } },
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
return mutedRulesFilterQuery;
|
||||
};
|
||||
|
||||
export const buildRuleKey = (benchmarkId: string, benchmarkVersion: string, ruleNumber: string) => {
|
||||
return `${benchmarkId};${benchmarkVersion};${ruleNumber}`;
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
import { useBenchmarkDynamicValues } from './use_benchmark_dynamic_values';
|
||||
import { renderHook } from '@testing-library/react-hooks/dom';
|
||||
import type { BenchmarksCisId } from '@kbn/cloud-security-posture-common';
|
||||
import { useCspIntegrationLink } from '../navigation/use_csp_integration_link';
|
||||
import { BenchmarksCisId } from '../../../common/types/benchmarks/v2';
|
||||
|
||||
jest.mock('../navigation/use_csp_integration_link');
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { CSPM_POLICY_TEMPLATE, KSPM_POLICY_TEMPLATE } from '@kbn/cloud-security-posture-common';
|
||||
import type { BenchmarksCisId } from '@kbn/cloud-security-posture-common';
|
||||
import { useCspIntegrationLink } from '../navigation/use_csp_integration_link';
|
||||
import { BenchmarksCisId } from '../../../common/types/benchmarks/v2';
|
||||
|
||||
type BenchmarkDynamicNames =
|
||||
| {
|
||||
|
|
|
@ -24,7 +24,7 @@ import { NoDataPage } from '@kbn/kibana-react-plugin/public';
|
|||
|
||||
const chance = new Chance();
|
||||
|
||||
jest.mock('../common/api/use_setup_status_api');
|
||||
jest.mock('@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api');
|
||||
jest.mock('../common/api/use_license_management_locator_api');
|
||||
jest.mock('../common/hooks/use_is_subscription_status_valid');
|
||||
jest.mock('../common/navigation/use_csp_integration_link');
|
||||
|
|
|
@ -39,7 +39,7 @@ import {
|
|||
} from '../../../common/constants';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { createReactQueryResponse } from '../../test/fixtures/react_query';
|
||||
import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api';
|
||||
import { useCspSetupStatusApi } from '@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api';
|
||||
import { usePackagePolicyList } from '../../common/api/use_package_policy_list';
|
||||
import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl';
|
||||
import {
|
||||
|
@ -67,7 +67,7 @@ jest.mock('react-router-dom', () => ({
|
|||
integration: undefined,
|
||||
}),
|
||||
}));
|
||||
jest.mock('../../common/api/use_setup_status_api');
|
||||
jest.mock('@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api');
|
||||
jest.mock('../../common/api/use_package_policy_list');
|
||||
jest.mock('../../common/hooks/use_is_subscription_status_valid');
|
||||
jest.mock('../../common/api/use_license_management_locator_api');
|
||||
|
|
|
@ -22,6 +22,7 @@ import { i18n } from '@kbn/i18n';
|
|||
import { css } from '@emotion/react';
|
||||
import { CSPM_POLICY_TEMPLATE, KSPM_POLICY_TEMPLATE } from '@kbn/cloud-security-posture-common';
|
||||
import type { IndexDetails, CspStatusCode } from '@kbn/cloud-security-posture-common';
|
||||
import { useCspSetupStatusApi } from '@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api';
|
||||
import { FullSizeCenteredPage } from '../full_size_centered_page';
|
||||
import { useCISIntegrationPoliciesLink } from '../../common/navigation/use_navigate_to_cis_integration_policies';
|
||||
import {
|
||||
|
@ -30,7 +31,6 @@ import {
|
|||
NO_FINDINGS_STATUS_TEST_SUBJ,
|
||||
} from '../test_subjects';
|
||||
import { CloudPosturePage, PACKAGE_NOT_INSTALLED_TEST_SUBJECT } from '../cloud_posture_page';
|
||||
import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api';
|
||||
import type { PostureTypes } from '../../../common/types_old';
|
||||
import noDataIllustration from '../../assets/illustrations/no_data_illustration.svg';
|
||||
import { useCspIntegrationLink } from '../../common/navigation/use_csp_integration_link';
|
||||
|
|
|
@ -22,10 +22,10 @@ import { FormattedMessage } from '@kbn/i18n-react';
|
|||
import { i18n } from '@kbn/i18n';
|
||||
import { css } from '@emotion/react';
|
||||
import type { IndexDetails } from '@kbn/cloud-security-posture-common';
|
||||
import { useCspSetupStatusApi } from '@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api';
|
||||
import { VULN_MGMT_POLICY_TEMPLATE } from '../../common/constants';
|
||||
import { FullSizeCenteredPage } from './full_size_centered_page';
|
||||
import { CloudPosturePage } from './cloud_posture_page';
|
||||
import { useCspSetupStatusApi } from '../common/api/use_setup_status_api';
|
||||
import {
|
||||
NO_VULNERABILITIES_STATUS_TEST_SUBJ,
|
||||
CNVM_NOT_INSTALLED_ACTION_SUBJ,
|
||||
|
|
|
@ -14,13 +14,13 @@ import { TestProvider } from '../../test/test_provider';
|
|||
import { Benchmarks } from './benchmarks';
|
||||
import * as TEST_SUBJ from './test_subjects';
|
||||
import { useCspBenchmarkIntegrationsV2 } from './use_csp_benchmark_integrations';
|
||||
import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api';
|
||||
import { useCspSetupStatusApi } from '@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api';
|
||||
import { useCspIntegrationLink } from '../../common/navigation/use_csp_integration_link';
|
||||
import { ERROR_STATE_TEST_SUBJECT } from './benchmarks_table';
|
||||
import { useLicenseManagementLocatorApi } from '../../common/api/use_license_management_locator_api';
|
||||
|
||||
jest.mock('./use_csp_benchmark_integrations');
|
||||
jest.mock('../../common/api/use_setup_status_api');
|
||||
jest.mock('@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api');
|
||||
jest.mock('../../common/api/use_license_management_locator_api');
|
||||
jest.mock('../../common/hooks/use_is_subscription_status_valid');
|
||||
jest.mock('../../common/navigation/use_csp_integration_link');
|
||||
|
|
|
@ -21,6 +21,8 @@ import { FormattedMessage } from '@kbn/i18n-react';
|
|||
import useDebounce from 'react-use/lib/useDebounce';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { pagePathGetters } from '@kbn/fleet-plugin/public';
|
||||
import { extractErrorMessage } from '@kbn/cloud-security-posture-common';
|
||||
import { useCspSetupStatusApi } from '@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api';
|
||||
import { CLOUD_SECURITY_POSTURE_PACKAGE_NAME } from '../../../common/constants';
|
||||
import { CloudPosturePageTitle } from '../../components/cloud_posture_page_title';
|
||||
import { CloudPosturePage } from '../../components/cloud_posture_page';
|
||||
|
@ -29,7 +31,7 @@ import {
|
|||
useCspBenchmarkIntegrationsV2,
|
||||
UseCspBenchmarkIntegrationsProps,
|
||||
} from './use_csp_benchmark_integrations';
|
||||
import { extractErrorMessage, getBenchmarkCisName } from '../../../common/utils/helpers';
|
||||
import { getBenchmarkCisName } from '../../../common/utils/helpers';
|
||||
import * as TEST_SUBJ from './test_subjects';
|
||||
import {
|
||||
LOCAL_STORAGE_PAGE_SIZE_BENCHMARK_KEY,
|
||||
|
@ -37,7 +39,6 @@ import {
|
|||
} from '../../common/constants';
|
||||
import { usePageSize } from '../../common/hooks/use_page_size';
|
||||
import { useKibana } from '../../common/hooks/use_kibana';
|
||||
import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api';
|
||||
import { NoFindingsStates } from '../../components/no_findings_states';
|
||||
|
||||
const SEARCH_DEBOUNCE_MS = 300;
|
||||
|
|
|
@ -21,9 +21,10 @@ import React, { useMemo } from 'react';
|
|||
import { i18n } from '@kbn/i18n';
|
||||
import { FormattedMessage } from '@kbn/i18n-react';
|
||||
import { generatePath } from 'react-router-dom';
|
||||
import type { BenchmarksCisId } from '@kbn/cloud-security-posture-common';
|
||||
import { FINDINGS_GROUPING_OPTIONS } from '../../common/constants';
|
||||
import { useNavigateFindings } from '../../common/hooks/use_navigate_findings';
|
||||
import type { BenchmarkScore, Benchmark, BenchmarksCisId } from '../../../common/types/latest';
|
||||
import type { BenchmarkScore, Benchmark } from '../../../common/types/latest';
|
||||
import * as TEST_SUBJ from './test_subjects';
|
||||
import { isCommonError } from '../../components/cloud_posture_page';
|
||||
import { FullSizeCenteredPage } from '../../components/full_size_centered_page';
|
||||
|
|
|
@ -12,7 +12,7 @@ import type { BaseCspSetupStatus, CspStatusCode } from '@kbn/cloud-security-post
|
|||
import { render, screen } from '@testing-library/react';
|
||||
import { TestProvider } from '../../test/test_provider';
|
||||
import { ComplianceDashboard, getDefaultTab } from '.';
|
||||
import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api';
|
||||
import { useCspSetupStatusApi } from '@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api';
|
||||
import { useLicenseManagementLocatorApi } from '../../common/api/use_license_management_locator_api';
|
||||
import { useKspmStatsApi, useCspmStatsApi } from '../../common/api/use_stats_api';
|
||||
import {
|
||||
|
@ -36,7 +36,7 @@ import { ComplianceDashboardDataV2 } from '../../../common/types_old';
|
|||
import { cloudPosturePages } from '../../common/navigation/constants';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
|
||||
jest.mock('../../common/api/use_setup_status_api');
|
||||
jest.mock('@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api');
|
||||
jest.mock('../../common/api/use_stats_api');
|
||||
jest.mock('../../common/api/use_license_management_locator_api');
|
||||
jest.mock('../../common/hooks/use_is_subscription_status_valid');
|
||||
|
|
|
@ -15,6 +15,7 @@ import { Route, Routes } from '@kbn/shared-ux-router';
|
|||
import { Redirect, useHistory, useLocation } from 'react-router-dom';
|
||||
import { CSPM_POLICY_TEMPLATE, KSPM_POLICY_TEMPLATE } from '@kbn/cloud-security-posture-common';
|
||||
import type { BaseCspSetupStatus } from '@kbn/cloud-security-posture-common';
|
||||
import { useCspSetupStatusApi } from '@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api';
|
||||
import { NO_FINDINGS_STATUS_TEST_SUBJ } from '../../components/test_subjects';
|
||||
import { useCspIntegrationLink } from '../../common/navigation/use_csp_integration_link';
|
||||
import type { PosturePolicyTemplate, ComplianceDashboardDataV2 } from '../../../common/types_old';
|
||||
|
@ -35,7 +36,6 @@ import {
|
|||
CLOUD_POSTURE_DASHBOARD_PAGE_HEADER,
|
||||
} from './test_subjects';
|
||||
import { useCspmStatsApi, useKspmStatsApi } from '../../common/api/use_stats_api';
|
||||
import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api';
|
||||
import { NoFindingsStates } from '../../components/no_findings_states';
|
||||
import { SummarySection } from './dashboard_sections/summary_section';
|
||||
import { BenchmarksSection } from './dashboard_sections/benchmarks_section';
|
||||
|
|
|
@ -8,8 +8,8 @@ import React from 'react';
|
|||
import { Redirect, useLocation } from 'react-router-dom';
|
||||
import { Routes, Route } from '@kbn/shared-ux-router';
|
||||
import { TrackApplicationView } from '@kbn/usage-collection-plugin/public';
|
||||
import { useCspSetupStatusApi } from '@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api';
|
||||
import { CDR_MISCONFIGURATIONS_DATA_VIEW_ID_PREFIX } from '../../../common/constants';
|
||||
import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api';
|
||||
import { NoFindingsStates } from '../../components/no_findings_states';
|
||||
import { CloudPosturePage, defaultLoadingRenderer } from '../../components/cloud_posture_page';
|
||||
import { useDataView } from '../../common/api/use_data_view';
|
||||
|
|
|
@ -11,8 +11,8 @@ import { GenericBuckets, GroupingQuery, RootAggregation } from '@kbn/grouping/sr
|
|||
import { useQuery } from '@tanstack/react-query';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
import { CDR_MISCONFIGURATIONS_INDEX_PATTERN } from '@kbn/cloud-security-posture-common';
|
||||
import { showErrorToast } from '@kbn/cloud-security-posture';
|
||||
import { useKibana } from '../../../common/hooks/use_kibana';
|
||||
import { showErrorToast } from '../../../common/utils/show_error_toast';
|
||||
|
||||
// Elasticsearch returns `null` when a sub-aggregation cannot be computed
|
||||
type NumberOrNull = number | null;
|
||||
|
|
|
@ -11,18 +11,18 @@ import type { IKibanaSearchResponse, IKibanaSearchRequest } from '@kbn/search-ty
|
|||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { buildDataTableRecord } from '@kbn/discover-utils';
|
||||
import { EsHitRecord } from '@kbn/discover-utils/types';
|
||||
import { MAX_FINDINGS_TO_LOAD } from '@kbn/cloud-security-posture-common';
|
||||
import { showErrorToast } from '@kbn/cloud-security-posture';
|
||||
import { MAX_FINDINGS_TO_LOAD, buildMutedRulesFilter } from '@kbn/cloud-security-posture-common';
|
||||
import {
|
||||
CDR_MISCONFIGURATIONS_INDEX_PATTERN,
|
||||
LATEST_FINDINGS_RETENTION_POLICY,
|
||||
} from '@kbn/cloud-security-posture-common';
|
||||
import type { CspBenchmarkRulesStates, CspFinding } from '@kbn/cloud-security-posture-common';
|
||||
import type { CspFinding } from '@kbn/cloud-security-posture-common';
|
||||
import type { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import type { FindingsBaseEsQuery } from '@kbn/cloud-security-posture';
|
||||
import { useGetCspBenchmarkRulesStatesApi } from '@kbn/cloud-security-posture/src/hooks/use_get_benchmark_rules_state_api';
|
||||
import { useKibana } from '../../../common/hooks/use_kibana';
|
||||
import { getAggregationCount, getFindingsCountAggQuery } from '../utils/utils';
|
||||
import { showErrorToast } from '../../../common/utils/show_error_toast';
|
||||
import { useGetCspBenchmarkRulesStatesApi } from './use_get_benchmark_rules_state_api';
|
||||
import { buildMutedRulesFilter } from '../../../../common/utils/rules_states';
|
||||
|
||||
interface UseFindingsOptions extends FindingsBaseEsQuery {
|
||||
sort: string[][];
|
||||
|
|
|
@ -15,7 +15,11 @@ import {
|
|||
} from '@kbn/grouping/src';
|
||||
import { useMemo } from 'react';
|
||||
import { buildEsQuery, Filter } from '@kbn/es-query';
|
||||
import { LATEST_FINDINGS_RETENTION_POLICY } from '@kbn/cloud-security-posture-common';
|
||||
import {
|
||||
LATEST_FINDINGS_RETENTION_POLICY,
|
||||
buildMutedRulesFilter,
|
||||
} from '@kbn/cloud-security-posture-common';
|
||||
import { useGetCspBenchmarkRulesStatesApi } from '@kbn/cloud-security-posture/src/hooks/use_get_benchmark_rules_state_api';
|
||||
import {
|
||||
FINDINGS_GROUPING_OPTIONS,
|
||||
LOCAL_STORAGE_FINDINGS_GROUPING_KEY,
|
||||
|
@ -36,8 +40,6 @@ import {
|
|||
} from './constants';
|
||||
import { useCloudSecurityGrouping } from '../../../components/cloud_security_grouping';
|
||||
import { getFilters } from '../utils/get_filters';
|
||||
import { useGetCspBenchmarkRulesStatesApi } from './use_get_benchmark_rules_state_api';
|
||||
import { buildMutedRulesFilter } from '../../../../common/utils/rules_states';
|
||||
|
||||
const getTermAggregation = (key: keyof FindingsGroupingAggregation, field: string) => ({
|
||||
[key]: {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import { HttpSetup } from '@kbn/core/public';
|
||||
import { LATEST_FINDINGS_RETENTION_POLICY } from '@kbn/cloud-security-posture-common';
|
||||
import { CspBenchmarkRule } from '../../../../common/types/latest';
|
||||
import type { CspBenchmarkRule } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { FINDINGS_INDEX_PATTERN } from '../../../../common/constants';
|
||||
|
||||
import { createDetectionRule } from '../../../common/api/create_detection_rule';
|
||||
|
|
|
@ -10,11 +10,11 @@ import { EuiSpacer, EuiTab, EuiTabs, EuiTitle } from '@elastic/eui';
|
|||
import { FormattedMessage } from '@kbn/i18n-react';
|
||||
import { Redirect, useHistory, useLocation, matchPath } from 'react-router-dom';
|
||||
import { Routes, Route } from '@kbn/shared-ux-router';
|
||||
import { useCspSetupStatusApi } from '@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api';
|
||||
import { Configurations } from '../configurations';
|
||||
import { cloudPosturePages, findingsNavigation } from '../../common/navigation/constants';
|
||||
import { LOCAL_STORAGE_FINDINGS_LAST_SELECTED_TAB_KEY } from '../../common/constants';
|
||||
import { VULNERABILITIES_INDEX_NAME, FINDINGS_INDEX_NAME } from '../../../common/constants';
|
||||
import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api';
|
||||
import { getStatusForIndexName } from '../../../common/utils/helpers';
|
||||
import { Vulnerabilities } from '../vulnerabilities';
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import { generatePath, Link, type RouteComponentProps } from 'react-router-dom';
|
|||
import { EuiButtonEmpty, EuiFlexGroup, EuiPageHeader, EuiSpacer, EuiFlexItem } from '@elastic/eui';
|
||||
import { FormattedMessage } from '@kbn/i18n-react';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import type { PageUrlParams } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { CloudPosturePageTitle } from '../../components/cloud_posture_page_title';
|
||||
import { RulesContainer } from './rules_container';
|
||||
import { cloudPosturePages } from '../../common/navigation/constants';
|
||||
|
@ -18,7 +19,6 @@ import { useSecuritySolutionContext } from '../../application/security_solution_
|
|||
import { useCspBenchmarkIntegrationsV2 } from '../benchmarks/use_csp_benchmark_integrations';
|
||||
import { CISBenchmarkIcon } from '../../components/cis_benchmark_icon';
|
||||
import { getBenchmarkCisName } from '../../../common/utils/helpers';
|
||||
import { PageUrlParams } from '../../../common/types/latest';
|
||||
|
||||
export const Rules = ({ match: { params } }: RouteComponentProps<PageUrlParams>) => {
|
||||
const benchmarksInfo = useCspBenchmarkIntegrationsV2();
|
||||
|
|
|
@ -12,16 +12,16 @@ import { render, screen } from '@testing-library/react';
|
|||
import { QueryClient } from '@tanstack/react-query';
|
||||
import { TestProvider } from '../../test/test_provider';
|
||||
import { type RouteComponentProps } from 'react-router-dom';
|
||||
import { PageUrlParams } from '../../../common/types/latest';
|
||||
import type { PageUrlParams } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { createReactQueryResponse } from '../../test/fixtures/react_query';
|
||||
import { coreMock } from '@kbn/core/public/mocks';
|
||||
import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api';
|
||||
import { useCspSetupStatusApi } from '@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api';
|
||||
import { useCspIntegrationLink } from '../../common/navigation/use_csp_integration_link';
|
||||
import { useLicenseManagementLocatorApi } from '../../common/api/use_license_management_locator_api';
|
||||
import { useCspBenchmarkIntegrationsV2 } from '../benchmarks/use_csp_benchmark_integrations';
|
||||
import * as TEST_SUBJECTS from './test_subjects';
|
||||
|
||||
jest.mock('../../common/api/use_setup_status_api');
|
||||
jest.mock('@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api');
|
||||
jest.mock('../../common/api/use_license_management_locator_api');
|
||||
jest.mock('../../common/hooks/use_is_subscription_status_valid');
|
||||
jest.mock('../../common/navigation/use_csp_integration_link');
|
||||
|
|
|
@ -13,7 +13,7 @@ import { useFindCspBenchmarkRule } from './use_csp_benchmark_rules';
|
|||
import * as TEST_SUBJECTS from './test_subjects';
|
||||
import { Chance } from 'chance';
|
||||
import { TestProvider } from '../../test/test_provider';
|
||||
import type { CspBenchmarkRule } from '../../../common/types/latest';
|
||||
import type { CspBenchmarkRule } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { coreMock } from '@kbn/core/public/mocks';
|
||||
|
||||
|
|
|
@ -8,9 +8,14 @@ import React, { useState, useMemo, useEffect } from 'react';
|
|||
import compareVersions from 'compare-versions';
|
||||
import { EuiSpacer } from '@elastic/eui';
|
||||
import { useParams, useHistory, generatePath } from 'react-router-dom';
|
||||
import type {
|
||||
CspBenchmarkRule,
|
||||
PageUrlParams,
|
||||
RuleStateAttributes,
|
||||
} from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { extractErrorMessage } from '@kbn/cloud-security-posture-common';
|
||||
import { benchmarksNavigation } from '../../common/navigation/constants';
|
||||
import { buildRuleKey } from '../../../common/utils/rules_states';
|
||||
import { extractErrorMessage } from '../../../common/utils/helpers';
|
||||
import { RulesTable } from './rules_table';
|
||||
import { RulesTableHeader } from './rules_table_header';
|
||||
import { useFindCspBenchmarkRule, type RulesQuery } from './use_csp_benchmark_rules';
|
||||
|
@ -18,11 +23,6 @@ import * as TEST_SUBJECTS from './test_subjects';
|
|||
import { RuleFlyout } from './rules_flyout';
|
||||
import { LOCAL_STORAGE_PAGE_SIZE_RULES_KEY } from '../../common/constants';
|
||||
import { usePageSize } from '../../common/hooks/use_page_size';
|
||||
import type {
|
||||
CspBenchmarkRule,
|
||||
PageUrlParams,
|
||||
RuleStateAttributes,
|
||||
} from '../../../common/types/latest';
|
||||
import { useCspGetRulesStates } from './use_csp_rules_state';
|
||||
import { RulesCounters } from './rules_counters';
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import type { HttpSetup } from '@kbn/core/public';
|
||||
import React from 'react';
|
||||
import { CspBenchmarkRule } from '../../../common/types/latest';
|
||||
import type { CspBenchmarkRule } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { getFindingsDetectionRuleSearchTags } from '../../../common/utils/detection_rules';
|
||||
import { DetectionRuleCounter } from '../../components/detection_rule_counter';
|
||||
import { createDetectionRuleFromBenchmarkRule } from '../configurations/utils/create_detection_rule_from_benchmark';
|
||||
|
|
|
@ -23,7 +23,7 @@ import {
|
|||
import { i18n } from '@kbn/i18n';
|
||||
import { FormattedMessage } from '@kbn/i18n-react';
|
||||
import { HttpSetup } from '@kbn/core/public';
|
||||
import type { CspBenchmarkRuleMetadata } from '@kbn/cloud-security-posture-common';
|
||||
import type { CspBenchmarkRuleMetadata } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { getRuleList } from '../configurations/findings_flyout/rule_tab';
|
||||
import { getRemediationList } from '../configurations/findings_flyout/overview_tab';
|
||||
import * as TEST_SUBJECTS from './test_subjects';
|
||||
|
|
|
@ -8,6 +8,7 @@ import React from 'react';
|
|||
import { act, renderHook } from '@testing-library/react-hooks';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { useKibana } from '@kbn/kibana-react-plugin/public';
|
||||
import type { RuleStateAttributes } from '@kbn/cloud-security-posture-common/schema/rules/v4';
|
||||
import {
|
||||
useChangeCspRuleState,
|
||||
createRulesWithUpdatedState,
|
||||
|
@ -17,7 +18,6 @@ import { CSP_RULES_STATES_QUERY_KEY } from './use_csp_rules_state';
|
|||
import { BENCHMARK_INTEGRATION_QUERY_KEY_V2 } from '../benchmarks/use_csp_benchmark_integrations';
|
||||
import { CSPM_STATS_QUERY_KEY, KSPM_STATS_QUERY_KEY } from '../../common/api';
|
||||
import { CSP_BENCHMARK_RULES_BULK_ACTION_ROUTE_PATH } from '../../../common/constants';
|
||||
import { RuleStateAttributes } from '../../../common/types/rules/v4';
|
||||
|
||||
const initialRules = {
|
||||
rule_1: {
|
||||
|
|
|
@ -10,13 +10,13 @@ import { toMountPoint } from '@kbn/react-kibana-mount';
|
|||
import { EuiText } from '@elastic/eui';
|
||||
import { FormattedMessage } from '@kbn/i18n-react';
|
||||
import { i18n as kbnI18n } from '@kbn/i18n';
|
||||
import type {
|
||||
CspBenchmarkRulesBulkActionResponse,
|
||||
RuleStateAttributes,
|
||||
} from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { CSP_RULES_STATES_QUERY_KEY } from './use_csp_rules_state';
|
||||
import { CSPM_STATS_QUERY_KEY, KSPM_STATS_QUERY_KEY } from '../../common/api';
|
||||
import { BENCHMARK_INTEGRATION_QUERY_KEY_V2 } from '../benchmarks/use_csp_benchmark_integrations';
|
||||
import {
|
||||
CspBenchmarkRulesBulkActionResponse,
|
||||
RuleStateAttributes,
|
||||
} from '../../../common/types/latest';
|
||||
import { CSP_BENCHMARK_RULES_BULK_ACTION_ROUTE_PATH } from '../../../common/constants';
|
||||
import { CloudSecurityPostureStartServices } from '../../types';
|
||||
import { useKibana } from '../../common/hooks/use_kibana';
|
||||
|
|
|
@ -8,7 +8,7 @@ import { useQuery } from '@tanstack/react-query';
|
|||
import {
|
||||
FindCspBenchmarkRuleRequest,
|
||||
FindCspBenchmarkRuleResponse,
|
||||
} from '../../../common/types/latest';
|
||||
} from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { useKibana } from '../../common/hooks/use_kibana';
|
||||
|
||||
import {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { CSP_GET_BENCHMARK_RULES_STATE_ROUTE_PATH } from '@kbn/cloud-security-posture-common';
|
||||
import type { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common';
|
||||
import type { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { useKibana } from '../../common/hooks/use_kibana';
|
||||
|
||||
export const CSP_RULES_STATES_QUERY_KEY = ['csp_rules_states_v1'];
|
||||
|
|
|
@ -10,9 +10,9 @@ import type { IKibanaSearchResponse } from '@kbn/search-types';
|
|||
import { GenericBuckets, GroupingQuery, RootAggregation } from '@kbn/grouping/src';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
import { showErrorToast } from '@kbn/cloud-security-posture';
|
||||
import { LATEST_VULNERABILITIES_INDEX_PATTERN } from '../../../../common/constants';
|
||||
import { useKibana } from '../../../common/hooks/use_kibana';
|
||||
import { showErrorToast } from '../../../common/utils/show_error_toast';
|
||||
|
||||
// Elasticsearch returns `null` when a sub-aggregation cannot be computed
|
||||
type NumberOrNull = number | null;
|
||||
|
|
|
@ -17,7 +17,7 @@ import {
|
|||
import { buildDataTableRecord } from '@kbn/discover-utils';
|
||||
import { EsHitRecord } from '@kbn/discover-utils/types';
|
||||
import { MAX_FINDINGS_TO_LOAD } from '@kbn/cloud-security-posture-common';
|
||||
import { FindingsBaseEsQuery } from '@kbn/cloud-security-posture';
|
||||
import { FindingsBaseEsQuery, showErrorToast } from '@kbn/cloud-security-posture';
|
||||
import { VULNERABILITY_FIELDS } from '../../../common/constants';
|
||||
import { CspVulnerabilityFinding } from '../../../../common/schemas';
|
||||
import {
|
||||
|
@ -25,7 +25,6 @@ import {
|
|||
LATEST_VULNERABILITIES_RETENTION_POLICY,
|
||||
} from '../../../../common/constants';
|
||||
import { useKibana } from '../../../common/hooks/use_kibana';
|
||||
import { showErrorToast } from '../../../common/utils/show_error_toast';
|
||||
import { getCaseInsensitiveSortScript } from '../utils/custom_sort_script';
|
||||
type LatestFindingsRequest = IKibanaSearchRequest<SearchRequest>;
|
||||
type LatestFindingsResponse = IKibanaSearchResponse<
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
*/
|
||||
import React from 'react';
|
||||
import { Routes, Route } from '@kbn/shared-ux-router';
|
||||
import { useCspSetupStatusApi } from '@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api';
|
||||
import { CDR_VULNERABILITIES_DATA_VIEW_ID_PREFIX } from '../../../common/constants';
|
||||
import { NoVulnerabilitiesStates } from '../../components/no_vulnerabilities_states';
|
||||
import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api';
|
||||
import { CloudPosturePage } from '../../components/cloud_posture_page';
|
||||
import { findingsNavigation } from '../../common/navigation/constants';
|
||||
import { useDataView } from '../../common/api/use_data_view';
|
||||
|
|
|
@ -12,7 +12,7 @@ import {
|
|||
LATEST_VULNERABILITIES_INDEX_DEFAULT_NS,
|
||||
VULN_MGMT_POLICY_TEMPLATE,
|
||||
} from '../../../common/constants';
|
||||
import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api';
|
||||
import { useCspSetupStatusApi } from '@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api';
|
||||
import { useDataView } from '../../common/api/use_data_view';
|
||||
import { createReactQueryResponse } from '../../test/fixtures/react_query';
|
||||
import { useCISIntegrationPoliciesLink } from '../../common/navigation/use_navigate_to_cis_integration_policies';
|
||||
|
@ -28,7 +28,7 @@ import { useLicenseManagementLocatorApi } from '../../common/api/use_license_man
|
|||
import { createStubDataView } from '@kbn/data-views-plugin/common/stubs';
|
||||
|
||||
jest.mock('../../common/api/use_data_view');
|
||||
jest.mock('../../common/api/use_setup_status_api');
|
||||
jest.mock('@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api');
|
||||
jest.mock('../../common/api/use_license_management_locator_api');
|
||||
jest.mock('../../common/hooks/use_is_subscription_status_valid');
|
||||
jest.mock('../../common/navigation/use_navigate_to_cis_integration_policies');
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
} from '../../../common/constants';
|
||||
import { chartPluginMock } from '@kbn/charts-plugin/public/mocks';
|
||||
import { discoverPluginMock } from '@kbn/discover-plugin/public/mocks';
|
||||
import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api';
|
||||
import { useCspSetupStatusApi } from '@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api';
|
||||
import { createReactQueryResponse } from '../../test/fixtures/react_query';
|
||||
import { useCISIntegrationPoliciesLink } from '../../common/navigation/use_navigate_to_cis_integration_policies';
|
||||
import { useCspIntegrationLink } from '../../common/navigation/use_csp_integration_link';
|
||||
|
@ -32,7 +32,7 @@ import { useVulnerabilityDashboardApi } from '../../common/api/use_vulnerability
|
|||
import { mockCnvmDashboardData } from './_mocks_/vulnerability_dashboard.mock';
|
||||
|
||||
jest.mock('../../common/api/use_data_view');
|
||||
jest.mock('../../common/api/use_setup_status_api');
|
||||
jest.mock('@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api');
|
||||
jest.mock('../../common/api/use_license_management_locator_api');
|
||||
jest.mock('../../common/hooks/use_is_subscription_status_valid');
|
||||
jest.mock('../../common/navigation/use_navigate_to_cis_integration_policies');
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
import React from 'react';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { EuiPageHeader, EuiSpacer } from '@elastic/eui';
|
||||
import { useCspSetupStatusApi } from '@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api';
|
||||
import { useVulnerabilityDashboardApi } from '../../common/api/use_vulnerability_dashboard_api';
|
||||
import { VulnerabilityTrendGraph } from './vulnerability_trend_graph';
|
||||
import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api';
|
||||
import { NoVulnerabilitiesStates } from '../../components/no_vulnerabilities_states';
|
||||
import {
|
||||
VULNERABILITY_DASHBOARD_CONTAINER,
|
||||
|
|
|
@ -10,8 +10,8 @@ import {
|
|||
SavedObjectsClientContract,
|
||||
} from '@kbn/core-saved-objects-api-server';
|
||||
import type { Logger } from '@kbn/core/server';
|
||||
import type { CspBenchmarkRule } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE } from '../../../../common/constants';
|
||||
import { CspBenchmarkRule } from '../../../../common/types/latest';
|
||||
import { getCspBenchmarkRulesStatesHandler } from '../../../routes/benchmark_rules/get_states/v1';
|
||||
import { MutedRulesStats } from './types';
|
||||
|
||||
|
|
|
@ -24,6 +24,10 @@ import type {
|
|||
TaskManagerSetupContract,
|
||||
TaskManagerStartContract,
|
||||
} from '@kbn/task-manager-plugin/server';
|
||||
import type {
|
||||
CspBenchmarkRule,
|
||||
CspSettings,
|
||||
} from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { isCspPackage } from '../common/utils/helpers';
|
||||
import { isSubscriptionAllowed } from '../common/utils/subscription';
|
||||
import { cleanupCredentials } from '../common/utils/helpers';
|
||||
|
@ -47,7 +51,6 @@ import {
|
|||
} from './tasks/findings_stats_task';
|
||||
import { registerCspmUsageCollector } from './lib/telemetry/collectors/register';
|
||||
import { CloudSecurityPostureConfig } from './config';
|
||||
import { CspBenchmarkRule, CspSettings } from '../common/types/latest';
|
||||
|
||||
export class CspPlugin
|
||||
implements
|
||||
|
|
|
@ -9,8 +9,8 @@ import { transformError } from '@kbn/securitysolution-es-utils';
|
|||
import {
|
||||
CspBenchmarkRulesBulkActionRequestSchema,
|
||||
cspBenchmarkRulesBulkActionRequestSchema,
|
||||
CspBenchmarkRulesBulkActionResponse,
|
||||
} from '../../../../common/types/rules/v4';
|
||||
} from '@kbn/cloud-security-posture-common/schema/rules/v4';
|
||||
import type { CspBenchmarkRulesBulkActionResponse } from '@kbn/cloud-security-posture-common/schema/rules/v4';
|
||||
import { CspRouter } from '../../../types';
|
||||
|
||||
import { CSP_BENCHMARK_RULES_BULK_ACTION_ROUTE_PATH } from '../../../../common/constants';
|
||||
|
|
|
@ -6,14 +6,14 @@
|
|||
*/
|
||||
|
||||
import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
|
||||
import type { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common';
|
||||
import type { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import type { FindResult, RulesClient } from '@kbn/alerting-plugin/server';
|
||||
import type { RuleParams } from '@kbn/alerting-plugin/server/application/rule/types';
|
||||
import type {
|
||||
CspBenchmarkRule,
|
||||
RulesToUpdate,
|
||||
CspSettings,
|
||||
} from '../../../../common/types/rules/v4';
|
||||
} from '@kbn/cloud-security-posture-common/schema/rules/v4';
|
||||
import {
|
||||
convertRuleTagsToMatchAllKQL,
|
||||
generateBenchmarkRuleTags,
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
|
||||
import { Logger } from '@kbn/core/server';
|
||||
import type { RulesClient } from '@kbn/alerting-plugin/server';
|
||||
import type {
|
||||
BulkActionBenchmarkRulesResponse,
|
||||
RulesToUpdate,
|
||||
} from '@kbn/cloud-security-posture-common/schema/rules/v4';
|
||||
import { buildRuleKey } from '../../../../common/utils/rules_states';
|
||||
import {
|
||||
getBenchmarkRules,
|
||||
|
@ -14,10 +18,6 @@ import {
|
|||
setRulesStates,
|
||||
updateBenchmarkRulesStates,
|
||||
} from './utils';
|
||||
import type {
|
||||
BulkActionBenchmarkRulesResponse,
|
||||
RulesToUpdate,
|
||||
} from '../../../../common/types/rules/v4';
|
||||
|
||||
const muteStatesMap = {
|
||||
mute: true,
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { CspBenchmarkRule } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { getSortedCspBenchmarkRulesTemplates } from './utils';
|
||||
import { CspBenchmarkRule } from '../../../../common/types/latest';
|
||||
|
||||
describe('getSortedCspBenchmarkRules', () => {
|
||||
it('sorts by metadata.benchmark.rule_number, invalid semantic version still should still get sorted and empty values should be sorted last', () => {
|
||||
|
|
|
@ -9,15 +9,11 @@ import {
|
|||
FindCspBenchmarkRuleRequest,
|
||||
FindCspBenchmarkRuleResponse,
|
||||
findCspBenchmarkRuleRequestSchema,
|
||||
} from '../../../../common/types/latest';
|
||||
import {
|
||||
FindCspBenchmarkRuleRequest as FindCspBenchmarkRuleRequestV1,
|
||||
findCspBenchmarkRuleRequestSchema as findCspBenchmarkRuleRequestSchemaV1,
|
||||
} from '../../../../common/types/rules/v3';
|
||||
import {
|
||||
FindCspBenchmarkRuleRequest as FindCspBenchmarkRuleRequestV2,
|
||||
findCspBenchmarkRuleRequestSchema as findCspBenchmarkRuleRequestSchemaV2,
|
||||
} from '../../../../common/types/rules/v4';
|
||||
} from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { findCspBenchmarkRuleRequestSchema as findCspBenchmarkRuleRequestSchemaV1 } from '@kbn/cloud-security-posture-common/schema/rules/v3';
|
||||
import type { FindCspBenchmarkRuleRequest as FindCspBenchmarkRuleRequestV1 } from '@kbn/cloud-security-posture-common/schema/rules/v3';
|
||||
import { findCspBenchmarkRuleRequestSchema as findCspBenchmarkRuleRequestSchemaV2 } from '@kbn/cloud-security-posture-common/schema/rules/v4';
|
||||
import type { FindCspBenchmarkRuleRequest as FindCspBenchmarkRuleRequestV2 } from '@kbn/cloud-security-posture-common/schema/rules/v4';
|
||||
import { FIND_CSP_BENCHMARK_RULE_ROUTE_PATH } from '../../../../common/constants';
|
||||
import { CspRouter } from '../../../types';
|
||||
import { findBenchmarkRuleHandler as findRuleHandlerV1 } from './v1';
|
||||
|
|
|
@ -8,11 +8,10 @@ import semverValid from 'semver/functions/valid';
|
|||
import semverCompare from 'semver/functions/compare';
|
||||
import { NewPackagePolicy } from '@kbn/fleet-plugin/common';
|
||||
import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
|
||||
import type { CspBenchmarkRule } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../benchmarks/benchmarks';
|
||||
import { getBenchmarkFromPackagePolicy } from '../../../../common/utils/helpers';
|
||||
|
||||
import type { CspBenchmarkRule } from '../../../../common/types/latest';
|
||||
|
||||
export const getSortedCspBenchmarkRulesTemplates = (
|
||||
cspBenchmarkRules: CspBenchmarkRule[],
|
||||
sortDirection: 'asc' | 'desc'
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
* 2.0.
|
||||
*/
|
||||
import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
|
||||
import { getBenchmarkFilter } from '../../../../common/utils/helpers';
|
||||
import { CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE } from '../../../../common/constants';
|
||||
import { getBenchmarkIdFromPackagePolicyId, getSortedCspBenchmarkRulesTemplates } from './utils';
|
||||
import type { CspBenchmarkRule } from '../../../../common/types/latest';
|
||||
import type { CspBenchmarkRule } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import type {
|
||||
FindCspBenchmarkRuleRequest,
|
||||
FindCspBenchmarkRuleResponse,
|
||||
} from '../../../../common/types/rules/v3';
|
||||
} from '@kbn/cloud-security-posture-common/schema/rules/v3';
|
||||
import { getBenchmarkFilter } from '../../../../common/utils/helpers';
|
||||
import { CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE } from '../../../../common/constants';
|
||||
import { getBenchmarkIdFromPackagePolicyId, getSortedCspBenchmarkRulesTemplates } from './utils';
|
||||
|
||||
export const findBenchmarkRuleHandler = async (
|
||||
soClient: SavedObjectsClientContract,
|
||||
|
|
|
@ -6,14 +6,14 @@
|
|||
*/
|
||||
|
||||
import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
|
||||
import { getBenchmarkFilterQuery } from '../../../../common/utils/helpers';
|
||||
import { CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE } from '../../../../common/constants';
|
||||
|
||||
import type {
|
||||
CspBenchmarkRule,
|
||||
FindCspBenchmarkRuleRequest,
|
||||
FindCspBenchmarkRuleResponse,
|
||||
} from '../../../../common/types/rules/v4';
|
||||
} from '@kbn/cloud-security-posture-common/schema/rules/v4';
|
||||
import { getBenchmarkFilterQuery } from '../../../../common/utils/helpers';
|
||||
import { CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE } from '../../../../common/constants';
|
||||
|
||||
import { getSortedCspBenchmarkRulesTemplates } from './utils';
|
||||
|
||||
export const findBenchmarkRuleHandler = async (
|
||||
|
|
|
@ -6,14 +6,14 @@
|
|||
*/
|
||||
|
||||
import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
|
||||
import { getBenchmarkFilterQueryV2 } from '../../../../common/utils/helpers';
|
||||
import { CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE } from '../../../../common/constants';
|
||||
|
||||
import type {
|
||||
CspBenchmarkRule,
|
||||
FindCspBenchmarkRuleRequest,
|
||||
FindCspBenchmarkRuleResponse,
|
||||
} from '../../../../common/types/latest';
|
||||
} from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { getBenchmarkFilterQueryV2 } from '../../../../common/utils/helpers';
|
||||
import { CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE } from '../../../../common/constants';
|
||||
|
||||
import { getSortedCspBenchmarkRulesTemplates } from './utils';
|
||||
|
||||
export const findBenchmarkRuleHandler = async (
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
import { CSP_GET_BENCHMARK_RULES_STATE_ROUTE_PATH } from '@kbn/cloud-security-posture-common';
|
||||
import type { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common';
|
||||
import type { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { CspRouter } from '../../../types';
|
||||
import { getCspBenchmarkRulesStatesHandler } from './v1';
|
||||
|
||||
|
|
|
@ -10,13 +10,13 @@ import {
|
|||
} from '@kbn/core-saved-objects-api-server';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common';
|
||||
import { CspSettings } from '../../../../common/types/rules/v4';
|
||||
import { buildMutedRulesFilter } from '@kbn/cloud-security-posture-common';
|
||||
import type { CspBenchmarkRulesStates } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import type { CspSettings } from '@kbn/cloud-security-posture-common/schema/rules/v4';
|
||||
import {
|
||||
INTERNAL_CSP_SETTINGS_SAVED_OBJECT_ID,
|
||||
INTERNAL_CSP_SETTINGS_SAVED_OBJECT_TYPE,
|
||||
} from '../../../../common/constants';
|
||||
import { buildMutedRulesFilter } from '../../../../common/utils/rules_states';
|
||||
|
||||
export const createCspSettingObject = async (soClient: SavedObjectsClientContract) => {
|
||||
return soClient.create<CspSettings>(
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
|
||||
import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
|
||||
|
||||
import { CspBenchmarkRule } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE } from '../../../common/constants';
|
||||
|
||||
import { CspBenchmarkRule } from '../../../common/types/latest';
|
||||
import { BenchmarkId } from '../../../common/types_old';
|
||||
import { getBenchmarkFilter } from '../../../common/utils/helpers';
|
||||
|
||||
|
|
|
@ -9,12 +9,13 @@ import { QueryDslQueryContainer } from '@kbn/data-views-plugin/common/types';
|
|||
import { MappingRuntimeFields } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { ElasticsearchClient, Logger } from '@kbn/core/server';
|
||||
import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
|
||||
import type { CspBenchmarkRule } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import {
|
||||
CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE,
|
||||
LATEST_FINDINGS_INDEX_DEFAULT_NS,
|
||||
} from '../../../common/constants';
|
||||
|
||||
import { CspBenchmarkRule, Benchmark } from '../../../common/types/latest';
|
||||
import { Benchmark } from '../../../common/types/latest';
|
||||
import { getClusters } from '../compliance_dashboard/get_clusters';
|
||||
import { getStats } from '../compliance_dashboard/get_stats';
|
||||
import { getSafePostureTypeRuntimeMapping } from '../../../common/runtime_mappings/get_safe_posture_type_runtime_mapping';
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import { SECURITY_SOLUTION_SAVED_OBJECT_INDEX } from '@kbn/core-saved-objects-server';
|
||||
import { SavedObjectsType } from '@kbn/core/server';
|
||||
import { rulesV1, rulesV2, rulesV3 } from '../../common/types';
|
||||
import { rulesV1, rulesV2, rulesV3 } from '@kbn/cloud-security-posture-common/schema/rules';
|
||||
import { CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE } from '../../common/constants';
|
||||
import { cspBenchmarkRuleMigrations } from './migrations';
|
||||
import { cspBenchmarkRuleSavedObjectMapping } from './mappings';
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import { SavedObjectsType } from '@kbn/core/server';
|
||||
import { SECURITY_SOLUTION_SAVED_OBJECT_INDEX } from '@kbn/core-saved-objects-server';
|
||||
import { cspSettingsSchema } from '../../common/types/rules/v4';
|
||||
import { cspSettingsSchema } from '@kbn/cloud-security-posture-common/schema/rules/v4';
|
||||
import { cspSettingsSavedObjectMapping } from './mappings';
|
||||
import { INTERNAL_CSP_SETTINGS_SAVED_OBJECT_TYPE } from '../../common/constants';
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import {
|
|||
SavedObjectUnsanitizedDoc,
|
||||
SavedObjectMigrationContext,
|
||||
} from '@kbn/core/server';
|
||||
import { rulesV1, rulesV2, rulesV3 } from '../../../common/types';
|
||||
import { rulesV1, rulesV2, rulesV3 } from '@kbn/cloud-security-posture-common/schema/rules';
|
||||
|
||||
function migrateCspBenchmarkRuleToV840(
|
||||
doc: SavedObjectUnsanitizedDoc<rulesV1.CspBenchmarkRule>,
|
||||
|
|
|
@ -9,7 +9,7 @@ import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
|
|||
import type {
|
||||
CspBenchmarkRule,
|
||||
FindCspBenchmarkRuleResponse,
|
||||
} from '@kbn/cloud-security-posture-plugin/common/types/rules/v3';
|
||||
} from '@kbn/cloud-security-posture-common/schema/rules/v3';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
import { createPackagePolicy } from './helper';
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
|
|||
import type {
|
||||
CspBenchmarkRule,
|
||||
FindCspBenchmarkRuleResponse,
|
||||
} from '@kbn/cloud-security-posture-plugin/common/types/rules/v3';
|
||||
} from '@kbn/cloud-security-posture-common/schema/rules/v3';
|
||||
import { FtrProviderContext } from '../../../ftr_provider_context';
|
||||
import { createPackagePolicy } from '../helper';
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
|
|||
import type {
|
||||
CspBenchmarkRule,
|
||||
FindCspBenchmarkRuleResponse,
|
||||
} from '@kbn/cloud-security-posture-plugin/common/types/latest';
|
||||
} from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { FtrProviderContext } from '../../../ftr_provider_context';
|
||||
import { createPackagePolicy } from '../helper';
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ import {
|
|||
} from '@kbn/cloud-security-posture-plugin/common/constants';
|
||||
import expect from '@kbn/expect';
|
||||
import Chance from 'chance';
|
||||
import { CspBenchmarkRule } from '@kbn/cloud-security-posture-plugin/common/types/latest';
|
||||
import { CspBenchmarkRule } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { FtrProviderContext } from '../ftr_provider_context';
|
||||
import { CspSecurityCommonProvider } from './helper/user_roles_utilites';
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import {
|
|||
CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE,
|
||||
DETECTION_RULE_RULES_API_CURRENT_VERSION,
|
||||
} from '@kbn/cloud-security-posture-plugin/common/constants';
|
||||
import type { CspBenchmarkRule } from '@kbn/cloud-security-posture-plugin/common/types/latest';
|
||||
import type { CspBenchmarkRule } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
// eslint-disable @kbn/imports/no_boundary_crossing
|
||||
import { generateBenchmarkRuleTags } from '@kbn/cloud-security-posture-plugin/common/utils/detection_rules';
|
||||
import type { FtrProviderContext } from '../ftr_provider_context';
|
||||
|
|
|
@ -13,7 +13,7 @@ import {
|
|||
X_ELASTIC_INTERNAL_ORIGIN_REQUEST,
|
||||
} from '@kbn/core-http-common';
|
||||
import { CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE } from '@kbn/cloud-security-posture-plugin/common/constants';
|
||||
import type { CspBenchmarkRule } from '@kbn/cloud-security-posture-plugin/common/types/latest';
|
||||
import type { CspBenchmarkRule } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import type { FtrProviderContext } from '../ftr_provider_context';
|
||||
import { CspSecurityCommonProvider } from './helper/user_roles_utilites';
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import expect from '@kbn/expect';
|
||||
import Chance from 'chance';
|
||||
import { CspBenchmarkRule } from '@kbn/cloud-security-posture-plugin/common/types/latest';
|
||||
import { CspBenchmarkRule } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE } from '@kbn/cloud-security-posture-plugin/common/constants';
|
||||
import {
|
||||
ELASTIC_HTTP_VERSION_HEADER,
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import expect from '@kbn/expect';
|
||||
import Chance from 'chance';
|
||||
import { asyncForEach } from '@kbn/std';
|
||||
import { CspBenchmarkRule } from '@kbn/cloud-security-posture-plugin/common/types/latest';
|
||||
import { CspBenchmarkRule } from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
import { CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE } from '@kbn/cloud-security-posture-plugin/common/constants';
|
||||
import {
|
||||
ELASTIC_HTTP_VERSION_HEADER,
|
||||
|
|
|
@ -9,7 +9,7 @@ import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
|
|||
import type {
|
||||
CspBenchmarkRule,
|
||||
FindCspBenchmarkRuleResponse,
|
||||
} from '@kbn/cloud-security-posture-plugin/common/types/latest';
|
||||
} from '@kbn/cloud-security-posture-common/schema/rules/latest';
|
||||
|
||||
import { createPackagePolicy } from '@kbn/test-suites-xpack/api_integration/apis/cloud_security_posture/helper';
|
||||
import { FtrProviderContext } from '../../../ftr_provider_context';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue