Skip to content

[Bug] [DAC] The export-rules-from-repo command includes all exceptions/action connectors #5768

@eric-forte-elastic

Description

@eric-forte-elastic

Describe the Bug

When using export-rules-from-repo with --include-exceptions (-e) or --include-action-connectors (-ac), the command includes all exception lists and all action connectors from the repo in the exported NDJSON file, instead of only those whose metadata.rule_ids are associated with the rules being exported.

By contrast, kibana import-rules correctly scopes exceptions and action connectors to the rule IDs being imported (via _matches_rule_ids). Export should mirror that behavior so that a subset export (e.g. --rule-id X -e) only includes exceptions/connectors linked to the exported rules.

To Reproduce

  1. Have a repo with multiple rules and multiple exception lists (and/or action connectors), where different rules reference different exceptions.
  2. Export a subset of rules with exceptions:
    python -m detection_rules export-rules-from-repo --rule-id <one-rule-id> -e -o subset.ndjson
  3. Inspect the NDJSON: it contains every exception list in the repo, not only the one(s) linked to <one-rule-id>.

Expected Behavior

  • When --include-exceptions is used, only exception lists whose metadata.rule_ids intersect with the set of exported rule IDs should be included in the NDJSON.
  • When --include-action-connectors is used, only action connectors whose metadata.rule_ids intersect with the set of exported rule IDs should be included.
  • Full-repo export (no --rule-id filter) should still include all exceptions/connectors that are linked to any of the exported rules (unchanged in practice when exporting all rules).

Screenshots

No response

Desktop - OS

None

Desktop - Version

No response

Additional Context

  • Can use same fix from [Bug] Fix Filter Support for Import Rules #4852 to address
  • Same rule-ID association is used in exception/connector TOML: metadata.rule_ids (and in kbwrap, _matches_rule_ids). Centralizing this in generic_loader.matches_rule_ids keeps import and export behavior aligned and avoids duplication.

Metadata

Metadata

Labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions