Before you run
Data & scope
- Required tables
- Time window
- 24 hours
- Microsoft Entra ID connector with AADServicePrincipalSignInLogs selected and arriving in this workspace.
- Microsoft Entra ID P1 or P2 for sign-in ingestion and query access; workload risk-event licensing is a separate feature.
Documentation review by Codex (AI). No live-tenant execution or detection-performance claim. Validate schema, data coverage and expected results in your workspace.
// Hunting starter. Documentation checked 2026-11-13; not tenant-tested.
let lookback = 1d;
AADServicePrincipalSignInLogs
| where TimeGenerated >= ago(lookback) and TimeGenerated <= now()
| extend NumericResult = tolong(ResultType)
| where ResultType =~ "Failure"
or (isnotnull(NumericResult) and NumericResult != 0)
| summarize FailureRecords = count(), FirstSeen = min(TimeGenerated),
LastSeen = max(TimeGenerated), Descriptions = make_set(ResultDescription, 5),
CredentialTypes = make_set(ClientCredentialType, 5),
CorrelationIds = make_set(CorrelationId, 5)
by AADTenantId, ServicePrincipalId, ServicePrincipalName, AppId,
ResourceDisplayName, IPAddress, ResultType, ResultSignature
| order by FailureRecords desc, LastSeen desc
| take 200
Read-only query. Run in your own authorized workspace after checking prerequisites.
Use this hunt when an application, deployment pipeline or background service reports authentication trouble, or when unfamiliar application failures deserve investigation. Service-principal sign-ins use the application’s own credentials; managed-identity sign-ins have a separate table and are intentionally excluded. Service-principal sign-in semantics.
Read the result
Microsoft’s table reference describes ResultType as Success or Failure, while its sample queries also use numeric zero for success. The filter accepts an explicit Failure or a convertible nonzero numeric code, covering both documented representations. It does not classify an empty or unknown nonnumeric value as failure. tolong() returns null for an unsuccessful conversion. Schema, sample queries, and conversion behavior.
The result groups failure rows by directory tenant, service principal, application, destination, IP and result fields. It retains up to five descriptions, credential types and correlation IDs for follow-up. Those lists are bounded samples. The highest-volume 200 groups are shown; counts represent ingested records, not a guaranteed count of individual application requests.
Triage and tune
Resolve the principal ID to its application owner and compare the target resource with the application’s intended dependencies. Retrieve raw events for the selected interval. Check credential expiry or rotation, certificate identifiers, workload-federation configuration, tenant selection and recent application changes before assuming abuse. A production deployment using the wrong identity can resemble hostile traffic.
Investigate unexplained source addresses, unexpected target services and failures followed by successful activity. Use the retained correlation IDs to align workload logs with Entra events. Keep secret values out of incident notes; identifiers and timestamps are normally sufficient for correlation.
Limits and validation
This is an authentication view, not a record of every authorized API action. An application can acquire a token successfully and fail authorization later in the destination service. Empty output also requires checking collection and unfamiliar result encodings. No thresholds have been validated for your environment. The query is read-only, documentation-checked and not tenant-tested; validate known failure cases before adapting it into a rule.
Verify the source
Microsoft references
Measure normal activity, validate known test cases, account for ingestion delays, choose a threshold and entity mapping, and assign an owner. Results require investigation.
Follow the detection learning path →