L5.2 β€” Detection & Investigation 🟠

πŸ“ Level 5 Β· Detect Β· Chapter 2 of 3 Β Β·Β  Previous: L5.1 β€” Sentinel Foundation Β Β·Β  Next: L5.3 β€” SOC Operations & Automation


Goal: write detections that fire on this environment’s real behaviour, then investigate what they produce. Detection logic is free β€” you pay for the data, not the queries.

The IaC lesson: a detection is a reviewable text artifact β€” each analytics rule’s query, threshold, severity and entity mapping is Bicep a colleague can argue with in a pull request before it ever pages anyone.


Who this is for Time You need first Cost while it runs
Chapter 2 of Level 5 · everyone ~20 min L5.1 🟒 $0.00/hr in the trial · +$0.03/hr after it

[!IMPORTANT] One of these rules is only possible because of a decision made in L2.1 β€” it joins security data to operations data, and that join exists because every level wrote into the same workspace instead of standing up its own.


What you’re building

Three analytics rules, written as Bicep β€” two deploy, one is deliberately withheld. Rule 1 joins Defender alerts to failed SQL logins; Rule 2 watches the firewall’s Basic-plan table for outbound destinations it has never seen; Rule 3 needs sign-in logs nobody here has permission to connect. Both deployed rules map entities, so their incidents can be investigated rather than just counted.

flowchart LR
  SA["SecurityAlert<br/>from L3.3"]
  SQL["SQLSecurityAuditEvents<br/>from L3.2"]
  FW["AZFWApplicationRule<br/>from L2.1 Β· Basic plan"]
  SIGN["SigninLogs<br/>needs a directory admin"]

  R1["Rule 1 Β· SQL brute force<br/>+ Defender alert Β· High"]
  R2["Rule 2 Β· new egress destination<br/>Low Β· hunting-grade"]
  R3["Rule 3 Β· sign-in anomaly<br/>NOT deployed"]
  INC["incidents<br/>with mapped entities"]

  SA --> R1
  SQL --> R1
  FW --> R2
  SIGN -. "empty table" .-> R3
  R1 --> INC
  R2 --> INC

  classDef data fill:#eef4ff,stroke:#4472c4,color:#1a1a1a
  classDef rule fill:#fff4e5,stroke:#d97706,color:#1a1a1a
  classDef off fill:#fdecea,stroke:#c0392b,color:#1a1a1a
  class SA,SQL,FW data
  class R1,R2,INC rule
  class SIGN,R3 off

Text description of this diagram</summary>

Three rules, two of which deploy.

Rule 1 is the payoff for one workspace. It correlates repeated failed SQL authentications β€” which exist because L3.2 turned on auditing β€” with Defender for Cloud alerts on the same resource, which exist because L3.3 exported them. Severity High, because the combination is far more specific than either half.

Rule 2 queries AZFWApplicationRule, the table L5.1 moved to the Basic plan, and looks for outbound destinations not seen in the previous seven days. Severity Low on purpose: it is a hunting-grade signal promoted to a rule so the class has something that actually fires to practise triage on.

Rule 3 is deliberately not deployed. It needs SigninLogs, which needs the directory connector nobody here can enable. A rule over an empty table never fires and looks like coverage β€” worse than not existing.

Both deployed rules carry entity mappings. Without them an incident is a row in a table; with them Sentinel can pivot to everything else that resource or address touched.

</details>

Source: curriculum/L5.2-detection-investigation/main.bicep Β· main.bicepparam


πŸ” Going deeper β€” the join that one workspace buys you</summary>


Rule 1 joins SecurityAlert to SQLSecurityAuditEvents β€” security data to operations data. Neither table alone is an incident; the join is the detection. That join exists because every level wrote into the same workspace instead of standing up its own, which is the decision L2.1 made and the entire redesign has been protecting since.

</details>

πŸ” Going deeper β€” analytics rules over Basic tables</summary>


Rule 2 proves something about Basic tables. L2.4 taught that alert rules cannot read them β€” that is true of Log Analytics scheduled query alerts. Sentinel analytics rules over a Basic table work when the query is a simple filter and aggregation, which this one is. The distinction is fiddly, real, and exactly the kind of thing that gets a detection quietly disabled six months later. Test the rule, do not assume the plan.

</details>

πŸ” Going deeper β€” the permissions this needs</summary>

Azure RBAC β€” the minimum this chapter needs

Microsoft Sentinel Contributor on the workspace β€” a requirement on the workshop deploy identity that ships the rules, not on you. Your own Reader is enough to open the incidents they produce.
Why: analytics rules are Microsoft.SecurityInsights resources, same as the onboarding in L5.1. Worth knowing the narrower roles too β€” Microsoft Sentinel Responder can investigate and manage incidents but not change rules, and Microsoft Sentinel Reader can only look. A SOC that gives every analyst Contributor has no change control over its own detections β€” which is exactly why this workshop routes every rule change through the deploy identity and a pull request rather than granting write access to each participant.
Microsoft Entra ID roles

