Skip to content
high severityMicrosoft Sentinel

Detect new app or service principal secrets (KQL)

Adding a client secret or certificate to an application or service principal gives an attacker a durable, MFA-free way back into the tenant that survives password resets. This AuditLogs query returns credential-management operations on apps and service principals, resolves the actor, and extracts the key description from modifiedProperties.

Credential additions on highly privileged apps should be rare; treat a new secret on an app with directory write permissions as high priority.

The query

AuditLogs
| where TimeGenerated > ago(24h)
| where OperationName in (
    "Add service principal credentials",
    "Update application – Certificates and secrets management",
    "Update application")
| extend Actor = coalesce(
      tostring(InitiatedBy.user.userPrincipalName),
      tostring(InitiatedBy.app.displayName))
| mv-expand TargetResources
| extend TargetApp = tostring(TargetResources.displayName)
| mv-apply mp = TargetResources.modifiedProperties on (
    where tostring(mp.displayName) in ("KeyDescription", "KeyIdentifier")
    | project Change = strcat(tostring(mp.displayName), ": ", tostring(mp.newValue))
  )
| project TimeGenerated, Actor, TargetApp, Change, Result
| sort by TimeGenerated desc

Line-by-line explanation

  • | where OperationName in ("Add service principal credentials", ...)

    Covers the operations written when a secret or certificate is added to a service principal or application registration.

  • where tostring(mp.displayName) in ("KeyDescription", "KeyIdentifier")

    KeyDescription records the credential type and display name; KeyIdentifier its id. Extracting them shows what was added without the full diff.

  • extend TargetApp = tostring(TargetResources.displayName)

    Identifies which application or service principal received the new credential, so you can judge its privilege.

Required tables and columns

  • OperationNameThe credential-management operation on an app or service principal.
  • TargetResourcesThe affected app/service principal and its modifiedProperties (the key details).
  • InitiatedByThe user or app that added the credential.
  • ResultSuccess or failure of the operation.

MITRE ATT&CK mapping

Tuning and false positives

  • Cross-reference TargetApp against your inventory of high-privilege apps and alert louder when those receive new credentials.
  • Exclude known CI/CD or secret-rotation service principals that add credentials on a schedule.

Limitations

  • The exact OperationName strings have changed over time; confirm the values present in your tenant and add any variants.
  • The secret value is never logged, so this detects the addition, not misuse — correlate with later service-principal sign-ins.

References

Last reviewed 2026-11-18.