Home / Azure

AzureRunbookAdvanced

Disabled a compromised Entra ID account and it still has access: revoking sessions, CAE and token lifetimes

Contain a compromised Entra ID user properly. Disable and revoke in the right order, know which resources honour revocation at once, rotate what tokens can't cover and prove access has stopped.

Deepak Bhardwaj7 min read

Applies toMicrosoft Entra ID (P1/P2 for Conditional Access and sign-in logs in Log Analytics), Azure RBAC, Microsoft Graph PowerShell SDK 2.x, Azure CLI 2.60+

Symptom

You disabled the user and maybe reset the password. Then the sign-in logs or the Azure Activity Log show the account still doing things for some time afterwards. That's expected behaviour, not a failed control. Disabling the account stops new token issuance. Tokens already issued stay valid until they expire, unless the resource that receives them takes part in Continuous Access Evaluation (CAE).

This runbook contains the account in the right order, shows what revocation doesn't reach, and how to prove access has stopped.

How long tokens live

Token or credential Lifetime Stopped by disable plus revoke?
Refresh token / session cookie Long-lived (days) Yes. Revocation invalidates them.
Access token, non-CAE resource Usually 60–90 minutes No. It stays valid until it expires.
Access token, CAE-aware client and resource Up to 28 hours Yes, close to real time. The resource rejects the token on a critical event.
SAS tokens, storage keys, Key Vault secrets the user read Whatever was set No. Entra ID doesn't know about them.
App registration secrets or certs the attacker added Until they expire No. They belong to a different identity.

CAE-aware resources include Exchange Online, SharePoint Online, Teams and Microsoft Graph. Critical events include account disable or delete, password change or reset, an admin revoking sessions and high user risk. Microsoft documents that propagation can take up to about 15 minutes, while IP-location enforcement is immediate. For other resource APIs, including many Azure data planes, assume the access token works until it expires. Check the current CAE documentation for the resource list.

1. Contain: disable, revoke, reset

Do these back to back. Revocation without disabling lets the attacker sign in again straight away with the password they already have.

Connect-MgGraph -Scopes "User.ReadWrite.All","User.RevokeSessions.All","UserAuthenticationMethod.ReadWrite.All"

$upn = "j.doe@contoso.com"
$user = Get-MgUser -UserId $upn -Property Id,AccountEnabled,OnPremisesSyncEnabled

# 1. Block sign-in
Update-MgUser -UserId $user.Id -AccountEnabled:$false

# 2. Invalidate refresh tokens and session cookies
Revoke-MgUserSignInSession -UserId $user.Id

# 3. Record the revocation time for later checks
(Get-MgUser -UserId $user.Id -Property SignInSessionsValidFromDateTime).SignInSessionsValidFromDateTime

The same calls work from the Azure CLI if that's what you have open:

az ad user update --id j.doe@contoso.com --account-enabled false
az rest --method post --url "https://graph.microsoft.com/v1.0/users/j.doe@contoso.com/revokeSignInSessions"

Warning

If the user is synced from on-premises AD (OnPremisesSyncEnabled = True), the next sync cycle can re-enable the cloud account or put back a password the attacker knows. Disable the account and reset the password in AD as well, and make sure the change has synced.

Then reset the password (in AD for synced users) and review authentication methods. Attackers commonly register their own authenticator app or phone:

Get-MgUserAuthenticationMethod -UserId $user.Id |
  Select-Object Id, @{n='Type';e={$_.AdditionalProperties['@odata.type']}}

Remove anything the real user didn't register. Then require re-registration with a Temporary Access Pass when the account comes back.

2. Remove standing privilege

If the account holds directory roles or Azure RBAC, remove them now. Don't wait for tokens to expire.

# Azure RBAC across the subscriptions you can see (include inherited)
az role assignment list --assignee j.doe@contoso.com --all --include-inherited \
  --query "[].{role:roleDefinitionName, scope:scope}" -o table
# Active and eligible Entra roles (PIM)
Get-MgRoleManagementDirectoryRoleAssignment -Filter "principalId eq '$($user.Id)'"
Get-MgRoleManagementDirectoryRoleEligibilitySchedule -Filter "principalId eq '$($user.Id)'"

