Detection-as-Code: Sigma, KQL and CI for Sentinel
A detection-as-code pipeline for Microsoft Sentinel: Sigma rules, tests, pySigma conversion to KQL and feedback, plus our test of 226 public cloud rules.
On 31 March 2027, Microsoft Sentinel stops being supported in the Azure portal and moves to the Defender portal only. In April 2026, MITRE's ATT&CK v19 split the Defense Evasion tactic in two, which left mappings across the industry pointing at a tactic that no longer exists. And on 4 October 2026, pySigma, the library behind most Sigma tooling, shipped version 2.0. SOCs whose detection rules live in a portal, edited by hand, will feel each of these changes. Teams that keep their rules in Git, with tests, will see them as a pull request.
This article is for CISOs, SOC leads, detection engineers and the platform teams who run the pipeline. We show the detection-as-code pipeline we build for Microsoft Sentinel, and what happened when we put all 226 public SigmaHQ cloud rules through it in November 2026. The short version: authoring and conversion are easy. The work is in schema mapping and test data, and the public rule corpus gives you neither.
TL;DR / Key takeaways
- Detection-as-code is a loop, not a converter. Author, test, convert, deploy, measure, and turn every false positive into a test case.
- Sigma converts to KQL, but cloud rules need your own mapping. The stock Kusto backend pipelines placed 0 of 226 SigmaHQ cloud rules in a Sentinel table in our test.
- Field names are the real gap. Only 18 of 226 cloud rules use field names that exist verbatim in the matching Sentinel table; 100 more differ only in case.
- The public corpus has no cloud test data. 0 of 226 SigmaHQ cloud rules carry regression test samples, against 447 of 2,427 Windows rules.
- Pin your toolchain. The Kusto backend requires pySigma 1.x, sigma-cli 4.0 requires 2.x, and an unpinned install broke.
Download: Editable draw.io file · Open in diagrams.net · Chart data (CSV)
Why detection-as-code matters now
Detection engineering is plain software engineering applied to rules: review, tests, versions and rollback. Three changes in 2026 turned it from good practice into unavoidable maintenance.
- The platform is moving. After 31 March 2027, Sentinel is available only in the Defender portal. Custom detection rules as code (a new
Microsoft.Security/detectionRulesBicep resource) are in preview and need Defender portal onboarding and a Microsoft 365 E5 or equivalent licence. Rules in Git can be redeployed; portal-only rules get rebuilt by hand. - The taxonomy moved. ATT&CK v19 (28 April 2026) replaced Defense Evasion with Stealth (keeping TA0005) and Defense Impairment (TA0112). v20 followed on 13 October 2026. In YAML, retagging is a scripted, reviewable change.
- The tooling moved. pySigma 2.0 shipped on 4 October 2026 and sigma-cli 4.0 on 28 October. The Kusto backend had not followed by mid-November, so only a pinned toolchain works.
For the wider SOC architecture around this pipeline, see our guide to building a modern SOC with Microsoft Sentinel.
The pipeline, stage by stage
The numbers match the callouts in the figure.
① Author the rule in Sigma
Sigma is a vendor-neutral YAML format for log detections: a logsource, a detection block, a condition, and metadata such as level, falsepositives and ATT&CK tags. The current specification is v2.1.0 (September 2025); v2.0 added formats for correlation rules and filters. One rule per file, a UUID that never changes, and a second-team reviewer via CODEOWNERS.
Why Sigma rather than raw KQL? Less for portability than for review: a Sigma rule states what it detects in about fifteen readable lines. Where Sigma cannot express the logic, such as joins across tables, we write native KQL in the same repository, with the same tests.
② Test before anything is converted
SigmaHQ's own CI is a good template: yamllint, sigma check with the SigmaHQ validators, a duplicate-ID check and regression tests that replay event samples. We add one rule: every rule ships with an attack fixture that must match and a benign fixture that must not.
Here the public corpus leaves you alone. In the SigmaHQ repository at commit 54967d6 (13 November 2026), 448 of 3,164 rules point to regression test data. 447 of them are Windows rules. None of the 226 cloud rules has a sample. For cloud rules, the fixture is a small JSON event, built from a lab replay or a sanitised production event.
③ Convert with pySigma, and own the mapping
Conversion uses pySigma with pySigma-backend-kusto, usually through sigma-cli. Its four pipelines (azure_monitor, sentinel_asim, microsoft_xdr, microsoft_365_defender) map endpoint categories such as process_creation to tables, not cloud log sources such as product: aws, service: cloudtrail. Every cloud rule failed in our test with "Unable to determine table name from rule".
The fix is a pipeline you own. This one, tested with sigma-cli 3.1.0, pySigma 1.5.1 and pySigma-backend-kusto 1.0.1, sets the table and renames CloudTrail fields to the Sentinel column names:
name: sentinel-cloud-tables
priority: 20
transformations:
- id: aws_cloudtrail_table
type: set_state
key: query_table
val: AWSCloudTrail
rule_conditions:
- type: logsource
product: aws
service: cloudtrail
- id: aws_cloudtrail_fields
type: field_name_mapping
mapping:
eventName: EventName
eventSource: EventSource
userIdentity.arn: UserIdentityArn
rule_conditions:
- type: logsource
product: aws
service: cloudtrail
postprocessing:
- type: template
template: |
{{ pipeline.state.query_table }}
| where {{ query }}Run against SigmaHQ's rule for a deleted Bedrock guardrail, sigma convert -t kusto -p sentinel_cloud.yml produces:
AWSCloudTrail
| where EventName =~ "DeleteGuardrail" and EventSource =~ "bedrock.amazonaws.com"Then test the KQL itself. Microsoft's Kusto emulator is a free Linux container meant for local development and automated testing: a CI job creates the table from the documented schema, ingests the fixtures and asserts row counts. It proves logic and column names, not that your connector delivers the data.
④ Deploy through Sentinel Repositories
Sentinel Repositories deploys analytics rules, hunting queries, parsers, playbooks, workbooks and, in preview, custom detection rules from Bicep or ARM templates in GitHub or Azure DevOps. We wrap each query in a Bicep template, deploy to a staging workspace and run a smoke query against real data before promoting it.
Three documented limits shape the design: five repository connections per workspace, 800 deployments in a resource group's history, and deleting a file does not delete the rule. We keep a retired/ list that a scheduled job enforces.
⑤ Close the loop with telemetry
The SecurityIncident table records the Classification and ClassificationReason analysts set when closing an incident. Join it to the rule name and you get volume and precision per rule, weekly. A rule with more benign and false positives than true positives for a month goes back into the pipeline, and the offending event becomes its next benign fixture.
What the numbers say
How much of a free rule library survives contact with Sentinel? Method: SigmaHQ/sigma at commit 54967d6, all 226 rules under rules/cloud, counted with a short Python script. We mapped each log source to a Sentinel table ourselves (AWSCloudTrail, AzureActivity, AuditLogs, SigninLogs, AADUserRiskEvents, GCPAuditLogs, OfficeActivity) and compared field names case-sensitively with the column lists on Microsoft Learn. Field names only, not values.
The first chart is our design, not a measurement: linting catches syntax, only fixtures catch logic errors, only the workspace catches a connector that never sends the field.
The tactic picture is lopsided. Privilege Escalation (99 rules), Persistence (98), Initial Access (71) and Stealth (71) dominate; Discovery and Lateral Movement have 4 rules each. Azure and Entra account for 123 of the 226 rules. A public library covers identity and control-plane abuse reasonably, and almost nothing of what an attacker does after landing. Our article on cloud attack paths shows why that middle part of the chain matters.
Only 18 rules use field names that exist verbatim in the mapped table. 100 differ only in case (eventName versus EventName), and Microsoft documents KQL as case-sensitive for table and column names, so they fail until mapped. 88 use nested paths such as properties.message or fields the table lacks. 17 have no native Sentinel table in our mapping, mostly Google Workspace and PIM sources, and 3 match keywords only, with no fields at all. Without a pipeline, 224 of 226 rules convert, but with no table and raw field names: a string, not a detection.
Caveats: these counts describe a public library, not your coverage, and our table mapping is a judgement call, especially mapping the Microsoft 365 rules to OfficeActivity.
In a recent engagement…
In a recent engagement with a DACH financial services firm, the SOC ran a few hundred Sentinel analytics rules, from Content Hub templates and years of portal edits, none in source control. The trigger was an internal audit question under DORA: show us your detection mechanisms are tested. Nobody could say which rules had ever fired on a true positive, and several queried a table a connector migration had emptied long before.
We did not start by converting anything. We exported the rules to Bicep, committed them unchanged, flagged rules on empty tables nightly, and wrote fixtures for the rules that mattered most. Sigma came later. The audit finding closed on evidence the pipeline now produces anyway.
The detection-as-code checklist
| # | Control | Stage |
|---|---|---|
| 1 | Every rule in Git, one file per rule, immutable UUID | ① |
| 2 | Second-team review enforced via CODEOWNERS | ① |
| 3 | ATT&CK tags on v19+ names (Stealth, Defense Impairment) | ① |
| 4 | sigma check with validators on every pull request | ② |
| 5 | At least one attack and one benign fixture per rule | ② |
| 6 | Toolchain pinned in a lock file, upgraded by pull request | ③ |
| 7 | Custom pipeline maps each log source to a table and columns | ③ |
| 8 | Converted KQL tested in the Kusto emulator | ③ |
| 9 | Staging workspace and smoke query before production | ④ |
| 10 | Explicit retirement list, enforced by a job | ④ |
| 11 | Weekly precision and volume per rule from SecurityIncident | ⑤ |
| 12 | Every false positive becomes a benign fixture | ⑤ |
Governance for European enterprises
Two regimes make detection testing a matter of evidence.
- DORA (Regulation (EU) 2022/2554), Article 10. Financial entities must have mechanisms to promptly detect anomalous activities. The article states that "all detection mechanisms … shall be regularly tested in accordance with Article 25". Article 10(2) also asks for defined alert thresholds and criteria. Fixtures, staging tests and precision history are that evidence.
- NIS2 (Directive (EU) 2022/2555), Article 21(2). Point (b) requires incident handling and point (f) requires policies and procedures to assess the effectiveness of cybersecurity risk-management measures. In Germany the NIS2UmsG carries this into the BSI Act. Our NIS2-to-Sentinel control mapping shows which detections typically anchor which measure.
Treat the rule repository as a production system: a compromised detection pipeline can silently disable your SOC. Our GitHub Actions hardening controls apply directly, and policy-as-code with OPA, Kyverno and Conftest is the natural sibling for preventive controls.
A pragmatic adoption path
- Weeks 1–2: export and commit. Export every custom rule to Bicep, commit it unchanged, connect a staging workspace.
- Weeks 3–4: find dead rules. Flag rules on empty tables or with no true positive in 90 days; fix or retire them by pull request.
- Weeks 5–6: pin and map. Lock the toolchain, write the pipeline for the log sources you ingest, retag to ATT&CK v19.
- Weeks 7–10: fixtures first. Attack and benign fixtures for your crown-jewel rules; Kusto emulator in CI.
- Week 11 onwards: close the loop. Weekly precision per rule, "false positive becomes fixture", new rules in Sigma by default.
The verdict
Detection-as-code is worth it, but not for the reason usually given. Sigma's portability is overstated for cloud rules: the public corpus needs table and field mapping before almost any rule runs in Sentinel, and ships no test data. The value is everything around the converter: review, fixtures, a pinned toolchain, staged deployment and precision per rule. That turns portal state into a system you can audit, migrate to the Defender portal and defend to a DORA examiner.
If you want help standing up the pipeline, from rule export and pySigma mappings to fixtures and CI, our DevSecOps practice builds exactly this with European security teams. For detection strategy and Sentinel operations, see our Zero Trust and cybersecurity practice.
FAQ
What is detection-as-code?
Treating detection rules like software: each rule is a file in Git, changed by pull request, checked by automated tests, deployed by a pipeline and measured in production. Microsoft describes Sentinel Repositories as an implementation of it. The point is that no rule reaches production without review, a test and a way back.
Can Sigma rules be converted to KQL for Microsoft Sentinel?
Yes, with pySigma and the pySigma-backend-kusto package, usually through sigma-cli. In our November 2026 test the backend's stock pipelines placed none of the 226 SigmaHQ cloud rules in a Sentinel table, so cloud log sources need a small custom pipeline that maps each source to a table and its column names.
Which versions of sigma-cli and pySigma work with the Kusto backend?
As of 15 November 2026, pySigma-backend-kusto 1.0.1 requires pySigma 1.x, while sigma-cli 4.0 requires pySigma 2.x, and an unpinned install failed to import. Pinning sigma-cli 3.1, pySigma 1.5.1 and pySigma-backend-kusto 1.0.1 worked. Keep the toolchain in a lock file.
How do you unit test a KQL detection?
Test the Sigma logic against small attack and benign fixtures, then run the converted KQL against fixtures in Microsoft's Kusto emulator, a free Linux container intended for automated testing. A final smoke test in a staging Sentinel workspace catches schema and connector differences.
Does Microsoft Sentinel support CI/CD natively?
Yes. Sentinel Repositories deploys analytics rules, hunting queries, parsers, playbooks, workbooks and other content from Bicep or ARM templates in GitHub or Azure DevOps; custom detection rules are in preview. Deleting a file from the repository does not delete the rule from the workspace, so plan retirement explicitly.
Is detection-as-code required by NIS2 or DORA?
Not by name. DORA Article 10 says detection mechanisms shall be regularly tested, and NIS2 Article 21 requires incident handling and policies to assess the effectiveness of security measures. A tested, versioned detection pipeline is one of the cleanest ways to produce that evidence.
Sources
Checked on 15 November 2026. Rule counts and conversion results are our own analysis and can be reproduced from the commit and package versions named.
Tier A: primary and regulatory
- Regulation (EU) 2022/2554 (DORA), EUR-Lex: Art. 10, Art. 25
- Directive (EU) 2022/2555 (NIS2), EUR-Lex: Art. 21(2)(b) and (f)
- MITRE ATT&CK: Updates, April 2026 (v19) and Enterprise tactics
- MITRE ATT&CK: Updates (v20, 13 October 2026)
- Sigma specification (v2.1.0)
Tier B: data and research
- SigmaHQ/sigma, rules/cloud at commit 54967d6: rule counts, tactic tags, regression test coverage (our analysis)
- SigmaHQ/sigma: regression test data README and CI workflow
- PyPI: pySigma, sigma-cli, pySigma-backend-kusto: versions, release dates and dependency ranges
Tier C: vendor documentation
- Microsoft Learn: Manage custom content with repository connections
- Microsoft Learn: Deploy custom content from your repository (Azure portal retirement after 31 March 2027)
- Microsoft Learn: Kusto Query Language overview (case sensitivity)
- Microsoft Learn: Azure Data Explorer Kusto emulator overview
- Microsoft Learn: Azure Monitor table reference (AWSCloudTrail, AzureActivity, AuditLogs, SigninLogs, AADUserRiskEvents, GCPAuditLogs, OfficeActivity, SecurityIncident)
- AttackIQ: pySigma-backend-kusto
Topics