forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Entity Analytics] New API endpoint to cleanup the risk engine instal…
…lation and data (elastic#191843) ## Summary 1. Create a new public API endpoint : `DELETE /api/risk_score/engine/dangerously_delete_data` ## Test cases Result ``` PASS x-pack/plugins/security_solution/server/lib/entity_analytics/risk_engine/routes/delete.test.ts (7.017 s) risk engine cleanup route invokes the risk engine cleanup route ✓ should call the router with the correct route and handler (71 ms) ✓ returns a 200 when cleanup is successful (64 ms) ✓ returns a 500 when cleanup is unsuccessful (57 ms) ✓ returns a 500 when cleanup is unsuccessful with multiple errors (53 ms) when task manager is unavailable ✓ returns a 400 when task manager is unavailable (55 ms) when user does not have the required privileges ✓ returns a 403 when user does not have the required privileges (88 ms) ``` ### API Responses ## When multiple errors encountered ``` { "risk_engine_cleanup": false, "errors": [ { "seq": 1, "error": "resource_not_found_exception\n\tRoot causes:\n\t\tresource_not_found_exception: Transform with id [risk_score_latest_transform_default] could not be found" }, { "seq": 2, "error": "index_not_found_exception\n\tRoot causes:\n\t\tindex_not_found_exception: no such index [risk-score.risk-score-default]" }, { "seq": 3, "error": "index_template_missing_exception\n\tRoot causes:\n\t\tindex_template_missing_exception: index_template [.risk-score.risk-score-default-index-template] missing" }, { "seq": 4, "error": "resource_not_found_exception\n\tRoot causes:\n\t\tresource_not_found_exception: .risk-score-mappings" } ], "status_code": 500 } ``` ## Success ``` { "risk_engine_cleanup": true } ``` ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### OpenAPI spec ![image](https://github.com/user-attachments/assets/56d69602-061d-4a01-9d2b-01a8398ffc76) ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- Loading branch information
1 parent
8d7dad2
commit 22f451b
Showing
19 changed files
with
823 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...ins/security_solution/common/api/entity_analytics/risk_engine/engine_cleanup_route.gen.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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: Risk Scoring API | ||
* version: 1 | ||
*/ | ||
|
||
import { z } from '@kbn/zod'; | ||
|
||
export type CleanUpRiskEngineErrorResponse = z.infer<typeof CleanUpRiskEngineErrorResponse>; | ||
export const CleanUpRiskEngineErrorResponse = z.object({ | ||
cleanup_successful: z.boolean(), | ||
errors: z.array( | ||
z.object({ | ||
seq: z.number().int(), | ||
error: z.string(), | ||
}) | ||
), | ||
}); | ||
|
||
export type CleanUpRiskEngineResponse = z.infer<typeof CleanUpRiskEngineResponse>; | ||
export const CleanUpRiskEngineResponse = z.object({ | ||
cleanup_successful: z.boolean().optional(), | ||
}); |
60 changes: 60 additions & 0 deletions
60
...ecurity_solution/common/api/entity_analytics/risk_engine/engine_cleanup_route.schema.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
openapi: 3.0.0 | ||
info: | ||
version: '1' | ||
title: Risk Scoring API | ||
description: These APIs allow the consumer to manage Entity Risk Scores within Entity Analytics. | ||
paths: | ||
/api/risk_score/engine/dangerously_delete_data: | ||
delete: | ||
x-labels: [ess, serverless] | ||
x-codegen-enabled: true | ||
operationId: CleanUpRiskEngine | ||
summary: Cleanup the Risk Engine | ||
description: Cleaning up the the Risk Engine by removing the indices, mapping and transforms | ||
responses: | ||
'200': | ||
description: Successful response | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
cleanup_successful: | ||
type: boolean | ||
'400': | ||
description: Task manager is unavailable | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '../common/common.schema.yaml#/components/schemas/TaskManagerUnavailableResponse' | ||
default: | ||
description: Unexpected error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/CleanUpRiskEngineErrorResponse' | ||
|
||
components: | ||
schemas: | ||
CleanUpRiskEngineErrorResponse: | ||
type: object | ||
required: | ||
- cleanup_successful | ||
- errors | ||
properties: | ||
cleanup_successful: | ||
type: boolean | ||
example: false | ||
errors: | ||
type: array | ||
items: | ||
type: object | ||
required: | ||
- seq | ||
- error | ||
properties: | ||
seq: | ||
type: integer | ||
error: | ||
type: string | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...ty_solution/docs/openapi/ess/security_solution_entity_analytics_api_1.bundled.schema.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
openapi: 3.0.3 | ||
info: | ||
description: '' | ||
title: Security Entity Analytics API (Elastic Cloud and self-hosted) | ||
version: '1' | ||
servers: | ||
- url: http://{kibana_host}:{port} | ||
variables: | ||
kibana_host: | ||
default: localhost | ||
port: | ||
default: '5601' | ||
paths: | ||
/api/risk_score/engine/dangerously_delete_data: | ||
delete: | ||
description: >- | ||
Cleaning up the the Risk Engine by removing the indices, mapping and | ||
transforms | ||
operationId: CleanUpRiskEngine | ||
responses: | ||
'200': | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
cleanup_successful: | ||
type: boolean | ||
description: Successful response | ||
'400': | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/TaskManagerUnavailableResponse' | ||
description: Task manager is unavailable | ||
default: | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/CleanUpRiskEngineErrorResponse' | ||
description: Unexpected error | ||
summary: Cleanup the Risk Engine | ||
tags: | ||
- Security Entity Analytics API | ||
components: | ||
schemas: | ||
CleanUpRiskEngineErrorResponse: | ||
type: object | ||
properties: | ||
cleanup_successful: | ||
example: false | ||
type: boolean | ||
errors: | ||
items: | ||
type: object | ||
properties: | ||
error: | ||
type: string | ||
seq: | ||
type: integer | ||
required: | ||
- seq | ||
- error | ||
type: array | ||
required: | ||
- cleanup_successful | ||
- errors | ||
TaskManagerUnavailableResponse: | ||
description: Task manager is unavailable | ||
type: object | ||
properties: | ||
message: | ||
type: string | ||
status_code: | ||
minimum: 400 | ||
type: integer | ||
required: | ||
- status_code | ||
- message | ||
securitySchemes: | ||
BasicAuth: | ||
scheme: basic | ||
type: http | ||
security: | ||
- BasicAuth: [] | ||
tags: | ||
- description: '' | ||
name: Security Entity Analytics API |
Oops, something went wrong.