diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b4237eff609be..61b20febc9b17 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -754,6 +754,7 @@ x-pack/test/security_functional/plugins/test_endpoints @elastic/kibana-security packages/kbn-securitysolution-autocomplete @elastic/security-detection-engine x-pack/packages/security-solution/data_table @elastic/security-threat-hunting-investigations packages/kbn-securitysolution-ecs @elastic/security-threat-hunting-explore +packages/kbn-securitysolution-endpoint-exceptions-common @elastic/security-detection-engine packages/kbn-securitysolution-es-utils @elastic/security-detection-engine packages/kbn-securitysolution-exception-list-components @elastic/security-detection-engine packages/kbn-securitysolution-exceptions-common @elastic/security-detection-engine diff --git a/package.json b/package.json index 333b5350245cb..753100217f707 100644 --- a/package.json +++ b/package.json @@ -769,6 +769,7 @@ "@kbn/securitysolution-autocomplete": "link:packages/kbn-securitysolution-autocomplete", "@kbn/securitysolution-data-table": "link:x-pack/packages/security-solution/data_table", "@kbn/securitysolution-ecs": "link:packages/kbn-securitysolution-ecs", + "@kbn/securitysolution-endpoint-exceptions-common": "link:packages/kbn-securitysolution-endpoint-exceptions-common", "@kbn/securitysolution-es-utils": "link:packages/kbn-securitysolution-es-utils", "@kbn/securitysolution-exception-list-components": "link:packages/kbn-securitysolution-exception-list-components", "@kbn/securitysolution-exceptions-common": "link:packages/kbn-securitysolution-exceptions-common", diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/README.md b/packages/kbn-securitysolution-endpoint-exceptions-common/README.md new file mode 100644 index 0000000000000..3846d171e3ccd --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/README.md @@ -0,0 +1,20 @@ +# Security Solution Endpoint Exceptions + +The package contains common files for the Endpoint Exceptions feature. + +`common` in the name highlights that this package is intended to combine any common entities related to Endpoint Exceptions. E.g. the other `kbn-securitysolution-endpoint-exception-list-*` packages +content should be moved here while `kbn-securitysolution-io-ts-list-types` package should be +gone eventually. + +## API folder + +`api` folder contains OpenAPI schemas for Security Solution Endpoint Exceptions feature. There are automatically generated Zod schemas and TS types for each schemas located in corresponding +`*.gen.ts` files. + +**Please add any Endpoint Exceptions feature related schemas to this package.** + +TS types and/or Zod schemas can be imported in a plugin or another package like + +```ts +import { CreateEndpointExceptionRequestBody } from '@kbn/securitysolution-endpoint-exceptions-common/api'; +``` diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/api/create_endpoint_list/create_endpoint_list.gen.ts b/packages/kbn-securitysolution-endpoint-exceptions-common/api/create_endpoint_list/create_endpoint_list.gen.ts new file mode 100644 index 0000000000000..7a6f0231a9f59 --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/api/create_endpoint_list/create_endpoint_list.gen.ts @@ -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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Create endpoint list API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { EndpointList } from '../model/endpoint_list_common.gen'; + +export type CreateEndpointListResponse = z.infer; +export const CreateEndpointListResponse = EndpointList; diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/api/create_endpoint_list/create_endpoint_list.schema.yaml b/packages/kbn-securitysolution-endpoint-exceptions-common/api/create_endpoint_list/create_endpoint_list.schema.yaml new file mode 100644 index 0000000000000..12132ce5562b3 --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/api/create_endpoint_list/create_endpoint_list.schema.yaml @@ -0,0 +1,47 @@ +openapi: 3.0.0 +info: + title: Create endpoint list API endpoint + version: '2023-10-31' +paths: + /api/endpoint_list: + post: + x-labels: [serverless, ess] + x-codegen-enabled: true + operationId: CreateEndpointList + summary: Creates an endpoint list + description: Creates an endpoint list or does nothing if the list already exists + tags: + - Endpoint exceptions API + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/endpoint_list_common.schema.yaml#/components/schemas/EndpointList' + 400: + description: Invalid input data + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Insufficient privileges + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 500: + description: Internal server error + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/api/create_endpoint_list_item/create_endpoint_list_item.gen.ts b/packages/kbn-securitysolution-endpoint-exceptions-common/api/create_endpoint_list_item/create_endpoint_list_item.gen.ts new file mode 100644 index 0000000000000..f36f79f7b0b2a --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/api/create_endpoint_list_item/create_endpoint_list_item.gen.ts @@ -0,0 +1,50 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Create endpoint list item API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { + ExceptionListItemHumanId, + ExceptionListItemType, + ExceptionListItemName, + ExceptionListItemDescription, + ExceptionListItemOsTypeArray, + ExceptionListItemTags, + ExceptionListItemMeta, + ExceptionListItemCommentArray, +} from '@kbn/securitysolution-exceptions-common/api/model/exception_list_common.gen'; +import { ExceptionListItemEntryArray } from '@kbn/securitysolution-exceptions-common/api/model/exception_list_item_entry.gen'; +import { EndpointListItem } from '../model/endpoint_list_common.gen'; + +export type CreateEndpointListItemRequestBody = z.infer; +export const CreateEndpointListItemRequestBody = z.object({ + item_id: ExceptionListItemHumanId.optional(), + type: ExceptionListItemType, + name: ExceptionListItemName, + description: ExceptionListItemDescription, + entries: ExceptionListItemEntryArray, + os_types: ExceptionListItemOsTypeArray.optional().default([]), + tags: ExceptionListItemTags.optional().default([]), + meta: ExceptionListItemMeta.optional(), + comments: ExceptionListItemCommentArray.optional().default([]), +}); +export type CreateEndpointListItemRequestBodyInput = z.input< + typeof CreateEndpointListItemRequestBody +>; + +export type CreateEndpointListItemResponse = z.infer; +export const CreateEndpointListItemResponse = EndpointListItem; diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/api/create_endpoint_list_item/create_endpoint_list_item.schema.yaml b/packages/kbn-securitysolution-endpoint-exceptions-common/api/create_endpoint_list_item/create_endpoint_list_item.schema.yaml new file mode 100644 index 0000000000000..575e77ef84910 --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/api/create_endpoint_list_item/create_endpoint_list_item.schema.yaml @@ -0,0 +1,86 @@ +openapi: 3.0.0 +info: + title: Create endpoint list item API endpoint + version: '2023-10-31' +paths: + /api/endpoint_list/items: + post: + x-labels: [serverless, ess] + x-codegen-enabled: true + operationId: CreateEndpointListItem + summary: Creates an endpoint list item + tags: + - Endpoint exceptions API + requestBody: + description: Exception list item's properties + required: true + content: + application/json: + schema: + type: object + properties: + item_id: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemHumanId' + type: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemType' + name: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemName' + description: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemDescription' + entries: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.schema.yaml#/components/schemas/ExceptionListItemEntryArray' + os_types: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemOsTypeArray' + default: [] + tags: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemTags' + default: [] + meta: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemMeta' + comments: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemCommentArray' + default: [] + required: + - type + - name + - description + - entries + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/endpoint_list_common.schema.yaml#/components/schemas/EndpointListItem' + 400: + description: Invalid input data + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Insufficient privileges + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 409: + description: Endpoint list item already exists + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/api/delete_endpoint_list_item/delete_endpoint_list_item.gen.ts b/packages/kbn-securitysolution-endpoint-exceptions-common/api/delete_endpoint_list_item/delete_endpoint_list_item.gen.ts new file mode 100644 index 0000000000000..cd02179c2922f --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/api/delete_endpoint_list_item/delete_endpoint_list_item.gen.ts @@ -0,0 +1,42 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Delete endpoint list item API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { + ExceptionListItemId, + ExceptionListItemHumanId, +} from '@kbn/securitysolution-exceptions-common/api/model/exception_list_common.gen'; +import { EndpointListItem } from '../model/endpoint_list_common.gen'; + +export type DeleteEndpointListItemRequestQuery = z.infer; +export const DeleteEndpointListItemRequestQuery = z.object({ + /** + * Either `id` or `item_id` must be specified + */ + id: ExceptionListItemId.optional(), + /** + * Either `id` or `item_id` must be specified + */ + item_id: ExceptionListItemHumanId.optional(), +}); +export type DeleteEndpointListItemRequestQueryInput = z.input< + typeof DeleteEndpointListItemRequestQuery +>; + +export type DeleteEndpointListItemResponse = z.infer; +export const DeleteEndpointListItemResponse = EndpointListItem; diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/api/delete_endpoint_list_item/delete_endpoint_list_item.schema.yaml b/packages/kbn-securitysolution-endpoint-exceptions-common/api/delete_endpoint_list_item/delete_endpoint_list_item.schema.yaml new file mode 100644 index 0000000000000..e60fe54abb261 --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/api/delete_endpoint_list_item/delete_endpoint_list_item.schema.yaml @@ -0,0 +1,65 @@ +openapi: 3.0.0 +info: + title: Delete endpoint list item API endpoint + version: '2023-10-31' +paths: + /api/endpoint_list/items: + delete: + x-labels: [serverless, ess] + x-codegen-enabled: true + operationId: DeleteEndpointListItem + summary: Deletes an endpoint list item + tags: + - Endpoint exceptions API + parameters: + - name: id + in: query + required: false + description: Either `id` or `item_id` must be specified + schema: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemId' + - name: item_id + in: query + required: false + description: Either `id` or `item_id` must be specified + schema: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemHumanId' + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/endpoint_list_common.schema.yaml#/components/schemas/EndpointListItem' + 400: + description: Invalid input data + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Insufficient privileges + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: Endpoint list item not found + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/api/find_endpoint_list_item/find_endpoint_list_item.gen.ts b/packages/kbn-securitysolution-endpoint-exceptions-common/api/find_endpoint_list_item/find_endpoint_list_item.gen.ts new file mode 100644 index 0000000000000..ac1f955df209e --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/api/find_endpoint_list_item/find_endpoint_list_item.gen.ts @@ -0,0 +1,62 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Find endpoint list items API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { NonEmptyString } from '@kbn/openapi-common/schemas/primitives.gen'; +import { EndpointListItem } from '../model/endpoint_list_common.gen'; + +export type FindEndpointListItemsFilter = z.infer; +export const FindEndpointListItemsFilter = NonEmptyString; + +export type FindEndpointListItemsRequestQuery = z.infer; +export const FindEndpointListItemsRequestQuery = z.object({ + /** + * Filters the returned results according to the value of the specified field, +using the `:` syntax. + + */ + filter: FindEndpointListItemsFilter.optional(), + /** + * The page number to return + */ + page: z.coerce.number().int().min(0).optional(), + /** + * The number of exception list items to return per page + */ + per_page: z.coerce.number().int().min(0).optional(), + /** + * Determines which field is used to sort the results + */ + sort_field: NonEmptyString.optional(), + /** + * Determines the sort order, which can be `desc` or `asc` + */ + sort_order: z.enum(['desc', 'asc']).optional(), +}); +export type FindEndpointListItemsRequestQueryInput = z.input< + typeof FindEndpointListItemsRequestQuery +>; + +export type FindEndpointListItemsResponse = z.infer; +export const FindEndpointListItemsResponse = z.object({ + data: z.array(EndpointListItem), + page: z.number().int().min(0), + per_page: z.number().int().min(0), + total: z.number().int().min(0), + pit: z.string().optional(), +}); diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/api/find_endpoint_list_item/find_endpoint_list_item.schema.yaml b/packages/kbn-securitysolution-endpoint-exceptions-common/api/find_endpoint_list_item/find_endpoint_list_item.schema.yaml new file mode 100644 index 0000000000000..ca5d656c57c83 --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/api/find_endpoint_list_item/find_endpoint_list_item.schema.yaml @@ -0,0 +1,114 @@ +openapi: 3.0.0 +info: + title: Find endpoint list items API endpoint + version: '2023-10-31' +paths: + /api/endpoint_list/items/_find: + get: + x-labels: [serverless, ess] + x-codegen-enabled: true + operationId: FindEndpointListItems + summary: Finds endpoint list items + tags: + - Endpoint exceptions API + parameters: + - name: filter + in: query + required: false + description: | + Filters the returned results according to the value of the specified field, + using the `:` syntax. + schema: + $ref: '#/components/schemas/FindEndpointListItemsFilter' + - name: page + in: query + required: false + description: The page number to return + schema: + type: integer + minimum: 0 + - name: per_page + in: query + required: false + description: The number of exception list items to return per page + schema: + type: integer + minimum: 0 + - name: sort_field + in: query + required: false + description: Determines which field is used to sort the results + schema: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + - name: sort_order + in: query + required: false + description: Determines the sort order, which can be `desc` or `asc` + schema: + type: string + enum: [desc, asc] + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: object + properties: + data: + type: array + items: + $ref: '../model/endpoint_list_common.schema.yaml#/components/schemas/EndpointListItem' + page: + type: integer + minimum: 0 + per_page: + type: integer + minimum: 0 + total: + type: integer + minimum: 0 + pit: + type: string + required: + - data + - page + - per_page + - total + 400: + description: Invalid input data + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Insufficient privileges + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: Endpoint list not found + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + +components: + schemas: + FindEndpointListItemsFilter: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/api/index.ts b/packages/kbn-securitysolution-endpoint-exceptions-common/api/index.ts new file mode 100644 index 0000000000000..7565f71ac9798 --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/api/index.ts @@ -0,0 +1,14 @@ +/* + * 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. + */ + +export * from './create_endpoint_list/create_endpoint_list.gen'; +export * from './create_endpoint_list_item/create_endpoint_list_item.gen'; +export * from './read_endpoint_list_item/read_endpoint_list_item.gen'; +export * from './update_endpoint_list_item/update_endpoint_list_item.gen'; +export * from './delete_endpoint_list_item/delete_endpoint_list_item.gen'; +export * from './find_endpoint_list_item/find_endpoint_list_item.gen'; diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/api/model/endpoint_list_common.gen.ts b/packages/kbn-securitysolution-endpoint-exceptions-common/api/model/endpoint_list_common.gen.ts new file mode 100644 index 0000000000000..30f7c80ba257c --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/api/model/endpoint_list_common.gen.ts @@ -0,0 +1,29 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Common Exception List Attributes + * version: not applicable + */ + +import { z } from 'zod'; + +import { + ExceptionList, + ExceptionListItem, +} from '@kbn/securitysolution-exceptions-common/api/model/exception_list_common.gen'; + +export type EndpointList = z.infer; +export const EndpointList = z.union([ExceptionList, z.object({}).strict()]); + +export type EndpointListItem = z.infer; +export const EndpointListItem = ExceptionListItem; diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/api/model/endpoint_list_common.schema.yaml b/packages/kbn-securitysolution-endpoint-exceptions-common/api/model/endpoint_list_common.schema.yaml new file mode 100644 index 0000000000000..8f91f3250b357 --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/api/model/endpoint_list_common.schema.yaml @@ -0,0 +1,16 @@ +openapi: 3.0.0 +info: + title: Common Exception List Attributes + version: 'not applicable' +paths: {} +components: + x-codegen-enabled: true + schemas: + EndpointList: + oneOf: + - $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionList' + - type: object + additionalProperties: false + + EndpointListItem: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItem' diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/api/read_endpoint_list_item/read_endpoint_list_item.gen.ts b/packages/kbn-securitysolution-endpoint-exceptions-common/api/read_endpoint_list_item/read_endpoint_list_item.gen.ts new file mode 100644 index 0000000000000..e3661cb8099d3 --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/api/read_endpoint_list_item/read_endpoint_list_item.gen.ts @@ -0,0 +1,42 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Read endpoint list item API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { + ExceptionListItemId, + ExceptionListItemHumanId, +} from '@kbn/securitysolution-exceptions-common/api/model/exception_list_common.gen'; +import { EndpointListItem } from '../model/endpoint_list_common.gen'; + +export type ReadEndpointListItemRequestQuery = z.infer; +export const ReadEndpointListItemRequestQuery = z.object({ + /** + * Either `id` or `item_id` must be specified + */ + id: ExceptionListItemId.optional(), + /** + * Either `id` or `item_id` must be specified + */ + item_id: ExceptionListItemHumanId.optional(), +}); +export type ReadEndpointListItemRequestQueryInput = z.input< + typeof ReadEndpointListItemRequestQuery +>; + +export type ReadEndpointListItemResponse = z.infer; +export const ReadEndpointListItemResponse = z.array(EndpointListItem); diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/api/read_endpoint_list_item/read_endpoint_list_item.schema.yaml b/packages/kbn-securitysolution-endpoint-exceptions-common/api/read_endpoint_list_item/read_endpoint_list_item.schema.yaml new file mode 100644 index 0000000000000..c4025370763f4 --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/api/read_endpoint_list_item/read_endpoint_list_item.schema.yaml @@ -0,0 +1,67 @@ +openapi: 3.0.0 +info: + title: Read endpoint list item API endpoint + version: '2023-10-31' +paths: + /api/endpoint_list/items: + get: + x-labels: [serverless, ess] + x-codegen-enabled: true + operationId: ReadEndpointListItem + summary: Reads an endpoint list item + tags: + - Endpoint exceptions API + parameters: + - name: id + in: query + required: false + description: Either `id` or `item_id` must be specified + schema: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemId' + - name: item_id + in: query + required: false + description: Either `id` or `item_id` must be specified + schema: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemHumanId' + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: array + items: + $ref: '../model/endpoint_list_common.schema.yaml#/components/schemas/EndpointListItem' + 400: + description: Invalid input data + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Insufficient privileges + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: Endpoint list item not found + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/api/update_endpoint_list_item/update_endpoint_list_item.gen.ts b/packages/kbn-securitysolution-endpoint-exceptions-common/api/update_endpoint_list_item/update_endpoint_list_item.gen.ts new file mode 100644 index 0000000000000..38d8cd87a430e --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/api/update_endpoint_list_item/update_endpoint_list_item.gen.ts @@ -0,0 +1,59 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Update endpoint list item API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { + ExceptionListItemId, + ExceptionListItemHumanId, + ExceptionListItemType, + ExceptionListItemName, + ExceptionListItemDescription, + ExceptionListItemOsTypeArray, + ExceptionListItemTags, + ExceptionListItemMeta, + ExceptionListItemCommentArray, +} from '@kbn/securitysolution-exceptions-common/api/model/exception_list_common.gen'; +import { ExceptionListItemEntryArray } from '@kbn/securitysolution-exceptions-common/api/model/exception_list_item_entry.gen'; +import { EndpointListItem } from '../model/endpoint_list_common.gen'; + +export type UpdateEndpointListItemRequestBody = z.infer; +export const UpdateEndpointListItemRequestBody = z.object({ + /** + * Either `id` or `item_id` must be specified + */ + id: ExceptionListItemId.optional(), + /** + * Either `id` or `item_id` must be specified + */ + item_id: ExceptionListItemHumanId.optional(), + type: ExceptionListItemType, + name: ExceptionListItemName, + description: ExceptionListItemDescription, + entries: ExceptionListItemEntryArray, + os_types: ExceptionListItemOsTypeArray.optional().default([]), + tags: ExceptionListItemTags.optional(), + meta: ExceptionListItemMeta.optional(), + comments: ExceptionListItemCommentArray.optional().default([]), + _version: z.string().optional(), +}); +export type UpdateEndpointListItemRequestBodyInput = z.input< + typeof UpdateEndpointListItemRequestBody +>; + +export type UpdateEndpointListItemResponse = z.infer; +export const UpdateEndpointListItemResponse = EndpointListItem; diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/api/update_endpoint_list_item/update_endpoint_list_item.schema.yaml b/packages/kbn-securitysolution-endpoint-exceptions-common/api/update_endpoint_list_item/update_endpoint_list_item.schema.yaml new file mode 100644 index 0000000000000..740ebb0107eb0 --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/api/update_endpoint_list_item/update_endpoint_list_item.schema.yaml @@ -0,0 +1,91 @@ +openapi: 3.0.0 +info: + title: Update endpoint list item API endpoint + version: '2023-10-31' +paths: + /api/endpoint_list/items: + put: + x-labels: [serverless, ess] + x-codegen-enabled: true + operationId: UpdateEndpointListItem + summary: Updates an endpoint list item + tags: + - Endpoint exceptions API + requestBody: + description: Exception list item's properties + required: true + content: + application/json: + schema: + type: object + properties: + id: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemId' + description: Either `id` or `item_id` must be specified + item_id: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemHumanId' + description: Either `id` or `item_id` must be specified + type: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemType' + name: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemName' + description: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemDescription' + entries: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.schema.yaml#/components/schemas/ExceptionListItemEntryArray' + os_types: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemOsTypeArray' + default: [] + tags: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemTags' + meta: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemMeta' + comments: + $ref: '../../../kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemCommentArray' + default: [] + _version: + type: string + required: + - type + - name + - description + - entries + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/endpoint_list_common.schema.yaml#/components/schemas/EndpointListItem' + 400: + description: Invalid input data + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Insufficient privileges + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: Endpoint list item not found + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/kibana.jsonc b/packages/kbn-securitysolution-endpoint-exceptions-common/kibana.jsonc new file mode 100644 index 0000000000000..76a63cc5ac561 --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/kibana.jsonc @@ -0,0 +1,5 @@ +{ + "type": "shared-common", + "id": "@kbn/securitysolution-endpoint-exceptions-common", + "owner": "@elastic/security-detection-engine" +} diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/package.json b/packages/kbn-securitysolution-endpoint-exceptions-common/package.json new file mode 100644 index 0000000000000..e07ac8c130c36 --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/package.json @@ -0,0 +1,10 @@ +{ + "description": "OpenAPI Endpoint Exceptions Common", + "license": "SSPL-1.0 OR Elastic License 2.0", + "name": "@kbn/securitysolution-endpoint-exceptions-common", + "private": true, + "version": "1.0.0", + "scripts": { + "openapi:generate": "node scripts/openapi_generate" + } +} diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/scripts/openapi_generate.js b/packages/kbn-securitysolution-endpoint-exceptions-common/scripts/openapi_generate.js new file mode 100644 index 0000000000000..3d72bd5bc2b7b --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/scripts/openapi_generate.js @@ -0,0 +1,37 @@ +/* + * 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. + */ + +require('../../../src/setup_node_env'); +const { join, resolve } = require('path'); +const { generate } = require('@kbn/openapi-generator'); +const { REPO_ROOT } = require('@kbn/repo-info'); + +const ROOT = resolve(__dirname, '..'); + +(async () => { + await generate({ + title: 'OpenAPI Endpoint Exceptions API Schemas', + rootDir: ROOT, + sourceGlob: './api/**/*.schema.yaml', + templateName: 'zod_operation_schema', + }); + + await generate({ + title: 'Endpoint Exceptions API client for tests', + rootDir: ROOT, + sourceGlob: './api/**/*.schema.yaml', + templateName: 'api_client_supertest', + skipLinting: true, + bundle: { + outFile: join( + REPO_ROOT, + 'x-pack/test/api_integration/services/security_solution_endpoint_exceptions_api.gen.ts' + ), + }, + }); +})(); diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/tsconfig.json b/packages/kbn-securitysolution-endpoint-exceptions-common/tsconfig.json new file mode 100644 index 0000000000000..750feb76c4bd2 --- /dev/null +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "outDir": "target/types", + "types": ["jest", "node"] + }, + "exclude": ["target/**/*"], + "extends": "../../tsconfig.base.json", + "include": ["**/*.ts"], + "kbn_references": ["@kbn/securitysolution-exceptions-common", "@kbn/openapi-common"] +} diff --git a/tsconfig.base.json b/tsconfig.base.json index e073f465a20ec..894f8684d535b 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1502,6 +1502,8 @@ "@kbn/securitysolution-data-table/*": ["x-pack/packages/security-solution/data_table/*"], "@kbn/securitysolution-ecs": ["packages/kbn-securitysolution-ecs"], "@kbn/securitysolution-ecs/*": ["packages/kbn-securitysolution-ecs/*"], + "@kbn/securitysolution-endpoint-exceptions-common": ["packages/kbn-securitysolution-endpoint-exceptions-common"], + "@kbn/securitysolution-endpoint-exceptions-common/*": ["packages/kbn-securitysolution-endpoint-exceptions-common/*"], "@kbn/securitysolution-es-utils": ["packages/kbn-securitysolution-es-utils"], "@kbn/securitysolution-es-utils/*": ["packages/kbn-securitysolution-es-utils/*"], "@kbn/securitysolution-exception-list-components": ["packages/kbn-securitysolution-exception-list-components"], @@ -1892,9 +1894,7 @@ "@kbn/zod-helpers/*": ["packages/kbn-zod-helpers/*"], // END AUTOMATED PACKAGE LISTING // Allows for importing from `kibana` package for the exported types. - "@emotion/core": [ - "typings/@emotion" - ] + "@emotion/core": ["typings/@emotion"] }, // Support .tsx files and transform JSX into calls to React.createElement "jsx": "react", diff --git a/x-pack/plugins/lists/common/api/exceptions/create_endpoint_list/create_endpoint_list_route.ts b/x-pack/plugins/lists/common/api/exceptions/create_endpoint_list/create_endpoint_list_route.ts deleted file mode 100644 index e3d43a6b6a75c..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/create_endpoint_list/create_endpoint_list_route.ts +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { - CreateEndpointListSchema, - createEndpointListSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export const createEndpointListResponse = createEndpointListSchema; -export type CreateEndpointListResponse = CreateEndpointListSchema; diff --git a/x-pack/plugins/lists/common/api/exceptions/create_endpoint_list_item/create_endpoint_list_item_route.ts b/x-pack/plugins/lists/common/api/exceptions/create_endpoint_list_item/create_endpoint_list_item_route.ts deleted file mode 100644 index f4815aa8aba5f..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/create_endpoint_list_item/create_endpoint_list_item_route.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { - CreateEndpointListItemSchemaDecoded, - ExceptionListItemSchema, - createEndpointListItemSchema, - exceptionListItemSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { createEndpointListItemSchema as createEndpointListItemRequest }; -export type { CreateEndpointListItemSchemaDecoded as CreateEndpointListItemRequestDecoded }; - -export const createEndpointListItemResponse = exceptionListItemSchema; -export type CreateEndpointListItemResponse = ExceptionListItemSchema; diff --git a/x-pack/plugins/lists/common/api/exceptions/delete_endpoint_list_item/delete_endpoint_list_item_route.ts b/x-pack/plugins/lists/common/api/exceptions/delete_endpoint_list_item/delete_endpoint_list_item_route.ts deleted file mode 100644 index c6b4a3758ac67..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/delete_endpoint_list_item/delete_endpoint_list_item_route.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { - DeleteEndpointListItemSchemaDecoded, - deleteEndpointListItemSchema, - exceptionListItemSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { - deleteEndpointListItemSchema as deleteEndpointListItemRequestQuery, - exceptionListItemSchema as deleteEndpointListItemResponse, -}; -export type { DeleteEndpointListItemSchemaDecoded as DeleteEndpointListItemRequestQueryDecoded }; diff --git a/x-pack/plugins/lists/common/api/exceptions/find_endpoint_list_item/find_endpoint_list_item_route.ts b/x-pack/plugins/lists/common/api/exceptions/find_endpoint_list_item/find_endpoint_list_item_route.ts deleted file mode 100644 index 4d03147b87a72..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/find_endpoint_list_item/find_endpoint_list_item_route.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { - FindEndpointListItemSchemaDecoded, - findEndpointListItemSchema, - foundExceptionListItemSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { - findEndpointListItemSchema as findEndpointListItemRequestQuery, - foundExceptionListItemSchema as findEndpointListItemResponse, -}; -export type { FindEndpointListItemSchemaDecoded as FindEndpointListItemRequestQueryDecoded }; diff --git a/x-pack/plugins/lists/common/api/exceptions/read_endpoint_list_item/read_endpoint_list_item_route.ts b/x-pack/plugins/lists/common/api/exceptions/read_endpoint_list_item/read_endpoint_list_item_route.ts deleted file mode 100644 index 684f124f427ca..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/read_endpoint_list_item/read_endpoint_list_item_route.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { - ReadEndpointListItemSchemaDecoded, - exceptionListItemSchema, - readEndpointListItemSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { - readEndpointListItemSchema as readEndpointListItemRequestQuery, - exceptionListItemSchema as readEndpointListItemResponse, -}; -export type { ReadEndpointListItemSchemaDecoded as ReadEndpointListItemRequestQueryDecoded }; diff --git a/x-pack/plugins/lists/common/api/exceptions/update_endpoint_list_item/update_endpoint_list_item_route.ts b/x-pack/plugins/lists/common/api/exceptions/update_endpoint_list_item/update_endpoint_list_item_route.ts deleted file mode 100644 index 4d6b2095e6a8e..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/update_endpoint_list_item/update_endpoint_list_item_route.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { - UpdateEndpointListItemSchemaDecoded, - exceptionListItemSchema, - updateEndpointListItemSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { - updateEndpointListItemSchema as updateEndpointListItemRequest, - exceptionListItemSchema as updateEndpointListItemResponse, -}; -export type { UpdateEndpointListItemSchemaDecoded as UpdateEndpointListItemRequestDecoded }; diff --git a/x-pack/plugins/lists/common/api/index.ts b/x-pack/plugins/lists/common/api/index.ts index bc8f36dbfde0e..832c6c5cbe77d 100644 --- a/x-pack/plugins/lists/common/api/index.ts +++ b/x-pack/plugins/lists/common/api/index.ts @@ -5,12 +5,6 @@ * 2.0. */ -export * from './exceptions/create_endpoint_list_item/create_endpoint_list_item_route'; -export * from './exceptions/create_endpoint_list/create_endpoint_list_route'; export * from './exceptions/create_exception_list/create_exception_list_route'; -export * from './exceptions/delete_endpoint_list_item/delete_endpoint_list_item_route'; -export * from './exceptions/find_endpoint_list_item/find_endpoint_list_item_route'; export * from './exceptions/get_exception_filter/get_exception_filter_route'; -export * from './exceptions/read_endpoint_list_item/read_endpoint_list_item_route'; -export * from './exceptions/update_endpoint_list_item/update_endpoint_list_item_route'; export * from './values/find_lists_by_size/find_lists_by_size_route'; diff --git a/x-pack/plugins/lists/server/routes/create_endpoint_list_item_route.ts b/x-pack/plugins/lists/server/routes/create_endpoint_list_item_route.ts index f4381a8675872..29f7c14c863c6 100644 --- a/x-pack/plugins/lists/server/routes/create_endpoint_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/create_endpoint_list_item_route.ts @@ -5,18 +5,18 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; +import { v4 as uuidv4 } from 'uuid'; import { transformError } from '@kbn/securitysolution-es-utils'; import { ENDPOINT_LIST_ID, ENDPOINT_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; - +import { buildRouteValidationWithZod, stringifyZodError } from '@kbn/zod-helpers'; import { - CreateEndpointListItemRequestDecoded, - createEndpointListItemRequest, - createEndpointListItemResponse, -} from '../../common/api'; + CreateEndpointListItemRequestBody, + CreateEndpointListItemResponse, +} from '@kbn/securitysolution-endpoint-exceptions-common/api'; + import type { ListsPluginRouter } from '../types'; -import { buildRouteValidation, buildSiemResponse, getExceptionListClient } from './utils'; +import { buildSiemResponse, getExceptionListClient } from './utils'; import { validateExceptionListSize } from './validate'; export const createEndpointListItemRoute = (router: ListsPluginRouter): void => { @@ -32,10 +32,7 @@ export const createEndpointListItemRoute = (router: ListsPluginRouter): void => { validate: { request: { - body: buildRouteValidation< - typeof createEndpointListItemRequest, - CreateEndpointListItemRequestDecoded - >(createEndpointListItemRequest), + body: buildRouteValidationWithZod(CreateEndpointListItemRequestBody), }, }, version: '2023-10-31', @@ -50,7 +47,7 @@ export const createEndpointListItemRoute = (router: ListsPluginRouter): void => comments, description, entries, - item_id: itemId, + item_id: itemId = uuidv4(), os_types: osTypes, type, } = request.body; @@ -76,9 +73,10 @@ export const createEndpointListItemRoute = (router: ListsPluginRouter): void => tags, type, }); - const [validated, errors] = validate(createdList, createEndpointListItemResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); + + const { success, data, error } = CreateEndpointListItemResponse.safeParse(createdList); + if (success === false) { + return siemResponse.error({ body: stringifyZodError(error), statusCode: 500 }); } else { const listSizeError = await validateExceptionListSize( exceptionLists, @@ -92,7 +90,7 @@ export const createEndpointListItemRoute = (router: ListsPluginRouter): void => }); return siemResponse.error(listSizeError); } - return response.ok({ body: validated ?? {} }); + return response.ok({ body: data ?? {} }); } } } catch (err) { diff --git a/x-pack/plugins/lists/server/routes/create_endpoint_list_route.ts b/x-pack/plugins/lists/server/routes/create_endpoint_list_route.ts index 3029c052752f5..b15658a40d7fb 100644 --- a/x-pack/plugins/lists/server/routes/create_endpoint_list_route.ts +++ b/x-pack/plugins/lists/server/routes/create_endpoint_list_route.ts @@ -5,12 +5,11 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { ENDPOINT_LIST_URL } from '@kbn/securitysolution-list-constants'; +import { CreateEndpointListResponse } from '@kbn/securitysolution-endpoint-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; -import { createEndpointListResponse } from '../../common/api'; import { buildSiemResponse } from './utils'; import { getExceptionListClient } from './utils/get_exception_list_client'; @@ -43,18 +42,15 @@ export const createEndpointListRoute = (router: ListsPluginRouter): void => { try { const exceptionLists = await getExceptionListClient(context); const createdList = await exceptionLists.createEndpointList(); + // We always return ok on a create endpoint list route but with an empty body as // an additional fetch of the full list would be slower and the UI has everything hard coded // within it to get the list if it needs details about it. Our goal is to be as fast as possible // and block the least amount of time with this route since it could end up in various parts of the // stack at some point such as repeatedly being called by endpoint agents. - const body = createdList ?? {}; - const [validated, errors] = validate(body, createEndpointListResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ + body: CreateEndpointListResponse.parse(createdList ?? {}), + }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/delete_endpoint_list_item_route.ts b/x-pack/plugins/lists/server/routes/delete_endpoint_list_item_route.ts index 58a8c1586a594..0262b747744ec 100644 --- a/x-pack/plugins/lists/server/routes/delete_endpoint_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/delete_endpoint_list_item_route.ts @@ -5,19 +5,17 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { ENDPOINT_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + DeleteEndpointListItemRequestQuery, + DeleteEndpointListItemResponse, +} from '@kbn/securitysolution-endpoint-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; -import { - DeleteEndpointListItemRequestQueryDecoded, - deleteEndpointListItemRequestQuery, - deleteEndpointListItemResponse, -} from '../../common/api'; import { - buildRouteValidation, buildSiemResponse, getErrorMessageExceptionListItem, getExceptionListClient, @@ -36,10 +34,7 @@ export const deleteEndpointListItemRoute = (router: ListsPluginRouter): void => { validate: { request: { - query: buildRouteValidation< - typeof deleteEndpointListItemRequestQuery, - DeleteEndpointListItemRequestQueryDecoded - >(deleteEndpointListItemRequestQuery), + query: buildRouteValidationWithZod(DeleteEndpointListItemRequestQuery), }, }, version: '2023-10-31', @@ -65,12 +60,7 @@ export const deleteEndpointListItemRoute = (router: ListsPluginRouter): void => statusCode: 404, }); } else { - const [validated, errors] = validate(deleted, deleteEndpointListItemResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: DeleteEndpointListItemResponse.parse(deleted) }); } } } catch (err) { diff --git a/x-pack/plugins/lists/server/routes/find_endpoint_list_item_route.ts b/x-pack/plugins/lists/server/routes/find_endpoint_list_item_route.ts index 152b7f62153f1..01539424b8d69 100644 --- a/x-pack/plugins/lists/server/routes/find_endpoint_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/find_endpoint_list_item_route.ts @@ -5,18 +5,17 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { ENDPOINT_LIST_ID, ENDPOINT_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + FindEndpointListItemsRequestQuery, + FindEndpointListItemsResponse, +} from '@kbn/securitysolution-endpoint-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; -import { - FindEndpointListItemRequestQueryDecoded, - findEndpointListItemRequestQuery, - findEndpointListItemResponse, -} from '../../common/api'; -import { buildRouteValidation, buildSiemResponse, getExceptionListClient } from './utils'; +import { buildSiemResponse, getExceptionListClient } from './utils'; export const findEndpointListItemRoute = (router: ListsPluginRouter): void => { router.versioned @@ -31,10 +30,7 @@ export const findEndpointListItemRoute = (router: ListsPluginRouter): void => { { validate: { request: { - query: buildRouteValidation< - typeof findEndpointListItemRequestQuery, - FindEndpointListItemRequestQueryDecoded - >(findEndpointListItemRequestQuery), + query: buildRouteValidationWithZod(FindEndpointListItemsRequestQuery), }, }, version: '2023-10-31', @@ -69,12 +65,8 @@ export const findEndpointListItemRoute = (router: ListsPluginRouter): void => { statusCode: 404, }); } - const [validated, errors] = validate(exceptionListItems, findEndpointListItemResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + + return response.ok({ body: FindEndpointListItemsResponse.parse(exceptionListItems) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/read_endpoint_list_item_route.ts b/x-pack/plugins/lists/server/routes/read_endpoint_list_item_route.ts index b09d34f90c04a..d7e057a70d5de 100644 --- a/x-pack/plugins/lists/server/routes/read_endpoint_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/read_endpoint_list_item_route.ts @@ -5,19 +5,17 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { ENDPOINT_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + ReadEndpointListItemRequestQuery, + ReadEndpointListItemResponse, +} from '@kbn/securitysolution-endpoint-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; -import { - ReadEndpointListItemRequestQueryDecoded, - readEndpointListItemRequestQuery, - readEndpointListItemResponse, -} from '../../common/api'; import { - buildRouteValidation, buildSiemResponse, getErrorMessageExceptionListItem, getExceptionListClient, @@ -36,10 +34,7 @@ export const readEndpointListItemRoute = (router: ListsPluginRouter): void => { { validate: { request: { - query: buildRouteValidation< - typeof readEndpointListItemRequestQuery, - ReadEndpointListItemRequestQueryDecoded - >(readEndpointListItemRequestQuery), + query: buildRouteValidationWithZod(ReadEndpointListItemRequestQuery), }, }, version: '2023-10-31', @@ -60,12 +55,7 @@ export const readEndpointListItemRoute = (router: ListsPluginRouter): void => { statusCode: 404, }); } else { - const [validated, errors] = validate(exceptionListItem, readEndpointListItemResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: ReadEndpointListItemResponse.parse(exceptionListItem) }); } } else { return siemResponse.error({ body: 'id or item_id required', statusCode: 400 }); diff --git a/x-pack/plugins/lists/server/routes/update_endpoint_list_item_route.ts b/x-pack/plugins/lists/server/routes/update_endpoint_list_item_route.ts index 73d57941f75e5..048816c519a0f 100644 --- a/x-pack/plugins/lists/server/routes/update_endpoint_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/update_endpoint_list_item_route.ts @@ -5,18 +5,17 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { ENDPOINT_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + UpdateEndpointListItemRequestBody, + UpdateEndpointListItemResponse, +} from '@kbn/securitysolution-endpoint-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; -import { - UpdateEndpointListItemRequestDecoded, - updateEndpointListItemRequest, - updateEndpointListItemResponse, -} from '../../common/api'; -import { buildRouteValidation, buildSiemResponse } from './utils'; +import { buildSiemResponse } from './utils'; import { getExceptionListClient } from '.'; @@ -33,10 +32,7 @@ export const updateEndpointListItemRoute = (router: ListsPluginRouter): void => { validate: { request: { - body: buildRouteValidation< - typeof updateEndpointListItemRequest, - UpdateEndpointListItemRequestDecoded - >(updateEndpointListItemRequest), + body: buildRouteValidationWithZod(UpdateEndpointListItemRequestBody), }, }, version: '2023-10-31', @@ -84,12 +80,7 @@ export const updateEndpointListItemRoute = (router: ListsPluginRouter): void => }); } } else { - const [validated, errors] = validate(exceptionListItem, updateEndpointListItemResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: UpdateEndpointListItemResponse.parse(exceptionListItem) }); } } catch (err) { const error = transformError(err); diff --git a/x-pack/plugins/lists/tsconfig.json b/x-pack/plugins/lists/tsconfig.json index 784e8e27ef7d0..a7d1c5b7b3153 100644 --- a/x-pack/plugins/lists/tsconfig.json +++ b/x-pack/plugins/lists/tsconfig.json @@ -21,6 +21,7 @@ "@kbn/securitysolution-list-api", "@kbn/securitysolution-lists-common", "@kbn/securitysolution-exceptions-common", + "@kbn/securitysolution-endpoint-exceptions-common", "@kbn/kibana-react-plugin", "@kbn/i18n", "@kbn/data-plugin", diff --git a/x-pack/test/api_integration/services/security_solution_endpoint_exceptions_api.gen.ts b/x-pack/test/api_integration/services/security_solution_endpoint_exceptions_api.gen.ts new file mode 100644 index 0000000000000..9f77c4575828a --- /dev/null +++ b/x-pack/test/api_integration/services/security_solution_endpoint_exceptions_api.gen.ts @@ -0,0 +1,100 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Endpoint Exceptions API client for tests + * version: Bundle (no version) + */ + +import { + ELASTIC_HTTP_VERSION_HEADER, + X_ELASTIC_INTERNAL_ORIGIN_REQUEST, +} from '@kbn/core-http-common'; + +import { CreateEndpointListItemRequestBodyInput } from '@kbn/securitysolution-endpoint-exceptions-common/api/create_endpoint_list_item/create_endpoint_list_item.gen'; +import { DeleteEndpointListItemRequestQueryInput } from '@kbn/securitysolution-endpoint-exceptions-common/api/delete_endpoint_list_item/delete_endpoint_list_item.gen'; +import { FindEndpointListItemsRequestQueryInput } from '@kbn/securitysolution-endpoint-exceptions-common/api/find_endpoint_list_item/find_endpoint_list_item.gen'; +import { ReadEndpointListItemRequestQueryInput } from '@kbn/securitysolution-endpoint-exceptions-common/api/read_endpoint_list_item/read_endpoint_list_item.gen'; +import { UpdateEndpointListItemRequestBodyInput } from '@kbn/securitysolution-endpoint-exceptions-common/api/update_endpoint_list_item/update_endpoint_list_item.gen'; +import { FtrProviderContext } from '../ftr_provider_context'; + +export function SecuritySolutionApiProvider({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + return { + /** + * Creates an endpoint list or does nothing if the list already exists + */ + createEndpointList() { + return supertest + .post('/api/endpoint_list') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana'); + }, + createEndpointListItem(props: CreateEndpointListItemProps) { + return supertest + .post('/api/endpoint_list/items') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .send(props.body as object); + }, + deleteEndpointListItem(props: DeleteEndpointListItemProps) { + return supertest + .delete('/api/endpoint_list/items') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + findEndpointListItems(props: FindEndpointListItemsProps) { + return supertest + .get('/api/endpoint_list/items/_find') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + readEndpointListItem(props: ReadEndpointListItemProps) { + return supertest + .get('/api/endpoint_list/items') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + updateEndpointListItem(props: UpdateEndpointListItemProps) { + return supertest + .put('/api/endpoint_list/items') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .send(props.body as object); + }, + }; +} + +export interface CreateEndpointListItemProps { + body: CreateEndpointListItemRequestBodyInput; +} +export interface DeleteEndpointListItemProps { + query: DeleteEndpointListItemRequestQueryInput; +} +export interface FindEndpointListItemsProps { + query: FindEndpointListItemsRequestQueryInput; +} +export interface ReadEndpointListItemProps { + query: ReadEndpointListItemRequestQueryInput; +} +export interface UpdateEndpointListItemProps { + body: UpdateEndpointListItemRequestBodyInput; +} diff --git a/x-pack/test/security_solution_cypress/cypress/tasks/api_calls/exceptions.ts b/x-pack/test/security_solution_cypress/cypress/tasks/api_calls/exceptions.ts index f66eab9528d9d..201885ced959c 100644 --- a/x-pack/test/security_solution_cypress/cypress/tasks/api_calls/exceptions.ts +++ b/x-pack/test/security_solution_cypress/cypress/tasks/api_calls/exceptions.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { CreateEndpointListItemResponse } from '@kbn/lists-plugin/common/api'; +import { CreateEndpointListItemResponse } from '@kbn/securitysolution-endpoint-exceptions-common/api'; import type { ExceptionListSchema, ExceptionListItemSchema, diff --git a/x-pack/test/security_solution_cypress/cypress/tsconfig.json b/x-pack/test/security_solution_cypress/cypress/tsconfig.json index c6e1919d8b5fc..d07d03536f7f4 100644 --- a/x-pack/test/security_solution_cypress/cypress/tsconfig.json +++ b/x-pack/test/security_solution_cypress/cypress/tsconfig.json @@ -33,7 +33,6 @@ "@kbn/security-solution-plugin", "@kbn/dev-utils", "@kbn/config-schema", - "@kbn/lists-plugin", "@kbn/securitysolution-list-constants", "@kbn/security-plugin", "@kbn/management-settings-ids", @@ -42,5 +41,6 @@ "@kbn/license-management-plugin", "@kbn/actions-plugin", "@kbn/alerts-ui-shared", + "@kbn/securitysolution-endpoint-exceptions-common", ] } diff --git a/x-pack/test/tsconfig.json b/x-pack/test/tsconfig.json index 6e05b3d929fbe..887dff951e312 100644 --- a/x-pack/test/tsconfig.json +++ b/x-pack/test/tsconfig.json @@ -174,6 +174,7 @@ "@kbn/openapi-common", "@kbn/securitysolution-lists-common", "@kbn/securitysolution-exceptions-common", + "@kbn/securitysolution-endpoint-exceptions-common", "@kbn/entityManager-plugin", "@kbn/osquery-plugin", "@kbn/entities-schema" diff --git a/yarn.lock b/yarn.lock index dbf662adb4c0f..4a5ed8f8eff26 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6269,6 +6269,10 @@ version "0.0.0" uid "" +"@kbn/securitysolution-endpoint-exceptions-common@link:packages/kbn-securitysolution-endpoint-exceptions-common": + version "0.0.0" + uid "" + "@kbn/securitysolution-es-utils@link:packages/kbn-securitysolution-es-utils": version "0.0.0" uid ""