-
Notifications
You must be signed in to change notification settings - Fork 513
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
[Bug] [DaC] Metadata maturity field default mismatch and poor enforcement of rule naming conventions #4285
base: main
Are you sure you want to change the base?
Conversation
Bug - GuidelinesThese guidelines serve as a reminder set of considerations when addressing a bug in the code. Documentation and Context
Code Standards and Practices
Testing
Additional Checks
|
rules = RuleCollection() | ||
rules.load_file(directory / f"{rule_name}") | ||
if rules: | ||
maturity = rules.rules[0].contents.metadata.maturity |
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.
I may be reading this wrong.
- For a given rule, get the first tactic and build expected file naming convention
- If that rule exists, initialize rule collection and load that specific rule
- If we successfully load that rule, overwrite maturity with what the rule has statically defined
- Overwrite the updated and created dates by formatting what is statically in the fine --> Is this necessary?
Other than my question on 4. it looks good to me.
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.
For question 4, short answer is no. This is not necessary and we may not want to do it, looking for input as to other's thoughts on this. More context from the PR summary above.
There is also an update that we may or may not want to include that is currently in this PR which, in addition to maturity, the creation and modified dates are now inherited from the file if they exist, and if not, the dates from Kibana are used. However, as this represents a potential change to how dates are calculated (before the date is specific to the date that the rule existed on disk in the repo) we may or may not want to include these changes and I would ask reviewers to leave their thoughts on this change in the PR.
click.secho( | ||
f"WARNING: Rule path does not match required path: {rule.path.name} != {rule_name}", fg="yellow" | ||
) |
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.
Is click the best option we have without adding new dependencies for warnings?
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.
We do not have a logging standard for Detection Rules as far as I am aware, and each entry point for the CLI commands uses click. Other than introducing something new that would break current convention, I do not see a strong alternative, but certainly open to suggestions.
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.
Couple of questions. Otherwise looks good to me.
Pull Request
Issue link(s):
Resolves #4282
Summary - What I changed
In this PR I added explicit warnings when the rule file path does not match the expected path convention as if the rule was created via Kibana or the Detection Rules CLI rule prompt. This check occurs when the rules are added to a collection in the
kibana import-rules
and theexport-rules-from-repo
logic. The other routes assign the filename using the expected convention. This check simply compares the real path with what the constructed path would be if the rule was being written to the repo. If these do not match, it writes a warning message via click.Additionally, this PR addresses a bug where if a rule already exists in the repo, the maturity metadata field may change unexpectedly depending on the import path one uses. Originally, the default metadata value on importing rules to the repo was "development" if it came from an
.ndjson
file andproduction
if it came from Kibana. In this way, rules could move fromproduction
back todevelopment
if an.ndjson
file was used for the import instead of the Kibana CLI/API commands. This PR adds a check that if the file exists in the repo/on disk in the expected location, it will instead use the existing maturity value; otherwise, it will default todevelopment
There is also an update that we may or may not want to include that is currently in this PR which, in addition to maturity, the creation and modified dates are now inherited from the file if they exist, and if not, the dates from Kibana are used. However, as this represents a potential change to how dates are calculated (before the date is specific to the date that the rule existed on disk in the repo) we may or may not want to include these changes and I would ask reviewers to leave their thoughts on this change in the PR.
How To Test
production
.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