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

[Security Solution] Bulk editing rule custom highlighted fields #179312

Merged
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
669d295
Add custom highlighted fields through the bulk edit feature (#164301)
e40pud Mar 18, 2024
400aba4
Get all index patterns to build available custom highlighted fields
e40pud Mar 20, 2024
16256a7
Test coverage
e40pud Mar 22, 2024
1ad0a44
Fix the issue with removing all highlighted fields
e40pud Mar 24, 2024
231de6c
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
kibanamachine Mar 27, 2024
f734cfb
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
kibanamachine Apr 2, 2024
21273b4
[CI] Auto-commit changed files from 'yarn openapi:generate'
kibanamachine Apr 2, 2024
15411bd
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
kibanamachine Apr 4, 2024
414d2fb
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
kibanamachine Apr 5, 2024
01e6018
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
kibanamachine Apr 8, 2024
9baf5a4
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
kibanamachine Apr 10, 2024
733d5c5
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
kibanamachine Apr 11, 2024
2d89410
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
kibanamachine Apr 12, 2024
1bc4eb0
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
kibanamachine Apr 15, 2024
85b05c7
Test coverage
e40pud Apr 12, 2024
c0b76bc
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
kibanamachine Apr 15, 2024
d8b3995
Convert `bulk get sources` route into internal one
e40pud Apr 15, 2024
525f7fc
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
e40pud Apr 16, 2024
7d0c533
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
kibanamachine Apr 17, 2024
861afa6
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
kibanamachine Apr 22, 2024
6d3a396
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
kibanamachine Apr 22, 2024
bab5dc9
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
kibanamachine Apr 23, 2024
53ea0b6
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
kibanamachine Apr 24, 2024
411e618
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
kibanamachine Apr 25, 2024
8c7ac5a
Hide the feature behind a feature flag `bulkCustomHighlightedFieldsEn…
e40pud Apr 25, 2024
d805d62
Add basic telemetry
e40pud Apr 25, 2024
6c3c65e
Fix types
e40pud Apr 25, 2024
611c445
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
e40pud Apr 29, 2024
8ad3a67
Review feedback
e40pud Apr 29, 2024
46fc61a
Merge branch 'main' into security/on-week/2024-03-highlighted-fields
e40pud May 2, 2024
448ad4f
Show fields from the index patterns defined in Security Solution adva…
e40pud May 2, 2024
22e1788
Apply suggestions from code review
e40pud May 2, 2024
ce924b4
Updated messages
e40pud May 2, 2024
450296c
[CI] Auto-commit changed files from 'yarn openapi:generate'
kibanamachine May 2, 2024
9e0524f
Fix types
e40pud May 2, 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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
RuleActionAlertsFilter,
IndexPatternArray,
RuleTagArray,
InvestigationFields,
TimelineTemplateId,
TimelineTemplateTitle,
} from '../../model/rule_schema/common_attributes.gen';
Expand All @@ -52,6 +53,7 @@ export const BulkActionsDryRunErrCode = z.enum([
'MACHINE_LEARNING_AUTH',
'MACHINE_LEARNING_INDEX_PATTERN',
'ESQL_INDEX_PATTERN',
'INVESTIGATION_FIELDS_FEATURE',
]);
export type BulkActionsDryRunErrCodeEnum = typeof BulkActionsDryRunErrCode.enum;
export const BulkActionsDryRunErrCodeEnum = BulkActionsDryRunErrCode.enum;
Expand Down Expand Up @@ -187,6 +189,9 @@ export const BulkActionEditType = z.enum([
'add_rule_actions',
'set_rule_actions',
'set_schedule',
'add_investigation_fields',
'delete_investigation_fields',
'set_investigation_fields',
]);
export type BulkActionEditTypeEnum = typeof BulkActionEditType.enum;
export const BulkActionEditTypeEnum = BulkActionEditType.enum;
Expand Down Expand Up @@ -239,6 +244,18 @@ export const BulkActionEditPayloadTags = z.object({
value: RuleTagArray,
});

export type BulkActionEditPayloadInvestigationFields = z.infer<
typeof BulkActionEditPayloadInvestigationFields
>;
export const BulkActionEditPayloadInvestigationFields = z.object({
type: z.enum([
'add_investigation_fields',
'delete_investigation_fields',
'set_investigation_fields',
]),
value: InvestigationFields,
});

export type BulkActionEditPayloadTimeline = z.infer<typeof BulkActionEditPayloadTimeline>;
export const BulkActionEditPayloadTimeline = z.object({
type: z.literal('set_timeline'),
Expand All @@ -252,6 +269,7 @@ export type BulkActionEditPayload = z.infer<typeof BulkActionEditPayload>;
export const BulkActionEditPayload = z.union([
BulkActionEditPayloadTags,
BulkActionEditPayloadIndexPatterns,
BulkActionEditPayloadInvestigationFields,
BulkActionEditPayloadTimeline,
BulkActionEditPayloadRuleActions,
BulkActionEditPayloadSchedule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ components:
- MACHINE_LEARNING_AUTH
- MACHINE_LEARNING_INDEX_PATTERN
- ESQL_INDEX_PATTERN
- INVESTIGATION_FIELDS_FEATURE

NormalizedRuleError:
type: object
Expand Down Expand Up @@ -281,6 +282,9 @@ components:
- add_rule_actions
- set_rule_actions
- set_schedule
- add_investigation_fields
- delete_investigation_fields
- set_investigation_fields

# Per rulesClient.bulkEdit rules actions operation contract (x-pack/plugins/alerting/server/rules_client/rules_client.ts) normalized rule action object is expected (NormalizedAlertAction) as value for the edit operation
NormalizedRuleAction:
Expand Down Expand Up @@ -381,6 +385,21 @@ components:
- type
- value

BulkActionEditPayloadInvestigationFields:
type: object
properties:
type:
type: string
enum:
- add_investigation_fields
- delete_investigation_fields
- set_investigation_fields
value:
$ref: '../../model/rule_schema/common_attributes.schema.yaml#/components/schemas/InvestigationFields'
required:
- type
- value

BulkActionEditPayloadTimeline:
type: object
properties:
Expand All @@ -406,6 +425,7 @@ components:
anyOf:
- $ref: '#/components/schemas/BulkActionEditPayloadTags'
- $ref: '#/components/schemas/BulkActionEditPayloadIndexPatterns'
- $ref: '#/components/schemas/BulkActionEditPayloadInvestigationFields'
- $ref: '#/components/schemas/BulkActionEditPayloadTimeline'
- $ref: '#/components/schemas/BulkActionEditPayloadRuleActions'
- $ref: '#/components/schemas/BulkActionEditPayloadSchedule'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ describe('Perform bulk action request schema', () => {
expectParseError(result);

expect(stringifyZodError(result.error)).toMatchInlineSnapshot(
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 9 more"`
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 11 more"`
);
});

