= RouteValidatorConfig {
it('generates the expected OpenAPI document', () => {
const [routers, versionedRouters] = createTestRouters({
- routers: { testRouter: { routes: [{ method: 'get' }, { method: 'post' }] } },
+ routers: {
+ testRouter: {
+ routes: [
+ { method: 'get' },
+ { method: 'post' },
+ {
+ method: 'delete',
+ validationSchemas: {
+ request: {},
+ response: { [200]: { description: 'good response' } },
+ },
+ },
+ ],
+ },
+ },
versionedRouters: { testVersionedRouter: { routes: [{}] } },
});
expect(
diff --git a/packages/kbn-router-to-openapispec/src/generate_oas.test.util.ts b/packages/kbn-router-to-openapispec/src/generate_oas.test.util.ts
index aeaf3aeb08a4b..f00ee68e6d86d 100644
--- a/packages/kbn-router-to-openapispec/src/generate_oas.test.util.ts
+++ b/packages/kbn-router-to-openapispec/src/generate_oas.test.util.ts
@@ -83,6 +83,7 @@ export const getVersionedRouterDefaults = (bodySchema?: RuntimeSchema) => ({
},
response: {
[200]: {
+ description: 'OK response oas-test-version-1',
body: () =>
schema.object(
{ fooResponseWithDescription: schema.string() },
@@ -101,6 +102,7 @@ export const getVersionedRouterDefaults = (bodySchema?: RuntimeSchema) => ({
request: { body: schema.object({ foo: schema.string() }) },
response: {
[200]: {
+ description: 'OK response oas-test-version-2',
body: () => schema.stream({ meta: { description: 'stream response' } }),
bodyContentType: 'application/octet-stream',
},
diff --git a/packages/kbn-router-to-openapispec/src/process_router.test.ts b/packages/kbn-router-to-openapispec/src/process_router.test.ts
index 41850b31c5d46..e73506a574003 100644
--- a/packages/kbn-router-to-openapispec/src/process_router.test.ts
+++ b/packages/kbn-router-to-openapispec/src/process_router.test.ts
@@ -33,10 +33,12 @@ describe('extractResponses', () => {
response: {
200: {
bodyContentType: 'application/test+json',
+ description: 'OK response',
body: () => schema.object({ bar: schema.number({ min: 1, max: 99 }) }),
},
404: {
bodyContentType: 'application/test2+json',
+ description: 'Not Found response',
body: () => schema.object({ ok: schema.literal(false) }),
},
unsafe: { body: false },
@@ -45,6 +47,7 @@ describe('extractResponses', () => {
};
expect(extractResponses(route, oasConverter)).toEqual({
200: {
+ description: 'OK response',
content: {
'application/test+json; Elastic-Api-Version=2023-10-31': {
schema: {
@@ -59,6 +62,7 @@ describe('extractResponses', () => {
},
},
404: {
+ description: 'Not Found response',
content: {
'application/test2+json; Elastic-Api-Version=2023-10-31': {
schema: {
diff --git a/packages/kbn-router-to-openapispec/src/process_router.ts b/packages/kbn-router-to-openapispec/src/process_router.ts
index 9437612211a92..aa40ee37d89ab 100644
--- a/packages/kbn-router-to-openapispec/src/process_router.ts
+++ b/packages/kbn-router-to-openapispec/src/process_router.ts
@@ -19,6 +19,7 @@ import {
getPathParameters,
getVersionedContentTypeString,
getVersionedHeaderParam,
+ mergeResponseContent,
prepareRoutes,
} from './util';
import type { OperationIdCounter } from './operation_id_counter';
@@ -102,18 +103,23 @@ export const extractResponses = (route: InternalRouterRoute, converter: OasConve
const contentType = extractContentType(route.options?.body);
return Object.entries(validationSchemas).reduce(
(acc, [statusCode, schema]) => {
- const oasSchema = converter.convert(schema.body());
+ const newContent = schema.body
+ ? {
+ [getVersionedContentTypeString(
+ SERVERLESS_VERSION_2023_10_31,
+ schema.bodyContentType ? [schema.bodyContentType] : contentType
+ )]: {
+ schema: converter.convert(schema.body()),
+ },
+ }
+ : undefined;
acc[statusCode] = {
...acc[statusCode],
- content: {
- ...((acc[statusCode] ?? {}) as OpenAPIV3.ResponseObject).content,
- [getVersionedContentTypeString(
- SERVERLESS_VERSION_2023_10_31,
- schema.bodyContentType ? [schema.bodyContentType] : contentType
- )]: {
- schema: oasSchema,
- },
- },
+ description: schema.description!,
+ ...mergeResponseContent(
+ ((acc[statusCode] ?? {}) as OpenAPIV3.ResponseObject).content,
+ newContent
+ ),
};
return acc;
},
diff --git a/packages/kbn-router-to-openapispec/src/process_versioned_router.test.ts b/packages/kbn-router-to-openapispec/src/process_versioned_router.test.ts
index 04605ea431b14..5ae2b4ef746ca 100644
--- a/packages/kbn-router-to-openapispec/src/process_versioned_router.test.ts
+++ b/packages/kbn-router-to-openapispec/src/process_versioned_router.test.ts
@@ -20,60 +20,6 @@ import {
extractVersionedRequestBodies,
} from './process_versioned_router';
-const route: VersionedRouterRoute = {
- path: '/foo',
- method: 'get',
- options: {
- access: 'public',
- options: { body: { access: ['application/test+json'] } as any },
- },
- handlers: [
- {
- fn: jest.fn(),
- options: {
- version: '2023-10-31',
- validate: () => ({
- request: {
- body: schema.object({ foo: schema.string() }),
- },
- response: {
- 200: {
- bodyContentType: 'application/test+json',
- body: () => schema.object({ bar: schema.number({ min: 1, max: 99 }) }),
- },
- 404: {
- bodyContentType: 'application/test2+json',
- body: () => schema.object({ ok: schema.literal(false) }),
- },
- unsafe: { body: false },
- },
- }),
- },
- },
- {
- fn: jest.fn(),
- options: {
- version: '2024-12-31',
- validate: () => ({
- request: {
- body: schema.object({ foo2: schema.string() }),
- },
- response: {
- 200: {
- bodyContentType: 'application/test+json',
- body: () => schema.object({ bar2: schema.number({ min: 1, max: 99 }) }),
- },
- 500: {
- bodyContentType: 'application/test2+json',
- body: () => schema.object({ ok: schema.literal(false) }),
- },
- unsafe: { body: false },
- },
- }),
- },
- },
- ],
-};
let oasConverter: OasConverter;
beforeEach(() => {
oasConverter = new OasConverter();
@@ -81,7 +27,9 @@ beforeEach(() => {
describe('extractVersionedRequestBodies', () => {
test('handles full request config as expected', () => {
- expect(extractVersionedRequestBodies(route, oasConverter, ['application/json'])).toEqual({
+ expect(
+ extractVersionedRequestBodies(createTestRoute(), oasConverter, ['application/json'])
+ ).toEqual({
'application/json; Elastic-Api-Version=2023-10-31': {
schema: {
additionalProperties: false,
@@ -112,8 +60,11 @@ describe('extractVersionedRequestBodies', () => {
describe('extractVersionedResponses', () => {
test('handles full response config as expected', () => {
- expect(extractVersionedResponses(route, oasConverter, ['application/test+json'])).toEqual({
+ expect(
+ extractVersionedResponses(createTestRoute(), oasConverter, ['application/test+json'])
+ ).toEqual({
200: {
+ description: 'OK response 2023-10-31\nOK response 2024-12-31', // merge multiple version descriptions
content: {
'application/test+json; Elastic-Api-Version=2023-10-31': {
schema: {
@@ -138,6 +89,7 @@ describe('extractVersionedResponses', () => {
},
},
404: {
+ description: 'Not Found response 2023-10-31',
content: {
'application/test2+json; Elastic-Api-Version=2023-10-31': {
schema: {
@@ -172,7 +124,7 @@ describe('extractVersionedResponses', () => {
describe('processVersionedRouter', () => {
it('correctly extracts the version based on the version filter', () => {
const baseCase = processVersionedRouter(
- { getRoutes: () => [route] } as unknown as CoreVersionedRouter,
+ { getRoutes: () => [createTestRoute()] } as unknown as CoreVersionedRouter,
new OasConverter(),
createOperationIdCounter(),
{}
@@ -184,7 +136,7 @@ describe('processVersionedRouter', () => {
]);
const filteredCase = processVersionedRouter(
- { getRoutes: () => [route] } as unknown as CoreVersionedRouter,
+ { getRoutes: () => [createTestRoute()] } as unknown as CoreVersionedRouter,
new OasConverter(),
createOperationIdCounter(),
{ version: '2023-10-31' }
@@ -194,3 +146,61 @@ describe('processVersionedRouter', () => {
]);
});
});
+
+const createTestRoute: () => VersionedRouterRoute = () => ({
+ path: '/foo',
+ method: 'get',
+ options: {
+ access: 'public',
+ options: { body: { access: ['application/test+json'] } as any },
+ },
+ handlers: [
+ {
+ fn: jest.fn(),
+ options: {
+ version: '2023-10-31',
+ validate: () => ({
+ request: {
+ body: schema.object({ foo: schema.string() }),
+ },
+ response: {
+ 200: {
+ description: 'OK response 2023-10-31',
+ bodyContentType: 'application/test+json',
+ body: () => schema.object({ bar: schema.number({ min: 1, max: 99 }) }),
+ },
+ 404: {
+ description: 'Not Found response 2023-10-31',
+ bodyContentType: 'application/test2+json',
+ body: () => schema.object({ ok: schema.literal(false) }),
+ },
+ unsafe: { body: false },
+ },
+ }),
+ },
+ },
+ {
+ fn: jest.fn(),
+ options: {
+ version: '2024-12-31',
+ validate: () => ({
+ request: {
+ body: schema.object({ foo2: schema.string() }),
+ },
+ response: {
+ 200: {
+ description: 'OK response 2024-12-31',
+ bodyContentType: 'application/test+json',
+ body: () => schema.object({ bar2: schema.number({ min: 1, max: 99 }) }),
+ },
+ 500: {
+ bodyContentType: 'application/test2+json',
+ body: () => schema.object({ ok: schema.literal(false) }),
+ },
+ unsafe: { body: false },
+ },
+ }),
+ },
+ },
+ ],
+});
diff --git a/packages/kbn-router-to-openapispec/src/process_versioned_router.ts b/packages/kbn-router-to-openapispec/src/process_versioned_router.ts
index 19b41f4812a30..38b8563be55af 100644
--- a/packages/kbn-router-to-openapispec/src/process_versioned_router.ts
+++ b/packages/kbn-router-to-openapispec/src/process_versioned_router.ts
@@ -15,6 +15,7 @@ import {
import type { OpenAPIV3 } from 'openapi-types';
import type { GenerateOpenApiDocumentOptionsFilters } from './generate_oas';
import type { OasConverter } from './oas_converter';
+import { isReferenceObject } from './oas_converter/common';
import type { OperationIdCounter } from './operation_id_counter';
import {
prepareRoutes,
@@ -24,6 +25,7 @@ import {
getVersionedHeaderParam,
getVersionedContentTypeString,
extractTags,
+ mergeResponseContent,
} from './util';
export const processVersionedRouter = (
@@ -153,31 +155,49 @@ export const extractVersionedResponse = (
const result: OpenAPIV3.ResponsesObject = {};
const { unsafe, ...responses } = schemas.response;
for (const [statusCode, responseSchema] of Object.entries(responses)) {
- const maybeSchema = unwrapVersionedResponseBodyValidation(responseSchema.body);
- const schema = converter.convert(maybeSchema);
- const contentTypeString = getVersionedContentTypeString(
- handler.options.version,
- responseSchema.bodyContentType ? [responseSchema.bodyContentType] : contentType
- );
- result[statusCode] = {
- ...result[statusCode],
- content: {
- ...((result[statusCode] ?? {}) as OpenAPIV3.ResponseObject).content,
+ let newContent: OpenAPIV3.ResponseObject['content'];
+ if (responseSchema.body) {
+ const maybeSchema = unwrapVersionedResponseBodyValidation(responseSchema.body);
+ const schema = converter.convert(maybeSchema);
+ const contentTypeString = getVersionedContentTypeString(
+ handler.options.version,
+ responseSchema.bodyContentType ? [responseSchema.bodyContentType] : contentType
+ );
+ newContent = {
[contentTypeString]: {
schema,
},
- },
+ };
+ }
+ result[statusCode] = {
+ ...result[statusCode],
+ description: responseSchema.description!,
+ ...mergeResponseContent(
+ ((result[statusCode] ?? {}) as OpenAPIV3.ResponseObject).content,
+ newContent
+ ),
};
}
return result;
};
+const mergeDescriptions = (
+ existing: undefined | string,
+ toAppend: OpenAPIV3.ResponsesObject[string]
+): string | undefined => {
+ if (!isReferenceObject(toAppend) && toAppend.description) {
+ return existing?.length ? `${existing}\n${toAppend.description}` : toAppend.description;
+ }
+ return existing;
+};
+
const mergeVersionedResponses = (a: OpenAPIV3.ResponsesObject, b: OpenAPIV3.ResponsesObject) => {
const result: OpenAPIV3.ResponsesObject = Object.assign({}, a);
for (const [statusCode, responseContent] of Object.entries(b)) {
const existing = (result[statusCode] as OpenAPIV3.ResponseObject) ?? {};
result[statusCode] = {
...result[statusCode],
+ description: mergeDescriptions(existing.description, responseContent)!,
content: Object.assign(
{},
existing.content,
diff --git a/packages/kbn-router-to-openapispec/src/util.test.ts b/packages/kbn-router-to-openapispec/src/util.test.ts
index b4008249fed88..0b69ee9fbc6b2 100644
--- a/packages/kbn-router-to-openapispec/src/util.test.ts
+++ b/packages/kbn-router-to-openapispec/src/util.test.ts
@@ -7,7 +7,7 @@
*/
import { OpenAPIV3 } from 'openapi-types';
-import { buildGlobalTags, prepareRoutes } from './util';
+import { buildGlobalTags, mergeResponseContent, prepareRoutes } from './util';
import { assignToPaths, extractTags } from './util';
describe('extractTags', () => {
@@ -159,3 +159,29 @@ describe('prepareRoutes', () => {
expect(prepareRoutes(input, filters)).toEqual(output);
});
});
+
+describe('mergeResponseContent', () => {
+ it('returns an empty object if no content is provided', () => {
+ expect(mergeResponseContent(undefined, undefined)).toEqual({});
+ expect(mergeResponseContent({}, {})).toEqual({});
+ });
+
+ it('merges content objects', () => {
+ expect(
+ mergeResponseContent(
+ {
+ ['application/json+v1']: { encoding: {} },
+ },
+ {
+ ['application/json+v1']: { example: 'overridden' },
+ ['application/json+v2']: {},
+ }
+ )
+ ).toEqual({
+ content: {
+ ['application/json+v1']: { example: 'overridden' },
+ ['application/json+v2']: {},
+ },
+ });
+ });
+});
diff --git a/packages/kbn-router-to-openapispec/src/util.ts b/packages/kbn-router-to-openapispec/src/util.ts
index 315b1478d4504..786dcbd5fa120 100644
--- a/packages/kbn-router-to-openapispec/src/util.ts
+++ b/packages/kbn-router-to-openapispec/src/util.ts
@@ -131,3 +131,14 @@ export const assignToPaths = (
const pathName = path.replace('?', '');
paths[pathName] = { ...paths[pathName], ...pathObject };
};
+
+export const mergeResponseContent = (
+ a: OpenAPIV3.ResponseObject['content'],
+ b: OpenAPIV3.ResponseObject['content']
+) => {
+ const mergedContent = {
+ ...(a ?? {}),
+ ...(b ?? {}),
+ };
+ return { ...(Object.keys(mergedContent).length ? { content: mergedContent } : {}) };
+};
From 03148d203f56406509f07ff7b38f1487c87946b5 Mon Sep 17 00:00:00 2001
From: Alex Szabo
Date: Mon, 22 Jul 2024 15:32:53 +0200
Subject: [PATCH 12/30] [CI] Prevent skippable changes pr break (#188740)
## Summary
Closes: https://github.com/elastic/kibana-operations/issues/159
---
.../scripts/pipelines/pull_request/pipeline.ts | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/.buildkite/scripts/pipelines/pull_request/pipeline.ts b/.buildkite/scripts/pipelines/pull_request/pipeline.ts
index cd5d9aa470b3c..db6be6c6e83f7 100644
--- a/.buildkite/scripts/pipelines/pull_request/pipeline.ts
+++ b/.buildkite/scripts/pipelines/pull_request/pipeline.ts
@@ -6,12 +6,12 @@
* Side Public License, v 1.
*/
-import { execSync } from 'child_process';
import fs from 'fs';
import prConfigs from '../../../pull_requests.json';
import { areChangesSkippable, doAnyChangesMatch, getAgentImageConfig } from '#pipeline-utils';
const prConfig = prConfigs.jobs.find((job) => job.pipelineSlug === 'kibana-pull-request');
+const emptyStep = `steps: []`;
if (!prConfig) {
console.error(`'kibana-pull-request' pipeline not found in .buildkite/pull_requests.json`);
@@ -28,21 +28,16 @@ const getPipeline = (filename: string, removeSteps = true) => {
};
(async () => {
+ const pipeline: string[] = [];
+
try {
const skippable = await areChangesSkippable(SKIPPABLE_PR_MATCHERS, REQUIRED_PATHS);
if (skippable) {
- console.log('All changes in PR are skippable. Skipping CI.');
-
- // Since we skip everything, including post-build, we need to at least make sure the commit status gets set
- execSync('BUILD_SUCCESSFUL=true .buildkite/scripts/lifecycle/commit_status_complete.sh', {
- stdio: 'inherit',
- });
- process.exit(0);
+ console.log(emptyStep);
+ return;
}
- const pipeline = [];
-
pipeline.push(getAgentImageConfig({ returnYaml: true }));
pipeline.push(getPipeline('.buildkite/pipelines/pull_request/base.yml', false));
From 91ed11ac91b1026c47056e1919b40f6b3bf9759a Mon Sep 17 00:00:00 2001
From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Date: Mon, 22 Jul 2024 15:35:59 +0200
Subject: [PATCH 13/30] skip failing test suite (#118488)
---
.../test_suites/saved_objects_management/hidden_types.ts | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/test/plugin_functional/test_suites/saved_objects_management/hidden_types.ts b/test/plugin_functional/test_suites/saved_objects_management/hidden_types.ts
index 8e7adb504ebee..99a86bbe23791 100644
--- a/test/plugin_functional/test_suites/saved_objects_management/hidden_types.ts
+++ b/test/plugin_functional/test_suites/saved_objects_management/hidden_types.ts
@@ -21,7 +21,8 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide
const esArchiver = getService('esArchiver');
const testSubjects = getService('testSubjects');
- describe('saved objects management with hidden types', () => {
+ // Failing: See https://github.com/elastic/kibana/issues/118488
+ describe.skip('saved objects management with hidden types', () => {
before(async () => {
await esArchiver.load(
'test/functional/fixtures/es_archiver/saved_objects_management/hidden_types'
From 7f3f757a382f7c567401dde05131beab33b577e0 Mon Sep 17 00:00:00 2001
From: Pierre Gayvallet
Date: Mon, 22 Jul 2024 15:40:35 +0200
Subject: [PATCH 14/30] [i18n] include i18nrc file in 3rd party plugin bundles
(#188814)
## Summary
Fix #57273
Include the `. i18nrc.json` file when bundling 3rd party plugins
---
packages/kbn-plugin-helpers/src/integration_tests/build.test.ts | 1 +
packages/kbn-plugin-helpers/src/tasks/write_server_files.ts | 1 +
2 files changed, 2 insertions(+)
diff --git a/packages/kbn-plugin-helpers/src/integration_tests/build.test.ts b/packages/kbn-plugin-helpers/src/integration_tests/build.test.ts
index e7a5db404c5ca..90ba58720d3c2 100644
--- a/packages/kbn-plugin-helpers/src/integration_tests/build.test.ts
+++ b/packages/kbn-plugin-helpers/src/integration_tests/build.test.ts
@@ -96,6 +96,7 @@ it('builds a generated plugin into a viable archive', async () => {
expect(files).toMatchInlineSnapshot(`
Array [
+ "kibana/fooTestPlugin/.i18nrc.json",
"kibana/fooTestPlugin/common/index.js",
"kibana/fooTestPlugin/kibana.json",
"kibana/fooTestPlugin/node_modules/.yarn-integrity",
diff --git a/packages/kbn-plugin-helpers/src/tasks/write_server_files.ts b/packages/kbn-plugin-helpers/src/tasks/write_server_files.ts
index 362ef171cd9da..c5c61fbad90ff 100644
--- a/packages/kbn-plugin-helpers/src/tasks/write_server_files.ts
+++ b/packages/kbn-plugin-helpers/src/tasks/write_server_files.ts
@@ -32,6 +32,7 @@ export async function writeServerFiles({
vfs.src(
[
'kibana.json',
+ '.i18nrc.json',
...(plugin.manifest.server
? config.serverSourcePatterns || [
'yarn.lock',
From 2438c36fd9bfabad9b09775d031c8cdd3d43d105 Mon Sep 17 00:00:00 2001
From: Drew Tate
Date: Mon, 22 Jul 2024 08:06:27 -0600
Subject: [PATCH 15/30] [ES|QL] improve `SORT` command suggestions (#188579)
## Summary
- Suggests options in uppercase
- Applies syntax highlighting
**Before**
https://github.com/user-attachments/assets/5f04d8fc-d61a-4779-906b-a7f4f42b4014
**After**
https://github.com/user-attachments/assets/cd585306-020a-4a55-867a-affe373666f6
---------
Co-authored-by: Stratoula Kalafateli
---
.../src/autocomplete/autocomplete.test.ts | 4 ++--
.../src/definitions/commands.ts | 4 ++--
.../kbn-monaco/src/esql/lib/esql_theme.ts | 3 +--
.../src/esql/lib/esql_token_helpers.ts | 19 ++++++++++++++++---
.../src/esql/lib/esql_tokens_provider.ts | 5 +++--
5 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts b/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts
index 687684f6fcf34..c417562499d81 100644
--- a/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts
+++ b/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts
@@ -329,8 +329,8 @@ describe('autocomplete', () => {
...getFieldNamesByType('any'),
...getFunctionSignaturesByReturnType('sort', 'any', { evalMath: true }),
]);
- testSuggestions('from a | sort stringField ', ['asc', 'desc', ',', '|']);
- testSuggestions('from a | sort stringField desc ', ['nulls first', 'nulls last', ',', '|']);
+ testSuggestions('from a | sort stringField ', ['ASC', 'DESC', ',', '|']);
+ testSuggestions('from a | sort stringField desc ', ['NULLS FIRST', 'NULLS LAST', ',', '|']);
// @TODO: improve here
// testSuggestions('from a | sort stringField desc ', ['first', 'last']);
});
diff --git a/packages/kbn-esql-validation-autocomplete/src/definitions/commands.ts b/packages/kbn-esql-validation-autocomplete/src/definitions/commands.ts
index 2485b32837a5b..9bbc8a5b903d2 100644
--- a/packages/kbn-esql-validation-autocomplete/src/definitions/commands.ts
+++ b/packages/kbn-esql-validation-autocomplete/src/definitions/commands.ts
@@ -372,8 +372,8 @@ export const commandDefinitions: CommandDefinition[] = [
multipleParams: true,
params: [
{ name: 'expression', type: 'any' },
- { name: 'direction', type: 'string', optional: true, values: ['asc', 'desc'] },
- { name: 'nulls', type: 'string', optional: true, values: ['nulls first', 'nulls last'] },
+ { name: 'direction', type: 'string', optional: true, values: ['ASC', 'DESC'] },
+ { name: 'nulls', type: 'string', optional: true, values: ['NULLS FIRST', 'NULLS LAST'] },
],
},
},
diff --git a/packages/kbn-monaco/src/esql/lib/esql_theme.ts b/packages/kbn-monaco/src/esql/lib/esql_theme.ts
index a6907847c7ade..511fcbf9114f4 100644
--- a/packages/kbn-monaco/src/esql/lib/esql_theme.ts
+++ b/packages/kbn-monaco/src/esql/lib/esql_theme.ts
@@ -78,14 +78,13 @@ export const buildESQlTheme = (): monaco.editor.IStandaloneThemeData => ({
'as',
'expr_ws',
'limit',
- 'nulls_ordering_direction',
- 'nulls_ordering',
'null',
'enrich',
'on',
'with',
'asc',
'desc',
+ 'nulls_order',
],
euiThemeVars.euiColorAccentText,
true // isBold
diff --git a/packages/kbn-monaco/src/esql/lib/esql_token_helpers.ts b/packages/kbn-monaco/src/esql/lib/esql_token_helpers.ts
index e77b9ccfe6e40..a43360f48e9c9 100644
--- a/packages/kbn-monaco/src/esql/lib/esql_token_helpers.ts
+++ b/packages/kbn-monaco/src/esql/lib/esql_token_helpers.ts
@@ -13,9 +13,7 @@ function nonNullable(value: T | undefined): value is T {
return value != null;
}
-export function enrichTokensWithFunctionsMetadata(
- tokens: monaco.languages.IToken[]
-): monaco.languages.IToken[] {
+export function addFunctionTokens(tokens: monaco.languages.IToken[]): monaco.languages.IToken[] {
// need to trim spaces as "abs (arg)" is still valid as function
const myTokensWithoutSpaces = tokens.filter(
({ scopes }) => scopes !== 'expr_ws' + ESQL_TOKEN_POSTFIX
@@ -34,3 +32,18 @@ export function enrichTokensWithFunctionsMetadata(
}
return [...tokens];
}
+
+export function addNullsOrder(tokens: monaco.languages.IToken[]): void {
+ const nullsIndex = tokens.findIndex((token) => token.scopes === 'nulls' + ESQL_TOKEN_POSTFIX);
+ if (
+ // did we find a "nulls"?
+ nullsIndex > -1 &&
+ // is the next non-whitespace token an order?
+ ['first' + ESQL_TOKEN_POSTFIX, 'last' + ESQL_TOKEN_POSTFIX].includes(
+ tokens[nullsIndex + 2]?.scopes
+ )
+ ) {
+ tokens[nullsIndex].scopes = 'nulls_order' + ESQL_TOKEN_POSTFIX;
+ tokens.splice(nullsIndex + 1, 2);
+ }
+}
diff --git a/packages/kbn-monaco/src/esql/lib/esql_tokens_provider.ts b/packages/kbn-monaco/src/esql/lib/esql_tokens_provider.ts
index 378e86cbfb27d..d5cbdf4349b4c 100644
--- a/packages/kbn-monaco/src/esql/lib/esql_tokens_provider.ts
+++ b/packages/kbn-monaco/src/esql/lib/esql_tokens_provider.ts
@@ -15,7 +15,7 @@ import { ESQLLineTokens } from './esql_line_tokens';
import { ESQLState } from './esql_state';
import { ESQL_TOKEN_POSTFIX } from './constants';
-import { enrichTokensWithFunctionsMetadata } from './esql_token_helpers';
+import { addFunctionTokens, addNullsOrder } from './esql_token_helpers';
const EOF = -1;
@@ -77,7 +77,8 @@ export class ESQLTokensProvider implements monaco.languages.TokensProvider {
// special treatment for functions
// the previous custom Kibana grammar baked functions directly as tokens, so highlight was easier
// The ES grammar doesn't have the token concept of "function"
- const tokensWithFunctions = enrichTokensWithFunctionsMetadata(myTokens);
+ const tokensWithFunctions = addFunctionTokens(myTokens);
+ addNullsOrder(tokensWithFunctions);
return new ESQLLineTokens(tokensWithFunctions, prevState.getLineNumber() + 1);
}
From 76c6f550dc5c945f1410bb53d54923c7363c7660 Mon Sep 17 00:00:00 2001
From: Drew Tate
Date: Mon, 22 Jul 2024 08:25:30 -0600
Subject: [PATCH 16/30] [ES|QL] distinguish between trigger kinds in tests
(#188604)
## Summary
Part of https://github.com/elastic/kibana/issues/188677
Monaco editor has different [kinds of completion
triggers](https://microsoft.github.io/monaco-editor/typedoc/enums/languages.CompletionTriggerKind.html).
However, the current tests only validate the "TriggerCharacter" events.
This PR prepares the tests to support validating "Invoke" as well.
**Note:** It does change many of the tests from a "TriggerCharacter" to
an "Invoke" scenario. I think this is okay because
- there are still plenty of "TriggerCharacter" tests
- it would take a lot of work to update all the tests
- I will be adding a full set of tests to cover both scenarios as part
of https://github.com/elastic/kibana/issues/188677
- We may rely less and less on trigger characters in the future
---------
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Stratoula Kalafateli
---
.../src/autocomplete/__tests__/helpers.ts | 7 +-
.../src/autocomplete/autocomplete.test.ts | 316 ++++++++++--------
2 files changed, 182 insertions(+), 141 deletions(-)
diff --git a/packages/kbn-esql-validation-autocomplete/src/autocomplete/__tests__/helpers.ts b/packages/kbn-esql-validation-autocomplete/src/autocomplete/__tests__/helpers.ts
index 657b5de67896e..2ceb7ae2cd45a 100644
--- a/packages/kbn-esql-validation-autocomplete/src/autocomplete/__tests__/helpers.ts
+++ b/packages/kbn-esql-validation-autocomplete/src/autocomplete/__tests__/helpers.ts
@@ -247,15 +247,12 @@ export function createCustomCallbackMocks(
};
}
-export function createSuggestContext(text: string, triggerCharacter?: string) {
+export function createCompletionContext(triggerCharacter?: string) {
if (triggerCharacter) {
return { triggerCharacter, triggerKind: 1 }; // any number is fine here
}
- const foundTriggerCharIndexes = triggerCharacters.map((char) => text.lastIndexOf(char));
- const maxIndex = Math.max(...foundTriggerCharIndexes);
return {
- triggerCharacter: text[maxIndex],
- triggerKind: 1,
+ triggerKind: 0,
};
}
diff --git a/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts b/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts
index c417562499d81..26e0159e70102 100644
--- a/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts
+++ b/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts
@@ -23,7 +23,7 @@ import {
getLiteralsByType,
getDateLiteralsByFieldType,
createCustomCallbackMocks,
- createSuggestContext,
+ createCompletionContext,
getPolicyFields,
} from './__tests__/helpers';
@@ -31,31 +31,30 @@ describe('autocomplete', () => {
type TestArgs = [
string,
string[],
- (string | number)?,
+ string?,
+ number?,
Parameters?
];
- const testSuggestionsFn = (
+ const _testSuggestionsFn = (
+ { only, skip }: { only?: boolean; skip?: boolean } = {},
statement: string,
expected: string[],
- triggerCharacter: string | number = '',
+ triggerCharacter?: string,
+ _offset?: number,
customCallbacksArgs: Parameters = [
undefined,
undefined,
undefined,
- ],
- { only, skip }: { only?: boolean; skip?: boolean } = {}
+ ]
) => {
- const triggerCharacterString =
- triggerCharacter == null || typeof triggerCharacter === 'string'
- ? triggerCharacter
- : statement[triggerCharacter + 1];
- const context = createSuggestContext(statement, triggerCharacterString);
- const offset =
- typeof triggerCharacter === 'string'
- ? statement.lastIndexOf(context.triggerCharacter) + 1
- : triggerCharacter;
+ const context = createCompletionContext(triggerCharacter);
const testFn = only ? test.only : skip ? test.skip : test;
+ const offset = _offset
+ ? _offset
+ : triggerCharacter
+ ? statement.lastIndexOf(triggerCharacter) + 1
+ : statement.length;
testFn(statement, async () => {
const callbackMocks = createCustomCallbackMocks(...customCallbacksArgs);
@@ -79,24 +78,12 @@ describe('autocomplete', () => {
// DO NOT CHANGE THE NAME OF THIS FUNCTION WITHOUT ALSO CHANGING
// THE LINTER RULE IN packages/kbn-eslint-config/typescript.js
//
- const testSuggestions = Object.assign(testSuggestionsFn, {
+ const testSuggestions = Object.assign(_testSuggestionsFn.bind(null, {}), {
skip: (...args: TestArgs) => {
- const paddingArgs = ['', [undefined, undefined, undefined]].slice(args.length - 2);
- return testSuggestionsFn(
- ...((args.length > 1 ? [...args, ...paddingArgs] : args) as TestArgs),
- {
- skip: true,
- }
- );
+ return _testSuggestionsFn({ skip: true }, ...args);
},
only: (...args: TestArgs) => {
- const paddingArgs = ['', [undefined, undefined, undefined]].slice(args.length - 2);
- return testSuggestionsFn(
- ...((args.length > 1 ? [...args, ...paddingArgs] : args) as TestArgs),
- {
- only: true,
- }
- );
+ return _testSuggestionsFn({ only: true }, ...args);
},
});
@@ -223,7 +210,8 @@ describe('autocomplete', () => {
testSuggestions(
'from a | stats a=avg(numberField) | where numberField ',
[],
- '',
+ undefined,
+ undefined,
// make the fields suggest aware of the previous STATS, leave the other callbacks untouched
[[{ name: 'a', type: 'number' }], undefined, undefined]
);
@@ -277,6 +265,7 @@ describe('autocomplete', () => {
),
...getFunctionSignaturesByReturnType('where', 'number', { evalMath: true }),
],
+ undefined,
54 // after the first suggestions
);
testSuggestions(
@@ -287,42 +276,53 @@ describe('autocomplete', () => {
),
...getFunctionSignaturesByReturnType('where', 'number', { evalMath: true }),
],
+ undefined,
58 // after the first suggestions
);
});
- for (const command of ['grok', 'dissect']) {
- describe(command, () => {
- const constantPattern = command === 'grok' ? '"%{WORD:firstWord}"' : '"%{firstWord}"';
- const subExpressions = [
- '',
- `${command} stringField |`,
- `${command} stringField ${constantPattern} |`,
- `dissect stringField ${constantPattern} append_separator = ":" |`,
- ];
- if (command === 'grok') {
- subExpressions.push(`dissect stringField ${constantPattern} |`);
- }
- for (const subExpression of subExpressions) {
- testSuggestions(`from a | ${subExpression} ${command} `, getFieldNamesByType('string'));
- testSuggestions(`from a | ${subExpression} ${command} stringField `, [constantPattern]);
- testSuggestions(
- `from a | ${subExpression} ${command} stringField ${constantPattern} `,
- (command === 'dissect' ? ['APPEND_SEPARATOR = $0'] : []).concat(['|'])
- );
- if (command === 'dissect') {
- testSuggestions(
- `from a | ${subExpression} ${command} stringField ${constantPattern} append_separator = `,
- ['":"', '";"']
- );
- testSuggestions(
- `from a | ${subExpression} ${command} stringField ${constantPattern} append_separator = ":" `,
- ['|']
- );
- }
- }
- });
- }
+ describe('grok', () => {
+ const constantPattern = '"%{WORD:firstWord}"';
+ const subExpressions = [
+ '',
+ `grok stringField |`,
+ `grok stringField ${constantPattern} |`,
+ `dissect stringField ${constantPattern} append_separator = ":" |`,
+ `dissect stringField ${constantPattern} |`,
+ ];
+ for (const subExpression of subExpressions) {
+ testSuggestions(`from a | ${subExpression} grok `, getFieldNamesByType('string'));
+ testSuggestions(`from a | ${subExpression} grok stringField `, [constantPattern], ' ');
+ testSuggestions(`from a | ${subExpression} grok stringField ${constantPattern} `, ['|']);
+ }
+ });
+
+ describe('dissect', () => {
+ const constantPattern = '"%{firstWord}"';
+ const subExpressions = [
+ '',
+ `dissect stringField |`,
+ `dissect stringField ${constantPattern} |`,
+ `dissect stringField ${constantPattern} append_separator = ":" |`,
+ ];
+ for (const subExpression of subExpressions) {
+ testSuggestions(`from a | ${subExpression} dissect `, getFieldNamesByType('string'));
+ testSuggestions(`from a | ${subExpression} dissect stringField `, [constantPattern], ' ');
+ testSuggestions(
+ `from a | ${subExpression} dissect stringField ${constantPattern} `,
+ ['APPEND_SEPARATOR = $0', '|'],
+ ' '
+ );
+ testSuggestions(
+ `from a | ${subExpression} dissect stringField ${constantPattern} append_separator = `,
+ ['":"', '";"']
+ );
+ testSuggestions(
+ `from a | ${subExpression} dissect stringField ${constantPattern} append_separator = ":" `,
+ ['|']
+ );
+ }
+ });
describe('sort', () => {
testSuggestions('from a | sort ', [
@@ -347,7 +347,7 @@ describe('autocomplete', () => {
describe('rename', () => {
testSuggestions('from a | rename ', getFieldNamesByType('any'));
- testSuggestions('from a | rename stringField ', ['AS $0']);
+ testSuggestions('from a | rename stringField ', ['AS $0'], ' ');
testSuggestions('from a | rename stringField as ', ['var0']);
});
@@ -408,10 +408,11 @@ describe('autocomplete', () => {
'kubernetes.something.something',
]);
testSuggestions(`from a ${prevCommand}| enrich policy on b `, ['WITH $0', ',', '|']);
- testSuggestions(`from a ${prevCommand}| enrich policy on b with `, [
- 'var0 =',
- ...getPolicyFields('policy'),
- ]);
+ testSuggestions(
+ `from a ${prevCommand}| enrich policy on b with `,
+ ['var0 =', ...getPolicyFields('policy')],
+ ' '
+ );
testSuggestions(`from a ${prevCommand}| enrich policy on b with var0 `, ['= $0', ',', '|']);
testSuggestions(`from a ${prevCommand}| enrich policy on b with var0 = `, [
...getPolicyFields('policy'),
@@ -433,10 +434,11 @@ describe('autocomplete', () => {
`from a ${prevCommand}| enrich policy on b with var0 = stringField, var1 = `,
[...getPolicyFields('policy')]
);
- testSuggestions(`from a ${prevCommand}| enrich policy with `, [
- 'var0 =',
- ...getPolicyFields('policy'),
- ]);
+ testSuggestions(
+ `from a ${prevCommand}| enrich policy with `,
+ ['var0 =', ...getPolicyFields('policy')],
+ ' '
+ );
testSuggestions(`from a ${prevCommand}| enrich policy with stringField `, ['= $0', ',', '|']);
}
});
@@ -512,11 +514,13 @@ describe('autocomplete', () => {
);
testSuggestions(
'from a | eval raund(5, ', // note the typo in round
- []
+ [],
+ ' '
);
testSuggestions(
'from a | eval var0 = raund(5, ', // note the typo in round
- []
+ [],
+ ' '
);
testSuggestions('from a | eval a=round(numberField) ', [
',',
@@ -525,18 +529,26 @@ describe('autocomplete', () => {
'number',
]),
]);
- testSuggestions('from a | eval a=round(numberField, ', [
- ...getFieldNamesByType('number'),
- ...getFunctionSignaturesByReturnType('eval', 'number', { evalMath: true }, undefined, [
- 'round',
- ]),
- ]);
- testSuggestions('from a | eval round(numberField, ', [
- ...getFieldNamesByType('number'),
- ...getFunctionSignaturesByReturnType('eval', 'number', { evalMath: true }, undefined, [
- 'round',
- ]),
- ]);
+ testSuggestions(
+ 'from a | eval a=round(numberField, ',
+ [
+ ...getFieldNamesByType('number'),
+ ...getFunctionSignaturesByReturnType('eval', 'number', { evalMath: true }, undefined, [
+ 'round',
+ ]),
+ ],
+ ' '
+ );
+ testSuggestions(
+ 'from a | eval round(numberField, ',
+ [
+ ...getFieldNamesByType('number'),
+ ...getFunctionSignaturesByReturnType('eval', 'number', { evalMath: true }, undefined, [
+ 'round',
+ ]),
+ ],
+ ' '
+ );
testSuggestions('from a | eval a=round(numberField),', [
'var0 =',
...getFieldNamesByType('any'),
@@ -571,6 +583,7 @@ describe('autocomplete', () => {
...getFunctionSignaturesByReturnType('eval', 'any', { evalMath: true }),
],
' ',
+ undefined,
// make aware EVAL of the previous STATS command
[[], undefined, undefined]
);
@@ -592,6 +605,7 @@ describe('autocomplete', () => {
...getFunctionSignaturesByReturnType('eval', 'any', { evalMath: true }),
],
' ',
+ undefined,
// make aware EVAL of the previous STATS command with the buggy field name from expression
[[{ name: 'avg_numberField_', type: 'number' }], undefined, undefined]
);
@@ -604,6 +618,7 @@ describe('autocomplete', () => {
...getFunctionSignaturesByReturnType('eval', 'any', { evalMath: true }),
],
' ',
+ undefined,
// make aware EVAL of the previous STATS command with the buggy field name from expression
[
[
@@ -631,19 +646,27 @@ describe('autocomplete', () => {
'concat',
]).map((v) => `${v},`),
]);
- testSuggestions('from a | eval a=concat(stringField, ', [
- ...getFieldNamesByType('string'),
- ...getFunctionSignaturesByReturnType('eval', 'string', { evalMath: true }, undefined, [
- 'concat',
- ]),
- ]);
+ testSuggestions(
+ 'from a | eval a=concat(stringField, ',
+ [
+ ...getFieldNamesByType('string'),
+ ...getFunctionSignaturesByReturnType('eval', 'string', { evalMath: true }, undefined, [
+ 'concat',
+ ]),
+ ],
+ ' '
+ );
// test that the arg type is correct after minParams
- testSuggestions('from a | eval a=cidr_match(ipField, stringField,', [
- ...getFieldNamesByType('string'),
- ...getFunctionSignaturesByReturnType('eval', 'string', { evalMath: true }, undefined, [
- 'cidr_match',
- ]),
- ]);
+ testSuggestions(
+ 'from a | eval a=cidr_match(ipField, stringField, ',
+ [
+ ...getFieldNamesByType('string'),
+ ...getFunctionSignaturesByReturnType('eval', 'string', { evalMath: true }, undefined, [
+ 'cidr_match',
+ ]),
+ ],
+ ' '
+ );
// test that comma is correctly added to the suggestions if minParams is not reached yet
testSuggestions('from a | eval a=cidr_match( ', [
...getFieldNamesByType('ip').map((v) => `${v},`),
@@ -651,12 +674,16 @@ describe('autocomplete', () => {
'cidr_match',
]).map((v) => `${v},`),
]);
- testSuggestions('from a | eval a=cidr_match(ipField, ', [
- ...getFieldNamesByType('string'),
- ...getFunctionSignaturesByReturnType('eval', 'string', { evalMath: true }, undefined, [
- 'cidr_match',
- ]),
- ]);
+ testSuggestions(
+ 'from a | eval a=cidr_match(ipField, ',
+ [
+ ...getFieldNamesByType('string'),
+ ...getFunctionSignaturesByReturnType('eval', 'string', { evalMath: true }, undefined, [
+ 'cidr_match',
+ ]),
+ ],
+ ' '
+ );
// test deep function nesting suggestions (and check that the same function is not suggested)
// round(round(
// round(round(round(
@@ -684,6 +711,7 @@ describe('autocomplete', () => {
'number',
]),
],
+ undefined,
38 /* " " after abs(b) */
);
testSuggestions(
@@ -694,6 +722,7 @@ describe('autocomplete', () => {
'abs',
]),
],
+ undefined,
26 /* b column in abs */
);
@@ -747,7 +776,8 @@ describe('autocomplete', () => {
...getLiteralsByType(getTypesFromParamDefs(constantOnlyParamDefs)).map((d) =>
requiresMoreArgs ? `${d},` : d
),
- ]
+ ],
+ ' '
);
testSuggestions(
`from a | eval var0 = ${fn.name}(${Array(i).fill('field').join(', ')}${
@@ -772,7 +802,8 @@ describe('autocomplete', () => {
...getLiteralsByType(getTypesFromParamDefs(constantOnlyParamDefs)).map((d) =>
requiresMoreArgs ? `${d},` : d
),
- ]
+ ],
+ ' '
);
}
});
@@ -780,19 +811,23 @@ describe('autocomplete', () => {
}
}
- testSuggestions('from a | eval var0 = bucket(@timestamp,', getUnitDuration(1));
+ testSuggestions('from a | eval var0 = bucket(@timestamp, ', getUnitDuration(1), ' ');
describe('date math', () => {
const dateSuggestions = timeUnitsToSuggest.map(({ name }) => name);
// If a literal number is detected then suggest also date period keywords
- testSuggestions('from a | eval a = 1 ', [
- ...dateSuggestions,
- ',',
- '|',
- ...getFunctionSignaturesByReturnType('eval', 'any', { builtin: true, skipAssign: true }, [
- 'number',
- ]),
- ]);
+ testSuggestions(
+ 'from a | eval a = 1 ',
+ [
+ ...dateSuggestions,
+ ',',
+ '|',
+ ...getFunctionSignaturesByReturnType('eval', 'any', { builtin: true, skipAssign: true }, [
+ 'number',
+ ]),
+ ],
+ ' '
+ );
testSuggestions('from a | eval a = 1 year ', [
',',
'|',
@@ -800,20 +835,28 @@ describe('autocomplete', () => {
'time_interval',
]),
]);
- testSuggestions('from a | eval a = 1 day + 2 ', [
- ...dateSuggestions,
- ',',
- '|',
- ...getFunctionSignaturesByReturnType('eval', 'any', { builtin: true, skipAssign: true }, [
- 'number',
- ]),
- ]);
- testSuggestions('from a | eval 1 day + 2 ', [
- ...dateSuggestions,
- ...getFunctionSignaturesByReturnType('eval', 'any', { builtin: true, skipAssign: true }, [
- 'number',
- ]),
- ]);
+ testSuggestions(
+ 'from a | eval a = 1 day + 2 ',
+ [
+ ...dateSuggestions,
+ ',',
+ '|',
+ ...getFunctionSignaturesByReturnType('eval', 'any', { builtin: true, skipAssign: true }, [
+ 'number',
+ ]),
+ ],
+ ' '
+ );
+ testSuggestions(
+ 'from a | eval 1 day + 2 ',
+ [
+ ...dateSuggestions,
+ ...getFunctionSignaturesByReturnType('eval', 'any', { builtin: true, skipAssign: true }, [
+ 'number',
+ ]),
+ ],
+ ' '
+ );
testSuggestions(
'from a | eval var0=date_trunc()',
[
@@ -826,10 +869,11 @@ describe('autocomplete', () => {
],
'('
);
- testSuggestions('from a | eval var0=date_trunc(2 )', [
- ...dateSuggestions.map((t) => `${t},`),
- ',',
- ]);
+ testSuggestions(
+ 'from a | eval var0=date_trunc(2 )',
+ [...dateSuggestions.map((t) => `${t},`), ','],
+ ' '
+ );
});
});
@@ -838,7 +882,7 @@ describe('autocomplete', () => {
const callbackMocks = createCustomCallbackMocks(undefined, undefined, undefined);
const statement = 'from a | drop stringField | eval var0 = abs(numberField) ';
const triggerOffset = statement.lastIndexOf(' ');
- const context = createSuggestContext(statement, statement[triggerOffset]);
+ const context = createCompletionContext(statement[triggerOffset]);
await suggest(
statement,
triggerOffset + 1,
@@ -854,7 +898,7 @@ describe('autocomplete', () => {
const callbackMocks = createCustomCallbackMocks(undefined, undefined, undefined);
const statement = 'from a | drop | eval var0 = abs(numberField) ';
const triggerOffset = statement.lastIndexOf('p') + 1; // drop
- const context = createSuggestContext(statement, statement[triggerOffset]);
+ const context = createCompletionContext(statement[triggerOffset]);
await suggest(
statement,
triggerOffset + 1,
@@ -870,7 +914,7 @@ describe('autocomplete', () => {
function getSuggestionsFor(statement: string) {
const callbackMocks = createCustomCallbackMocks(undefined, undefined, undefined);
const triggerOffset = statement.lastIndexOf(' ') + 1; // drop
- const context = createSuggestContext(statement, statement[triggerOffset]);
+ const context = createCompletionContext(statement[triggerOffset]);
return suggest(
statement,
triggerOffset + 1,
From b7b3260db2b150911f283351655a721d7f16e711 Mon Sep 17 00:00:00 2001
From: Marta Bondyra <4283304+mbondyra@users.noreply.github.com>
Date: Mon, 22 Jul 2024 16:59:40 +0200
Subject: [PATCH 17/30] [Dashboard][ES|QL] Unable to load page error on
edit/add ES|QL panel (#188664)
## Summary
Fixes https://github.com/elastic/kibana/issues/184544
---
.../metric/dimension_editor.test.tsx | 33 +++++++++++--------
.../metric/dimension_editor.tsx | 2 +-
2 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.test.tsx b/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.test.tsx
index a239b12deb5be..0b34d4453b2f1 100644
--- a/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.test.tsx
+++ b/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.test.tsx
@@ -249,9 +249,9 @@ describe('dimension editor', () => {
userEvent.type(customPrefixTextbox, prefix);
};
return {
- settingNone: screen.getByTitle(/none/i),
- settingAuto: screen.getByTitle(/auto/i),
- settingCustom: screen.getByTitle(/custom/i),
+ settingNone: () => screen.getByTitle(/none/i),
+ settingAuto: () => screen.getByTitle(/auto/i),
+ settingCustom: () => screen.getByTitle(/custom/i),
customPrefixTextbox,
typePrefix,
...rtlRender,
@@ -266,6 +266,11 @@ describe('dimension editor', () => {
expect(screen.queryByTestId(SELECTORS.BREAKDOWN_EDITOR)).not.toBeInTheDocument();
});
+ it(`doesn't break when layer data is missing`, () => {
+ renderSecondaryMetricEditor({ frame: { activeData: { first: undefined } } });
+ expect(screen.getByTestId(SELECTORS.SECONDARY_METRIC_EDITOR)).toBeInTheDocument();
+ });
+
describe('metric prefix', () => {
const NONE_PREFIX = '';
const AUTO_PREFIX = undefined;
@@ -280,9 +285,9 @@ describe('dimension editor', () => {
state: localState,
});
- expect(settingAuto).toHaveAttribute('aria-pressed', 'true');
- expect(settingNone).toHaveAttribute('aria-pressed', 'false');
- expect(settingCustom).toHaveAttribute('aria-pressed', 'false');
+ expect(settingAuto()).toHaveAttribute('aria-pressed', 'true');
+ expect(settingNone()).toHaveAttribute('aria-pressed', 'false');
+ expect(settingCustom()).toHaveAttribute('aria-pressed', 'false');
expect(customPrefixTextbox).not.toBeInTheDocument();
});
@@ -290,9 +295,9 @@ describe('dimension editor', () => {
const { settingAuto, settingCustom, settingNone, customPrefixTextbox } =
renderSecondaryMetricEditor({ state: { ...localState, secondaryPrefix: NONE_PREFIX } });
- expect(settingNone).toHaveAttribute('aria-pressed', 'true');
- expect(settingAuto).toHaveAttribute('aria-pressed', 'false');
- expect(settingCustom).toHaveAttribute('aria-pressed', 'false');
+ expect(settingNone()).toHaveAttribute('aria-pressed', 'true');
+ expect(settingAuto()).toHaveAttribute('aria-pressed', 'false');
+ expect(settingCustom()).toHaveAttribute('aria-pressed', 'false');
expect(customPrefixTextbox).not.toBeInTheDocument();
});
@@ -301,9 +306,9 @@ describe('dimension editor', () => {
const { settingAuto, settingCustom, settingNone, customPrefixTextbox } =
renderSecondaryMetricEditor({ state: customPrefixState });
- expect(settingAuto).toHaveAttribute('aria-pressed', 'false');
- expect(settingNone).toHaveAttribute('aria-pressed', 'false');
- expect(settingCustom).toHaveAttribute('aria-pressed', 'true');
+ expect(settingAuto()).toHaveAttribute('aria-pressed', 'false');
+ expect(settingNone()).toHaveAttribute('aria-pressed', 'false');
+ expect(settingCustom()).toHaveAttribute('aria-pressed', 'true');
expect(customPrefixTextbox).toHaveValue(customPrefixState.secondaryPrefix);
});
@@ -316,12 +321,12 @@ describe('dimension editor', () => {
state: { ...localState, secondaryPrefix: customPrefix },
});
- userEvent.click(settingNone);
+ userEvent.click(settingNone());
expect(setState).toHaveBeenCalledWith(
expect.objectContaining({ secondaryPrefix: NONE_PREFIX })
);
- userEvent.click(settingAuto);
+ userEvent.click(settingAuto());
expect(setState).toHaveBeenCalledWith(
expect.objectContaining({ secondaryPrefix: AUTO_PREFIX })
);
diff --git a/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.tsx b/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.tsx
index f040c6dc86fa4..24248621c0982 100644
--- a/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.tsx
+++ b/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.tsx
@@ -131,7 +131,7 @@ function MaximumEditor({ setState, state, idPrefix }: SubProps) {
}
function SecondaryMetricEditor({ accessor, idPrefix, frame, layerId, setState, state }: SubProps) {
- const columnName = getColumnByAccessor(accessor, frame.activeData?.[layerId].columns)?.name;
+ const columnName = getColumnByAccessor(accessor, frame.activeData?.[layerId]?.columns)?.name;
const defaultPrefix = columnName || '';
return (
From 240d988ce301cccecf3799263a3d5afe2cfe9038 Mon Sep 17 00:00:00 2001
From: Pablo Machado
Date: Mon, 22 Jul 2024 17:06:33 +0200
Subject: [PATCH 18/30] [Observability][SecuritySolution] Update entity manager
to support extension of mappings and ingest pipeline (#188410)
## Summary
### Acceptance Criteria
- [x] When starting Kibana, the global entity index templates are no
longer created
- [x] When installing a definition, an index template is generated and
installed scoped to the definition ID
- [x] When deleting a definition, the related index template is also
deleted
- [x] The index template composes the current component templates (base,
entity, event) as well as the new custom component templates with the
setting ignore_missing_component_templates set to true
- [x] The new component templates should be named:
@platform, -history@platform,
-latest@platform, @custom,
-history@custom and -latest@custom
- [x] The ingest pipelines include a pipeline processor that calls out
the pipelines named @platform and
-history@platform or -latest@platform,
@custom and -history@custom or
-latest@custom if they exist
- [x] The index template should have a priority of 200 and be set to
managed
- [x] The @custom component template should take precedence over the
@platform component template, allowing users to override things we have
set if they so wish
- [x] set managed_by to 'elastic_entity_model',
### Checklist
- [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
---------
Co-authored-by: Kevin Lacabane
Co-authored-by: Elastic Machine
---
.../common/constants_entities.ts | 4 --
.../entity_manager/common/helpers.test.ts | 22 ++++++++++
.../entity_manager/common/helpers.ts | 19 +++++++++
.../server/lib/auth/privileges.ts | 8 +++-
.../generate_history_processors.test.ts.snap | 24 +++++++++++
.../generate_latest_processors.test.ts.snap | 24 +++++++++++
.../generate_history_processors.ts | 25 ++++++++++++
.../generate_latest_processors.ts | 25 ++++++++++++
.../install_entity_definition.test.ts | 26 ++++++++++++
.../lib/entities/install_entity_definition.ts | 40 +++++++++++++++++++
.../entities/uninstall_entity_definition.ts | 8 ++++
.../server/lib/manage_index_templates.ts | 29 ++++++++++++--
.../entity_manager/server/plugin.ts | 21 +---------
.../templates/components/helpers.test.ts | 32 +++++++++++++++
.../server/templates/components/helpers.ts | 20 ++++++++++
.../templates/entities_history_template.ts | 16 +++++---
.../templates/entities_latest_template.ts | 14 +++++--
17 files changed, 320 insertions(+), 37 deletions(-)
create mode 100644 x-pack/plugins/observability_solution/entity_manager/common/helpers.test.ts
create mode 100644 x-pack/plugins/observability_solution/entity_manager/common/helpers.ts
create mode 100644 x-pack/plugins/observability_solution/entity_manager/server/templates/components/helpers.test.ts
create mode 100644 x-pack/plugins/observability_solution/entity_manager/server/templates/components/helpers.ts
diff --git a/x-pack/plugins/observability_solution/entity_manager/common/constants_entities.ts b/x-pack/plugins/observability_solution/entity_manager/common/constants_entities.ts
index 28e9823c15620..633dfa2f9fd29 100644
--- a/x-pack/plugins/observability_solution/entity_manager/common/constants_entities.ts
+++ b/x-pack/plugins/observability_solution/entity_manager/common/constants_entities.ts
@@ -18,8 +18,6 @@ export const ENTITY_EVENT_COMPONENT_TEMPLATE_V1 =
// History constants
export const ENTITY_HISTORY = 'history' as const;
-export const ENTITY_HISTORY_INDEX_TEMPLATE_V1 =
- `${ENTITY_BASE_PREFIX}_${ENTITY_SCHEMA_VERSION_V1}_${ENTITY_HISTORY}_index_template` as const;
export const ENTITY_HISTORY_BASE_COMPONENT_TEMPLATE_V1 =
`${ENTITY_BASE_PREFIX}_${ENTITY_SCHEMA_VERSION_V1}_${ENTITY_HISTORY}_base` as const;
export const ENTITY_HISTORY_PREFIX_V1 =
@@ -29,8 +27,6 @@ export const ENTITY_HISTORY_INDEX_PREFIX_V1 =
// Latest constants
export const ENTITY_LATEST = 'latest' as const;
-export const ENTITY_LATEST_INDEX_TEMPLATE_V1 =
- `${ENTITY_BASE_PREFIX}_${ENTITY_SCHEMA_VERSION_V1}_${ENTITY_LATEST}_index_template` as const;
export const ENTITY_LATEST_BASE_COMPONENT_TEMPLATE_V1 =
`${ENTITY_BASE_PREFIX}_${ENTITY_SCHEMA_VERSION_V1}_${ENTITY_LATEST}_base` as const;
export const ENTITY_LATEST_PREFIX_V1 =
diff --git a/x-pack/plugins/observability_solution/entity_manager/common/helpers.test.ts b/x-pack/plugins/observability_solution/entity_manager/common/helpers.test.ts
new file mode 100644
index 0000000000000..50ce0caeba0a3
--- /dev/null
+++ b/x-pack/plugins/observability_solution/entity_manager/common/helpers.test.ts
@@ -0,0 +1,22 @@
+/*
+ * 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 { getEntityHistoryIndexTemplateV1, getEntityLatestIndexTemplateV1 } from './helpers';
+
+describe('helpers', () => {
+ it('getEntityHistoryIndexTemplateV1 should return the correct value', () => {
+ const definitionId = 'test';
+ const result = getEntityHistoryIndexTemplateV1(definitionId);
+ expect(result).toEqual('entities_v1_history_test_index_template');
+ });
+
+ it('getEntityLatestIndexTemplateV1 should return the correct value', () => {
+ const definitionId = 'test';
+ const result = getEntityLatestIndexTemplateV1(definitionId);
+ expect(result).toEqual('entities_v1_latest_test_index_template');
+ });
+});
diff --git a/x-pack/plugins/observability_solution/entity_manager/common/helpers.ts b/x-pack/plugins/observability_solution/entity_manager/common/helpers.ts
new file mode 100644
index 0000000000000..97a6317fee283
--- /dev/null
+++ b/x-pack/plugins/observability_solution/entity_manager/common/helpers.ts
@@ -0,0 +1,19 @@
+/*
+ * 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 {
+ ENTITY_BASE_PREFIX,
+ ENTITY_HISTORY,
+ ENTITY_LATEST,
+ ENTITY_SCHEMA_VERSION_V1,
+} from './constants_entities';
+
+export const getEntityHistoryIndexTemplateV1 = (definitionId: string) =>
+ `${ENTITY_BASE_PREFIX}_${ENTITY_SCHEMA_VERSION_V1}_${ENTITY_HISTORY}_${definitionId}_index_template` as const;
+
+export const getEntityLatestIndexTemplateV1 = (definitionId: string) =>
+ `${ENTITY_BASE_PREFIX}_${ENTITY_SCHEMA_VERSION_V1}_${ENTITY_LATEST}_${definitionId}_index_template` as const;
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/lib/auth/privileges.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/auth/privileges.ts
index 00f09209fb3b6..3bc88127a5964 100644
--- a/x-pack/plugins/observability_solution/entity_manager/server/lib/auth/privileges.ts
+++ b/x-pack/plugins/observability_solution/entity_manager/server/lib/auth/privileges.ts
@@ -21,7 +21,13 @@ export const requiredRunTimePrivileges = {
privileges: ['read', 'view_index_metadata'],
},
],
- cluster: ['manage_transform', 'monitor_transform', 'manage_ingest_pipelines', 'monitor'],
+ cluster: [
+ 'manage_transform',
+ 'monitor_transform',
+ 'manage_ingest_pipelines',
+ 'monitor',
+ 'manage_index_templates',
+ ],
application: [
{
application: 'kibana-.kibana',
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/__snapshots__/generate_history_processors.test.ts.snap b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/__snapshots__/generate_history_processors.test.ts.snap
index 925c62d97710f..9e62633a0a7d6 100644
--- a/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/__snapshots__/generate_history_processors.test.ts.snap
+++ b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/__snapshots__/generate_history_processors.test.ts.snap
@@ -148,5 +148,29 @@ if (ctx.entity?.metadata?.sourceIndex != null) {
"index_name_prefix": ".entities.v1.history.admin-console-services.",
},
},
+ Object {
+ "pipeline": Object {
+ "ignore_missing_pipeline": true,
+ "name": "admin-console-services@platform",
+ },
+ },
+ Object {
+ "pipeline": Object {
+ "ignore_missing_pipeline": true,
+ "name": "admin-console-services-history@platform",
+ },
+ },
+ Object {
+ "pipeline": Object {
+ "ignore_missing_pipeline": true,
+ "name": "admin-console-services@custom",
+ },
+ },
+ Object {
+ "pipeline": Object {
+ "ignore_missing_pipeline": true,
+ "name": "admin-console-services-history@custom",
+ },
+ },
]
`;
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/__snapshots__/generate_latest_processors.test.ts.snap b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/__snapshots__/generate_latest_processors.test.ts.snap
index 69e63abd0cb94..e96d7366e7e04 100644
--- a/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/__snapshots__/generate_latest_processors.test.ts.snap
+++ b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/__snapshots__/generate_latest_processors.test.ts.snap
@@ -108,5 +108,29 @@ ctx.event.category = ctx.entity.identity.event.category.keySet().toArray()[0];",
"value": ".entities.v1.latest.admin-console-services",
},
},
+ Object {
+ "pipeline": Object {
+ "ignore_missing_pipeline": true,
+ "name": "admin-console-services@platform",
+ },
+ },
+ Object {
+ "pipeline": Object {
+ "ignore_missing_pipeline": true,
+ "name": "admin-console-services-latest@platform",
+ },
+ },
+ Object {
+ "pipeline": Object {
+ "ignore_missing_pipeline": true,
+ "name": "admin-console-services@custom",
+ },
+ },
+ Object {
+ "pipeline": Object {
+ "ignore_missing_pipeline": true,
+ "name": "admin-console-services-latest@custom",
+ },
+ },
]
`;
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_history_processors.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_history_processors.ts
index 45ee008f9c6b5..43f18b2b81bf0 100644
--- a/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_history_processors.ts
+++ b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_history_processors.ts
@@ -163,5 +163,30 @@ export function generateHistoryProcessors(definition: EntityDefinition) {
date_formats: ['UNIX_MS', 'ISO8601', "yyyy-MM-dd'T'HH:mm:ss.SSSXX"],
},
},
+ {
+ pipeline: {
+ ignore_missing_pipeline: true,
+ name: `${definition.id}@platform`,
+ },
+ },
+ {
+ pipeline: {
+ ignore_missing_pipeline: true,
+ name: `${definition.id}-history@platform`,
+ },
+ },
+
+ {
+ pipeline: {
+ ignore_missing_pipeline: true,
+ name: `${definition.id}@custom`,
+ },
+ },
+ {
+ pipeline: {
+ ignore_missing_pipeline: true,
+ name: `${definition.id}-history@custom`,
+ },
+ },
];
}
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_latest_processors.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_latest_processors.ts
index 22b2ac19775a1..b9a18e8b7a2b6 100644
--- a/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_latest_processors.ts
+++ b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_latest_processors.ts
@@ -122,5 +122,30 @@ export function generateLatestProcessors(definition: EntityDefinition) {
value: `${generateLatestIndexName(definition)}`,
},
},
+ {
+ pipeline: {
+ ignore_missing_pipeline: true,
+ name: `${definition.id}@platform`,
+ },
+ },
+ {
+ pipeline: {
+ ignore_missing_pipeline: true,
+ name: `${definition.id}-latest@platform`,
+ },
+ },
+ {
+ pipeline: {
+ ignore_missing_pipeline: true,
+ name: `${definition.id}@custom`,
+ },
+ },
+
+ {
+ pipeline: {
+ ignore_missing_pipeline: true,
+ name: `${definition.id}-latest@custom`,
+ },
+ },
];
}
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/install_entity_definition.test.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/install_entity_definition.test.ts
index 8560f0a4f1f4f..95eb63253f40c 100644
--- a/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/install_entity_definition.test.ts
+++ b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/install_entity_definition.test.ts
@@ -34,6 +34,18 @@ const assertHasCreatedDefinition = (
overwrite: true,
});
+ expect(esClient.indices.putIndexTemplate).toBeCalledTimes(2);
+ expect(esClient.indices.putIndexTemplate).toBeCalledWith(
+ expect.objectContaining({
+ name: `entities_v1_history_${definition.id}_index_template`,
+ })
+ );
+ expect(esClient.indices.putIndexTemplate).toBeCalledWith(
+ expect.objectContaining({
+ name: `entities_v1_latest_${definition.id}_index_template`,
+ })
+ );
+
expect(esClient.ingest.putPipeline).toBeCalledTimes(2);
expect(esClient.ingest.putPipeline).toBeCalledWith({
id: generateHistoryIngestPipelineId(builtInServicesFromLogsEntityDefinition),
@@ -111,6 +123,20 @@ const assertHasUninstalledDefinition = (
expect(esClient.transform.deleteTransform).toBeCalledTimes(2);
expect(esClient.ingest.deletePipeline).toBeCalledTimes(2);
expect(soClient.delete).toBeCalledTimes(1);
+
+ expect(esClient.indices.deleteIndexTemplate).toBeCalledTimes(2);
+ expect(esClient.indices.deleteIndexTemplate).toBeCalledWith(
+ {
+ name: `entities_v1_history_${definition.id}_index_template`,
+ },
+ { ignore: [404] }
+ );
+ expect(esClient.indices.deleteIndexTemplate).toBeCalledWith(
+ {
+ name: `entities_v1_latest_${definition.id}_index_template`,
+ },
+ { ignore: [404] }
+ );
};
describe('install_entity_definition', () => {
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/install_entity_definition.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/install_entity_definition.ts
index 980c743575fe2..b47f17b6b00fa 100644
--- a/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/install_entity_definition.ts
+++ b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/install_entity_definition.ts
@@ -9,6 +9,10 @@ import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
import { EntityDefinition } from '@kbn/entities-schema';
import { Logger } from '@kbn/logging';
+import {
+ getEntityHistoryIndexTemplateV1,
+ getEntityLatestIndexTemplateV1,
+} from '../../../common/helpers';
import {
createAndInstallHistoryIngestPipeline,
createAndInstallLatestIngestPipeline,
@@ -28,6 +32,9 @@ import {
stopAndDeleteLatestTransform,
} from './stop_and_delete_transform';
import { uninstallEntityDefinition } from './uninstall_entity_definition';
+import { deleteTemplate, upsertTemplate } from '../manage_index_templates';
+import { getEntitiesLatestIndexTemplateConfig } from '../../templates/entities_latest_template';
+import { getEntitiesHistoryIndexTemplateConfig } from '../../templates/entities_history_template';
export interface InstallDefinitionParams {
esClient: ElasticsearchClient;
@@ -52,6 +59,10 @@ export async function installEntityDefinition({
latest: false,
},
definition: false,
+ indexTemplates: {
+ history: false,
+ latest: false,
+ },
};
try {
@@ -62,6 +73,20 @@ export async function installEntityDefinition({
const entityDefinition = await saveEntityDefinition(soClient, definition);
installState.definition = true;
+ // install scoped index template
+ await upsertTemplate({
+ esClient,
+ logger,
+ template: getEntitiesHistoryIndexTemplateConfig(definition.id),
+ });
+ installState.indexTemplates.history = true;
+ await upsertTemplate({
+ esClient,
+ logger,
+ template: getEntitiesLatestIndexTemplateConfig(definition.id),
+ });
+ installState.indexTemplates.latest = true;
+
// install ingest pipelines
logger.debug(`Installing ingest pipelines for definition ${definition.id}`);
await createAndInstallHistoryIngestPipeline(esClient, entityDefinition, logger);
@@ -99,6 +124,21 @@ export async function installEntityDefinition({
await stopAndDeleteLatestTransform(esClient, definition, logger);
}
+ if (installState.indexTemplates.history) {
+ await deleteTemplate({
+ esClient,
+ logger,
+ name: getEntityHistoryIndexTemplateV1(definition.id),
+ });
+ }
+ if (installState.indexTemplates.latest) {
+ await deleteTemplate({
+ esClient,
+ logger,
+ name: getEntityLatestIndexTemplateV1(definition.id),
+ });
+ }
+
throw e;
}
}
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/uninstall_entity_definition.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/uninstall_entity_definition.ts
index 8642ebafa904b..9b8685031642a 100644
--- a/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/uninstall_entity_definition.ts
+++ b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/uninstall_entity_definition.ts
@@ -9,6 +9,10 @@ import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
import { EntityDefinition } from '@kbn/entities-schema';
import { Logger } from '@kbn/logging';
+import {
+ getEntityHistoryIndexTemplateV1,
+ getEntityLatestIndexTemplateV1,
+} from '../../../common/helpers';
import { deleteEntityDefinition } from './delete_entity_definition';
import { deleteIndices } from './delete_index';
import { deleteHistoryIngestPipeline, deleteLatestIngestPipeline } from './delete_ingest_pipeline';
@@ -17,6 +21,7 @@ import {
stopAndDeleteHistoryTransform,
stopAndDeleteLatestTransform,
} from './stop_and_delete_transform';
+import { deleteTemplate } from '../manage_index_templates';
export async function uninstallEntityDefinition({
definition,
@@ -36,6 +41,9 @@ export async function uninstallEntityDefinition({
await deleteHistoryIngestPipeline(esClient, definition, logger);
await deleteLatestIngestPipeline(esClient, definition, logger);
await deleteEntityDefinition(soClient, definition, logger);
+ await deleteTemplate({ esClient, logger, name: getEntityHistoryIndexTemplateV1(definition.id) });
+ await deleteTemplate({ esClient, logger, name: getEntityLatestIndexTemplateV1(definition.id) });
+
if (deleteData) {
await deleteIndices(esClient, definition, logger);
}
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/lib/manage_index_templates.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/manage_index_templates.ts
index 0f73ba7715bfd..f300df4a92c1d 100644
--- a/x-pack/plugins/observability_solution/entity_manager/server/lib/manage_index_templates.ts
+++ b/x-pack/plugins/observability_solution/entity_manager/server/lib/manage_index_templates.ts
@@ -10,6 +10,7 @@ import {
IndicesPutIndexTemplateRequest,
} from '@elastic/elasticsearch/lib/api/types';
import { ElasticsearchClient, Logger } from '@kbn/core/server';
+import { retryTransientEsErrors } from './entities/helpers/retry';
interface TemplateManagementOptions {
esClient: ElasticsearchClient;
@@ -23,12 +24,18 @@ interface ComponentManagementOptions {
logger: Logger;
}
+interface DeleteTemplateOptions {
+ esClient: ElasticsearchClient;
+ name: string;
+ logger: Logger;
+}
+
export async function upsertTemplate({ esClient, template, logger }: TemplateManagementOptions) {
try {
- await esClient.indices.putIndexTemplate(template);
+ await retryTransientEsErrors(() => esClient.indices.putIndexTemplate(template), { logger });
} catch (error: any) {
logger.error(`Error updating entity manager index template: ${error.message}`);
- return;
+ throw error;
}
logger.info(
@@ -37,12 +44,26 @@ export async function upsertTemplate({ esClient, template, logger }: TemplateMan
logger.debug(() => `Entity manager index template: ${JSON.stringify(template)}`);
}
+export async function deleteTemplate({ esClient, name, logger }: DeleteTemplateOptions) {
+ try {
+ await retryTransientEsErrors(
+ () => esClient.indices.deleteIndexTemplate({ name }, { ignore: [404] }),
+ { logger }
+ );
+ } catch (error: any) {
+ logger.error(`Error deleting entity manager index template: ${error.message}`);
+ throw error;
+ }
+}
+
export async function upsertComponent({ esClient, component, logger }: ComponentManagementOptions) {
try {
- await esClient.cluster.putComponentTemplate(component);
+ await retryTransientEsErrors(() => esClient.cluster.putComponentTemplate(component), {
+ logger,
+ });
} catch (error: any) {
logger.error(`Error updating entity manager component template: ${error.message}`);
- return;
+ throw error;
}
logger.info(
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/plugin.ts b/x-pack/plugins/observability_solution/entity_manager/server/plugin.ts
index 3a51988841766..80154149e2402 100644
--- a/x-pack/plugins/observability_solution/entity_manager/server/plugin.ts
+++ b/x-pack/plugins/observability_solution/entity_manager/server/plugin.ts
@@ -14,7 +14,7 @@ import {
PluginConfigDescriptor,
Logger,
} from '@kbn/core/server';
-import { upsertComponent, upsertTemplate } from './lib/manage_index_templates';
+import { upsertComponent } from './lib/manage_index_templates';
import { setupRoutes } from './routes';
import {
EntityManagerPluginSetupDependencies,
@@ -27,8 +27,6 @@ import { entityDefinition, EntityDiscoveryApiKeyType } from './saved_objects';
import { entitiesEntityComponentTemplateConfig } from './templates/components/entity';
import { entitiesLatestBaseComponentTemplateConfig } from './templates/components/base_latest';
import { entitiesHistoryBaseComponentTemplateConfig } from './templates/components/base_history';
-import { entitiesHistoryIndexTemplateConfig } from './templates/entities_history_template';
-import { entitiesLatestIndexTemplateConfig } from './templates/entities_latest_template';
export type EntityManagerServerPluginSetup = ReturnType;
export type EntityManagerServerPluginStart = ReturnType;
@@ -113,22 +111,7 @@ export class EntityManagerServerPlugin
logger: this.logger,
component: entitiesEntityComponentTemplateConfig,
}),
- ])
- .then(() =>
- upsertTemplate({
- esClient,
- logger: this.logger,
- template: entitiesHistoryIndexTemplateConfig,
- })
- )
- .then(() =>
- upsertTemplate({
- esClient,
- logger: this.logger,
- template: entitiesLatestIndexTemplateConfig,
- })
- )
- .catch(() => {});
+ ]).catch(() => {});
return {};
}
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/templates/components/helpers.test.ts b/x-pack/plugins/observability_solution/entity_manager/server/templates/components/helpers.test.ts
new file mode 100644
index 0000000000000..3321ee39edeb4
--- /dev/null
+++ b/x-pack/plugins/observability_solution/entity_manager/server/templates/components/helpers.test.ts
@@ -0,0 +1,32 @@
+/*
+ * 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 { getCustomHistoryTemplateComponents, getCustomLatestTemplateComponents } from './helpers';
+
+describe('helpers', () => {
+ it('getCustomLatestTemplateComponents should return template component in the right sort order', () => {
+ const definitionId = 'test';
+ const result = getCustomLatestTemplateComponents(definitionId);
+ expect(result).toEqual([
+ 'test@platform',
+ 'test-latest@platform',
+ 'test@custom',
+ 'test-latest@custom',
+ ]);
+ });
+
+ it('getCustomHistoryTemplateComponents should return template component in the right sort order', () => {
+ const definitionId = 'test';
+ const result = getCustomHistoryTemplateComponents(definitionId);
+ expect(result).toEqual([
+ 'test@platform',
+ 'test-history@platform',
+ 'test@custom',
+ 'test-history@custom',
+ ]);
+ });
+});
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/templates/components/helpers.ts b/x-pack/plugins/observability_solution/entity_manager/server/templates/components/helpers.ts
new file mode 100644
index 0000000000000..e976a216da97b
--- /dev/null
+++ b/x-pack/plugins/observability_solution/entity_manager/server/templates/components/helpers.ts
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+export const getCustomLatestTemplateComponents = (definitionId: string) => [
+ `${definitionId}@platform`, // @platform goes before so it can be overwritten by custom
+ `${definitionId}-latest@platform`,
+ `${definitionId}@custom`,
+ `${definitionId}-latest@custom`,
+];
+
+export const getCustomHistoryTemplateComponents = (definitionId: string) => [
+ `${definitionId}@platform`, // @platform goes before so it can be overwritten by custom
+ `${definitionId}-history@platform`,
+ `${definitionId}@custom`,
+ `${definitionId}-history@custom`,
+];
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/templates/entities_history_template.ts b/x-pack/plugins/observability_solution/entity_manager/server/templates/entities_history_template.ts
index d5ceeecd44828..63d589bfaa754 100644
--- a/x-pack/plugins/observability_solution/entity_manager/server/templates/entities_history_template.ts
+++ b/x-pack/plugins/observability_solution/entity_manager/server/templates/entities_history_template.ts
@@ -6,29 +6,35 @@
*/
import { IndicesPutIndexTemplateRequest } from '@elastic/elasticsearch/lib/api/types';
+import { getEntityHistoryIndexTemplateV1 } from '../../common/helpers';
import {
ENTITY_ENTITY_COMPONENT_TEMPLATE_V1,
ENTITY_EVENT_COMPONENT_TEMPLATE_V1,
ENTITY_HISTORY_BASE_COMPONENT_TEMPLATE_V1,
ENTITY_HISTORY_INDEX_PREFIX_V1,
- ENTITY_HISTORY_INDEX_TEMPLATE_V1,
} from '../../common/constants_entities';
+import { getCustomHistoryTemplateComponents } from './components/helpers';
-export const entitiesHistoryIndexTemplateConfig: IndicesPutIndexTemplateRequest = {
- name: ENTITY_HISTORY_INDEX_TEMPLATE_V1,
+export const getEntitiesHistoryIndexTemplateConfig = (
+ definitionId: string
+): IndicesPutIndexTemplateRequest => ({
+ name: getEntityHistoryIndexTemplateV1(definitionId),
_meta: {
description:
"Index template for indices managed by the Elastic Entity Model's entity discovery framework for the history dataset",
ecs_version: '8.0.0',
managed: true,
+ managed_by: 'elastic_entity_model',
},
+ ignore_missing_component_templates: getCustomHistoryTemplateComponents(definitionId),
composed_of: [
ENTITY_HISTORY_BASE_COMPONENT_TEMPLATE_V1,
ENTITY_ENTITY_COMPONENT_TEMPLATE_V1,
ENTITY_EVENT_COMPONENT_TEMPLATE_V1,
+ ...getCustomHistoryTemplateComponents(definitionId),
],
index_patterns: [`${ENTITY_HISTORY_INDEX_PREFIX_V1}.*`],
- priority: 1,
+ priority: 200,
template: {
mappings: {
_meta: {
@@ -72,4 +78,4 @@ export const entitiesHistoryIndexTemplateConfig: IndicesPutIndexTemplateRequest
},
},
},
-};
+});
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/templates/entities_latest_template.ts b/x-pack/plugins/observability_solution/entity_manager/server/templates/entities_latest_template.ts
index f601c3aa9d57d..3ad09e7257a1a 100644
--- a/x-pack/plugins/observability_solution/entity_manager/server/templates/entities_latest_template.ts
+++ b/x-pack/plugins/observability_solution/entity_manager/server/templates/entities_latest_template.ts
@@ -6,26 +6,32 @@
*/
import { IndicesPutIndexTemplateRequest } from '@elastic/elasticsearch/lib/api/types';
+import { getEntityLatestIndexTemplateV1 } from '../../common/helpers';
import {
ENTITY_ENTITY_COMPONENT_TEMPLATE_V1,
ENTITY_EVENT_COMPONENT_TEMPLATE_V1,
ENTITY_LATEST_BASE_COMPONENT_TEMPLATE_V1,
ENTITY_LATEST_INDEX_PREFIX_V1,
- ENTITY_LATEST_INDEX_TEMPLATE_V1,
} from '../../common/constants_entities';
+import { getCustomLatestTemplateComponents } from './components/helpers';
-export const entitiesLatestIndexTemplateConfig: IndicesPutIndexTemplateRequest = {
- name: ENTITY_LATEST_INDEX_TEMPLATE_V1,
+export const getEntitiesLatestIndexTemplateConfig = (
+ definitionId: string
+): IndicesPutIndexTemplateRequest => ({
+ name: getEntityLatestIndexTemplateV1(definitionId),
_meta: {
description:
"Index template for indices managed by the Elastic Entity Model's entity discovery framework for the latest dataset",
ecs_version: '8.0.0',
managed: true,
+ managed_by: 'elastic_entity_model',
},
+ ignore_missing_component_templates: getCustomLatestTemplateComponents(definitionId),
composed_of: [
ENTITY_LATEST_BASE_COMPONENT_TEMPLATE_V1,
ENTITY_ENTITY_COMPONENT_TEMPLATE_V1,
ENTITY_EVENT_COMPONENT_TEMPLATE_V1,
+ ...getCustomLatestTemplateComponents(definitionId),
],
index_patterns: [`${ENTITY_LATEST_INDEX_PREFIX_V1}.*`],
priority: 1,
@@ -72,4 +78,4 @@ export const entitiesLatestIndexTemplateConfig: IndicesPutIndexTemplateRequest =
},
},
},
-};
+});
From 1ac9c8e2dcfc95fdef19f67de7878c55fa1e8de7 Mon Sep 17 00:00:00 2001
From: Paul Tavares <56442535+paul-tavares@users.noreply.github.com>
Date: Mon, 22 Jul 2024 11:34:28 -0400
Subject: [PATCH 19/30] [Security Solution][Endpoint] Fix authz on File
Info/Download APIs for `execute` response action (#188698)
## Summary
- Fixes the API route for response actions file information and file
download to ensure that user only needs Authz to the Execute action.
- Centralizes the logic to determine the platform for a given host which
was (under certain data conditions) causing the platform icon to not be
shown in the response console.
---
.../use_alert_response_actions_support.ts | 13 +---
.../endpoint/utils/get_host_platform.test.ts | 52 ++++++++++++++
.../lib/endpoint/utils/get_host_platform.ts | 39 +++++++++++
.../endpoint/header_endpoint_info.tsx | 3 +-
.../view/hooks/use_endpoint_action_items.tsx | 4 +-
.../actions/file_download_handler.test.ts | 7 +-
.../routes/actions/file_download_handler.ts | 2 +-
.../routes/actions/file_info_handler.test.ts | 7 +-
.../routes/actions/file_info_handler.ts | 2 +-
.../endpoint/routes/with_endpoint_authz.ts | 37 +++++++++-
...rity_solution_edr_workflows_roles_users.ts | 23 +++++-
.../trial_license_complete_tier/execute.ts | 70 ++++++++++++++++++-
.../tsconfig.json | 1 +
13 files changed, 238 insertions(+), 22 deletions(-)
create mode 100644 x-pack/plugins/security_solution/public/common/lib/endpoint/utils/get_host_platform.test.ts
create mode 100644 x-pack/plugins/security_solution/public/common/lib/endpoint/utils/get_host_platform.ts
diff --git a/x-pack/plugins/security_solution/public/common/hooks/endpoint/use_alert_response_actions_support.ts b/x-pack/plugins/security_solution/public/common/hooks/endpoint/use_alert_response_actions_support.ts
index e56c10d589f5f..a483a5c465b3f 100644
--- a/x-pack/plugins/security_solution/public/common/hooks/endpoint/use_alert_response_actions_support.ts
+++ b/x-pack/plugins/security_solution/public/common/hooks/endpoint/use_alert_response_actions_support.ts
@@ -9,6 +9,7 @@ import type { TimelineEventsDetailsItem } from '@kbn/timelines-plugin/common';
import { useMemo } from 'react';
import { find, some } from 'lodash/fp';
import { i18n } from '@kbn/i18n';
+import { getHostPlatform } from '../../lib/endpoint/utils/get_host_platform';
import { getAlertDetailsFieldValue } from '../../lib/endpoint/utils/get_event_details_field_values';
import { isAgentTypeAndActionSupported } from '../../lib/endpoint';
import type {
@@ -176,16 +177,8 @@ export const useAlertResponseActionsSupport = (
}, [eventData]);
const platform = useMemo(() => {
- // TODO:TC I couldn't find host.os.family in the example data, thus using host.os.type and host.os.platform which are present one at a time in different type of events
- if (agentType === 'crowdstrike') {
- return (
- getAlertDetailsFieldValue({ category: 'host', field: 'host.os.type' }, eventData) ||
- getAlertDetailsFieldValue({ category: 'host', field: 'host.os.platform' }, eventData)
- );
- }
-
- return getAlertDetailsFieldValue({ category: 'host', field: 'host.os.type' }, eventData);
- }, [agentType, eventData]);
+ return getHostPlatform(eventData ?? []);
+ }, [eventData]);
const unsupportedReason = useMemo(() => {
if (!doesHostSupportResponseActions) {
diff --git a/x-pack/plugins/security_solution/public/common/lib/endpoint/utils/get_host_platform.test.ts b/x-pack/plugins/security_solution/public/common/lib/endpoint/utils/get_host_platform.test.ts
new file mode 100644
index 0000000000000..61cc2053eb8fc
--- /dev/null
+++ b/x-pack/plugins/security_solution/public/common/lib/endpoint/utils/get_host_platform.test.ts
@@ -0,0 +1,52 @@
+/*
+ * 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 { set } from 'lodash';
+import { getHostPlatform } from './get_host_platform';
+import type { TimelineEventsDetailsItem } from '@kbn/timelines-plugin/common';
+
+describe('getHostPlatform() util', () => {
+ const buildEcsData = (data: Record) => {
+ const ecsData = {};
+
+ for (const [key, value] of Object.entries(data)) {
+ set(ecsData, `host.os.${key}`, value);
+ }
+
+ return ecsData;
+ };
+
+ const buildEventDetails = (data: Record) => {
+ const eventDetails: TimelineEventsDetailsItem[] = [];
+
+ for (const [key, value] of Object.entries(data)) {
+ eventDetails.push({
+ category: 'host',
+ field: `host.os.${key}`,
+ values: [value],
+ originalValue: value,
+ isObjectArray: false,
+ });
+ }
+
+ return eventDetails;
+ };
+
+ it.each`
+ title | setupData | expectedResult
+ ${'ECS data with host.os.platform info'} | ${buildEcsData({ platform: 'windows' })} | ${'windows'}
+ ${'ECS data with host.os.type info'} | ${buildEcsData({ type: 'Linux' })} | ${'linux'}
+ ${'ECS data with host.os.name info'} | ${buildEcsData({ name: 'MACOS' })} | ${'macos'}
+ ${'ECS data with all os info'} | ${buildEcsData({ platform: 'macos', type: 'windows', name: 'linux' })} | ${'macos'}
+ ${'Event Details data with host.os.platform info'} | ${buildEventDetails({ platform: 'windows' })} | ${'windows'}
+ ${'Event Details data with host.os.type info'} | ${buildEventDetails({ type: 'Linux' })} | ${'linux'}
+ ${'Event Details data with host.os.name info'} | ${buildEventDetails({ name: 'MACOS' })} | ${'macos'}
+ ${'Event Details data with all os info'} | ${buildEventDetails({ platform: 'macos', type: 'windows', name: 'linux' })} | ${'macos'}
+ `(`should handle $title`, ({ setupData, expectedResult }) => {
+ expect(getHostPlatform(setupData)).toEqual(expectedResult);
+ });
+});
diff --git a/x-pack/plugins/security_solution/public/common/lib/endpoint/utils/get_host_platform.ts b/x-pack/plugins/security_solution/public/common/lib/endpoint/utils/get_host_platform.ts
new file mode 100644
index 0000000000000..52df785cabff0
--- /dev/null
+++ b/x-pack/plugins/security_solution/public/common/lib/endpoint/utils/get_host_platform.ts
@@ -0,0 +1,39 @@
+/*
+ * 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 type { Ecs } from '@elastic/ecs';
+import type { TimelineEventsDetailsItem } from '@kbn/timelines-plugin/common';
+import type { MaybeImmutable } from '../../../../../common/endpoint/types';
+import { getAlertDetailsFieldValue } from './get_event_details_field_values';
+import type { Platform } from '../../../../management/components/endpoint_responder/components/header_info/platforms';
+
+type EcsHostData = MaybeImmutable>;
+
+const isTimelineEventDetailsItems = (
+ data: EcsHostData | TimelineEventsDetailsItem[]
+): data is TimelineEventsDetailsItem[] => {
+ return Array.isArray(data);
+};
+
+/**
+ * Retrieve a host's platform type from either ECS data or Event Details list of items
+ * @param data
+ */
+export const getHostPlatform = (data: EcsHostData | TimelineEventsDetailsItem[]): Platform => {
+ let platform = '';
+
+ if (isTimelineEventDetailsItems(data)) {
+ platform = (getAlertDetailsFieldValue({ category: 'host', field: 'host.os.platform' }, data) ||
+ getAlertDetailsFieldValue({ category: 'host', field: 'host.os.type' }, data) ||
+ getAlertDetailsFieldValue({ category: 'host', field: 'host.os.name' }, data)) as Platform;
+ } else {
+ platform =
+ ((data.host?.os?.platform || data.host?.os?.type || data.host?.os?.name) as Platform) || '';
+ }
+
+ return platform.toLowerCase() as Platform;
+};
diff --git a/x-pack/plugins/security_solution/public/management/components/endpoint_responder/components/header_info/endpoint/header_endpoint_info.tsx b/x-pack/plugins/security_solution/public/management/components/endpoint_responder/components/header_info/endpoint/header_endpoint_info.tsx
index f302a31c5f48e..0cd96b4f3acf0 100644
--- a/x-pack/plugins/security_solution/public/management/components/endpoint_responder/components/header_info/endpoint/header_endpoint_info.tsx
+++ b/x-pack/plugins/security_solution/public/management/components/endpoint_responder/components/header_info/endpoint/header_endpoint_info.tsx
@@ -7,6 +7,7 @@
import React, { memo } from 'react';
import { EuiSkeletonText } from '@elastic/eui';
+import { getHostPlatform } from '../../../../../../common/lib/endpoint/utils/get_host_platform';
import { AgentStatus } from '../../../../../../common/components/endpoint/agents/agent_status';
import { HeaderAgentInfo } from '../header_agent_info';
import { useGetEndpointDetails } from '../../../../../hooks';
@@ -31,7 +32,7 @@ export const HeaderEndpointInfo = memo(({ endpointId })
return (
{
it('should error if user has no authz to api', async () => {
(
(await httpHandlerContextMock.securitySolution).getEndpointAuthz as jest.Mock
- ).mockResolvedValue(getEndpointAuthzInitialStateMock({ canWriteFileOperations: false }));
+ ).mockResolvedValue(
+ getEndpointAuthzInitialStateMock({
+ canWriteFileOperations: false,
+ canWriteExecuteOperations: false,
+ })
+ );
await apiTestSetup
.getRegisteredVersionedRoute('get', ACTION_AGENT_FILE_DOWNLOAD_ROUTE, '2023-10-31')
diff --git a/x-pack/plugins/security_solution/server/endpoint/routes/actions/file_download_handler.ts b/x-pack/plugins/security_solution/server/endpoint/routes/actions/file_download_handler.ts
index 0037d5dded81f..7095b7d87a50c 100644
--- a/x-pack/plugins/security_solution/server/endpoint/routes/actions/file_download_handler.ts
+++ b/x-pack/plugins/security_solution/server/endpoint/routes/actions/file_download_handler.ts
@@ -47,7 +47,7 @@ export const registerActionFileDownloadRoutes = (
},
},
withEndpointAuthz(
- { all: ['canWriteFileOperations'] },
+ { any: ['canWriteFileOperations', 'canWriteExecuteOperations'] },
logger,
getActionFileDownloadRouteHandler(endpointContext)
)
diff --git a/x-pack/plugins/security_solution/server/endpoint/routes/actions/file_info_handler.test.ts b/x-pack/plugins/security_solution/server/endpoint/routes/actions/file_info_handler.test.ts
index e6554ee14ad6d..e9914dc4232d9 100644
--- a/x-pack/plugins/security_solution/server/endpoint/routes/actions/file_info_handler.test.ts
+++ b/x-pack/plugins/security_solution/server/endpoint/routes/actions/file_info_handler.test.ts
@@ -69,7 +69,12 @@ describe('Response Action file info API', () => {
it('should error if user has no authz to api', async () => {
(
(await httpHandlerContextMock.securitySolution).getEndpointAuthz as jest.Mock
- ).mockResolvedValue(getEndpointAuthzInitialStateMock({ canWriteFileOperations: false }));
+ ).mockResolvedValue(
+ getEndpointAuthzInitialStateMock({
+ canWriteFileOperations: false,
+ canWriteExecuteOperations: false,
+ })
+ );
await apiTestSetup
.getRegisteredVersionedRoute('get', ACTION_AGENT_FILE_INFO_ROUTE, '2023-10-31')
diff --git a/x-pack/plugins/security_solution/server/endpoint/routes/actions/file_info_handler.ts b/x-pack/plugins/security_solution/server/endpoint/routes/actions/file_info_handler.ts
index abc576fe3c9d9..a84f3b3a8bf6f 100644
--- a/x-pack/plugins/security_solution/server/endpoint/routes/actions/file_info_handler.ts
+++ b/x-pack/plugins/security_solution/server/endpoint/routes/actions/file_info_handler.ts
@@ -83,7 +83,7 @@ export const registerActionFileInfoRoute = (
},
},
withEndpointAuthz(
- { all: ['canWriteFileOperations'] },
+ { any: ['canWriteFileOperations', 'canWriteExecuteOperations'] },
endpointContext.logFactory.get('actionFileInfo'),
getActionFileInfoRouteHandler(endpointContext)
)
diff --git a/x-pack/plugins/security_solution/server/endpoint/routes/with_endpoint_authz.ts b/x-pack/plugins/security_solution/server/endpoint/routes/with_endpoint_authz.ts
index 8822db6c68367..a241148c7b714 100644
--- a/x-pack/plugins/security_solution/server/endpoint/routes/with_endpoint_authz.ts
+++ b/x-pack/plugins/security_solution/server/endpoint/routes/with_endpoint_authz.ts
@@ -6,6 +6,7 @@
*/
import type { RequestHandler, Logger } from '@kbn/core/server';
+import { stringify } from '../utils/stringify';
import type { EndpointAuthzKeyList } from '../../../common/endpoint/types/authz';
import type { SecuritySolutionRequestHandlerContext } from '../../types';
import { EndpointAuthorizationError } from '../errors';
@@ -39,6 +40,21 @@ export const withEndpointAuthz = (
const validateAll = needAll.length > 0;
const validateAny = needAny.length > 0;
const enforceAuthz = validateAll || validateAny;
+ const logAuthzFailure = (
+ user: string,
+ authzValidationResults: Record,
+ needed: string[]
+ ) => {
+ logger.debug(
+ `Unauthorized: user ${user} ${
+ needed === needAll ? 'needs ALL' : 'needs at least one'
+ } of the following privileges:\n${stringify(needed)}\nbut is missing: ${stringify(
+ Object.entries(authzValidationResults)
+ .filter(([_, value]) => !value)
+ .map(([key]) => key)
+ )}`
+ );
+ };
if (!enforceAuthz) {
logger.warn(`Authorization disabled for API route: ${new Error('').stack ?? '?'}`);
@@ -51,18 +67,37 @@ export const withEndpointAuthz = (
SecuritySolutionRequestHandlerContext
> = async (context, request, response) => {
if (enforceAuthz) {
+ const coreServices = await context.core;
const endpointAuthz = await (await context.securitySolution).getEndpointAuthz();
- const permissionChecker = (permission: EndpointAuthzKeyList[0]) => endpointAuthz[permission];
+ let authzValidationResults: Record = {};
+ const permissionChecker = (permission: EndpointAuthzKeyList[0]) => {
+ authzValidationResults[permission] = endpointAuthz[permission];
+ return endpointAuthz[permission];
+ };
// has `all`?
if (validateAll && !needAll.every(permissionChecker)) {
+ logAuthzFailure(
+ coreServices.security.authc.getCurrentUser()?.username ?? '',
+ authzValidationResults,
+ needAll
+ );
+
return response.forbidden({
body: new EndpointAuthorizationError({ need_all: [...needAll] }),
});
}
+ authzValidationResults = {};
+
// has `any`?
if (validateAny && !needAny.some(permissionChecker)) {
+ logAuthzFailure(
+ coreServices.security.authc.getCurrentUser()?.username ?? '',
+ authzValidationResults,
+ needAny
+ );
+
return response.forbidden({
body: new EndpointAuthorizationError({ need_any: [...needAny] }),
});
diff --git a/x-pack/test/security_solution_api_integration/config/services/security_solution_edr_workflows_roles_users.ts b/x-pack/test/security_solution_api_integration/config/services/security_solution_edr_workflows_roles_users.ts
index f364943164322..92e0cc9ba1f13 100644
--- a/x-pack/test/security_solution_api_integration/config/services/security_solution_edr_workflows_roles_users.ts
+++ b/x-pack/test/security_solution_api_integration/config/services/security_solution_edr_workflows_roles_users.ts
@@ -5,6 +5,7 @@
* 2.0.
*/
+import { Role } from '@kbn/security-plugin/common';
import {
EndpointSecurityRoleNames,
ENDPOINT_SECURITY_ROLE_NAMES,
@@ -61,9 +62,25 @@ export function RolesUsersProvider({ getService }: FtrProviderContext) {
await security.role.create(predefinedRole, roleConfig);
}
if (customRole) {
- await security.role.create(customRole.roleName, {
- permissions: { feature: { siem: [...customRole.extraPrivileges] } },
- });
+ const role: Omit = {
+ description: '',
+ elasticsearch: {
+ cluster: [],
+ indices: [],
+ run_as: [],
+ },
+ kibana: [
+ {
+ spaces: ['*'],
+ base: [],
+ feature: {
+ siem: customRole.extraPrivileges,
+ },
+ },
+ ],
+ };
+
+ await security.role.create(customRole.roleName, role);
}
},
diff --git a/x-pack/test/security_solution_api_integration/test_suites/edr_workflows/response_actions/trial_license_complete_tier/execute.ts b/x-pack/test/security_solution_api_integration/test_suites/edr_workflows/response_actions/trial_license_complete_tier/execute.ts
index 4178fd80b653a..6e50f67e3510d 100644
--- a/x-pack/test/security_solution_api_integration/test_suites/edr_workflows/response_actions/trial_license_complete_tier/execute.ts
+++ b/x-pack/test/security_solution_api_integration/test_suites/edr_workflows/response_actions/trial_license_complete_tier/execute.ts
@@ -6,14 +6,21 @@
*/
import { wrapErrorAndRejectPromise } from '@kbn/security-solution-plugin/common/endpoint/data_loaders/utils';
import expect from '@kbn/expect';
-import { EXECUTE_ROUTE } from '@kbn/security-solution-plugin/common/endpoint/constants';
+import {
+ ACTION_AGENT_FILE_INFO_ROUTE,
+ EXECUTE_ROUTE,
+} from '@kbn/security-solution-plugin/common/endpoint/constants';
import { IndexedHostsAndAlertsResponse } from '@kbn/security-solution-plugin/common/endpoint/index_data';
+import { ActionDetails } from '@kbn/security-solution-plugin/common/endpoint/types';
+import { getFileDownloadId } from '@kbn/security-solution-plugin/common/endpoint/service/response_actions/get_file_download_id';
import { FtrProviderContext } from '../../../../ftr_provider_context_edr_workflows';
import { ROLE } from '../../../../config/services/security_solution_edr_workflows_roles_users';
export default function ({ getService }: FtrProviderContext) {
const supertestWithoutAuth = getService('supertestWithoutAuth');
const endpointTestResources = getService('endpointTestResources');
+ const rolesUsersProvider = getService('rolesUsersProvider');
+
// @skipInServerlessMKI - this test uses internal index manipulation in before/after hooks
describe('@ess @serverless @skipInServerlessMKI Endpoint `execute` response action', function () {
let indexedData: IndexedHostsAndAlertsResponse;
@@ -150,5 +157,66 @@ export default function ({ getService }: FtrProviderContext) {
expect(data.parameters.command).to.eql('ls -la');
expect(data.parameters.timeout).to.eql(2000);
});
+
+ // Test checks to ensure API works with a custom role
+ describe('@skipInServerless @skipInServerlessMKI and with minimal authz', () => {
+ const username = 'execute_limited';
+ const password = 'changeme';
+ let fileInfoApiRoutePath: string = '';
+
+ before(async () => {
+ await rolesUsersProvider.createRole({
+ customRole: {
+ roleName: username,
+ extraPrivileges: ['minimal_all', 'execute_operations_all'],
+ },
+ });
+ await rolesUsersProvider.createUser({ name: username, password, roles: [username] });
+
+ const {
+ body: { data },
+ } = await supertestWithoutAuth
+ .post(EXECUTE_ROUTE)
+ .auth(username, password)
+ .set('kbn-xsrf', 'true')
+ .set('Elastic-Api-Version', '2023-10-31')
+ .send({ endpoint_ids: [agentId], parameters: { command: 'ls -la' } })
+ .expect(200);
+
+ const actionDetails = data as ActionDetails;
+
+ fileInfoApiRoutePath = ACTION_AGENT_FILE_INFO_ROUTE.replace('{action_id}', data.id).replace(
+ '{file_id}',
+ getFileDownloadId(actionDetails)
+ );
+ });
+
+ after(async () => {
+ await rolesUsersProvider.deleteRoles([username]);
+ await rolesUsersProvider.deleteUsers([username]);
+ });
+
+ it('should have access to file info api', async () => {
+ await supertestWithoutAuth
+ .get(fileInfoApiRoutePath)
+ .auth(username, password)
+ .set('kbn-xsrf', 'true')
+ .set('Elastic-Api-Version', '2023-10-31')
+ // We expect 404 because the indexes with the file info don't exist.
+ // The key here is that we do NOT get a 401 or 403
+ .expect(404);
+ });
+
+ it('should have access to file download api', async () => {
+ await supertestWithoutAuth
+ .get(`${fileInfoApiRoutePath}/download`)
+ .auth(username, password)
+ .set('kbn-xsrf', 'true')
+ .set('Elastic-Api-Version', '2023-10-31')
+ // We expect 404 because the indexes with the file info don't exist.
+ // The key here is that we do NOT get a 401 or 403
+ .expect(404);
+ });
+ });
});
}
diff --git a/x-pack/test/security_solution_api_integration/tsconfig.json b/x-pack/test/security_solution_api_integration/tsconfig.json
index 8584cebd03edb..a4b454cb27870 100644
--- a/x-pack/test/security_solution_api_integration/tsconfig.json
+++ b/x-pack/test/security_solution_api_integration/tsconfig.json
@@ -46,5 +46,6 @@
"@kbn/utility-types",
"@kbn/timelines-plugin",
"@kbn/dev-cli-runner",
+ "@kbn/security-plugin",
]
}
From 7aae5d9ce1dc84fd3763bba4930e798f0897d453 Mon Sep 17 00:00:00 2001
From: Maxim Palenov
Date: Mon, 22 Jul 2024 17:50:40 +0200
Subject: [PATCH 20/30] [Security Solution] Enable OpenAPI schemas linting in
Security Solution plugin (#188529)
**Relates to:** https://github.com/elastic/security-team/issues/9401
## Summary
Disabling OpenAPI spec linting in https://github.com/elastic/kibana/pull/179074 lead to accumulating invalid OpenAPi specs.
This PR enables OpenAPI linting for Security Solution plugin and make appropriate fixes to make the linting pass.
## Details
OpenAPI linting is a part of code generation. It runs automatically but can be disabled via `skipLinting: true`. Code generation with disabled linting isn't able to catch all possible problems in processing specs.
The majority of problems came from Entity Analytics and Osquery OpenAPI specs. These specs were fixed and refactored to enable code generation and integrate generated artefacts into routes to make sure OpenAPI spec match API endpoints they describe. It helped to catch some subtle inconsistencies.
---
.../redocly_linter/config.yaml | 15 +-
.../osquery/common/api/asset/assets.gen.ts | 37 ++++
.../common/api/asset/assets.schema.yaml | 24 ++-
.../common/api/asset/assets_status.gen.ts | 3 -
.../api/asset/assets_status.schema.yaml | 13 +-
.../api/fleet_wrapper/fleet_wrapper.gen.ts | 51 +++++
.../fleet_wrapper/fleet_wrapper.schema.yaml | 54 +++--
.../fleet_wrapper/get_agent_details.gen.ts | 23 ---
.../get_agent_details.schema.yaml | 20 --
.../fleet_wrapper/get_agent_details_route.ts | 14 --
.../fleet_wrapper/get_agent_policies.gen.ts | 23 ---
.../get_agent_policies.schema.yaml | 26 ---
.../fleet_wrapper/get_agent_policies_route.ts | 20 --
.../api/fleet_wrapper/get_agent_policy.gen.ts | 27 ---
.../get_agent_policy.schema.yaml | 23 ---
.../api/fleet_wrapper/get_agent_status.gen.ts | 3 -
.../get_agent_status.schema.yaml | 19 +-
.../api/fleet_wrapper/get_agents.gen.ts | 23 ---
.../api/fleet_wrapper/get_agents.schema.yaml | 20 --
.../fleet_wrapper/get_package_policies.gen.ts | 23 ---
.../get_package_policies.schema.yaml | 20 --
x-pack/plugins/osquery/common/api/index.ts | 3 +-
.../api/status/privileges_check.schema.yaml | 3 +-
.../common/api/status/status.schema.yaml | 3 +-
.../osquery/scripts/openapi/generate.js | 2 -
.../routes/fleet_wrapper/get_agent_details.ts | 13 +-
.../fleet_wrapper/get_agent_policies.ts | 22 +-
.../routes/fleet_wrapper/get_agent_policy.ts | 10 +-
.../fleet_wrapper/get_package_policies.ts | 12 +-
x-pack/plugins/osquery/tsconfig.json | 7 +-
.../create_index/create_index.schema.yaml | 1 +
.../read_index/read_index.schema.yaml | 1 +
.../bulk_upload_asset_criticality.gen.ts | 32 ++-
.../bulk_upload_asset_criticality.schema.yaml | 80 ++++++--
.../asset_criticality/common.gen.ts | 43 ----
.../asset_criticality/common.schema.yaml | 61 ------
.../create_asset_criticality.gen.ts | 59 ++++++
.../create_asset_criticality.schema.yaml | 25 ++-
.../delete_asset_criticality.gen.ts | 61 ++++++
.../delete_asset_criticality.schema.yaml | 51 ++++-
.../get_asset_criticality.gen.ts | 39 ++++
.../get_asset_criticality.schema.yaml | 36 +++-
.../get_asset_criticality_status.gen.ts | 4 +-
.../get_asset_criticality_status.schema.yaml | 16 +-
.../asset_criticality/index.ts | 2 +-
.../list_asset_criticality.gen.ts | 35 +++-
.../list_asset_criticality.schema.yaml | 53 +++--
.../list_asset_criticality_query_params.ts | 18 --
.../upload_asset_criticality_csv.gen.ts | 46 +++++
.../upload_asset_criticality_csv.schema.yaml | 72 ++++++-
.../risk_engine/engine_disable_route.gen.ts | 10 +-
.../engine_disable_route.schema.yaml | 12 +-
.../risk_engine/engine_enable_route.gen.ts | 14 +-
.../engine_enable_route.schema.yaml | 16 +-
.../risk_engine/engine_init_route.gen.ts | 18 +-
.../risk_engine/engine_init_route.schema.yaml | 23 +--
.../risk_engine/engine_settings_route.gen.ts | 4 +-
.../engine_settings_route.schema.yaml | 16 +-
.../risk_engine/engine_status_route.gen.ts | 3 +
.../engine_status_route.schema.yaml | 2 +
.../entity_calculation_route.gen.ts | 26 +++
.../entity_calculation_route.schema.yaml | 5 +
.../risk_engine/preview_route.gen.ts | 7 +
.../risk_engine/preview_route.schema.yaml | 2 +
...ections_api_2023_10_31.bundled.schema.yaml | 2 +
.../public/entity_analytics/api/api.ts | 22 +-
.../hooks/use_disable_risk_engine_mutation.ts | 4 +-
.../hooks/use_enable_risk_engine_mutation.ts | 8 +-
.../hooks/use_init_risk_engine_mutation.ts | 10 +-
.../components/result_step.tsx | 4 +-
.../reducer.test.ts | 4 +-
.../reducer.ts | 6 +-
.../scripts/openapi/generate.js | 1 -
.../asset_criticality_data_client.ts | 8 +-
.../asset_criticality/routes/bulk_upload.ts | 8 +-
.../asset_criticality/routes/delete.ts | 11 +-
.../asset_criticality/routes/get.ts | 8 +-
.../asset_criticality/routes/list.ts | 8 +-
.../asset_criticality/routes/status.ts | 4 +-
.../asset_criticality/routes/upload_csv.ts | 4 +-
.../asset_criticality/routes/upsert.ts | 11 +-
.../risk_engine/routes/disable.ts | 4 +-
.../risk_engine/routes/enable.ts | 4 +-
.../risk_engine/routes/init.ts | 8 +-
.../risk_engine/routes/settings.ts | 4 +-
.../lib/telemetry/event_based/events.ts | 8 +-
.../services/security_solution_api.gen.ts | 191 ++++++++++++++++++
.../utils/asset_criticality.ts | 4 +-
88 files changed, 1077 insertions(+), 718 deletions(-)
create mode 100644 x-pack/plugins/osquery/common/api/asset/assets.gen.ts
create mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/fleet_wrapper.gen.ts
delete mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_details.gen.ts
delete mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_details.schema.yaml
delete mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_details_route.ts
delete mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policies.gen.ts
delete mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policies.schema.yaml
delete mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policies_route.ts
delete mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policy.gen.ts
delete mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policy.schema.yaml
delete mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_agents.gen.ts
delete mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_agents.schema.yaml
delete mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_package_policies.gen.ts
delete mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_package_policies.schema.yaml
create mode 100644 x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/create_asset_criticality.gen.ts
create mode 100644 x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/delete_asset_criticality.gen.ts
create mode 100644 x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/get_asset_criticality.gen.ts
delete mode 100644 x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/list_asset_criticality_query_params.ts
create mode 100644 x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/upload_asset_criticality_csv.gen.ts
diff --git a/packages/kbn-openapi-generator/redocly_linter/config.yaml b/packages/kbn-openapi-generator/redocly_linter/config.yaml
index b423d9172b1c8..fc4ff630cc2bb 100644
--- a/packages/kbn-openapi-generator/redocly_linter/config.yaml
+++ b/packages/kbn-openapi-generator/redocly_linter/config.yaml
@@ -5,23 +5,24 @@ plugins:
rules:
spec: error
- spec-strict-refs: warn
+ spec-strict-refs: error
no-path-trailing-slash: error
no-identical-paths: error
- no-ambiguous-paths: warn
+ no-ambiguous-paths: error
no-unresolved-refs: error
no-enum-type-mismatch: error
component-name-unique: error
path-declaration-must-exist: error
path-not-include-query: error
- path-parameters-defined: warn
- operation-description: warn
operation-2xx-response: error
- operation-4xx-response: warn
operation-operationId: error
operation-operationId-unique: error
- operation-summary: warn
operation-operationId-url-safe: error
operation-parameters-unique: error
- boolean-parameter-prefixes: warn
extra-linter-rules-plugin/valid-x-modify: error
+ # Disable rules generating the majority of warnings.
+ # They will be handled separately.
+ # operation-description: warn
+ # operation-summary: warn
+ # operation-4xx-response: warn
+ # path-parameters-defined: warn
diff --git a/x-pack/plugins/osquery/common/api/asset/assets.gen.ts b/x-pack/plugins/osquery/common/api/asset/assets.gen.ts
new file mode 100644
index 0000000000000..f0cc5209e13a4
--- /dev/null
+++ b/x-pack/plugins/osquery/common/api/asset/assets.gen.ts
@@ -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; 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: Assets Schema
+ * version: 1
+ */
+
+import { z } from 'zod';
+
+import { AssetsRequestQuery } from './assets_status.gen';
+
+export type ReadAssetsStatusRequestParams = z.infer;
+export const ReadAssetsStatusRequestParams = z.object({
+ query: AssetsRequestQuery,
+});
+export type ReadAssetsStatusRequestParamsInput = z.input;
+
+export type ReadAssetsStatusResponse = z.infer;
+export const ReadAssetsStatusResponse = z.object({});
+
+export type UpdateAssetsStatusRequestParams = z.infer;
+export const UpdateAssetsStatusRequestParams = z.object({
+ query: AssetsRequestQuery,
+});
+export type UpdateAssetsStatusRequestParamsInput = z.input;
+
+export type UpdateAssetsStatusResponse = z.infer;
+export const UpdateAssetsStatusResponse = z.object({});
diff --git a/x-pack/plugins/osquery/common/api/asset/assets.schema.yaml b/x-pack/plugins/osquery/common/api/asset/assets.schema.yaml
index 31688b7ce66cb..2769bc188ab20 100644
--- a/x-pack/plugins/osquery/common/api/asset/assets.schema.yaml
+++ b/x-pack/plugins/osquery/common/api/asset/assets.schema.yaml
@@ -5,25 +5,41 @@ info:
paths:
/internal/osquery/assets:
get:
+ x-codegen-enabled: true
+ operationId: ReadAssetsStatus
summary: Get assets
parameters:
- - $ref: './assets_status.schema.yaml#/components/parameters/AssetsStatusRequestQueryParameter'
+ - name: query
+ in: path
+ required: true
+ schema:
+ $ref: './assets_status.schema.yaml#/components/schemas/AssetsRequestQuery'
responses:
'200':
description: OK
content:
application/json:
schema:
- $ref: './assets_status.schema.yaml#/components/schemas/SuccessResponse'
+ type: object
+ properties: {}
+ # Define properties for the success response if needed
/internal/osquery/assets/update:
post:
+ x-codegen-enabled: true
+ operationId: UpdateAssetsStatus
summary: Update assets
parameters:
- - $ref: './assets_status.schema.yaml#/components/parameters/AssetsStatusRequestQueryParameter'
+ - name: query
+ in: path
+ required: true
+ schema:
+ $ref: './assets_status.schema.yaml#/components/schemas/AssetsRequestQuery'
responses:
'200':
description: OK
content:
application/json:
schema:
- $ref: './assets_status.schema.yaml#/components/schemas/SuccessResponse'
+ type: object
+ properties: {}
+ # Define properties for the success response if needed
diff --git a/x-pack/plugins/osquery/common/api/asset/assets_status.gen.ts b/x-pack/plugins/osquery/common/api/asset/assets_status.gen.ts
index 53a98b96612ea..fd3c50374943f 100644
--- a/x-pack/plugins/osquery/common/api/asset/assets_status.gen.ts
+++ b/x-pack/plugins/osquery/common/api/asset/assets_status.gen.ts
@@ -18,6 +18,3 @@ import { z } from 'zod';
export type AssetsRequestQuery = z.infer;
export const AssetsRequestQuery = z.object({});
-
-export type SuccessResponse = z.infer;
-export const SuccessResponse = z.object({});
diff --git a/x-pack/plugins/osquery/common/api/asset/assets_status.schema.yaml b/x-pack/plugins/osquery/common/api/asset/assets_status.schema.yaml
index 48322c1266b07..fb57329a9992d 100644
--- a/x-pack/plugins/osquery/common/api/asset/assets_status.schema.yaml
+++ b/x-pack/plugins/osquery/common/api/asset/assets_status.schema.yaml
@@ -2,19 +2,8 @@ openapi: 3.0.0
info:
title: Assets Status Schema
version: '1'
-paths: { }
+paths: {}
components:
- parameters:
- AssetsStatusRequestQueryParameter:
- name: query
- in: path
- required: true
- schema:
- $ref: '#/components/schemas/AssetsRequestQuery'
schemas:
AssetsRequestQuery:
type: object
- SuccessResponse:
- type: object
- properties: {}
- # Define properties for the success response if needed
diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/fleet_wrapper.gen.ts b/x-pack/plugins/osquery/common/api/fleet_wrapper/fleet_wrapper.gen.ts
new file mode 100644
index 0000000000000..1ecea2c4caf19
--- /dev/null
+++ b/x-pack/plugins/osquery/common/api/fleet_wrapper/fleet_wrapper.gen.ts
@@ -0,0 +1,51 @@
+/*
+ * 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: Fleet wrapper schema
+ * version: 1
+ */
+
+import { z } from 'zod';
+
+import { Id } from '../model/schema/common_attributes.gen';
+
+export type GetAgentDetailsRequestParams = z.infer;
+export const GetAgentDetailsRequestParams = z.object({
+ id: Id,
+});
+export type GetAgentDetailsRequestParamsInput = z.input;
+
+export type GetAgentDetailsResponse = z.infer;
+export const GetAgentDetailsResponse = z.object({});
+
+export type GetAgentPackagePoliciesResponse = z.infer;
+export const GetAgentPackagePoliciesResponse = z.object({});
+
+export type GetAgentPoliciesResponse = z.infer;
+export const GetAgentPoliciesResponse = z.object({});
+
+export type GetAgentPolicyRequestParams = z.infer;
+export const GetAgentPolicyRequestParams = z.object({
+ id: Id,
+});
+export type GetAgentPolicyRequestParamsInput = z.input;
+
+export type GetAgentPolicyResponse = z.infer;
+export const GetAgentPolicyResponse = z.object({});
+export type GetAgentsRequestQuery = z.infer;
+export const GetAgentsRequestQuery = z.object({
+ query: z.object({}),
+});
+export type GetAgentsRequestQueryInput = z.input;
+
+export type GetAgentsResponse = z.infer;
+export const GetAgentsResponse = z.object({});
diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/fleet_wrapper.schema.yaml b/x-pack/plugins/osquery/common/api/fleet_wrapper/fleet_wrapper.schema.yaml
index 7e46e15abb825..fa5a576cb1a2e 100644
--- a/x-pack/plugins/osquery/common/api/fleet_wrapper/fleet_wrapper.schema.yaml
+++ b/x-pack/plugins/osquery/common/api/fleet_wrapper/fleet_wrapper.schema.yaml
@@ -5,66 +5,94 @@ info:
paths:
/internal/osquery/fleet_wrapper/agents:
get:
+ x-codegen-enabled: true
+ operationId: GetAgents
summary: Get agents
parameters:
- - $ref: './get_agents.schema.yaml#/components/parameters/GetAgentsRequestQueryParameter'
+ - name: query
+ in: query
+ required: true
+ schema:
+ type: object
+ additionalProperties: true
responses:
'200':
description: OK
content:
application/json:
schema:
- $ref: './get_agents.schema.yaml#/components/schemas/SuccessResponse'
+ type: object
+ properties: {}
+ # Define properties for the success response if needed
/internal/osquery/fleet_wrapper/agents/{id}:
get:
+ x-codegen-enabled: true
+ operationId: GetAgentDetails
summary: Get Agent details
parameters:
- - $ref: './get_agent_details.schema.yaml#/components/parameters/GetAgentDetailsRequestQueryParameter'
+ - name: id
+ in: path
+ required: true
+ schema:
+ $ref: '../model/schema/common_attributes.schema.yaml#/components/schemas/Id'
responses:
'200':
description: OK
content:
application/json:
schema:
- $ref: './get_agent_details.schema.yaml#/components/schemas/SuccessResponse'
+ type: object
+ properties: {}
+ # Define properties for the success response if needed
/internal/osquery/fleet_wrapper/agent_policies:
get:
+ x-codegen-enabled: true
+ operationId: GetAgentPolicies
summary: Get Agent policies
- parameters:
- - $ref: './get_agent_policies.schema.yaml#/components/parameters/GetAgentPoliciesRequestParameter'
- - $ref: './get_agent_policies.schema.yaml#/components/parameters/GetAgentPoliciesRequestQueryParameter'
responses:
'200':
description: OK
content:
application/json:
schema:
- $ref: './get_agent_policies.schema.yaml#/components/schemas/SuccessResponse'
+ type: object
+ properties: {}
+ # Define properties for the success response if needed
/internal/osquery/fleet_wrapper/agent_policies/{id}:
get:
+ x-codegen-enabled: true
+ operationId: GetAgentPolicy
summary: Get Agent policy
parameters:
- - $ref: './get_agent_policy.schema.yaml#/components/parameters/GetAgentPolicyRequestParameter'
+ - name: id
+ in: path
+ required: true
+ schema:
+ $ref: '../model/schema/common_attributes.schema.yaml#/components/schemas/Id'
responses:
'200':
description: OK
content:
application/json:
schema:
- $ref: './get_agent_policy.schema.yaml#/components/schemas/SuccessResponse'
+ type: object
+ properties: {}
+ # Define properties for the success response if needed
/internal/osquery/fleet_wrapper/package_policies:
get:
+ x-codegen-enabled: true
+ operationId: GetAgentPackagePolicies
summary: Get Agent policy
- parameters:
- - $ref: './get_package_policies.schema.yaml#/components/parameters/GetPackagePoliciesRequestQueryParameter'
responses:
'200':
description: OK
content:
application/json:
schema:
- $ref: './get_package_policies.schema.yaml#/components/schemas/SuccessResponse'
+ type: object
+ properties: {}
+ # Define properties for the success response if needed
diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_details.gen.ts b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_details.gen.ts
deleted file mode 100644
index 5d721a018205b..0000000000000
--- a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_details.gen.ts
+++ /dev/null
@@ -1,23 +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.
- */
-
-/*
- * NOTICE: Do not edit this file manually.
- * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator.
- *
- * info:
- * title: Get agent details schema
- * version: 1
- */
-
-import { z } from 'zod';
-
-export type GetAgentDetailsRequestParams = z.infer;
-export const GetAgentDetailsRequestParams = z.object({});
-
-export type SuccessResponse = z.infer;
-export const SuccessResponse = z.object({});
diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_details.schema.yaml b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_details.schema.yaml
deleted file mode 100644
index bdf4cb3329cdf..0000000000000
--- a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_details.schema.yaml
+++ /dev/null
@@ -1,20 +0,0 @@
-openapi: 3.0.0
-info:
- title: Get agent details schema
- version: '1'
-paths: { }
-components:
- parameters:
- GetAgentDetailsRequestQueryParameter:
- name: query
- in: path
- required: true
- schema:
- $ref: '#/components/schemas/GetAgentDetailsRequestParams'
- schemas:
- GetAgentDetailsRequestParams:
- type: object
- SuccessResponse:
- type: object
- properties: {}
- # Define properties for the success response if needed
diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_details_route.ts b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_details_route.ts
deleted file mode 100644
index fcc7dad089bab..0000000000000
--- a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_details_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 * as t from 'io-ts';
-
-export const getAgentDetailsRequestParamsSchema = t.unknown;
-
-export type GetAgentDetailsRequestParamsSchema = t.OutputOf<
- typeof getAgentDetailsRequestParamsSchema
->;
diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policies.gen.ts b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policies.gen.ts
deleted file mode 100644
index 875c21a600e93..0000000000000
--- a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policies.gen.ts
+++ /dev/null
@@ -1,23 +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.
- */
-
-/*
- * NOTICE: Do not edit this file manually.
- * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator.
- *
- * info:
- * title: Get agent policies schema
- * version: 1
- */
-
-import { z } from 'zod';
-
-export type GetAgentPoliciesRequestParams = z.infer;
-export const GetAgentPoliciesRequestParams = z.object({});
-
-export type SuccessResponse = z.infer;
-export const SuccessResponse = z.object({});
diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policies.schema.yaml b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policies.schema.yaml
deleted file mode 100644
index cdfb521712674..0000000000000
--- a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policies.schema.yaml
+++ /dev/null
@@ -1,26 +0,0 @@
-openapi: 3.0.0
-info:
- title: Get agent policies schema
- version: '1'
-paths: { }
-components:
- parameters:
- GetAgentPoliciesRequestQueryParameter:
- name: query
- in: query
- required: true
- schema:
- $ref: '#/components/schemas/GetAgentPoliciesRequestParams'
- GetAgentPoliciesRequestParameter:
- name: query
- in: path
- required: true
- schema:
- $ref: '#/components/schemas/GetAgentPoliciesRequestParams'
- schemas:
- GetAgentPoliciesRequestParams:
- type: object
- SuccessResponse:
- type: object
- properties: {}
- # Define properties for the success response if needed
diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policies_route.ts b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policies_route.ts
deleted file mode 100644
index 84a68e5fbf4c7..0000000000000
--- a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policies_route.ts
+++ /dev/null
@@ -1,20 +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 * as t from 'io-ts';
-
-export const getAgentPoliciesRequestParamsSchema = t.unknown;
-
-export type GetAgentPoliciesRequestParamsSchema = t.OutputOf<
- typeof getAgentPoliciesRequestParamsSchema
->;
-
-export const getAgentPoliciesRequestQuerySchema = t.unknown;
-
-export type GetAgentPoliciesRequestQuerySchema = t.OutputOf<
- typeof getAgentPoliciesRequestQuerySchema
->;
diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policy.gen.ts b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policy.gen.ts
deleted file mode 100644
index 3f19e274761bd..0000000000000
--- a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policy.gen.ts
+++ /dev/null
@@ -1,27 +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.
- */
-
-/*
- * NOTICE: Do not edit this file manually.
- * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator.
- *
- * info:
- * title: Get agent policy schema
- * version: 1
- */
-
-import { z } from 'zod';
-
-import { Id } from '../model/schema/common_attributes.gen';
-
-export type GetAgentPolicyRequestParams = z.infer;
-export const GetAgentPolicyRequestParams = z.object({
- id: Id.optional(),
-});
-
-export type SuccessResponse = z.infer;
-export const SuccessResponse = z.object({});
diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policy.schema.yaml b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policy.schema.yaml
deleted file mode 100644
index dc4a2607bfc6b..0000000000000
--- a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policy.schema.yaml
+++ /dev/null
@@ -1,23 +0,0 @@
-openapi: 3.0.0
-info:
- title: Get agent policy schema
- version: '1'
-paths: { }
-components:
- parameters:
- GetAgentPolicyRequestParameter:
- name: query
- in: path
- required: true
- schema:
- $ref: '#/components/schemas/GetAgentPolicyRequestParams'
- schemas:
- GetAgentPolicyRequestParams:
- type: object
- properties:
- id:
- $ref: '../model/schema/common_attributes.schema.yaml#/components/schemas/Id'
- SuccessResponse:
- type: object
- properties: {}
- # Define properties for the success response if needed
diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_status.gen.ts b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_status.gen.ts
index 80adc112312a7..041aac0bf2320 100644
--- a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_status.gen.ts
+++ b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_status.gen.ts
@@ -26,6 +26,3 @@ export const GetAgentStatusRequestQueryParams = z.object({
kuery: KueryOrUndefined.optional(),
policyId: Id.optional(),
});
-
-export type SuccessResponse = z.infer;
-export const SuccessResponse = z.object({});
diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_status.schema.yaml b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_status.schema.yaml
index e10174bee2634..af2e9307b4c12 100644
--- a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_status.schema.yaml
+++ b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_status.schema.yaml
@@ -2,21 +2,8 @@ openapi: 3.0.0
info:
title: Get agent status schema
version: '1'
-paths: { }
+paths: {}
components:
- parameters:
- GetAgentStatusRequestQueryParameter:
- name: query
- in: query
- required: true
- schema:
- $ref: '#/components/schemas/GetAgentStatusRequestQueryParams'
- GetAgentStatusRequestParameter:
- name: query
- in: path
- required: true
- schema:
- $ref: '#/components/schemas/GetAgentStatusRequestParams'
schemas:
GetAgentStatusRequestParams:
type: object
@@ -27,7 +14,3 @@ components:
$ref: '../model/schema/common_attributes.schema.yaml#/components/schemas/KueryOrUndefined'
policyId:
$ref: '../model/schema/common_attributes.schema.yaml#/components/schemas/Id'
- SuccessResponse:
- type: object
- properties: {}
- # Define properties for the success response if needed
diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agents.gen.ts b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agents.gen.ts
deleted file mode 100644
index b162bcbfd967b..0000000000000
--- a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agents.gen.ts
+++ /dev/null
@@ -1,23 +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.
- */
-
-/*
- * NOTICE: Do not edit this file manually.
- * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator.
- *
- * info:
- * title: Get agents schema
- * version: 1
- */
-
-import { z } from 'zod';
-
-export type GetAgentsRequestParams = z.infer;
-export const GetAgentsRequestParams = z.object({});
-
-export type SuccessResponse = z.infer;
-export const SuccessResponse = z.object({});
diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agents.schema.yaml b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agents.schema.yaml
deleted file mode 100644
index c1a387512c3d3..0000000000000
--- a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agents.schema.yaml
+++ /dev/null
@@ -1,20 +0,0 @@
-openapi: 3.0.0
-info:
- title: Get agents schema
- version: '1'
-paths: { }
-components:
- parameters:
- GetAgentsRequestQueryParameter:
- name: query
- in: path
- required: true
- schema:
- $ref: '#/components/schemas/GetAgentsRequestParams'
- schemas:
- GetAgentsRequestParams:
- type: object
- SuccessResponse:
- type: object
- properties: {}
- # Define properties for the success response if needed
diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_package_policies.gen.ts b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_package_policies.gen.ts
deleted file mode 100644
index f4c3be37371ea..0000000000000
--- a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_package_policies.gen.ts
+++ /dev/null
@@ -1,23 +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.
- */
-
-/*
- * NOTICE: Do not edit this file manually.
- * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator.
- *
- * info:
- * title: Get package policies schema
- * version: 1
- */
-
-import { z } from 'zod';
-
-export type GetPackagePoliciesRequestParams = z.infer;
-export const GetPackagePoliciesRequestParams = z.object({});
-
-export type SuccessResponse = z.infer;
-export const SuccessResponse = z.object({});
diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_package_policies.schema.yaml b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_package_policies.schema.yaml
deleted file mode 100644
index 708867e8f7fa1..0000000000000
--- a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_package_policies.schema.yaml
+++ /dev/null
@@ -1,20 +0,0 @@
-openapi: 3.0.0
-info:
- title: Get package policies schema
- version: '1'
-paths: { }
-components:
- parameters:
- GetPackagePoliciesRequestQueryParameter:
- name: query
- in: path
- required: true
- schema:
- $ref: '#/components/schemas/GetPackagePoliciesRequestParams'
- schemas:
- GetPackagePoliciesRequestParams:
- type: object
- SuccessResponse:
- type: object
- properties: {}
- # Define properties for the success response if needed
diff --git a/x-pack/plugins/osquery/common/api/index.ts b/x-pack/plugins/osquery/common/api/index.ts
index 681eaab583ca8..b1c42a8dc45e6 100644
--- a/x-pack/plugins/osquery/common/api/index.ts
+++ b/x-pack/plugins/osquery/common/api/index.ts
@@ -7,8 +7,7 @@
export * from './asset/get_assets_status_route';
export * from './asset/update_assets_status_route';
-export * from './fleet_wrapper/get_agent_policies_route';
-export * from './fleet_wrapper/get_agent_details_route';
+export * from './fleet_wrapper/fleet_wrapper.gen';
export * from './fleet_wrapper/get_agent_policy_route';
export * from './fleet_wrapper/get_agent_status_for_agent_policy_route';
export * from './fleet_wrapper/get_agents_route';
diff --git a/x-pack/plugins/osquery/common/api/status/privileges_check.schema.yaml b/x-pack/plugins/osquery/common/api/status/privileges_check.schema.yaml
index 2702d1bafa040..8a8267a83f336 100644
--- a/x-pack/plugins/osquery/common/api/status/privileges_check.schema.yaml
+++ b/x-pack/plugins/osquery/common/api/status/privileges_check.schema.yaml
@@ -5,6 +5,7 @@ info:
paths:
/internal/osquery/privileges_check:
get:
+ operationId: ReadPrivilegesCheck
summary: Get Osquery privileges check
responses:
'200':
@@ -13,4 +14,4 @@ paths:
application/json:
schema:
type: object
- properties: { }
+ properties: {}
diff --git a/x-pack/plugins/osquery/common/api/status/status.schema.yaml b/x-pack/plugins/osquery/common/api/status/status.schema.yaml
index 9ab4d3bd0e607..1ed1e096ba10e 100644
--- a/x-pack/plugins/osquery/common/api/status/status.schema.yaml
+++ b/x-pack/plugins/osquery/common/api/status/status.schema.yaml
@@ -5,6 +5,7 @@ info:
paths:
/internal/osquery/status:
get:
+ operationId: ReadInstallationStatus
summary: Get Osquery installation status
responses:
'200':
@@ -13,4 +14,4 @@ paths:
application/json:
schema:
type: object
- properties: { }
+ properties: {}
diff --git a/x-pack/plugins/osquery/scripts/openapi/generate.js b/x-pack/plugins/osquery/scripts/openapi/generate.js
index 35c099301e81c..018a965702c3e 100644
--- a/x-pack/plugins/osquery/scripts/openapi/generate.js
+++ b/x-pack/plugins/osquery/scripts/openapi/generate.js
@@ -17,6 +17,4 @@ generate({
rootDir: OSQUERY_ROOT,
sourceGlob: './**/*.schema.yaml',
templateName: 'zod_operation_schema',
- // TODO: Fix lint errors
- skipLinting: true,
});
diff --git a/x-pack/plugins/osquery/server/routes/fleet_wrapper/get_agent_details.ts b/x-pack/plugins/osquery/server/routes/fleet_wrapper/get_agent_details.ts
index b3b6539f9fc35..c1d445fd40183 100644
--- a/x-pack/plugins/osquery/server/routes/fleet_wrapper/get_agent_details.ts
+++ b/x-pack/plugins/osquery/server/routes/fleet_wrapper/get_agent_details.ts
@@ -6,12 +6,11 @@
*/
import type { IRouter } from '@kbn/core/server';
-import type { GetAgentDetailsRequestParamsSchema } from '../../../common/api';
-import { buildRouteValidation } from '../../utils/build_validation/route_validation';
+import { buildRouteValidationWithZod } from '@kbn/zod-helpers';
import { API_VERSIONS } from '../../../common/constants';
import { PLUGIN_ID } from '../../../common';
import type { OsqueryAppContext } from '../../lib/osquery_app_context_services';
-import { getAgentDetailsRequestParamsSchema } from '../../../common/api';
+import { GetAgentDetailsRequestParams } from '../../../common/api';
export const getAgentDetailsRoute = (router: IRouter, osqueryContext: OsqueryAppContext) => {
router.versioned
@@ -25,10 +24,7 @@ export const getAgentDetailsRoute = (router: IRouter, osqueryContext: OsqueryApp
version: API_VERSIONS.internal.v1,
validate: {
request: {
- params: buildRouteValidation<
- typeof getAgentDetailsRequestParamsSchema,
- GetAgentDetailsRequestParamsSchema
- >(getAgentDetailsRequestParamsSchema),
+ params: buildRouteValidationWithZod(GetAgentDetailsRequestParams),
},
},
},
@@ -38,8 +34,7 @@ export const getAgentDetailsRoute = (router: IRouter, osqueryContext: OsqueryApp
try {
agent = await osqueryContext.service
.getAgentService()
- ?.asInternalUser // @ts-expect-error update types
- ?.getAgent(request.params.id);
+ ?.asInternalUser?.getAgent(request.params.id);
} catch (err) {
return response.notFound();
}
diff --git a/x-pack/plugins/osquery/server/routes/fleet_wrapper/get_agent_policies.ts b/x-pack/plugins/osquery/server/routes/fleet_wrapper/get_agent_policies.ts
index ee80758652706..9e84410712506 100644
--- a/x-pack/plugins/osquery/server/routes/fleet_wrapper/get_agent_policies.ts
+++ b/x-pack/plugins/osquery/server/routes/fleet_wrapper/get_agent_policies.ts
@@ -11,19 +11,10 @@ import { satisfies } from 'semver';
import type { GetAgentPoliciesResponseItem, PackagePolicy } from '@kbn/fleet-plugin/common';
import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '@kbn/fleet-plugin/common';
import type { IRouter } from '@kbn/core/server';
-import type {
- GetAgentPoliciesRequestParamsSchema,
- GetAgentPoliciesRequestQuerySchema,
-} from '../../../common/api';
-import { buildRouteValidation } from '../../utils/build_validation/route_validation';
import { API_VERSIONS } from '../../../common/constants';
import { OSQUERY_INTEGRATION_NAME, PLUGIN_ID } from '../../../common';
import type { OsqueryAppContext } from '../../lib/osquery_app_context_services';
import { getInternalSavedObjectsClient } from '../utils';
-import {
- getAgentPoliciesRequestParamsSchema,
- getAgentPoliciesRequestQuerySchema,
-} from '../../../common/api';
export const getAgentPoliciesRoute = (router: IRouter, osqueryContext: OsqueryAppContext) => {
router.versioned
@@ -35,18 +26,7 @@ export const getAgentPoliciesRoute = (router: IRouter, osqueryContext: OsqueryAp
.addVersion(
{
version: API_VERSIONS.internal.v1,
- validate: {
- request: {
- params: buildRouteValidation<
- typeof getAgentPoliciesRequestParamsSchema,
- GetAgentPoliciesRequestParamsSchema
- >(getAgentPoliciesRequestParamsSchema),
- query: buildRouteValidation<
- typeof getAgentPoliciesRequestQuerySchema,
- GetAgentPoliciesRequestQuerySchema
- >(getAgentPoliciesRequestQuerySchema),
- },
- },
+ validate: {},
},
async (context, request, response) => {
const internalSavedObjectsClient = await getInternalSavedObjectsClient(
diff --git a/x-pack/plugins/osquery/server/routes/fleet_wrapper/get_agent_policy.ts b/x-pack/plugins/osquery/server/routes/fleet_wrapper/get_agent_policy.ts
index 85de68f7e44d9..bad5b01289d52 100644
--- a/x-pack/plugins/osquery/server/routes/fleet_wrapper/get_agent_policy.ts
+++ b/x-pack/plugins/osquery/server/routes/fleet_wrapper/get_agent_policy.ts
@@ -6,13 +6,12 @@
*/
import type { IRouter } from '@kbn/core/server';
-import type { GetAgentPolicyRequestParamsSchema } from '../../../common/api';
-import { buildRouteValidation } from '../../utils/build_validation/route_validation';
+import { buildRouteValidationWithZod } from '@kbn/zod-helpers';
import { API_VERSIONS } from '../../../common/constants';
import { PLUGIN_ID } from '../../../common';
import type { OsqueryAppContext } from '../../lib/osquery_app_context_services';
import { getInternalSavedObjectsClient } from '../utils';
-import { getAgentPolicyRequestParamsSchema } from '../../../common/api';
+import { GetAgentPolicyRequestParams } from '../../../common/api';
export const getAgentPolicyRoute = (router: IRouter, osqueryContext: OsqueryAppContext) => {
router.versioned
@@ -26,10 +25,7 @@ export const getAgentPolicyRoute = (router: IRouter, osqueryContext: OsqueryAppC
version: API_VERSIONS.internal.v1,
validate: {
request: {
- params: buildRouteValidation<
- typeof getAgentPolicyRequestParamsSchema,
- GetAgentPolicyRequestParamsSchema
- >(getAgentPolicyRequestParamsSchema),
+ params: buildRouteValidationWithZod(GetAgentPolicyRequestParams),
},
},
},
diff --git a/x-pack/plugins/osquery/server/routes/fleet_wrapper/get_package_policies.ts b/x-pack/plugins/osquery/server/routes/fleet_wrapper/get_package_policies.ts
index 887fa4811e73e..86719125b97eb 100644
--- a/x-pack/plugins/osquery/server/routes/fleet_wrapper/get_package_policies.ts
+++ b/x-pack/plugins/osquery/server/routes/fleet_wrapper/get_package_policies.ts
@@ -7,13 +7,10 @@
import type { IRouter } from '@kbn/core/server';
import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '@kbn/fleet-plugin/common';
-import type { GetPackagePoliciesRequestQuerySchema } from '../../../common/api';
-import { buildRouteValidation } from '../../utils/build_validation/route_validation';
import { API_VERSIONS } from '../../../common/constants';
import { PLUGIN_ID, OSQUERY_INTEGRATION_NAME } from '../../../common';
import type { OsqueryAppContext } from '../../lib/osquery_app_context_services';
import { getInternalSavedObjectsClient } from '../utils';
-import { getPackagePoliciesRequestQuerySchema } from '../../../common/api';
export const getPackagePoliciesRoute = (router: IRouter, osqueryContext: OsqueryAppContext) => {
router.versioned
@@ -25,14 +22,7 @@ export const getPackagePoliciesRoute = (router: IRouter, osqueryContext: Osquery
.addVersion(
{
version: API_VERSIONS.internal.v1,
- validate: {
- request: {
- query: buildRouteValidation<
- typeof getPackagePoliciesRequestQuerySchema,
- GetPackagePoliciesRequestQuerySchema
- >(getPackagePoliciesRequestQuerySchema),
- },
- },
+ validate: {},
},
async (context, request, response) => {
const internalSavedObjectsClient = await getInternalSavedObjectsClient(
diff --git a/x-pack/plugins/osquery/tsconfig.json b/x-pack/plugins/osquery/tsconfig.json
index 6d713311c777d..6cc74e9733a92 100644
--- a/x-pack/plugins/osquery/tsconfig.json
+++ b/x-pack/plugins/osquery/tsconfig.json
@@ -3,9 +3,7 @@
"compilerOptions": {
"outDir": "target/types"
},
- "exclude": [
- "target/**/*"
- ],
+ "exclude": ["target/**/*"],
"include": [
// add all the folders contains files to be compiled
"common/**/*",
@@ -77,6 +75,7 @@
"@kbn/openapi-generator",
"@kbn/code-editor",
"@kbn/search-types",
- "@kbn/react-kibana-context-render"
+ "@kbn/react-kibana-context-render",
+ "@kbn/zod-helpers"
]
}
diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/create_index/create_index.schema.yaml b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/create_index/create_index.schema.yaml
index 63213117bd9fb..b825f5f7af7c0 100644
--- a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/create_index/create_index.schema.yaml
+++ b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/create_index/create_index.schema.yaml
@@ -35,6 +35,7 @@ paths:
schema:
$ref: '../../../model/error_responses.schema.yaml#/components/schemas/SiemErrorResponse'
404:
+ description: Not found
content:
application/json:
schema:
diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/read_index/read_index.schema.yaml b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/read_index/read_index.schema.yaml
index 4c38c57da7592..ddfbf564de2ac 100644
--- a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/read_index/read_index.schema.yaml
+++ b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/read_index/read_index.schema.yaml
@@ -38,6 +38,7 @@ paths:
schema:
$ref: '../../../model/error_responses.schema.yaml#/components/schemas/SiemErrorResponse'
404:
+ description: Not found
content:
application/json:
schema:
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/bulk_upload_asset_criticality.gen.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/bulk_upload_asset_criticality.gen.ts
index c0d00e394b6b1..5315edc16ab9f 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/bulk_upload_asset_criticality.gen.ts
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/bulk_upload_asset_criticality.gen.ts
@@ -18,7 +18,35 @@ import { z } from 'zod';
import { CreateAssetCriticalityRecord } from './common.gen';
-export type AssetCriticalityBulkUploadRequest = z.infer;
-export const AssetCriticalityBulkUploadRequest = z.object({
+export type AssetCriticalityBulkUploadErrorItem = z.infer<
+ typeof AssetCriticalityBulkUploadErrorItem
+>;
+export const AssetCriticalityBulkUploadErrorItem = z.object({
+ message: z.string(),
+ index: z.number().int(),
+});
+
+export type AssetCriticalityBulkUploadStats = z.infer;
+export const AssetCriticalityBulkUploadStats = z.object({
+ successful: z.number().int(),
+ failed: z.number().int(),
+ total: z.number().int(),
+});
+
+export type BulkUpsertAssetCriticalityRecordsRequestBody = z.infer<
+ typeof BulkUpsertAssetCriticalityRecordsRequestBody
+>;
+export const BulkUpsertAssetCriticalityRecordsRequestBody = z.object({
records: z.array(CreateAssetCriticalityRecord).min(1).max(1000),
});
+export type BulkUpsertAssetCriticalityRecordsRequestBodyInput = z.input<
+ typeof BulkUpsertAssetCriticalityRecordsRequestBody
+>;
+
+export type BulkUpsertAssetCriticalityRecordsResponse = z.infer<
+ typeof BulkUpsertAssetCriticalityRecordsResponse
+>;
+export const BulkUpsertAssetCriticalityRecordsResponse = z.object({
+ errors: z.array(AssetCriticalityBulkUploadErrorItem),
+ stats: AssetCriticalityBulkUploadStats,
+});
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/bulk_upload_asset_criticality.schema.yaml b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/bulk_upload_asset_criticality.schema.yaml
index b4b7d5d2f1fe4..c0fecede6da72 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/bulk_upload_asset_criticality.schema.yaml
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/bulk_upload_asset_criticality.schema.yaml
@@ -13,40 +13,82 @@ paths:
/api/asset_criticality/bulk:
post:
x-labels: [ess, serverless]
+ x-codegen-enabled: true
+ operationId: BulkUpsertAssetCriticalityRecords
summary: Bulk upsert asset criticality data, creating or updating records as needed
requestBody:
content:
application/json:
schema:
- $ref: '#/components/schemas/AssetCriticalityBulkUploadRequest'
-
+ type: object
+ example:
+ records:
+ - id_value: 'host-1'
+ id_field: 'host.name'
+ criticality_level: 'low_impact'
+ - id_value: 'host-2'
+ id_field: 'host.name'
+ criticality_level: 'medium_impact'
+ properties:
+ records:
+ type: array
+ minItems: 1
+ maxItems: 1000
+ items:
+ $ref: './common.schema.yaml#/components/schemas/CreateAssetCriticalityRecord'
+ required:
+ - records
responses:
'200':
description: Bulk upload successful
content:
application/json:
schema:
- $ref: './common.schema.yaml#/components/schemas/AssetCriticalityBulkUploadResponse'
+ type: object
+ example:
+ errors:
+ - message: 'Invalid ID field'
+ index: 0
+ stats:
+ successful: 1
+ failed: 1
+ total: 2
+ properties:
+ errors:
+ type: array
+ items:
+ $ref: '#/components/schemas/AssetCriticalityBulkUploadErrorItem'
+ stats:
+ $ref: '#/components/schemas/AssetCriticalityBulkUploadStats'
+ required:
+ - errors
+ - stats
'413':
description: File too large
+
components:
schemas:
- AssetCriticalityBulkUploadRequest:
+ AssetCriticalityBulkUploadErrorItem:
type: object
- example:
- records:
- - id_value: 'host-1'
- id_field: 'host.name'
- criticality_level: 'low_impact'
- - id_value: 'host-2'
- id_field: 'host.name'
- criticality_level: 'medium_impact'
properties:
- records:
- type: array
- minItems: 1
- maxItems: 1000
- items:
- $ref: './common.schema.yaml#/components/schemas/CreateAssetCriticalityRecord'
+ message:
+ type: string
+ index:
+ type: integer
required:
- - records
+ - message
+ - index
+
+ AssetCriticalityBulkUploadStats:
+ type: object
+ properties:
+ successful:
+ type: integer
+ failed:
+ type: integer
+ total:
+ type: integer
+ required:
+ - successful
+ - failed
+ - total
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/common.gen.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/common.gen.ts
index 4b689d22944e1..dfaa5d852c993 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/common.gen.ts
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/common.gen.ts
@@ -53,28 +53,6 @@ export const CreateAssetCriticalityRecord = AssetCriticalityRecordIdParts.merge(
})
);
-export type CreateSingleAssetCriticalityRequest = z.infer<
- typeof CreateSingleAssetCriticalityRequest
->;
-export const CreateSingleAssetCriticalityRequest = CreateAssetCriticalityRecord.merge(
- z.object({
- /**
- * If 'wait_for' the request will wait for the index refresh.
- */
- refresh: z.literal('wait_for').optional(),
- })
-);
-
-export type DeleteAssetCriticalityRecord = z.infer;
-export const DeleteAssetCriticalityRecord = AssetCriticalityRecordIdParts.merge(
- z.object({
- /**
- * If 'wait_for' the request will wait for the index refresh.
- */
- refresh: z.literal('wait_for').optional(),
- })
-);
-
export type AssetCriticalityRecord = z.infer;
export const AssetCriticalityRecord = CreateAssetCriticalityRecord.merge(
z.object({
@@ -84,24 +62,3 @@ export const AssetCriticalityRecord = CreateAssetCriticalityRecord.merge(
'@timestamp': z.string().datetime(),
})
);
-
-export type AssetCriticalityBulkUploadErrorItem = z.infer<
- typeof AssetCriticalityBulkUploadErrorItem
->;
-export const AssetCriticalityBulkUploadErrorItem = z.object({
- message: z.string(),
- index: z.number().int(),
-});
-
-export type AssetCriticalityBulkUploadStats = z.infer;
-export const AssetCriticalityBulkUploadStats = z.object({
- successful: z.number().int(),
- failed: z.number().int(),
- total: z.number().int(),
-});
-
-export type AssetCriticalityBulkUploadResponse = z.infer;
-export const AssetCriticalityBulkUploadResponse = z.object({
- errors: z.array(AssetCriticalityBulkUploadErrorItem),
- stats: AssetCriticalityBulkUploadStats,
-});
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/common.schema.yaml b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/common.schema.yaml
index 3218ec07e0fe2..8d3e05ab59bac 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/common.schema.yaml
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/common.schema.yaml
@@ -58,24 +58,6 @@ components:
$ref: '#/components/schemas/AssetCriticalityLevel'
required:
- criticality_level
- CreateSingleAssetCriticalityRequest:
- allOf:
- - $ref: '#/components/schemas/CreateAssetCriticalityRecord'
- - type: object
- properties:
- refresh:
- type: string
- enum: [wait_for]
- description: If 'wait_for' the request will wait for the index refresh.
- DeleteAssetCriticalityRecord:
- allOf:
- - $ref: '#/components/schemas/AssetCriticalityRecordIdParts'
- - type: object
- properties:
- refresh:
- type: string
- enum: [wait_for]
- description: If 'wait_for' the request will wait for the index refresh.
AssetCriticalityRecord:
allOf:
- $ref: '#/components/schemas/CreateAssetCriticalityRecord'
@@ -88,46 +70,3 @@ components:
description: The time the record was created or updated.
required:
- '@timestamp'
- AssetCriticalityBulkUploadErrorItem:
- type: object
- properties:
- message:
- type: string
- index:
- type: integer
- required:
- - message
- - index
- AssetCriticalityBulkUploadStats:
- type: object
- properties:
- successful:
- type: integer
- failed:
- type: integer
- total:
- type: integer
- required:
- - successful
- - failed
- - total
- AssetCriticalityBulkUploadResponse:
- type: object
- example:
- errors:
- - message: 'Invalid ID field'
- index: 0
- stats:
- successful: 1
- failed: 1
- total: 2
- properties:
- errors:
- type: array
- items:
- $ref: '#/components/schemas/AssetCriticalityBulkUploadErrorItem'
- stats:
- $ref: '#/components/schemas/AssetCriticalityBulkUploadStats'
- required:
- - errors
- - stats
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/create_asset_criticality.gen.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/create_asset_criticality.gen.ts
new file mode 100644
index 0000000000000..4836f4fe844dd
--- /dev/null
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/create_asset_criticality.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; 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: Asset Criticality Create Record Schema
+ * version: 1
+ */
+
+import { z } from 'zod';
+
+import { CreateAssetCriticalityRecord, AssetCriticalityRecord } from './common.gen';
+
+export type CreateAssetCriticalityRecordRequestBody = z.infer<
+ typeof CreateAssetCriticalityRecordRequestBody
+>;
+export const CreateAssetCriticalityRecordRequestBody = CreateAssetCriticalityRecord.merge(
+ z.object({
+ /**
+ * If 'wait_for' the request will wait for the index refresh.
+ */
+ refresh: z.literal('wait_for').optional(),
+ })
+);
+export type CreateAssetCriticalityRecordRequestBodyInput = z.input<
+ typeof CreateAssetCriticalityRecordRequestBody
+>;
+
+export type CreateAssetCriticalityRecordResponse = z.infer<
+ typeof CreateAssetCriticalityRecordResponse
+>;
+export const CreateAssetCriticalityRecordResponse = AssetCriticalityRecord;
+
+export type InternalCreateAssetCriticalityRecordRequestBody = z.infer<
+ typeof InternalCreateAssetCriticalityRecordRequestBody
+>;
+export const InternalCreateAssetCriticalityRecordRequestBody = CreateAssetCriticalityRecord.merge(
+ z.object({
+ /**
+ * If 'wait_for' the request will wait for the index refresh.
+ */
+ refresh: z.literal('wait_for').optional(),
+ })
+);
+export type InternalCreateAssetCriticalityRecordRequestBodyInput = z.input<
+ typeof InternalCreateAssetCriticalityRecordRequestBody
+>;
+
+export type InternalCreateAssetCriticalityRecordResponse = z.infer<
+ typeof InternalCreateAssetCriticalityRecordResponse
+>;
+export const InternalCreateAssetCriticalityRecordResponse = AssetCriticalityRecord;
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/create_asset_criticality.schema.yaml b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/create_asset_criticality.schema.yaml
index d59ce99c8717c..3d0bbf108d95f 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/create_asset_criticality.schema.yaml
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/create_asset_criticality.schema.yaml
@@ -14,14 +14,23 @@ paths:
post:
x-labels: [ess, serverless]
x-internal: true
- operationId: AssetCriticalityCreateRecord
+ x-codegen-enabled: true
+ operationId: InternalCreateAssetCriticalityRecord
summary: Deprecated Internal Create Criticality Record
+ deprecated: true
requestBody:
required: true
content:
application/json:
schema:
- $ref: './common.schema.yaml#/components/schemas/CreateSingleAssetCriticalityRequest'
+ allOf:
+ - $ref: './common.schema.yaml#/components/schemas/CreateAssetCriticalityRecord'
+ - type: object
+ properties:
+ refresh:
+ type: string
+ enum: [wait_for]
+ description: If 'wait_for' the request will wait for the index refresh.
responses:
'200':
description: Successful response
@@ -34,14 +43,22 @@ paths:
/api/asset_criticality:
post:
x-labels: [ess, serverless]
- operationId: AssetCriticalityCreateRecord
+ x-codegen-enabled: true
+ operationId: CreateAssetCriticalityRecord
summary: Create Criticality Record
requestBody:
required: true
content:
application/json:
schema:
- $ref: './common.schema.yaml#/components/schemas/CreateSingleAssetCriticalityRequest'
+ allOf:
+ - $ref: './common.schema.yaml#/components/schemas/CreateAssetCriticalityRecord'
+ - type: object
+ properties:
+ refresh:
+ type: string
+ enum: [wait_for]
+ description: If 'wait_for' the request will wait for the index refresh.
responses:
'200':
description: Successful response
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/delete_asset_criticality.gen.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/delete_asset_criticality.gen.ts
new file mode 100644
index 0000000000000..fe290a67c6634
--- /dev/null
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/delete_asset_criticality.gen.ts
@@ -0,0 +1,61 @@
+/*
+ * 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: Asset Criticality Delete Record Schema
+ * version: 1
+ */
+
+import { z } from 'zod';
+
+import { IdField } from './common.gen';
+
+export type DeleteAssetCriticalityRecordRequestQuery = z.infer<
+ typeof DeleteAssetCriticalityRecordRequestQuery
+>;
+export const DeleteAssetCriticalityRecordRequestQuery = z.object({
+ /**
+ * The ID value of the asset.
+ */
+ id_value: z.string(),
+ /**
+ * The field representing the ID.
+ */
+ id_field: IdField,
+ /**
+ * If 'wait_for' the request will wait for the index refresh.
+ */
+ refresh: z.literal('wait_for').optional(),
+});
+export type DeleteAssetCriticalityRecordRequestQueryInput = z.input<
+ typeof DeleteAssetCriticalityRecordRequestQuery
+>;
+
+export type InternalDeleteAssetCriticalityRecordRequestQuery = z.infer<
+ typeof InternalDeleteAssetCriticalityRecordRequestQuery
+>;
+export const InternalDeleteAssetCriticalityRecordRequestQuery = z.object({
+ /**
+ * The ID value of the asset.
+ */
+ id_value: z.string(),
+ /**
+ * The field representing the ID.
+ */
+ id_field: IdField,
+ /**
+ * If 'wait_for' the request will wait for the index refresh.
+ */
+ refresh: z.literal('wait_for').optional(),
+});
+export type InternalDeleteAssetCriticalityRecordRequestQueryInput = z.input<
+ typeof InternalDeleteAssetCriticalityRecordRequestQuery
+>;
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/delete_asset_criticality.schema.yaml b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/delete_asset_criticality.schema.yaml
index 94e1cc82e15ad..d66a2283596c0 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/delete_asset_criticality.schema.yaml
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/delete_asset_criticality.schema.yaml
@@ -14,11 +14,31 @@ paths:
delete:
x-labels: [ess, serverless]
x-internal: true
- operationId: AssetCriticalityDeleteRecord
+ x-codegen-enabled: true
+ operationId: InternalDeleteAssetCriticalityRecord
summary: Deprecated Internal Delete Criticality Record
+ deprecated: true
parameters:
- - $ref: './common.schema.yaml#/components/parameters/id_value'
- - $ref: './common.schema.yaml#/components/parameters/id_field'
+ - name: id_value
+ in: query
+ required: true
+ schema:
+ type: string
+ description: The ID value of the asset.
+ - name: id_field
+ in: query
+ required: true
+ schema:
+ $ref: './common.schema.yaml#/components/schemas/IdField'
+ example: 'host.name'
+ description: The field representing the ID.
+ - name: refresh
+ in: query
+ required: false
+ schema:
+ type: string
+ enum: [wait_for]
+ description: If 'wait_for' the request will wait for the index refresh.
responses:
'200':
description: Successful response
@@ -27,11 +47,30 @@ paths:
/api/asset_criticality:
delete:
x-labels: [ess, serverless]
- operationId: AssetCriticalityDeleteRecord
+ x-codegen-enabled: true
+ operationId: DeleteAssetCriticalityRecord
summary: Delete Criticality Record
parameters:
- - $ref: './common.schema.yaml#/components/parameters/id_value'
- - $ref: './common.schema.yaml#/components/parameters/id_field'
+ - name: id_value
+ in: query
+ required: true
+ schema:
+ type: string
+ description: The ID value of the asset.
+ - name: id_field
+ in: query
+ required: true
+ schema:
+ $ref: './common.schema.yaml#/components/schemas/IdField'
+ example: 'host.name'
+ description: The field representing the ID.
+ - name: refresh
+ in: query
+ required: false
+ schema:
+ type: string
+ enum: [wait_for]
+ description: If 'wait_for' the request will wait for the index refresh.
responses:
'200':
description: Successful response
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/get_asset_criticality.gen.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/get_asset_criticality.gen.ts
new file mode 100644
index 0000000000000..7437960ef9cae
--- /dev/null
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/get_asset_criticality.gen.ts
@@ -0,0 +1,39 @@
+/*
+ * 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: Asset Criticality Get Record Schema
+ * version: 1
+ */
+
+import { z } from 'zod';
+
+import { IdField, AssetCriticalityRecord } from './common.gen';
+
+export type GetAssetCriticalityRecordRequestQuery = z.infer<
+ typeof GetAssetCriticalityRecordRequestQuery
+>;
+export const GetAssetCriticalityRecordRequestQuery = z.object({
+ /**
+ * The ID value of the asset.
+ */
+ id_value: z.string(),
+ /**
+ * The field representing the ID.
+ */
+ id_field: IdField,
+});
+export type GetAssetCriticalityRecordRequestQueryInput = z.input<
+ typeof GetAssetCriticalityRecordRequestQuery
+>;
+
+export type GetAssetCriticalityRecordResponse = z.infer;
+export const GetAssetCriticalityRecordResponse = AssetCriticalityRecord;
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/get_asset_criticality.schema.yaml b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/get_asset_criticality.schema.yaml
index 56f3e37de1126..ca2784c48653d 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/get_asset_criticality.schema.yaml
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/get_asset_criticality.schema.yaml
@@ -14,11 +14,23 @@ paths:
get:
x-labels: [ess, serverless]
x-internal: true
- operationId: AssetCriticalityGetRecord
+ operationId: InternalGetAssetCriticalityRecord
summary: Deprecated Internal Get Criticality Record
+ deprecated: true
parameters:
- - $ref: './common.schema.yaml#/components/parameters/id_value'
- - $ref: './common.schema.yaml#/components/parameters/id_field'
+ - name: id_value
+ in: query
+ required: true
+ schema:
+ type: string
+ description: The ID value of the asset.
+ - name: id_field
+ in: query
+ required: true
+ schema:
+ $ref: './common.schema.yaml#/components/schemas/IdField'
+ example: 'host.name'
+ description: The field representing the ID.
responses:
'200':
description: Successful response
@@ -33,11 +45,23 @@ paths:
/api/asset_criticality:
get:
x-labels: [ess, serverless]
- operationId: AssetCriticalityGetRecord
+ x-codegen-enabled: true
+ operationId: GetAssetCriticalityRecord
summary: Get Criticality Record
parameters:
- - $ref: './common.schema.yaml#/components/parameters/id_value'
- - $ref: './common.schema.yaml#/components/parameters/id_field'
+ - name: id_value
+ in: query
+ required: true
+ schema:
+ type: string
+ description: The ID value of the asset.
+ - name: id_field
+ in: query
+ required: true
+ schema:
+ $ref: './common.schema.yaml#/components/schemas/IdField'
+ example: 'host.name'
+ description: The field representing the ID.
responses:
'200':
description: Successful response
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/get_asset_criticality_status.gen.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/get_asset_criticality_status.gen.ts
index bb51693825def..f9d24b61bbef0 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/get_asset_criticality_status.gen.ts
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/get_asset_criticality_status.gen.ts
@@ -16,7 +16,7 @@
import { z } from 'zod';
-export type AssetCriticalityStatusResponse = z.infer;
-export const AssetCriticalityStatusResponse = z.object({
+export type GetAssetCriticalityStatusResponse = z.infer;
+export const GetAssetCriticalityStatusResponse = z.object({
asset_criticality_resources_installed: z.boolean().optional(),
});
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/get_asset_criticality_status.schema.yaml b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/get_asset_criticality_status.schema.yaml
index 4052ad8f07177..f8f5dcb7c8ecd 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/get_asset_criticality_status.schema.yaml
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/get_asset_criticality_status.schema.yaml
@@ -14,7 +14,8 @@ paths:
get:
x-labels: [ess, serverless]
x-internal: true
- operationId: AssetCriticalityGetStatus
+ x-codegen-enabled: true
+ operationId: GetAssetCriticalityStatus
summary: Get Asset Criticality Status
responses:
'200':
@@ -22,14 +23,9 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/AssetCriticalityStatusResponse'
+ type: object
+ properties:
+ asset_criticality_resources_installed:
+ type: boolean
'400':
description: Invalid request
-
-components:
- schemas:
- AssetCriticalityStatusResponse:
- type: object
- properties:
- asset_criticality_resources_installed:
- type: boolean
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/index.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/index.ts
index 326a20d6c66a7..fb99a69f49f92 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/index.ts
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/index.ts
@@ -9,5 +9,5 @@ export * from './common.gen';
export * from './get_asset_criticality_status.gen';
export * from './get_asset_criticality_privileges.gen';
export * from './bulk_upload_asset_criticality.gen';
+export * from './upload_asset_criticality_csv.gen';
export * from './list_asset_criticality.gen';
-export * from './list_asset_criticality_query_params';
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/list_asset_criticality.gen.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/list_asset_criticality.gen.ts
index 9cf2f7ca7c628..e17a2b006896c 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/list_asset_criticality.gen.ts
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/list_asset_criticality.gen.ts
@@ -18,8 +18,39 @@ import { z } from 'zod';
import { AssetCriticalityRecord } from './common.gen';
-export type AssetCriticalityListResponse = z.infer;
-export const AssetCriticalityListResponse = z.object({
+export type FindAssetCriticalityRecordsRequestQuery = z.infer<
+ typeof FindAssetCriticalityRecordsRequestQuery
+>;
+export const FindAssetCriticalityRecordsRequestQuery = z.object({
+ /**
+ * The field to sort by.
+ */
+ sort_field: z.enum(['id_value', 'id_field', 'criticality_level', '@timestamp']).optional(),
+ /**
+ * The order to sort by.
+ */
+ sort_direction: z.enum(['asc', 'desc']).optional(),
+ /**
+ * The page number to return.
+ */
+ page: z.coerce.number().int().min(1).optional(),
+ /**
+ * The number of records to return per page.
+ */
+ per_page: z.coerce.number().int().min(1).max(1000).optional(),
+ /**
+ * The kuery to filter by.
+ */
+ kuery: z.string().optional(),
+});
+export type FindAssetCriticalityRecordsRequestQueryInput = z.input<
+ typeof FindAssetCriticalityRecordsRequestQuery
+>;
+
+export type FindAssetCriticalityRecordsResponse = z.infer<
+ typeof FindAssetCriticalityRecordsResponse
+>;
+export const FindAssetCriticalityRecordsResponse = z.object({
records: z.array(AssetCriticalityRecord),
page: z.number().int().min(1),
per_page: z.number().int().min(1).max(1000),
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/list_asset_criticality.schema.yaml b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/list_asset_criticality.schema.yaml
index 7c9a28c4eeaaf..34c5b98a4617f 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/list_asset_criticality.schema.yaml
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/list_asset_criticality.schema.yaml
@@ -13,6 +13,8 @@ paths:
/api/asset_criticality/list:
post:
x-labels: [ess, serverless]
+ x-codegen-enabled: true
+ operationId: FindAssetCriticalityRecords
summary: List asset criticality data, filtering and sorting as needed
parameters:
- name: sort_field
@@ -26,7 +28,7 @@ paths:
- criticality_level
- \@timestamp
description: The field to sort by.
- - name: sort_order
+ - name: sort_direction
in: query
required: false
schema:
@@ -62,31 +64,24 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/AssetCriticalityListResponse'
-
-components:
- schemas:
- AssetCriticalityListResponse:
- type: object
- properties:
- records:
- type: array
- items:
- $ref: './common.schema.yaml#/components/schemas/AssetCriticalityRecord'
- page:
- type: integer
- minimum: 1
- per_page:
- type: integer
- minimum: 1
- maximum: 1000
- total:
- type: integer
- minimum: 0
- required:
- - records
- - page
- - per_page
- - total
-
-
\ No newline at end of file
+ type: object
+ properties:
+ records:
+ type: array
+ items:
+ $ref: './common.schema.yaml#/components/schemas/AssetCriticalityRecord'
+ page:
+ type: integer
+ minimum: 1
+ per_page:
+ type: integer
+ minimum: 1
+ maximum: 1000
+ total:
+ type: integer
+ minimum: 0
+ required:
+ - records
+ - page
+ - per_page
+ - total
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/list_asset_criticality_query_params.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/list_asset_criticality_query_params.ts
deleted file mode 100644
index b70393056c48f..0000000000000
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/list_asset_criticality_query_params.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 { z } from 'zod';
-
-export const ListAssetCriticalityQueryParams = z.object({
- page: z.coerce.number().min(1).optional(),
- per_page: z.coerce.number().min(1).max(10000).optional(),
- sort_field: z.enum(['id_field', 'id_value', '@timestamp', 'criticality_level']).optional(),
- sort_direction: z.enum(['asc', 'desc']).optional(),
- kuery: z.string().optional(),
-});
-
-export type ListAssetCriticalityQueryParams = z.infer;
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/upload_asset_criticality_csv.gen.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/upload_asset_criticality_csv.gen.ts
new file mode 100644
index 0000000000000..4282056378426
--- /dev/null
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/upload_asset_criticality_csv.gen.ts
@@ -0,0 +1,46 @@
+/*
+ * 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: Asset Criticality CSV Upload Schema
+ * version: 1
+ */
+
+import { z } from 'zod';
+
+export type AssetCriticalityCsvUploadErrorItem = z.infer;
+export const AssetCriticalityCsvUploadErrorItem = z.object({
+ message: z.string(),
+ index: z.number().int(),
+});
+
+export type AssetCriticalityCsvUploadStats = z.infer;
+export const AssetCriticalityCsvUploadStats = z.object({
+ successful: z.number().int(),
+ failed: z.number().int(),
+ total: z.number().int(),
+});
+
+export type InternalUploadAssetCriticalityRecordsResponse = z.infer<
+ typeof InternalUploadAssetCriticalityRecordsResponse
+>;
+export const InternalUploadAssetCriticalityRecordsResponse = z.object({
+ errors: z.array(AssetCriticalityCsvUploadErrorItem),
+ stats: AssetCriticalityCsvUploadStats,
+});
+
+export type UploadAssetCriticalityRecordsResponse = z.infer<
+ typeof UploadAssetCriticalityRecordsResponse
+>;
+export const UploadAssetCriticalityRecordsResponse = z.object({
+ errors: z.array(AssetCriticalityCsvUploadErrorItem),
+ stats: AssetCriticalityCsvUploadStats,
+});
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/upload_asset_criticality_csv.schema.yaml b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/upload_asset_criticality_csv.schema.yaml
index c348dcefa8b78..77e78f5c6d4d3 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/upload_asset_criticality_csv.schema.yaml
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/asset_criticality/upload_asset_criticality_csv.schema.yaml
@@ -14,7 +14,10 @@ paths:
post:
x-labels: [ess, serverless]
x-internal: true
+ x-codegen-enabled: true
+ operationId: InternalUploadAssetCriticalityRecords
summary: Deprecated internal API which Uploads a CSV file containing asset criticality data
+ deprecated: true
requestBody:
content:
multipart/form-data:
@@ -33,13 +36,33 @@ paths:
content:
application/json:
schema:
- $ref: '#./common/components/schemas/AssetCriticalityBulkUploadResponse'
+ type: object
+ example:
+ errors:
+ - message: 'Invalid ID field'
+ index: 0
+ stats:
+ successful: 1
+ failed: 1
+ total: 2
+ properties:
+ errors:
+ type: array
+ items:
+ $ref: '#/components/schemas/AssetCriticalityCsvUploadErrorItem'
+ stats:
+ $ref: '#/components/schemas/AssetCriticalityCsvUploadStats'
+ required:
+ - errors
+ - stats
'413':
description: File too large
/api/asset_criticality/upload_csv:
post:
x-labels: [ess, serverless]
x-internal: true
+ x-codegen-enabled: true
+ operationId: UploadAssetCriticalityRecords
summary: Uploads a CSV file containing asset criticality data
requestBody:
content:
@@ -59,6 +82,51 @@ paths:
content:
application/json:
schema:
- $ref: '#./common/components/schemas/AssetCriticalityBulkUploadResponse'
+ type: object
+ example:
+ errors:
+ - message: 'Invalid ID field'
+ index: 0
+ stats:
+ successful: 1
+ failed: 1
+ total: 2
+ properties:
+ errors:
+ type: array
+ items:
+ $ref: '#/components/schemas/AssetCriticalityCsvUploadErrorItem'
+ stats:
+ $ref: '#/components/schemas/AssetCriticalityCsvUploadStats'
+ required:
+ - errors
+ - stats
'413':
description: File too large
+
+components:
+ schemas:
+ AssetCriticalityCsvUploadErrorItem:
+ type: object
+ properties:
+ message:
+ type: string
+ index:
+ type: integer
+ required:
+ - message
+ - index
+
+ AssetCriticalityCsvUploadStats:
+ type: object
+ properties:
+ successful:
+ type: integer
+ failed:
+ type: integer
+ total:
+ type: integer
+ required:
+ - successful
+ - failed
+ - total
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_disable_route.gen.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_disable_route.gen.ts
index 620620c95b888..b50eb00db6301 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_disable_route.gen.ts
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_disable_route.gen.ts
@@ -16,13 +16,13 @@
import { z } from 'zod';
-export type RiskEngineDisableResponse = z.infer;
-export const RiskEngineDisableResponse = z.object({
- success: z.boolean().optional(),
-});
-
export type RiskEngineDisableErrorResponse = z.infer;
export const RiskEngineDisableErrorResponse = z.object({
message: z.string(),
full_error: z.string(),
});
+
+export type DisableRiskEngineResponse = z.infer;
+export const DisableRiskEngineResponse = z.object({
+ success: z.boolean().optional(),
+});
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_disable_route.schema.yaml b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_disable_route.schema.yaml
index 33f35aa1bef1b..c491ec74e2a50 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_disable_route.schema.yaml
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_disable_route.schema.yaml
@@ -18,6 +18,8 @@ paths:
post:
x-labels: [ess, serverless]
x-internal: true
+ x-codegen-enabled: true
+ operationId: DisableRiskEngine
summary: Disable the Risk Engine
requestBody:
content:
@@ -28,7 +30,10 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/RiskEngineDisableResponse'
+ type: object
+ properties:
+ success:
+ type: boolean
'400':
description: Task manager is unavailable
content:
@@ -44,11 +49,6 @@ paths:
components:
schemas:
- RiskEngineDisableResponse:
- type: object
- properties:
- success:
- type: boolean
RiskEngineDisableErrorResponse:
type: object
required:
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_enable_route.gen.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_enable_route.gen.ts
index cee1121b778ae..7bdbfd17449db 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_enable_route.gen.ts
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_enable_route.gen.ts
@@ -16,13 +16,13 @@
import { z } from 'zod';
-export type RiskEngineEnableResponse = z.infer;
-export const RiskEngineEnableResponse = z.object({
- success: z.boolean().optional(),
-});
-
-export type RiskEngineEnableErrorResponse = z.infer;
-export const RiskEngineEnableErrorResponse = z.object({
+export type EnableRiskEngineErrorResponse = z.infer;
+export const EnableRiskEngineErrorResponse = z.object({
message: z.string(),
full_error: z.string(),
});
+
+export type EnableRiskEngineResponse = z.infer;
+export const EnableRiskEngineResponse = z.object({
+ success: z.boolean().optional(),
+});
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_enable_route.schema.yaml b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_enable_route.schema.yaml
index 5cfd5ffdd4fdf..6b2656bbb21b0 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_enable_route.schema.yaml
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_enable_route.schema.yaml
@@ -18,6 +18,8 @@ paths:
post:
x-labels: [ess, serverless]
x-internal: true
+ x-codegen-enabled: true
+ operationId: EnableRiskEngine
summary: Enable the Risk Engine
requestBody:
content:
@@ -28,7 +30,10 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/RiskEngineEnableResponse'
+ type: object
+ properties:
+ success:
+ type: boolean
'400':
description: Task manager is unavailable
content:
@@ -40,16 +45,11 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/RiskEngineEnableErrorResponse'
+ $ref: '#/components/schemas/EnableRiskEngineErrorResponse'
components:
schemas:
- RiskEngineEnableResponse:
- type: object
- properties:
- success:
- type: boolean
- RiskEngineEnableErrorResponse:
+ EnableRiskEngineErrorResponse:
type: object
required:
- message
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_init_route.gen.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_init_route.gen.ts
index d973a435b9aec..f9d79cd8f96a6 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_init_route.gen.ts
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_init_route.gen.ts
@@ -16,8 +16,8 @@
import { z } from 'zod';
-export type RiskEngineInitResult = z.infer;
-export const RiskEngineInitResult = z.object({
+export type InitRiskEngineResult = z.infer;
+export const InitRiskEngineResult = z.object({
risk_engine_enabled: z.boolean(),
risk_engine_resources_installed: z.boolean(),
risk_engine_configuration_created: z.boolean(),
@@ -25,13 +25,13 @@ export const RiskEngineInitResult = z.object({
errors: z.array(z.string()),
});
-export type RiskEngineInitResponse = z.infer;
-export const RiskEngineInitResponse = z.object({
- result: RiskEngineInitResult,
-});
-
-export type RiskEngineInitErrorResponse = z.infer;
-export const RiskEngineInitErrorResponse = z.object({
+export type InitRiskEngineErrorResponse = z.infer;
+export const InitRiskEngineErrorResponse = z.object({
message: z.string(),
full_error: z.string(),
});
+
+export type InitRiskEngineResponse = z.infer;
+export const InitRiskEngineResponse = z.object({
+ result: InitRiskEngineResult,
+});
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_init_route.schema.yaml b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_init_route.schema.yaml
index 498ac266a9aa0..d1d35f4a720c6 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_init_route.schema.yaml
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_init_route.schema.yaml
@@ -16,6 +16,8 @@ paths:
post:
x-labels: [ess, serverless]
x-internal: true
+ x-codegen-enabled: true
+ operationId: InitRiskEngine
summary: Initialize the Risk Engine
description: Initializes the Risk Engine by creating the necessary indices and mappings, removing old transforms, and starting the new risk engine
responses:
@@ -24,7 +26,12 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/RiskEngineInitResponse'
+ type: object
+ required:
+ - result
+ properties:
+ result:
+ $ref: '#/components/schemas/InitRiskEngineResult'
'400':
description: Task manager is unavailable
content:
@@ -36,11 +43,11 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/RiskEngineInitErrorResponse'
+ $ref: '#/components/schemas/InitRiskEngineErrorResponse'
components:
schemas:
- RiskEngineInitResult:
+ InitRiskEngineResult:
type: object
required:
- risk_engine_enabled
@@ -62,15 +69,7 @@ components:
items:
type: string
- RiskEngineInitResponse:
- type: object
- required:
- - result
- properties:
- result:
- $ref: '#/components/schemas/RiskEngineInitResult'
-
- RiskEngineInitErrorResponse:
+ InitRiskEngineErrorResponse:
type: object
required:
- message
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_settings_route.gen.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_settings_route.gen.ts
index c8d10bd87d75e..e01edb31397a6 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_settings_route.gen.ts
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_settings_route.gen.ts
@@ -18,7 +18,7 @@ import { z } from 'zod';
import { DateRange } from '../common/common.gen';
-export type RiskEngineSettingsResponse = z.infer;
-export const RiskEngineSettingsResponse = z.object({
+export type ReadRiskEngineSettingsResponse = z.infer;
+export const ReadRiskEngineSettingsResponse = z.object({
range: DateRange.optional(),
});
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_settings_route.schema.yaml b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_settings_route.schema.yaml
index 3622a9ff7c62b..a5cc6d6b44008 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_settings_route.schema.yaml
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_settings_route.schema.yaml
@@ -16,7 +16,8 @@ paths:
get:
x-labels: [ess, serverless]
x-internal: true
- operationId: RiskEngineSettingsGet
+ x-codegen-enabled: true
+ operationId: ReadRiskEngineSettings
summary: Get the settings of the Risk Engine
responses:
'200':
@@ -24,12 +25,7 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/RiskEngineSettingsResponse'
-
-components:
- schemas:
- RiskEngineSettingsResponse:
- type: object
- properties:
- range:
- $ref: '../common/common.schema.yaml#/components/schemas/DateRange'
+ type: object
+ properties:
+ range:
+ $ref: '../common/common.schema.yaml#/components/schemas/DateRange'
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_status_route.gen.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_status_route.gen.ts
index 6a6e15d9c71a3..0d3fd0b9f0dd4 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_status_route.gen.ts
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_status_route.gen.ts
@@ -30,3 +30,6 @@ export const RiskEngineStatusResponse = z.object({
*/
is_max_amount_of_risk_engines_reached: z.boolean(),
});
+
+export type GetRiskEngineStatusResponse = z.infer;
+export const GetRiskEngineStatusResponse = RiskEngineStatusResponse;
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_status_route.schema.yaml b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_status_route.schema.yaml
index 3f1cc33e94288..57f46b99f3a77 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_status_route.schema.yaml
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/engine_status_route.schema.yaml
@@ -16,6 +16,8 @@ paths:
get:
x-labels: [ess, serverless]
x-internal: true
+ x-codegen-enabled: true
+ operationId: GetRiskEngineStatus
summary: Get the status of the Risk Engine
description: Returns the status of both the legacy transform-based risk engine, as well as the new risk engine
responses:
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/entity_calculation_route.gen.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/entity_calculation_route.gen.ts
index c9b6c8cc47aa3..ebefbd772ed96 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/entity_calculation_route.gen.ts
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/entity_calculation_route.gen.ts
@@ -41,3 +41,29 @@ export const RiskScoresEntityCalculationResponse = z.object({
success: z.boolean(),
score: EntityRiskScoreRecord.optional(),
});
+
+export type DeprecatedTriggerRiskScoreCalculationRequestBody = z.infer<
+ typeof DeprecatedTriggerRiskScoreCalculationRequestBody
+>;
+export const DeprecatedTriggerRiskScoreCalculationRequestBody = RiskScoresEntityCalculationRequest;
+export type DeprecatedTriggerRiskScoreCalculationRequestBodyInput = z.input<
+ typeof DeprecatedTriggerRiskScoreCalculationRequestBody
+>;
+
+export type DeprecatedTriggerRiskScoreCalculationResponse = z.infer<
+ typeof DeprecatedTriggerRiskScoreCalculationResponse
+>;
+export const DeprecatedTriggerRiskScoreCalculationResponse = RiskScoresEntityCalculationResponse;
+
+export type TriggerRiskScoreCalculationRequestBody = z.infer<
+ typeof TriggerRiskScoreCalculationRequestBody
+>;
+export const TriggerRiskScoreCalculationRequestBody = RiskScoresEntityCalculationRequest;
+export type TriggerRiskScoreCalculationRequestBodyInput = z.input<
+ typeof TriggerRiskScoreCalculationRequestBody
+>;
+
+export type TriggerRiskScoreCalculationResponse = z.infer<
+ typeof TriggerRiskScoreCalculationResponse
+>;
+export const TriggerRiskScoreCalculationResponse = RiskScoresEntityCalculationResponse;
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/entity_calculation_route.schema.yaml b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/entity_calculation_route.schema.yaml
index bb94305254885..69be93f7ceb49 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/entity_calculation_route.schema.yaml
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/entity_calculation_route.schema.yaml
@@ -19,8 +19,11 @@ paths:
post:
x-labels: [ess, serverless]
x-internal: true
+ x-codegen-enabled: true
+ operationId: DeprecatedTriggerRiskScoreCalculation
summary: Deprecated Trigger calculation of Risk Scores for an entity. Moved to /internal/risk_score/calculation/entity
description: Calculates and persists Risk Scores for an entity, returning the calculated risk score.
+ deprecated: true
requestBody:
description: The entity type and identifier
content:
@@ -41,6 +44,8 @@ paths:
/internal/risk_score/calculation/entity:
post:
x-labels: [ess, serverless]
+ x-codegen-enabled: true
+ operationId: TriggerRiskScoreCalculation
summary: Trigger calculation of Risk Scores for an entity
description: Calculates and persists Risk Scores for an entity, returning the calculated risk score.
requestBody:
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/preview_route.gen.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/preview_route.gen.ts
index fe0b90e5a2e7a..13515d239c81c 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/preview_route.gen.ts
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/preview_route.gen.ts
@@ -83,3 +83,10 @@ export const RiskScoresPreviewResponse = z.object({
user: z.array(EntityRiskScoreRecord).optional(),
}),
});
+
+export type PreviewRiskScoreRequestBody = z.infer;
+export const PreviewRiskScoreRequestBody = RiskScoresPreviewRequest;
+export type PreviewRiskScoreRequestBodyInput = z.input;
+
+export type PreviewRiskScoreResponse = z.infer;
+export const PreviewRiskScoreResponse = RiskScoresPreviewResponse;
diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/preview_route.schema.yaml b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/preview_route.schema.yaml
index a2ce9bcafd697..424ca98436768 100644
--- a/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/preview_route.schema.yaml
+++ b/x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/preview_route.schema.yaml
@@ -16,6 +16,8 @@ paths:
post:
x-labels: [ess, serverless]
x-internal: true
+ x-codegen-enabled: true
+ operationId: PreviewRiskScore
summary: Preview the calculation of Risk Scores
description: Calculates and returns a list of Risk Scores, sorted by identifier_type and risk score.
requestBody:
diff --git a/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_detections_api_2023_10_31.bundled.schema.yaml b/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_detections_api_2023_10_31.bundled.schema.yaml
index 6cb21c69c0492..4fd2ec1aed3b6 100644
--- a/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_detections_api_2023_10_31.bundled.schema.yaml
+++ b/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_detections_api_2023_10_31.bundled.schema.yaml
@@ -91,6 +91,7 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/SiemErrorResponse'
+ description: Not found
'500':
content:
application/json:
@@ -131,6 +132,7 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/SiemErrorResponse'
+ description: Not found
'500':
content:
application/json:
diff --git a/x-pack/plugins/security_solution/public/entity_analytics/api/api.ts b/x-pack/plugins/security_solution/public/entity_analytics/api/api.ts
index aa3b432533027..500c327d86b0c 100644
--- a/x-pack/plugins/security_solution/public/entity_analytics/api/api.ts
+++ b/x-pack/plugins/security_solution/public/entity_analytics/api/api.ts
@@ -6,10 +6,11 @@
*/
import { useMemo } from 'react';
-import type { RiskEngineDisableResponse } from '../../../common/api/entity_analytics/risk_engine/engine_disable_route.gen';
+import type { UploadAssetCriticalityRecordsResponse } from '../../../common/api/entity_analytics/asset_criticality/upload_asset_criticality_csv.gen';
+import type { DisableRiskEngineResponse } from '../../../common/api/entity_analytics/risk_engine/engine_disable_route.gen';
import type { RiskEngineStatusResponse } from '../../../common/api/entity_analytics/risk_engine/engine_status_route.gen';
-import type { RiskEngineInitResponse } from '../../../common/api/entity_analytics/risk_engine/engine_init_route.gen';
-import type { RiskEngineEnableResponse } from '../../../common/api/entity_analytics/risk_engine/engine_enable_route.gen';
+import type { InitRiskEngineResponse } from '../../../common/api/entity_analytics/risk_engine/engine_init_route.gen';
+import type { EnableRiskEngineResponse } from '../../../common/api/entity_analytics/risk_engine/engine_enable_route.gen';
import type {
RiskScoresPreviewRequest,
RiskScoresPreviewResponse,
@@ -18,7 +19,6 @@ import type {
RiskScoresEntityCalculationRequest,
RiskScoresEntityCalculationResponse,
} from '../../../common/api/entity_analytics/risk_engine/entity_calculation_route.gen';
-import type { AssetCriticalityBulkUploadResponse } from '../../../common/entity_analytics/asset_criticality/types';
import type {
AssetCriticalityRecord,
EntityAnalyticsPrivileges,
@@ -39,9 +39,9 @@ import {
RISK_SCORE_ENTITY_CALCULATION_URL,
API_VERSIONS,
} from '../../../common/constants';
-import type { RiskEngineSettingsResponse } from '../../../common/api/entity_analytics/risk_engine';
import type { SnakeToCamelCase } from '../common/utils';
import { useKibana } from '../../common/lib/kibana/kibana_react';
+import type { ReadRiskEngineSettingsResponse } from '../../../common/api/entity_analytics/risk_engine';
export interface DeleteAssetCriticalityResponse {
deleted: true;
@@ -81,7 +81,7 @@ export const useEntityAnalyticsRoutes = () => {
* Init risk score engine
*/
const initRiskEngine = () =>
- http.fetch(RISK_ENGINE_INIT_URL, {
+ http.fetch(RISK_ENGINE_INIT_URL, {
version: '1',
method: 'POST',
});
@@ -90,7 +90,7 @@ export const useEntityAnalyticsRoutes = () => {
* Enable risk score engine
*/
const enableRiskEngine = () =>
- http.fetch(RISK_ENGINE_ENABLE_URL, {
+ http.fetch(RISK_ENGINE_ENABLE_URL, {
version: '1',
method: 'POST',
});
@@ -99,7 +99,7 @@ export const useEntityAnalyticsRoutes = () => {
* Disable risk score engine
*/
const disableRiskEngine = () =>
- http.fetch(RISK_ENGINE_DISABLE_URL, {
+ http.fetch(RISK_ENGINE_DISABLE_URL, {
version: '1',
method: 'POST',
});
@@ -181,12 +181,12 @@ export const useEntityAnalyticsRoutes = () => {
const uploadAssetCriticalityFile = async (
fileContent: string,
fileName: string
- ): Promise => {
+ ): Promise => {
const file = new File([new Blob([fileContent])], fileName, { type: 'text/csv' });
const body = new FormData();
body.append('file', file);
- return http.fetch(
+ return http.fetch(
ASSET_CRITICALITY_PUBLIC_CSV_UPLOAD_URL,
{
version: API_VERSIONS.public.v1,
@@ -224,7 +224,7 @@ export const useEntityAnalyticsRoutes = () => {
* Fetches risk engine settings
*/
const fetchRiskEngineSettings = () =>
- http.fetch(RISK_ENGINE_SETTINGS_URL, {
+ http.fetch(RISK_ENGINE_SETTINGS_URL, {
version: '1',
method: 'GET',
});
diff --git a/x-pack/plugins/security_solution/public/entity_analytics/api/hooks/use_disable_risk_engine_mutation.ts b/x-pack/plugins/security_solution/public/entity_analytics/api/hooks/use_disable_risk_engine_mutation.ts
index e19cf94fc379f..fb8a0bbb12972 100644
--- a/x-pack/plugins/security_solution/public/entity_analytics/api/hooks/use_disable_risk_engine_mutation.ts
+++ b/x-pack/plugins/security_solution/public/entity_analytics/api/hooks/use_disable_risk_engine_mutation.ts
@@ -9,7 +9,7 @@ import { useMutation } from '@tanstack/react-query';
import type { TaskManagerUnavailableResponse } from '../../../../common/api/entity_analytics/common';
import type {
RiskEngineDisableErrorResponse,
- RiskEngineDisableResponse,
+ DisableRiskEngineResponse,
} from '../../../../common/api/entity_analytics/risk_engine/engine_disable_route.gen';
import { useEntityAnalyticsRoutes } from '../api';
import { useInvalidateRiskEngineStatusQuery } from './use_risk_engine_status';
@@ -21,7 +21,7 @@ export const useDisableRiskEngineMutation = (options?: UseMutationOptions<{}>) =
const { disableRiskEngine } = useEntityAnalyticsRoutes();
return useMutation<
- RiskEngineDisableResponse,
+ DisableRiskEngineResponse,
{ body: RiskEngineDisableErrorResponse | TaskManagerUnavailableResponse }
>(() => disableRiskEngine(), {
...options,
diff --git a/x-pack/plugins/security_solution/public/entity_analytics/api/hooks/use_enable_risk_engine_mutation.ts b/x-pack/plugins/security_solution/public/entity_analytics/api/hooks/use_enable_risk_engine_mutation.ts
index 658c4a5cdb185..cd5083d13892e 100644
--- a/x-pack/plugins/security_solution/public/entity_analytics/api/hooks/use_enable_risk_engine_mutation.ts
+++ b/x-pack/plugins/security_solution/public/entity_analytics/api/hooks/use_enable_risk_engine_mutation.ts
@@ -8,8 +8,8 @@ import type { UseMutationOptions } from '@tanstack/react-query';
import { useMutation } from '@tanstack/react-query';
import type { TaskManagerUnavailableResponse } from '../../../../common/api/entity_analytics/common';
import type {
- RiskEngineEnableErrorResponse,
- RiskEngineEnableResponse,
+ EnableRiskEngineErrorResponse,
+ EnableRiskEngineResponse,
} from '../../../../common/api/entity_analytics/risk_engine/engine_enable_route.gen';
import { useEntityAnalyticsRoutes } from '../api';
import { useInvalidateRiskEngineStatusQuery } from './use_risk_engine_status';
@@ -19,8 +19,8 @@ export const useEnableRiskEngineMutation = (options?: UseMutationOptions<{}>) =>
const invalidateRiskEngineStatusQuery = useInvalidateRiskEngineStatusQuery();
const { enableRiskEngine } = useEntityAnalyticsRoutes();
return useMutation<
- RiskEngineEnableResponse,
- { body: RiskEngineEnableErrorResponse | TaskManagerUnavailableResponse }
+ EnableRiskEngineResponse,
+ { body: EnableRiskEngineErrorResponse | TaskManagerUnavailableResponse }
>(enableRiskEngine, {
...options,
mutationKey: ENABLE_RISK_ENGINE_MUTATION_KEY,
diff --git a/x-pack/plugins/security_solution/public/entity_analytics/api/hooks/use_init_risk_engine_mutation.ts b/x-pack/plugins/security_solution/public/entity_analytics/api/hooks/use_init_risk_engine_mutation.ts
index 67d94257e9165..d774853c7d026 100644
--- a/x-pack/plugins/security_solution/public/entity_analytics/api/hooks/use_init_risk_engine_mutation.ts
+++ b/x-pack/plugins/security_solution/public/entity_analytics/api/hooks/use_init_risk_engine_mutation.ts
@@ -6,11 +6,11 @@
*/
import type { UseMutationOptions } from '@tanstack/react-query';
import { useMutation } from '@tanstack/react-query';
-import type { TaskManagerUnavailableResponse } from '../../../../common/api/entity_analytics/common';
import type {
- RiskEngineInitErrorResponse,
- RiskEngineInitResponse,
+ InitRiskEngineErrorResponse,
+ InitRiskEngineResponse,
} from '../../../../common/api/entity_analytics/risk_engine/engine_init_route.gen';
+import type { TaskManagerUnavailableResponse } from '../../../../common/api/entity_analytics/common';
import { useEntityAnalyticsRoutes } from '../api';
import { useInvalidateRiskEngineStatusQuery } from './use_risk_engine_status';
@@ -21,8 +21,8 @@ export const useInitRiskEngineMutation = (options?: UseMutationOptions<{}>) => {
const { initRiskEngine } = useEntityAnalyticsRoutes();
return useMutation<
- RiskEngineInitResponse,
- { body: RiskEngineInitErrorResponse | TaskManagerUnavailableResponse }
+ InitRiskEngineResponse,
+ { body: InitRiskEngineErrorResponse | TaskManagerUnavailableResponse }
>(() => initRiskEngine(), {
...options,
mutationKey: INIT_RISK_ENGINE_STATUS_KEY,
diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/components/result_step.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/components/result_step.tsx
index 1652c85eace1f..c3be648103d7f 100644
--- a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/components/result_step.tsx
+++ b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/components/result_step.tsx
@@ -18,11 +18,11 @@ import React from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import { css } from '@emotion/react';
-import type { AssetCriticalityBulkUploadResponse } from '../../../../../common/entity_analytics/asset_criticality/types';
+import type { BulkUpsertAssetCriticalityRecordsResponse } from '../../../../../common/entity_analytics/asset_criticality/types';
import { buildAnnotationsFromError } from '../helpers';
export const AssetCriticalityResultStep: React.FC<{
- result?: AssetCriticalityBulkUploadResponse;
+ result?: BulkUpsertAssetCriticalityRecordsResponse;
validLinesAsText: string;
errorMessage?: string;
onReturn: () => void;
diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/reducer.test.ts b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/reducer.test.ts
index 60b6191a777d6..3fa2eb89e5d65 100644
--- a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/reducer.test.ts
+++ b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/reducer.test.ts
@@ -5,7 +5,7 @@
* 2.0.
*/
-import type { AssetCriticalityBulkUploadResponse } from '../../../../common/api/entity_analytics';
+import type { UploadAssetCriticalityRecordsResponse } from '../../../../common/api/entity_analytics';
import type { ReducerAction, ReducerState, ValidationStepState } from './reducer';
import { reducer } from './reducer';
import { FileUploaderSteps } from './types';
@@ -43,7 +43,7 @@ describe('reducer', () => {
});
it('should handle "fileUploaded" action with response', () => {
- const response: AssetCriticalityBulkUploadResponse = {
+ const response: UploadAssetCriticalityRecordsResponse = {
errors: [],
stats: {
total: 10,
diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/reducer.ts b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/reducer.ts
index e7f233015434f..eb0153d261871 100644
--- a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/reducer.ts
+++ b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/reducer.ts
@@ -5,7 +5,7 @@
* 2.0.
*/
-import type { AssetCriticalityBulkUploadResponse } from '../../../../common/entity_analytics/asset_criticality/types';
+import type { UploadAssetCriticalityRecordsResponse } from '../../../../common/api/entity_analytics';
import { FileUploaderSteps } from './types';
import type { ValidatedFile } from './types';
import { isFilePickerStep, isValidationStep } from './helpers';
@@ -26,7 +26,7 @@ export interface ValidationStepState {
export interface ResultStepState {
step: FileUploaderSteps.RESULT;
- fileUploadResponse?: AssetCriticalityBulkUploadResponse;
+ fileUploadResponse?: UploadAssetCriticalityRecordsResponse;
fileUploadError?: string;
validLinesAsText: string;
}
@@ -46,7 +46,7 @@ export type ReducerAction =
| { type: 'uploadingFile' }
| {
type: 'fileUploaded';
- payload: { response?: AssetCriticalityBulkUploadResponse; errorMessage?: string };
+ payload: { response?: UploadAssetCriticalityRecordsResponse; errorMessage?: string };
};
export const INITIAL_STATE: FilePickerState = {
diff --git a/x-pack/plugins/security_solution/scripts/openapi/generate.js b/x-pack/plugins/security_solution/scripts/openapi/generate.js
index 38eb0fe06f95a..adfe11192ae49 100644
--- a/x-pack/plugins/security_solution/scripts/openapi/generate.js
+++ b/x-pack/plugins/security_solution/scripts/openapi/generate.js
@@ -18,7 +18,6 @@ const SECURITY_SOLUTION_ROOT = resolve(__dirname, '../..');
rootDir: SECURITY_SOLUTION_ROOT,
sourceGlob: './common/**/*.schema.yaml',
templateName: 'zod_operation_schema',
- skipLinting: true,
});
await generate({
diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/asset_criticality_data_client.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/asset_criticality_data_client.ts
index ac22303c09af6..4770d051f2e99 100644
--- a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/asset_criticality_data_client.ts
+++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/asset_criticality_data_client.ts
@@ -11,7 +11,7 @@ import { mappingFromFieldMap } from '@kbn/alerting-plugin/common';
import type { AuditLogger } from '@kbn/security-plugin-types-server';
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
import type {
- AssetCriticalityBulkUploadResponse,
+ BulkUpsertAssetCriticalityRecordsResponse,
AssetCriticalityUpsert,
} from '../../../../common/entity_analytics/asset_criticality/types';
import type { AssetCriticalityRecord } from '../../../../common/api/entity_analytics';
@@ -211,9 +211,9 @@ export class AssetCriticalityDataClient {
recordsStream,
flushBytes,
retries,
- }: BulkUpsertFromStreamOptions): Promise => {
- const errors: AssetCriticalityBulkUploadResponse['errors'] = [];
- const stats: AssetCriticalityBulkUploadResponse['stats'] = {
+ }: BulkUpsertFromStreamOptions): Promise => {
+ const errors: BulkUpsertAssetCriticalityRecordsResponse['errors'] = [];
+ const stats: BulkUpsertAssetCriticalityRecordsResponse['stats'] = {
successful: 0,
failed: 0,
total: 0,
diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/bulk_upload.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/bulk_upload.ts
index e1eb6872d3a33..822c8a644d9b3 100644
--- a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/bulk_upload.ts
+++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/bulk_upload.ts
@@ -9,8 +9,8 @@ import { buildSiemResponse } from '@kbn/lists-plugin/server/routes/utils';
import { transformError } from '@kbn/securitysolution-es-utils';
import { Readable } from 'node:stream';
import { buildRouteValidationWithZod } from '@kbn/zod-helpers';
-import type { AssetCriticalityBulkUploadResponse } from '../../../../../common/api/entity_analytics';
-import { AssetCriticalityBulkUploadRequest } from '../../../../../common/api/entity_analytics';
+import type { BulkUpsertAssetCriticalityRecordsResponse } from '../../../../../common/api/entity_analytics';
+import { BulkUpsertAssetCriticalityRecordsRequestBody } from '../../../../../common/api/entity_analytics';
import type { ConfigType } from '../../../../config';
import {
ASSET_CRITICALITY_PUBLIC_BULK_UPLOAD_URL,
@@ -42,7 +42,7 @@ export const assetCriticalityPublicBulkUploadRoute = (
version: API_VERSIONS.public.v1,
validate: {
request: {
- body: buildRouteValidationWithZod(AssetCriticalityBulkUploadRequest),
+ body: buildRouteValidationWithZod(BulkUpsertAssetCriticalityRecordsRequestBody),
},
},
},
@@ -90,7 +90,7 @@ export const assetCriticalityPublicBulkUploadRoute = (
() => `Asset criticality Bulk upload completed in ${tookMs}ms ${JSON.stringify(stats)}`
);
- const resBody: AssetCriticalityBulkUploadResponse = { errors, stats };
+ const resBody: BulkUpsertAssetCriticalityRecordsResponse = { errors, stats };
return response.ok({ body: resBody });
} catch (e) {
diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/delete.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/delete.ts
index c7a0f07400cc8..b39013359eed4 100644
--- a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/delete.ts
+++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/delete.ts
@@ -8,6 +8,10 @@ import type { IKibanaResponse, KibanaResponseFactory, Logger } from '@kbn/core/s
import { buildSiemResponse } from '@kbn/lists-plugin/server/routes/utils';
import { transformError } from '@kbn/securitysolution-es-utils';
import { buildRouteValidationWithZod } from '@kbn/zod-helpers';
+import {
+ DeleteAssetCriticalityRecordRequestQuery,
+ InternalDeleteAssetCriticalityRecordRequestQuery,
+} from '../../../../../common/api/entity_analytics/asset_criticality/delete_asset_criticality.gen';
import type { SecuritySolutionRequestHandlerContext } from '../../../../types';
import {
ASSET_CRITICALITY_PUBLIC_URL,
@@ -16,7 +20,6 @@ import {
ENABLE_ASSET_CRITICALITY_SETTING,
API_VERSIONS,
} from '../../../../../common/constants';
-import { DeleteAssetCriticalityRecord } from '../../../../../common/api/entity_analytics/asset_criticality';
import { checkAndInitAssetCriticalityResources } from '../check_and_init_asset_criticality_resources';
import { assertAdvancedSettingsEnabled } from '../../utils/assert_advanced_setting_enabled';
import type { EntityAnalyticsRoutesDeps } from '../../types';
@@ -26,7 +29,7 @@ import { AUDIT_CATEGORY, AUDIT_OUTCOME, AUDIT_TYPE } from '../../audit';
type DeleteHandler = (
context: SecuritySolutionRequestHandlerContext,
request: {
- query: DeleteAssetCriticalityRecord;
+ query: DeleteAssetCriticalityRecordRequestQuery;
},
response: KibanaResponseFactory
) => Promise;
@@ -88,7 +91,7 @@ export const assetCriticalityInternalDeleteRoute = (
version: API_VERSIONS.internal.v1,
validate: {
request: {
- query: buildRouteValidationWithZod(DeleteAssetCriticalityRecord),
+ query: buildRouteValidationWithZod(InternalDeleteAssetCriticalityRecordRequestQuery),
},
},
},
@@ -113,7 +116,7 @@ export const assetCriticalityPublicDeleteRoute = (
version: API_VERSIONS.public.v1,
validate: {
request: {
- query: buildRouteValidationWithZod(DeleteAssetCriticalityRecord),
+ query: buildRouteValidationWithZod(DeleteAssetCriticalityRecordRequestQuery),
},
},
},
diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/get.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/get.ts
index 07d0cb3098dbc..e1ab013a373b6 100644
--- a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/get.ts
+++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/get.ts
@@ -8,6 +8,7 @@ import type { IKibanaResponse, KibanaResponseFactory, Logger } from '@kbn/core/s
import { buildSiemResponse } from '@kbn/lists-plugin/server/routes/utils';
import { transformError } from '@kbn/securitysolution-es-utils';
import { buildRouteValidationWithZod } from '@kbn/zod-helpers';
+import { GetAssetCriticalityRecordRequestQuery } from '../../../../../common/api/entity_analytics/asset_criticality/get_asset_criticality.gen';
import type { SecuritySolutionRequestHandlerContext } from '../../../../types';
import {
ASSET_CRITICALITY_INTERNAL_URL,
@@ -17,7 +18,6 @@ import {
API_VERSIONS,
} from '../../../../../common/constants';
import { checkAndInitAssetCriticalityResources } from '../check_and_init_asset_criticality_resources';
-import { AssetCriticalityRecordIdParts } from '../../../../../common/api/entity_analytics/asset_criticality';
import { assertAdvancedSettingsEnabled } from '../../utils/assert_advanced_setting_enabled';
import type { EntityAnalyticsRoutesDeps } from '../../types';
import { AssetCriticalityAuditActions } from '../audit';
@@ -25,7 +25,7 @@ import { AUDIT_CATEGORY, AUDIT_OUTCOME, AUDIT_TYPE } from '../../audit';
type GetHandler = (
context: SecuritySolutionRequestHandlerContext,
request: {
- query: AssetCriticalityRecordIdParts;
+ query: GetAssetCriticalityRecordRequestQuery;
},
response: KibanaResponseFactory
) => Promise;
@@ -86,7 +86,7 @@ export const assetCriticalityInternalGetRoute = (
version: API_VERSIONS.internal.v1,
validate: {
request: {
- query: buildRouteValidationWithZod(AssetCriticalityRecordIdParts),
+ query: buildRouteValidationWithZod(GetAssetCriticalityRecordRequestQuery),
},
},
},
@@ -111,7 +111,7 @@ export const assetCriticalityPublicGetRoute = (
version: API_VERSIONS.public.v1,
validate: {
request: {
- query: buildRouteValidationWithZod(AssetCriticalityRecordIdParts),
+ query: buildRouteValidationWithZod(GetAssetCriticalityRecordRequestQuery),
},
},
},
diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/list.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/list.ts
index 66db32f2bdb17..711426e4df510 100644
--- a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/list.ts
+++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/list.ts
@@ -15,8 +15,8 @@ import {
API_VERSIONS,
} from '../../../../../common/constants';
import { checkAndInitAssetCriticalityResources } from '../check_and_init_asset_criticality_resources';
-import type { AssetCriticalityListResponse } from '../../../../../common/api/entity_analytics/asset_criticality';
-import { ListAssetCriticalityQueryParams } from '../../../../../common/api/entity_analytics/asset_criticality';
+import type { FindAssetCriticalityRecordsResponse } from '../../../../../common/api/entity_analytics/asset_criticality';
+import { FindAssetCriticalityRecordsRequestQuery } from '../../../../../common/api/entity_analytics/asset_criticality';
import { assertAdvancedSettingsEnabled } from '../../utils/assert_advanced_setting_enabled';
import type { EntityAnalyticsRoutesDeps } from '../../types';
import { AssetCriticalityAuditActions } from '../audit';
@@ -39,7 +39,7 @@ export const assetCriticalityPublicListRoute = (
version: API_VERSIONS.public.v1,
validate: {
request: {
- query: buildRouteValidationWithZod(ListAssetCriticalityQueryParams),
+ query: buildRouteValidationWithZod(FindAssetCriticalityRecordsRequestQuery),
},
},
},
@@ -81,7 +81,7 @@ export const assetCriticalityPublicListRoute = (
},
});
- const body: AssetCriticalityListResponse = {
+ const body: FindAssetCriticalityRecordsResponse = {
records,
total,
page,
diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/status.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/status.ts
index 2afa73ed5a059..9d77817a20d98 100644
--- a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/status.ts
+++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/status.ts
@@ -7,7 +7,7 @@
import type { Logger } from '@kbn/core/server';
import { buildSiemResponse } from '@kbn/lists-plugin/server/routes/utils';
import { transformError } from '@kbn/securitysolution-es-utils';
-import type { AssetCriticalityStatusResponse } from '../../../../../common/api/entity_analytics/asset_criticality';
+import type { GetAssetCriticalityStatusResponse } from '../../../../../common/api/entity_analytics';
import {
ASSET_CRITICALITY_INTERNAL_STATUS_URL,
APP_ID,
@@ -55,7 +55,7 @@ export const assetCriticalityInternalStatusRoute = (
},
});
- const body: AssetCriticalityStatusResponse = {
+ const body: GetAssetCriticalityStatusResponse = {
asset_criticality_resources_installed: result.isAssetCriticalityResourcesInstalled,
};
return response.ok({
diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/upload_csv.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/upload_csv.ts
index 28c8333c5f596..7e284bfe042a0 100644
--- a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/upload_csv.ts
+++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/upload_csv.ts
@@ -10,7 +10,7 @@ import { schema } from '@kbn/config-schema';
import Papa from 'papaparse';
import { transformError } from '@kbn/securitysolution-es-utils';
import type internal from 'stream';
-import type { AssetCriticalityBulkUploadResponse } from '../../../../../common/api/entity_analytics';
+import type { UploadAssetCriticalityRecordsResponse } from '../../../../../common/api/entity_analytics/asset_criticality/upload_asset_criticality_csv.gen';
import { CRITICALITY_CSV_MAX_SIZE_BYTES_WITH_TOLERANCE } from '../../../../../common/entity_analytics/asset_criticality';
import type { ConfigType } from '../../../../config';
import type { HapiReadableStream, SecuritySolutionRequestHandlerContext } from '../../../../types';
@@ -90,7 +90,7 @@ const handler: (
);
// type assignment here to ensure that the response body stays in sync with the API schema
- const resBody: AssetCriticalityBulkUploadResponse = { errors, stats };
+ const resBody: UploadAssetCriticalityRecordsResponse = { errors, stats };
const [eventType, event] = createAssetCriticalityProcessedFileEvent({
startTime: start,
diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/upsert.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/upsert.ts
index cb3c36f450e43..20ad8173af666 100644
--- a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/upsert.ts
+++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/upsert.ts
@@ -8,6 +8,10 @@ import type { IKibanaResponse, KibanaResponseFactory, Logger } from '@kbn/core/s
import { buildSiemResponse } from '@kbn/lists-plugin/server/routes/utils';
import { transformError } from '@kbn/securitysolution-es-utils';
import { buildRouteValidationWithZod } from '@kbn/zod-helpers';
+import {
+ CreateAssetCriticalityRecordRequestBody,
+ InternalCreateAssetCriticalityRecordRequestBody,
+} from '../../../../../common/api/entity_analytics/asset_criticality/create_asset_criticality.gen';
import type { SecuritySolutionRequestHandlerContext } from '../../../../types';
import {
ASSET_CRITICALITY_PUBLIC_URL,
@@ -17,7 +21,6 @@ import {
API_VERSIONS,
} from '../../../../../common/constants';
import { checkAndInitAssetCriticalityResources } from '../check_and_init_asset_criticality_resources';
-import { CreateSingleAssetCriticalityRequest } from '../../../../../common/api/entity_analytics';
import type { EntityAnalyticsRoutesDeps } from '../../types';
import { AssetCriticalityAuditActions } from '../audit';
import { AUDIT_CATEGORY, AUDIT_OUTCOME, AUDIT_TYPE } from '../../audit';
@@ -26,7 +29,7 @@ import { assertAdvancedSettingsEnabled } from '../../utils/assert_advanced_setti
type UpsertHandler = (
context: SecuritySolutionRequestHandlerContext,
request: {
- body: CreateSingleAssetCriticalityRequest;
+ body: CreateAssetCriticalityRecordRequestBody;
},
response: KibanaResponseFactory
) => Promise;
@@ -93,7 +96,7 @@ export const assetCriticalityInternalUpsertRoute = (
version: API_VERSIONS.internal.v1,
validate: {
request: {
- body: buildRouteValidationWithZod(CreateSingleAssetCriticalityRequest),
+ body: buildRouteValidationWithZod(InternalCreateAssetCriticalityRecordRequestBody),
},
},
},
@@ -118,7 +121,7 @@ export const assetCriticalityPublicUpsertRoute = (
version: API_VERSIONS.public.v1,
validate: {
request: {
- body: buildRouteValidationWithZod(CreateSingleAssetCriticalityRequest),
+ body: buildRouteValidationWithZod(CreateAssetCriticalityRecordRequestBody),
},
},
},
diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_engine/routes/disable.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_engine/routes/disable.ts
index f1f0348a69e33..3501d1869d5ed 100644
--- a/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_engine/routes/disable.ts
+++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_engine/routes/disable.ts
@@ -7,7 +7,7 @@
import { buildSiemResponse } from '@kbn/lists-plugin/server/routes/utils';
import { transformError } from '@kbn/securitysolution-es-utils';
-import type { RiskEngineDisableResponse } from '../../../../../common/api/entity_analytics/risk_engine/engine_disable_route.gen';
+import type { DisableRiskEngineResponse } from '../../../../../common/api/entity_analytics/risk_engine/engine_disable_route.gen';
import { RISK_ENGINE_DISABLE_URL, APP_ID } from '../../../../../common/constants';
import { TASK_MANAGER_UNAVAILABLE_ERROR } from './translations';
import { withRiskEnginePrivilegeCheck } from '../risk_engine_privileges';
@@ -71,7 +71,7 @@ export const riskEngineDisableRoute = (
try {
await riskEngineClient.disableRiskEngine({ taskManager });
- const body: RiskEngineDisableResponse = { success: true };
+ const body: DisableRiskEngineResponse = { success: true };
return response.ok({ body });
} catch (e) {
const error = transformError(e);
diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_engine/routes/enable.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_engine/routes/enable.ts
index a4eed8701d1e1..9397af65675da 100644
--- a/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_engine/routes/enable.ts
+++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_engine/routes/enable.ts
@@ -7,7 +7,7 @@
import { buildSiemResponse } from '@kbn/lists-plugin/server/routes/utils';
import { transformError } from '@kbn/securitysolution-es-utils';
-import type { RiskEngineEnableResponse } from '../../../../../common/api/entity_analytics/risk_engine/engine_enable_route.gen';
+import type { EnableRiskEngineResponse } from '../../../../../common/api/entity_analytics/risk_engine/engine_enable_route.gen';
import { RISK_ENGINE_ENABLE_URL, APP_ID } from '../../../../../common/constants';
import { TASK_MANAGER_UNAVAILABLE_ERROR } from './translations';
import { withRiskEnginePrivilegeCheck } from '../risk_engine_privileges';
@@ -69,7 +69,7 @@ export const riskEngineEnableRoute = (
try {
await riskEngineClient.enableRiskEngine({ taskManager });
- const body: RiskEngineEnableResponse = { success: true };
+ const body: EnableRiskEngineResponse = { success: true };
return response.ok({ body });
} catch (e) {
const error = transformError(e);
diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_engine/routes/init.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_engine/routes/init.ts
index 8360f3652a7f3..9e50e0b98ccd8 100644
--- a/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_engine/routes/init.ts
+++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_engine/routes/init.ts
@@ -8,8 +8,8 @@
import { buildSiemResponse } from '@kbn/lists-plugin/server/routes/utils';
import { transformError } from '@kbn/securitysolution-es-utils';
import type {
- RiskEngineInitResponse,
- RiskEngineInitResult,
+ InitRiskEngineResponse,
+ InitRiskEngineResult,
} from '../../../../../common/api/entity_analytics/risk_engine/engine_init_route.gen';
import { RISK_ENGINE_INIT_URL, APP_ID } from '../../../../../common/constants';
import { TASK_MANAGER_UNAVAILABLE_ERROR } from './translations';
@@ -64,7 +64,7 @@ export const riskEngineInitRoute = (
riskScoreDataClient,
});
- const result: RiskEngineInitResult = {
+ const result: InitRiskEngineResult = {
risk_engine_enabled: initResult.riskEngineEnabled,
risk_engine_resources_installed: initResult.riskEngineResourcesInstalled,
risk_engine_configuration_created: initResult.riskEngineConfigurationCreated,
@@ -72,7 +72,7 @@ export const riskEngineInitRoute = (
errors: initResult.errors,
};
- const initResponse: RiskEngineInitResponse = {
+ const initResponse: InitRiskEngineResponse = {
result,
};
diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_engine/routes/settings.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_engine/routes/settings.ts
index 032114f7871b6..1d39fbaf18420 100644
--- a/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_engine/routes/settings.ts
+++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_engine/routes/settings.ts
@@ -7,7 +7,7 @@
import { buildSiemResponse } from '@kbn/lists-plugin/server/routes/utils';
import { transformError } from '@kbn/securitysolution-es-utils';
-import type { RiskEngineSettingsResponse } from '../../../../../common/api/entity_analytics/risk_engine';
+import type { ReadRiskEngineSettingsResponse } from '../../../../../common/api/entity_analytics/risk_engine';
import { RISK_ENGINE_SETTINGS_URL, APP_ID } from '../../../../../common/constants';
import { AUDIT_CATEGORY, AUDIT_OUTCOME, AUDIT_TYPE } from '../../audit';
import type { EntityAnalyticsRoutesDeps } from '../../types';
@@ -43,7 +43,7 @@ export const riskEngineSettingsRoute = (router: EntityAnalyticsRoutesDeps['route
if (!result) {
throw new Error('Unable to get risk engine configuration');
}
- const body: RiskEngineSettingsResponse = {
+ const body: ReadRiskEngineSettingsResponse = {
range: result.range,
};
return response.ok({
diff --git a/x-pack/plugins/security_solution/server/lib/telemetry/event_based/events.ts b/x-pack/plugins/security_solution/server/lib/telemetry/event_based/events.ts
index 97a4d44fcd594..8eb46b2046c10 100644
--- a/x-pack/plugins/security_solution/server/lib/telemetry/event_based/events.ts
+++ b/x-pack/plugins/security_solution/server/lib/telemetry/event_based/events.ts
@@ -5,7 +5,7 @@
* 2.0.
*/
import type { EventTypeOpts } from '@kbn/core/server';
-import type { AssetCriticalityBulkUploadResponse } from '../../../../common/api/entity_analytics';
+import type { BulkUpsertAssetCriticalityRecordsResponse } from '../../../../common/api/entity_analytics';
export const RISK_SCORE_EXECUTION_SUCCESS_EVENT: EventTypeOpts<{
scoresWritten: number;
@@ -88,7 +88,7 @@ interface AssetCriticalitySystemProcessedAssignmentFileEvent {
endTime: string;
tookMs: number;
};
- result?: AssetCriticalityBulkUploadResponse['stats'];
+ result?: BulkUpsertAssetCriticalityRecordsResponse['stats'];
status: 'success' | 'partial_success' | 'fail';
}
@@ -124,7 +124,7 @@ export const ASSET_CRITICALITY_SYSTEM_PROCESSED_ASSIGNMENT_FILE_EVENT: EventType
};
interface CreateAssetCriticalityProcessedFileEvent {
- result?: AssetCriticalityBulkUploadResponse['stats'];
+ result?: BulkUpsertAssetCriticalityRecordsResponse['stats'];
startTime: Date;
endTime: Date;
}
@@ -154,7 +154,7 @@ export const createAssetCriticalityProcessedFileEvent = ({
];
};
-const getUploadStatus = (stats?: AssetCriticalityBulkUploadResponse['stats']) => {
+const getUploadStatus = (stats?: BulkUpsertAssetCriticalityRecordsResponse['stats']) => {
if (!stats) {
return 'fail';
}
diff --git a/x-pack/test/api_integration/services/security_solution_api.gen.ts b/x-pack/test/api_integration/services/security_solution_api.gen.ts
index f5089b489a617..91ae460bbb563 100644
--- a/x-pack/test/api_integration/services/security_solution_api.gen.ts
+++ b/x-pack/test/api_integration/services/security_solution_api.gen.ts
@@ -26,13 +26,17 @@ import { BulkDeleteRulesRequestBodyInput } from '@kbn/security-solution-plugin/c
import { BulkDeleteRulesPostRequestBodyInput } from '@kbn/security-solution-plugin/common/api/detection_engine/rule_management/bulk_crud/bulk_delete_rules/bulk_delete_rules_route.gen';
import { BulkPatchRulesRequestBodyInput } from '@kbn/security-solution-plugin/common/api/detection_engine/rule_management/bulk_crud/bulk_patch_rules/bulk_patch_rules_route.gen';
import { BulkUpdateRulesRequestBodyInput } from '@kbn/security-solution-plugin/common/api/detection_engine/rule_management/bulk_crud/bulk_update_rules/bulk_update_rules_route.gen';
+import { BulkUpsertAssetCriticalityRecordsRequestBodyInput } from '@kbn/security-solution-plugin/common/api/entity_analytics/asset_criticality/bulk_upload_asset_criticality.gen';
import { CreateAlertsMigrationRequestBodyInput } from '@kbn/security-solution-plugin/common/api/detection_engine/signals_migration/create_signals_migration/create_signals_migration.gen';
+import { CreateAssetCriticalityRecordRequestBodyInput } from '@kbn/security-solution-plugin/common/api/entity_analytics/asset_criticality/create_asset_criticality.gen';
import { CreateRuleRequestBodyInput } from '@kbn/security-solution-plugin/common/api/detection_engine/rule_management/crud/create_rule/create_rule_route.gen';
import {
CreateUpdateProtectionUpdatesNoteRequestParamsInput,
CreateUpdateProtectionUpdatesNoteRequestBodyInput,
} from '@kbn/security-solution-plugin/common/api/endpoint/protection_updates_note/protection_updates_note.gen';
+import { DeleteAssetCriticalityRecordRequestQueryInput } from '@kbn/security-solution-plugin/common/api/entity_analytics/asset_criticality/delete_asset_criticality.gen';
import { DeleteRuleRequestQueryInput } from '@kbn/security-solution-plugin/common/api/detection_engine/rule_management/crud/delete_rule/delete_rule_route.gen';
+import { DeprecatedTriggerRiskScoreCalculationRequestBodyInput } from '@kbn/security-solution-plugin/common/api/entity_analytics/risk_engine/entity_calculation_route.gen';
import { EndpointIsolateRedirectRequestBodyInput } from '@kbn/security-solution-plugin/common/api/endpoint/actions/isolate_route.gen';
import { EndpointUnisolateRedirectRequestBodyInput } from '@kbn/security-solution-plugin/common/api/endpoint/actions/unisolate_route.gen';
import {
@@ -40,9 +44,11 @@ import {
ExportRulesRequestBodyInput,
} from '@kbn/security-solution-plugin/common/api/detection_engine/rule_management/export_rules/export_rules_route.gen';
import { FinalizeAlertsMigrationRequestBodyInput } from '@kbn/security-solution-plugin/common/api/detection_engine/signals_migration/finalize_signals_migration/finalize_signals_migration.gen';
+import { FindAssetCriticalityRecordsRequestQueryInput } from '@kbn/security-solution-plugin/common/api/entity_analytics/asset_criticality/list_asset_criticality.gen';
import { FindRulesRequestQueryInput } from '@kbn/security-solution-plugin/common/api/detection_engine/rule_management/find_rules/find_rules_route.gen';
import { GetAgentPolicySummaryRequestQueryInput } from '@kbn/security-solution-plugin/common/api/endpoint/policy/policy.gen';
import { GetAlertsMigrationStatusRequestQueryInput } from '@kbn/security-solution-plugin/common/api/detection_engine/signals_migration/get_signals_migration_status/get_signals_migration_status.gen';
+import { GetAssetCriticalityRecordRequestQueryInput } from '@kbn/security-solution-plugin/common/api/entity_analytics/asset_criticality/get_asset_criticality.gen';
import {
GetEndpointSuggestionsRequestParamsInput,
GetEndpointSuggestionsRequestBodyInput,
@@ -58,18 +64,22 @@ import {
GetRuleExecutionResultsRequestParamsInput,
} from '@kbn/security-solution-plugin/common/api/detection_engine/rule_monitoring/rule_execution_logs/get_rule_execution_results/get_rule_execution_results_route.gen';
import { ImportRulesRequestQueryInput } from '@kbn/security-solution-plugin/common/api/detection_engine/rule_management/import_rules/import_rules_route.gen';
+import { InternalCreateAssetCriticalityRecordRequestBodyInput } from '@kbn/security-solution-plugin/common/api/entity_analytics/asset_criticality/create_asset_criticality.gen';
+import { InternalDeleteAssetCriticalityRecordRequestQueryInput } from '@kbn/security-solution-plugin/common/api/entity_analytics/asset_criticality/delete_asset_criticality.gen';
import { ManageAlertTagsRequestBodyInput } from '@kbn/security-solution-plugin/common/api/detection_engine/alert_tags/set_alert_tags/set_alert_tags.gen';
import { PatchRuleRequestBodyInput } from '@kbn/security-solution-plugin/common/api/detection_engine/rule_management/crud/patch_rule/patch_rule_route.gen';
import {
PerformBulkActionRequestQueryInput,
PerformBulkActionRequestBodyInput,
} from '@kbn/security-solution-plugin/common/api/detection_engine/rule_management/bulk_actions/bulk_actions_route.gen';
+import { PreviewRiskScoreRequestBodyInput } from '@kbn/security-solution-plugin/common/api/entity_analytics/risk_engine/preview_route.gen';
import { ReadRuleRequestQueryInput } from '@kbn/security-solution-plugin/common/api/detection_engine/rule_management/crud/read_rule/read_rule_route.gen';
import { RulePreviewRequestBodyInput } from '@kbn/security-solution-plugin/common/api/detection_engine/rule_preview/rule_preview.gen';
import { SearchAlertsRequestBodyInput } from '@kbn/security-solution-plugin/common/api/detection_engine/signals/query_signals/query_signals_route.gen';
import { SetAlertAssigneesRequestBodyInput } from '@kbn/security-solution-plugin/common/api/detection_engine/alert_assignees/set_alert_assignees_route.gen';
import { SetAlertsStatusRequestBodyInput } from '@kbn/security-solution-plugin/common/api/detection_engine/signals/set_signal_status/set_signals_status_route.gen';
import { SuggestUserProfilesRequestQueryInput } from '@kbn/security-solution-plugin/common/api/detection_engine/users/suggest_user_profiles_route.gen';
+import { TriggerRiskScoreCalculationRequestBodyInput } from '@kbn/security-solution-plugin/common/api/entity_analytics/risk_engine/entity_calculation_route.gen';
import { UpdateRuleRequestBodyInput } from '@kbn/security-solution-plugin/common/api/detection_engine/rule_management/crud/update_rule/update_rule_route.gen';
import { FtrProviderContext } from '../ftr_provider_context';
@@ -153,6 +163,14 @@ after 30 days. It also deletes other artifacts specific to the migration impleme
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.send(props.body as object);
},
+ bulkUpsertAssetCriticalityRecords(props: BulkUpsertAssetCriticalityRecordsProps) {
+ return supertest
+ .post('/api/asset_criticality/bulk')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
+ .send(props.body as object);
+ },
createAlertsIndex() {
return supertest
.post('/api/detection_engine/index')
@@ -173,6 +191,14 @@ Migrations are initiated per index. While the process is neither destructive nor
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.send(props.body as object);
},
+ createAssetCriticalityRecord(props: CreateAssetCriticalityRecordProps) {
+ return supertest
+ .post('/api/asset_criticality')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
+ .send(props.body as object);
+ },
/**
* Create a new detection rule.
*/
@@ -201,6 +227,14 @@ Migrations are initiated per index. While the process is neither destructive nor
.set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana');
},
+ deleteAssetCriticalityRecord(props: DeleteAssetCriticalityRecordProps) {
+ return supertest
+ .delete('/api/asset_criticality')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
+ .query(props.query);
+ },
/**
* Delete a detection rule using the `rule_id` or `id` field.
*/
@@ -212,6 +246,31 @@ Migrations are initiated per index. While the process is neither destructive nor
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.query(props.query);
},
+ /**
+ * Calculates and persists Risk Scores for an entity, returning the calculated risk score.
+ */
+ deprecatedTriggerRiskScoreCalculation(props: DeprecatedTriggerRiskScoreCalculationProps) {
+ return supertest
+ .post('/api/risk_scores/calculation/entity')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
+ .send(props.body as object);
+ },
+ disableRiskEngine() {
+ return supertest
+ .post('/internal/risk_score/engine/disable')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana');
+ },
+ enableRiskEngine() {
+ return supertest
+ .post('/internal/risk_score/engine/enable')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana');
+ },
endpointIsolateRedirect(props: EndpointIsolateRedirectProps) {
return supertest
.post('/api/endpoint/isolate')
@@ -259,6 +318,14 @@ finalize it.
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.send(props.body as object);
},
+ findAssetCriticalityRecords(props: FindAssetCriticalityRecordsProps) {
+ return supertest
+ .post('/api/asset_criticality/list')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
+ .query(props.query);
+ },
/**
* Retrieve a paginated list of detection rules. By default, the first page is returned, with 20 results per page.
*/
@@ -296,6 +363,21 @@ finalize it.
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.query(props.query);
},
+ getAssetCriticalityRecord(props: GetAssetCriticalityRecordProps) {
+ return supertest
+ .get('/api/asset_criticality')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
+ .query(props.query);
+ },
+ getAssetCriticalityStatus() {
+ return supertest
+ .get('/internal/asset_criticality/status')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana');
+ },
getEndpointSuggestions(props: GetEndpointSuggestionsProps) {
return supertest
.post(replaceParams('/api/endpoint/suggestions/{suggestion_type}', props.params))
@@ -345,6 +427,16 @@ detection engine rules.
.set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana');
},
+ /**
+ * Returns the status of both the legacy transform-based risk engine, as well as the new risk engine
+ */
+ getRiskEngineStatus() {
+ return supertest
+ .get('/internal/risk_score/engine/status')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana');
+ },
getRuleExecutionEvents(props: GetRuleExecutionEventsProps) {
return supertest
.put(
@@ -379,6 +471,16 @@ detection engine rules.
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.query(props.query);
},
+ /**
+ * Initializes the Risk Engine by creating the necessary indices and mappings, removing old transforms, and starting the new risk engine
+ */
+ initRiskEngine() {
+ return supertest
+ .post('/internal/risk_score/engine/init')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana');
+ },
/**
* Install and update all Elastic prebuilt detection rules and Timelines.
*/
@@ -389,6 +491,29 @@ detection engine rules.
.set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana');
},
+ internalCreateAssetCriticalityRecord(props: InternalCreateAssetCriticalityRecordProps) {
+ return supertest
+ .post('/internal/asset_criticality')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
+ .send(props.body as object);
+ },
+ internalDeleteAssetCriticalityRecord(props: InternalDeleteAssetCriticalityRecordProps) {
+ return supertest
+ .delete('/internal/asset_criticality')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
+ .query(props.query);
+ },
+ internalUploadAssetCriticalityRecords() {
+ return supertest
+ .post('/internal/asset_criticality/upload_csv')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana');
+ },
/**
* And tags to detection alerts, and remove them from alerts.
> info
@@ -426,6 +551,24 @@ detection engine rules.
.send(props.body as object)
.query(props.query);
},
+ /**
+ * Calculates and returns a list of Risk Scores, sorted by identifier_type and risk score.
+ */
+ previewRiskScore(props: PreviewRiskScoreProps) {
+ return supertest
+ .post('/internal/risk_score/preview')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
+ .send(props.body as object);
+ },
+ readRiskEngineSettings() {
+ return supertest
+ .get('/internal/risk_score/engine/settings')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana');
+ },
/**
* Retrieve a detection rule using the `rule_id` or `id` field.
*/
@@ -502,6 +645,17 @@ detection engine rules.
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.query(props.query);
},
+ /**
+ * Calculates and persists Risk Scores for an entity, returning the calculated risk score.
+ */
+ triggerRiskScoreCalculation(props: TriggerRiskScoreCalculationProps) {
+ return supertest
+ .post('/internal/risk_score/calculation/entity')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
+ .send(props.body as object);
+ },
/**
* Update a detection rule using the `rule_id` or `id` field. The original rule is replaced, and all unspecified fields are deleted.
> info
@@ -516,6 +670,13 @@ detection engine rules.
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.send(props.body as object);
},
+ uploadAssetCriticalityRecords() {
+ return supertest
+ .post('/api/asset_criticality/upload_csv')
+ .set('kbn-xsrf', 'true')
+ .set(ELASTIC_HTTP_VERSION_HEADER, '1')
+ .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana');
+ },
};
}
@@ -537,9 +698,15 @@ export interface BulkPatchRulesProps {
export interface BulkUpdateRulesProps {
body: BulkUpdateRulesRequestBodyInput;
}
+export interface BulkUpsertAssetCriticalityRecordsProps {
+ body: BulkUpsertAssetCriticalityRecordsRequestBodyInput;
+}
export interface CreateAlertsMigrationProps {
body: CreateAlertsMigrationRequestBodyInput;
}
+export interface CreateAssetCriticalityRecordProps {
+ body: CreateAssetCriticalityRecordRequestBodyInput;
+}
export interface CreateRuleProps {
body: CreateRuleRequestBodyInput;
}
@@ -547,9 +714,15 @@ export interface CreateUpdateProtectionUpdatesNoteProps {
params: CreateUpdateProtectionUpdatesNoteRequestParamsInput;
body: CreateUpdateProtectionUpdatesNoteRequestBodyInput;
}
+export interface DeleteAssetCriticalityRecordProps {
+ query: DeleteAssetCriticalityRecordRequestQueryInput;
+}
export interface DeleteRuleProps {
query: DeleteRuleRequestQueryInput;
}
+export interface DeprecatedTriggerRiskScoreCalculationProps {
+ body: DeprecatedTriggerRiskScoreCalculationRequestBodyInput;
+}
export interface EndpointIsolateRedirectProps {
body: EndpointIsolateRedirectRequestBodyInput;
}
@@ -563,6 +736,9 @@ export interface ExportRulesProps {
export interface FinalizeAlertsMigrationProps {
body: FinalizeAlertsMigrationRequestBodyInput;
}
+export interface FindAssetCriticalityRecordsProps {
+ query: FindAssetCriticalityRecordsRequestQueryInput;
+}
export interface FindRulesProps {
query: FindRulesRequestQueryInput;
}
@@ -572,6 +748,9 @@ export interface GetAgentPolicySummaryProps {
export interface GetAlertsMigrationStatusProps {
query: GetAlertsMigrationStatusRequestQueryInput;
}
+export interface GetAssetCriticalityRecordProps {
+ query: GetAssetCriticalityRecordRequestQueryInput;
+}
export interface GetEndpointSuggestionsProps {
params: GetEndpointSuggestionsRequestParamsInput;
body: GetEndpointSuggestionsRequestBodyInput;
@@ -593,6 +772,12 @@ export interface GetRuleExecutionResultsProps {
export interface ImportRulesProps {
query: ImportRulesRequestQueryInput;
}
+export interface InternalCreateAssetCriticalityRecordProps {
+ body: InternalCreateAssetCriticalityRecordRequestBodyInput;
+}
+export interface InternalDeleteAssetCriticalityRecordProps {
+ query: InternalDeleteAssetCriticalityRecordRequestQueryInput;
+}
export interface ManageAlertTagsProps {
body: ManageAlertTagsRequestBodyInput;
}
@@ -603,6 +788,9 @@ export interface PerformBulkActionProps {
query: PerformBulkActionRequestQueryInput;
body: PerformBulkActionRequestBodyInput;
}
+export interface PreviewRiskScoreProps {
+ body: PreviewRiskScoreRequestBodyInput;
+}
export interface ReadRuleProps {
query: ReadRuleRequestQueryInput;
}
@@ -621,6 +809,9 @@ export interface SetAlertsStatusProps {
export interface SuggestUserProfilesProps {
query: SuggestUserProfilesRequestQueryInput;
}
+export interface TriggerRiskScoreCalculationProps {
+ body: TriggerRiskScoreCalculationRequestBodyInput;
+}
export interface UpdateRuleProps {
body: UpdateRuleRequestBodyInput;
}
diff --git a/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/utils/asset_criticality.ts b/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/utils/asset_criticality.ts
index 9ae70f540f897..11343e077eeaf 100644
--- a/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/utils/asset_criticality.ts
+++ b/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/utils/asset_criticality.ts
@@ -23,7 +23,7 @@ import {
import type {
AssetCriticalityRecord,
CreateAssetCriticalityRecord,
- ListAssetCriticalityQueryParams,
+ FindAssetCriticalityRecordsRequestQuery,
} from '@kbn/security-solution-plugin/common/api/entity_analytics';
import type { Client } from '@elastic/elasticsearch';
import type { ToolingLog } from '@kbn/tooling-log';
@@ -187,7 +187,7 @@ export const assetCriticalityRouteHelpersFactory = (
.expect(expectStatusCode);
},
list: async (
- opts: ListAssetCriticalityQueryParams = {},
+ opts: FindAssetCriticalityRecordsRequestQuery = {},
{ expectStatusCode }: { expectStatusCode: number } = { expectStatusCode: 200 }
) => {
const qs = querystring.stringify(opts);
From 47b0105ea7b1bb5d53de0c3b341b22633f66f7ed Mon Sep 17 00:00:00 2001
From: Steph Milovic
Date: Mon, 22 Jul 2024 11:06:37 -0500
Subject: [PATCH 21/30] Gemini connector - update test message (#188850)
---
docs/management/connectors/action-types/gemini.asciidoc | 2 +-
.../public/connector_types/gemini/constants.tsx | 2 +-
.../group2/tests/actions/connector_types/gemini.ts | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/docs/management/connectors/action-types/gemini.asciidoc b/docs/management/connectors/action-types/gemini.asciidoc
index 3c835d981465c..610fb4ad48f15 100644
--- a/docs/management/connectors/action-types/gemini.asciidoc
+++ b/docs/management/connectors/action-types/gemini.asciidoc
@@ -56,7 +56,7 @@ Body:: A stringified JSON payload sent to the {gemini} invoke model API. Fo
body: JSON.stringify({
contents: [{
role: user,
- parts: [{ text: 'Write the first line of a story about a magic backpack.' }]
+ parts: [{ text: 'Hello world!' }]
}],
generation_config: {
temperature: 0,
diff --git a/x-pack/plugins/stack_connectors/public/connector_types/gemini/constants.tsx b/x-pack/plugins/stack_connectors/public/connector_types/gemini/constants.tsx
index 162f78efabc48..e9844a1c39b03 100644
--- a/x-pack/plugins/stack_connectors/public/connector_types/gemini/constants.tsx
+++ b/x-pack/plugins/stack_connectors/public/connector_types/gemini/constants.tsx
@@ -27,7 +27,7 @@ const contents = [
role: 'user',
parts: [
{
- text: 'Write the first line of a story about a magic backpack.',
+ text: 'Hello world!',
},
],
},
diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/actions/connector_types/gemini.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/actions/connector_types/gemini.ts
index d483d11db96ec..54eebf207e7d7 100644
--- a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/actions/connector_types/gemini.ts
+++ b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/actions/connector_types/gemini.ts
@@ -310,7 +310,7 @@ export default function geminiTest({ getService }: FtrProviderContext) {
role: 'user',
parts: [
{
- text: 'Write the first line of a story about a magic backpack.',
+ text: 'Hello world!',
},
],
},
@@ -325,7 +325,7 @@ export default function geminiTest({ getService }: FtrProviderContext) {
contents: [
{
role: 'user',
- parts: [{ text: 'Write the first line of a story about a magic backpack.' }],
+ parts: [{ text: 'Hello world!' }],
},
],
generation_config: { temperature: 0, maxOutputTokens: 8192 },
From e33f010d6d9e160968d8c19645605b8db7968b85 Mon Sep 17 00:00:00 2001
From: Tiago Costa
Date: Mon, 22 Jul 2024 17:16:25 +0100
Subject: [PATCH 22/30] skip flaky suite (#188234)
---
.../server/integration_tests/telemetry.test.ts | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/x-pack/plugins/security_solution/server/integration_tests/telemetry.test.ts b/x-pack/plugins/security_solution/server/integration_tests/telemetry.test.ts
index 7a38948c0c46d..46f85a01f4760 100644
--- a/x-pack/plugins/security_solution/server/integration_tests/telemetry.test.ts
+++ b/x-pack/plugins/security_solution/server/integration_tests/telemetry.test.ts
@@ -683,7 +683,8 @@ describe('telemetry tasks', () => {
});
});
- describe('telemetry-prebuilt-rule-alerts', () => {
+ // FLAKY: https://github.com/elastic/kibana/issues/188234
+ describe.skip('telemetry-prebuilt-rule-alerts', () => {
it('should execute when scheduled', async () => {
await mockAndSchedulePrebuiltRulesTask();
From f380962a6e822a597d96c0f96c74f92766eb7452 Mon Sep 17 00:00:00 2001
From: Tiago Costa
Date: Mon, 22 Jul 2024 17:20:04 +0100
Subject: [PATCH 23/30] skip flaky suite (#188660)
---
.../serverless_metering/cloud_security_metering.ts | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/serverless_metering/cloud_security_metering.ts b/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/serverless_metering/cloud_security_metering.ts
index c1ce48215e2e2..49c223c8d1424 100644
--- a/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/serverless_metering/cloud_security_metering.ts
+++ b/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/serverless_metering/cloud_security_metering.ts
@@ -40,7 +40,8 @@ export default function (providerContext: FtrProviderContext) {
The task manager is running by default in security serverless project in the background and sending usage API requests to the usage API.
This test mocks the usage API server and intercepts the usage API request sent by the metering background task manager.
*/
- describe('Intercept the usage API request sent by the metering background task manager', function () {
+ // FLAKY: https://github.com/elastic/kibana/issues/188660
+ describe.skip('Intercept the usage API request sent by the metering background task manager', function () {
this.tags(['skipMKI']);
let mockUsageApiServer: http.Server;
From e026c2a2a9e8283fbe9fc5700d223fa940bbfe7d Mon Sep 17 00:00:00 2001
From: "Joey F. Poon"
Date: Mon, 22 Jul 2024 09:30:17 -0700
Subject: [PATCH 24/30] [Security Solution] unskip endpoint metering
integration tests (#187816)
---
.../public/management/cypress/e2e/serverless/metering.cy.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/x-pack/plugins/security_solution/public/management/cypress/e2e/serverless/metering.cy.ts b/x-pack/plugins/security_solution/public/management/cypress/e2e/serverless/metering.cy.ts
index 6e436e2a529f8..8cc4cadda44f2 100644
--- a/x-pack/plugins/security_solution/public/management/cypress/e2e/serverless/metering.cy.ts
+++ b/x-pack/plugins/security_solution/public/management/cypress/e2e/serverless/metering.cy.ts
@@ -17,8 +17,7 @@ import type { ReturnTypeFromChainable } from '../../types';
import { indexEndpointHeartbeats } from '../../tasks/index_endpoint_heartbeats';
import { login, ROLE } from '../../tasks/login';
-// Failing: See https://github.com/elastic/kibana/issues/187083
-describe.skip(
+describe(
'Metering',
{
tags: ['@serverless', '@skipInServerlessMKI'],
@@ -30,6 +29,7 @@ describe.skip(
],
},
},
+ pageLoadTimeout: 1 * 60 * 1000,
},
() => {
const HEARTBEAT_COUNT = 2001;
From d8302eb2ec96a74444195ed4ba13adfbe9de185e Mon Sep 17 00:00:00 2001
From: Jon
Date: Mon, 22 Jul 2024 11:31:20 -0500
Subject: [PATCH 25/30] [deb] Add adduser as a dependency (#185048)
adduser is used in the deb post install script. Installing kibana.deb in
a container won't have the necessary dependencies by default
Closes #182537
---------
Co-authored-by: Elastic Machine
---
.buildkite/pipelines/pull_request/base.yml | 2 +-
src/dev/build/tasks/os_packages/create_os_package_tasks.ts | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/.buildkite/pipelines/pull_request/base.yml b/.buildkite/pipelines/pull_request/base.yml
index 8b57562c7a329..e5da8ce788e5b 100644
--- a/.buildkite/pipelines/pull_request/base.yml
+++ b/.buildkite/pipelines/pull_request/base.yml
@@ -14,7 +14,7 @@ steps:
preemptible: true
key: build
if: "build.env('KIBANA_BUILD_ID') == null || build.env('KIBANA_BUILD_ID') == ''"
- timeout_in_minutes: 60
+ timeout_in_minutes: 90
retry:
automatic:
- exit_status: '-1'
diff --git a/src/dev/build/tasks/os_packages/create_os_package_tasks.ts b/src/dev/build/tasks/os_packages/create_os_package_tasks.ts
index f422d9fae221a..052d7592024d7 100644
--- a/src/dev/build/tasks/os_packages/create_os_package_tasks.ts
+++ b/src/dev/build/tasks/os_packages/create_os_package_tasks.ts
@@ -28,6 +28,8 @@ export const CreateDebPackage: Task = {
'amd64',
'--deb-priority',
'optional',
+ '--depends',
+ ' adduser',
]);
await runFpm(config, log, build, 'deb', 'arm64', [
@@ -35,6 +37,8 @@ export const CreateDebPackage: Task = {
'arm64',
'--deb-priority',
'optional',
+ '--depends',
+ ' adduser',
]);
},
};
From 8fb8c27fac201892eb58d0a11dce23c6ccb12cbd Mon Sep 17 00:00:00 2001
From: Rachel Shen
Date: Mon, 22 Jul 2024 11:03:26 -0600
Subject: [PATCH 26/30] [A11y] aria label for context for try in console open
in a new tab or embedded console (#188367)
## Summary
Closes https://github.com/elastic/search-team/issues/7627
---
.../components/try_in_console_button.tsx | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/packages/kbn-try-in-console/components/try_in_console_button.tsx b/packages/kbn-try-in-console/components/try_in_console_button.tsx
index a49011749e14e..e54b139fe6734 100644
--- a/packages/kbn-try-in-console/components/try_in_console_button.tsx
+++ b/packages/kbn-try-in-console/components/try_in_console_button.tsx
@@ -72,12 +72,27 @@ export const TryInConsoleButton = ({
);
}
+ const getAriaLabel = () => {
+ if (
+ consolePlugin?.openEmbeddedConsole !== undefined &&
+ consolePlugin?.isEmbeddedConsoleAvailable?.()
+ ) {
+ return i18n.translate('tryInConsole.embeddedConsoleButton', {
+ defaultMessage: 'Try the snipped in the Console - opens in embedded console',
+ });
+ }
+ return i18n.translate('tryInConsole.inNewTab.button', {
+ defaultMessage: 'Try the below snippet in Console - opens in a new tab',
+ });
+ };
+
return (
{content ?? TRY_IN_CONSOLE}
From 375c6ffd619ef6bbb5b68e90ff2b647c6287c379 Mon Sep 17 00:00:00 2001
From: Chris Cowan
Date: Mon, 22 Jul 2024 11:24:29 -0600
Subject: [PATCH 27/30] [EEM] Convert route validation to Zod (#188691)
## Summary
This PR closes https://github.com/elastic/kibana/issues/188171 by
converting the route validate to Zod for `get`, `reset`, and `delete`
APIs. This also changes the validation for the `create` API to use
`buildRouteValidationWithZod` along with adding `strict()` to each of
the schemas.
Closes https://github.com/elastic/elastic-entity-model/issues/103
---------
Co-authored-by: Kevin Lacabane
---
x-pack/packages/kbn-entities-schema/index.ts | 3 +++
.../kbn-entities-schema/src/rest_spec/delete.ts | 16 ++++++++++++++++
.../kbn-entities-schema/src/rest_spec/get.ts | 13 +++++++++++++
.../kbn-entities-schema/src/rest_spec/reset.ts | 11 +++++++++++
.../server/routes/entities/create.ts | 10 ++--------
.../server/routes/entities/delete.ts | 14 +++++++-------
.../entity_manager/server/routes/entities/get.ts | 8 +++-----
.../server/routes/entities/reset.ts | 7 +++----
8 files changed, 58 insertions(+), 24 deletions(-)
create mode 100644 x-pack/packages/kbn-entities-schema/src/rest_spec/delete.ts
create mode 100644 x-pack/packages/kbn-entities-schema/src/rest_spec/get.ts
create mode 100644 x-pack/packages/kbn-entities-schema/src/rest_spec/reset.ts
diff --git a/x-pack/packages/kbn-entities-schema/index.ts b/x-pack/packages/kbn-entities-schema/index.ts
index 92b93b7938125..8251e1c14755f 100644
--- a/x-pack/packages/kbn-entities-schema/index.ts
+++ b/x-pack/packages/kbn-entities-schema/index.ts
@@ -8,3 +8,6 @@
export * from './src/schema/entity_definition';
export * from './src/schema/entity';
export * from './src/schema/common';
+export * from './src/rest_spec/delete';
+export * from './src/rest_spec/reset';
+export * from './src/rest_spec/get';
diff --git a/x-pack/packages/kbn-entities-schema/src/rest_spec/delete.ts b/x-pack/packages/kbn-entities-schema/src/rest_spec/delete.ts
new file mode 100644
index 0000000000000..b1243d5aa6d9e
--- /dev/null
+++ b/x-pack/packages/kbn-entities-schema/src/rest_spec/delete.ts
@@ -0,0 +1,16 @@
+/*
+ * 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 { z } from 'zod';
+
+export const deleteEntityDefinitionParamsSchema = z.object({
+ id: z.string(),
+});
+
+export const deleteEntityDefinitionQuerySchema = z.object({
+ deleteData: z.optional(z.coerce.boolean().default(false)),
+});
diff --git a/x-pack/packages/kbn-entities-schema/src/rest_spec/get.ts b/x-pack/packages/kbn-entities-schema/src/rest_spec/get.ts
new file mode 100644
index 0000000000000..f703da8a7b6b2
--- /dev/null
+++ b/x-pack/packages/kbn-entities-schema/src/rest_spec/get.ts
@@ -0,0 +1,13 @@
+/*
+ * 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 { z } from 'zod';
+
+export const getEntityDefinitionQuerySchema = z.object({
+ page: z.optional(z.coerce.number()),
+ perPage: z.optional(z.coerce.number()),
+});
diff --git a/x-pack/packages/kbn-entities-schema/src/rest_spec/reset.ts b/x-pack/packages/kbn-entities-schema/src/rest_spec/reset.ts
new file mode 100644
index 0000000000000..e93b8e789280f
--- /dev/null
+++ b/x-pack/packages/kbn-entities-schema/src/rest_spec/reset.ts
@@ -0,0 +1,11 @@
+/*
+ * 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 { z } from 'zod';
+
+export const resetEntityDefinitionParamsSchema = z.object({
+ id: z.string(),
+});
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/create.ts b/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/create.ts
index 8d17debc8914d..9d38cc7c5e716 100644
--- a/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/create.ts
+++ b/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/create.ts
@@ -7,7 +7,7 @@
import { RequestHandlerContext } from '@kbn/core/server';
import { EntityDefinition, entityDefinitionSchema } from '@kbn/entities-schema';
-import { stringifyZodError } from '@kbn/zod-helpers';
+import { buildRouteValidationWithZod } from '@kbn/zod-helpers';
import { SetupRouteOptions } from '../types';
import { EntityIdConflict } from '../../lib/entities/errors/entity_id_conflict_error';
import { EntitySecurityException } from '../../lib/entities/errors/entity_security_exception';
@@ -23,13 +23,7 @@ export function createEntityDefinitionRoute({
{
path: '/internal/entities/definition',
validate: {
- body: (body, res) => {
- try {
- return res.ok(entityDefinitionSchema.parse(body));
- } catch (e) {
- return res.badRequest(stringifyZodError(e));
- }
- },
+ body: buildRouteValidationWithZod(entityDefinitionSchema.strict()),
},
},
async (context, req, res) => {
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/delete.ts b/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/delete.ts
index f79fdce2368c6..b0c423a47a4b9 100644
--- a/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/delete.ts
+++ b/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/delete.ts
@@ -6,7 +6,11 @@
*/
import { RequestHandlerContext } from '@kbn/core/server';
-import { schema } from '@kbn/config-schema';
+import { buildRouteValidationWithZod } from '@kbn/zod-helpers';
+import {
+ deleteEntityDefinitionParamsSchema,
+ deleteEntityDefinitionQuerySchema,
+} from '@kbn/entities-schema';
import { SetupRouteOptions } from '../types';
import { EntitySecurityException } from '../../lib/entities/errors/entity_security_exception';
import { InvalidTransformError } from '../../lib/entities/errors/invalid_transform_error';
@@ -22,12 +26,8 @@ export function deleteEntityDefinitionRoute({
{
path: '/internal/entities/definition/{id}',
validate: {
- params: schema.object({
- id: schema.string(),
- }),
- query: schema.object({
- deleteData: schema.maybe(schema.boolean({ defaultValue: false })),
- }),
+ params: buildRouteValidationWithZod(deleteEntityDefinitionParamsSchema.strict()),
+ query: buildRouteValidationWithZod(deleteEntityDefinitionQuerySchema.strict()),
},
},
async (context, req, res) => {
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/get.ts b/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/get.ts
index 25a593c05209e..3f1ffde5afef4 100644
--- a/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/get.ts
+++ b/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/get.ts
@@ -6,7 +6,8 @@
*/
import { RequestHandlerContext } from '@kbn/core/server';
-import { schema } from '@kbn/config-schema';
+import { buildRouteValidationWithZod } from '@kbn/zod-helpers';
+import { getEntityDefinitionQuerySchema } from '@kbn/entities-schema';
import { SetupRouteOptions } from '../types';
import { findEntityDefinitions } from '../../lib/entities/find_entity_definition';
@@ -17,10 +18,7 @@ export function getEntityDefinitionRoute({
{
path: '/internal/entities/definition',
validate: {
- query: schema.object({
- page: schema.maybe(schema.number()),
- perPage: schema.maybe(schema.number()),
- }),
+ query: buildRouteValidationWithZod(getEntityDefinitionQuerySchema.strict()),
},
},
async (context, req, res) => {
diff --git a/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/reset.ts b/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/reset.ts
index ffa85931a3bef..6f97a5fbe0d51 100644
--- a/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/reset.ts
+++ b/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/reset.ts
@@ -6,7 +6,8 @@
*/
import { RequestHandlerContext } from '@kbn/core/server';
-import { schema } from '@kbn/config-schema';
+import { buildRouteValidationWithZod } from '@kbn/zod-helpers';
+import { resetEntityDefinitionParamsSchema } from '@kbn/entities-schema';
import { SetupRouteOptions } from '../types';
import { EntitySecurityException } from '../../lib/entities/errors/entity_security_exception';
import { InvalidTransformError } from '../../lib/entities/errors/invalid_transform_error';
@@ -39,9 +40,7 @@ export function resetEntityDefinitionRoute({
{
path: '/internal/entities/definition/{id}/_reset',
validate: {
- params: schema.object({
- id: schema.string(),
- }),
+ params: buildRouteValidationWithZod(resetEntityDefinitionParamsSchema.strict()),
},
},
async (context, req, res) => {
From 013276edac16b3437b7f125b6eaec1b6ad949c87 Mon Sep 17 00:00:00 2001
From: Dzmitry Lemechko
Date: Mon, 22 Jul 2024 19:27:40 +0200
Subject: [PATCH 28/30] [kbn-test] improve run_check_ftr_configs_cli script
(#188854)
## Summary
Follow-up to #188825
@crespocarlos reported that some Oblt configs after missing after
#187440
I was using `node scripts/check_ftr_configs.js` to validate I did not
miss anything and decided to debug the script.
We had a pretty strict config file content validation like
`testRunner|testFiles`, that was skipping some FTR configs like
`x-pack/test/apm_api_integration/basic/config.ts`
I extended file content check to look for default export function and
also skip test/suite or Cypress-own config files.
In the end 7 FTR configs were discovered, but only 2 are with tests. I
will ask owners to confirm if it should be enabled/disabled. Script run
output:
```
node scripts/check_ftr_configs.js
ERROR The following files look like FTR configs which are not listed in one of manifest files:
- x-pack/plugins/observability_solution/uptime/e2e/config.ts
- x-pack/test/functional_basic/apps/ml/config.base.ts
- x-pack/test/functional_basic/apps/transform/config.base.ts
- x-pack/test/security_solution_api_integration/config/ess/config.base.trial.ts
- x-pack/test_serverless/functional/test_suites/observability/cypress/oblt_config.base.ts
Make sure to add your new FTR config to the correct manifest file.
Stateful tests:
.buildkite/ftr_platform_stateful_configs.yml
.buildkite/ftr_oblt_stateful_configs.yml
.buildkite/ftr_security_stateful_configs.yml
.buildkite/ftr_search_stateful_configs.yml
Serverless tests:
.buildkite/ftr_base_serverless_configs.yml
.buildkite/ftr_oblt_serverless_configs.yml
.buildkite/ftr_security_serverless_configs.yml
.buildkite/ftr_search_serverless_configs.yml
ERROR Please add the listed paths to the correct manifest file. If it's not an FTR config, you can add it to the IGNORED_PATHS in packages/kbn-test/src/functional_test_runner/lib/config/run_check_ftr_configs_cli.ts or contact #kibana-operations
```
---
.buildkite/ftr_oblt_serverless_configs.yml | 1 +
.buildkite/ftr_oblt_stateful_configs.yml | 3 ++
.buildkite/ftr_platform_stateful_configs.yml | 2 +
.../ftr_security_serverless_configs.yml | 2 +
.buildkite/ftr_security_stateful_configs.yml | 1 +
.../lib/config/run_check_ftr_configs_cli.ts | 39 ++++++++++++++++---
6 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/.buildkite/ftr_oblt_serverless_configs.yml b/.buildkite/ftr_oblt_serverless_configs.yml
index 9534e62926f06..085c25f2d80a6 100644
--- a/.buildkite/ftr_oblt_serverless_configs.yml
+++ b/.buildkite/ftr_oblt_serverless_configs.yml
@@ -1,5 +1,6 @@
disabled:
# Base config files, only necessary to inform config finding script
+ - x-pack/test_serverless/functional/test_suites/observability/cypress/oblt_config.base.ts
# Cypress configs, for now these are still run manually
- x-pack/test_serverless/functional/test_suites/observability/cypress/config_headless.ts
diff --git a/.buildkite/ftr_oblt_stateful_configs.yml b/.buildkite/ftr_oblt_stateful_configs.yml
index d9f557dac7f6a..4edf75f385816 100644
--- a/.buildkite/ftr_oblt_stateful_configs.yml
+++ b/.buildkite/ftr_oblt_stateful_configs.yml
@@ -10,6 +10,9 @@ disabled:
- x-pack/plugins/observability_solution/profiling/e2e/ftr_config_runner.ts
- x-pack/plugins/observability_solution/profiling/e2e/ftr_config.ts
+ #FTR configs
+ - x-pack/plugins/observability_solution/uptime/e2e/config.ts
+
# Elastic Synthetics configs
- x-pack/plugins/observability_solution/uptime/e2e/uptime/synthetics_run.ts
- x-pack/plugins/observability_solution/synthetics/e2e/config.ts
diff --git a/.buildkite/ftr_platform_stateful_configs.yml b/.buildkite/ftr_platform_stateful_configs.yml
index a0425f766f569..96c15cce513c6 100644
--- a/.buildkite/ftr_platform_stateful_configs.yml
+++ b/.buildkite/ftr_platform_stateful_configs.yml
@@ -8,6 +8,8 @@ disabled:
- x-pack/test/functional_with_es_ssl/config.base.ts
- x-pack/test/api_integration/config.ts
- x-pack/test/fleet_api_integration/config.base.ts
+ - x-pack/test/functional_basic/apps/ml/config.base.ts
+ - x-pack/test/functional_basic/apps/transform/config.base.ts
# QA suites that are run out-of-band
- x-pack/test/stack_functional_integration/configs/config.stack_functional_integration_base.js
diff --git a/.buildkite/ftr_security_serverless_configs.yml b/.buildkite/ftr_security_serverless_configs.yml
index 51e3eba941c6b..3880175623fdd 100644
--- a/.buildkite/ftr_security_serverless_configs.yml
+++ b/.buildkite/ftr_security_serverless_configs.yml
@@ -1,5 +1,7 @@
disabled:
# Base config files, only necessary to inform config finding script
+ - x-pack/test_serverless/functional/test_suites/security/cypress/security_config.base.ts
+ - x-pack/test_serverless/functional/test_suites/security/cypress/cypress.config.ts
- x-pack/test/security_solution_api_integration/config/serverless/config.base.ts
- x-pack/test/security_solution_api_integration/config/serverless/config.base.essentials.ts
- x-pack/test/security_solution_api_integration/config/serverless/config.base.edr_workflows.ts
diff --git a/.buildkite/ftr_security_stateful_configs.yml b/.buildkite/ftr_security_stateful_configs.yml
index 8f1605b363e3d..a7931bab0a68d 100644
--- a/.buildkite/ftr_security_stateful_configs.yml
+++ b/.buildkite/ftr_security_stateful_configs.yml
@@ -5,6 +5,7 @@ disabled:
- x-pack/test/security_solution_api_integration/config/ess/config.base.edr_workflows.trial.ts
- x-pack/test/security_solution_api_integration/config/ess/config.base.edr_workflows.ts
- x-pack/test/security_solution_api_integration/config/ess/config.base.basic.ts
+ - x-pack/test/security_solution_api_integration/config/ess/config.base.trial.ts
- x-pack/test/security_solution_endpoint/configs/config.base.ts
- x-pack/test/security_solution_endpoint/config.base.ts
- x-pack/test/security_solution_endpoint_api_int/config.base.ts
diff --git a/packages/kbn-test/src/functional_test_runner/lib/config/run_check_ftr_configs_cli.ts b/packages/kbn-test/src/functional_test_runner/lib/config/run_check_ftr_configs_cli.ts
index 31afcac759357..57f819bb44771 100644
--- a/packages/kbn-test/src/functional_test_runner/lib/config/run_check_ftr_configs_cli.ts
+++ b/packages/kbn-test/src/functional_test_runner/lib/config/run_check_ftr_configs_cli.ts
@@ -62,13 +62,36 @@ export async function runCheckFtrConfigsCli() {
return false;
}
- if (file.match(/jest.config.(t|j)s$/)) {
+ if (file.match(/(jest(\.integration)?)\.config\.(t|j)s$/)) {
return false;
}
- return readFileSync(file)
- .toString()
- .match(/(testRunner)|(testFiles)/);
+ if (file.match(/mocks.ts$/)) {
+ return false;
+ }
+
+ const fileContent = readFileSync(file).toString();
+
+ if (fileContent.match(/(testRunner)|(testFiles)/)) {
+ // test config
+ return true;
+ }
+
+ if (fileContent.match(/(describe)|(defineCypressConfig)/)) {
+ // test file or Cypress config
+ return false;
+ }
+
+ // FTR config file should have default export
+ try {
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
+ const exports = require(file);
+ const defaultExport = exports.__esModule ? exports.default : exports;
+ return !!defaultExport;
+ } catch (err) {
+ log.debug(`Failed to load file: ${err.message}`);
+ return false;
+ }
});
const { allFtrConfigs, manifestPaths } = getAllFtrConfigsAndManifests();
@@ -77,10 +100,14 @@ export async function runCheckFtrConfigsCli() {
if (invalid.length) {
const invalidList = invalid.map((path) => Path.relative(REPO_ROOT, path)).join('\n - ');
log.error(
- `The following files look like FTR configs which are not listed in one of manifest files:\nstateful: ${manifestPaths.stateful}\nserverless: ${manifestPaths.serverless}\n - ${invalidList}`
+ `The following files look like FTR configs which are not listed in one of manifest files:\n${invalidList}\n
+Make sure to add your new FTR config to the correct manifest file.\n
+Stateful tests:\n${(manifestPaths.stateful as string[]).join('\n')}\n
+Serverless tests:\n${(manifestPaths.serverless as string[]).join('\n')}
+ `
);
throw createFailError(
- `Please add the listed paths to the correct manifest file. If it's not an FTR config, you can add it to the IGNORED_PATHS in ${THIS_REL} or contact #kibana-operations`
+ `Please add the listed paths to the correct manifest files. If it's not an FTR config, you can add it to the IGNORED_PATHS in ${THIS_REL} or contact #kibana-operations`
);
}
},
From 232a16637d3ee03a435224eb11852c4f2f1b1810 Mon Sep 17 00:00:00 2001
From: Juan Pablo Djeredjian
Date: Mon, 22 Jul 2024 19:36:31 +0200
Subject: [PATCH 29/30] [Security Solution] Implement normalization of
ruleSource for API responses (#188631)
Fixes: https://github.com/elastic/kibana/issues/180140
## Summary
- Implements normalization of`rule_source` for API responses
- `rule_source` field in API responses is calculated out of the
`immutable` and `ruleSource` fields.
### 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)
---
.../routes/__mocks__/utils.ts | 3 +
...egacy_rules_notification_rule_type.test.ts | 3 +
.../internal_rule_to_api_response.ts | 4 +-
.../converters/normalize_rule_params.test.ts | 55 ++++++++++++++
.../converters/normalize_rule_params.ts | 48 ++++++++++++
.../logic/export/get_export_all.test.ts | 6 ++
.../rule_management/utils/validate.test.ts | 74 +------------------
.../rule_schema/model/rule_schemas.mock.ts | 3 +
.../factories/utils/build_alert.test.ts | 6 ++
9 files changed, 129 insertions(+), 73 deletions(-)
create mode 100644 x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/logic/detection_rules_client/converters/normalize_rule_params.test.ts
create mode 100644 x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/logic/detection_rules_client/converters/normalize_rule_params.ts
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/__mocks__/utils.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/__mocks__/utils.ts
index 819bf87165e12..687bf91655e2a 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/__mocks__/utils.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/__mocks__/utils.ts
@@ -47,6 +47,9 @@ export const getOutputRuleAlertForRest = (): RuleResponse => ({
from: 'now-6m',
id: '04128c15-0d1b-4716-a4c5-46997ac7f3bd',
immutable: false,
+ rule_source: {
+ type: 'internal',
+ },
index: ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'],
interval: '5m',
risk_score: 50,
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_actions_legacy/logic/notifications/legacy_rules_notification_rule_type.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_actions_legacy/logic/notifications/legacy_rules_notification_rule_type.test.ts
index 767c01f02b187..4adf71d258e0a 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_actions_legacy/logic/notifications/legacy_rules_notification_rule_type.test.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_actions_legacy/logic/notifications/legacy_rules_notification_rule_type.test.ts
@@ -76,6 +76,9 @@ const reported = {
from: 'now-6m',
id: 'rule-id',
immutable: false,
+ rule_source: {
+ type: 'internal',
+ },
index: ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'],
investigation_fields: undefined,
language: 'kuery',
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/logic/detection_rules_client/converters/internal_rule_to_api_response.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/logic/detection_rules_client/converters/internal_rule_to_api_response.ts
index 452f59df8dcf9..349f54b1e3b3c 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/logic/detection_rules_client/converters/internal_rule_to_api_response.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/logic/detection_rules_client/converters/internal_rule_to_api_response.ts
@@ -17,6 +17,7 @@ import {
} from '../../../normalization/rule_actions';
import { typeSpecificCamelToSnake } from './type_specific_camel_to_snake';
import { commonParamsCamelToSnake } from './common_params_camel_to_snake';
+import { normalizeRuleParams } from './normalize_rule_params';
export const internalRuleToAPIResponse = (
rule: SanitizedRule | ResolvedSanitizedRule
@@ -31,6 +32,7 @@ export const internalRuleToAPIResponse = (
const alertActions = rule.actions.map(transformAlertToRuleAction);
const throttle = transformFromAlertThrottle(rule);
const actions = transformToActionFrequency(alertActions, throttle);
+ const normalizedRuleParams = normalizeRuleParams(rule.params);
return {
// saved object properties
@@ -49,7 +51,7 @@ export const internalRuleToAPIResponse = (
enabled: rule.enabled,
revision: rule.revision,
// Security solution shared rule params
- ...commonParamsCamelToSnake(rule.params),
+ ...commonParamsCamelToSnake(normalizedRuleParams),
// Type specific security solution rule params
...typeSpecificCamelToSnake(rule.params),
// Actions
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/logic/detection_rules_client/converters/normalize_rule_params.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/logic/detection_rules_client/converters/normalize_rule_params.test.ts
new file mode 100644
index 0000000000000..b8b5db137583b
--- /dev/null
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/logic/detection_rules_client/converters/normalize_rule_params.test.ts
@@ -0,0 +1,55 @@
+/*
+ * 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 { normalizeRuleSource } from './normalize_rule_params';
+import type { BaseRuleParams } from '../../../../rule_schema';
+
+describe('normalizeRuleSource', () => {
+ it('should return rule_source of type `internal` when immutable is false and ruleSource is undefined', () => {
+ const result = normalizeRuleSource({
+ immutable: false,
+ ruleSource: undefined,
+ });
+ expect(result).toEqual({
+ type: 'internal',
+ });
+ });
+
+ it('should return rule_source of type `external` and `isCustomized: false` when immutable is true and ruleSource is undefined', () => {
+ const result = normalizeRuleSource({
+ immutable: true,
+ ruleSource: undefined,
+ });
+ expect(result).toEqual({
+ type: 'external',
+ isCustomized: false,
+ });
+ });
+
+ it('should return existing value when ruleSource is present', () => {
+ const externalRuleSource: BaseRuleParams['ruleSource'] = {
+ type: 'external',
+ isCustomized: true,
+ };
+ const externalResult = normalizeRuleSource({ immutable: true, ruleSource: externalRuleSource });
+ expect(externalResult).toEqual({
+ type: externalRuleSource.type,
+ isCustomized: externalRuleSource.isCustomized,
+ });
+
+ const internalRuleSource: BaseRuleParams['ruleSource'] = {
+ type: 'internal',
+ };
+ const internalResult = normalizeRuleSource({
+ immutable: false,
+ ruleSource: internalRuleSource,
+ });
+ expect(internalResult).toEqual({
+ type: internalRuleSource.type,
+ });
+ });
+});
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/logic/detection_rules_client/converters/normalize_rule_params.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/logic/detection_rules_client/converters/normalize_rule_params.ts
new file mode 100644
index 0000000000000..eddd8b0434ba0
--- /dev/null
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/logic/detection_rules_client/converters/normalize_rule_params.ts
@@ -0,0 +1,48 @@
+/*
+ * 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 type { BaseRuleParams, RuleSourceCamelCased } from '../../../../rule_schema';
+
+interface NormalizeRuleSourceParams {
+ immutable: BaseRuleParams['immutable'];
+ ruleSource: BaseRuleParams['ruleSource'];
+}
+
+/*
+ * Since there's no mechanism to migrate all rules at the same time,
+ * we cannot guarantee that the ruleSource params is present in all rules.
+ * This function will normalize the ruleSource param, creating it if does
+ * not exist in ES, based on the immutable param.
+ */
+export const normalizeRuleSource = ({
+ immutable,
+ ruleSource,
+}: NormalizeRuleSourceParams): RuleSourceCamelCased => {
+ if (!ruleSource) {
+ const normalizedRuleSource: RuleSourceCamelCased = immutable
+ ? {
+ type: 'external',
+ isCustomized: false,
+ }
+ : {
+ type: 'internal',
+ };
+
+ return normalizedRuleSource;
+ }
+ return ruleSource;
+};
+
+export const normalizeRuleParams = (params: BaseRuleParams) => {
+ return {
+ ...params,
+ // Fields to normalize
+ ruleSource: normalizeRuleSource({
+ immutable: params.immutable,
+ ruleSource: params.ruleSource,
+ }),
+ };
+};
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/logic/export/get_export_all.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/logic/export/get_export_all.test.ts
index 0ba0afbce715a..382df4bfa5ffc 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/logic/export/get_export_all.test.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/logic/export/get_export_all.test.ts
@@ -100,6 +100,9 @@ describe('getExportAll', () => {
from: 'now-6m',
id: '04128c15-0d1b-4716-a4c5-46997ac7f3bd',
immutable: false,
+ rule_source: {
+ type: 'internal',
+ },
index: ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'],
interval: '5m',
rule_id: 'rule-1',
@@ -280,6 +283,9 @@ describe('getExportAll', () => {
from: 'now-6m',
id: '04128c15-0d1b-4716-a4c5-46997ac7f3bd',
immutable: false,
+ rule_source: {
+ type: 'internal',
+ },
index: ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'],
interval: '5m',
rule_id: 'rule-1',
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/utils/validate.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/utils/validate.test.ts
index f11e31691d25b..c9a5a93a4f1c3 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/utils/validate.test.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/utils/validate.test.ts
@@ -8,85 +8,15 @@
import { transformValidateBulkError } from './validate';
import type { BulkError } from '../../routes/utils';
import { getRuleMock } from '../../routes/__mocks__/request_responses';
-import { getListArrayMock } from '../../../../../common/detection_engine/schemas/types/lists.mock';
-import { getThreatMock } from '../../../../../common/detection_engine/schemas/types/threat.mock';
import { getQueryRuleParams } from '../../rule_schema/mocks';
-import type { RuleResponse } from '../../../../../common/api/detection_engine/model/rule_schema';
-
-export const ruleOutput = (): RuleResponse => ({
- actions: [],
- author: ['Elastic'],
- building_block_type: 'default',
- created_at: '2019-12-13T16:40:33.400Z',
- updated_at: '2019-12-13T16:40:33.400Z',
- created_by: 'elastic',
- description: 'Detecting root and admin users',
- enabled: true,
- false_positives: [],
- from: 'now-6m',
- id: '04128c15-0d1b-4716-a4c5-46997ac7f3bd',
- immutable: false,
- interval: '5m',
- rule_id: 'rule-1',
- language: 'kuery',
- license: 'Elastic License',
- output_index: '.siem-signals',
- max_signals: 10000,
- risk_score: 50,
- risk_score_mapping: [],
- name: 'Detect Root/Admin Users',
- query: 'user.name: root or user.name: admin',
- references: ['http://example.com', 'https://example.com'],
- severity: 'high',
- severity_mapping: [],
- updated_by: 'elastic',
- tags: [],
- to: 'now',
- type: 'query',
- throttle: undefined,
- threat: getThreatMock(),
- version: 1,
- revision: 0,
- filters: [
- {
- query: {
- match_phrase: {
- 'host.name': 'some-host',
- },
- },
- },
- ],
- exceptions_list: getListArrayMock(),
- index: ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'],
- meta: {
- someMeta: 'someField',
- },
- note: '# Investigative notes',
- timeline_title: 'some-timeline-title',
- timeline_id: 'some-timeline-id',
- related_integrations: [],
- required_fields: [],
- response_actions: undefined,
- setup: '',
- outcome: undefined,
- alias_target_id: undefined,
- alias_purpose: undefined,
- rule_name_override: undefined,
- timestamp_override: undefined,
- timestamp_override_fallback_disabled: undefined,
- namespace: undefined,
- data_view_id: undefined,
- saved_id: undefined,
- alert_suppression: undefined,
- investigation_fields: undefined,
-});
+import { getOutputRuleAlertForRest } from '../../routes/__mocks__/utils';
describe('validate', () => {
describe('transformValidateBulkError', () => {
test('it should do a validation correctly of a rule id', () => {
const ruleAlert = getRuleMock(getQueryRuleParams());
const validatedOrError = transformValidateBulkError('rule-1', ruleAlert);
- expect(validatedOrError).toEqual(ruleOutput());
+ expect(validatedOrError).toEqual(getOutputRuleAlertForRest());
});
test('it should do an in-validation correctly of a rule id', () => {
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_schema/model/rule_schemas.mock.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_schema/model/rule_schemas.mock.ts
index 3a4fa1dadd778..8099d7a00049f 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_schema/model/rule_schemas.mock.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_schema/model/rule_schemas.mock.ts
@@ -32,6 +32,9 @@ export const getBaseRuleParams = (): BaseRuleParams => {
description: 'Detecting root and admin users',
falsePositives: [],
immutable: false,
+ ruleSource: {
+ type: 'internal',
+ },
from: 'now-6m',
to: 'now',
severity: 'high',
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_types/factories/utils/build_alert.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_types/factories/utils/build_alert.test.ts
index ffb5f6ee45170..4aaa0189eefc4 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_types/factories/utils/build_alert.test.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_types/factories/utils/build_alert.test.ts
@@ -162,6 +162,9 @@ describe('buildAlert', () => {
},
],
immutable: false,
+ rule_source: {
+ type: 'internal',
+ },
type: 'query',
language: 'kuery',
index: ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'],
@@ -357,6 +360,9 @@ describe('buildAlert', () => {
},
],
immutable: false,
+ rule_source: {
+ type: 'internal',
+ },
type: 'query',
language: 'kuery',
index: ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'],
From 0c5d7b95c0a6783a54a415797bed3e54065251e7 Mon Sep 17 00:00:00 2001
From: Juan Pablo Djeredjian
Date: Mon, 22 Jul 2024 19:53:13 +0200
Subject: [PATCH 30/30] [Security Solution] Remove remaining usage of
rule_schema_legacy types (#188079)
## Summary
Leftover work from https://github.com/elastic/kibana/pull/186615
- Removes remaining usage of `rule_schema_legacy` types. In this PR,
simply inlines the last io-ts types used, to be able to get rid of the
legacy folder.
- The remaining files that need to be migrated to using Zod schema types
are:
-
`x-pack/plugins/security_solution/common/api/detection_engine/rule_exceptions/find_exception_references/find_exception_references_route.ts`
- `x-pack/plugins/security_solution/common/api/timeline/model/api.ts`
### 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)
---------
Co-authored-by: Georgii Gorbachev
---
.../rule_schema_legacy/common_attributes.ts | 60 -------------------
.../model/rule_schema_legacy/index.ts | 8 ---
.../find_exception_references_route.ts | 13 +++-
.../common/api/timeline/model/api.ts | 31 ++++++++--
4 files changed, 35 insertions(+), 77 deletions(-)
delete mode 100644 x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema_legacy/common_attributes.ts
delete mode 100644 x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema_legacy/index.ts
diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema_legacy/common_attributes.ts b/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema_legacy/common_attributes.ts
deleted file mode 100644
index ba07c49a7b130..0000000000000
--- a/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema_legacy/common_attributes.ts
+++ /dev/null
@@ -1,60 +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 * as t from 'io-ts';
-import { NonEmptyString, UUID } from '@kbn/securitysolution-io-ts-types';
-
-/*
-IMPORTANT NOTE ON THIS FILE:
-
-This file contains the remaining rule schema types created manually via io-ts. They have been
-migrated to Zod schemas created via code generation out of OpenAPI schemas
-(found in x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema/common_attributes.gen.ts)
-
-The remaining types here couldn't easily be deleted/replaced because they are dependencies in
-complex derived schemas in two files:
-
-- x-pack/plugins/security_solution/common/api/detection_engine/rule_exceptions/find_exception_references/find_exception_references_route.ts
-- x-pack/plugins/security_solution/common/api/timeline/model/api.ts
-
-Once those two files are migrated to Zod, the /common/api/detection_engine/model/rule_schema_legacy
-folder can be removed.
-*/
-
-export type RuleObjectId = t.TypeOf;
-export const RuleObjectId = UUID;
-
-/**
- * NOTE: Never make this a strict uuid, we allow the rule_id to be any string at the moment
- * in case we encounter 3rd party rule systems which might be using auto incrementing numbers
- * or other different things.
- */
-export type RuleSignatureId = t.TypeOf;
-export const RuleSignatureId = t.string; // should be non-empty string?
-
-export type RuleName = t.TypeOf;
-export const RuleName = NonEmptyString;
-
-/**
- * Outcome is a property of the saved object resolve api
- * will tell us info about the rule after 8.0 migrations
- */
-export type SavedObjectResolveOutcome = t.TypeOf;
-export const SavedObjectResolveOutcome = t.union([
- t.literal('exactMatch'),
- t.literal('aliasMatch'),
- t.literal('conflict'),
-]);
-
-export type SavedObjectResolveAliasTargetId = t.TypeOf;
-export const SavedObjectResolveAliasTargetId = t.string;
-
-export type SavedObjectResolveAliasPurpose = t.TypeOf;
-export const SavedObjectResolveAliasPurpose = t.union([
- t.literal('savedObjectConversion'),
- t.literal('savedObjectImport'),
-]);
diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema_legacy/index.ts b/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema_legacy/index.ts
deleted file mode 100644
index a112f6ca1b29f..0000000000000
--- a/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema_legacy/index.ts
+++ /dev/null
@@ -1,8 +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.
- */
-
-export * from './common_attributes';
diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/rule_exceptions/find_exception_references/find_exception_references_route.ts b/x-pack/plugins/security_solution/common/api/detection_engine/rule_exceptions/find_exception_references/find_exception_references_route.ts
index cbef9a41de718..63b9363bb97c4 100644
--- a/x-pack/plugins/security_solution/common/api/detection_engine/rule_exceptions/find_exception_references/find_exception_references_route.ts
+++ b/x-pack/plugins/security_solution/common/api/detection_engine/rule_exceptions/find_exception_references/find_exception_references_route.ts
@@ -12,10 +12,17 @@ import {
list_id,
DefaultNamespaceArray,
} from '@kbn/securitysolution-io-ts-list-types';
-import { NonEmptyStringArray } from '@kbn/securitysolution-io-ts-types';
+import { NonEmptyStringArray, NonEmptyString, UUID } from '@kbn/securitysolution-io-ts-types';
+
// TODO https://github.com/elastic/security-team/issues/7491
-// eslint-disable-next-line no-restricted-imports
-import { RuleName, RuleObjectId, RuleSignatureId } from '../../model/rule_schema_legacy';
+type RuleObjectId = t.TypeOf;
+const RuleObjectId = UUID;
+
+type RuleSignatureId = t.TypeOf;
+const RuleSignatureId = t.string;
+
+type RuleName = t.TypeOf;
+const RuleName = NonEmptyString;
// If ids and list_ids are undefined, route will fetch all lists matching the
// specified namespace type
diff --git a/x-pack/plugins/security_solution/common/api/timeline/model/api.ts b/x-pack/plugins/security_solution/common/api/timeline/model/api.ts
index 3e69bd14b646c..10b12aee32f2f 100644
--- a/x-pack/plugins/security_solution/common/api/timeline/model/api.ts
+++ b/x-pack/plugins/security_solution/common/api/timeline/model/api.ts
@@ -15,12 +15,31 @@ import { Direction } from '../../../search_strategy';
import type { PinnedEvent } from '../pinned_events/pinned_events_route';
import { PinnedEventRuntimeType } from '../pinned_events/pinned_events_route';
// TODO https://github.com/elastic/security-team/issues/7491
-// eslint-disable-next-line no-restricted-imports
-import {
- SavedObjectResolveAliasPurpose,
- SavedObjectResolveAliasTargetId,
- SavedObjectResolveOutcome,
-} from '../../detection_engine/model/rule_schema_legacy';
+
+/**
+ * Outcome is a property of the saved object resolve api
+ * will tell us info about the rule after 8.0 migrations
+ */
+export type SavedObjectResolveOutcome = runtimeTypes.TypeOf;
+export const SavedObjectResolveOutcome = runtimeTypes.union([
+ runtimeTypes.literal('exactMatch'),
+ runtimeTypes.literal('aliasMatch'),
+ runtimeTypes.literal('conflict'),
+]);
+
+export type SavedObjectResolveAliasTargetId = runtimeTypes.TypeOf<
+ typeof SavedObjectResolveAliasTargetId
+>;
+export const SavedObjectResolveAliasTargetId = runtimeTypes.string;
+
+export type SavedObjectResolveAliasPurpose = runtimeTypes.TypeOf<
+ typeof SavedObjectResolveAliasPurpose
+>;
+export const SavedObjectResolveAliasPurpose = runtimeTypes.union([
+ runtimeTypes.literal('savedObjectConversion'),
+ runtimeTypes.literal('savedObjectImport'),
+]);
+
import { ErrorSchema } from './error_schema';
export const BareNoteSchema = runtimeTypes.intersection([