AS-301g · Module 2
Detection as Code
3 min read
Detection rules maintained through a SIEM UI are rules that have no version history, no code review, and no automated testing. Detection as code applies software engineering practices to security detection: rules are defined in code, stored in version control, reviewed through pull requests, tested against sample data, and deployed through CI/CD pipelines. Every rule change is documented. Every rule has a test case. Every deployment is reversible.
- Rule Definition in Code Write detection rules in a declarative format — Sigma, YARA-L, or the native rule language of your SIEM, stored as files in a git repository. Each rule file includes the detection logic, the severity classification, the response playbook reference, and metadata about what threat it detects.
- Automated Testing For each detection rule, create sample log events that should trigger the rule and sample events that should not. Run the test suite in CI on every rule change. A rule that fails its test suite does not deploy. A new rule ships with a minimum of three positive and three negative test cases.
- Deployment Pipeline Changes to detection rules flow through the same CI/CD pipeline as application code. Feature branch, code review, test suite, staging validation, production deployment. Rollback is a git revert. The deployment pipeline ensures that no untested, unreviewed rule reaches production.