Global Administrator or Security Administrator β€” only if you want Rule 3 to do anything.
Rule 3 is included in the template and disabled by default precisely so the gap is visible. If a directory admin connects Microsoft Entra ID logs, set CURRICULUM_ENTRA_RULES=true and it starts working. Until then it is documentation of a dependency, not a detection.

For more info β€” Sentinel Contributor, Responder and Reader

</details>



[!NOTE] 🏫 Classroom: use the GitHub Actions option. Your Azure account holds Reader, so local az deployment commands will be refused β€” deploys go through your fork’s workflow, which uses the workshop deploy identity automatically. Compiling locally (az bicep build) works for everyone.

πŸš€ Deploy it β€” pick any one of three ways



1 Β· Bicep CLI
Copy-paste in the terminal


2 Β· GitHub Actions
One button in the browser


3 Β· GitHub Copilot
Ask AI in plain English



Β  Option 1 Β· Bicep from the terminal

az deployment group what-if --resource-group $env:AZURE_RESOURCE_GROUP --parameters curriculum/L5.2-detection-investigation/main.bicepparam
az deployment group create  --resource-group $env:AZURE_RESOURCE_GROUP --parameters curriculum/L5.2-detection-investigation/main.bicepparam

You should see: ruleCount of 2, and blockedRule explaining why the third is absent rather than silently missing.

If a directory admin has connected the logs:

$env:CURRICULUM_ENTRA_RULES = "true"



Β  Option 2 Β· GitHub Actions (push-button)

Actions β†’ β€œCurriculum L5 - Microsoft Sentinel” β†’ Run workflow β†’ L5.2 - Detection & Investigation.

The directory admin has connected Entra ID logs toggle is the only input that matters here. Leave it off unless someone has actually done it.



Β  Option 3 Β· GitHub Copilot (plain English)

Load your values first: ./scripts/Load-LabSettings.ps1. Then in Copilot Chat β†’ Agent mode:

Deploy curriculum/L5.2-detection-investigation/main.bicep to my lab resource group ($env:AZURE_RESOURCE_GROUP) with az deployment group create.

Then make it write a detection for something you know happened:

In curriculum/L5.2-detection-investigation/main.bicep, add a scheduled analytics rule that fires when a backup job fails twice in 24 hours, using the AddonAzureBackupJobs table from L4.3. Map the resource as an entity. Run az bicep build, then show me a what-if.

Ask yourself whether that belongs in Sentinel at all. L4.3 already alerts on it through Azure Monitor, for $0.50/month, without Sentinel analysis charges. Every signal has a right home, and β€œwe have a SIEM” is not a reason to route everything through it.



βœ… Verify it

  1. Both rules exist and are enabled:

    az sentinel alert-rule list --workspace-name "log-$env:AZURE_PREFIX-l3" -g $env:AZURE_RESOURCE_GROUP `
      --query "[].{name:displayName, severity:severity, enabled:enabled}" -o table
    
  2. Make Rule 1 fire β€” repeat the failed-login test from L3.2 six or more times against the SQL server, then wait for the hourly evaluation:

    1..8 | ForEach-Object { sqlcmd -S "$SQL.database.windows.net" -U notauser -P "wrong-$_" -Q "SELECT 1" }
    

    You should see: an incident within the hour, with the SQL server already attached as an entity. Open it and use the investigation graph β€” that pivot is what the entity mapping bought you.

  3. Check the MITRE coverage honestly: in the portal, Microsoft Sentinel β†’ MITRE ATT&CK.

    You should see: two techniques covered and a great many not. Say the number out loud. Two rules is not a detection strategy, and a coverage map that looks sparse is more useful than one that looks full because someone enabled every template rule without checking the data behind them.

  4. Hunt without an alert. In Hunting, run:

    AzureActivity
    | where OperationNameValue has "delete" and ActivityStatusValue == "Success"
    | summarize Deletions = count() by Caller, ResourceGroup
    | order by Deletions desc
    

    You should see: your own teardown activity from earlier levels. Hunting starts from a hypothesis rather than a rule, and recognising your own footprints is the first step to recognising someone else’s.


GitHub feature spotlight Β· Detections reviewed before they page anyone

You just used it: these rules are Bicep β€” the query, the threshold, the severity and the entity mapping are all text a colleague can argue with before the rule wakes anybody at 3am. Find it: the entityMappings block on each rule, and the comment explaining why Rule 3 is not deployed. Beyond the lab: a SOC that edits detections in the portal cannot answer β€œwho changed this, and why” β€” which is the first question asked after a missed incident. Docs β†’



➑️ What carries forward

L5.3 automates the triage these incidents need, and closes the level with a cost review that turns off a connector you have proved you do not need.


🧭 Where next?

Your situation Go to
Ready to keep going β€” automate the triage L5.3 β€” SOC Operations & Automation
Want the big picture of this level first Level 5 Β· Detect overview
Done for the day β€” the estate bills while idle Cleanup & Reset
Something didn’t work Troubleshooting
β¬… Back to the main path grid πŸ—ΊοΈ Curriculum Map