Skip to content

Commit a20a807

Browse files
[SIEM][Detection Engine][Lists] Adds conflict versioning and io-ts improvements to lists (#72337) (#72483)
## Summary * Adds conflict versioning by exposing the "_version" from the saved object system. It renames "version" to "_version" so that we can use regular "version" later for versioning things for pre-packaged lists abilities. * Utilizes `t.OutputOf` in the requests and the data types to give us more correctly types * Removes the `Identity` utility as that is adding confusion and can confuse vs code rather than improves things * Removes extra types that were causing confusion which was an idiom from io-ts * Changes the wording of `Partial` by removing that and instead focuses the request types on either client side or server side at this point. NOTE: The UI can migrate to holding onto the `_version` and then push it back down when it wants to migrate to using the conflict resolution. If the UI does not push it down, then a value of undefined will be used which is indicating that no conflict errors are wanted. Output example of posting an exception list: ❯ ./post_exception_list.sh ```ts { "_tags": [ "endpoint", "process", "malware", "os:linux" ], "_version": "Wzk4NiwxXQ==", "created_at": "2020-07-17T18:59:22.872Z", "created_by": "yo", "description": "This is a sample endpoint type exception", "id": "a08795b0-c85f-11ea-b1a6-c155df988a92", "list_id": "simple_list", "name": "Sample Endpoint Exception List", "namespace_type": "single", "tags": [ "user added string for a tag", "malware" ], "tie_breaker_id": "b789ec05-3e0f-4344-a156-0c0f5b6e2f9c", "type": "detection", "updated_at": "2020-07-17T18:59:22.891Z", "updated_by": "yo" } ``` Output example of posting an exception list item ❯ ./post_exception_list_item.sh ```ts { "_tags": [ "endpoint", "process", "malware", "os:linux" ], "_version": "Wzk4NywxXQ==", "comments": [], "created_at": "2020-07-17T18:59:30.286Z", "created_by": "yo", "description": "This is a sample endpoint type exception", "entries": [ { "field": "actingProcess.file.signer", "operator": "excluded", "type": "exists" }, { "field": "host.name", "operator": "included", "type": "match_any", "value": [ "some host", "another host" ] } ], "id": "a4f2b800-c85f-11ea-b1a6-c155df988a92", "item_id": "simple_list_item", "list_id": "simple_list", "name": "Sample Endpoint Exception List", "namespace_type": "single", "tags": [ "user added string for a tag", "malware" ], "tie_breaker_id": "1dc456bc-7aa9-44b4-bca3-131689cf729f", "type": "simple", "updated_at": "2020-07-17T18:59:30.304Z", "updated_by": "yo" } ``` Output example of when you get an exception list: ❯ ./get_exception_list.sh simple_list ```ts { "_tags": [ "endpoint", "process", "malware", "os:linux" ], "_version": "WzEwNzcsMV0=", "created_at": "2020-07-17T18:59:22.872Z", "created_by": "yo", "description": "Different description", "id": "a08795b0-c85f-11ea-b1a6-c155df988a92", "list_id": "simple_list", "name": "Sample Endpoint Exception List", "namespace_type": "single", "tags": [ "user added string for a tag", "malware" ], "tie_breaker_id": "b789ec05-3e0f-4344-a156-0c0f5b6e2f9c", "type": "endpoint", "updated_at": "2020-07-17T20:01:24.958Z", "updated_by": "yo" } ``` Example of the error you get if you do an update of an exception list and someone else has changed it: ```ts { "message": "[exception-list:a08795b0-c85f-11ea-b1a6-c155df988a92]: version conflict, required seqNo [1074], primary term [1]. current document has seqNo [1077] and primary term [1]: [version_conflict_engine_exception] [exception-list:a08795b0-c85f-11ea-b1a6-c155df988a92]: version conflict, required seqNo [1074], primary term [1]. current document has seqNo [1077] and primary term [1], with { index_uuid=\"a2mgXBO6Tl2ULDq-MTs1Tw\" & shard=\"0\" & index=\".kibana-hassanabad_1\" }", "status_code": 409 } ``` Lists are the same way and flavor, they encode the _version the same way that saved objects do. To see those work you run these scripts: ```ts ./post_list.sh ./post_list_item.sh ./find_list.sh ./find_list_item.sh ``` ### Checklist - [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 10e6b52 commit a20a807

File tree

128 files changed

+517
-435
lines changed

Some content is hidden

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

128 files changed

+517
-435
lines changed

x-pack/plugins/lists/common/constants.mock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ export const TAGS = [];
6060
export const COMMENTS = [];
6161
export const FILTER = 'name:Nicolas Bourbaki';
6262
export const CURSOR = 'c29tZXN0cmluZ2ZvcnlvdQ==';
63+
export const _VERSION = 'WzI5NywxXQ==';

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,7 @@ export type Deserializer = t.TypeOf<typeof deserializer>;
307307

308308
export const deserializerOrUndefined = t.union([deserializer, t.undefined]);
309309
export type DeserializerOrUndefined = t.TypeOf<typeof deserializerOrUndefined>;
310+
311+
export const _version = t.string;
312+
export const _versionOrUndefined = t.union([_version, t.undefined]);
313+
export type _VersionOrUndefined = t.TypeOf<typeof _versionOrUndefined>;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ export const createEsBulkTypeSchema = t.exact(
1414
})
1515
);
1616

