-
Notifications
You must be signed in to change notification settings - Fork 564
[FR] [DAC] Import Exceptions from API Export and ndjson #3869
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
Conversation
Note this PR has a minor update to the schemas and GenericLoader. The prior _assert_new for the GenericLoader assumes that each item will have a unique name and ID, which the Kibana schema does not enforce. If you write a new Exceptions TOML File you do not need to provide an id as one will be generated for you. However, you do need to provide a name. As such, we remove the ID check and just kept the name check. Additionally since each Toml File represents a single Exceptions List, the list's name was added to the metadata for ease of use. |
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.
Approving ✅
Reviewed with Eric and no further questions or concerns.
Issues
#3674
Summary
This PR adds support for exporting exception lists from Kibana that are attached to rules that we export. The existing API functionality included exporting exceptions. However, these still needed to be parsed. The main logic is to handle the API response that returns the exception objects in a list after the rule objects. Some of these objects are containers while others are the exceptions in the containers, and these have to be put together after the API call. The current naming convention for rule exception list files is
{exceptions_list_id}_exceptions.toml
.This PR is the export part of that functionality.
Note: the prior exception list logic does not support importing to Kibana. This PR contains only the export logic, a separate PR: #3870 will be needed to support importing into Kibana.
Details
Current output if you attempt to import rules with exceptions list (the exceptions list does not get moved with the rule).
Additional note: while it may be desirable to also provide support for pulling exception lists when one has a .ndjson export from Kibana, this may be blocked by #3863.
Kibana API Docs
https://www.elastic.co/guide/en/security/current/exceptions-api-get-item.html
https://www.elastic.co/guide/en/security/current/exceptions-api-create-container.html
Testing
To test this code:
0. If you have not already please update your config to include actions and exception directories.
Example Config
Details
-e
flag to also export the exceptions.Example Command:
python -m detection_rules kibana export-rules -d custom_rules/rules -s -sv -e
Note: Depending on how many custom rules you have in your Kibana instance, your numbers may be slightly different.
Expected Output
detection-rules on 3674-frdac-add-exceptions-importing-from-ndjson [!?] is v0.1.0 via v3.12.4 (detection-rules-build) on eric.forte took 2s
❯ python -m detection_rules kibana export-rules -d custom_rules/rules -s -sv -e
Loaded config file: /home/forteea1/Code/clean_mains/detection-rules/.detection-rules-cfg.json
█▀▀▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄ ▄ █▀▀▄ ▄ ▄ ▄ ▄▄▄ ▄▄▄
█ █ █▄▄ █ █▄▄ █ █ █ █ █ █▀▄ █ █▄▄▀ █ █ █ █▄▄ █▄▄
█▄▄▀ █▄▄ █ █▄▄ █▄▄ █ ▄█▄ █▄█ █ ▀▄█ █ ▀▄ █▄▄█ █▄▄ █▄▄ ▄▄█
8 rules exported
8 rules converted
2 exceptions exported
8 saved to custom_rules/rules
exceptions/
folder in your custom rules directory.Example Exception File Contents
Example Shared Exceptions List
Example Rule File Toml (in rules directory of custom rules dir) that is attached to the above exception list
Testing from ndjson
To test importing from ndjson run the following command with an appropriate rule export for a rule(s) that container exceptions, and see that an exceptions TOML file is created. The
-e
flag is used to specify importing exceptionspython -m detection_rules import-rules-to-repo ~/Downloads/rules_export_exception_list.ndjson -s custom_rules/rules --required-only -e
Example ndjson Export
rules_export_exception_list.ndjson.txt
Example Output