-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Cloud Security] Misconfiguration preview & Refactor CSP Plugin to include new package PHASE 3 #191317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Cloud Security] Misconfiguration preview & Refactor CSP Plugin to include new package PHASE 3 #191317
Changes from 37 commits
f97c940
5989868
6283bd4
7fafa52
dad76fd
72f00b0
783626e
a89617d
6600a34
19d7451
51b44b9
e2b8f48
4496119
9f2814e
113376a
c1a3b6a
3398ecf
8c69b3e
0c1f750
447c47b
feae686
ceafb0b
6b8adb6
02bbdb8
7cb59d3
c349bac
dff574d
1874c0c
5a3aa7d
0fcacb6
e96f6d8
85f8ca5
57dee10
8925785
6343043
3078818
8bdeb63
050e23d
54bb14c
c4127c5
f5f3072
e5ae31a
b01e87c
39ae84b
2395a7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,5 +16,8 @@ | |
| ], | ||
| "kbn_references": [ | ||
| "@kbn/config-schema", | ||
| "@kbn/data-views-plugin", | ||
| "@kbn/i18n", | ||
| "@kbn/core", | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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'; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * 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 type { CspBenchmarkRulesStates } from '../schema/rules/latest'; | ||
|
|
||
| export const extractErrorMessage = (e: unknown, defaultMessage = 'Unknown Error'): string => { | ||
|
opauloh marked this conversation as resolved.
Outdated
|
||
| if (e instanceof Error) return e.message; | ||
| if (typeof e === 'string') return e; | ||
|
|
||
| return defaultMessage; // TODO: i18n | ||
| }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's fix this todo: 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; | ||
| }; | ||
|
opauloh marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| */ | ||
| import type { CoreStart } from '@kbn/core/public'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { extractErrorMessage } from '../../../common/utils/helpers'; | ||
| import { extractErrorMessage } from './helpers'; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this file be in |
||
| const SEARCH_FAILED_TEXT = i18n.translate( | ||
| 'xpack.csp.findings.findingsErrorToast.searchFailedTitle', | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,16 +6,18 @@ | |||||
| */ | ||||||
|
|
||||||
| 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'; | ||||||
| import type { CspClientPluginStartDeps } from '../../type'; | ||||||
|
|
||||||
| const getCspSetupStatusQueryKey = 'csp_status_key'; | ||||||
|
|
||||||
| export const useCspSetupStatusApi = ( | ||||||
| options?: UseQueryOptions<CspSetupStatus, unknown, CspSetupStatus> | ||||||
| ) => { | ||||||
| const { http } = useKibana().services; | ||||||
| const { http } = useKibana<CoreStart & CspClientPluginStartDeps>().services; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| return useQuery<CspSetupStatus, unknown, CspSetupStatus>( | ||||||
| [getCspSetupStatusQueryKey], | ||||||
| () => http.get<CspSetupStatus>(STATUS_ROUTE_PATH, { version: STATUS_API_CURRENT_VERSION }), | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,13 +10,15 @@ 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'; | ||
| import type { CspClientPluginStartDeps } from '../../type'; | ||
|
|
||
| export const getRuleStatesKey = ['get_rules_state_key']; | ||
|
|
||
| export const useGetCspBenchmarkRulesStatesApi = () => { | ||
| const { http } = useKibana().services; | ||
| const { http } = useKibana<CoreStart & CspClientPluginStartDeps>().services; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,5 +5,4 @@ | |
| * 2.0. | ||
| */ | ||
|
|
||
| export * from './rules/v5'; | ||
| export * from './benchmarks/v2'; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's either put it under
./types.tsor another way around splittypes.tsinto meaningful files, eg.types/status.tsandtypes/finding.ts