How to MFA in the Azure CLI
02 Nov 2026
If you’ve got a sufficiently pricey license for Microsoft’s Visual Studio IDE, then whether or not you actually bother to install VS, one of the free perks is an Azure subscription with a few bucks a month of credits. You can’t accidentally run up a huge bill – it’s more like a prepaid gift card – it simply stops you from using it for the rest of the month when you’re out of credits.
If you’re like a lot of cloud-native infrastructure engineers and software developers, you probably play in that Azure subscription a lot.
And if you do so via some sort of secondary command-line interface (“CLI”) tool (e.g. Terraform) piggybacking on top of your logged-in state within the Azure (“az“) CLI tool, this week you might suddenly find yourself dealing with a RequestDisallowedByAzure 401 Unauthorized error, saying that your Azure resource create/edit/delete request “was disallowed by Azure: You are receiving this error because you tried to create, update, or delete Azure resources without authenticating through MFA.”
I think I’ve found a fix.
How to interactively authenticate into the Azure CLI after October 2026
The trick is not to let anything but the az CLI be the first “write” action against your Azure subscription that you attempt in a while.
The actual az CLI is the one that’ll give you the best error message – the one you actually need to get your day started and get MFA kicked off.
Here’s what worked for me:
- Use the Azure CLI (not the Terraform CLI or any other layered-on tool!) to try to create an Azure resource group with some name that I don’t actually care about creating for real:
az group create --location 'centralus' --resource-group 'helloworld'- I got this error message, which luckily informed my next steps (note that you might have a different value where I wrote
eyJhY2Nlc3NfdG9rZW4iOnsiYWNycyI6eyJlc3NlbnRpYWwiOnRydWUsInZhbHVlcyI6WyJwMSJdfX19– I’m not sure if it’s always that, or just in the Entra tenant I got to test in that had P1 features like MFA enabled):Run the command below to authenticate interactively; additional arguments maybe be added as needed.
az logout az login --tenant "TENANT_GUID_HERE" --scope "https://management.core.windows.net//.default" --claims-challenge "eyJhY2Nlc3NfdG9rZW4iOnsiYWNycyI6eyJlc3NlbnRpYWwiOnRydWUsInZhbHVlcyI6WyJwMSJdfX19"SubError: basic_action V2Error: invalid_grant AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access ‘797f4846-ba00-4fd7-ba43-dac1f8f63013’.
- I got this error message, which luckily informed my next steps (note that you might have a different value where I wrote
- Log out & back in, this time adding the
--scope&--claims-challengeflags from the error message:az logout az login --tenant 'TENANT_GUID_HERE' --subscription 'SUB_GUID_HERE' --scope 'https://management.core.windows.net//.default' --claims-challenge 'eyJhY2Nlc3NfdG9rZW4iOnsiYWNycyI6eyJlc3NlbnRpYWwiOnRydWUsInZhbHVlcyI6WyJwMSJdfX19' - Complete the single sign-on and MFA challenge that pops up (note that it might be hidden behind other open windows, or on a different monitor).
- Finally, Terraform ran just fine against my VS Azure subscription, using my human Entra user principal:
terraform apply
Note: eyJhY2Nlc3NfdG9rZW4iOnsiYWNycyI6eyJlc3NlbnRpYWwiOnRydWUsInZhbHVlcyI6WyJwMSJdfX19 is Base64 that decodes into the following JSON snippet:
{
"access_token": {
"acrs": {
"essential":true,
"values": ["p1"]
}
}
}
Be responsible
Of course, as EpiFive and Cohash point out, if you’re not actually doing interactive work where you can interactively step through the MFA process, then you have no business using a human Entra principal as your az login identity, and you’re being kicked out of bad design on purpose.
For those cirumstances, I don’t have a workaround for you.
You’ll need to fix your automations to stop lying about being a human.
Create proper Entra service principals for them to use, instead.
Possibly outdated
From what I can tell, newer releases of the Terraform CLI tool might be doing a better job passing through the underlying az CLI tool’s error messages when running commands such as terraform plan, terraform apply, terraform destroy, etc.
For example, I ran terraform apply on a Monday, which gave my last az CLI MFA time to lapse over the weekend. Running it against a resource "azurerm_resource_group" "my_example_rg {...} Terraform resource block specification surfaced the following error message:
azurerm_resource_group.my_example_rg: Creating…
Error: checking for presence of existing Resource Group
…
authorizing request: running Azure CLI: exit status 1: ERROR: SubError: basic_action V2Error: invalid_grant AADSTS50078: Presented multi-factor authentication has expired due to policies configured by your administrator, you must refresh your multi-factor authentication to access ‘797f4846-ba00-4fd7-ba43-dac1f8f63013’.
…
Run the command below to authenticate interactively; additional arguments maybe be added as needed.
az logout az login --tenant "TENANT_GUID_HERE" --scope "https://management.azure.com/.default"with azurerm_resource_group.my_example_rg, on main.tf line LINE_NUMBER_HERE, in resource “azurerm_resource_group” “my_example_rg”: LINE_NUMBER_HERE: resource “azurerm_resource_group” “my_example_rg”
I got a similar error message running terraform plan against a data azurerm_subscription" "my_example_subscription" {} Terraform data resource block specification.
Now, the reason that happened to me, when a few weeks ago neither creating a resource group nor reading information about a subscription were MFA-protected operations, is because I asked to be made a guinea pig for EpiFive’s and Cohash’s idea to simply make the az CLI even stricter and require MFA for all interactive operations.
What I can’t yet tell is if following EpiFive’s/Cohash’s idea actually helps with user experience, in the end.
For example, if the Terraform CLI simply got better about surfacing the Azure CLI’s error messages through the Terraform CLI, then it wouldn’t be necessary to force everyone in your enterprise to MFA when doing low-risk interactive az CLI operations like querying for information about an Azure subscription. This whole blog post would simply become irrelevant, except to a few people running outdated versions of the Terraform CLI tool.
Unfortunately, now that the Entra tenant I’m playing in recognizes me as someone who’s MFA’ed before, my account’s no longer “clean” enough in that tenant to test whether me getting specific error messages through the Terraform CLI instead of the vague “You are receiving this error because you tried to create, update, or delete Azure resources without authenticating through MFA” error message relates to Terraform CLI improvements or relates to my-Entra-user-specific changes in what the Azure CLI tool is surfacing to Terraform CLI tool.
(See GitHub kkgthb/az-cli-mfa-troubleshooting-tf-cli code comments as I noodle, trying to figure it out.)
Related articles
- Mandatory multifactor authentication for Azure and admin portals - Phase 2 applications on Microsoft Learn
- Azure mandatory MFA phase 2: fix CLI, PowerShell and Terraform sign-ins by EpiFive
- Azure mandatory MFA now blocks CLI, PowerShell and Terraform changes: moving service accounts to workload identities by Cohash Security Practice
- Azure mandatory MFA Phase 2: which identities break at the Resource Manager layer by Samantha Kloos-Kilkens