Skip to content

Lesson 13 of 14 · 18m

Detection as Code: The Lifecycle

Rules in git, CI compile plus fixture tests, API deploys, and lifecycle states — so nothing lives only in a console edit history.

Open any mature SIEM's rule console and look at the edit history: anonymous changes from three admins ago, no explanation, no diff, no rollback. Someone widened a filter in June and the rule has been applauding the build server ever since. Then the org migrates SIEMs and discovers the detection program lived entirely in a vendor's database. Detection-as-code is the fix: rules are files in git, changes are reviewed, deployments are automated, and nothing lives only in a console.

The repo shape

The standard layout: one git repository of Sigma rules, plus the pieces that make them deployable.

detections/
  rules/
    credential_access/lsass-comsvcs-minidump.yml
    lateral_movement/wmiprvse-spawns-shell.yml
  pipelines/
    splunk.yml              # field mappings: Image → winlog.event_data.Image
    sentinel.yml
  tests/
    fixtures/               # captured events: must_fire / must_stay_silent

pipelines/ holds per-backend field mappings — the dialect — so the rules themselves stay stack-neutral. tests/fixtures/ holds captured events: real (sanitized) event exports from your atomic tests, split into samples the rule must fire on and benign lookalikes it must not.

The lifecycle

Every rule moves through states, and the state lives in the file (status: field plus a detection_level convention of your own):

  • draft — written, not deployed anywhere
  • experimental — deployed in report-only mode, baseline running (the tuning lesson's first step)
  • stable — alerting, tested, fidelity tracked
  • deprecated — retired; kept in git because the history is the institution's memory

Each state transition is a pull request with the evidence attached: the atomic test output, the baseline noise distribution, the FP sample that motivated a filter. "Quiet rules nobody reviewed" stops being a failure mode because quiet rules never existed in the repo — only reviewed edits did.

CI is where it earns the name

On every commit:

  1. Syntax/taxonomy lint — sigma check catches malformed YAML and bad tag spelling before a human wastes a review.
  2. Convert-compile per backend — sigma convert -t splunk -p splunk.yml, -t kusto -p sentinel.yml, whatever you run (setup does sigma plugin install splunk kusto first; sigma-cli ships zero backends and convert stops at No backends installed without them). A rule that doesn't compile doesn't ship, and you find out in CI rather than in the console at 2 a.m.
  3. Fixture tests — run the converted query against stored events: the malicious sample must match, the benign must not. This is the atomic-test loop institutionalized — regression testing for detections.
  4. Deploy — via the SIEM's API: Sentinel's repos/CI-CD integration or analytics-rules API, Splunk's savedsearches.conf/savedsearch REST endpoints, Elastic's detection-rules API. Console edits become either backported diffs or a sync that overwrites them — pick deliberately, document it, or your git history stops being the truth.

What it buys and what it costs

Buys: blame and rollback (git log is the audit trail the console never had), portability (the SIEM migration becomes "write a new pipeline file," not "rebuild the program"), review (a second engineer sees every filter), and honest history — tuning diffs are searchable evidence.

Costs: someone maintains the pipeline files when schemas drift, CI needs the fixture corpus kept honest, and there's a real discipline gap to close — an admin who hot-edits the console is now unilaterally forking production. The fix is cultural before it's technical: console edits get reverted by the next deploy, everyone knows it, and the PR is faster than the meeting anyway.

The practice

Move one rule — the one that's been silently edited twice — into a git repo with a CI job that converts it and tests it against two stored events. Deploy it via API. You've built the whole mechanism; everything after is repetition. When the migration or the audit arrives, the program you can git clone is the program you can prove.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.