Expired Service Principal Credentials Leave PIM Role Active
0 reputation · 20 Jul 2021, 08:07 UTC
0 reputation · 20 Jul 2021, 08:07 UTC
When a service principal is granted an elevated role through Azure AD Privileged Identity Management (PIM), the role assignment can be activated within a defined window. The service principal’s password or certificate credential may be set to expire, yet PIM keeps the role assignment active once it has been granted. This creates a potential security gap: an expired credential can still be used to perform privileged actions if the role assignment remains active.
Current public documentation indicates that PIM does not automatically revoke the role assignment when the credential expires, and no API or policy setting forces such revocation. The behavior is consistent across tenants, though custom roles or conditional access policies may influence the outcome.
Key questions for investigation:
35775 reputation · 20 Jul 2021, 14:06 UTC
Azure AD Privileged Identity Management (PIM) does not automatically revoke or deactivate a role assignment when a service principal’s password or certificate credential expires. The assignment remains active until the assignment itself expires or an administrator removes it.
• PIM tracks the role assignment lifecycle, not the underlying credential state.
• Microsoft Graph exposes credential expiration but has no built‑in trigger that links it to PIM assignments.
• Conditional Access policies cannot evaluate credential expiration; they only evaluate sign‑in context.
1. Detect Expired Credentials
# Graph API query (JSON) – list credentials with expiry past today
GET https://graph.microsoft.com/v1.0/servicePrincipals/{sp-id}/appRoleAssignments?$filter=appRoleId eq 'role-id'
# Or PowerShell
Get-AzADServicePrincipal -DisplayName "MySP" | Get-AzADAppCredential | Where-Object {$_.EndDate -lt (Get-Date)}
2. Check for Active PIM Role Assignments
# List active PIM assignments for the SP
GET https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments?$filter=principalId eq '{sp-id}' and isActive eq true
3. Deactivate or Remove the Assignment
# Delete the specific role assignment (requires Privileged Role Admin or Global Admin)
DELETE https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments/{assignment-id}
4. Automate the Process
5. Validate the Result
Do you currently have a renewal or rotation workflow for service principal credentials that runs before the expiry date? This will determine if the automation should only alert or also block the role assignment.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.