Skip to content
Tutorials Center
My learning

Topics

Lesson 55 of 57 ยท Practice and Review

Common Azure Mistakes and How to Avoid Them

Avoid the Azure mistakes that cause breaches and surprise bills: public storage, over-privileged roles, secrets in code, no budgets, quotas and orphaned resources.

Most Azure incidents are not exotic. Behind the headlines about leaked data and five-figure bills there is usually the same short list of mistakes: a storage container left open, a role granted too widely, a secret committed to a repository, a budget nobody set, a resource nobody remembered to delete. They are easy to make because the portal lets you do them in a few clicks, and easy to prevent once you know where they hide.

This lesson walks through the mistakes in the order they tend to hurt, with the one habit or control that prevents each. The Azure commands and Bicep are read-only. Two runnable stand-ins at the end, an orphaned-resource finder and a secret scanner, show how you can catch problems automatically; they run on sample data in your browser and are not connected to any account.

flowchart LR
    M1["Public storage"] --> G1["Policy: deny public access"]
    M2["Broad roles"] --> G2["RBAC at narrow scope + PIM"]
    M3["Secrets in code"] --> G3["Managed identity + Key Vault"]
    M4["No budgets or tags"] --> G4["Budgets + required-tag policy"]
    M5["Orphaned resources"] --> G5["Scheduled cleanup reports"]

Each common mistake has a matching guardrail that should exist before the first workload does.

Mistake 1: public storage

A storage account lets you allow anonymous reads on a container. That is sometimes intended (public images for a website), but when it is left on by accident, anyone who guesses or discovers the container URL can list and download the files. Backups, exports and logs stored this way are the stuff of breach reports.

How to avoid it:

  • Turn off anonymous blob access at the account level unless you have a deliberate public container. In Bicep this is allowBlobPublicAccess: false, as the earlier Bicep exercises show.
  • Prefer Entra ID authentication and short-lived SAS tokens over account keys; read Storage Security and SAS Tokens for the details.
  • Use the storage firewall and private endpoints so the account is not reachable from the whole internet.
  • Add an Azure Policy that denies or audits accounts that allow public access, so the setting cannot drift.
Terminal
# Read-only: switch off anonymous access on an existing account
az storage account update \
  --name stdemo001 \
  --resource-group rg-demo \
  --allow-blob-public-access false

Mistake 2: over-privileged roles

The fastest way to make an error message go away is to grant Owner or Contributor at the subscription. It works, it is silent, and it gives that person or pipeline the power to delete everything, and (with Owner) to give that power to others. The same applies to service principals that CI/CD uses: a deployment identity with subscription-wide Owner is a stolen-credential disaster waiting to happen.

How to avoid it:

  • Grant the narrowest built-in role at the narrowest scope that works, usually a resource group, as practiced in Role-Based Access Control.
  • Give people eligible access through Privileged Identity Management (PIM) so they activate elevated roles for a few hours with an approval, not forever.
  • Review assignments regularly: list them, remove what nobody can explain, and remove access when people change teams.
  • Never share a single admin account. Individual identities with MFA leave an audit trail.
Terminal
# Read-only: who has what at subscription scope?
az role assignment list --scope /subscriptions/<id> --include-inherited \
  --query "[].{who:principalName, role:roleDefinitionName, scope:scope}" -o table

Mistake 3: secrets in code

Connection strings with account keys, SQL passwords in appsettings.json, API keys in a .env file committed "just for now": once a secret is in Git history, deleting the file does not remove it. Bots scan public repositories within minutes, and private repositories are copied, forked and leaked too.

How to avoid it:

  • Use managed identities. An app running on App Service, Functions or Container Apps can authenticate to Storage, SQL and Key Vault with no secret at all, as explained in Managed Identities and Service Principals.
  • Where a secret is unavoidable (a third-party API key), store it in Key Vault and reference it from app settings.
  • For pipelines, use OIDC federated credentials instead of stored client secrets (CI/CD Pipelines).
  • Enable secret scanning and push protection on your repositories, and rotate any secret that ever appeared in a commit.

Mistake 4: no tags and no budgets

Without tags you cannot tell who owns a resource or which project pays for it. Without budgets, the first sign of a runaway cost is the invoice. A forgotten GPU VM, an autoscaled service in a retry loop, a log workspace ingesting debug logs at high volume: each can add hundreds of dollars a day.

How to avoid it:

  • Define a tagging standard (for example owner, costCenter, env) and enforce it with a policy such as "require tag" or "inherit tag from resource group" (Azure Policy, Locks and Tags).
  • Create budgets with alerts at 50%, 80% and 100% of the monthly plan, and an anomaly alert. Remember that a budget notifies; it does not stop the spending by itself. Pair it with an action group that can run automation if you need an actual brake.
  • Review cost by tag every month (Pricing, Cost Management and Budgets).

Mistake 5: region and quota surprises

