Before you run
Data & scope
- Required tables
- Time window
- 15 days: 14-day baseline and 1-day review
- Microsoft Entra ID connector with AADServicePrincipalSignInLogs retained and consistently collected for 15 days.
- Microsoft Entra ID P1 or P2 for ingestion and an Analytics table/query experience supporting joins.
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 recentStart = ago(1d);
let successful = AADServicePrincipalSignInLogs
| where TimeGenerated >= recentStart - 14d and TimeGenerated <= now()
| where ResultType =~ "Success" or tolong(ResultType) == 0
| where isnotempty(AADTenantId) and isnotempty(ServicePrincipalId) and isnotempty(IPAddress);
let knownPairs = successful
| where TimeGenerated < recentStart
| distinct AADTenantId, ServicePrincipalId, IPAddress;
let establishedPrincipals = knownPairs
| summarize PriorIPCount = count() by AADTenantId, ServicePrincipalId;
successful
| where TimeGenerated >= recentStart
| summarize SignInRows = count(), FirstSeenInReview = min(TimeGenerated),
LastSeen = max(TimeGenerated), Resources = make_set(ResourceDisplayName, 10),
CredentialTypes = make_set(ClientCredentialType, 5)
by AADTenantId, ServicePrincipalId, ServicePrincipalName, AppId, IPAddress
| join kind=inner establishedPrincipals on AADTenantId, ServicePrincipalId
| join kind=leftanti knownPairs on AADTenantId, ServicePrincipalId, IPAddress
| project AADTenantId, ServicePrincipalId, ServicePrincipalName, AppId,
IPAddress, PriorIPCount, FirstSeenInReview, LastSeen, SignInRows, Resources, CredentialTypes
| order by LastSeen desc
| take 200
Read-only query. Run in your own authorized workspace after checking prerequisites.
A workload suddenly authenticating through different infrastructure can indicate a deployment change or an investigation lead. This query finds recent successful service-principal and IP pairs absent from the preceding fourteen days. It requires older successful history for the principal, making it a change detector for observed workloads rather than a list of every newly onboarded application.
Understand the comparison
The baseline and review intervals are disjoint. The established-principal join requires a historical pair, while the left-anti join removes addresses already present for that principal. Names are display context; the directory and service-principal object ID establish the identity boundary. An application ID alone would conflate different service-principal instances across directories.
The query accepts both the Success representation in the table reference and numeric zero used in Microsoft’s sample queries. Unknown result strings are not treated as success. FirstSeenInReview means first observed within the last day, not the first use of that address in the workload’s lifetime.
Explain the network change
Resolve the principal to its owner, deployment and approved runtime locations. Compare the source address with deployment records, hosted runner pools, proxies and expected cloud egress. A dynamic cloud address is not automatically suspicious, but an unrecognized address should not be dismissed merely because it belongs to a familiar provider.
Inspect the credential type and destination resources, then retrieve original events for exact identifiers. A credential rotation, moved pipeline or failover can explain a legitimate change. A stolen credential used from an already familiar egress can evade this comparison. Follow up with destination service logs to establish actual activity.
Validate and tune
Confirm fifteen days of source coverage and consistent identity collection. Missing baseline data excludes a principal with no history and can make partially collected principals appear newly active from an address. Sample known old and new addresses, a new principal and a missing-IP event. The latter two should be excluded.
Use narrowly scoped deployment exceptions with an owner and expiry, rather than permanent exclusions for all automation. The output cap does not reduce history scan or join cost. This documentation-checked hunt has not been executed in a tenant, and the suggested comparison window is not a validated detection threshold. Microsoft’s application monitoring guidance supplies the broader review context.
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 →