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][Detection Engine] move lists to data stream #162508

Merged
merged 78 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
245ba57
add test element
vitaliidm May 5, 2023
c3d1806
Merge branch 'elastic:main' into main
vitaliidm May 5, 2023
cea3e3b
Revert "add test element"
vitaliidm May 5, 2023
8a240c5
Merge remote-tracking branch 'upstream/main'
vitaliidm May 10, 2023
d1b32ab
Merge branch 'elastic:main' into main
vitaliidm May 16, 2023
1b8bd2b
Merge branch 'elastic:main' into main
vitaliidm May 18, 2023
711fe3e
Merge remote-tracking branch 'upstream/main'
vitaliidm Jun 7, 2023
5272556
Merge branch 'main' of ssh://github.com/vitaliidm/kibana
vitaliidm Jun 7, 2023
9589ab4
Merge remote-tracking branch 'upstream/main'
vitaliidm Jun 9, 2023
fcd9618
Merge remote-tracking branch 'upstream/main'
vitaliidm Jun 30, 2023
5b12314
Merge remote-tracking branch 'upstream/main'
vitaliidm Jul 10, 2023
0b09ae1
Merge remote-tracking branch 'upstream/main'
vitaliidm Jul 17, 2023
82db206
Merge remote-tracking branch 'upstream/main'
vitaliidm Jul 25, 2023
8eb1e39
[Security Solution][Detection Engine] move lists to data stream
vitaliidm Jul 25, 2023
b80c1b4
update apis
vitaliidm Jul 26, 2023
ed9ddee
update schemas
vitaliidm Jul 26, 2023
5b7092b
add migration
vitaliidm Jul 27, 2023
a1754e3
add delete stream
vitaliidm Jul 28, 2023
d19ce2c
Merge remote-tracking branch 'upstream/main'
vitaliidm Jul 28, 2023
0870df1
Merge branch 'main' of https://github.com/vitaliidm/kibana
vitaliidm Jul 28, 2023
f298651
Merge remote-tracking branch 'upstream/main'
vitaliidm Jul 28, 2023
659f27b
Merge branch 'main' of ssh://github.com/vitaliidm/kibana
vitaliidm Jul 28, 2023
c05770f
Merge branch 'main' into alerts_8_10/move-lists-to-ds
vitaliidm Jul 28, 2023
7960d47
move routes to separate folder
vitaliidm Jul 28, 2023
5719cfd
add delete list
vitaliidm Jul 28, 2023
4938846
routes files cleanup
vitaliidm Jul 28, 2023
599dc37
create list API
vitaliidm Jul 28, 2023
c5f82f0
update most of APIs, apart from patch/delete
vitaliidm Jul 28, 2023
382342c
fix types
vitaliidm Jul 28, 2023
9f281a2
fix list privileges test
vitaliidm Jul 28, 2023
2823643
fix types
vitaliidm Jul 31, 2023
85ae8b6
fix some tests
vitaliidm Jul 31, 2023
89fa3f8
Merge branch 'main' into alerts_8_10/move-lists-to-ds
vitaliidm Jul 31, 2023
316753d
add more tests/fixes
vitaliidm Jul 31, 2023
22a2043
Merge branch 'alerts_8_10/move-lists-to-ds' of ssh://github.com/vital…
vitaliidm Jul 31, 2023
3e02401
patch list API
vitaliidm Jul 31, 2023
d49abe6
fix eslint tests
vitaliidm Jul 31, 2023
7eaea0a
fix typings
vitaliidm Jul 31, 2023
399a17c
Merge branch 'main' into alerts_8_10/move-lists-to-ds
vitaliidm Aug 1, 2023
3185503
fix unit tests
vitaliidm Aug 1, 2023
2f729aa
add update list item
vitaliidm Aug 1, 2023
0ef449b
fix unit test
vitaliidm Aug 1, 2023
cb9c6e0
add [atch and tests
vitaliidm Aug 1, 2023
ca026c3
remove only
vitaliidm Aug 1, 2023
761b5f9
fix index create route
vitaliidm Aug 1, 2023
f212977
Merge branch 'alerts_8_10/move-lists-to-ds' of ssh://github.com/vital…
vitaliidm Aug 1, 2023
7ddf5c0
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Aug 1, 2023
6ccedad
fix typings
vitaliidm Aug 1, 2023
ffeb829
OCC
vitaliidm Aug 1, 2023
43f55d9
tests
vitaliidm Aug 2, 2023
dfbf250
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Aug 2, 2023
c8ea9ac
addmore tests
vitaliidm Aug 2, 2023
db394b5
Merge branch 'alerts_8_10/move-lists-to-ds' of ssh://github.com/vital…
vitaliidm Aug 2, 2023
2048810
fix unit test
vitaliidm Aug 2, 2023
307bfc2
renaming
vitaliidm Aug 2, 2023
d4044c1
Merge branch 'main' into alerts_8_10/move-lists-to-ds
vitaliidm Aug 2, 2023
c142a10
add comments
vitaliidm Aug 2, 2023
84405ba
Merge branch 'alerts_8_10/move-lists-to-ds' of ssh://github.com/vital…
vitaliidm Aug 2, 2023
55f942e
Merge branch 'main' into alerts_8_10/move-lists-to-ds
vitaliidm Aug 2, 2023
80965b7
Merge branch 'main' into alerts_8_10/move-lists-to-ds
vitaliidm Aug 3, 2023
11f04d0
Merge branch 'main' into alerts_8_10/move-lists-to-ds
vitaliidm Aug 3, 2023
aef8f75
ILNM policy cleanup
vitaliidm Aug 3, 2023
9bc6dae
Merge branch 'alerts_8_10/move-lists-to-ds' of ssh://github.com/vital…
vitaliidm Aug 3, 2023
43847cb
Merge branch 'main' into alerts_8_10/move-lists-to-ds
vitaliidm Aug 3, 2023
2dc4470
Merge branch 'main' into alerts_8_10/move-lists-to-ds
vitaliidm Aug 4, 2023
ae4b47b
update APIs
vitaliidm Aug 4, 2023
d664868
import
vitaliidm Aug 4, 2023
79ffe2d
Merge branch 'main' into alerts_8_10/move-lists-to-ds
vitaliidm Aug 7, 2023
fc8cb43
Merge branch 'main' into alerts_8_10/move-lists-to-ds
vitaliidm Aug 9, 2023
c85531e
Merge branch 'main' into alerts_8_10/move-lists-to-ds
vitaliidm Aug 15, 2023
ee45572
CR: Update read_list_index_route.ts
vitaliidm Aug 17, 2023
6ff6bb8
Merge branch 'main' into alerts_8_10/move-lists-to-ds
vitaliidm Aug 17, 2023
d54dbaf
CR: delete logic rehaul
vitaliidm Aug 17, 2023
3f8cc90
Merge branch 'alerts_8_10/move-lists-to-ds' of ssh://github.com/vital…
vitaliidm Aug 17, 2023
65fc067
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Aug 17, 2023
561b3e6
Merge branch 'main' into alerts_8_10/move-lists-to-ds
vitaliidm Aug 22, 2023
b7f2179
Merge branch 'main' into alerts_8_10/move-lists-to-ds
vitaliidm Aug 23, 2023
61c13e8
Merge branch 'main' into alerts_8_10/move-lists-to-ds
vitaliidm Aug 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ describe('AutocompleteFieldListsComponent', () => {

await waitFor(() => {
expect(mockOnChange).toHaveBeenCalledWith({
'@timestamp': DATE_NOW,
_version: undefined,
created_at: DATE_NOW,
created_by: 'some user',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const NAME = 'some name';
// TODO: Once this mock is available within packages, use it instead, https://github.com/elastic/kibana/issues/100715
// import { getListResponseMock } from '../../../../../lists/common/schemas/response/list_schema.mock';
export const getListResponseMock = (): ListSchema => ({
'@timestamp': DATE_NOW,
_version: undefined,
created_at: DATE_NOW,
created_by: USER,
Expand Down
6 changes: 6 additions & 0 deletions packages/kbn-securitysolution-es-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

export * from './src/bad_request_error';
export * from './src/create_boostrap_index';
export * from './src/create_data_stream';
export * from './src/decode_version';
export * from './src/delete_all_index';
export * from './src/delete_data_stream';
export * from './src/delete_index_template';
export * from './src/delete_policy';
export * from './src/delete_template';
Expand All @@ -18,11 +20,15 @@ export * from './src/get_bootstrap_index_exists';
export * from './src/get_index_aliases';
export * from './src/get_index_count';
export * from './src/get_index_exists';
export * from './src/get_data_stream_exists';
export * from './src/get_index_template_exists';
export * from './src/get_policy_exists';
export * from './src/get_template_exists';
export * from './src/migrate_to_data_stream';
export * from './src/read_index';
export * from './src/read_privileges';
export * from './src/put_mappings';
export * from './src/remove_policy_from_index';
export * from './src/set_index_template';
export * from './src/set_policy';
export * from './src/set_template';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { ElasticsearchClient } from '../elasticsearch_client';

/**
* creates data stream
* @param esClient
* @param name
*/
export const createDataStream = async (
esClient: ElasticsearchClient,
name: string
): Promise<unknown> => {
return esClient.indices.createDataStream({
name,
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { ElasticsearchClient } from '../elasticsearch_client';

/**
* deletes data stream
* @param esClient
* @param name
*/
export const deleteDataStream = async (
esClient: ElasticsearchClient,
name: string
): Promise<boolean> => {
return (
await esClient.indices.deleteDataStream(
{
name,
},
{ meta: true }
)
).body.acknowledged;
};
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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { ElasticsearchClient } from '../elasticsearch_client';

/**
* checks if data stream exists
* @param esClient
* @param name
*/
export const getDataStreamExists = async (
esClient: ElasticsearchClient,
name: string
): Promise<boolean> => {
try {
const body = await esClient.indices.getDataStream({ name, expand_wildcards: 'all' });
return body.data_streams.length > 0;
} catch (err) {
if (err.body != null && err.body.status === 404) {
return false;
} else if (
// if index already created, _data_stream/${name} request will produce the following error
// data stream does not exist at this point, so we can return false
err?.body?.error?.reason?.includes(
`The provided expression [${name}] matches an alias, specify the corresponding concrete indices instead.`
)
) {
return false;
} else {
throw err.body ? err.body : err;
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { ElasticsearchClient } from '../elasticsearch_client';

/**
* migrate to data stream
* @param esClient
* @param name
*/
export const migrateToDataStream = async (
esClient: ElasticsearchClient,
name: string
): Promise<unknown> => {
return esClient.indices.migrateToDataStream({
name,
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { MappingProperty } from '@elastic/elasticsearch/lib/api/types';
import type { ElasticsearchClient } from '../elasticsearch_client';

/**
* update mappings of index
* @param esClient
* @param index
* @param mappings
*/
export const putMappings = async (
esClient: ElasticsearchClient,
index: string,
mappings: Record<string, MappingProperty>
): Promise<unknown> => {
return await esClient.indices.putMapping({
index,
properties: mappings,
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { ElasticsearchClient } from '../elasticsearch_client';

export const removePolicyFromIndex = async (
esClient: ElasticsearchClient,
index: string
): Promise<unknown> => {
return (await esClient.ilm.removePolicy({ index }, { meta: true })).body;
};
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export * from './sort_field';
export * from './sort_order';
export * from './tags';
export * from './tie_breaker_id';
export * from './timestamp';
export * from './total';
export * from './type';
export * from './underscore_version';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ export const meta = t.object;
export type Meta = t.TypeOf<typeof meta>;
export const metaOrUndefined = t.union([meta, t.undefined]);
export type MetaOrUndefined = t.TypeOf<typeof metaOrUndefined>;

export const nullableMetaOrUndefined = t.union([metaOrUndefined, t.null]);
export type NullableMetaOrUndefined = t.TypeOf<typeof nullableMetaOrUndefined>;
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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import * as t from 'io-ts';
import { IsoDateString } from '@kbn/securitysolution-io-ts-types';

export const timestamp = IsoDateString;
export const timestampOrUndefined = t.union([IsoDateString, t.undefined]);
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {

export const getListItemResponseMock = (): ListItemSchema => ({
_version: undefined,
'@timestamp': DATE_NOW,
created_at: DATE_NOW,
created_by: USER,
deserializer: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as t from 'io-ts';
import { _versionOrUndefined } from '../../common/underscore_version';
import { deserializerOrUndefined } from '../../common/deserializer';
import { metaOrUndefined } from '../../common/meta';
import { timestampOrUndefined } from '../../common/timestamp';
import { serializerOrUndefined } from '../../common/serializer';
import { created_at } from '../../common/created_at';
import { created_by } from '../../common/created_by';
Expand All @@ -25,6 +26,7 @@ import { value } from '../../common/value';
export const listItemSchema = t.exact(
t.type({
_version: _versionOrUndefined,
'@timestamp': timestampOrUndefined,
created_at,
created_by,
deserializer: deserializerOrUndefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {

export const getListResponseMock = (): ListSchema => ({
_version: undefined,
'@timestamp': DATE_NOW,
created_at: DATE_NOW,
created_by: USER,
description: DESCRIPTION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { deserializerOrUndefined } from '../../common/deserializer';
import { metaOrUndefined } from '../../common/meta';
import { serializerOrUndefined } from '../../common/serializer';
import { created_at } from '../../common/created_at';
import { timestampOrUndefined } from '../../common/timestamp';
import { created_by } from '../../common/created_by';
import { description } from '../../common/description';
import { id } from '../../common/id';
Expand All @@ -26,6 +27,7 @@ import { updated_by } from '../../common/updated_by';
export const listSchema = t.exact(
t.type({
_version: _versionOrUndefined,
'@timestamp': timestampOrUndefined,
created_at,
created_by,
description,
Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-securitysolution-list-api/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {

import {
ENDPOINT_LIST_URL,
EXCEPTION_FILTER,
INTERNAL_EXCEPTION_FILTER,
EXCEPTION_LIST_ITEM_URL,
EXCEPTION_LIST_URL,
} from '@kbn/securitysolution-list-constants';
Expand Down Expand Up @@ -579,7 +579,7 @@ export const getExceptionFilterFromExceptionListIds = async ({
http,
signal,
}: GetExceptionFilterFromExceptionListIdsProps): Promise<ExceptionFilterResponse> =>
http.fetch(EXCEPTION_FILTER, {
http.fetch(INTERNAL_EXCEPTION_FILTER, {
method: 'POST',
body: JSON.stringify({
exception_list_ids: exceptionListIds,
Expand Down Expand Up @@ -607,7 +607,7 @@ export const getExceptionFilterFromExceptions = async ({
chunkSize,
signal,
}: GetExceptionFilterFromExceptionsProps): Promise<ExceptionFilterResponse> =>
http.fetch(EXCEPTION_FILTER, {
http.fetch(INTERNAL_EXCEPTION_FILTER, {
method: 'POST',
body: JSON.stringify({
exceptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
LIST_ITEM_URL,
LIST_PRIVILEGES_URL,
LIST_URL,
FIND_LISTS_BY_SIZE,
INTERNAL_FIND_LISTS_BY_SIZE,
} from '@kbn/securitysolution-list-constants';
import { toError, toPromise } from '../fp_utils';

Expand Down Expand Up @@ -115,7 +115,7 @@ const findListsBySize = async ({
per_page,
signal,
}: ApiParams & FindListSchemaEncoded): Promise<FoundListsBySizeSchema> => {
return http.fetch(`${FIND_LISTS_BY_SIZE}`, {
return http.fetch(`${INTERNAL_FIND_LISTS_BY_SIZE}`, {
method: 'GET',
query: {
cursor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from '../constants.mock';

export const getListResponseMock = (): ListSchema => ({
'@timestamp': DATE_NOW,
_version: undefined,
created_at: DATE_NOW,
created_by: USER,
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-securitysolution-list-constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const LIST_PRIVILEGES_URL = `${LIST_URL}/privileges`;
* Internal value list routes
*/
export const INTERNAL_LIST_URL = '/internal/lists';
export const FIND_LISTS_BY_SIZE = `${INTERNAL_LIST_URL}/_find_lists_by_size` as const;
export const EXCEPTION_FILTER = `${INTERNAL_LIST_URL}/_create_filter` as const;
export const INTERNAL_FIND_LISTS_BY_SIZE = `${INTERNAL_LIST_URL}/_find_lists_by_size` as const;
export const INTERNAL_EXCEPTION_FILTER = `${INTERNAL_LIST_URL}/_create_filter` as const;

/**
* Exception list routes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from '../constants.mock';

export const getListResponseMock = (): ListSchema => ({
'@timestamp': DATE_NOW,
_version: undefined,
created_at: DATE_NOW,
created_by: USER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from '../../constants.mock';

export const getListItemResponseMock = (): ListItemSchema => ({
'@timestamp': DATE_NOW,
_version: undefined,
created_at: DATE_NOW,
created_by: USER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '../../constants.mock';

export const getListResponseMock = (): ListSchema => ({
'@timestamp': DATE_NOW,
_version: undefined,
created_at: DATE_NOW,
created_by: USER,
Expand Down
Loading