1. Resources
  2. Detection sources
  3. Add policy to service principal

Add policy to service principal: A policy was attached to a service principal

Recorded by Core Directory when a policy object is attached to a service principal. A home realm discovery, claims mapping or token lifetime policy changes how users sign in to that one application or what its tokens contain.

Log source
Microsoft Entra ID audit logs
Detection value
Supporting
Volume
Low (estimate)
Last updated
Log
Microsoft Entra ID audit logs (Microsoft Entra ID audit logs, on by default)
Service
Microsoft Entra ID audit logs
Operation
Add policy to service principal
Detects
1 attack (1 rule · 1 detection logic)
MITRE ATT&CK
1 technique in 3 tactics
Threat groups
2 groups that MITRE ATT&CK records using these techniques
Fields the rules read
OperationNameResult

When it is written

Core Directory writes the record in the ApplicationManagement category. Microsoft lists the activity name only. Several application policies take effect for an application when they are attached to its service principal, through Microsoft Graph (servicePrincipals/{id}/homeRealmDiscoveryPolicies/$ref, .../claimsMappingPolicies/$ref, .../tokenLifetimePolicies/$ref, .../appManagementPolicies/$ref) or the matching PowerShell cmdlets:

  • a home realm discovery policy (one per service principal), which can send users straight to a federated identity provider or, with AllowCloudPasswordValidation set to true, let federated users authenticate to this application with a username and password directly at Microsoft Entra ID (password hash synchronization required);
  • a claims mapping policy, which changes the claims the application receives; Microsoft states that these can only be assigned to service principals;
  • a token lifetime policy, which changes how long its access, ID and SAML tokens are valid, up to one day; an organization-level policy takes precedence, and managed identities are not supported;
  • an app management policy (one per object), which the service principal then follows instead of the tenant-wide restrictions on credentials and other properties.

The first three calls take Application.ReadWrite.All and Policy.Read.All, or for an application Application.ReadWrite.OwnedBy and Policy.Read.All, and Microsoft's procedure for home realm discovery policies signs in with at least the Application Administrator role; the app management call takes Application.Read.All and Policy.ReadWrite.ApplicationConfiguration, with the Cloud Application Administrator or Application Administrator role. Microsoft's list of the actions owners can take on their enterprise applications includes microsoft.directory/servicePrincipals/policies/update.

Microsoft does not say which of these assignments write this activity, and the record does not say in a documented field which type of policy was attached. The service principal and the policy are expected in TargetResources and the actor in InitiatedBy; Microsoft shows no sample of this record.

How to turn it on

Microsoft Entra ID audit logs records Add policy to service principal calls to Microsoft Entra ID audit logs without any setup. Vendor documentation

