RepositoryPowerShellGBUnited Kingdom
noodlemctwoodle

noodlemctwoodle/Sentinel-As-Code

An automation framework for deploying Microsoft Sentinel environments using pipelines. This project combines infrastructure-as-code (Bicep) with PowerShell automation to streamline the deployment of Sentinel solutions, analytics rules, and workbooks.

86stars
40forks
2issues
1views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: microsoft-security

#1 Repository of the week

1
TINIX TRENDING·Topic: unified-soc

#1 Repository of the week

1
TINIX TRENDING·Topic: defender-xdr

#1 Repository of the week

Sentinel-As-Code

Overview

This repository provides a complete end-to-end CI/CD solution for deploying Microsoft Sentinel environments using Azure DevOps pipelines or GitHub Actions. Starting from an empty subscription, the pipeline provisions all required infrastructure via Bicep, deploys Content Hub solutions (the source of truth for out-of-the-box content), deploys custom content (detections, watchlists, playbooks, workbooks, hunting queries, automation rules, summary rules), and deploys Defender XDR custom detection rules — all from a single repo.

It ships with a five-job PR validation gate, a nightly end-to-end smoke test against a dedicated test workspace, daily portal-drift detection that absorbs edits back into the repo as PRs, an auto-derived dependency graph, a workbook round-trip exporter, and thirteen cross-platform GitHub Copilot agents that work on github.com and in every supported IDE so authors can build, edit, tune, and explain content with repo-aware AI assistance.

💛 For organisations using this repository

Sentinel-As-Code is built and maintained on my own time as an open source project. I spend countless hours developing, testing, documenting, and supporting the work that lands in this repository — at no cost to the people and organisations who benefit from it.

If you are an organisation deploying this code into production, or if it has saved your team meaningful engineering time, please consider supporting the project. Your contribution directly funds the next wave of features, the test infrastructure, and the time it takes to keep the content current with Microsoft's release cadence.

Recurring Organisation tiers (£125 / £250 / £500 per month), one-off tips at any amount, and annual sponsorships by invoice are all live on sentinel.blog/support. All channels are Stripe-backed, all blog content stays free for everyone, and contributions do not create a support contract — see the support page for the full disclaimer.

Support sentinel.blog

Repository Structure

.archive/                  # Deprecated legacy files
.github/                   # GitHub Actions workflows + composite actions + Copilot customisations (instructions / agents / prompts)
AGENTS.md                  # Cross-tool agent guidance (Copilot, Claude, Gemini, Cursor)
AnalyticalRules/           # Custom Sentinel analytics rules (YAML, see Docs/Content/Analytical-Rules.md)
Automation/                # Standalone Azure Automation runbooks (DCR-Watchlist sync)
AutomationRules/           # Custom automation rules (JSON, see Docs/Content/Automation-Rules.md)
Bicep/                     # Infrastructure templates (see Docs/Deployment/Bicep.md)
DefenderCustomDetections/  # Defender XDR custom detection rules (YAML, see Docs/Content/Defender-Custom-Detections.md)
Docs/                      # All documentation, grouped by concern (start at Docs/README.md)
HuntingQueries/            # Custom hunting queries (YAML, see Docs/Content/Hunting-Queries.md)
Modules/                   # In-repo PowerShell modules (Sentinel.Common — shared deployer + KQL discovery helpers)
Parsers/                   # KQL parsers/functions (YAML)
Pipelines/                 # Azure DevOps pipeline definitions (see Docs/Deployment/Pipelines.md)
Playbooks/                 # Custom playbooks (ARM templates, see Docs/Content/Playbooks.md)
Scripts/                   # PowerShell automation scripts (see Docs/Deployment/Scripts.md)
SummaryRules/              # Custom summary rules (JSON, see Docs/Content/Summary-Rules.md)
Tests/                     # Pester test suite (see Docs/Development/Pester-Tests.md)
Watchlists/                # Custom watchlists (JSON + CSV, see Docs/Content/Watchlists.md)
Workbooks/                 # Custom workbooks (gallery JSON, see Docs/Content/Workbooks.md)
dependencies.json          # Auto-derived content dependency graph (see Docs/Operations/Dependency-Manifest.md)
sentinel-deployment.config # Smart-deployment configuration
README.md                  # This file

