Skip to content
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 Posture] - Deprecate csp rule remove migration object #148530

Merged
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
377e022
Fixing tests + types + registered saved objects types
ofiriro3 Jan 2, 2023
747bdcb
Merge branch 'main' of github.com:ofiriro3/kibana
ofiriro3 Jan 3, 2023
f19225d
Merge branch 'main' of github.com:ofiriro3/kibana
ofiriro3 Jan 3, 2023
e8a9c28
Merge branch 'main' of github.com:ofiriro3/kibana
ofiriro3 Jan 5, 2023
66440c5
Deprecating the csp_rule saved object
ofiriro3 Jan 9, 2023
f5e883b
Merge branch 'main' into deprecate_csp_rule_remove_migration_object
ofiriro3 Jan 10, 2023
744aac4
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jan 10, 2023
0323dac
Merge branch 'main' into deprecate_csp_rule_remove_migration_object
ofiriro3 Jan 10, 2023
9b105c6
Merge branch 'main' of github.com:ofiriro3/kibana
ofiriro3 Jan 15, 2023
1551ca2
Adding the csp_rule to the unused_types.ts
ofiriro3 Jan 15, 2023
58f72e3
Update translation
ofiriro3 Jan 15, 2023
16f1c8d
Update translation
ofiriro3 Jan 15, 2023
1c015b7
Merge branch 'main' of github.com:ofiriro3/kibana
ofiriro3 Jan 15, 2023
5427892
Merge branch 'main' into deprecate_csp_rule_remove_migration_object
ofiriro3 Jan 15, 2023
55e9f05
Fix core tests
rudolf Jan 16, 2023
8a46843
Merge branch 'main' into deprecate_csp_rule_remove_migration_object
ofiriro3 Jan 16, 2023
911123e
Merge branch 'main' into deprecate_csp_rule_remove_migration_object
ofiriro3 Jan 17, 2023
5c371e3
Merge branch 'main' into deprecate_csp_rule_remove_migration_object
ofiriro3 Jan 24, 2023
914c815
remove CSP_RULE from constants.ts
ofiriro3 Jan 24, 2023
07e4120
Merge branch 'main' of github.com:ofiriro3/kibana
ofiriro3 Jan 24, 2023
a609659
merging main to mine
ofiriro3 Jan 24, 2023
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export const REMOVED_TYPES: string[] = [
'ui-counter',
// Deprecated, no longer used since 7.13 https://github.com/elastic/kibana/pull/94923/files
'application_usage_transactional',
// Deprecated, no longer used since 8.7 https://github.com/elastic/kibana/pull/148530
'csp_rule',
].sort();

