Removing a Managed Identity From an Entra Group Leaves Its Access Working for Hours
Overview
The group no longer lists the identity, yet the app still reads the storage account. The token it holds still carries the old group.
At a glance
- Symptom
- A team retires an integration.
- Likely cause
- An identity's groups and roles are expressed as claims in the access token that Microsoft Entra ID issues, and Azure RBAC uses those claims…
- Impact
- For removals, the identity keeps access you meant to withdraw, for a window you cannot shorten.
- Verification signal
- Re-run the two read-only checks.
- Safe correction
- Microsoft recommends treating a user-assigned managed identity as the group.
- Rollback or recovery
- Each state change reverses on its own.
If you take a managed identity out of a Microsoft Entra security group, or remove an app role from it, the Azure resource using that identity can keep its old access for several hours. Microsoft documents that the managed identity back end caches tokens for around 24 hours, and that you cannot force a refresh. To cut access quickly, put the permissions directly on a user-assigned managed identity rather than on a group, and change that role assignment instead.
Symptom
A team retires an integration. The access review says the function app must lose read access to a storage account, so someone removes its managed identity from the app-data-readers group that holds the role assignment. The portal shows the identity gone from the group. The directory change is done and the ticket is closed.
Later that day the function app still reads the storage account without an error. Nothing is misconfigured on the storage side, the group membership list is correct, and the logs show successful requests from the identity. The opposite also happens: you add an identity to a group to grant access, and the first calls still fail.
Why removing the member looks safe
Group changes feel immediate to the people who make them. A user removed from a group signs out and in, or waits for the access token to expire, and the new membership applies. Microsoft states that lifetime is one hour by default. It is natural to expect the same for a managed identity, and the directory view reinforces that, because it shows the new state at once.
Root cause
An identity’s groups and roles are expressed as claims in the access token that Microsoft Entra ID issues, and Azure RBAC uses those claims to evaluate access. So an authorisation change does not apply until the token is refreshed. For managed identities the documentation says the back-end services keep a cache per resource URI for around 24 hours. A change can therefore take several hours to apply. It also says that forcing a refresh before expiry is not possible today.
That is the trap: the removal succeeded, but the token the resource already holds still carries the group. Adding a member behaves the same way in reverse.
Impact
For removals, the identity keeps access you meant to withdraw, for a window you cannot shorten. For additions, a deployment that depends on the new permission fails until the cache turns over, which looks like a bad role assignment and invites further changes. A review that checks only group membership will report the access as removed while the old token is still in use.
How to confirm it
Two read-only checks separate this from a genuine misconfiguration. First check that the directory change did happen, then see what the identity holds directly. Use the identity’s object (principal) ID, not its display name.
- Run
az ad group member checkwith the group and the identity’s object ID. If it reports that the identity is no longer a member while requests still succeed, the cached token is the likely cause. - Run
az role assignment list --assignee <object-id> --all. It lists the identity’s own role assignments across subscriptions, which tells you whether access also comes from a direct assignment you forgot. Without--allit shows the current subscription only.
If a direct assignment exists, that is a second reason access continues, and no waiting will fix it. Related behaviour on other identity changes is covered in System-Assigned Managed Identity Silently Loses Access After a VM Rebuild.
The workarounds that make it worse
Under pressure people try to force the change. Microsoft documents that the token cannot be refreshed on demand, so restarting the app is not a documented fix.
Deleting the identity is a heavier move with its own cost: role assignments are not removed when a managed identity is deleted, so they linger as Identity not found entries, and they count towards the role assignment limit until someone deletes them. Do not delete an identity just to shorten a delay you can plan for.
Correction
Microsoft recommends treating a user-assigned managed identity as the group. Assign permissions directly to the identity, then assign that identity to the Azure resources that need it. Changes then take effect quickly.
Who can attach the identity is controlled with the Managed Identity Contributor and Managed Identity Operator roles. Try it in a non-production subscription first, in the order below. See Adding a Second User-Assigned Managed Identity to an Azure VM for what happens to apps that never named their identity.
- Record the current state: save the output of the two checks above.
- Create the direct role assignment on the user-assigned identity with
az role assignment create, using--assignee-object-id,--assignee-principal-type ServicePrincipal, the role and the narrowest scope that works. - Assign that identity to the resource and confirm the app works with it.
- Only then remove the old group membership with
az ad group member remove, and expect the old token to keep working until its cache expires.
Following along? Tap a step’s number to tick it off.
For a planned offboarding, schedule the removal at least a day before the access must end, and avoid broad scopes such as the one discussed in App Service UAMI at Management Group Scope: Token Theft.
Verification
Re-run the two read-only checks. The group check should report non-membership and the role assignment list should show only the assignments you intend. Then watch the resource’s calls: those relying on the old group should fail once the cache turns over, and calls using the direct assignment should succeed throughout.
Rollback
Each state change reverses on its own. Remove a direct assignment with az role assignment delete using the same assignee, role and scope. Put the identity back in the group with az ad group member add. Because the cache applies in both directions, a rollback also takes hours to be seen.
How to prevent a surprise next time
Prefer direct role assignments on user-assigned identities for anything that must change quickly. Keep groups for human users, where a one-hour token is the norm. Remove orphaned role assignments, those that show Identity not found in the portal, as part of offboarding. Before the next access review, decide who owns the waiting period so a removed identity is not recorded as revoked before the cache has expired.
Apply the safer control
Before you change production
Confirm the affected scope, export the current configuration, and test the replacement control in a non-production environment first.
Fix commands and configuration
app-data-readersaz ad group member checkaz role assignment list --assignee <object-id> --allWhen to escalate
Validation and rollback are covered in the sections above.
Escalate
Escalate when the blast radius is uncertain, the control cannot be tested safely, or remediation requires an outage or security exception.
Fixed? Get the next one before it hits you: The KBY Brief
Practical fixes for the systems you run, by email about twice a week. Unsubscribe at any time.
About this page
Credited to
Dates
Published
Corrections
No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.
Was this useful?
Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.
Found this useful? Follow KBY for more like it.

