Skip to content

Commit 5b2d0b3

Browse files
[SIEM][Detection Engine][Lists] Adds the ability for exception lists to be multi-list queried. (#71540) (#71580)
## Summary * Adds the ability for exception lists to be multi-list queried * Fixes a bunch of script issues where I did not update everywhere I needed to use `ip_list` and deletes an old list that now lives within the new/lists folder * Fixes a few io-ts issues with Encode Decode while I was in there. * Adds two more types and their tests for supporting converting between comma separated strings and arrays for GET calls. * Fixes one weird circular dep issue while adding more types. You now send into the find an optional comma separated list of exception lists their namespace type and any filters like so: ```ts GET /api/exception_lists/items/_find?list_id=simple_list,endpoint_list&namespace_type=single,agnostic&filtering=filter1,filter2" ``` And this will return the results of both together with each filter applied to each list. If you use a sort field and ordering it will order across the lists together as if they are one list. Filter is optional like before. If you provide less filters than there are lists, the lists will only apply the filters to each list until it runs out of filters and then not filter the other lists. If at least one list is found this will _not_ return a 404 but it will _only_ query the list(s) it did find. If none of the lists are found, then this will return a 404 not found exception. **Script testing** See these files for more information: * find_exception_list_items.sh * find_exception_list_items_by_filter.sh But basically you can create two lists and an item for each of the lists: ```ts ./post_exception_list.sh ./exception_lists/new/exception_list.json ./post_exception_list_item.sh ./exception_lists/new/exception_list_item.json ./post_exception_list.sh ./exception_lists/new/exception_list_agnostic.json ./post_exception_list_item.sh ./exception_lists/new/exception_list_item_agnostic.json ``` And then you can query these two lists together: ```ts ./find_exception_list_items.sh simple_list,endpoint_list single,agnostic ``` Or for filtering you can query both and add a filter for each one: ```ts ./find_exception_list_items_by_filter.sh simple_list,endpoint_list "exception-list.attributes.name:%20Sample%20Endpoint%20Exception%20List,exception-list-agnostic.attributes.name:%20Sample%20Endpoint%20Exception%20List" single,agnostic ``` ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios
1 parent 0dad095 commit 5b2d0b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+786
-143
lines changed

x-pack/plugins/lists/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ which will:
5757
- Delete any existing exception list items you have
5858
- Delete any existing mapping, policies, and templates, you might have previously had.
5959
- Add the latest list and list item index and its mappings using your settings from `kibana.dev.yml` environment variable of `xpack.lists.listIndex` and `xpack.lists.listItemIndex`.
60-
- Posts the sample list from `./lists/new/list_ip.json`
60+
- Posts the sample list from `./lists/new/ip_list.json`
6161

6262
Now you can run
6363

@@ -69,7 +69,7 @@ You should see the new list created like so:
6969

7070
```sh
7171
{
72-
"id": "list_ip",
72+
"id": "ip_list",
7373
"created_at": "2020-05-28T19:15:22.344Z",
7474
"created_by": "yo",
7575
"description": "This list describes bad internet ip",
@@ -96,7 +96,7 @@ You should see the new list item created and attached to the above list like so:
9696
"value": "127.0.0.1",
9797
"created_at": "2020-05-28T19:15:49.790Z",
9898
"created_by": "yo",
99-
"list_id": "list_ip",
99+
"list_id": "ip_list",
100100
"tie_breaker_id": "a881bf2e-1e17-4592-bba8-d567cb07d234",
101101
"updated_at": "2020-05-28T19:15:49.790Z",
102102
"updated_by": "yo"
@@ -195,7 +195,7 @@ You can then do find for each one like so:
195195
"cursor": "WzIwLFsiYzU3ZWZiYzQtNDk3Ny00YTMyLTk5NWYtY2ZkMjk2YmVkNTIxIl1d",
196196
"data": [
197197
{
198-
"id": "list_ip",
198+
"id": "ip_list",
199199
"created_at": "2020-05-28T19:15:22.344Z",
200200
"created_by": "yo",
201201
"description": "This list describes bad internet ip",

x-pack/plugins/lists/common/schemas/common/schemas.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ export const cursorOrUndefined = t.union([cursor, t.undefined]);
273273
export type CursorOrUndefined = t.TypeOf<typeof cursorOrUndefined>;
274274

275275
export const namespace_type = DefaultNamespace;
276-
export type NamespaceType = t.TypeOf<typeof namespace_type>;
277276

278277
export const operator = t.keyof({ excluded: null, included: null });
279278
export type Operator = t.TypeOf<typeof operator>;

x-pack/plugins/lists/common/schemas/request/create_exception_list_item_schema.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import * as t from 'io-ts';
1010

1111
import {
1212
ItemId,
13-
NamespaceType,
1413
Tags,
1514
_Tags,
1615
_tags,
@@ -23,7 +22,12 @@ import {
2322
tags,
2423
} from '../common/schemas';
2524
import { Identity, RequiredKeepUndefined } from '../../types';
26-
import { CreateCommentsArray, DefaultCreateCommentsArray, DefaultEntryArray } from '../types';
25+
import {
26+
CreateCommentsArray,
27+
DefaultCreateCommentsArray,
28+
DefaultEntryArray,
29+
NamespaceType,
30+
} from '../types';
2731
import { EntriesArray } from '../types/entries';
2832
import { DefaultUuid } from '../../siem_common_deps';
2933

x-pack/plugins/lists/common/schemas/request/create_exception_list_schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import * as t from 'io-ts';
1010

1111
import {
1212
ListId,
13-
NamespaceType,
1413
Tags,
1514
_Tags,
1615
_tags,
@@ -23,6 +22,7 @@ import {
2322
} from '../common/schemas';
2423
import { Identity, RequiredKeepUndefined } from '../../types';
2524
import { DefaultUuid } from '../../siem_common_deps';
25+
import { NamespaceType } from '../types';
2626

2727
export const createExceptionListSchema = t.intersection([
2828
t.exact(

x-pack/plugins/lists/common/schemas/request/delete_exception_list_item_schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
import * as t from 'io-ts';
1010

11-
import { NamespaceType, id, item_id, namespace_type } from '../common/schemas';
11+
import { id, item_id, namespace_type } from '../common/schemas';
12+
import { NamespaceType } from '../types';
1213

1314
export const deleteExceptionListItemSchema = t.exact(
1415
t.partial({

x-pack/plugins/lists/common/schemas/request/delete_exception_list_schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
import * as t from 'io-ts';
1010

11-
import { NamespaceType, id, list_id, namespace_type } from '../common/schemas';
11+
import { id, list_id, namespace_type } from '../common/schemas';
12+
import { NamespaceType } from '../types';
1213

1314
export const deleteExceptionListSchema = t.exact(
1415
t.partial({

x-pack/plugins/lists/common/schemas/request/find_exception_list_item_schema.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,26 @@
88

99
import * as t from 'io-ts';
1010

11-
import {
12-
NamespaceType,
13-
filter,
14-
list_id,
15-
namespace_type,
16-
sort_field,
17-
sort_order,
18-
} from '../common/schemas';
11+
import { sort_field, sort_order } from '../common/schemas';
1912
import { RequiredKeepUndefined } from '../../types';
2013
import { StringToPositiveNumber } from '../types/string_to_positive_number';
14+
import {
15+
DefaultNamespaceArray,
16+
DefaultNamespaceArrayTypeDecoded,
17+
} from '../types/default_namespace_array';
18+
import { NonEmptyStringArray } from '../types/non_empty_string_array';
19+
import { EmptyStringArray, EmptyStringArrayDecoded } from '../types/empty_string_array';
2120

2221
export const findExceptionListItemSchema = t.intersection([
2322
t.exact(
2423
t.type({
25-
list_id,
24+
list_id: NonEmptyStringArray,
2625
})
2726
),
2827
t.exact(
2928
t.partial({
30-
filter, // defaults to undefined if not set during decode
31-
namespace_type, // defaults to 'single' if not set during decode
29+
filter: EmptyStringArray, // defaults to undefined if not set during decode
30+
namespace_type: DefaultNamespaceArray, // defaults to ['single'] if not set during decode
3231
page: StringToPositiveNumber, // defaults to undefined if not set during decode
3332
per_page: StringToPositiveNumber, // defaults to undefined if not set during decode
3433
sort_field, // defaults to undefined if not set during decode
@@ -37,14 +36,15 @@ export const findExceptionListItemSchema = t.intersection([
3736
),
3837
]);
3938

40-
export type FindExceptionListItemSchemaPartial = t.TypeOf<typeof findExceptionListItemSchema>;
39+
export type FindExceptionListItemSchemaPartial = t.OutputOf<typeof findExceptionListItemSchema>;
4140

4241
// This type is used after a decode since some things are defaults after a decode.
4342
export type FindExceptionListItemSchemaPartialDecoded = Omit<
44-
FindExceptionListItemSchemaPartial,
45-
'namespace_type'
43+
t.TypeOf<typeof findExceptionListItemSchema>,
44+
'namespace_type' | 'filter'
4645
> & {
47-
namespace_type: NamespaceType;
46+
filter: EmptyStringArrayDecoded;
47+
namespace_type: DefaultNamespaceArrayTypeDecoded;
4848
};
4949

5050
// This type is used after a decode since some things are defaults after a decode.

x-pack/plugins/lists/common/schemas/request/find_exception_list_schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
import * as t from 'io-ts';
1010

11-
import { NamespaceType, filter, namespace_type, sort_field, sort_order } from '../common/schemas';
11+
import { filter, namespace_type, sort_field, sort_order } from '../common/schemas';
1212
import { RequiredKeepUndefined } from '../../types';
1313
import { StringToPositiveNumber } from '../types/string_to_positive_number';
14+
import { NamespaceType } from '../types';
1415

1516
export const findExceptionListSchema = t.exact(
1617
t.partial({

x-pack/plugins/lists/common/schemas/request/read_exception_list_item_schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
import * as t from 'io-ts';
1010

11-
import { NamespaceType, id, item_id, namespace_type } from '../common/schemas';
11+
import { id, item_id, namespace_type } from '../common/schemas';
1212
import { RequiredKeepUndefined } from '../../types';
13+
import { NamespaceType } from '../types';
1314

1415
export const readExceptionListItemSchema = t.exact(
1516
t.partial({

x-pack/plugins/lists/common/schemas/request/read_exception_list_schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
import * as t from 'io-ts';
1010

11-
import { NamespaceType, id, list_id, namespace_type } from '../common/schemas';
11+
import { id, list_id, namespace_type } from '../common/schemas';
1212
import { RequiredKeepUndefined } from '../../types';
13+
import { NamespaceType } from '../types';
1314

1415
export const readExceptionListSchema = t.exact(
1516
t.partial({

0 commit comments

Comments
 (0)