Azure AD service principal token persists after client credential expiry
0 reputation · 05 Feb 2022, 00:17 UTC
0 reputation · 05 Feb 2022, 00:17 UTC
When a service principal's client credential expires, previously issued access tokens remain valid until their own intrinsic expiry, typically 60–90 minutes, because Azure AD token validation does not re-check credential status after issuance. This means the token's granted roles and permissions are fixed for its lifetime and do not reflect subsequent role revocation or credential rotation.
Credential rotation, which adds a new secret or certificate before removing the old one, creates an overlap period where both the old and new credentials can obtain new tokens, potentially widening the attack surface if the original credential is compromised. However, there is no built-in mechanism to instantly revoke all tokens issued under an expired or rotated credential, nor to enforce least-privilege constraints after token issuance.
Conditional Access policies can enforce shorter session lifetimes or re-authentication for interactive user sign-ins, but they do not apply to non-interactive service principal client-credential flows, leaving a gap in automated token lifecycle management for workload identities.
What mechanisms, if any, can reliably invalidate tokens issued under expired service principal credentials without disrupting legitimate operations? How does role-based access control interact with tokens issued before credential rotation? Can organizational policies bridge the gap between token lifetime and credential expiry for service principals?
35275 reputation · 05 Feb 2022, 06:31 UTC
There is no native, built-in mechanism to instantly revoke access tokens issued to a service principal once the client secret or certificate expires. Because Azure AD access tokens are stateless JSON Web Tokens (JWTs), resource providers validate them locally by checking the digital signature and the exp claim rather than performing a live check against Entra ID (formerly Azure AD) for every request.
When a credential expires, any token already issued remains valid until its intrinsic lifetime ends—typically 60 to 90 minutes. Furthermore, Role-Based Access Control (RBAC) permissions are evaluated at the moment of token issuance. If a role is revoked from a service principal after a token has been cached, that token will retain the granted permissions until it naturally expires.
To bridge the gap between token lifetime and credential expiry, consider the following technical approaches:
Standard credential rotation (adding a new secret before deleting the old one) is designed for zero-downtime. This creates an overlap period where both credentials are valid. If the original credential is compromised, rotation alone does not invalidate the tokens generated by the compromised secret; it only prevents new tokens from being issued using that secret.
Note: Is your application using a custom middleware that caches tokens in-memory, or is it requesting a new token for every transaction? Understanding the caching behavior is critical for determining the actual window of risk.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.