Join our Newsletter — 33% off our NHI Course
Home› Guides› How to investigate a compromised Azure service principal:…
Guide Incident Response & Forensics

How to investigate a compromised Azure service principal: sign-in logs, activity log and Graph activity

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 20 November 2026 15 min read
On this page

Investigating a compromised Azure service principal means answering four questions from four log sources: which credential was used (service principal sign-in logs), what changed in the directory (Entra audit logs), what was done to Azure resources (the Activity log) and what data was read or written through Microsoft Graph (Graph activity logs). Service principals do not have a user who notices odd prompts or reports a phishing email. When one is compromised, the first signal is often an alert on a new credential, a sign-in from an unfamiliar network, or an unexpected burst of Graph calls, and the investigation has to reconstruct everything else from logs.

This guide is a working runbook for that reconstruction: the evidence to secure first, how to pivot between the log sources using the identifiers they share, the persistence techniques to check, and how to contain and recover without destroying evidence. It focuses on the investigation itself. For a full incident playbook template covering roles, notification and post-incident review for third-party multi-tenant apps, see the Multi-Tenant SaaS App Credential Compromise Playbook, and for subscription-wide incidents the Azure Subscription Compromise Playbook.

This is an independent guide from NHI Mgmt Group, based on Microsoft's public documentation as of November 2026. It is not sponsored or reviewed by Microsoft. Product features change, so confirm settings against Microsoft's current documentation.

Key takeaways

  • Correlate four sources: service principal sign-in logs, Entra audit logs, the Azure Activity log and Microsoft Graph activity logs.
  • The credential key ID or thumbprint in each sign-in tells you which secret or certificate the attacker holds; compare it with the credentials on the application and service principal objects.
  • Check both the application object and the service principal object for added credentials; Microsoft documents credential removal endpoints on both.
  • Graph activity logs show the actual API calls, and their SignInActivityId joins to the sign-in log's UniqueTokenIdentifier.
  • Graph activity logs need Entra ID P1 or P2 and a diagnostic setting configured before the incident; if they were not enabled, record that gap early.
  • Contain in a coordinated eviction: disable the service principal, remove every credential, then review role assignments, consents and owners before re-enabling anything.

Secure the evidence before you act

Containment actions such as deleting credentials or the application change the very objects you need to examine. Spend the first minutes capturing state.

  • Snapshot the objects. Export the application object and the service principal object, including passwordCredentials, keyCredentials, federated identity credentials, owners, required resource access, app role assignments, OAuth2 permission grants and redirect URIs. Record each credential's key ID, display name, start and end dates.
  • Snapshot Azure RBAC. Export role assignments where the service principal is the assignee across management groups, subscriptions and resource groups, and any directory role assignments. Our Privileged Service Principal Check covers the directory side.
  • Preserve logs beyond default retention. Confirm where sign-in logs, audit logs, the Activity log and Graph activity logs are routed (Log Analytics, storage or an event hub) and export the relevant window to storage you control. If any source was never routed anywhere, write that down now; it limits what you can conclude.
  • Note latency. Microsoft states that Graph activity log events are delivered within 30 minutes in most regions and can take up to 2 hours. Queries run immediately after an alert may be incomplete.

Decide early whether the attacker may also hold administrator credentials. Microsoft's compromised and malicious application investigation playbook advises weighing business impact before disabling an application and, where admin credentials may also be compromised, coordinating with an eviction event so that all access routes are cut at once. Acting on the service principal alone can tip off an attacker who still has another way in.

Scope the identity

Before reading logs, understand what the service principal is and what it can reach. This defines the blast radius and tells you which resources to examine.

  • Single tenant or multi-tenant. Microsoft's playbook distinguishes single-tenant applications, whose owners you can find under Enterprise Applications, Owners or through GET /applications/{id}/owners in Microsoft Graph, from multi-tenant applications hosted by a third party, where you need to contact the vendor. A third-party multi-tenant app's credentials are held by the vendor, which changes containment. See How to find multi-tenant Azure app registrations.
  • Risk state. Check Microsoft Entra ID Protection risky workload identities for the service principal's risk state, as the playbook recommends.
  • Permissions. List Microsoft Graph application permissions (app roles), delegated grants, directory roles and Azure RBAC roles. Application permissions such as broad directory or mailbox access matter more than anything else here, because they let the attacker act without any user.
  • Owners. Every owner of the application can add credentials. Owners are part of the blast radius and a possible route of initial compromise.

