-
Notifications
You must be signed in to change notification settings - Fork 609
[Bug] Add synthetic properties check to remote ESQL validation #5308
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
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
|
Mikaayenson
left a comment
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.
Might be good to add a test case with the exact scenario from the PR description:
- Integration schema: "azure.signinlogs.properties.authentication_details": "flattened"
- Non-ECS schema: "azure.signinlogs.properties.authentication_details.authentication_method": "keyword"
- Verify that after merging and pruning, the flattened field's properties key is correctly removed.
What about edge cases:
- Fields with
.fields.in the path - Fields at different nesting levels
- Multiple flattened fields in the same schema
Also, can we verify delete_nested_key_from_dict works correctly with the constructed paths above.
|
Added unit test for conflicts between schema. In this case, we only need to test for integration schema and non_ecs conflicts. The parsing/pruning logic has been updated such that these are the only two logical paths where pruning occurs.
The reason for the complexity for this kind of validation support is to support the field type not supported errors like this: Which required the proper index mapping to be built and checked independent from what is specified in non_ecs, as this error is specific to ES|QL rules. We need the index mapping to be built and pushed even if ES|QL does not support it so that we can get the specific type error (e.g. |
|
Updated test results with the prune removal/re-structure and list comprehension: |
|
Updated Unit Test with new unit Test: Unit test running on main without ES|QL rules (tests that just the unit test can catch the error and not dependent on a specific rule) |
shashank-elastic
left a comment
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.
Manually Checked. Things are good
detection-rules on 5306-bug-esql-schema-field-pruning [$?] is 📦 v1.5.9 via 🐍 v3.12.8 (.venv) on ☁️ shashank.suryanarayana@elastic.co took 6s
❯ python -m detection_rules dev test esql-remote-validation
Loaded config file: /Users/shashankks/elastic_workspace/detection-rules/.detection-rules-cfg.json
█▀▀▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄ ▄ █▀▀▄ ▄ ▄ ▄ ▄▄▄ ▄▄▄
█ █ █▄▄ █ █▄▄ █ █ █ █ █ █▀▄ █ █▄▄▀ █ █ █ █▄▄ █▄▄
█▄▄▀ █▄▄ █ █▄▄ █▄▄ █ ▄█▄ █▄█ █ ▀▄█ █ ▀▄ █▄▄█ █▄▄ █▄▄ ▄▄█
/Users/shashankks/elastic_workspace/detection-rules/detection_rules/index_mappings.py:367: ElasticsearchWarning: No limit defined, adding default limit of [1000]
response = elastic_client.esql.query(query=query)
/Users/shashankks/elastic_workspace/detection-rules/detection_rules/index_mappings.py:367: ElasticsearchWarning: Line 57:5: Field 'Esql.azure_signinlogs_result_description_values' shadowed by field at line 64:5
response = elastic_client.esql.query(query=query)
ESQL rules loaded: 67
Total rules: 67
Failed rules: 0
Failed rules written to failed_rules.log
|
Backport Checks 🟢 Detailsdetection-rules on 5306-bug-esql-schema-field-pruning is v1.5.9 via on eric.forte
❯ git checkout 8.19 -- rules_building_block
detection-rules on 5306-bug-esql-schema-field-pruning is v1.5.9 via on eric.forte
❯ git checkout 8.19 -- rules
detection-rules on 5306-bug-esql-schema-field-pruning [+] is v1.5.9 via on eric.forte
❯ source env/detection-rules-build/bin/activate.fish
detection-rules on 5306-bug-esql-schema-field-pruning [+] is v1.5.9 via v3.12.12 (detection-rules-build) on eric.forte
❯ export DR_REMOTE_ESQL_VALIDATION=True
detection-rules on 5306-bug-esql-schema-field-pruning [+] is v1.5.9 via v3.12.12 (detection-rules-build) on eric.forte
❯ python -m detection_rules dev test esql-remote-validation
Loaded config file: /tmp/detection-rules/.detection-rules-cfg.json
█▀▀▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄ ▄ █▀▀▄ ▄ ▄ ▄ ▄▄▄ ▄▄▄
█ █ █▄▄ █ █▄▄ █ █ █ █ █ █▀▄ █ █▄▄▀ █ █ █ █▄▄ █▄▄
█▄▄▀ █▄▄ █ █▄▄ █▄▄ █ ▄█▄ █▄█ █ ▀▄█ █ ▀▄ █▄▄█ █▄▄ █▄▄ ▄▄█
Total rules: 67
Failed rules: 0
Failed rules written to failed_rules.logIn branches 9.0 and onward, there are no rule differences in the packages so the test from main is equivalent: detection-rules on 5306-bug-esql-schema-field-pruning is v1.5.9 via v3.12.12 (detection-rules-build) on eric.forte
❯ git checkout 9.0 -- rules_building_block
detection-rules on 5306-bug-esql-schema-field-pruning is v1.5.9 via v3.12.12 (detection-rules-build) on eric.forte
❯ git checkout 9.0 -- rules
detection-rules on 5306-bug-esql-schema-field-pruning is v1.5.9 via v3.12.12 (detection-rules-build) on eric.forte
❯ git status
On branch 5306-bug-esql-schema-field-pruning
Your branch is up to date with 'origin/5306-bug-esql-schema-field-pruning'.
nothing to commit, working tree clean
detection-rules on 5306-bug-esql-schema-field-pruning is v1.5.9 via v3.12.12 (detection-rules-build) on eric.forte
❯ git checkout 9.1 -- rules_building_block
detection-rules on 5306-bug-esql-schema-field-pruning is v1.5.9 via v3.12.12 (detection-rules-build) on eric.forte
❯ git checkout 9.1 -- rules
detection-rules on 5306-bug-esql-schema-field-pruning is v1.5.9 via v3.12.12 (detection-rules-build) on eric.forte
❯ git status
On branch 5306-bug-esql-schema-field-pruning
Your branch is up to date with 'origin/5306-bug-esql-schema-field-pruning'.
nothing to commit, working tree clean
detection-rules on 5306-bug-esql-schema-field-pruning is v1.5.9 via v3.12.12 (detection-rules-build) on eric.forte
❯ git checkout 9.2 -- rules_building_block
detection-rules on 5306-bug-esql-schema-field-pruning is v1.5.9 via v3.12.12 (detection-rules-build) on eric.forte
❯ git checkout 9.2 -- rules
detection-rules on 5306-bug-esql-schema-field-pruning is v1.5.9 via v3.12.12 (detection-rules-build) on eric.forte
❯ git status
On branch 5306-bug-esql-schema-field-pruning
Your branch is up to date with 'origin/5306-bug-esql-schema-field-pruning'.
nothing to commit, working tree clean
detection-rules on 5306-bug-esql-schema-field-pruning is v1.5.9 via v3.12.12 (detection-rules-build) on eric.forte
❯
|
Mikaayenson
left a comment
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.
🚢


Pull Request
Issue link(s): #5306
Summary - What I changed
While #5256 fixed an issue where non-ecs schemas were not being loaded in to the proper indexes, this can cause issues where on certain indexs where the merging of non-ecs and the integration schema can cause artificial conflicts.
For instance in the example run:
What was once a non-nested flattened field from the intgration:
"azure.signinlogs.properties.authentication_details": "flattened"gets merged with:
"azure.signinlogs.properties.authentication_details.authentication_method": "keyword",which then causes it to become a nested field. As such, pruning needs to happen again after merging. However, the pruning logic also needed to be updated to handle cases where flattened fields can have keywords which can occur as the result of an artificial merge of non-ecs and the integration in the index. While having properties on flattened fields is supported (see docs), typically (so far as we've encountered) integrations use the
.fieldsparameter instead, so we were only checking for the.fieldsparamter to determine if a nested field had "fields" instead of checking for both.fieldsand.properties.Example Run Error.
Note: this only will occur if a rule with a specific index pattern that can cause this is used, as the schema is filtered beforehand by index.
How To Test
Run the
python -m detection_rules dev test esql-remote-validationcommand with a local/remote stack and observe no errorsAlso pull in the rule from #5305 and then re-run the test. (included below)
defense_evasion_masquerading_as_svchost.toml.txt
Checklist
bug,enhancement,schema,maintenance,Rule: New,Rule: Deprecation,Rule: Tuning,Hunt: New, orHunt: Tuningso guidelines can be generatedmeta:rapid-mergelabel if planning to merge within 24 hoursContributor checklist