// When migrating from the outdated index we use a read query which excludes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ describe('createInitialState', () => {
"type": "cases-sub-case",
},
},
Object {
"term": Object {
"type": "csp_rule",
},
},
Object {
"term": Object {
"type": "file-upload-telemetry",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ describe('checking migration metadata changes on all registered SO types', () =>
"connector_token": "fa5301aa5a2914795d3b1b82d0a49939444009da",
"core-usage-stats": "f40a213da2c597b0de94e364a4326a5a1baa4ca9",
"csp-rule-template": "d6104585d0b032355c64a7dbf2a834163351cb1c",
"csp_rule": "d2bb53ea5d2bdfba1a835ad8956dfcd2b2c32e19",
"dashboard": "7e37790f802b39c852f905c010e13674e893105a",
"endpoint:user-artifact": "f94c250a52b30d0a2d32635f8b4c5bdabd1e25c0",
"endpoint:user-artifact-manifest": "8c14d49a385d5d1307d956aa743ec78de0b2be88",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// TODO: this needs to be defined in a versioned schema
import type { EcsEvent } from '@kbn/ecs';
import type { CspRuleMetadata } from './csp_rule_metadata';
import type { CspRuleTemplateMetadata } from './csp_rule_template_metadata';

export interface CspFinding {
'@timestamp': string;
Expand All @@ -19,7 +19,7 @@ export interface CspFinding {
};
result: CspFindingResult;
resource: CspFindingResource;
rule: CspRuleMetadata;
rule: CspRuleTemplateMetadata;
host: CspFindingHost;
event: EcsEvent;
agent: CspFindingAgent;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/
import { schema as rt, TypeOf } from '@kbn/config-schema';
import { cspRuleMetadataSchema } from './csp_rule_metadata';
import { cspRuleTemplateMetadataSchema } from './csp_rule_template_metadata';

export const cspRuleTemplateSchemaV830 = rt.object({
audit: rt.string(),
Expand All @@ -29,12 +29,12 @@ export const cspRuleTemplateSchemaV830 = rt.object({

export const cspRuleTemplateSchemaV840 = rt.object({
enabled: rt.boolean(),
metadata: cspRuleMetadataSchema,
metadata: cspRuleTemplateMetadataSchema,
muted: rt.boolean(),
});

export const cspRuleTemplateSchemaV870 = rt.object({
metadata: cspRuleMetadataSchema,
metadata: cspRuleTemplateMetadataSchema,
});

export type CspRuleTemplateV830 = TypeOf<typeof cspRuleTemplateSchemaV830>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { schema as rt, TypeOf } from '@kbn/config-schema';

export const cspRuleMetadataSchema = rt.object({
export const cspRuleTemplateMetadataSchema = rt.object({
audit: rt.string(),
benchmark: rt.object({
name: rt.string(),
Expand All @@ -28,4 +28,4 @@ export const cspRuleMetadataSchema = rt.object({
version: rt.string(),
});

export type CspRuleMetadata = TypeOf<typeof cspRuleMetadataSchema>;
export type CspRuleTemplateMetadata = TypeOf<typeof cspRuleTemplateMetadataSchema>;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@
* 2.0.
*/

export * from './csp_rule';
export * from './csp_rule_metadata';
export * from './csp_rule_template_metadata';
export * from './csp_rule_template';
export * from './csp_rules_configuration';
6 changes: 3 additions & 3 deletions x-pack/plugins/cloud_security_posture/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { PackagePolicy, AgentPolicy } from '@kbn/fleet-plugin/common';
import { SUPPORTED_CLOUDBEAT_INPUTS, SUPPORTED_POLICY_TEMPLATES } from './constants';
import type { CspRuleMetadata } from './schemas/csp_rule_metadata';
import type { CspRuleTemplateMetadata } from './schemas/csp_rule_template_metadata';

export type Evaluation = 'passed' | 'failed' | 'NA';
/** number between 1-100 */
Expand Down Expand Up @@ -100,8 +100,8 @@ export interface Benchmark {
rules_count: number;
}

export type BenchmarkId = CspRuleMetadata['benchmark']['id'];
export type BenchmarkName = CspRuleMetadata['benchmark']['name'];
export type BenchmarkId = CspRuleTemplateMetadata['benchmark']['id'];
export type BenchmarkName = CspRuleTemplateMetadata['benchmark']['name'];

// Fleet Integration types
export type PostureInput = typeof SUPPORTED_CLOUDBEAT_INPUTS[number];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
import { RulesContainer } from './rules_container';
import { render, screen } from '@testing-library/react';
import { QueryClient } from '@tanstack/react-query';
import { useFindCspRules, type RuleSavedObject } from './use_csp_rules';
import { useFindCspRuleTemplates, type RuleSavedObject } from './use_csp_rules';
import * as TEST_SUBJECTS from './test_subjects';
import { Chance } from 'chance';
import { TestProvider } from '../../test/test_provider';
Expand All @@ -19,8 +19,8 @@ import { coreMock } from '@kbn/core/public/mocks';
const chance = new Chance();

jest.mock('./use_csp_rules', () => ({
useFindCspRules: jest.fn(),
useBulkUpdateCspRules: jest.fn(),
useFindCspRuleTemplates: jest.fn(),
useBulkUpdateCspRuleTemplates: jest.fn(),
}));

jest.mock('react-router-dom', () => ({
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('<RulesContainer />', () => {
const Wrapper = getWrapper();
const rule1 = getRuleMock({ enabled: true });

(useFindCspRules as jest.Mock).mockReturnValue({
(useFindCspRuleTemplates as jest.Mock).mockReturnValue({
status: 'success',
data: {
total: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { extractErrorMessage, isNonNullable } from '../../../common/utils/helper
import { RulesTable } from './rules_table';
import { RulesTableHeader } from './rules_table_header';
import {
useFindCspRules,
useFindCspRuleTemplates,
type RuleSavedObject,
type RulesQuery,
type RulesQueryResult,
Expand Down Expand Up @@ -74,7 +74,7 @@ export const RulesContainer = () => {
perPage: pageSize || 10,
});

const { data, status, error } = useFindCspRules(
const { data, status, error } = useFindCspRuleTemplates(
{
filter: rulesQuery.filter,
search: rulesQuery.search,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const RulesTable = ({
};

const rowProps = (row: RuleSavedObject) => ({
['data-test-subj']: TEST_SUBJECTS.getCspRulesTableRowItemTestId(row.id),
['data-test-subj']: TEST_SUBJECTS.getCspRuleTemplatesTableRowItemTestId(row.id),
style: { background: row.id === selectedRuleId ? euiTheme.colors.highlight : undefined },
onClick: (e: MouseEvent) => {
const tag = (e.target as HTMLDivElement).tagName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export const CSP_RULES_TABLE = 'csp_rules_table';
export const CSP_RULES_TABLE_ROW_ITEM_NAME = 'csp_rules_table_row_item_name';
export const CSP_RULES_FLYOUT_CONTAINER = 'csp_rules_flyout_container';

export const getCspRulesTableRowItemTestId = (id: string) =>
export const getCspRuleTemplatesTableRowItemTestId = (id: string) =>
`${CSP_RULES_TABLE_ROW_ITEM_NAME}_${id}`;
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export type RuleSavedObject = Omit<
export type RulesQuery = Required<
Pick<SavedObjectsFindOptions, 'search' | 'page' | 'perPage' | 'filter'>
>;
export type RulesQueryResult = ReturnType<typeof useFindCspRules>;
export type RulesQueryResult = ReturnType<typeof useFindCspRuleTemplates>;

export const useFindCspRules = (
export const useFindCspRuleTemplates = (
{ search, page, perPage, filter }: RulesQuery,
packagePolicyId: string
) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ describe('benchmarks API', () => {
});
});

describe('test addPackagePolicyCspRules', () => {
describe('test addPackagePolicyCspRuleTemplates', () => {
it('should retrieve the rules count by the filtered benchmark type', async () => {
const benchmark = 'cis_k8s';
mockSoClient.find.mockResolvedValueOnce({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,6 @@

import { SavedObjectsTypeMappingDefinition } from '@kbn/core/server';

export const cspRuleSavedObjectMapping: SavedObjectsTypeMappingDefinition = {
dynamic: false,
properties: {
metadata: {
type: 'object',
properties: {
name: {
type: 'keyword',
fields: {
text: {
type: 'text',
},
},
},
},
},
package_policy_id: {
type: 'keyword',
},
policy_id: {
type: 'keyword',
},
enabled: {
type: 'boolean',
fields: {
keyword: {
type: 'keyword',
},
},
},
},
};

export const cspRuleTemplateSavedObjectMapping: SavedObjectsTypeMappingDefinition = {
dynamic: false,
properties: {
Expand Down
Loading