Skip to content

Commit f912d03

Browse files
Add ESQL rules to dataset exception
1 parent 9345e0e commit f912d03

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,30 @@ 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-*
57+
58+
// Filter for access denied errors from GenAI responses
59+
| where gen_ai.response.error_code == "AccessDeniedException"
60+
61+
// keep ECS and response fields
62+
| keep
63+
user.id,
64+
gen_ai.request.model.id,
65+
cloud.account.id,
66+
gen_ai.response.error_code
67+
"""
68+
rule = RuleCollection().load_dict(production_rule)
69+
related_integrations = rule.contents.to_api_format()["related_integrations"]
70+
for integration in related_integrations:
71+
assert integration["package"] == "aws_bedrock", f"Expected 'aws_bedrock', but got {integration['package']}"
72+
4973
def test_esql_event_dataset_schema_error(self):
5074
"""Test an ESQL rule that uses event.dataset field in the query that restricts the schema failing validation."""
5175
file_path = get_path(["tests", "data", "command_control_dummy_production_rule.toml"])

0 commit comments

Comments
 (0)