-
Notifications
You must be signed in to change notification settings - Fork 613
Description
Describe the Bug
Summary
Thanks to @SHolzhauer for finding this (see thread for more detail)! There is a mismatch in detection rules with the file naming defaults and metadata defaults.
-
In the
import-rules-to-repologic path the maturity metadata is hardcoded to development currentlymeta = {'creation_date': creation_date, 'updated_date': creation_date, 'maturity': 'development'}and the dates are hardcoded to today:creation_date = datetime.date.today().strftime("%Y/%m/%d") -
In
export-rulesthe logic path has the dates hardcoded to today as well if none provided (which there will not be from Kibana), but maturity is overwritten to be productioncontents = TOMLRuleContents.from_rule_resource(rule_resource, maturity="production")
This can cause arbitrary metadata changes in cases where the rule name does not match the expected <tactic>_<rule_name> convention, which also is not enforced outside of the CLI rule creation prompt, which some users may not use. In this case, the existing metadata in the repo will not be used and will be overridden with these defaults causing arbitrary rule file content changes depending on which path is used for the import/export.
An immediate fix could be to load all of the custom rules and check for existing metadata by rule ID, and use this if it exists. Additionally, this could be used to mitigate the rule naming convention issues. However, this could lead to significant performance degradation so we will want to put some thought into a more performant approach to accomplish the same result.
Furthermore, a warning should be printed if a rule is discovered that does not follow the expected naming convention, along with a the expected/correct file name to use.
To Reproduce
- Create a rule in detection rules, not using the rule creation CLI where the file name does not match the naming convention and where the metadata created and modified dates are a date prior to the current day.
- Import this rule into Kibana (or ndjson)
- Export this rule from Kibana (or ndjson)
- Observe that there are now 2 rules with the same rule ID. One with the correct file name and one with the original name. Additionally, observe that the created and modified dates has now been updated to today with no rule changed.
E.g.
Expected Behavior
- Create a rule in detection rules, not using the rule creation CLI where the file name does not match the naming convention and where the metadata created and modified dates are a date prior to the current day.
- Import this rule into Kibana (or ndjson)
- Export this rule from Kibana (or ndjson)
- Observe that there is only one rule, with the metadata and filename of what was originally written.
Screenshots
No response
Desktop - OS
None
Desktop - Version
No response
Additional Context
No response
