Query Details
let EntraConnectAppIdentities = OAuthAppInfo
| where parse_json(Permissions) has 'ADSynchronization.ReadWrite.All'
| summarize by AppName;
AuditLogs
| where OperationName has_any ("Add service principal", "Certificates and secrets management", "Update application")
| where Result =~ "success"
| mv-apply TargetResource = TargetResources on
(
where TargetResource.type =~ "Application" or TargetResource.type =~ "ServicePrincipal"
| extend
TargetName = tostring(TargetResource.displayName),
TargetObjectType = tostring(TargetResource.type),
ResourceId = tostring(TargetResource.id),
AddedKeyEvent = TargetResource.modifiedProperties
)
| where TargetName in~ (EntraConnectAppIdentities)
| extend InitiatingBy = iff(isnotempty(InitiatedBy.user.id), tostring(InitiatedBy.user.userPrincipalName), tostring(InitiatedBy.app.displayName))
| extend InitiatingUserOrAppId = iff(isnotempty(InitiatedBy.user.id), tostring(InitiatedBy.user.id), tostring(InitiatedBy.app.servicePrincipalId))
| extend InitiatingIpAddress = iff(isnotempty(InitiatedBy.user.ipAddress), tostring(InitiatedBy.user.ipAddress), tostring(InitiatedBy.app.ipAddress))
| mv-apply Property = AddedKeyEvent on
(
where Property.displayName =~ "KeyDescription" or Property.displayName =~ "FederatedIdentityCredentials"
| extend
OldValue = parse_json(tostring(Property.newValue)),
NewValue = parse_json(tostring(Property.oldValue))
)
| extend diff = set_difference(NewValue, OldValue)
| parse diff with * "KeyIdentifier=" keyIdentifier: string ",KeyType=" keyType: string ",KeyUsage=" keyUsage: string ",DisplayName=" keyDisplayName: string "]" *
| project ActivityDateTime, ActivityDisplayName, CorrelationId, Result, TargetName, TargetObjectType, InitiatingBy, InitiatingIpAddress, AddedKeyEvent, AddedKeyId = keyIdentifier, OldValue, NewValueThis query is designed to track and analyze changes made to certain Azure AD applications or service principals, specifically those with the permission 'ADSynchronization.ReadWrite.All'. Here's a simplified breakdown of what the query does:
Identify Relevant Applications:
OAuthAppInfo table. The application names are stored in a variable called EntraConnectAppIdentities.Filter Audit Logs:
AuditLogs table for successful operations related to adding service principals, managing certificates and secrets, or updating applications.Extract Target Resources:
Match with Identified Applications:
Capture Initiator Details:
Analyze Modified Properties:
Calculate Differences:
Extract Key Details:
Project Results:
This query is useful for auditing and monitoring changes to critical applications or service principals in Azure AD, especially those with synchronization permissions, to ensure security and compliance.

Thomas Naunheim
Released: May 28, 2025
Tables
Keywords
Operators