Skip to content

Commit 634de61

Browse files
[FR] ES|QL remote validation support newline split indices (#5356)
* Updated regex pattern for multiline * Add line split unit test
1 parent 0e67a02 commit 634de61

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

detection_rules/schemas/definitions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ def validator_wrapper(value: Any) -> Any:
7676
CONDITION_VERSION_PATTERN = re.compile(rf"^\^{_version}$")
7777
VERSION_PATTERN = f"^{_version}$"
7878
MINOR_SEMVER = re.compile(r"^\d+\.\d+$")
79-
FROM_SOURCES_REGEX = re.compile(r"^\s*FROM\s+(?P<sources>.+?)\s*(?:\||\bmetadata\b|//|$)", re.IGNORECASE | re.MULTILINE)
79+
FROM_SOURCES_REGEX = re.compile(
80+
r"^\s*FROM\s+(?P<sources>(?:.+?(?:,\s*)?\n?)+?)\s*(?:\||\bmetadata\b|//|$)", re.IGNORECASE | re.MULTILINE
81+
)
8082
BRANCH_PATTERN = f"{VERSION_PATTERN}|^master$"
8183
ELASTICSEARCH_EQL_FEATURES = {
8284
"allow_negation": (Version.parse("8.9.0"), None),

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "detection_rules"
3-
version = "1.5.17"
3+
version = "1.5.18"
44
description = "Detection Rules is the home for rules used by Elastic Security. This repository is used for the development, maintenance, testing, validation, and release of rules for Elastic Security’s Detection Engine."
55
readme = "README.md"
66
requires-python = ">=3.12"

tests/test_rules_remote.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,22 @@ def test_esql_filtered_index_error(self):
155155
with pytest.raises(EsqlSchemaError):
156156
_ = RuleCollection().load_dict(production_rule)
157157

158+
def test_new_line_split_index(self):
159+
"""Test an ESQL rule's index validation to ensure that it can handle new line split indices."""
160+
file_path = get_path(["tests", "data", "command_control_dummy_production_rule.toml"])
161+
original_production_rule = load_rule_contents(file_path)
162+
production_rule = deepcopy(original_production_rule)[0]
163+
production_rule["metadata"]["integration"] = ["aws"]
164+
production_rule["rule"]["query"] = """
165+
from logs-aws.cloud*, logs-network_traffic.http-*,
166+
logs-nginx.access-* metadata _id, _version, _index
167+
| where @timestamp > now() - 30 minutes
168+
and aws.cloudtrail.user_identity.type == "IAMUser"
169+
| keep
170+
aws.*
171+
"""
172+
_ = RuleCollection().load_dict(production_rule)
173+
158174
def test_esql_endpoint_alerts_index(self):
159175
"""Test an ESQL rule's schema validation using ecs fields in the alerts index."""
160176
file_path = get_path(["tests", "data", "command_control_dummy_production_rule.toml"])

0 commit comments

Comments
 (0)