Skip to content

Commit e60cfa0

Browse files
authored
[Security Solution][Detections] Convert EQL validation to use search strategy (#79538)
* Rename types from the top-level plugin These are the same types with a different name. However, the benefit is that they exist in a non-restricted path (the top level of the plugin). * Convert our validation function to use the EQL search strategy Rather than calling our custom EQL validation endpoint, we can instead leverage the EQL search strategy. The downside is that we have to move our response parsing logic to the frontend, but the benefit is that there's no backend to maintain. * Remove server code related to our EQL validation endpoint We're keeping our io-ts schemas for now since they're still being used to type the I/O of our client function. * Add the data contract to our KibanaServices I'm not aware of a way to pass react context to the form lib validator functions, so for now we have to pass this the ugly way :( * Remove io-ts types corresponding to our defunct validation endpoint We were keeping these around for the types, but they're so simple that it's really not worth the overhead. The tests are similarly for functionality that is no longer used, so no hard feelings there. * Ensure that our validation does not bother generating hits We only care about the query's validity, so we can tell the response handler to do less work here. * Pass transport options when retrieving an existing search Without passing transport options to .get, a query with an `ignore` would succeed if it completed in the `waitForCompletionTimeout` window, but fail (with the ignored error) on the subsequent request if it became async. * Use constant for our strategy key * Export search strategy constants for client consumption Common values cannot be consumed directly by client code (compilation error), so we need to re-export them from data_enhanced's public module.
1 parent 641f2cc commit e60cfa0

File tree

22 files changed

+70
-363
lines changed

22 files changed

+70
-363
lines changed

x-pack/plugins/data_enhanced/public/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ import { DataEnhancedPlugin, DataEnhancedSetup, DataEnhancedStart } from './plug
99
export const plugin = () => new DataEnhancedPlugin();
1010

1111
export { DataEnhancedSetup, DataEnhancedStart };
12+
13+
export { ENHANCED_ES_SEARCH_STRATEGY, EQL_SEARCH_STRATEGY } from '../common';

x-pack/plugins/data_enhanced/server/search/eql_search_strategy.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ describe('EQL search strategy', () => {
163163
})
164164
);
165165
});
166+
167+
it('passes transport options for an existing request', async () => {
168+
const eqlSearch = await eqlSearchStrategyProvider(mockLogger);
169+
await eqlSearch.search(mockContext, { id: 'my-search-id', options: { ignore: [400] } });
170+
const [[, requestOptions]] = mockEqlGet.mock.calls;
171+
172+
expect(mockEqlSearch).not.toHaveBeenCalled();
173+
expect(requestOptions).toEqual(expect.objectContaining({ ignore: [400] }));
174+
});
166175
});
167176
});
168177
});

x-pack/plugins/data_enhanced/server/search/eql_search_strategy.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ export const eqlSearchStrategyProvider = (
3232
const eqlClient = context.core.elasticsearch.client.asCurrentUser.eql;
3333
const uiSettingsClient = await context.core.uiSettings.client;
3434
const asyncOptions = getAsyncOptions();
35+
const searchOptions = toSnakeCase({ ...request.options });
3536

3637
if (request.id) {
37-
promise = eqlClient.get({
38-
id: request.id,
39-
...toSnakeCase(asyncOptions),
40-
});
38+
promise = eqlClient.get(
39+
{
40+
id: request.id,
41+
...toSnakeCase(asyncOptions),
42+
},
43+
searchOptions
44+
);
4145
} else {
4246
const { ignoreThrottled, ignoreUnavailable } = await getDefaultSearchParams(
4347
uiSettingsClient
@@ -48,11 +52,10 @@ export const eqlSearchStrategyProvider = (
4852
...asyncOptions,
4953
...request.params,
5054
});
51-
const searchOptions = toSnakeCase({ ...request.options });
5255

5356
promise = eqlClient.search(
5457
searchParams as EqlSearchStrategyRequest['params'],
55-
searchOptions as EqlSearchStrategyRequest['options']
58+
searchOptions
5659
);
5760
}
5861

x-pack/plugins/security_solution/common/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ export const DETECTION_ENGINE_PREPACKAGED_URL = `${DETECTION_ENGINE_RULES_URL}/p
117117
export const DETECTION_ENGINE_PRIVILEGES_URL = `${DETECTION_ENGINE_URL}/privileges`;
118118
export const DETECTION_ENGINE_INDEX_URL = `${DETECTION_ENGINE_URL}/index`;
119119
export const DETECTION_ENGINE_TAGS_URL = `${DETECTION_ENGINE_URL}/tags`;
120-
export const DETECTION_ENGINE_EQL_VALIDATION_URL = `${DETECTION_ENGINE_URL}/validate_eql`;
121120
export const DETECTION_ENGINE_RULES_STATUS_URL = `${DETECTION_ENGINE_RULES_URL}/_find_statuses`;
122121
export const DETECTION_ENGINE_PREPACKAGED_RULES_STATUS_URL = `${DETECTION_ENGINE_RULES_URL}/prepackaged/_status`;
123122

x-pack/plugins/security_solution/common/detection_engine/schemas/request/eql_validation_schema.test.ts

Lines changed: 0 additions & 59 deletions
This file was deleted.

x-pack/plugins/security_solution/common/detection_engine/schemas/request/eql_validation_schema.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

x-pack/plugins/security_solution/common/detection_engine/schemas/response/eql_validation_schema.mock.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

x-pack/plugins/security_solution/common/detection_engine/schemas/response/eql_validation_schema.test.ts

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,4 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import * as t from 'io-ts';
8-
9-
export const eqlValidationSchema = t.exact(
10-
t.type({
11-
valid: t.boolean,
12-
errors: t.array(t.string),
13-
})
14-
);
15-
16-
export type EqlValidationSchema = t.TypeOf<typeof eqlValidationSchema>;
7+
export * from './validation';

0 commit comments

Comments
 (0)