Identify app registrations with credentials expiring soon and flag privileged service principals that are unused or stale.
Complexity: Advanced. Impact: security + compliance + identity + privileged-access + credential-management + audit.
Why use this workflow
Entra ID (Azure AD) app registrations are a common source of security incidents and outages. Client secrets and certificates silently expire, which breaks backup jobs, line-of-business integrations, and SSO. Abandoned apps with directory roles like Global Administrator provide a persistent, often forgotten attack path.
This workflow helps you perform a regular audit that answers two questions:
- Which app registrations have client secrets or certificates expiring within a window that you choose and need rotation before they cause an outage?
- Which apps hold privileged directory roles (Global Administrator and similar) and have not been used recently, making them candidates for removal or role reduction?
Run it on a regular schedule, or as part of access reviews, tenant hardening projects, or after an ownership change (for example, when an admin leaves the organization).
Expected outcomes
- A full inventory of app registrations with any client secret or certificate expiring within your chosen window, including the hint or thumbprint and expiry date.
- A list of apps whose service principals are assigned the Global Administrator role (or other privileged roles you target), together with their last sign-in activity.
- Flagged candidates for credential rotation and for role reduction or deletion.
- A repeatable process that you can schedule and feed into a ticketing system or notification channel.
Risks and considerations
- Do not delete unknown apps. Many Microsoft first-party and third-party SaaS connectors appear in app registrations or enterprise applications. Confirm ownership before you remove credentials or roles.
- Rotating a secret breaks the consumer. Coordinate with the app owner before you invalidate a credential: generate the new secret, hand it over, and remove the old one only once the consumer has switched.
- signInActivity requires AuditLog.Read.All and an Entra ID P1 or P2 license. In tenants without this data, treat "unknown last sign-in" as "needs manual review," not "safe to remove."
- Global Administrator on a service principal is almost always wrong. Apps should use the least-privileged application permission they need. If you find one, investigate how it was granted (often through admin consent on a legacy app) and look for non-human-readable names, which can be a compromise indicator.
- Federated credentials (workload identity federation) do not expire like secrets or certificates. The audit should not treat a missing
endDateTimeas a finding. - The audit is read-only. Mitigation (rotating or removing credentials) is a separate change that must follow your normal change control.
Required permissions
| Permission | Why it's needed |
|---|---|
| Application.Read.All | List all app registrations and read their passwordCredentials and keyCredentials |
| Directory.Read.All | Read service principals and directory role assignments |
| RoleManagement.Read.Directory | Enumerate directory role assignments to identify privileged apps |
| AuditLog.Read.All | Read signInActivity on service principals to determine recent use |
Ask Dex
Paste the prompt into a Dex conversation.
Prompt for IT admins
Audit our Entra ID app registrations. List any apps with client secrets or certificates expiring within the next {days} days, and flag any apps whose service principals hold Global Administrator (or other privileged directory roles) that haven't signed in within the last {inactive_days} days. Return a report I can hand to owners for rotation or cleanup.
Manual steps (admin center)
This walkthrough is useful for spot checks or when you need to act on a single finding. For a full tenant audit, the API or PowerShell approach is far more efficient.
Part 1: Find expiring secrets and certificates
- Sign in to the Microsoft Entra admin center as an account with Application Administrator or Global Reader.
- Go to Identity > Applications > App registrations.
- Select the All applications tab so you are not limited to apps you own.
- Select Columns and enable the Certificates & secrets column if it is available, or review each app individually.
- For each app, open it and go to Certificates & secrets. Note any Client secrets or Certificates with an Expires date inside your window.
- Record the app name, the credential hint or thumbprint, and the expiry date in your tracker.
Part 2: Find apps with Global Administrator (or other privileged roles)
- In the Entra admin center, go to Identity > Roles & admins > Roles & admins.
- Open the Global Administrator role.
- Review the Assignments tab. Assignments whose Type is Service Principal (not User or Group) are the apps you care about.
- Select each service principal to open its overview, then go to Sign-in logs (or review the Sign-in activity column) to see when the app last authenticated.
- Flag any service principal whose last sign-in is older than your inactivity threshold, or which has never signed in.
- Repeat for other high-privilege roles you care about: Privileged Role Administrator, Application Administrator, Cloud Application Administrator, Privileged Authentication Administrator, User Administrator, Exchange Administrator, and SharePoint Administrator.
Part 3: Triage findings
- For expiring credentials: contact the app owner and coordinate a rotation before the expiry date.
- For inactive privileged apps: confirm with the owner whether the role is still required. If not, remove the role assignment or delete the app.
Microsoft Graph API
The audit requires cross-referencing three Graph collections: applications (for credentials), servicePrincipals (for sign-in activity), and roleManagement/directory/roleAssignments (for privileged role holders).
Step 1: List all app registrations with credentials
GET https://graph.microsoft.com/v1.0/applications?$select=id,displayName,appId,passwordCredentials,keyCredentials&$top=999Follow @odata.nextLink until all pages are consumed. Each app's passwordCredentials[] and keyCredentials[] contain an endDateTime field in ISO 8601 format.
Step 2: Enumerate Global Administrator assignments
Global Administrator has the well-known template ID 62e90394-69f5-4237-9190-012177145e10:
GET https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments?$filter=roleDefinitionId eq '62e90394-69f5-4237-9190-012177145e10'Each result contains a principalId. Collect them into a set. Any service principal whose id is in that set has Global Administrator.
Step 3: Fetch service principals with sign-in activity
GET https://graph.microsoft.com/beta/servicePrincipals?$select=id,appId,displayName,signInActivitysignInActivity.lastSignInDateTime is populated only when the app has signed in during the audit log retention window, and it requires AuditLog.Read.All plus Entra ID P1 or P2.
Step 4: Correlate and report
Build a dictionary of service principals keyed by appId. For each application:
- Walk
passwordCredentialsandkeyCredentials. Report any whoseendDateTimeis within your window and still in the future. - Look up the matching service principal and check whether its
idis in the Global Administrator set. If so, evaluatesignInActivity.lastSignInDateTimeand flag it if it is older than your inactivity threshold or absent.
Example finding shape
{
"expiringSoon": [
{ "appName": "Backup Connector", "type": "Secret", "expiry": "2026-03-19T00:00:00Z" }
],
"flaggedPrivilegedApps": [
{ "appName": "Legacy Provisioning Tool", "role": "Global Administrator", "lastSignIn": "2024-08-02T11:14:00Z" }
]
}
PowerShell
Use the Microsoft.Graph PowerShell SDK to run the complete audit and emit a CSV report. Install the modules once:
Install-Module Microsoft.Graph.Applications,Microsoft.Graph.Identity.DirectoryManagement,Microsoft.Graph.Identity.SignIns -Scope CurrentUserThen authenticate with the required scopes:
Connect-MgGraph -Scopes "Application.Read.All","Directory.Read.All","RoleManagement.Read.Directory","AuditLog.Read.All"Approach
- Page through every app registration and check both
PasswordCredentialsandKeyCredentialsfor expiry within a configurable window. - Enumerate role assignments for a configurable set of privileged directory roles (for example, Global Administrator).
- Pull
signInActivityfrom the beta service principal endpoint and flag any privileged app that is inactive beyond a configurable threshold. - Write the results to CSV files and print a summary to the console.
Run the audit on a schedule (Azure Automation, Task Scheduler, or a pipeline) and feed the CSV output into your ticket system or a Teams webhook for follow-up.