Expand Down Expand Up @@ -249,7 +249,7 @@ describe('Perform bulk action request schema', () => {
expectParseError(result);

expect(stringifyZodError(result.error)).toMatchInlineSnapshot(
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 9 more"`
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 11 more"`
);
});

Expand Down Expand Up @@ -299,6 +299,62 @@ describe('Perform bulk action request schema', () => {
});
});

describe('investigation_fields', () => {
test('valid request: set_investigation_fields edit action', () => {
const payload: PerformBulkActionRequestBody = {
query: 'name: test',
action: BulkActionTypeEnum.edit,
[BulkActionTypeEnum.edit]: [
{
type: BulkActionEditTypeEnum.set_investigation_fields,
value: { field_names: ['field-1'] },
},
],
};

const result = PerformBulkActionRequestBody.safeParse(payload);

expectParseSuccess(result);
expect(result.data).toEqual(payload);
});

test('valid request: add_investigation_fields edit action', () => {
const payload: PerformBulkActionRequestBody = {
query: 'name: test',
action: BulkActionTypeEnum.edit,
[BulkActionTypeEnum.edit]: [
{
type: BulkActionEditTypeEnum.add_investigation_fields,
value: { field_names: ['field-2'] },
},
],
};

const result = PerformBulkActionRequestBody.safeParse(payload);

expectParseSuccess(result);
expect(result.data).toEqual(payload);
});

test('valid request: delete_investigation_fields edit action', () => {
const payload: PerformBulkActionRequestBody = {
query: 'name: test',
action: BulkActionTypeEnum.edit,
[BulkActionTypeEnum.edit]: [
{
type: BulkActionEditTypeEnum.delete_investigation_fields,
value: { field_names: ['field-3'] },
},
],
};

const result = PerformBulkActionRequestBody.safeParse(payload);

expectParseSuccess(result);
expect(result.data).toEqual(payload);
});
});

