-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Entity Analytics] New API endpoint to configure risk engine saved object #194545
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
Closed
abhishekbhatia1710
wants to merge
8
commits into
elastic:main
from
abhishekbhatia1710:ea-new-api-to-allow-user-to-configure-SO
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f0e10eb
Adding changes to include a public API endpoint to configure risk eng…
abhishekbhatia1710 884d0f3
Fixes for accepting the right request body
abhishekbhatia1710 368a0db
Merge branch 'main' into ea-new-api-to-allow-user-to-configure-SO
abhishekbhatia1710 32b6215
Adding unit tests
abhishekbhatia1710 e8af48f
Merge branch 'main' into ea-new-api-to-allow-user-to-configure-SO
abhishekbhatia1710 cf11636
Merge branch 'ea-new-api-to-allow-user-to-configure-SO' of https://gi…
abhishekbhatia1710 82cc11a
Adding integration tests
abhishekbhatia1710 7ead99d
Lint changes
abhishekbhatia1710 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
58 changes: 58 additions & 0 deletions
58
...ugins/security_solution/common/api/entity_analytics/risk_engine/so_configure_route.gen.ts
This file contains hidden or 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,58 @@ | ||
| /* | ||
| * 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 Engine API | ||
| * version: 2023-10-31 | ||
| */ | ||
|
|
||
| import { z } from '@kbn/zod'; | ||
|
|
||
| export type ConfigureRiskEngineRequest = z.infer<typeof ConfigureRiskEngineRequest>; | ||
| export const ConfigureRiskEngineRequest = z.object({ | ||
| dataViewId: z.string().optional(), | ||
| enabled: z.boolean().optional(), | ||
| filter: z.object({}).strict().optional(), | ||
| identifierType: z.string().optional(), | ||
| interval: z.string().optional(), | ||
| pageSize: z.number().int().optional(), | ||
| alertSampleSizePerShard: z.number().int().optional(), | ||
| range: z | ||
| .object({ | ||
| start: z.string().optional(), | ||
| end: z.string().optional(), | ||
| }) | ||
| .optional(), | ||
| excludeAlertStatuses: z | ||
| .array(z.enum(['open', 'closed', 'in-progress', 'acknowledged'])) | ||
| .optional(), | ||
| excludeAlertTags: z | ||
| .array(z.enum(['Duplicate', 'False Positive', 'Futher investigation required'])) | ||
| .optional(), | ||
| }); | ||
|
|
||
| export type ConfigureRiskEngineResponse = z.infer<typeof ConfigureRiskEngineResponse>; | ||
| export const ConfigureRiskEngineResponse = z.object({ | ||
| configuration_successful: z.boolean().optional(), | ||
| }); | ||
|
|
||
| export type ConfigureRiskEngineSavedObjectRequestBody = z.infer< | ||
| typeof ConfigureRiskEngineSavedObjectRequestBody | ||
| >; | ||
| export const ConfigureRiskEngineSavedObjectRequestBody = ConfigureRiskEngineRequest; | ||
| export type ConfigureRiskEngineSavedObjectRequestBodyInput = z.input< | ||
| typeof ConfigureRiskEngineSavedObjectRequestBody | ||
| >; | ||
|
|
||
| export type ConfigureRiskEngineSavedObjectResponse = z.infer< | ||
| typeof ConfigureRiskEngineSavedObjectResponse | ||
| >; | ||
| export const ConfigureRiskEngineSavedObjectResponse = ConfigureRiskEngineResponse; |
83 changes: 83 additions & 0 deletions
83
.../security_solution/common/api/entity_analytics/risk_engine/so_configure_route.schema.yaml
This file contains hidden or 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,83 @@ | ||
| openapi: 3.0.0 | ||
| info: | ||
| version: '2023-10-31' | ||
| title: Risk Engine API | ||
| description: These APIs allow the consumer to configure the Risk Engine saved object. | ||
| paths: | ||
| /api/risk_engine/saved_object/configure: | ||
| post: | ||
| x-labels: [ess, serverless] | ||
| x-internal: false | ||
| x-codegen-enabled: true | ||
| operationId: ConfigureRiskEngineSavedObject | ||
| summary: Configure the Risk Engine as per user requirements | ||
| requestBody: | ||
| description: User defined configuration the risk engine | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/ConfigureRiskEngineRequest' | ||
| required: true | ||
| responses: | ||
| '200': | ||
| description: Successful response | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/ConfigureRiskEngineResponse' | ||
| '400': | ||
| description: Invalid request | ||
|
|
||
| components: | ||
| schemas: | ||
| ConfigureRiskEngineRequest: | ||
| type: object | ||
| properties: | ||
| dataViewId: | ||
| type: string | ||
| enabled: | ||
| type: boolean | ||
| filter: | ||
| type: object | ||
| additionalProperties: false | ||
| properties: {} | ||
| identifierType: | ||
| type: string | ||
| interval: | ||
| type: string | ||
| pageSize: | ||
| type: integer | ||
| alertSampleSizePerShard: | ||
| type: integer | ||
| range: | ||
| type: object | ||
| properties: | ||
| start: | ||
| type: string | ||
| end: | ||
| type: string | ||
| excludeAlertStatuses: | ||
| type: array | ||
| items: | ||
| type: string | ||
| enum: | ||
| - open | ||
| - closed | ||
| - in-progress | ||
| - acknowledged | ||
| excludeAlertTags: | ||
| type: array | ||
| items: | ||
| type: string | ||
| enum: | ||
| - 'Duplicate' | ||
| - 'False Positive' | ||
| - 'Futher investigation required' | ||
|
|
||
| ConfigureRiskEngineResponse: | ||
| type: object | ||
| properties: | ||
| configuration_successful: | ||
| type: boolean | ||
|
|
||
|
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
14 changes: 14 additions & 0 deletions
14
...ugins/security_solution/server/lib/entity_analytics/risk_engine/saved_object/constants.ts
This file contains hidden or 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,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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| /** | ||
| * Public Risk Engine Saved Object Configuration routes | ||
| */ | ||
|
|
||
| export const APP_ID = 'securitySolution' as const; | ||
| export const PUBLIC_RISK_ENGINE_SO_URL = '/api/risk_score/engine/saved_object' as const; | ||
| export const RISK_ENGINE_SAVED_OBJECT_CONFIG_URL = `${PUBLIC_RISK_ENGINE_SO_URL}/config` as const; |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -6,3 +6,4 @@ | |
| */ | ||
|
|
||
| export * from './risk_engine_configuration_type'; | ||
| export * from './routes/configure'; | ||
65 changes: 65 additions & 0 deletions
65
...ecurity_solution/server/lib/entity_analytics/risk_engine/saved_object/routes/configure.ts
This file contains hidden or 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,65 @@ | ||
| /* | ||
| * 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 { buildSiemResponse } from '@kbn/lists-plugin/server/routes/utils'; | ||
| import { transformError } from '@kbn/securitysolution-es-utils'; | ||
| import type { IKibanaResponse } from '@kbn/core-http-server'; | ||
| import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; | ||
| import type { ConfigureRiskEngineResponse } from '../../../../../../common/api/entity_analytics/risk_engine'; | ||
| import { ConfigureRiskEngineSavedObjectRequestBody } from '../../../../../../common/api/entity_analytics/risk_engine'; | ||
| import { RISK_ENGINE_SAVED_OBJECT_CONFIG_URL, APP_ID } from '../constants'; | ||
| import type { EntityAnalyticsRoutesDeps } from '../../../types'; | ||
| import { API_VERSIONS } from '../../../../../../common/constants'; | ||
|
|
||
| export const riskEngineSOConfigurationRoute = (router: EntityAnalyticsRoutesDeps['router']) => { | ||
| router.versioned | ||
| .post({ | ||
| access: 'public', | ||
| path: RISK_ENGINE_SAVED_OBJECT_CONFIG_URL, | ||
| options: { | ||
| tags: ['access:securitySolution', `access:${APP_ID}-entity-analytics`], | ||
| }, | ||
| }) | ||
| .addVersion( | ||
| { | ||
| version: API_VERSIONS.public.v1, | ||
| validate: { | ||
| request: { | ||
| body: buildRouteValidationWithZod(ConfigureRiskEngineSavedObjectRequestBody), | ||
| }, | ||
| }, | ||
| }, | ||
| async (context, request, response): Promise<IKibanaResponse<ConfigureRiskEngineResponse>> => { | ||
| const siemResponse = buildSiemResponse(response); | ||
|
|
||
| const attributes = request.body; | ||
|
|
||
| const securitySolution = await context.securitySolution; | ||
| const riskEngineClient = securitySolution.getRiskEngineDataClient(); | ||
|
|
||
| try { | ||
| const result = await riskEngineClient.updateSavedObjectConfiguration({ attributes }); | ||
| if (!result) { | ||
| throw new Error('Unable to update risk engine configuration'); | ||
| } | ||
| return response.ok({ | ||
| body: { | ||
| configuration_successful: true, | ||
| }, | ||
| }); | ||
| } catch (e) { | ||
| const error = transformError(e); | ||
|
|
||
| return siemResponse.error({ | ||
| statusCode: error.statusCode, | ||
| body: { message: error.message, full_error: JSON.stringify(e) }, | ||
| bypassErrorFormat: true, | ||
| }); | ||
| } | ||
| } | ||
| ); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you split it into 2 different tests?