Processing Pipeline¶
The processing pipeline module provides the infrastructure for transforming Sigma rules before conversion.
See also
SigmaPolicy documents the effective
SigmaPolicy object, its security-sensitive settings, and how pipeline loaders
sanitize untrusted dictionary and YAML input.
ProcessingPipeline¶
- class sigma.processing.pipeline.ProcessingPipeline[source]¶
Bases:
objectA processing pipeline is configured with the transformation steps that are applied on Sigma rules and are configured by:
a backend to apply a set of base preprocessing of Sigma rules (e.g. renaming of fields).
the user in one or multiple configurations to conduct further rule transformation to adapt the rule to the environment.
A processing pipeline is instantiated once for a rule collection. Rules are processed in order of their appearance in a rule file or include order. Further, processing pipelines can be chained and contain variables that can be used from processing items.
Important: When combining multiple pipelines, the
ProcessingPipelineResolver.resolve()method should be used to respect pipeline priorities (lowest priority first). Simple addition with the+operator does not consider priorities and concatenates pipelines in the order specified. Use the resolver when you have multiple pipelines with different priority values that must be applied in a specific order.- items: list[ProcessingItem]¶
- postprocessing_items: list[QueryPostprocessingItem]¶
- vars: dict[str, Any]¶
- priority: int = 0¶
- name: str | None = None¶
- allowed_backends: frozenset[str]¶
- policy: SigmaPolicy | None = None¶
- applied: list[bool]¶
- applied_ids: set[str]¶
- field_name_applied_ids: dict[str, set[str]]¶
- field_mappings: FieldMappingTracking¶
- state: dict[str, Any]¶
- resolve_policy()[source]¶
Return the effective policy for this pipeline.
Prefer the policy attached to this pipeline and fall back to the global default policy only if no pipeline policy is set.
- Return type:
- resolve_regex_engine()[source]¶
Return the effective regex engine for this pipeline.
- Return type:
RegexEngine
- classmethod from_dict(d, policy=None)[source]¶
Instantiate processing pipeline from a parsed processing item description.
- Parameters:
d (dict[str, Any])
policy (SigmaPolicy | None)
- Return type:
- classmethod from_yaml(processing_pipeline, source_path=None, policy=None)[source]¶
Convert YAML input string into processing pipeline.
If source_path is provided and policy.vars_allowed_paths is
None, the directory containing source_path is automatically used as the only allowed base directory for template vars files. This prevents a pipeline YAML from referencing vars files outside its own directory tree.- Parameters:
processing_pipeline (str)
source_path (str | None)
policy (SigmaPolicy | None)
- Return type:
- apply(rule)[source]¶
Apply processing pipeline on Sigma rule.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
- Return type:
- postprocess_query(rule, query)[source]¶
Post-process queries with postprocessing_items.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
query (Any)
- Return type:
Any
- track_field_processing_items(src_field, dest_field, processing_item_id)[source]¶
Track processing items that were applied to field names. This adds the processing_item_id to the set of applied processing items from src_field and assigns a copy of this set ass tracking set to all fields in dest_field.
- Parameters:
src_field (str)
dest_field (list[str])
processing_item_id (str | None)
- Return type:
None
- field_was_processed_by(field, processing_item_id)[source]¶
Check if field name was processed by a particular processing item.
- Parameters:
field (str | None)
processing_item_id (str)
- Return type:
bool
- __init__(items=<factory>, postprocessing_items=<factory>, finalizers=<factory>, vars=<factory>, priority=0, name=None, allowed_backends=<factory>, policy=None)¶
- Parameters:
items (list[ProcessingItem])
postprocessing_items (list[QueryPostprocessingItem])
finalizers (list[Finalizer])
vars (dict[str, Any])
priority (int)
name (str | None)
allowed_backends (frozenset[str])
policy (SigmaPolicy | None)
- Return type:
None
ProcessingItem¶
- class sigma.processing.pipeline.ProcessingItem[source]¶
Bases:
ProcessingItemBaseA processing item consists of an optional condition and a transformation that is applied in the case that the condition evaluates to true against the given Sigma rule or if the condition is not present.
Processing items are instantiated by the processing pipeline for a whole collection that is about to be converted by a backend.
- transformation: PreprocessingTransformation¶
- detection_item_condition_linking: Callable[[Iterable[bool]], bool] | None = None¶
- detection_item_condition_negation: bool = False¶
- detection_item_conditions: list[DetectionItemProcessingCondition] | dict[str, DetectionItemProcessingCondition]¶
- detection_item_condition_expression: ConditionExpression | None = None¶
- field_name_condition_linking: Callable[[Iterable[bool]], bool] | None = None¶
- field_name_condition_negation: bool = False¶
- field_name_conditions: list[FieldNameProcessingCondition] | dict[str, FieldNameProcessingCondition]¶
- field_name_condition_expression: ConditionExpression | None = None¶
- classmethod from_dict(d, policy=None)[source]¶
Instantiate processing item from parsed definition and variables.
- Parameters:
d (dict[str, Any])
policy (SigmaPolicy | None)
- Return type:
- set_pipeline(pipeline)[source]¶
- Parameters:
pipeline (ProcessingPipeline)
- Return type:
None
- apply(rule)[source]¶
Matches condition against rule and performs transformation if condition is true or not present. Returns Sigma rule and bool if transformation was applied.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
- Return type:
bool
- match_detection_item(detection_item)[source]¶
Evalutates detection item and field name conditions from processing item to detection item and returns result.
- Parameters:
detection_item (SigmaDetectionItem)
- Return type:
bool
- match_field_name(field)[source]¶
Evaluate field name conditions on field names and return result.
- Parameters:
field (str | None)
- Return type:
bool
- match_field_in_value(value)[source]¶
Evaluate field name conditions in field reference values and return result.
- Parameters:
value (SigmaType)
- Return type:
bool
- __init__(transformation, rule_condition_linking=None, rule_condition_negation=False, rule_conditions=<factory>, rule_condition_expression=None, identifier=None, policy=None, detection_item_condition_linking=None, detection_item_condition_negation=False, detection_item_conditions=<factory>, detection_item_condition_expression=None, field_name_condition_linking=None, field_name_condition_negation=False, field_name_conditions=<factory>, field_name_condition_expression=None)¶
- Parameters:
transformation (PreprocessingTransformation)
rule_condition_linking (Callable[[Iterable[bool]], bool] | None)
rule_condition_negation (bool)
rule_conditions (list[RuleProcessingCondition] | dict[str, RuleProcessingCondition])
rule_condition_expression (ConditionExpression | None)
identifier (str | None)
policy (SigmaPolicy | None)
detection_item_condition_linking (Callable[[Iterable[bool]], bool] | None)
detection_item_condition_negation (bool)
detection_item_conditions (list[DetectionItemProcessingCondition] | dict[str, DetectionItemProcessingCondition])
detection_item_condition_expression (ConditionExpression | None)
field_name_condition_linking (Callable[[Iterable[bool]], bool] | None)
field_name_condition_negation (bool)
field_name_conditions (list[FieldNameProcessingCondition] | dict[str, FieldNameProcessingCondition])
field_name_condition_expression (ConditionExpression | None)
- Return type:
None
ProcessingItemBase¶
- class sigma.processing.pipeline.ProcessingItemBase[source]¶
Bases:
objectProcessingItemBase(transformation: ‘Transformation’, rule_condition_linking: ‘Callable[[Iterable[bool]], bool] | None’ = None, rule_condition_negation: ‘bool’ = False, rule_conditions: ‘list[RuleProcessingCondition] | dict[str, RuleProcessingCondition]’ = <factory>, rule_condition_expression: ‘ConditionExpression | None’ = None, identifier: ‘str | None’ = None, policy: “‘SigmaPolicy | None’” = None)
- transformation: Transformation¶
- rule_condition_linking: Callable[[Iterable[bool]], bool] | None = None¶
- rule_condition_negation: bool = False¶
- rule_conditions: list[RuleProcessingCondition] | dict[str, RuleProcessingCondition]¶
- rule_condition_expression: ConditionExpression | None = None¶
- identifier: str | None = None¶
- policy: SigmaPolicy | None = None¶
- match_rule_conditions(rule)[source]¶
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
- Return type:
bool
- set_pipeline(pipeline)[source]¶
- Parameters:
pipeline (ProcessingPipeline)
- Return type:
None
- __init__(transformation, rule_condition_linking=None, rule_condition_negation=False, rule_conditions=<factory>, rule_condition_expression=None, identifier=None, policy=None)¶
- Parameters:
transformation (Transformation)
rule_condition_linking (Callable[[Iterable[bool]], bool] | None)
rule_condition_negation (bool)
rule_conditions (list[RuleProcessingCondition] | dict[str, RuleProcessingCondition])
rule_condition_expression (ConditionExpression | None)
identifier (str | None)
policy (SigmaPolicy | None)
- Return type:
None
QueryPostprocessingItem¶
- class sigma.processing.pipeline.QueryPostprocessingItem[source]¶
Bases:
ProcessingItemBaseA query post-processing item consists of an optional rule condition and a post-processing transformation that operates on the queries that were emitted by a backend for a given rule in the case that a transformation that is applied the condition evaluates to true against the given Sigma rule or if the condition is not present.
These items are instantiated by the processing pipeline for a whole collection that was converted by a backend.
- transformation: QueryPostprocessingTransformation¶
- classmethod from_dict(d, policy=None)[source]¶
Instantiate processing item from parsed definition and variables.
Nested post-processing definitions are parsed recursively. Already constructed child items are retained.
- Parameters:
d (dict[str, Any])
policy (SigmaPolicy | None)
- Return type:
- apply(rule, query)[source]¶
Matches condition against rule and performs transformation of query if condition is true or not present. Returns query and bool if transformation was applied.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
query (str)
- Return type:
tuple[str, bool]
- __init__(transformation, rule_condition_linking=None, rule_condition_negation=False, rule_conditions=<factory>, rule_condition_expression=None, identifier=None, policy=None)¶
- Parameters:
transformation (QueryPostprocessingTransformation)
rule_condition_linking (Callable[[Iterable[bool]], bool] | None)
rule_condition_negation (bool)
rule_conditions (list[RuleProcessingCondition] | dict[str, RuleProcessingCondition])
rule_condition_expression (ConditionExpression | None)
identifier (str | None)
policy (SigmaPolicy | None)
- Return type:
None
ProcessingPipelineResolver¶
- class sigma.processing.resolver.ProcessingPipelineResolver[source]¶
Bases:
objectA processing pipeline resolver resolves a list of pipeline specifiers into one summarized processing pipeline. It handles sorting by priority, resolution of filenames, and pipeline name identifiers.
Key Feature: When combining multiple pipelines, the resolver sorts them by their priority value (lowest first) before merging, ensuring pipelines are applied in the intended order. This is different from simple addition (
+), which concatenates pipelines without considering priorities.- pipelines: dict[str, ProcessingPipeline | Callable[[], ProcessingPipeline]]¶
- add_pipeline_class(pipeline)[source]¶
Add named processing pipeline object to resolver. This pipeline can be resolved by the name.
- Parameters:
pipeline (ProcessingPipeline)
- Return type:
None
- classmethod from_pipeline_list(pipelines)[source]¶
Instantiate processing pipeline resolver from list of pipeline objects.
- Parameters:
pipelines (Iterable[ProcessingPipeline])
- Return type:
- list_pipelines()[source]¶
List identifier/processing pipeline tuples.
- Return type:
Iterable[tuple[str, ProcessingPipeline]]
- resolve_pipeline(spec, target=None)[source]¶
Resolve single processing pipeline. It first tries to find a pipeline with this identifier in the registered pipelines. If this fails, spec is treated as file name. If this fails too, a SigmaPipelineNotFoundError is raised.
If target is specified, an additional check of the compatibility of the specified backend to the resolved pipeline is conducted. A SigmaPipelineNotAllowedForBackendError is raised if this check fails. This check applies to registered pipelines and YAML files alike.
- Parameters:
spec (str)
target (str | None)
- Return type:
- resolve(pipeline_specs, target=None)[source]¶
Resolve a list of
processing pipeline names from pipelines added to the resolver or
file paths containing processing pipeline YAML definitions or
directories containing processing pipelines YAML definitions
into a consolidated processing pipeline.
Important: Pipelines are merged in order of their priority value (lowest first), not in the order specified by pipeline_specs. This ensures pipelines are applied in their intended sequence regardless of the resolution order.
If target is specified this is passed in each resolve_pipeline call to perform a compatibility check for the usage of the specified backend with the pipeline.
- Parameters:
pipeline_specs (list[str])
target (str | None)
- Return type:
- __init__(pipelines=<factory>)¶
- Parameters:
pipelines (dict[str, ProcessingPipeline | Callable[[], ProcessingPipeline]])
- Return type:
None