17-
export type CreateEsBulkTypeSchema = t.TypeOf<typeof createEsBulkTypeSchema>;
17+
export type CreateEsBulkTypeSchema = t.OutputOf<typeof createEsBulkTypeSchema>;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ export const indexEsListItemSchema = t.intersection([
3838
esDataTypeUnion,
3939
]);
4040

41-
export type IndexEsListItemSchema = t.TypeOf<typeof indexEsListItemSchema>;
41+
export type IndexEsListItemSchema = t.OutputOf<typeof indexEsListItemSchema>;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ export const indexEsListSchema = t.exact(
3838
})
3939
);
4040

41-
export type IndexEsListSchema = t.TypeOf<typeof indexEsListSchema>;
41+
export type IndexEsListSchema = t.OutputOf<typeof indexEsListSchema>;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ export const updateEsListItemSchema = t.intersection([
2121
esDataTypeUnion,
2222
]);
2323

24-
export type UpdateEsListItemSchema = t.TypeOf<typeof updateEsListItemSchema>;
24+
export type UpdateEsListItemSchema = t.OutputOf<typeof updateEsListItemSchema>;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ export const updateEsListSchema = t.exact(
2626
})
2727
);
2828

29-
export type UpdateEsListSchema = t.TypeOf<typeof updateEsListSchema>;
29+
export type UpdateEsListSchema = t.OutputOf<typeof updateEsListSchema>;

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
name,
2020
tags,
2121
} from '../common/schemas';
22-
import { Identity, RequiredKeepUndefined } from '../../types';
22+
import { RequiredKeepUndefined } from '../../types';
2323
import { CreateCommentsArray, DefaultCreateCommentsArray, DefaultEntryArray } from '../types';
2424
import { EntriesArray } from '../types/entries';
2525
import { DefaultUuid } from '../../siem_common_deps';
@@ -44,20 +44,16 @@ export const createEndpointListItemSchema = t.intersection([
4444
),
4545
]);
4646

47-
export type CreateEndpointListItemSchemaPartial = Identity<
48-
t.TypeOf<typeof createEndpointListItemSchema>
49-
>;
50-
export type CreateEndpointListItemSchema = RequiredKeepUndefined<
51-
t.TypeOf<typeof createEndpointListItemSchema>
52-
>;
47+
export type CreateEndpointListItemSchema = t.OutputOf<typeof createEndpointListItemSchema>;
5348

