Skip to content

Commit d462274

Browse files
authored
[SECURITY_SOLUTION][ENDPOINT] Add creation of Trusted Apps Agnostic List (#74868)
* Add method to ExceptionsListClient for creating trusted apps list
1 parent 02fcbaa commit d462274

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,12 @@ export const ENDPOINT_LIST_NAME = 'Elastic Endpoint Security Exception List';
5050
export const ENDPOINT_LIST_DESCRIPTION = 'Elastic Endpoint Security Exception List';
5151

5252
export const MAX_EXCEPTION_LIST_SIZE = 10000;
53+
54+
/** ID of trusted apps agnostic list */
55+
export const ENDPOINT_TRUSTED_APPS_LIST_ID = 'endpoint_trusted_apps';
56+
57+
/** Name of trusted apps agnostic list */
58+
export const ENDPOINT_TRUSTED_APPS_LIST_NAME = 'Elastic Endpoint Security Trusted Apps List';
59+
60+
/** Description of trusted apps agnostic list */
61+
export const ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION = 'Elastic Endpoint Security Trusted Apps List';
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { SavedObjectsClientContract } from 'kibana/server';
8+
import uuid from 'uuid';
9+
10+
import {
11+
ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION,
12+
ENDPOINT_TRUSTED_APPS_LIST_ID,
13+
ENDPOINT_TRUSTED_APPS_LIST_NAME,
14+
} from '../../../common/constants';
15+
import { ExceptionListSchema, ExceptionListSoSchema, Version } from '../../../common/schemas';
16+
17+
import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils';
18+
19+
interface CreateEndpointListOptions {
20+
savedObjectsClient: SavedObjectsClientContract;
21+
user: string;
22+
tieBreaker?: string;
23+
version: Version;
24+
}
25+
26+
/**
27+
* Creates the Endpoint Trusted Apps agnostic list if it does not yet exist
28+
*
29+
* @param savedObjectsClient
30+
* @param user
31+
* @param tieBreaker
32+
* @param version
33+
*/
34+
export const createEndpointTrustedAppsList = async ({
35+
savedObjectsClient,
36+
user,
37+
tieBreaker,
38+
version,
39+
}: CreateEndpointListOptions): Promise<ExceptionListSchema | null> => {
40+
const savedObjectType = getSavedObjectType({ namespaceType: 'agnostic' });
41+
const dateNow = new Date().toISOString();
42+
try {
43+
const savedObject = await savedObjectsClient.create<ExceptionListSoSchema>(
44+
savedObjectType,
45+
{
46+
_tags: [],
47+
comments: undefined,
48+
created_at: dateNow,
49+
created_by: user,
50+
description: ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION,
51+
entries: undefined,
52+
immutable: false,
53+
item_id: undefined,
54+
list_id: ENDPOINT_TRUSTED_APPS_LIST_ID,
55+
list_type: 'list',
56+
meta: undefined,
57+
name: ENDPOINT_TRUSTED_APPS_LIST_NAME,
58+
tags: [],
59+
tie_breaker_id: tieBreaker ?? uuid.v4(),
60+
type: 'endpoint',
61+
updated_by: user,
62+
version,
63+
},
64+
{
65+
// We intentionally hard coding the id so that there can only be one Trusted apps list within the space
66+
id: ENDPOINT_TRUSTED_APPS_LIST_ID,
67+
}
68+
);
69+
return transformSavedObjectToExceptionList({ savedObject });
70+
} catch (err) {
71+
if (savedObjectsClient.errors.isConflictError(err)) {
72+
return null;
73+
} else {
74+
throw err;
75+
}
76+
}
77+
};

x-pack/plugins/lists/server/services/exception_lists/exception_list_client.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { findExceptionListItem } from './find_exception_list_item';
4646
import { findExceptionList } from './find_exception_list';
4747
import { findExceptionListsItem } from './find_exception_list_items';
4848
import { createEndpointList } from './create_endpoint_list';
49+
import { createEndpointTrustedAppsList } from './create_endpoint_trusted_apps_list';
4950

5051
export class ExceptionListClient {
5152
private readonly user: string;
@@ -90,6 +91,18 @@ export class ExceptionListClient {
9091
});
9192
};
9293

94+
/**
95+
* Create the Trusted Apps Agnostic list if it does not yet exist (`null` is returned if it does exist)
96+
*/
97+
public createTrustedAppsList = async (): Promise<ExceptionListSchema | null> => {
98+
const { savedObjectsClient, user } = this;
99+
return createEndpointTrustedAppsList({
100+
savedObjectsClient,
101+
user,
102+
version: 1,
103+
});
104+
};
105+
93106
/**
94107
* This is the same as "createListItem" except it applies specifically to the agnostic endpoint list and will
95108
* auto-call the "createEndpointList" for you so that you have the best chance of the agnostic endpoint

0 commit comments

Comments
 (0)