Read the service principal sign-in logs

Service principal sign-ins are recorded separately from user sign-ins. Microsoft's service principal sign-in documentation describes them as sign-ins by apps or service principals that supply their own credential, such as a certificate or app secret, and notes that managed identity sign-ins appear only in the managed identity sign-in log. Entries are system generated and cannot be changed or deleted.

In Log Analytics the data lands in the AADServicePrincipalSignInLogs table. The table reference documents the columns that matter most to an investigation:

ColumnWhat it tells you
ServicePrincipalId, ServicePrincipalName, AppIdWhich identity signed in
ServicePrincipalCredentialKeyId, ServicePrincipalCredentialThumbprintWhich secret or certificate was used
ClientCredentialTypeThe credential type, for example client secret or client assertion
FederatedCredentialIdWhich federated identity credential was used, if any
IPAddress, AutonomousSystemNumber, LocationDetailsWhere the sign-in came from
ResourceDisplayName, ResourceIdentityThe resource the token was for (for example Microsoft Graph or Azure Resource Manager)
ResultType, ResultSignature, ResultDescriptionSuccess or failure and the error
ConditionalAccessStatus, ConditionalAccessPoliciesWhether workload identity policies applied
UniqueTokenIdentifierThe join key to Graph activity logs

Work through these questions:

  1. Which credential? Group successful sign-ins by ServicePrincipalCredentialKeyId and thumbprint. A key ID that does not match any credential the owning team recognises, or a recently added one, is the strongest single indicator. A key ID that matches a legitimate credential used from a new network points to theft of an existing secret.
  2. From where? Compare IP addresses and autonomous system numbers against the known hosting of the workload. A service principal that normally signs in from one cloud region or a fixed egress range should not appear from a consumer network or a hosting provider it does not use.
  3. For what? Look for new ResourceDisplayName values. A workload that only ever requested tokens for one API and suddenly requests Microsoft Graph or Azure Resource Manager tokens has changed behaviour.
  4. How often, and when did failures start? Microsoft's playbook lists unexpected locations, failures, odd timestamps, increased frequency and publicly leaked credentials as signals. Failed sign-ins with an old key ID can show an attacker testing a stolen secret before it worked.

An illustrative query to start from (adapt the time range and identifiers):

AADServicePrincipalSignInLogs | where TimeGenerated > ago(30d) | where ServicePrincipalId == "<sp-object-id>" | summarize Count=count(), FirstSeen=min(TimeGenerated), LastSeen=max(TimeGenerated) by ServicePrincipalCredentialKeyId, IPAddress, ResourceDisplayName, ResultType

Check the Entra audit logs for persistence

An attacker with control of a service principal, or of an account that owns it, typically adds a credential of their own so that access survives a rotation (MITRE ATT&CK T1098.001 Additional Cloud Credentials). Microsoft's playbook directs investigators to the Entra audit logs, category Application Management, and to these activities:

Audit activityWhat to look for
Update Application, Certificates and secrets managementNew secrets or certificates on the application object
Update Application and Update Service PrincipalConfiguration changes: permissions, redirect URIs, sign-out URLs, and accountEnabled set to true (re-enablement)
Add app role assignment to service principalNew application permissions, especially high-privilege Graph roles
Consent to applicationNew consent grants; check whether consent was admin consent and which permissions were granted
Add Service PrincipalRecovery of a soft-deleted application or creation of a new one

