Architecture

This page gives an overview of how the sigma package is structured and how its parts work together. pySigma parses Sigma rules into an object model, rewrites them with processing pipelines to fit the data model of a target environment, and then hands them to a backend (to generate queries), the matcher (to evaluate events directly) or the validator. Backends and pipelines for specific SIEMs live in separate plugin packages.

Layered architecture of pySigma: rule model, processing, execution and extension

Layers

1. Rule model

Sigma YAML is loaded into a SigmaCollection that contains SigmaRule, SigmaCorrelationRule and SigmaFilter objects, all derived from SigmaRuleBase. A rule consists of a log source, detections (SigmaDetections › SigmaDetection › SigmaDetectionItem) and conditions, which are parsed into a tree (sigma.conditions). Modifiers (sigma.modifiers) turn raw values into Sigma types (sigma.types).

2. Processing

The ProcessingPipelineResolver resolves pipeline specifications (YAML files, plugin IDs or Python code), sorts them by priority and joins them into one ProcessingPipeline. A pipeline has three stages: processing items (transformations with conditions) applied to the rule, postprocessing items applied to each generated query, and finalizers applied to the whole output. A SigmaPolicy controls the regex engine and whether templates may use variables or external sources; the default is the restrictive SafePolicy. See Writing Processing Pipelines and SigmaPolicy.

3. Execution

Three consumers work on the (processed) rules:

  • Backend and TextQueryBackend convert rules into queries. Backend plugins subclass TextQueryBackend and define tokens, operators and correlation templates as class attributes. See Building a Backend.

  • SigmaMatcher evaluates events directly against rules, including correlation rules with sliding time-window state. See Matching Events Against Rules.

  • SigmaValidator checks rules with the validators from sigma.validators.core, using the MITRE ATT&CK and D3FEND data from sigma.data. See Validating Sigma Rules.

4. Extension

InstalledSigmaPlugins.autodiscover() loads backends, pipelines and validators from the namespace packages sigma.backends, sigma.pipelines and sigma.validators. SigmaPluginDirectory installs plugin packages from PyPI. See Plugin System.

Cross-cutting

All layers report errors through the SigmaError hierarchy in sigma.exceptions, which carries a SigmaRuleLocation pointing to the affected rule.

Conversion flow

Backend.convert() runs these steps:

  1. Build the pipeline (init_processing_pipeline()): the backend’s own pipeline, the user-supplied pipeline and the output format pipeline are added together. The variables backend and output_format are set in the pipeline.

  2. Resolve references (SigmaCollection.resolve_rule_references()): correlation rules are linked to the rules they reference, and filters are applied to the affected rules.

  3. Transform the rule (ProcessingPipeline.apply()): every processing item checks its conditions and applies its transformation, for example field mapping or log source replacement.

  4. Convert the condition (convert_condition(), finish_query()): the parsed condition is translated recursively into a query. ConversionState collects state, and DeferredQueryExpression holds back parts that are inserted at the end.

  5. Postprocess the query (finalize_query()): the format-specific finalize_query_<format> method runs, followed by the pipeline’s postprocessing items.

  6. Finalize the output (finalize()): all queries are combined by finalize_output_<format> and passed through the pipeline’s finalizers.