
Using KQL to Detect Gaps in your Conditional Access Strategy
A blog post that provides three concrete KQL queries for Microsoft Sentinel/Log Analytics to detect Conditional Access Policy (CAP) violations in Entra ID: single-factor sign-ins by privileged admins that should require MFA, group members bypassing trusted-location/device-compliance requirements, and resources with no Conditional Access applied at all. It also surveys community tooling for CAP gap analysis, including the built-in Gap Analyzer Workbook, Maester, CA Optics, DCToolbox's What-if simulator, and Beau Bullock's MFASweep. The approach turns an organization's intended CAP strategy into ongoing detection logic rather than one-time policy review.
What it is
A defensive detection technique from attackthesoc.com: rather than testing Conditional Access (CA) policy coverage with what-if simulators, it inverts each CA policy into a KQL detection that fires when a sign-in occurs that the policy should have prevented. The post walks through two concrete examples built on Microsoft's CA policy templates, with working queries against Microsoft Sentinel / Entra SigninLogs and ExposureGraphEdges.
How it works
For each policy you articulate what shouldn't happen, then detect that activity. The Require MFA for administrators example: build the target population from ExposureGraphEdges (member of a named group) plus IdentityInfo where AssignedRoles matches a list of privileged roles, then find their successful single-factor sign-ins:
let firstPartyIds = dynamic(["c2ada927-a9e2-4564-aae2-70775a2fa0af","04436913-cf0d-4d2a-9cc6-2ffe7f1d3d1c"]);
let excludedResourceIds = dynamic([]);
let CAPTargetGroup = materialize(ExposureGraphEdges
| where EdgeLabel == "member of" and TargetNodeLabel == "group"
| where TargetNodeName == "<GROUP_NAME>"
| distinct SourceNodeName);
let privilegedRoles = dynamic(["Global Administrator", "Application Administrator", ... "User Administrator"]);
let CAPTargetAdmins = IdentityInfo
| where AssignedRoles has_any(privilegedRoles)
| distinct AccountDisplayName;
SigninLogs
| where Identity in (CAPTargetGroup, CAPTargetAdmins)
| where ResultType == 0
| where AuthenticationRequirement == @"singleFactorAuthentication"
| where ResourceId !in (firstPartyIds, excludedResourceIds)
| where AppDisplayName != @"Windows Sign In"The key filters: ResultType == 0 (successful), AuthenticationRequirement == "singleFactorAuthentication" (MFA didn't happen), minus first-party Microsoft resources that CA can't target and Windows Sign In. A second example (trusted-location + company-owned-device policy) is only partially shown before the text cuts off.
Preconditions / Affected
Requires Microsoft Sentinel / Advanced Hunting with SigninLogs, IdentityInfo, and ExposureGraphEdges (the latter implies Defender Exposure Management data) ingested. You must supply your own <GROUP_NAME>, excluded resource IDs, and app display names — the detections encode your stated CA strategy, so they're only as correct as your understanding of it.
What to do
Translate each CA policy into an inverse detection using the pattern above. The post also lists existing tools worth knowing before rolling your own: the built-in Conditional Access Gap Analyzer Workbook (Entra Admin Center > Identity > Monitoring & health > Workbooks), Maester (PowerShell what-if testing framework), DCToolbox CAP what-if simulation, CA Optics (archived), and MFASweep (Beau Bullock's tool that attempts auth against Microsoft services to surface single-factor gaps).
Caveats
Detections fire on gaps that have already been exploited in your logs — they catch drift after the fact, not before, so pair them with the what-if simulators for pre-emptive testing. The two hardcoded firstPartyIds and the privileged-role list are the author's choices; you must verify they match your tenant. The second KQL example is incomplete in the source text.
Organisations named here
- DCToolbox
Technologies named here
- Conditional Access Gap Analyzer Workbook
- Azure / Microsoft Entra ID Conditional Access
- Maester
- CA Optics
- CAP 'What if' Simulation - DCToolbox
- MFASweep
- Conditional Access Documenter
- KQL
- Microsoft Entra ID
- Microsoft Sentinel
Techniques named here
- Single-factor authentication bypass of admin MFA requirement
- Access from untrusted location/personal device
- Resources with no Conditional Access policy applied
Related in Blue Team & Detection
AI-Coded Malware | Analyzing Vibe-Coded AD Enumeration | Huntress