describe('timeline', () => {
test('invalid request: wrong timeline payload type', () => {
const payload = {
Expand All @@ -311,7 +367,7 @@ describe('Perform bulk action request schema', () => {

expectParseError(result);
expect(stringifyZodError(result.error)).toMatchInlineSnapshot(
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 7 more"`
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 9 more"`
);
});

Expand All @@ -333,7 +389,7 @@ describe('Perform bulk action request schema', () => {

expectParseError(result);
expect(stringifyZodError(result.error)).toMatchInlineSnapshot(
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 10 more"`
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 12 more"`
);
});

Expand Down Expand Up @@ -371,7 +427,7 @@ describe('Perform bulk action request schema', () => {

expectParseError(result);
expect(stringifyZodError(result.error)).toMatchInlineSnapshot(
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 7 more"`
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 9 more"`
);
});

Expand Down Expand Up @@ -416,7 +472,7 @@ describe('Perform bulk action request schema', () => {

expectParseError(result);
expect(stringifyZodError(result.error)).toMatchInlineSnapshot(
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 10 more"`
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 12 more"`
);
});

Expand All @@ -438,7 +494,7 @@ describe('Perform bulk action request schema', () => {

expectParseError(result);
expect(stringifyZodError(result.error)).toMatchInlineSnapshot(
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 10 more"`
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 12 more"`
);
});

Expand Down Expand Up @@ -476,7 +532,7 @@ describe('Perform bulk action request schema', () => {

expectParseError(result);
expect(stringifyZodError(result.error)).toMatchInlineSnapshot(
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 7 more"`
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 9 more"`
);
});

Expand All @@ -498,7 +554,7 @@ describe('Perform bulk action request schema', () => {

expectParseError(result);
expect(stringifyZodError(result.error)).toMatchInlineSnapshot(
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 11 more"`
`"action: Invalid literal value, expected \\"delete\\", action: Invalid literal value, expected \\"disable\\", action: Invalid literal value, expected \\"enable\\", action: Invalid literal value, expected \\"export\\", action: Invalid literal value, expected \\"duplicate\\", and 13 more"`
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import type {
BulkActionEditPayloadIndexPatterns,
BulkActionEditPayloadInvestigationFields,
BulkActionEditPayloadRuleActions,
BulkActionEditPayloadSchedule,
BulkActionEditPayloadTags,
Expand All @@ -26,5 +27,6 @@ export type BulkActionEditForRuleAttributes =
*/
export type BulkActionEditForRuleParams =
| BulkActionEditPayloadIndexPatterns
| BulkActionEditPayloadInvestigationFields
| BulkActionEditPayloadTimeline
| BulkActionEditPayloadSchedule;
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 { z } from 'zod';

/*
* NOTICE: Do not edit this file manually.
* This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator.
*
* info:
* title: Get Rules Sources API endpoint
* version: 2023-10-31
*/

export type BulkGetRulesSourcesRequestBody = z.infer<typeof BulkGetRulesSourcesRequestBody>;
export const BulkGetRulesSourcesRequestBody = z.object({
/**
* Query to filter rules
*/
query: z.string().optional(),
/**
* Array of rule IDs
*/
ids: z.array(z.string()).min(1).optional(),
});
export type BulkGetRulesSourcesRequestBodyInput = z.input<typeof BulkGetRulesSourcesRequestBody>;

export type BulkGetRulesSourcesResponse = z.infer<typeof BulkGetRulesSourcesResponse>;
export const BulkGetRulesSourcesResponse = z.object({
/**
* Array of index patterns
*/
indexPatterns: z.array(z.string()).optional(),
/**
* Array of data view ids
*/
dataViewIds: z.array(z.string()).optional(),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 { BulkGetRulesSourcesRequestBody } from './bulk_get_sources_route.gen';

export const getPerformBulkGetSourcesSchemaMock = (): BulkGetRulesSourcesRequestBody => ({
query: '',
ids: undefined,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
openapi: 3.0.0
info:
title: Get Rules Sources API endpoint
version: '2023-10-31'
paths:
/api/detection_engine/rules/_bulk_get_sources:
summary: Returns rules sources
post:
operationId: BulkGetRulesSources
x-codegen-enabled: true
summary: Get rules sources
description: Returns rules sources.
tags:
- Bulk API
requestBody:
content:
application/json:
schema:
x-inline: true
type: object
properties:
query:
type: string
description: Query to filter rules
ids:
type: array
description: Array of rule IDs
minItems: 1
items:
type: string
responses:
200:
description: OK
content:
application/json:
schema:
type: object
properties:
indexPatterns:
type: array
description: Array of index patterns
items:
type: string
dataViewIds:
type: array
description: Array of data view ids
items:
type: string
Loading