The Detection Lifecycle and Detections as Code
Transform security operations by treating threat detections as software code, establishing git-based CI/CD testing pipelines, and systematically navigating the end-to-end detection engineering lifecycle.
Contentsand lesson path
On this page
- The Paradigm Shift: Detection as Code (DaC)
- Telemetry Health Monitoring and CI/CD Quality Gates
- Practice check
- Review prompt
Lessons of Detection Engineering
- The Detection Lifecycle and Detections as Code Concept · 15 min
- Writing and Converting a Sigma Rule Lab · 30 min
- Proving Detections with Adversary Emulation Lab · 30 min
- Tuning for Precision Without Blind Spots Worked example · 20 min
- Coverage Gaps, Deception and Hypothesis-Driven Hunting Worked example · 25 min
- Detection Engineering Check Knowledge check · 8 questions
What you will learn
- Write a Sigma rule for a specific ATT&CK technique, convert it to a SIEM query, and document its data source, logic and known false positives.
Prerequisites: Security Logging & SIEM
01. The Paradigm Shift: Detection as Code (DaC)
For years, security operations relied on ad-hoc alert creation: an incident occurred, a security analyst logged into the SIEM web interface, clicked through a graphical builder to assemble a query, and saved an alert rule. This manual approach suffered from chronic failure modes: rules lacked version control, peer reviews were non-existent, logic regressions went unnoticed, and moving rules between different SIEM vendors required rewriting detection queries from scratch.
Detection as Code (DaC) applies modern software engineering principles to the craft of threat detection. Under the DaC paradigm, threat detections are authored in human-readable, declarative formats (such as Sigma YAML), stored in a version-controlled Git repository, tested in automated continuous integration (CI) pipelines, and deployed to production SIEM and EDR platforms via automated continuous deployment (CD).
Treating detections as code provides transformational operational benefits:
- Traceability & Auditability: Every modification to detection logic is tracked through Git commits, associating changes with author identity, timestamp, and justification.
- Peer Review & Guardrails: Proposed detection changes require peer review through pull requests, ensuring multiple engineers validate query logic, check for runaway performance impacts, and review documented false positives.
- Automated Syntax and Regression Testing: CI runners validate YAML syntax, verify MITRE ATT&CK tag validity, compile rules to native query dialects, and execute unit tests against historical benign datasets to prevent false-positive floods before deployment.
A mature detection engineering program structures work through a continuous six-stage lifecycle:
1. Threat Modeling & Requirements Gathering Detections begin with an understanding of active adversary tradecraft. Detection engineers analyze published threat intelligence reports, internal threat models, and the MITRE ATT&CK matrix to identify high-risk tactics, techniques, and procedures (TTPs) relevant to the organization's tech stack.
2. Telemetry Verification & Data Availability
Before writing detection logic, engineers verify that the required event logs actually exist in the SIEM. A rule designed to detect process injection (ATT&CK T1055) is completely useless if endpoints do not capture Sysmon Event ID 8 (CreateRemoteThread) or Linux ptrace auditd syscalls. Engineers validate log fidelity, schema parsing, and ingestion latency.
3. Declarative Rule Authoring (Sigma) The engineer writes the core detection logic in vendor-neutral Sigma syntax, defining the data source category, exact selection criteria, exclusions for known benign administrative patterns, alert severity, and MITRE ATT&CK tags.
4. Automated Testing & Adversary Emulation The detection is tested in an isolated lab environment using controlled adversary emulation frameworks (such as Atomic Red Team). The engineer validates both "hit" conditions (does the rule trigger when the malicious behavior executes?) and "miss" conditions (does the rule remain silent when benign background traffic runs?).
5. Production Deployment & Staged Canary Rollout The compiled rule is deployed to production in "silent" or "audit" mode for 7 to 14 days. During this canary phase, the rule evaluates live telemetry without alerting the on-call SOC. Engineers measure event volume and tune unexpected benign triggers.
6. Continuous Tuning, Maintenance & Retirement Enterprise environments evolve as software updates and infrastructure changes introduce new telemetry baselines. Detection engineers regularly review alert precision metrics, tune noisy rules, and retire obsolete signatures when legacy software is decommissioned.
02. Telemetry Health Monitoring and CI/CD Quality Gates
One of the most dangerous blind spots in security engineering is silent detection failure. An organization may possess world-class detection rules, but if an endpoint agent crashes, an operating system update resets an audit policy, or a network firewall rule blocks syslog transport, the SIEM receives zero events. Because the absence of logs results in zero alerts, security teams mistakenly assume the environment is clean.
To combat silent failure, detection engineering teams deploy automated telemetry health checks and missing-data monitors:
- Heartbeat Monitors: Automated queries that verify every active endpoint, cloud account, and firewall transmits a minimum threshold of events every 15 minutes. If event ingestion drops to zero, a high-priority operational alert is triggered.
- Audit Policy Drift Monitors: Automated checks that verify critical Windows Advanced Audit policies or Linux
/etc/audit/audit.rulesremain active and have not been cleared by an adversary. - Negative Control Ingestion Tests: Synthetic event generators that periodically inject benign test markers (such as an echo command with a specific canary tag) to verify end-to-end transport and indexing health.
In addition to event absence, detection engineers must continuously monitor telemetry latency. If high network utilization or SIEM manager queuing delays event indexing by 45 minutes, real-time alerts fire 45 minutes after an adversary has already executed credential harvesting. Real-time dashboards track the delta between the endpoint event generation timestamp (@timestamp) and the central ingestion timestamp (event.ingested). Any sustained divergence exceeding 60 seconds triggers operational alerts to identify backpressure or network choke points before adversary response windows expire.
name: Detection as Code CI
on:
pull_request:
paths:
- "rules/**.yml"
jobs:
validate-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Sigma CLI and backends
run: |
pip install sigma-cli \
pySigma-backend-opensearch \
pySigma-backend-elasticsearch
- name: Validate Sigma rule syntax
run: sigma check rules/
- name: Test rule conversion to OpenSearch Lucene
run: |
sigma convert \
-t opensearch-lucene \
-p ecs \
rules/# Automated detection rule metadata and telemetry verification utility
DETECTION_CATALOG = [
{
"id": "det-001",
"title": "Suspicious PowerShell Encoded Command",
"technique": "T1059.001",
"required_telemetry": "windows.process_creation",
"status": "production",
"precision_rate": 0.94,
},
{
"id": "det-002",
"title": "Linux Sudo GTFOBins Shell Spawn",
"technique": "T1548.003",
"required_telemetry": "linux.auditd",
"status": "canary",
"precision_rate": 0.88,
},
]
ACTIVE_TELEMETRY = {"windows.process_creation", "linux.auditd"}
def verify_catalog_health(catalog, available_telemetry):
healthy = []
for rule in catalog:
has_telemetry = rule["required_telemetry"] in available_telemetry
is_stable = rule["precision_rate"] >= 0.85
if has_telemetry and is_stable:
healthy.append(rule["id"])
return healthy
verified = verify_catalog_health(DETECTION_CATALOG, ACTIVE_TELEMETRY)
print(f"Verified {len(verified)} detection rules ready for deployment.")03. Practice check
04. Review prompt
Explain how the Detection as Code (DaC) paradigm bridges the gap between threat intelligence, security operations, and software engineering best practices.
Trace the six phases of the detection engineering lifecycle (Threat Modeling, Telemetry Verification, Rule Authoring, Emulation Testing, Staged Rollout, and Continuous Tuning). Detail the technical architecture of a GitHub Actions CI pipeline that automatically validates Sigma YAML syntax and compiles rules to OpenSearch Lucene using pySigma.
Explain the concept of silent detection failure, describing how automated heartbeat queries, latency trackers, and audit policy drift monitors alert engineers when telemetry collection pipelines fail in production.
Discuss the role of canary deployments and detection regression testing, explaining how staging rules against historical benign datasets measures false positive rates before rules are promoted to high-severity SOC alerts.
Detail how detection engineering teams coordinate with SOC incident response handlers to establish continuous feedback loops that convert novel post-incident forensic findings directly into validated automated detection rules within 48 hours.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.