-
Notifications
You must be signed in to change notification settings - Fork 587
[FR] [DAC] Add Arbitrary File location Support for Local Creation Date #4915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[FR] [DAC] Add Arbitrary File location Support for Local Creation Date #4915
Conversation
Enhancement - GuidelinesThese guidelines serve as a reminder set of considerations when addressing adding a feature to the code. Documentation and Context
Code Standards and Practices
Testing
Additional Checks
|
…ort-for-local-creation-date
detection_rules/rule_loader.py
Outdated
|
||
rule_contents = RuleCollection().load_file(rule_path).contents | ||
if not rule_path and not local_contents: | ||
raise ValueError("Either 'rule_path' or 'local_contents' must be provided.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙇🏻♂️
…ort-for-local-creation-date
input_rule_id: str | None = None | ||
|
||
if local_rule: | ||
input_rule_id = cast("definitions.UUIDString", local_rule.get("rule_id")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May want to switch to constructor here. (request from peer review)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as a note, cast is more performant (as it does not create a UUID string object whereas the constructor would). Additionally, there is no constructor for the UUIDString type in definitions. UUIDString is an alias and as such does not have a constructor.
…ort-for-local-creation-date
Pull Request
Issue link(s):
Resolves #4891
Summary - What I changed
Added the ability to specify
--load-rule-loading / -lr
to thekibana export-rules
andimport-rules-to-repo
commands. This enables one to make use of the local folders specified in one'sconfig.yaml
when exporting rules from Kibana to the repo.For instance, if I specify
And have two rules
dac_test/rules/my_test_rule.toml
dac_test/another_rules_dir/high_number_of_process_and_or_service_terminations.toml
Rule updates from Kibana (when using the new
-lr
option) will now use these additional paths instead of exporting directly to the specified directory.So if I run
python -m detection_rules kibana --space test_local export-rules -d dac_test/rules/ -sv -ac -e -lr
in a space with those two rules,my_test_rule.toml
will be written todac_test/rules/
as it was already on disk there andhigh_number_of_process_and_or_service_terminations.toml
will be written todac_test/another_rules_dir/
for the same reason.Note: This can be very slow with a high number of rules. For instance, it can take 5-10min to load 1-2k rules in this way depending on system resources. The reason for this is the need to load the rule in from disk prior to actually exporting the rules, in order to know the appropriate path for the rule to be written.
How To Test
Run the respective
kibana export-rules
andimport-rules-to-repo
commands with some rules already existing in different directories specified in the custom rules config yaml.e.g.
Checklist
bug
,enhancement
,schema
,maintenance
,Rule: New
,Rule: Deprecation
,Rule: Tuning
,Hunt: New
, orHunt: Tuning
so guidelines can be generatedmeta:rapid-merge
label if planning to merge within 24 hoursContributor checklist