5449
// This type is used after a decode since some things are defaults after a decode.
55-
export type CreateEndpointListItemSchemaDecoded = Identity<
56-
Omit<CreateEndpointListItemSchema, '_tags' | 'tags' | 'item_id' | 'entries' | 'comments'> & {
57-
_tags: _Tags;
58-
comments: CreateCommentsArray;
59-
tags: Tags;
60-
item_id: ItemId;
61-
entries: EntriesArray;
62-
}
63-
>;
50+
export type CreateEndpointListItemSchemaDecoded = Omit<
51+
RequiredKeepUndefined<t.TypeOf<typeof createEndpointListItemSchema>>,
52+
'_tags' | 'tags' | 'item_id' | 'entries' | 'comments'
53+
> & {
54+
_tags: _Tags;
55+
comments: CreateCommentsArray;
56+
tags: Tags;
57+
item_id: ItemId;
58+
entries: EntriesArray;
59+
};

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

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
namespace_type,
2222
tags,
2323
} from '../common/schemas';
24-
import { Identity, RequiredKeepUndefined } from '../../types';
24+
import { RequiredKeepUndefined } from '../../types';
2525
import {
2626
CreateCommentsArray,
2727
DefaultCreateCommentsArray,
@@ -53,24 +53,17 @@ export const createExceptionListItemSchema = t.intersection([
5353
),
5454
]);
5555

56-
export type CreateExceptionListItemSchemaPartial = Identity<
57-
t.TypeOf<typeof createExceptionListItemSchema>
58-
>;
59-
export type CreateExceptionListItemSchema = RequiredKeepUndefined<
60-
t.TypeOf<typeof createExceptionListItemSchema>
61-
>;
56+
export type CreateExceptionListItemSchema = t.OutputOf<typeof createExceptionListItemSchema>;
6257

6358
// This type is used after a decode since some things are defaults after a decode.
64-
export type CreateExceptionListItemSchemaDecoded = Identity<
65-
Omit<
66-
CreateExceptionListItemSchema,
67-
'_tags' | 'tags' | 'item_id' | 'entries' | 'namespace_type' | 'comments'
68-
> & {
69-
_tags: _Tags;
70-
comments: CreateCommentsArray;
71-
tags: Tags;
72-
item_id: ItemId;
73-
entries: EntriesArray;
74-
namespace_type: NamespaceType;
75-
}
76-
>;
59+
export type CreateExceptionListItemSchemaDecoded = Omit<
60+
RequiredKeepUndefined<t.TypeOf<typeof createExceptionListItemSchema>>,
61+
'_tags' | 'tags' | 'item_id' | 'entries' | 'namespace_type' | 'comments'
62+
> & {
63+
_tags: _Tags;
64+
comments: CreateCommentsArray;
65+
tags: Tags;
66+
item_id: ItemId;
67+
entries: EntriesArray;
68+
namespace_type: NamespaceType;
69+
};

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
namespace_type,
2121
tags,
2222
} from '../common/schemas';
23-
import { Identity, RequiredKeepUndefined } from '../../types';
23+
import { RequiredKeepUndefined } from '../../types';
2424
import { DefaultUuid } from '../../siem_common_deps';
2525
import { NamespaceType } from '../types';
2626

@@ -43,17 +43,15 @@ export const createExceptionListSchema = t.intersection([
4343
),
4444
]);
4545

46-
export type CreateExceptionListSchemaPartial = Identity<t.TypeOf<typeof createExceptionListSchema>>;
47-
export type CreateExceptionListSchema = RequiredKeepUndefined<
48-
t.TypeOf<typeof createExceptionListSchema>
49-
>;
46+
export type CreateExceptionListSchema = t.OutputOf<typeof createExceptionListSchema>;
5047

5148
// This type is used after a decode since some things are defaults after a decode.
52-
export type CreateExceptionListSchemaDecoded = Identity<
53-
Omit<CreateExceptionListSchema, '_tags' | 'tags' | 'list_id' | 'namespace_type'> & {
54-
_tags: _Tags;
55-
tags: Tags;
56-
list_id: ListId;
57-
namespace_type: NamespaceType;
58-
}
59-
>;
49+
export type CreateExceptionListSchemaDecoded = Omit<
50+
RequiredKeepUndefined<t.TypeOf<typeof createExceptionListSchema>>,
51+
'_tags' | 'tags' | 'list_id' | 'namespace_type'
52+
> & {
53+
_tags: _Tags;
54+
tags: Tags;
55+
list_id: ListId;
56+
namespace_type: NamespaceType;
57+
};

0 commit comments

Comments
 (0)