Skip to content

[Bug] Threshold Rule Importing Failures #3560

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

Merged
merged 4 commits into from
Apr 3, 2024

Conversation

eric-forte-elastic
Copy link
Contributor

Issues

#3547

Summary

This PR addresses an issue where threshold rules would not import correctly as the rule prompt would ask for information that was present in the rule file instead of using what was supplied. See the original issue for the steps to reproduce the error. The fix is to remove a hardcoding loading for specifically threshold rules to load them in this way. I expect that this was done due to a historic Kibana issue that is not longer necessary.

Note: If you import a rule and then run unit tests they will fail as we have some additional tags and fields that we enforce on our rules that should not be enforced on customers. In testing this, we also found a minor flaw in one of our unit tests (test_event_override) that is also fixed here. Previously the unit test would fail on the first instance of a test violation and not produce a list of all of the rules violating the test. This fix addresses that.

Testing

  1. Export a threshold rule from Kibana
    Example: rules_export_threashold.ndjson.txt

  2. Use the importer `python -m detection_rules import-rules <file.ndjson>

  3. See that the importer no longer tries to prompt for threshold fields even though they exist in the ndjson

@eric-forte-elastic eric-forte-elastic added bug Something isn't working Area: DED labels Apr 2, 2024
@eric-forte-elastic eric-forte-elastic self-assigned this Apr 2, 2024
@eric-forte-elastic eric-forte-elastic linked an issue Apr 2, 2024 that may be closed by this pull request
@botelastic botelastic bot added the python Internal python for the repository label Apr 2, 2024
@eric-forte-elastic eric-forte-elastic changed the title [Bug] Threshold rule importing failures [Bug] Threshold Rule Importing Failures Apr 2, 2024
Copy link
Contributor

@Mikaayenson Mikaayenson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the issue to do larger refactors later, I think this makes sense.

@@ -973,7 +973,7 @@ def test_event_override(self):
# TODO: determine if we expand this to ES|QL
# ignores any rule that does not use EQL or KQL queries specifically
# this does not avoid rule types where variants of KQL are used (e.g. new terms)
if rule_language not in ('eql', 'kuery') or rule.contents.data.is_sequence:
if rule_language not in ('eql', 'kuery') or getattr(rule.contents.data, 'is_sequence', False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

@shashank-elastic
Copy link
Contributor

🟢 Testing Looks Good.

Ran Import Rule of the test file.
threshold fields were not prompted by the importer

python -m detection_rules import-rules ~/Downloads/rules_export_threashold.ndjson 

█▀▀▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄   ▄      █▀▀▄ ▄  ▄ ▄   ▄▄▄ ▄▄▄
█  █ █▄▄  █  █▄▄ █    █   █  █ █ █▀▄ █      █▄▄▀ █  █ █   █▄▄ █▄▄
█▄▄▀ █▄▄  █  █▄▄ █▄▄  █  ▄█▄ █▄█ █ ▀▄█      █ ▀▄ █▄▄█ █▄▄ █▄▄ ▄▄█

[+] Building rule for /Users/shashankks/elastic_workspace/detection-rules/rules/test_threshold.toml
actions (multi, comma separated): 
alert_suppression: 
author (required)  (multi, comma separated): Elastic
building_block_type: 
data_view_id: 
exceptions_list (multi, comma separated): 
false_positives (multi, comma separated): 
filters (multi, comma separated): 
license: 
note: 
references (multi, comma separated): 
related_integrations (multi, comma separated): 
required_fields (multi, comma separated): 
risk_score_mapping (multi, comma separated): 
rule_name_override: 
setup: 
severity_mapping (multi, comma separated): 
tags (multi, comma separated): 
add mitre tactic? [y/N]: 
throttle: 
timeline_id: 
timeline_title: 
timestamp_override: 
(.venv) 

File creation

image

@eric-forte-elastic eric-forte-elastic merged commit a9cc323 into main Apr 3, 2024
@eric-forte-elastic eric-forte-elastic deleted the 3547-bug-threshold-rule-importing-failures branch April 3, 2024 18:15
protectionsmachine pushed a commit that referenced this pull request Apr 3, 2024
* remove threshold specific req

* fix test event override

---------

Co-authored-by: shashank-elastic <91139415+shashank-elastic@users.noreply.github.com>

(cherry picked from commit a9cc323)
protectionsmachine pushed a commit that referenced this pull request Apr 3, 2024
* remove threshold specific req

* fix test event override

---------

Co-authored-by: shashank-elastic <91139415+shashank-elastic@users.noreply.github.com>

(cherry picked from commit a9cc323)
protectionsmachine pushed a commit that referenced this pull request Apr 3, 2024
* remove threshold specific req

* fix test event override

---------

Co-authored-by: shashank-elastic <91139415+shashank-elastic@users.noreply.github.com>

(cherry picked from commit a9cc323)
protectionsmachine pushed a commit that referenced this pull request Apr 3, 2024
* remove threshold specific req

* fix test event override

---------

Co-authored-by: shashank-elastic <91139415+shashank-elastic@users.noreply.github.com>

(cherry picked from commit a9cc323)
protectionsmachine pushed a commit that referenced this pull request Apr 3, 2024
* remove threshold specific req

* fix test event override

---------

Co-authored-by: shashank-elastic <91139415+shashank-elastic@users.noreply.github.com>

(cherry picked from commit a9cc323)
protectionsmachine pushed a commit that referenced this pull request Apr 3, 2024
* remove threshold specific req

* fix test event override

---------

Co-authored-by: shashank-elastic <91139415+shashank-elastic@users.noreply.github.com>

(cherry picked from commit a9cc323)
protectionsmachine pushed a commit that referenced this pull request Apr 3, 2024
* remove threshold specific req

* fix test event override

---------

Co-authored-by: shashank-elastic <91139415+shashank-elastic@users.noreply.github.com>

(cherry picked from commit a9cc323)
protectionsmachine pushed a commit that referenced this pull request Apr 3, 2024
* remove threshold specific req

* fix test event override

---------

Co-authored-by: shashank-elastic <91139415+shashank-elastic@users.noreply.github.com>

(cherry picked from commit a9cc323)
protectionsmachine pushed a commit that referenced this pull request Apr 3, 2024
* remove threshold specific req

* fix test event override

---------

Co-authored-by: shashank-elastic <91139415+shashank-elastic@users.noreply.github.com>

(cherry picked from commit a9cc323)
protectionsmachine pushed a commit that referenced this pull request Apr 3, 2024
* remove threshold specific req

* fix test event override

---------

Co-authored-by: shashank-elastic <91139415+shashank-elastic@users.noreply.github.com>

(cherry picked from commit a9cc323)
protectionsmachine pushed a commit that referenced this pull request Apr 3, 2024
* remove threshold specific req

* fix test event override

---------

Co-authored-by: shashank-elastic <91139415+shashank-elastic@users.noreply.github.com>

(cherry picked from commit a9cc323)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport: auto bug Something isn't working python Internal python for the repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Threshold Rule Importing Failures [Bug] CLI Command import-rules Prompts Threshold Related Values to be Submitted
3 participants