Forum Discussion
Custom Detection Rules as Code in Sentinel Repositories: What Your Pipeline Owns Now
- Jul 12, 2026
Thanks, Jamony. There are two points in your reply I want to pick up on.
I did not give the rule ID issue enough weight in the post. Since the id property uniquely identifies the rule, changing it in a PR would presumably create a new rule rather than update the existing one, potentially leaving the old rule behind. That creates a quiet duplication risk, and a simple CI check that blocks unexpected ID changes would catch it cheaply. Good catch.
On validation against a non-production workspace, I agree that live validation provides the strongest signal, but it has a blind spot worth calling out. It only validates against the tables and columns available in that environment, and the schema can drift from production in either direction. A connector that is missing in dev can make a valid production query fail, while a table or column already migrated in dev but not yet in production can allow a query that would fail in production to pass.
That is why I would pair live validation with a static check against a maintained deprecation list. The static check is environment-independent and can catch known issues such as the AIAgentsInfo retirement regardless of what a particular workspace currently exposes. I am sketching something along those lines at the moment.
Out of curiosity, how would you implement the live validation technically? Would you call the hunting query API with | take 0 appended, or use another approach? And if you get to the retired-table test before I do, I would genuinely like to see the result here. :)
I don't like the workflow of testing KQL in Advanced Hunting and then needing to copy paste this to source control to deploy it and track the changes. This workflow might be perfectly fine for very large teams or SOC-as-a-Service providers, but no so much for smaller internal teams. For smaller teams this setup and the workflow you need to follow feels to cumbersome.
I do like this option where its part of an existing product and that product does simple change tracking:
https://socanywhere.com/blog/source-control-for-microsoft-defender-custom-detection-rules.html
Probably not suitable for those larger teams and MSP's, but for smaller teams, I really like this option.