Stolen service principal credential used to change permissions
An attacker signs in as a service principal with a stolen client secret or certificate, adds a credential of their own, and grants the application roles or permissions. The attacker keeps access after you rotate the stolen secret if their added credential survives. Disable the service principal first, which keeps its credentials as evidence, then remove what the attacker added.
Look here
Log
Search for
AADServicePrincipalSignInLogs
New IP addresses for the app, and the credential each sign-in used. ServicePrincipalCredentialKeyId names the credential, and ServicePrincipalCredentialThumbprint names a certificate: AADServicePrincipalSignInLogs | where AppId == "<app-id>" | summarize count() by IPAddress, ServicePrincipalCredentialKeyId, ServicePrincipalCredentialThumbprint, ResourceDisplayName, ResultType
AuditLogs, credentials
Secrets and certificates added. Add service principal credentials covers the service principal. The app registration activity contains an en dash, so match it with has: Update application – Certificates and secrets management
AuditLogs, roles and owners
Roles, owners and consents added: Add member to role, Add eligible member to role, Add owner to application, Consent to application and Add app role assignment to service principal
AuditLogs, query
These activities with their initiator and target: AuditLogs | where OperationName has_any ("Add service principal credentials", "Certificates and secrets management", "Add app role assignment to service principal", "Add member to role", "Add eligible member to role") | project TimeGenerated, OperationName, InitiatedBy, TargetResources
AzureActivity
Azure role assignments and custom roles the app created, logged under Microsoft.Authorization as roleAssignments/write and roleDefinitions/write. Query the assignments: AzureActivity | where OperationNameValue =~ "Microsoft.Authorization/roleAssignments/write" | project TimeGenerated, Caller, CallerIpAddress, _ResourceId, Properties_d
MicrosoftGraphActivityLogs
Graph calls by the app: MicrosoftGraphActivityLogs | where AppId == "<app-id>" | project TimeGenerated, IPAddress, RequestMethod, RequestUri, ResponseStatusCode
SecurityAlert
Defender for Resource Manager alerts, by AlertType: ARM_AnomalousRBACRoleAssignment and ARM_AnomalousServiceOperation.CredentialAccess
Contain
#
Item
1
Record the app registration's secrets, then run the same command with --cert for its certificates: az ad app credential list --id <app-id>
2
Record the service principal's secrets, then run the same command with --cert: az ad sp credential list --id <sp-object-id>
3
Disable the service principal, which keeps its credentials and assignments as evidence: Update-MgServicePrincipal -ServicePrincipalId <sp-object-id> -AccountEnabled:$false
4
Remove Azure role assignments added in the window: az role assignment delete --ids <assignment-id>
5
Find the service principal's directory roles: Get-MgRoleManagementDirectoryRoleAssignment -Filter "principalId eq '<sp-object-id>'"
6
Remove the directory roles the attacker added: Remove-MgRoleManagementDirectoryRoleAssignment -UnifiedRoleAssignmentId <id>
7
Find the application permissions granted to it: Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId <sp-object-id>
8
Remove the application permissions the attacker added: Remove-MgServicePrincipalAppRoleAssignment -ServicePrincipalId <sp-object-id> -AppRoleAssignmentId <id>
9
Delete the attacker's credential on the app registration destructive, after recording. Add --cert for a certificate: az ad app credential delete --id <app-id> --key-id <key-id>
10
Delete the attacker's credential on the service principal destructive, after recording. Add --cert for a certificate: az ad sp credential delete --id <sp-object-id> --key-id <key-id>
Eradicate and recover
#
Item
1
Search AuditLogs for credentials added to any other application in the window and remove unknown ones
2
Remove owners added through Add owner to application or Add owner to service principal
3
Issue one new credential to the workload's secret store: az ad app credential reset --id <app-id> --append
4
Re-enable the service principal: Update-MgServicePrincipal -ServicePrincipalId <sp-object-id> -AccountEnabled:$true
5
Block the service principal outside known IP ranges with a Conditional Access location policy (single-tenant apps, Workload Identities Premium license)
Watch out
az ad app credential reset without --append clears every existing secret and certificate on the app. Record them as evidence first.
An application and its service principal each have their own credentials. Check and clean both lists.
Disabling the service principal blocks new tokens only. Tokens already issued keep working for up to 90 minutes, so remove its role assignments too and keep watching its sign-ins.
Microsoft Learn: Entra audit log activity reference; AADServicePrincipalSignInLogs, AuditLogs, AzureActivity and MicrosoftGraphActivityLogs table references; access token lifetime; Conditional Access for workload identities; Azure CLI reference for az ad app credential and az ad sp credential; Microsoft Graph PowerShell reference for the cmdlets used. Checked October 2026. Defender for Cloud alerts for Resource Manager: checked October 2026.