Skip to content

Commit

Permalink
[Bug] Fix BBR Folder Location Requirements for Specific Integrations (#…
Browse files Browse the repository at this point in the history
…3348)

* fixing bug in BBR rule folder location

* fixed export rules missing BBR rules

* adjusted directory loading

* Update tests/test_all_rules.py

Co-authored-by: Eric Forte <119343520+eric-forte-elastic@users.noreply.github.com>

---------

Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com>
Co-authored-by: Eric Forte <119343520+eric-forte-elastic@users.noreply.github.com>
  • Loading branch information
3 people committed Dec 19, 2023
1 parent b327336 commit eafec1d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 8 additions & 4 deletions detection_rules/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
from . import ecs
from .attack import matrix, tactics, build_threat_map_entry
from .rule import TOMLRule, TOMLRuleContents
from .rule_loader import RuleCollection, DEFAULT_RULES_DIR, dict_filter
from .rule_loader import (RuleCollection,
DEFAULT_RULES_DIR,
DEFAULT_BBR_DIR,
dict_filter)
from .schemas import definitions
from .utils import clear_caches, get_path

Expand Down Expand Up @@ -46,8 +49,8 @@ def get_collection(*args, **kwargs):
rules.load_directories(Path(d) for d in directories)

if rule_id:
rules.load_directory(DEFAULT_RULES_DIR, toml_filter=dict_filter(rule__rule_id=rule_id))

rules.load_directories((DEFAULT_RULES_DIR, DEFAULT_BBR_DIR),
toml_filter=dict_filter(rule__rule_id=rule_id))
if len(rules) != 1:
client_error(f"Could not find rule with ID {rule_id}")

Expand Down Expand Up @@ -80,7 +83,8 @@ def get_collection(*args, **kwargs):
rules.load_directories(Path(d) for d in directories)

if rule_id:
rules.load_directory(DEFAULT_RULES_DIR, toml_filter=dict_filter(rule__rule_id=rule_id))
rules.load_directories((DEFAULT_RULES_DIR, DEFAULT_BBR_DIR),
toml_filter=dict_filter(rule__rule_id=rule_id))
found_ids = {rule.id for rule in rules}
missing = set(rule_id).difference(found_ids)

Expand Down
5 changes: 3 additions & 2 deletions tests/test_all_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,9 @@ def test_integration_tag(self):

# checks if the rule path matches the intended integration
# excludes BBR rules
if rule_integration in valid_integration_folders:
if rule.path.parent.name not in rule_integrations and rule.path.parent.name != "bbr":
if rule_integration in valid_integration_folders and \
not hasattr(rule.contents.data, 'building_block_type'):
if rule.path.parent.name not in rule_integrations:
err_msg = f'{self.rule_str(rule)} {rule_integration} tag, path is {rule.path.parent.name}'
failures.append(err_msg)

Expand Down

0 comments on commit eafec1d

Please sign in to comment.