For details on what's inside each folder and how content is authored, see the Documentation section below.

Features

  • End-to-End Deployment: Single pipeline provisions infrastructure via Bicep, deploys Content Hub content, custom Sentinel content, and Defender XDR custom detections
  • Smart Infrastructure Checks: Detects existing resources and skips Bicep deployment if infrastructure is already in place
  • Smart Deployment: Use git diff to detect changed files and only deploy modified content — state file tracks deployment outcomes across runs to automatically retry previously failed items
  • Auto-derived Dependency Graph: dependencies.json is generated from KQL content discovery, not hand-maintained. PR-validation gate refuses to merge on drift; daily auto-PR keeps the manifest fresh. See Docs/Operations/Dependency-Manifest.md
  • Content Hub Automation: Deploy solutions, analytics rules, workbooks, automation rules, and hunting queries via REST API
  • KQL Parsers/Functions: Deploy workspace saved searches as reusable KQL parser functions from YAML
  • Custom Content Deployment: Deploy custom analytical rules (YAML), watchlists (JSON+CSV), playbooks (ARM), workbooks (gallery JSON), hunting queries (YAML), automation rules (JSON), parsers (YAML), and summary rules (JSON) from the repo
  • Playbook Enhancements: Module-first ordering, ARM parameter auto-injection, optional separate resource group, template folder exclusion, 64-character name truncation
  • Custom Hunting Queries: Deploy YAML-based saved searches for proactive threat hunting
  • Custom Automation Rules: Deploy JSON-based automation rules for incident auto-response
  • Summary Rules: Deploy JSON-based summary rules to aggregate verbose log data into cost-effective summary tables
  • Defender XDR Custom Detections: Deploy Advanced Hunting-based custom detection rules to Defender XDR via the Graph Security API
  • Customisation Protection: Detect and skip locally modified analytics rules to preserve manual tuning
  • Drift Detection and Absorption: Daily drift detector compares every deployed rule against its source-of-truth and absorbs all three buckets back into the repo as Custom YAML — Custom edits update matching files, ContentHub edits become new YAMLs under AnalyticalRules/AbsorbedFromPortal/ContentHub/{Solution}/, Orphans land at AnalyticalRules/AbsorbedFromPortal/Orphans/. The next deploy round-trips every absorbed rule through governance. See Docs/Operations/Sentinel-Drift-Detection.md
  • Workbook Round-Trip Export: Scripts/Export-SentinelWorkbooks.ps1 pulls every user-authored workbook from a workspace into Workbooks/<DisplayName>/{workbook.json, metadata.json}. Filters out Content Hub workbooks, replaces workspace ARM IDs with placeholders, restores PascalCase folder naming, and preserves author-curated metadata on re-export. Portal authoring becomes a first-class repo workflow
  • Granular Content Control: Toggle deployment of individual content types via pipeline parameters
  • Dry Run Support: Preview changes with -WhatIf before applying
  • Azure Government Support: Target both commercial and government cloud environments
  • PR Validation Gate: Five-job merge gate (Pester · Bicep build · ARM What-If · KQL syntax · dependency-manifest drift) on every PR to main. See Docs/Development/Pester-Tests.md
  • Nightly E2E Smoke Test: Validates every deploy code path against a test workspace each night so production-deploy regressions are caught six days before the Monday cron runs
  • Shared PowerShell Module: Modules/Sentinel.Common exports the deployer helpers every script depends on (Write-PipelineMessage, Invoke-SentinelApi, Connect-AzureEnvironment) plus six KQL discovery functions used by the dependency-manifest builder. Single source of truth eliminates the bug-fix-in-one-copy class of regression
  • Reusable GitHub Actions Composites: azure-login-oidc and setup-pwsh-modules under .github/actions/. Replace inlined Azure/login@v2 and Install-Module patterns at every call site; pin every PSGallery dependency by version
  • GitHub Copilot Integration: Thirteen cross-platform Copilot agents in two tiers — five persona-broad (Build / Edit / Tune / Explain / Understand) plus eight engineering specialists (Pipelines, PowerShell, Bicep, KQL, Tests, Drift, Dependencies, Security) — nine path-scoped instruction files, and six reusable prompts. Works on github.com Chat, github.com cloud agent, VS Code, Visual Studio, JetBrains, and Copilot CLI without configuration. See Docs/Development/GitHub-Copilot.md