Azure is a shared pool of datacenters, and a few details bite people late in a project:

  • Quotas. Each subscription has regional limits on vCPUs per VM family and in total. A deployment in a new region can fail with a quota error on the day you launch. Check early with az vm list-usage --location westeurope -o table and request an increase well ahead of time.
  • Availability. Not every service, VM size or feature exists in every region, and some sizes are restricted for new customers. az vm list-skus shows what you can use.
  • Resource providers. In a fresh subscription, a service's provider may not be registered yet; az provider register --namespace Microsoft.ContainerService fixes that class of "not found" error.
  • Global names. Storage accounts, App Service apps and Key Vaults need globally unique names; make Bicep generate them with uniqueString.
  • Residency and latency. The region you pick decides where data lives. Decide on compliance and latency first, because moving data between regions later means downtime and egress charges. See Azure at a Glance.

Mistake 6: orphaned and idle resources

Deleting a VM does not always delete everything that came with it. Disks, public IP addresses and network interfaces can remain and keep billing. Other resources bill by the hour simply for existing:

  • Unattached managed disks and old snapshots.
  • Public IP addresses that nothing uses.
  • Network interfaces with no VM.
  • App Service plans with zero apps: the plan is the billed unit, not the apps in it.
  • VMs that were stopped from inside the operating system: they are still allocated and billed. Only a deallocated state stops compute charges.
  • Hourly-billed networking such as gateways, firewalls, Bastion hosts and load balancers in test environments nobody uses.

The prevention is a habit: put each project in its own resource group, tag it, and delete the whole group when the project ends. The detection is a report. These read-only queries use Azure Resource Graph (the resource-graph CLI extension):

KUSTO
resources
| where type == "microsoft.compute/disks" and isnull(managedBy)
| project name, resourceGroup, sizeGb = properties.diskSizeGB

A stand-in orphan finder

The real queries need a subscription. The stand-in below applies the same rules to a small, made-up inventory shaped like Azure's JSON. The monthly costs are invented round numbers, not Azure prices. Add more rules, or change an item, and run it again.

JS Find orphaned resources in a sample inventory

Press Run (or Ctrl + Enter) to see the console output here.

No output.

A real report must be reviewed by a person before anything is deleted: a "unused" disk may be a deliberate backup. Use resource locks on things that must survive, and tags such as keep-until to document intent.

A stand-in secret scanner

Catching secrets before they reach Git is cheaper than rotating them afterwards. Real tools (secret scanning and push protection, pre-commit hooks) use hundreds of patterns plus entropy checks. This tiny stand-in uses a few regular expressions on made-up files, with fake values, to show the idea.

JS Scan sample files for secrets

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice what a scanner cannot decide: whether Welcome123! is a real credential or a sample. Treat every hit as real until someone proves otherwise, rotate it, and move the value to Key Vault or, better, remove the need for it.

Other mistakes worth a line

  • Opening management ports to the world. RDP (3389) and SSH (22) open to Any get attacked within minutes. Use Bastion or just-in-time access (Network Security Groups and Firewalls).
  • A single VM with no redundancy. One instance has no SLA worth the name; use availability zones or scale sets (High Availability, Backup and Disaster Recovery).
  • Backups that were never restored. A backup you have not tested is a hope. Run a restore drill.
  • No diagnostic settings. If logs are not sent anywhere, the incident review has nothing to read (Azure Monitor).
  • Clicking in production. Manual portal changes drift from your templates; make changes through Bicep and pipelines.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. A budget alert at 100% of the monthly plan fires. What does Azure do to your resources?

    Budgets notify. To act on a breach you attach an action group with automation, or design the controls yourself.
  2. 2. A VM was shut down from inside Windows and shows as stopped. What about the bill?

    An OS-level shutdown leaves the hardware reserved. Use the Stop action in Azure to reach the deallocated state.
  3. 3. What is the best way to give an App Service app access to a storage account without storing a key?

    A managed identity authenticates through Entra ID, so there is no secret to leak or rotate.
  4. 4. Which grant follows least privilege for a pipeline that deploys to one resource group?

    Grant the narrowest role at the narrowest scope that does the job. Contributor on the group lets it deploy, without the rest of the subscription.
  5. 5. An App Service plan has no apps left. Does it still cost money?

    The plan is the billed unit. Delete empty paid plans, or scale them to a cheaper tier.

Summary

  • Turn off anonymous storage access, restrict network access, and enforce both with Azure Policy.
  • Assign roles at the narrowest scope, use PIM for elevation, and review assignments regularly.
  • Keep secrets out of code: use managed identities, Key Vault and OIDC, and scan repositories.
  • Tag everything and set budgets, remembering that budgets alert but do not stop spending.
  • Check quotas, SKU availability, provider registration and global name uniqueness before launch day.
  • Hunt orphaned disks, IPs, NICs, empty plans, old snapshots and stopped-not-deallocated VMs, and delete whole resource groups when a project ends.

Next: Azure Interview Questions.