ARM checks RBAC on each request, but role assignment changes take a few minutes to take effect. Group-based access is only re-evaluated when a new token is issued. Removing the user from a group doesn't end an access token that already carries that group claim.

3. Close the side doors

Tokens are only one path. In an incident, check for persistence the attacker may have created:

// Everything the account did in the directory since the suspected start
AuditLogs
| where TimeGenerated > ago(7d)
| where tostring(InitiatedBy.user.userPrincipalName) =~ "j.doe@contoso.com"
| project TimeGenerated, OperationName, Result,
          Target = tostring(TargetResources[0].displayName)
| order by TimeGenerated desc

Look for these operations (names vary slightly over time, so search with has):

Look for Why it matters Action
Certificates and secrets on an application Attacker credential on an app Remove the credential and review the app's permissions
Add owner to application / service principal Control of an identity that survives the user being disabled Remove the owner
Consent to application OAuth app with delegated access to mail or files Remove the grant and the enterprise app
Register security info New MFA method Remove it (step 1)
Add member to role / group Privilege escalation Revert it

In Azure, list the write and secret-read operations the user performed so you know what to rotate:

AzureActivity
| where TimeGenerated > ago(7d)
| where Caller =~ "j.doe@contoso.com"
| where OperationNameValue has_any ("listKeys", "listkeys", "regenerateKey", "write", "delete", "secrets")
| summarize count() by OperationNameValue, ResourceGroup, _ResourceId

Any listKeys on a storage account means the attacker may have a key that keeps working regardless of Entra ID. Rotate it. Do the same for Key Vault secrets read through the data plane (check the vault's AuditEvent logs for SecretGet), Cosmos DB keys and any SAS the user generated.

Caution

Rotating a storage account key or a shared secret breaks every legitimate consumer that still uses it. Rotate the key the attacker could have seen, update consumers, then rotate the other one. Don't regenerate both keys at once on a production account.

4. Prove access has stopped

Compare sign-in activity against the revocation time from step 1. Interactive and non-interactive sign-ins are in separate tables, and token refreshes show up in the non-interactive one.

let upn = "j.doe@contoso.com";
let revokedAt = datetime(2026-11-14T09:42:00Z);
union withsource=Table SigninLogs, AADNonInteractiveUserSignInLogs
| where TimeGenerated > revokedAt
| where UserPrincipalName =~ upn
| project TimeGenerated, Table, AppDisplayName, ResourceDisplayName, IPAddress,
          ResultType, ResultDescription
| order by TimeGenerated asc

After revocation you want only failures (for example ResultType 50057, account disabled). A success after the disable usually means one of these:

  • The sync engine re-enabled the account (see the warning in step 1).
  • The success is a CAE-aware app re-evaluating, followed by a failure. Read the sequence, not single rows.
  • A different account is involved. Check IPAddress against other users.

Azure Activity Log entries with the user as Caller can continue until access tokens issued before the revocation expire, which is usually up to about 90 minutes. Anything after that window needs investigation.

5. Tighten for next time

  • Strict location enforcement. In Conditional Access session controls, CAE can be set to strictly enforce location policies. A stolen token replayed from an IP outside your named locations is then rejected by CAE-aware resources. Test in report-only mode first, because split-tunnel VPNs and IPv6 cause false blocks.
  • Token protection (where it's supported) binds tokens to the device and makes replay from another machine fail. Check the current list of supported clients.
  • A scripted containment playbook. Wrap steps 1–2 in an Automation runbook or Logic App with a managed identity, so on-call can run it in one action at 03:00.
  • Short-lived credentials. Prefer RBAC data-plane access over shared keys. Prefer user delegation SAS over account-key SAS. You can invalidate every user delegation SAS on an account with az storage account revoke-delegation-keys -g <rg> -n <account> without rotating account keys. Containment then doesn't depend on rotating secrets.
  • Rehearse. Run the playbook against a test user each quarter and time how long until the sign-in logs show only failures.