Quick Start

Prerequisites

  • Azure subscription
  • Azure DevOps organisation and project
  • Service Principal with the following roles:
RoleScopePurpose
ContributorSubscriptionResource group, workspace, Bicep deployments, Sentinel content, and summary rules
User Access Administrator (ABAC-conditioned)SubscriptionPlaybook managed identity role assignments (restricted to 5 roles)
Security Administrator (Entra ID)TenantUEBA and Entity Analytics settings (optional)
CustomDetection.ReadWrite.All (Graph)TenantDefender XDR custom detection rules (Stage 5)

Least-privilege alternative: If your organisation requires tighter RBAC, you can replace Contributor with more granular roles. See the Pipelines doc for the least-privilege role assignment table.

Note on Setup: Run Scripts/Setup-ServicePrincipal.ps1 once to automatically grant all required permissions. The script provides a permission summary, requests Y/N consent, and supports -SkipEntraRole and -SkipGraphPermission switches for optional steps. After running once, the pipeline is fully autonomous.

Note on UEBA/Entity Analytics: These Sentinel settings require the Security Administrator Entra ID directory role on the service principal. If your organisation cannot assign this role to a service principal, UEBA and Entity Analytics can be enabled manually via the Azure portal by a user who holds Security Administrator. All other Bicep resources deploy without it.

Note on Defender XDR Detections: Stage 5 requires the CustomDetection.ReadWrite.All Microsoft Graph application permission on the service principal's app registration. Grant this in Entra ID > App Registrations > API Permissions > Microsoft Graph > Application permissions and provide admin consent.

Note: Required resource providers (Microsoft.OperationsManagement, Microsoft.SecurityInsights) are registered automatically by the pipeline during infrastructure deployment.

Setup

  1. Import this repository into your Azure DevOps project

  2. Create a service connection named sc-sentinel-as-code — see the Pipelines doc for role requirements

  3. Run the bootstrap script once: Scripts/Setup-ServicePrincipal.ps1 grants all required roles (Contributor, User Access Administrator, Security Administrator, CustomDetection.ReadWrite.All) with your Y/N consent. Optional steps can be skipped with -SkipEntraRole or -SkipGraphPermission switches.

  4. Create a variable group named sentinel-deployment in Pipelines > Library with your desired resource names — the pipeline will create them if they don't exist. Optionally add playbookResourceGroup to deploy playbooks to a separate resource group. See the Pipelines doc for details

  5. Create a pipeline in Azure DevOps pointing to Pipelines/Sentinel-Deploy.yml

  6. Run the pipeline — the pipeline will:

    • Check if infrastructure already exists
    • Deploy Bicep templates if needed (resource group, Log Analytics, Sentinel)
    • Configure Sentinel settings (Entity Analytics, UEBA, Anomalies, EyesOn)
    • Wait for workspace indexing (60s on new deployments)
    • Deploy Content Hub solutions and content
    • Deploy custom content (analytical rules, watchlists, playbooks, workbooks, hunting queries, parsers, automation rules, summary rules)
    • Deploy Defender XDR custom detection rules via Graph API

Optional: standalone pipelines

Pipelines that run on their own schedule alongside the main deploy:

  • Pipelines/Sentinel-Drift-Detect.yml (daily 06:00 UTC) — detects rules edited directly in the Sentinel portal, absorbs Custom drift back into the repo via PR. See Docs/Operations/Sentinel-Drift-Detection.md.
  • Pipelines/Sentinel-DCR-Inventory.yml (on-change) — deploys the Azure Automation runbook that inventories Data Collection Rule associations into a Sentinel watchlist for billing reporting. See Docs/Operations/DCR-Watchlist.md.
  • Pipelines/Sentinel-Dependency-Update.yml (daily 02:00 UTC) — runs Build-DependencyManifest -Mode Update and opens a PR if dependencies.json drifts from discovery. See Docs/Operations/Dependency-Manifest.md.
  • Pipelines/Sentinel-PR-Validation.yml (on PR) — runs every Pester suite plus the dependency-manifest drift gate. See Docs/Development/Pester-Tests.md.

