Detections as code, and a map of what you cover
Unit 5 of 5 in Detection engineering.
You will be able to describe how detections are kept as reviewed, tested code and how to map and review your coverage.
Lesson
Rules are code: store, review, version
Palantir's project page says each production or draft alert based on the ADS framework is stored in a durable, version-controlled, centralized location, such as a wiki or a repository, and peer-reviewed before it reaches production. That is detection as code: the rule, its documentation and its test live together, changes are proposed and reviewed, and history shows who changed what and why.
Sigma's own repository shows the habit at scale. Its contributing guide asks authors to fork, branch, test and open a pull request. It also separates rule folders by purpose, listing rules, emerging-threat rules, threat-hunting rules and compliance rules, so a noisy hunting rule is not mistaken for a production alert.
Test automatically
The Sigma contributing guide lists the checks a rule must pass before it is accepted. One test checks that every rule references a valid log source and field names. Another checks for structural problems and common mistakes. The Sigma command-line tool can run validation with options that make the run fail on errors or issues. An optional check runs the rules against clean Windows event log baselines to surface false positives, and optional regression tests run rules against recorded event files.
Each check maps to a lesson in this class: valid structure (the rule is well formed), baseline (false positives), regression (true positives and variants still fire). A pipeline that runs them on every change catches the day someone edits a rule so it stops firing, or starts matching normal activity. The lab for this unit builds such a pipeline and breaks it on purpose to watch it fail.
Convert and deploy for your own tools
Sigma rules are tool-neutral, so something must turn them into your SIEM's language. Backends are the drivers of that conversion, and the pySigma library provides the programming interface that each backend uses. With the command-line tool, a typical conversion names the target backend and, optionally, a processing pipeline that adapts the rules to how your logs are set up (its own example uses one for Sysmon logs), followed by a rule file or folder. Backends are installed as plugins, and the tool can list what is available.
The tool can also write one output file per rule, which its documentation describes as useful for version control or selective deployment. Keep the converted output out of hand-editing: if a converted query needs a fix, fix the rule, the filter or the pipeline, and convert again.
Map your coverage, honestly
A coverage map answers 'which techniques could we see, and which could we not?' The ATT&CK Navigator lets you create layers: custom views of the ATT&CK knowledge base that you can use to visualize your defensive coverage. DeTT&CT is a framework built on it that aims to help blue teams score and compare data source quality, visibility coverage and detection coverage, and to compare them with the behaviours of threat actors, so you can prioritise improvements. It produces layer files you open in the Navigator.
Read the map with care. This is our reasoning, not a quote from either project: a technique shown as covered may be covered by a single rule that catches one variation, so coverage is a statement about effort and evidence, not a promise of detection. Pair every coloured cell with a test result.
Own it, date it, retire it
Sigma's specification gives rules the vocabulary of a lifecycle: a modified date that you change when the title, detection, level or log source changes; a status that moves from experimental to test to stable and can end at deprecated; and a related field that records that one rule obsoletes or was derived from another. Palantir adds the human side: a response section so the next responder knows what to do, and a priority section that says why a rule has its level.
Give every rule an owner and a review date. When a rule stops being useful, mark it deprecated and say which rule replaces it, rather than deleting it, so that the history and the reason survive.
Key points
- Store each rule with its documentation and tests in version control, reviewed by a second person.
- Run automated checks on every change: structure, valid log source, baseline false positives and regression tests.
- Convert rules for your own tool with a backend and pipeline; fix the source, not the output.
- Map coverage with ATT&CK Navigator layers and DeTT&CT, and pair each cell with a test result.
- Give each rule an owner, a status and a review date; deprecate with a pointer to the replacement.
Sources
- Palantir: Alerting and Detection Strategies Framework (project page on GitHub)
- SigmaHQ rule repository: Contributing guide (on GitHub)
- Sigma command line interface (sigma-cli, project page on GitHub)
- Sigma documentation: Backends
- DeTT&CT (project page on GitHub)
- MITRE ATT&CK Navigator (project page on GitHub)
- Sigma Rules Specification, version 2.1.0
- Palantir: ADS Framework template (ADS-Framework.md on GitHub)
Practice in the labs
Build a rule pipeline that fails when a rule breaks, map your coverage, check that your telemetry has not gone silent, and prove a drafted rule before you trust it.
- Build a detection-as-code pipeline: unit-test your Sigma rules and gate them in CI: You unit-test Sigma rules in a git repository with sigma check, sigma convert and a false-positive gate, then watch the pipeline fail when you break a rule. Runs on your machine.
- Measure your detection coverage against ATT&CK with DeTT&CT: You score your own data sources and detections in DeTT&CT and open the resulting layer in the ATT&CK Navigator as a coverage map. Runs on your machine.
- Catch the silent failures in your detection pipeline (a telemetry-integrity monitor from scratch): You build a monitor that notices when a log source goes quiet or changes shape, the failure no rule can detect for itself. Runs offline.
- Draft Sigma rules with an LLM — then prove they actually work: You use a small local model to draft a Sigma rule, then prove it with sigma check, sigma convert and a test event, catching at least one model mistake. Runs on your machine.
Knowledge check
- Why does Sigma's repository keep hunting rules in a different folder from its main rules? Answer: So a noisy hunting rule is not mistaken for a production alert. The contributing guide lists separate folders for rules, emerging threats, threat hunting and compliance. Keeping purposes apart lets readers tell a rule meant for alerting from one meant for analyst-led searching.
- What does a pipeline step that runs rules against clean baseline logs catch? Answer: Rules that match normal activity, which would be false positives. The Sigma contributing guide describes a baseline check that runs your rules against clean Windows event log baselines to surface false positives before the rule is accepted.
- A converted SIEM query has a small bug. What is the best fix? Answer: Fix the Sigma rule, filter or pipeline and convert again. The rule is the source of truth. Editing only the converted output means the next conversion brings the bug back and the reviewed rule no longer matches what runs.
- Why is a technique shown as covered on a coverage map not a guarantee? Answer: One rule may catch only one variation, so a coloured cell needs a test result behind it. Coverage layers record your own scores for data and detection. They show effort and evidence, and a single passed test proves one variation of a technique, not the technique.
Back to the syllabus or see all classes.
Related
- Detection engineering
- Build a detection-as-code pipeline: unit-test your Sigma rules and gate them in CI
- Measure your detection coverage against ATT&CK with DeTT&CT
- Catch the silent failures in your detection pipeline (a telemetry-integrity monitor from scratch)
- Draft Sigma rules with an LLM — then prove they actually work
- All classes
- Free cyber labs