Skip to content

Commit e54bbb7

Browse files
[Bug] [DAC] Custom Rules Filter Discrepancy on Stacks Upgraded to 8.18 (#4945)
* Update Custom Rules KQL * Bump Patch Version * Update detection_rules/kbwrap.py Co-authored-by: Marshall Main <[email protected]> * Use or instead of and * Bump patch version * Fix results len typo --------- Co-authored-by: Marshall Main <[email protected]> (cherry picked from commit a726da5)
1 parent ad621f0 commit e54bbb7

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

detection_rules/kbwrap.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from .rule import TOMLRule, TOMLRuleContents, downgrade_contents_from_rule
3030
from .rule_loader import RawRuleCollection, RuleCollection, update_metadata_from_file
3131
from .schemas import definitions # noqa: TC001
32-
from .utils import format_command_options, rulename_to_filename
32+
from .utils import CUSTOM_RULES_KQL, format_command_options, rulename_to_filename
3333

3434
RULES_CONFIG = parse_rules_config()
3535

@@ -303,9 +303,7 @@ def kibana_export_rules( # noqa: PLR0912, PLR0913, PLR0915
303303
query = (
304304
export_query
305305
if not custom_rules_only
306-
else (
307-
f'alert.attributes.params.ruleSource.type: "internal"{f" and ({export_query})" if export_query else ""}'
308-
)
306+
else (f"({CUSTOM_RULES_KQL}){f' and ({export_query})' if export_query else ''}")
309307
)
310308

311309
results = ( # type: ignore[reportUnknownVariableType]
@@ -336,8 +334,10 @@ def kibana_export_rules( # noqa: PLR0912, PLR0913, PLR0915
336334
rules_results = results # type: ignore[reportUnknownVariableType]
337335
action_connector_results = []
338336
exception_results = []
337+
results_len = len(results) # type: ignore[reportUnknownVariableType]
339338
if kibana_include_details:
340339
# Assign counts to variables
340+
results_len = results_len - 1
341341
rules_count = results[-1]["exported_rules_count"] # type: ignore[reportUnknownVariableType]
342342
exception_list_count = results[-1]["exported_exception_list_count"] # type: ignore[reportUnknownVariableType]
343343
exception_list_item_count = results[-1]["exported_exception_list_item_count"] # type: ignore[reportUnknownVariableType]
@@ -497,7 +497,7 @@ def kibana_export_rules( # noqa: PLR0912, PLR0913, PLR0915
497497

498498
saved_action_connectors.append(action)
499499

500-
click.echo(f"{len(results)} results exported") # type: ignore[reportUnknownArgumentType]
500+
click.echo(f"{results_len} results exported") # type: ignore[reportUnknownArgumentType]
501501
click.echo(f"{len(exported)} rules converted")
502502
click.echo(f"{len(exceptions)} exceptions exported")
503503
click.echo(f"{len(action_connectors)} action connectors exported")

detection_rules/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
ROOT_DIR = CURR_DIR.parent
3535
ETC_DIR = ROOT_DIR / "detection_rules" / "etc"
3636
INTEGRATION_RULE_DIR = ROOT_DIR / "rules" / "integrations"
37+
CUSTOM_RULES_KQL = 'alert.attributes.params.ruleSource.type: "internal" or alert.attributes.params.immutable: false'
3738

3839

3940
class DateTimeEncoder(json.JSONEncoder):

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.3.21"
3+
version = "1.3.22"
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"

0 commit comments

Comments
 (0)