Microsoft Entra ID records the audit log of every tenant without any setup: the records cannot be changed or deleted, and they can be read in the admin center (Entra ID > Monitoring & health > Audit logs) or through Microsoft Graph (auditLogs/directoryAudits). Microsoft keeps them for 7 days with Microsoft Entra ID Free (where collection starts the first time someone opens Entra ID or calls the reporting APIs) and 30 days with P1 or P2. That is not a collection point: to keep the records longer and send them to a SIEM, create a diagnostic setting (Entra ID > Monitoring & health > Diagnostic settings) that includes the AuditLogs category.

  • Destinations: a Log Analytics workspace (the AuditLogs table that Microsoft Sentinel reads; Microsoft notes that sending the logs to Azure Monitor turns on Sentinel's Microsoft Entra ID connector), an event hub (for a third-party SIEM) or a storage account. Creating the setting needs at least the Security Administrator role; any Microsoft Entra ID licence is enough to export the audit log (sign-in logs need P1 or P2). Ingestion and storage are billed by the destination.
  • Microsoft batches the records in intervals of about 5 minutes. After a new setting, allow up to 24 hours before records reach a storage account or SIEM, and up to three days for a Log Analytics workspace.
  • B2C audit events are not included in the integration. With Microsoft 365 E5 or the Purview audit add-ons, Microsoft Purview Audit (Premium) can also keep the Entra ID audit log beyond the default period.
  • One change can write several records: the audit activity reference lists PIM assignments as a requested and a completed activity, and the records of one PIM activation can carry different CorrelationId values (PIM writes roleAssignmentRequestId in AdditionalDetails to tie them together).
  • The address in a record is the OAuth client's address, as the TCP peer of the service's endpoint saw it.
List the tenant's Microsoft Entra diagnostic settings and the categories they export (read only)
az rest --method get --url "https://management.azure.com/providers/microsoft.aadiam/diagnosticSettings?api-version=2017-04-01"
Based on vendor documentation.
Check that AuditLogs records reach the Log Analytics workspace (read only)
az monitor log-analytics query --workspace <workspace-guid> --analytics-query "AuditLogs | summarize LastRecord = max(TimeGenerated), Records = count()" --timespan P1D
Based on vendor documentation.
Find recent Add policy to service principal records (read only)
az rest --method get --url "https://graph.microsoft.com/v1.0/auditLogs/directoryAudits?\$filter=activityDisplayName eq 'Add policy to service principal'&\$top=5"
Based on vendor documentation.

Fields

The operation’s own fields first, then the fields every Microsoft Entra ID audit logs record has. Field names are the JSON paths of the record as the vendor documents it.

FieldWhat it holds
TargetResourcesExpected to name the service principal and the policy that was attached, with their id and displayName. Microsoft documents no target or modified property for this activity and no Microsoft template reads it, so check the layout on a record of your own; the policy type has to be read from the policy itself.
Fields every Microsoft Entra ID audit logs record has (17)
FieldWhat it holds
TimeGeneratedWhen the record was written to the Log Analytics workspace, in UTC.
ActivityDateTimeWhen the activity was performed, in UTC.
OperationNameRead by 1 ruleThe activity, as the audit activity reference names it (for example Add member to role); Microsoft Graph returns the same name as activityDisplayName. The operation this page is about.
CategoryThe audit category of the activity (UserManagement, GroupManagement, ApplicationManagement, RoleManagement, Policy...), as the audit activity reference lists it next to the activity and as Microsoft Graph describes its category property. Microsoft's AuditLogs table reference says instead that Audit is the only supported value, while Microsoft's Sentinel templates filter this column on the audit category (Category =~ "RoleManagement", Category =~ "AzureRBACRoleManagementElevateAccess"). Check the column on a record of your own.
LoggedByServiceThe service that wrote the record (Core Directory, PIM, Conditional Access, Device Registration Service, Account Provisioning...). Each page's sample gives the service name the audit activity reference lists for the activity; Microsoft publishes few raw records, so for most activities the exact string in the column is not shown by Microsoft: check it on a record of your own before matching on it.
AADOperationTypeThe kind of change (Add, Update, Delete, Assign, Unassign or Other).
ResultRead by 1 ruleResult of the activity (success, failure, timeout).
ResultReasonWhy the activity failed or timed out; some services also write a short text for successful activities.
InitiatedBy.user.userPrincipalNameWhen a user performed the activity, the user's UPN.
InitiatedBy.user.idWhen a user performed the activity, the user's object ID.
InitiatedBy.user.ipAddressThe address of the client the user acted from, as the TCP peer of the service's endpoint (the OAuth client's address).
InitiatedBy.app.displayNameWhen an application or a Microsoft service performed the activity, its name (for example MS-PIM for Privileged Identity Management).
InitiatedBy.app.servicePrincipalIdWhen an application performed the activity, the object ID of its service principal.
IdentityThe name of the identity in the token the request was made with: a user, a system account or a service principal.
CorrelationIdAn ID that ties together the records of activities that span services. Privileged Identity Management can write several values for one activation; it puts roleAssignmentRequestId in AdditionalDetails for that.
IdUnique identifier of the record.
AADTenantIdThe Microsoft Entra tenant the activity happened in.

Values to know

TargetResources

ValueMeaningSignal
A home realm discovery policy allowing cloud password validationFederated users can sign in to this application with a password at Microsoft Entra IDIt bypasses the federated identity provider's controls for this application; confirm the reason.Attack signal
A claims mapping or token lifetime policy set up by the application's ownersPlanned single sign-on customizationMatch it to the application's change record.Expected

Volume and noise

Low: policies are attached when an application's single sign-on is set up or customized, or when a legacy application needs a special token lifetime or sign-in path. A policy attached by someone who does not manage the application, or a home realm discovery policy that allows cloud password validation for federated users, is the record to read first.

Keeping it manageable

  • Read the policy in TargetResources and look it up (GET /policies/homeRealmDiscoveryPolicies, claimsMappingPolicies, tokenLifetimePolicies) to learn its type and definition.
  • Match each record to the owner of the application and a change record.
  • For a home realm discovery policy with AllowCloudPasswordValidation, look for password sign-ins by federated users to the application afterwards (the detection logic on this page).

Sample event

A Microsoft Entra ID audit logs record in the vendor’s format, with made-up values.

{
  "TimeGenerated": "2026-11-18T09:31:02.118Z",
  "ActivityDateTime": "2026-11-18T09:30:12.441Z",
  "Id": "Directory_00000000-1111-2222-3333-444444444444_ABCDE_12345678",
  "CorrelationId": "00000000-1111-2222-3333-444444444444",
  "OperationName": "Add policy to service principal",
  "Category": "ApplicationManagement",
  "LoggedByService": "Core Directory",
  "Result": "success",
  "ResultReason": "",
  "Identity": "Ops Admin",
  "InitiatedBy": {
    "user": {
      "id": "00000000-0000-0000-0000-00000000b0b0",
      "displayName": "Ops Admin",
      "userPrincipalName": "ops-admin@corp.example.com",
      "ipAddress": "203.0.113.24"
    }
  },
  "TargetResources": [
    {
      "id": "00000000-0000-0000-0000-0000000b1b1b",
      "displayName": "Legacy Reporting Portal",
      "type": "ServicePrincipal",
      "modifiedProperties": []
    },
    {
      "id": "00000000-0000-0000-0000-0000000c2c2c",
      "displayName": "HRD - allow cloud password",
      "type": "Policy",
      "modifiedProperties": []
    }
  ],
  "AdditionalDetails": [],
  "AADTenantId": "00000000-0000-0000-0000-00000000aaaa"
}

Attacks this event reveals

Detection rules that read this event:

References