Check both objects. Credentials can sit on the application object (in the home tenant) or directly on the service principal, and Microsoft documents removal endpoints for both. Credentials placed on the service principal are easy to miss because many portal views focus on the app registration. The playbook also calls for checking for custom roles created or modified, anomalous configuration changes including redirect URIs that point at expired domains an attacker could claim, unverified commercial apps, and phishing aimed at application owners and consent administrators in the unified audit log over the past 7 days, extending to 14 and 30 if needed.

Record who made each change. If a user account added the credential, that user is now in scope as a possible initial access vector and needs its own investigation.

Trace Azure resource actions in the Activity log

If the service principal holds Azure RBAC roles, the Activity log shows what it did to subscriptions and resources. According to Microsoft's Activity log event schema, the Administrative category records create, update, delete and action operations processed through Azure Resource Manager, including changes to role assignments. For operations that start processing, both the start and the final success or failure are recorded. Requests rejected during authentication or authorisation before the operation starts are not recorded, so the Activity log will not show failed attempts to use permissions the service principal does not have.

Key fields in each Administrative event:

  • caller: the schema defines this as the email address, UPN claim or SPN claim of whoever performed the operation, based on availability.
  • claims: the JWT used to authenticate the operation. Use the application identifier and object identifier claims to confirm which service principal made the call; treat this as matching on token contents rather than a documented one-field mapping.
  • authorization: the action, scope and usually the role that permitted it.
  • operationName, resourceId, status, correlationId and eventTimestamp.

Prioritise operations that create persistence or exfiltrate data: new role assignments, new managed identities or federated credentials, key vault access policy or role changes, storage account key listing, run command and extension operations on virtual machines, and new automation accounts or function apps. For the VM side, see How to detect Azure Run Command and VM extension abuse. The Administrative category covers operations processed through Azure Resource Manager, so also review each sensitive resource's own diagnostic logs, where enabled, for direct data access.

Reconstruct data access with Microsoft Graph activity logs

Graph activity logs fill the biggest gap in most service principal investigations: what the attacker actually read or changed through Microsoft Graph. Microsoft's Graph activity logs overview describes them as an audit trail of all HTTP requests that Microsoft Graph receives and processes for a tenant.

Prerequisites matter here because they must be in place before the incident. Microsoft lists a Microsoft Entra ID P1 or P2 tenant licence, an administrator with a supported role (Security Administrator is the least-privileged supported role for configuring diagnostic settings), and a destination: a Log Analytics workspace, a storage account or an event hub. Logs are streamed through diagnostic settings. Microsoft also notes that logs cover only the resource tenant, so you cannot see a multi-tenant application's activity in other tenants, and that diagnostic settings cannot filter the logs.

In Log Analytics the table is MicrosoftGraphActivityLogs. Useful fields include AppId, ServicePrincipalId, IPAddress, RequestUri, RequestMethod, ResponseStatusCode, Roles and Scopes from the token, TokenIssuedAt, UserAgent, ClientAuthMethod (0 public client, 1 client ID and secret, 2 client certificate) and SignInActivityId.

Pivot from sign-ins to API calls. Microsoft's documentation shows joining MicrosoftGraphActivityLogs to the sign-in tables, including AADServicePrincipalSignInLogs, on SignInActivityId equal to UniqueTokenIdentifier. That join links each suspicious sign-in (with its credential key ID and IP) to the exact requests made with the resulting token. An illustrative investigation query:

MicrosoftGraphActivityLogs | where TimeGenerated > ago(7d) | where ServicePrincipalId == "<sp-object-id>" | extend Path = tostring(parse_url(RequestUri).Path) | summarize Requests=count(), FirstSeen=min(TimeGenerated), LastSeen=max(TimeGenerated) by IPAddress, RequestMethod, Path, ResponseStatusCode | order by Requests desc

Look for reads of mailboxes, files, users and groups that the workload never normally touches, write operations (POST, PATCH, DELETE) against applications, service principals, role assignments or credentials, and bursts of 401 and 403 responses that show the attacker probing permissions. Microsoft's sample queries include one for entities failing authorisation, which works well as a probing detector.

Contain the service principal

