Skip to content

Commit 7604c20

Browse files
[FR] Add ESQL rules to dataset exception (#5249)
* Add ESQL rules to dataset exception * Add unit test
1 parent 9345e0e commit 7604c20

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

detection_rules/index_mappings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ def get_filtered_index_schema(
261261
filtered_keys.update(non_ecs_indices.keys())
262262
filtered_keys.update(custom_indices.keys())
263263
filtered_keys.add("logs-endpoint.alerts-*")
264-
filtered_keys.update(indices)
265264

266265
matches: list[str] = []
267266
for index in indices:

detection_rules/rule.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,11 @@ def get_packaged_integrations(
15281528
*definitions.NON_DATASET_PACKAGES,
15291529
*map(str.lower, definitions.MACHINE_LEARNING_PACKAGES),
15301530
]
1531-
if integration in ineligible_integrations or isinstance(data, MachineLearningRuleData):
1531+
if (
1532+
integration in ineligible_integrations
1533+
or isinstance(data, MachineLearningRuleData)
1534+
or (isinstance(data, ESQLRuleData) and integration not in datasets)
1535+
):
15321536
packaged_integrations.append({"package": integration, "integration": None})
15331537

15341538
packaged_integrations.extend(parse_datasets(list(datasets), package_manifest))

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.4"
3+
version = "1.5.5"
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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ def test_esql_related_integrations(self):
4646
for integration in related_integrations:
4747
assert integration["package"] == "aws", f"Expected 'aws', but got {integration['package']}"
4848

49+
def test_esql_non_dataset_package_related_integrations(self):
50+
"""Test an ESQL rule has its related integrations built correctly with a non dataset package."""
51+
file_path = get_path(["tests", "data", "command_control_dummy_production_rule.toml"])
52+
original_production_rule = load_rule_contents(file_path)
53+
production_rule = deepcopy(original_production_rule)[0]
54+
production_rule["metadata"]["integration"] = ["aws_bedrock"]
55+
production_rule["rule"]["query"] = """
56+
from logs-aws_bedrock.invocation-* metadata _id, _version, _index
57+
// Filter for access denied errors from GenAI responses
58+
| where gen_ai.response.error_code == "AccessDeniedException"
59+
// keep ECS and response fields
60+
| keep
61+
user.id,
62+
gen_ai.request.model.id,
63+
cloud.account.id,
64+
gen_ai.response.error_code
65+
"""
66+
rule = RuleCollection().load_dict(production_rule)
67+
related_integrations = rule.contents.to_api_format()["related_integrations"]
68+
for integration in related_integrations:
69+
assert integration["package"] == "aws_bedrock", f"Expected 'aws_bedrock', but got {integration['package']}"
70+
4971
def test_esql_event_dataset_schema_error(self):
5072
"""Test an ESQL rule that uses event.dataset field in the query that restricts the schema failing validation."""
5173
file_path = get_path(["tests", "data", "command_control_dummy_production_rule.toml"])

0 commit comments

Comments
 (0)