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][ENDPOINT] Add creation of Trusted Apps Agnostic List #74868

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
9 changes: 9 additions & 0 deletions x-pack/plugins/lists/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,12 @@ export const ENDPOINT_LIST_NAME = 'Elastic Endpoint Security Exception List';
export const ENDPOINT_LIST_DESCRIPTION = 'Elastic Endpoint Security Exception List';

export const MAX_EXCEPTION_LIST_SIZE = 10000;

/** ID of trusted apps agnostic list */
export const ENDPOINT_TRUSTED_APPS_LIST_ID = 'endpoint_trusted_apps';

/** Name of trusted apps agnostic list */
export const ENDPOINT_TRUSTED_APPS_LIST_NAME = 'Elastic Endpoint Security Trusted Apps List';

/** Description of trusted apps agnostic list */
export const ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION = 'Elastic Endpoint Security Trusted Apps List';
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { SavedObjectsClientContract } from 'kibana/server';
import uuid from 'uuid';

import {
ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION,
ENDPOINT_TRUSTED_APPS_LIST_ID,
ENDPOINT_TRUSTED_APPS_LIST_NAME,
} from '../../../common/constants';
import { ExceptionListSchema, ExceptionListSoSchema, Version } from '../../../common/schemas';

import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils';

interface CreateEndpointListOptions {
savedObjectsClient: SavedObjectsClientContract;
user: string;
tieBreaker?: string;
version: Version;
}

/**
* Creates the Endpoint Trusted Apps agnostic list if it does not yet exist
*
* @param savedObjectsClient
* @param user
* @param tieBreaker
* @param version
*/
export const createEndpointTrustedAppsList = async ({
paul-tavares marked this conversation as resolved.
Show resolved Hide resolved
savedObjectsClient,
user,
tieBreaker,
version,
}: CreateEndpointListOptions): Promise<ExceptionListSchema | null> => {
const savedObjectType = getSavedObjectType({ namespaceType: 'agnostic' });
const dateNow = new Date().toISOString();
try {
const savedObject = await savedObjectsClient.create<ExceptionListSoSchema>(
savedObjectType,
{
_tags: [],
paul-tavares marked this conversation as resolved.
Show resolved Hide resolved
comments: undefined,
created_at: dateNow,
created_by: user,
description: ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION,
entries: undefined,
immutable: false,
item_id: undefined,
list_id: ENDPOINT_TRUSTED_APPS_LIST_ID,
list_type: 'list',
meta: undefined,
name: ENDPOINT_TRUSTED_APPS_LIST_NAME,
tags: [],
tie_breaker_id: tieBreaker ?? uuid.v4(),
type: 'endpoint',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this list has different restrictions I would use a different list type such as endpointTrustedApps

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, we should be thinking about this as a different type for at least 2 reasons that I can think of. 1) to ensure that it doesn't have any side effects on existing code / API consumers, 2) in case we want to switch on this for schema customizations later one (I realize we can switch on the id/name instead, but it might be a good idea to have both available since we know that future features will require multiple lists, e.g. per-policy trusted apps or per-policy exceptions).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thiiiiink the convention for IDs/types like this is hyphen-delimited though, as opposed to camelcase. So maybe something like trusted-apps. Could be wrong, and super nitpicky anyway, but maybe look for some examples before changing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I will create a new type (was trying to minimize the impact to manifest_manager, but its a minor refactoring there).

updated_by: user,
version,
},
{
// We intentionally hard coding the id so that there can only be one Trusted apps list within the space
id: ENDPOINT_TRUSTED_APPS_LIST_ID,
}
);
return transformSavedObjectToExceptionList({ savedObject });
} catch (err) {
if (savedObjectsClient.errors.isConflictError(err)) {
return null;
} else {
throw err;
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ import { findExceptionListItem } from './find_exception_list_item';
import { findExceptionList } from './find_exception_list';
import { findExceptionListsItem } from './find_exception_list_items';
import { createEndpointList } from './create_endpoint_list';
import { createEndpointTrustedAppsList } from './create_endpoint_trusted_apps_list';

export class ExceptionListClient {
private readonly user: string;

private trustedAppsListCreated: boolean = false;
paul-tavares marked this conversation as resolved.
Show resolved Hide resolved

private readonly savedObjectsClient: SavedObjectsClientContract;

constructor({ user, savedObjectsClient }: ConstructorOptions) {
Expand Down Expand Up @@ -90,6 +93,24 @@ export class ExceptionListClient {
});
};

/**
* Create the Trusted Apps Agnostic list if it does not yet exist (`null` is returned if it does exist)
*/
public createTrustedAppsList = async (): Promise<ExceptionListSchema | null> => {
if (this.trustedAppsListCreated) {
return null;
}
const { savedObjectsClient, user } = this;
return createEndpointTrustedAppsList({
savedObjectsClient,
user,
version: 1,
}).then((response) => {
this.trustedAppsListCreated = true;
return response;
});
};
paul-tavares marked this conversation as resolved.
Show resolved Hide resolved

/**
* This is the same as "createListItem" except it applies specifically to the agnostic endpoint list and will
* auto-call the "createEndpointList" for you so that you have the best chance of the agnostic endpoint
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/security_solution/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
logger: this.logger,
cache: this.exceptionsCache,
});

// initialize the global agnostic Trusted Apps list
exceptionListClient.createTrustedAppsList().catch((error) => {
paul-tavares marked this conversation as resolved.
Show resolved Hide resolved
this.logger.error('Failed to create Trusted Apps list via list plugin');
this.logger.error(error);
});
}

this.endpointAppContextService.start({
Expand Down