Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
f97c940
preliminary adding types to csp and csp-common packages
animehart Aug 20, 2024
5989868
moving types from csp plugin to csp packages + updating import and ex…
animehart Aug 21, 2024
6283bd4
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 21, 2024
7fafa52
attempt on fixing bundle size leak
animehart Aug 21, 2024
dad76fd
Merge branch 'misconfiguration-preview-refactor-phase-2' of github.co…
animehart Aug 21, 2024
72f00b0
change schema import to be from schema folder + updating index.ts exp…
animehart Aug 23, 2024
783626e
forgot to add index.ts in last commit
animehart Aug 23, 2024
a89617d
removed re export on csp plugin + updated imports to be directly from…
animehart Aug 23, 2024
6600a34
fix ci failure: forgot to edit some file
animehart Aug 23, 2024
19d7451
fix check types failure
animehart Aug 23, 2024
51b44b9
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 23, 2024
e2b8f48
fix failed FTR due to forgot updating imports on that file
animehart Aug 23, 2024
4496119
fix conflict merge
animehart Aug 23, 2024
9f2814e
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 23, 2024
113376a
remove re exports and update imports of csp_finding related types to …
animehart Aug 24, 2024
c1a3b6a
Merge branch 'misconfiguration-preview-refactor-phase-2' of github.co…
animehart Aug 24, 2024
3398ecf
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 24, 2024
8c69b3e
fix check types failure + removed re-export and update import stateme…
animehart Aug 24, 2024
0c1f750
Merge branch 'misconfiguration-preview-refactor-phase-2' of github.co…
animehart Aug 24, 2024
447c47b
updating CspStatusCode imports to be directly from csp common package
animehart Aug 24, 2024
feae686
Merge branch 'main' into misconfiguration-preview-refactor-phase-2
animehart Aug 26, 2024
ceafb0b
PR Comments: Updated type imports to explicitly use import type inste…
animehart Aug 26, 2024
6b8adb6
fix conflict
animehart Aug 26, 2024
02bbdb8
added all Version of Rules into common csp package + updated usage of…
animehart Aug 26, 2024
7cb59d3
removed rules versions from csp plugin + updated imports for rule ve…
animehart Aug 26, 2024
c349bac
Reverting and Updating some changes from Phase 2 so now imports for R…
animehart Aug 26, 2024
dff574d
fix lint and check types ci failures
animehart Aug 26, 2024
1874c0c
added hooks and functions into csp packages
animehart Aug 27, 2024
5a3aa7d
fix index.ts, quick checks failure
animehart Aug 27, 2024
0fcacb6
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Aug 27, 2024
e96f6d8
updated function imports to be directly for csp packages + deleted or…
animehart Aug 27, 2024
85f8ca5
Merge branch 'misconfiguration-preview-refactor-phase-3' of github.co…
animehart Aug 27, 2024
57dee10
FIX MERGE CONFLICTS
animehart Aug 27, 2024
8925785
fix check types failed, removed useless file
animehart Aug 27, 2024
6343043
Merge branch 'main' into misconfiguration-preview-refactor-phase-3
animehart Aug 27, 2024
3078818
removed a useMisConfigurationPreview hook to make sure that hooks is …
animehart Aug 27, 2024
8bdeb63
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Aug 27, 2024
050e23d
PR Comments: Addressing PR Comments + Updated Imports for BenchmarksC…
animehart Aug 28, 2024
54bb14c
Merge branch 'misconfiguration-preview-refactor-phase-3' of github.co…
animehart Aug 28, 2024
c4127c5
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Aug 28, 2024
f5f3072
missed one PR comment for previous commit, adding it now
animehart Aug 28, 2024
e5ae31a
Merge branch 'misconfiguration-preview-refactor-phase-3' of github.co…
animehart Aug 28, 2024
b01e87c
PR Comments, removed types file and re added types into types folder
animehart Aug 28, 2024
39ae84b
Merge branch 'main' into misconfiguration-preview-refactor-phase-3
animehart Aug 28, 2024
2395a7d
Merge branch 'main' into misconfiguration-preview-refactor-phase-3
animehart Aug 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions x-pack/packages/kbn-cloud-security-posture-common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
12 changes: 12 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture-common/jest.config.js
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.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../../..',
roots: ['<rootDir>/x-pack/packages/kbn-cloud-security-posture-common'],
};
48 changes: 0 additions & 48 deletions x-pack/packages/kbn-cloud-security-posture-common/schema/rules.ts

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
Expand Up @@ -5,4 +5,4 @@
* 2.0.
*/

export { ruleStateAttributes, cspBenchmarkRuleMetadataSchema, rulesStates } from './rules';
export * from './v5';
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,44 @@
*/

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;

// Since version 8.7.0

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,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>;

Expand All @@ -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({
Expand Down Expand Up @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@
],
"kbn_references": [
"@kbn/config-schema",
"@kbn/data-views-plugin",
"@kbn/i18n",
]
}
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';
Copy link
Copy Markdown
Contributor

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.ts or another way around split types.ts into meaningful files, eg. types/status.ts and types/finding.ts

Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,15 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 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;
/*
* 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 { EcsDataStream, EcsEvent } from '@elastic/ecs';
import type { CspBenchmarkRuleMetadata } from '../schema/rules/latest';

export interface CspFinding {
'@timestamp': string;
Expand Down
51 changes: 51 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture-common/types/status.ts
Original file line number Diff line number Diff line change
@@ -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;
Loading