Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Add mapping version check before executing EQL rules (#79553) #79802

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import signalsMapping from './signals_mapping.json';
import ecsMapping from './ecs_mapping.json';

export const getSignalsTemplate = (index: string) => {
const version = 2;
const template = {
settings: {
index: {
Expand All @@ -29,8 +30,11 @@ export const getSignalsTemplate = (index: string) => {
...ecsMapping.mappings.properties,
signal: signalsMapping.mappings.properties.signal,
},
_meta: {
version,
},
},
version: 1,
version,
};
return template;
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { Logger, KibanaRequest } from 'src/core/server';

import { get } from 'lodash';
import {
SIGNALS_ID,
DEFAULT_SEARCH_AFTER_PAGE_SIZE,
Expand Down Expand Up @@ -116,6 +117,18 @@ export const signalRulesAlertType = ({
type,
exceptionsList,
} = params;
const outputIndexTemplateMapping: unknown = await services.callCluster(
'indices.getTemplate',
{ name: outputIndex }
);
const signalMappingVersion: number | undefined = get(outputIndexTemplateMapping, [
outputIndex,
'version',
]);
if (signalMappingVersion !== undefined && typeof signalMappingVersion !== 'number') {
throw new Error('Found non-numeric value for "version" in output index template');
}

const searchAfterSize = Math.min(maxSignals, DEFAULT_SEARCH_AFTER_PAGE_SIZE);
let hasError: boolean = false;
let result = createSearchAfterReturnType();
Expand Down Expand Up @@ -436,7 +449,16 @@ export const signalRulesAlertType = ({
});
} else if (isEqlRule(type)) {
if (query === undefined) {
throw new Error('eql query rule must have a query defined');
throw new Error('EQL query rule must have a query defined');
}
const MIN_EQL_RULE_TEMPLATE_VERSION = 2;
if (
signalMappingVersion === undefined ||
signalMappingVersion < MIN_EQL_RULE_TEMPLATE_VERSION
) {
throw new Error(
`EQL based rules require an update to version ${MIN_EQL_RULE_TEMPLATE_VERSION} of the detection alerts index mapping`
);
}
const inputIndex = await getInputIndex(services, version, index);
const request = buildEqlSearchRequest(
Expand Down