Published
Azure CLI Session Limits: Why They Matter and How to Set Them Up
Set an Azure CLI session limit on purpose: how token lifetimes, Conditional Access, MFA, PIM and workload identities keep a stolen az login from owning prod.
- Written by
- Ali ÖzdurmuşFounder, Veni AI
- Reading time
- 8 min read

An Azure CLI session on a laptop is a key to production. After az login, the CLI holds tokens that can create, change and delete resources, and it keeps renewing them in the background. A stolen laptop, a copied .azure folder or a forgotten session on a shared jump host hands that power to someone else.
An Azure CLI session limit is the control that bounds that risk. This guide explains why it matters, what actually limits a session, how to configure it well, and how to run automation without weakening it.
Why an Azure CLI Session Limit Matters
- A stolen token stops being useful. Every limit shortens the window in which a leaked or copied token works.
- Powerful actions get a fresh check. Re-authentication with MFA before control-plane changes means a copied session alone is not enough.
- Offboarding and role changes take effect. Short sessions and revocation make sure a removed permission is not still active in a cached login.
- Less standing privilege. Admin rights that are active only for a few hours leave less to steal.
- Audit clarity. Fresh sign-ins tie actions to a person and a moment. This supports the access-control and accountability expectations found in frameworks such as ISO 27001 and SOC 2, and in data protection regimes such as KVKK and GDPR. These frameworks expect controlled access and traceability, not a specific timeout value.
What Actually Limits a Session
An Azure CLI session is several independent mechanisms. This table summarises Microsoft's documented behaviour.
| Mechanism | What it does | Who controls it |
|---|---|---|
| Access token | Random lifetime of 60-90 minutes by default | Microsoft Entra ID |
| Continuous Access Evaluation (CAE) | Can extend tokens to 24-28 hours but revokes them near real time on events like account disablement or a password change | Entra ID, when client and resource support it |
| Refresh token | 90 days maximum inactivity; not configurable since 2021; revocable at any time | Entra ID |
| Conditional Access sign-in frequency | Forces re-authentication after hours, days or every time | Your tenant admin |
| Mandatory MFA | Requires MFA for create, update and delete through Azure CLI and other management clients (Phase 2 from 1 October 2025, gradual). Reads do not need it | Microsoft, per tenant |
| Cloud Shell idle timeout | Ends sessions after 20 minutes without interactive activity | Microsoft, fixed |
Refresh tokens roll forward each time they are used, so the 90-day limit only bites when a login sits idle. In practice, Conditional Access policy and revocation decide how long a login really works.
Conditional Access policies that target the Windows Azure Service Management API apply to Azure Resource Manager and the Azure portal. Microsoft lists Azure CLI and Azure PowerShell among the clients indirectly affected, so this is the policy target that governs az.
How to Set It Up Well
1. Require phishing-resistant MFA for administrators
Microsoft recommends a Conditional Access policy requiring the Phishing-resistant MFA authentication strength for administrator roles (Global Administrator, Privileged Role Administrator, Security Administrator and others). Register passkeys (FIDO2) or equivalent methods first, exclude emergency access accounts, and start in report-only mode. Mandatory MFA alone already applies to Azure management writes, but a stronger method is a separate, deliberate choice.
2. Set a sign-in frequency on Azure management
Create a Conditional Access policy for privileged users that targets Windows Azure Service Management API with the Sign-in frequency session control. The value is your decision. As an illustration, a few hours for privileged roles and a longer period for read-only roles is a common pattern. It is not a Microsoft-mandated number, so choose it from your risk and test with report-only mode and the What If tool. Microsoft advises "every time" only for specific needs, and says to disable "Remember MFA on trusted devices" before using sign-in frequency.
3. Use just-in-time roles with PIM
Microsoft Entra Privileged Identity Management (PIM) provides just-in-time, time-bound activation for Azure resource roles, with optional approval, MFA at activation, justification, notifications, access reviews and audit history. It requires the licensing described in Microsoft's documentation. Eligible assignments mean an admin holds no active Owner or Contributor role between tasks, so a stolen session has little to use.
4. Add device and token controls
- Device compliance: a Conditional Access grant control can require a compliant or managed device. This is standard Conditional Access functionality; confirm the exact requirements for your licences.
- Token protection: it binds sign-in tokens to the device to reduce replay. Microsoft documents it as generally available for native apps on Windows, macOS and iOS for Exchange Online, SharePoint Online and Teams, and as preview for selected web apps that access Azure Resource Manager. Azure CLI is not in the documented list, so do not assume it protects
aztokens.
5. Separate admin accounts and clean up shared hosts
Use a dedicated admin account for privileged work, not your daily mailbox identity. On shared machines, jump hosts and training laptops, finish with:
az logout
az account clearTreat the .azure folder in the home directory as a credential. Do not copy it, back it up to shared storage or bake it into images.
Automation Without Weakening the Control
The wrong response to "my script keeps being asked to sign in" is to lengthen sessions or exclude the user from the policy. That moves risk from the script to the whole tenant.
Microsoft's mandatory MFA exempts workload identities such as managed identities and service principals. That is the point: automation belongs on identities designed for it, and user accounts used as service accounts are expected to fail. Use:
| Identity | Best for | Login |
|---|---|---|
| Managed identity | Code on Azure (VM, container, App Service) | az login --identity |
| Federated credential (OIDC) | GitHub Actions, Azure Pipelines, Kubernetes, other clouds | no stored secret |
| Service principal with certificate | Everything else | az login --service-principal --username <app-id> --certificate <pem> --tenant <tenant-id> |
For a user-assigned managed identity add --client-id, --object-id or --resource-id. A service principal certificate PEM must contain the certificate appended to the private key. Prefer certificates over client secrets, and scope every role assignment to the smallest resource group or resource that works.
For GitHub Actions the OIDC login stores identifiers, not credentials:
permissions:
id-token: write
contents: read
steps:
- uses: azure/login@v3
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}For Azure Pipelines, Microsoft recommends service connections with workload identity federation. Our Jenkins CI/CD guide applies the same principle: credentials belong to the pipeline, not to a person. For the identity side of access control, see enterprise SSO with Entra ID.
When the CLI Asks You to Sign In Again
The prompt is the control working. Re-authenticate rather than bypass.
| Symptom or code | Meaning | What to do |
|---|---|---|
| AADSTS700082 | Refresh token expired after inactivity | az login |
| AADSTS70043 | Conditional Access sign-in frequency expired the session | az login; ask your admin about the policy if it surprises you |
| AADSTS50173 | Grant revoked, often after a password change | az logout, then az login |
| AADSTS50076 / "interactive authentication is needed" | MFA required | Sign in interactively; never script it with a user password |
| Write fails, reads work | MFA claims challenge | Use CLI 2.76 or later and the az login --tenant ... --scope ... --claims-challenge ... command from the error |
| Cloud Shell closed after 20 minutes | Idle timeout | Run long jobs on a pipeline or VM |
FAQ
Can I just make the session longer? Not for user sign-ins. Microsoft no longer lets you configure refresh token lifetimes, and the sign-in frequency policy exists to limit exposure. Disabling it for convenience removes the protection for the whole tenant. If a task needs to run unattended, use a workload identity.
Are service principals affected by sign-in frequency? Policies scoped to users do not apply to service principal calls. Microsoft offers Conditional Access for workload identities, with a separate licence, to govern them.
Quick Start for Admins
- Update Azure CLI to 2.76 or later across the team.
- Create a phishing-resistant MFA policy for admin roles in report-only mode, with break-glass accounts excluded.
- Add a sign-in frequency policy on Windows Azure Service Management API for privileged users and review the sign-in logs before enforcing it.
- Move standing Owner and Contributor assignments to PIM-eligible roles.
- Inventory scripts that run
az loginas a user and migrate them to managed identities or OIDC. - Run
az logouton shared hosts and keep.azureout of backups and images.
Summary
An Azure CLI session limit is a security control that shortens the life of a stolen login, forces fresh MFA before powerful changes and keeps privilege temporary. Configure it with Conditional Access, phishing-resistant MFA and PIM, and move automation to workload identities so nobody is tempted to loosen the policy.
We help teams design and operate this kind of access model as part of run and improve, and you can read more about our approach to security or get in touch.