GitHub-only:

  • .github/workflows/sentinel-deploy-nightly.yml (daily 03:00 UTC) — nightly E2E smoke test against the Phase C test workspace. Catches deploy-pipeline regressions before the weekly Monday production cron.

Schedule alignment

02:00 UTC daily    sentinel-dependency-update    Refresh dependencies.json + auto-PR
03:00 UTC daily    sentinel-deploy-nightly       E2E smoke test (GitHub-only)
04:00 UTC Monday   sentinel-deploy               Production deploy
06:00 UTC daily    sentinel-drift-detect         Portal-drift detection + auto-PR
on every PR        sentinel-pr-validation        5-job merge gate
on change          sentinel-dcr-inventory        DCR runbook deploy

GitHub Copilot agents

The repo ships with a complete GitHub Copilot customisation set so authors get repo-aware AI help out of the box. No VS Code settings or feature toggles required — open the workspace in any IDE with Copilot Chat enabled, or pick the agent from the dropdown on github.com.

Thirteen agents in two tiers:

Persona-broad — pick by what kind of help you want.

AgentPurpose
Sentinel-As-Code: Repo ExplorerUnderstand. Explains repo architecture, content flow, where things live. Read-only.
Sentinel-As-Code: Rule AuthorBuild. Authors new analytical rules, hunting queries, Defender detections end-to-end.
Sentinel-As-Code: Content EditorEdit. General-purpose edits across any content type with the right post-edit Pester suite.
Sentinel-As-Code: Rule TunerAdjust. Tunes thresholds, severity, query filters on existing rules without changing detection intent.
Sentinel-As-Code: Code ExplainerExplain. Walks through PowerShell, KQL, ARM, workflows in plain prose. Read-only.

Engineering specialists — pick by area of expertise.

AgentPurpose
Sentinel-As-Code: Pipeline EngineerGitHub Actions + ADO pipelines, parity, composite actions, schedules, failure diagnosis.
Sentinel-As-Code: PowerShell EngineerSentinel.Common module, scripts, AST extraction, the repo's foot-gun list.
Sentinel-As-Code: Bicep EngineerBicep templates, parameter design, Sentinel onboarding, test-workspace template.
Sentinel-As-Code: KQL EngineerQuery optimisation, parser extraction, watchlist promotion, ASIM compatibility.
Sentinel-As-Code: Test EngineerPester suite engineering, coverage analysis, mocking strategy.
Sentinel-As-Code: Security ReviewerReviews playbooks, scripts, role assignments, federated credentials. Read-only.
Sentinel-As-Code: Drift EngineerRule drift sub-system, daily auto-PR triage, Custom / ContentHub / Orphan absorption.
Sentinel-As-Code: Dependencies EngineerDependency-discovery extractor, Build-DependencyManifest, the drift gate, the daily refresh workflow.

Plus nine path-scoped instruction files under .github/instructions/ that load automatically when you edit a matching file (analytical rules, hunting queries, Defender detections, watchlists, playbooks, parsers, scripts, KQL queries, workflows), and six reusable prompts under .github/prompts/ (/new-analytical-rule, /new-hunting-query, /new-defender-detection, /new-pester-test, /review-rule, /regenerate-deps).

Repo-wide guidance lives in .github/copilot-instructions.md. Cross-tool agent guidance (Claude, Gemini, Cursor) lives in AGENTS.md. Full reference: Docs/Development/GitHub-Copilot.md.

Documentation

All documentation lives under Docs/, grouped by concern. Start at Docs/README.md for the index.

Content authoring — schemas and conventions

AreaDoc
Analytical RulesDocs/Content/Analytical-Rules.md
Automation RulesDocs/Content/Automation-Rules.md
Community RulesDocs/Content/Community-Rules.md
Defender Custom DetectionsDocs/Content/Defender-Custom-Detections.md
Hunting QueriesDocs/Content/Hunting-Queries.md
PlaybooksDocs/Content/Playbooks.md
Summary RulesDocs/Content/Summary-Rules.md
WatchlistsDocs/Content/Watchlists.md
WorkbooksDocs/Content/Workbooks.md

