-
Notifications
You must be signed in to change notification settings - Fork 529
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
[FR] Refactor to more seamlessly support multiple DAC approaches #3407
[FR] Refactor to more seamlessly support multiple DAC approaches #3407
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
If a customer wants to apply the same rule to multiple Imagine I want some rules applied to one stack vs another (organized by folder). I think based what's available so far, a user could create Subsequently, if they had to make a change to that common file, would then then have to update each instance in every subfolder? Similarily, for |
This comment was marked as resolved.
This comment was marked as resolved.
Note: If we have people manage a separate stack-schema-map, will they also have to manage schema and manifest updates? |
BYOS (schema) within the directories for integrations, etc. |
Remember, think of the repo and stack updates as completely decoupled. Meaning, if they wanted to push to multiple stacks, the could test once, and push the same folder 3 different times via a single CI/CD workflow. If the idea is to have 3 unique sets of rules, then yes, by design, 3 directories and config sets. In this scenario, they can handle shared rules using git
This is a good call out - either they will need to get us to approve it, where it would be globally accessible. Or, even better, we update this process to allow the custom dir to portably include schemas too |
FWIW, #3430 is another example of why we may want to enable custom schemas. We have an instance where we need to leverage the integration name to populate related integrations, but aren't using the integration for schema validation since we dont use new fields from the integration. In this case, we may not need it in our repo, but others may. |
@brokensound77 Is it true to say that a user has to change their auth config file or environment variables in between deploying to different environments? It seems like an easy enabler would be to allow them to specify environment for credentials in the auth config or maybe have the custom rules directory discern the correct credentials based on prefix or something? Id want to just run |
…ions [FR] Add support to decouple actions and exceptions
…-validation [FR] Add support for configurable tests and validation
# Conflicts: # detection_rules/devtools.py # detection_rules/packaging.py # tests/test_all_rules.py
This comment was marked as resolved.
This comment was marked as resolved.
Thanks for the feedback @Mikaayenson
agree, but in a subsequent PR (or better, targeting main) (🏈 )
not a bad idea but out of scope. I would consider adding that targeting main, and just allow the CLI to be launched with
refer to my previous comment here:
folder structure is dictated by users, especially since the loader is recursive. There is nothing special we need to do to support it. In fact, I think a better approach is using a filter in the loader to handle those, based on the data
this was also already answered in my previous comment:
🏈
From my previous 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.
Great peer review 👍
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.
# Conflicts: # detection_rules/cli_utils.py # detection_rules/rule.py # detection_rules/rule_loader.py # docs/developing.md
Note: this will be merged into the
DAC-feature
branch (with future consideration for going into main)Issues
resolves #1342
resolves #1738
The changes encompassed in this PR are primarily to enable detections-as-code adoption more seamlessly. This is being achieved mostly through decoupling of major components. These changes are considered a major refactor to the existing functionality of the repo (and detection-rules processes). As such, these will be merging to an intermediate
DAC-feature
branch (along with subsequent PRs) to ensure implementation is accurate and nothing major is breaking.Add custom rule directory support
Summary
This adds support to allow all a custom rule directory to be supplied via the environment variable
DETECTION_RULES_DIR
, which exposes most testing, loading, and building functionality of the repo (there are still internal things specific for this repo and internal Elastic team).Details
The portability of the rules dir is accomplished via a few changes:
RulesConfig
)_config.yaml
file to point to the proper files.DETECTION_RULES_DIR
Steps to configure custom directory
_config.yaml
to the root of the custom rules directoryDETECTION_RULES_DIR
custom-rules/_config.yaml
with:deprecated_rules: etc/deprecated_rules.json
packages: etc/packages.yml
stack_schema_map: etc/stack-schema-map.yaml
version_lock: etc/version.lock.json
CUSTOM_RULES_DIR=custom-rules make test
orCUSTOM_RULES_DIR=custom-rules python -m detection_rules test
config to opt out of unit tests and bypass query validation
Summary
This exposes a config file approach to opting in and out of existing unit tests and query validation.
Details
A test config is defined and passed within the
_config.yaml
or via a direct environment variable. From there glob patterns can be used to opt in (test_only
) or opt out (bypass
) or unit tests by pattern name.Additionally, rules can bypass query validation by their
rule_id
validation for exception_lists and actions
Summary
Adds objects for exception_lists and actions for basic validation
Details
The dataclasses are equivelent to the
Rule
and related classes hierarchical structure. For now, that is the limit of the support. We can look to stitching them in a subsequent PROther updates
GenericCollection
for loading and managing actions and exception listsFor more details, refer to the
docs/custom-rules.md
Testing
setup a custom dir like:
make test
for all combinations