Before you run
Data & scope
- Required tables
- Time window
- 15 days: 14-day baseline and 1-day review
- Microsoft Entra ID connector with AADServicePrincipalSignInLogs collected for fifteen days.
- Microsoft Entra ID P1 or P2 for ingestion and Analytics query access supporting the baseline 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(ResourceIdentity);
let knownResources = successful
| where TimeGenerated < recentStart
| distinct AADTenantId, ServicePrincipalId, ResourceIdentity, ResourceOwnerTenantId;
let establishedPrincipals = knownResources
| summarize PriorResourcePairs = count() by AADTenantId, ServicePrincipalId;
successful
| where TimeGenerated >= recentStart
| summarize SignInRows = count(), FirstSeenInReview = min(TimeGenerated),
LastSeen = max(TimeGenerated), ResourceNames = make_set(ResourceDisplayName, 5),
SourceIPs = make_set(IPAddress, 10)
by AADTenantId, ServicePrincipalId, ServicePrincipalName, AppId,
ResourceIdentity, ResourceOwnerTenantId
| join kind=inner establishedPrincipals on AADTenantId, ServicePrincipalId
| join kind=leftanti knownResources
on AADTenantId, ServicePrincipalId, ResourceIdentity, ResourceOwnerTenantId
| project AADTenantId, ServicePrincipalId, ServicePrincipalName, AppId,
ResourceIdentity, ResourceOwnerTenantId, ResourceNames, PriorResourcePairs,
FirstSeenInReview, LastSeen, SignInRows, SourceIPs
| order by LastSeen desc
| take 200
Read-only query. Run in your own authorized workspace after checking prerequisites.
This hunt asks whether an established application identity has recently authenticated toward a resource identifier not present in its available historical activity. It is useful when checking a workload’s dependency expansion, including AI applications that acquire tokens for search, storage or administrative services.
What a new resource means
The historical set records directory, principal, resource identity and resource-owner tenant. Recent pairs already in that set are removed. A separate join requires the principal to have older observed resources, excluding entirely new principals from this particular comparison. The fourteen-day baseline ends before the one-day review starts.
ResourceIdentity is the resource identifier recorded by the authentication system. It is not necessarily an individual Azure resource instance such as a particular storage account or vault. ResourceDisplayName is sampled as context, never used as the join key. Check the table schema and the original event before interpreting the destination.
An unfamiliar resource pair is not proof of a new grant, successful data access or privilege escalation. An application may have held unused permission for months, and token issuance can still be followed by downstream authorization failure. A newly populated resource-owner field can also split a previously blank pair, so investigate collection changes.
Follow the authority to the destination
Identify the principal owner and expected deployment change. Review the relevant application permissions, consent, role assignments and application configuration. Correlate the actual API or resource operation through destination logs. A legitimate new feature, failover or maintenance job can explain a newly observed dependency.
If the pair remains unexplained, preserve the authentication event and its correlation data. Determine which credential was used and whether a preceding ownership, credential or consent change affected the same object. Keep the application object distinct from its local service-principal instance.
Validate the baseline
Use test cases for a familiar resource, a new resource, a new principal and a resource-name change with stable IDs. Only the new pair for an established principal should be selected. Confirm fifteen days of telemetry and avoid truncating the historical set before the anti-join.
This documentation-checked query has not been run in a tenant. Its bounded output is an investigation aid, and its windows need adjustment for infrequent workloads. Refer to Microsoft’s application security operations guidance when combining this observation with change and permission evidence.
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 →