Deployment — how content reaches Sentinel

AreaDoc
BicepDocs/Deployment/Bicep.md
PipelinesDocs/Deployment/Pipelines.md
ScriptsDocs/Deployment/Scripts.md

Operations — continuous run-time concerns

AreaDoc
DCR Watchlist SyncDocs/Operations/DCR-Watchlist.md
Sentinel Drift DetectionDocs/Operations/Sentinel-Drift-Detection.md
Dependency ManifestDocs/Operations/Dependency-Manifest.md

Development — testing and contributing

AreaDoc
Pester TestsDocs/Development/Pester-Tests.md
GitHub CopilotDocs/Development/GitHub-Copilot.md

Infrastructure (Bicep)

Subscription-scoped Bicep templates in Bicep/ provision the resource group, Log Analytics workspace, Sentinel onboarding (both legacy OperationsManagement/solutions and modern SecurityInsights/onboardingStates), diagnostic settings, and an optional separate playbook resource group. Sentinel feature settings (Entity Analytics, UEBA, Anomalies, EyesOn) are configured via REST in the same pipeline stage.

For the full parameter reference, resource list, API versions, and limitations, see Docs/Deployment/Bicep.md.

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support the Project

If you've found Sentinel-As-Code useful, subscribe to sentinel.blog for more Sentinel and security content!

Subscribe to Sentinel Blog

The best way to support this project is by subscribing to the blog, submitting issues, suggesting improvements, or contributing code! If you're using this in an organisation, see the donation callout under Overview.

Disclaimer

This project is provided as-is, with no warranty and no support of any kind, express or implied. Use at your own risk.

The maintainers make no guarantee that the code is fit for any particular purpose, that it will work in your environment, or that any issue you encounter will be acknowledged or fixed. Bug reports and pull requests are welcome (see Contributing), but there is no SLA, no guaranteed response time, and no obligation to provide assistance.

You are solely responsible for reviewing, testing, and validating any content from this repository before deploying it to production Microsoft Sentinel or Defender XDR environments.

License

This project is licensed under the MIT License.

Similar Projects

Discover other similar projects and AI models.

Repository
HybridBrothers/Hunting-Queries-Detection-Rules

The purpose of this repository is to share KQL queries to help identify security misconfigurations, hunt for specific patterns, or detect malicious behavior

85
Sep 2, 2026
RepositoryTypeScript
n8n-io/n8n

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

212.9k
Dec 2, 2026
RepositoryPython
ThreatDefence/agentic-attack-detections

Detection rules and IOCs for AI agent attack frameworks: ARTEX, Cairn, PentAGI, HexStrike, CyberStrikeAI, Strix, Hermes Agent, Agent Zero, RedAmon, Xalgorix, Pentest Swarm AI. KQL hunts for Microsoft Sentinel and Defender XDR, Sigma, Suricata, Zeek, YARA, Splunk, Elastic, STIX 2.1.

1.1k
Dec 2, 2026
RepositoryBicep
Azure/CanadaPubSecALZ

This reference implementation is based on Cloud Adoption Framework for Azure and provides an opinionated implementation that enables ITSG-33 regulatory compliance by using NIST SP 800-53 Rev. 4 and Canada Federal PBMM Regulatory Compliance Policy Sets.

143
Sep 14, 2026
RepositoryPython
Panniantong/Agent-Reach

Give your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.

116.7k
Nov 24, 2026
RepositoryPython
langgenius/dify

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

162.3k
Dec 2, 2026
Repository
awesome-selfhosted/awesome-selfhosted

A list of Free Software network services and web applications which can be hosted on your own servers

342.5k
Nov 28, 2026
RepositoryMarkdown
DigitalPlatDev/FreeDomain

Free domain registration and practical DNS learning resources for everyone.

209.9k
Aug 12, 2026
RepositoryPython
microsoft/markitdown

Python tool for converting files and office documents to Markdown.

199.5k
Dec 2, 2026