Once scope is understood, act in one coordinated window. Microsoft's playbook gives the specific actions:

  1. Disable sign-in. In the portal set Enabled for users to sign in to No, or set accountEnabled to false on the service principal with Update-MgServicePrincipal in Microsoft Graph PowerShell. This stops new tokens being issued to it.
  2. Remove credentials from both objects. Use removePassword and removeKey on the application (/applications/{id}) and on the service principal (/servicePrincipals/{id}). Remove federated identity credentials that are not recognised.
  3. Roll to a new credential. Microsoft describes adding a new certificate with addKey and then immediately removing all old credentials. Where the workload runs in Azure, consider moving it to a managed identity or federated credential instead of issuing another secret; see How to replace Azure app secrets with federated credentials.
  4. Remove attacker changes. Revert added app role assignments, consents, redirect URIs, owners and Azure role assignments found during the investigation.
  5. Delete only when certain. Microsoft notes a soft delete of an application is recoverable for 30 days and a permanent delete uses the deleted items endpoint. Preserve the snapshots first.

Keep monitoring Graph activity and the Activity log for the identity after disabling it, and confirm activity stops. Then watch the audit logs for Update Service Principal with accountEnabled set back to true, and for Add Service Principal, which Microsoft identifies as signs of re-enablement or recovery.

Recover and harden

  • Reduce permissions on return. Re-enable the workload with the minimum Graph and Azure roles it actually used in the clean baseline period, taken from the logs you just reviewed.
  • Prefer credentials that cannot be copied. Managed identities and federated credentials remove long-lived secrets. Where secrets remain, keep them short-lived and vaulted; see the Azure Entra Client Secrets Security Guide.
  • Restrict where it can sign in from. Where your tenant supports Conditional Access for workload identities, limit sign-ins to known network ranges and check the outcome in ConditionalAccessStatus.
  • Turn on the logs you were missing. If Graph activity logs or service principal sign-ins were not routed to a workspace, fix that now and set retention to cover your typical detection delay.
  • Detect the persistence pattern. Alert on credential additions to applications and service principals outside change windows, new app role assignments for high-privilege Graph roles, and sign-ins with key IDs not seen before.
  • Review owners. Remove unnecessary owners and make sure every application has an accountable team.

Common failure patterns

  • Rotating the secret and stopping there. The attacker's own added credential, often on the service principal object, keeps working.
  • Checking only the app registration. Credentials and role assignments on the service principal object are missed.
  • Deleting the application first. Evidence in the object's configuration is lost and the deletion can be reversed by anyone with rights during the soft delete window.
  • Querying only sign-in logs. Sign-ins show access, not actions; without Graph activity and the Activity log, impact is unknown.
  • No Graph activity logs configured. Data access through Graph cannot be reconstructed after the fact.
  • Ignoring the owners. The user who added the malicious credential is never investigated.
  • Containing piecemeal. Disabling the service principal while an attacker still holds an admin account or another credential just alerts them.

Practitioner checklist

  • Snapshot the application and service principal objects, owners, permissions, consents and RBAC assignments before changing anything.
  • Export sign-in, audit, Activity log and Graph activity data for the investigation window to storage you control.
  • Group service principal sign-ins by credential key ID, IP, resource and result to identify the misused credential.
  • Review Application Management audit activities for credential, permission, consent and re-enablement changes on both objects.
  • Review Administrative Activity log events where the service principal is the caller, prioritising role assignments and secret access.
  • Join Graph activity logs to sign-ins on SignInActivityId and UniqueTokenIdentifier to see exactly which API calls each token made.
  • Contain in one window: disable the service principal, remove all credentials on both objects, revert attacker changes.
  • Move the workload to a managed identity or federated credential where possible and re-grant least privilege.
  • Enable missing log sources and alert on new credentials and new key IDs for privileged service principals.

Standards and references

Related NHI Mgmt Group resources: Multi-Tenant SaaS App Credential Compromise Playbook · Azure Subscription Compromise Playbook · Azure RBAC and Service Principals Guide · Entra Service Principal Sign-In Errors Guide (AADSTS7000215, 7000222, 700016)

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.