-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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 2 #190933
Merged
animehart
merged 23 commits into
elastic:main
from
animehart:misconfiguration-preview-refactor-phase-2
Aug 27, 2024
+392
−303
Merged
[Cloud Security] Misconfiguration preview & Refactor CSP Plugin to include new package PHASE 2 #190933
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f97c940
preliminary adding types to csp and csp-common packages
animehart 5989868
moving types from csp plugin to csp packages + updating import and ex…
animehart 6283bd4
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 7fafa52
attempt on fixing bundle size leak
animehart dad76fd
Merge branch 'misconfiguration-preview-refactor-phase-2' of github.co…
animehart 72f00b0
change schema import to be from schema folder + updating index.ts exp…
animehart 783626e
forgot to add index.ts in last commit
animehart a89617d
removed re export on csp plugin + updated imports to be directly from…
animehart 6600a34
fix ci failure: forgot to edit some file
animehart 19d7451
fix check types failure
animehart 51b44b9
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine e2b8f48
fix failed FTR due to forgot updating imports on that file
animehart 4496119
fix conflict merge
animehart 9f2814e
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 113376a
remove re exports and update imports of csp_finding related types to …
animehart c1a3b6a
Merge branch 'misconfiguration-preview-refactor-phase-2' of github.co…
animehart 3398ecf
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 8c69b3e
fix check types failure + removed re-export and update import stateme…
animehart 0c1f750
Merge branch 'misconfiguration-preview-refactor-phase-2' of github.co…
animehart 447c47b
updating CspStatusCode imports to be directly from csp common package
animehart feae686
Merge branch 'main' into misconfiguration-preview-refactor-phase-2
animehart ceafb0b
PR Comments: Updated type imports to explicitly use import type inste…
animehart 6b8adb6
fix conflict
animehart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
x-pack/packages/kbn-cloud-security-posture-common/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* 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 const KSPM_POLICY_TEMPLATE = 'kspm'; | ||
export const CSPM_POLICY_TEMPLATE = 'cspm'; | ||
export const CDR_LATEST_NATIVE_MISCONFIGURATIONS_INDEX_PATTERN = | ||
'logs-cloud_security_posture.findings_latest-default'; | ||
export const CDR_LATEST_THIRD_PARTY_MISCONFIGURATIONS_INDEX_PATTERN = | ||
'logs-*_latest_misconfigurations_cdr'; | ||
export const CDR_MISCONFIGURATIONS_INDEX_PATTERN = `${CDR_LATEST_NATIVE_MISCONFIGURATIONS_INDEX_PATTERN},${CDR_LATEST_THIRD_PARTY_MISCONFIGURATIONS_INDEX_PATTERN}`; | ||
export const LATEST_FINDINGS_RETENTION_POLICY = '26h'; | ||
export const MAX_FINDINGS_TO_LOAD = 500; | ||
export const CSP_GET_BENCHMARK_RULES_STATE_ROUTE_PATH = | ||
'/internal/cloud_security_posture/rules/_get_states'; | ||
export const CSP_GET_BENCHMARK_RULES_STATE_API_CURRENT_VERSION = '1'; | ||
export const STATUS_ROUTE_PATH = '/internal/cloud_security_posture/status'; | ||
export const STATUS_API_CURRENT_VERSION = '1'; |
22 changes: 22 additions & 0 deletions
22
x-pack/packages/kbn-cloud-security-posture-common/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
// Careful of exporting anything from this file as any file(s) you export here will cause your page bundle size to increase. | ||
// If you're using functions/types/etc... internally or within integration tests it's best to import directly from their paths | ||
// than expose the functions/types/etc... here. You should _only_ expose functions/types/etc... that need to be shared with other plugins here. | ||
|
||
export type { | ||
CspStatusCode, | ||
IndexStatus, | ||
IndexDetails, | ||
BaseCspSetupBothPolicy, | ||
BaseCspSetupStatus, | ||
CspSetupStatus, | ||
CspFinding, | ||
} from './types'; | ||
export * from './constants'; | ||
export type { CspBenchmarkRuleMetadata, CspBenchmarkRulesStates } from './schema/rules'; |
8 changes: 8 additions & 0 deletions
8
x-pack/packages/kbn-cloud-security-posture-common/schema/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* 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 { ruleStateAttributes, cspBenchmarkRuleMetadataSchema, rulesStates } from './rules'; |
48 changes: 48 additions & 0 deletions
48
x-pack/packages/kbn-cloud-security-posture-common/schema/rules.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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>; |
20 changes: 20 additions & 0 deletions
20
x-pack/packages/kbn-cloud-security-posture-common/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"extends": "../../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "target/types", | ||
"types": [ | ||
"jest", | ||
"node", | ||
] | ||
}, | ||
"include": [ | ||
"**/*.ts", | ||
"**/*.tsx", | ||
], | ||
"exclude": [ | ||
"target/**/*" | ||
], | ||
"kbn_references": [ | ||
"@kbn/config-schema", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* 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 * from './type'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"extends": "../../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "target/types", | ||
"types": [ | ||
"jest", | ||
"node", | ||
"react" | ||
] | ||
}, | ||
"include": [ | ||
"**/*.ts", | ||
"**/*.tsx", | ||
], | ||
"exclude": [ | ||
"target/**/*" | ||
], | ||
"kbn_references": [ | ||
"@kbn/core", | ||
"@kbn/licensing-plugin", | ||
"@kbn/data-views-plugin", | ||
"@kbn/unified-search-plugin", | ||
"@kbn/ui-actions-plugin", | ||
"@kbn/field-formats-plugin", | ||
"@kbn/data-view-field-editor-plugin", | ||
"@kbn/data-plugin", | ||
"@kbn/kibana-utils-plugin", | ||
"@kbn/charts-plugin", | ||
"@kbn/discover-plugin", | ||
"@kbn/fleet-plugin", | ||
"@kbn/usage-collection-plugin", | ||
"@kbn/share-plugin", | ||
"@kbn/es-query", | ||
"@kbn/cloud-plugin", | ||
"@kbn/spaces-plugin", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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 type { CloudSetup } from '@kbn/cloud-plugin/public'; | ||
import type { LicensingPluginStart } from '@kbn/licensing-plugin/public'; | ||
import { DataViewsServicePublic } from '@kbn/data-views-plugin/public'; | ||
import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public'; | ||
import { UiActionsStart } from '@kbn/ui-actions-plugin/public'; | ||
import { FieldFormatsStart } from '@kbn/field-formats-plugin/public'; | ||
import { IndexPatternFieldEditorStart } from '@kbn/data-view-field-editor-plugin/public'; | ||
import type { DataPublicPluginStart } from '@kbn/data-plugin/public'; | ||
import { ToastsStart } from '@kbn/core/public'; | ||
import { Storage } from '@kbn/kibana-utils-plugin/public'; | ||
|
||
import type { ChartsPluginStart } from '@kbn/charts-plugin/public'; | ||
import type { DiscoverStart } from '@kbn/discover-plugin/public'; | ||
import type { FleetStart } from '@kbn/fleet-plugin/public'; | ||
import type { UsageCollectionStart } from '@kbn/usage-collection-plugin/public'; | ||
import { SharePluginStart } from '@kbn/share-plugin/public'; | ||
import { SpacesPluginStart } from '@kbn/spaces-plugin/public'; | ||
|
||
import type { BoolQuery } from '@kbn/es-query'; | ||
export interface FindingsBaseEsQuery { | ||
query?: { | ||
bool: BoolQuery; | ||
}; | ||
} | ||
|
||
export interface CspClientPluginStartDeps { | ||
// required | ||
data: DataPublicPluginStart; | ||
dataViews: DataViewsServicePublic; | ||
dataViewFieldEditor: IndexPatternFieldEditorStart; | ||
unifiedSearch: UnifiedSearchPublicPluginStart; | ||
uiActions: UiActionsStart; | ||
fieldFormats: FieldFormatsStart; | ||
toastNotifications: ToastsStart; | ||
charts: ChartsPluginStart; | ||
discover: DiscoverStart; | ||
fleet: FleetStart; | ||
licensing: LicensingPluginStart; | ||
share: SharePluginStart; | ||
storage: Storage; | ||
spaces: SpacesPluginStart; | ||
cloud: CloudSetup; | ||
|
||
// optional | ||
usageCollection?: UsageCollectionStart; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I still think we need to move the whole
common/types
with all the versions into our common package. Otherwise the versioning won't work for us. Imagine you need to make a breaking change to the schema. If you do it in thecspBenchmarkRuleMetadataSchema
in the package you would break the versioning as it is imported here in the v3. To do it properly you need to introduce the new version of the schema, the same way as we migratedcspBenchmarkRuleMetadataSchema
between v2 and v3.I'm not sure if we can reduce the number of changes caused by moving the whole versioned types and schemas, but without it we are kind of breaking the versioning
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.
again to not make the change too large, maybe it's ok to proceed with this PR but then create a new PR right away moving the versioned types and schemas to our shared package so that we don't risk