,

Guardrails Before Workloads: Securing a Personal Azure Subscription

A study subscription is still a real subscription with a real credit card behind it. The guardrails I'd put in place before deploying a single VM: identity, budgets, policy, Defender and cleanup.

Guardrails Before Workloads: an empty harbour lined with glowing rune-post guardrails under an aurora

Every Azure certification path eventually says the same thing: get hands-on. Sign up, get a subscription, build things. That’s the right advice. It’s also how a lot of people end up with a surprise bill, a VM with RDP open to the whole internet, or a storage account full of lab data set to public because a tutorial said so.

A study subscription is still a real subscription. It has a credit card behind it, a public attack surfaceattack surface Everything an attacker could try to reach: open ports, exposed services, logins, APIs, people. Shrinking it is often the cheapest defence., and an identity that attackers would happily borrow to mine cryptocurrency on your dime. The good news is that the same guardrails an enterprise landing zonelanding zone The pre-built foundation of a cloud environment: identity, networking, policy, logging and cost controls, set up before any workload moves in. uses scale all the way down to one person, and most of them are free. This is the list I’d put in place before deploying the first workload, roughly in order.

What you’re actually protecting

  • Your money. The most likely bad outcome isn’t a breach, it’s a GPU VM or an expensive SKU left running over a long weekend.
  • Your identity. The account that owns the subscription can create anything. If it’s compromised, the attacker’s first move is usually compute for crypto mining, billed to you.
  • Whatever you put in it. Lab data is often copied from somewhere real. Treat it accordingly.
  • Your habits. The way you build in a lab is the way you’ll build at work. A lab with guardrails teaches the right reflexes.

1. Lock down the identity first

When you sign up for Azure with a personal Microsoft account, you get a subscription and a Microsoft Entra tenant (usually called “Default Directory”) that your account administers. Start there:

  • Strong sign-in on the owning account. Add a passkey or the Authenticator app to the Microsoft account itself, and remove SMS as a recovery option if you can. Microsoft now enforces MFAMFA Multi-factor authentication. Proving who you are with something beyond a password, like an authenticator app, passkey or hardware key. for Azure portal and CLI sign-ins anyway; get ahead of it with the strongest method you have.
  • Turn on security defaults in the tenant (Entra admin centre → Properties → Manage security defaults). It’s free, requires MFA for every user in the tenant, and blocks legacy authentication. Conditional Access is more flexible, but it needs Entra IDEntra ID Microsoft's cloud identity service (formerly Azure Active Directory), behind sign-in for Microsoft 365, Azure and many other apps. P1, and security defaults are exactly right for a one-person tenant.
  • Keep Owner to one identity. Check who has access at subscription scope, and keep it that way.
  • Give automation its own identity, with less. Pipelines and scripts get a managed identity or a workload identity federation login with Contributor on one resource group, not Owner on the subscription. No client secrets in config files.
# Who can do what at subscription scope?
az role assignment list --scope "/subscriptions/$(az account show --query id -o tsv)" \
  --include-inherited \
  --query "[].{who:principalName, type:principalType, role:roleDefinitionName}" -o table

# GitHub Actions without secrets: federated credential on an app registration
az ad app federated-credential create --id <app-id> --parameters '{
  "name": "gh-main",
  "issuer": "https://token.actions.githubusercontent.com",
  "subject": "repo:<you>/<repo>:ref:refs/heads/main",
  "audiences": ["api://AzureADTokenExchange"]
}'

2. Budgets and alerts before anything else costs money

The single most important thing to understand about Azure budgets: a budget doesn’t stop spending. It sends alerts. The free trial has a spending limit that switches things off when the credit runs out; a pay-as-you-go subscription doesn’t. So a budget is a smoke detector, not a sprinkler, and you want several detectors.

Set a monthly budget at the subscription with alerts on actual spend at 50%, 80% and 100%, plus a forecast alert at 100%. The forecast alert is the one that saves you: it fires when Azure predicts you’ll go over, often days before you actually do.

targetScope = 'subscription'

param amount int = 30            // in your billing currency
param email string
param startDate string = '2026-11-01'

resource budget 'Microsoft.Consumption/budgets@2023-11-01' = {
  name: 'lab-monthly'
  properties: {
    category: 'Cost'
    amount: amount
    timeGrain: 'Monthly'
    timePeriod: { startDate: startDate }
    notifications: {
      actual50:   { enabled: true, operator: 'GreaterThan', threshold: 50,  thresholdType: 'Actual',     contactEmails: [ email ] }
      actual80:   { enabled: true, operator: 'GreaterThan', threshold: 80,  thresholdType: 'Actual',     contactEmails: [ email ] }
      actual100:  { enabled: true, operator: 'GreaterThan', threshold: 100, thresholdType: 'Actual',     contactEmails: [ email ] }
      forecast100:{ enabled: true, operator: 'GreaterThan', threshold: 100, thresholdType: 'Forecasted', contactEmails: [ email ] }
    }
  }
}

Then add the extra detectors:

  • Cost anomaly alerts in Cost Management. They flag unusual daily spend, which catches “something new started running” faster than a monthly threshold does.
  • Auto-shutdown on every VM. It’s a checkbox on the VM (or a Microsoft.DevTestLab/schedules resource in code). Set it for an hour you’re definitely asleep.
  • A small per-resource-group budget for anything you know is expensive, like a lab that needs a firewall or a gateway, so it gets its own alert.
  • Check costs weekly, five minutes, Cost analysis grouped by resource group. Make it a habit, the way you’d check a bank balance.

If you want a hard stop, you have to build it: an action group on the budget that triggers an Automation runbook or Logic App to deallocate VMs. For most labs, alerts plus auto-shutdown are enough, and less likely to delete something you wanted.

3. A handful of policies, the same ones an enterprise would use

Azure PolicyAzure Policy Rules that Azure enforces or audits across subscriptions, like allowed regions, required tags or blocking public IP addresses. is free, and a few built-in definitions cover most lab risks. Assign them at the subscription:

Built-in policySettingWhy
Allowed locationsYour one or two nearest regions (for me, canadacentral and canadaeast)Stops resources appearing in a region you’ll never look at. Attackers who borrow subscriptions love far-away regions.
Allowed virtual machine size SKUsA short list of small B-series and D-series sizesThe best protection against a surprise bill there is. GPU sizes stay off the list.
Require a tag on resource groupsTag expiresEvery lab gets a date when it should be gone. Cleanup becomes a query.
Storage accounts should prevent public blob accessDenyTutorials set containers to public. Your lab doesn’t need to.
Management ports should be closed on your virtual machinesAuditFlags RDP and SSH open to the internet.
SUB="/subscriptions/$(az account show --query id -o tsv)"

# Allowed locations
az policy assignment create --name allowed-locations --scope "$SUB" \
  --policy e56962a6-4747-49cd-b67b-bf8b01975c4c \
  --params '{ "listOfAllowedLocations": { "value": ["canadacentral","canadaeast"] } }'

# Allowed VM sizes
az policy assignment create --name allowed-vm-skus --scope "$SUB" \
  --policy cccc23c7-8427-4f53-ad12-b6a63eb452b3 \
  --params '{ "listOfAllowedSKUs": { "value": ["Standard_B1s","Standard_B2s","Standard_B2ms","Standard_D2s_v5"] } }'

# Every resource group needs an expires tag
az policy assignment create --name rg-needs-expires --scope "$SUB" \
  --policy 96670d01-0a4d-4649-9c89-2d3abc0a5025 \
  --params '{ "tagName": { "value": "expires" } }'

A tip from the enterprise playbook that applies here too: you can’t create a resource group without the tag once that policy is on, which is mildly annoying for about a day and then becomes muscle memory. That’s the point.

4. Turn on Defender for Cloud’s free tier

Every subscription gets Defender for Cloud’s Foundational CSPMCSPM Cloud security posture management: tools that continuously compare cloud settings against good practice and flag the risky ones, such as Defender for Cloud. at no cost. It assigns the Microsoft Cloud Security Benchmark, scores your configuration and lists recommendations. For a lab, it’s a free security review that runs continuously.

  • Open it after every lab. New recommendations are a good way to learn what you just did wrong: public IPs, missing encryption settings, open ports, missing diagnostics.
  • Set the security contact (Environment settings → Email notifications) so high-severity alerts reach you.
  • Don’t switch on paid plans by accident. Defender for Servers, Storage, SQL and the rest are billed per resource. Turn them on deliberately when you’re studying them, and off when you’re done.

5. No management ports on the internet

A VM with port 22 or 3389 open to 0.0.0.0/0 starts receiving login attempts within minutes of getting a public IP. In a lab, the simplest fixes are also the right ones:

  • Don’t give lab VMs a public IP unless the lab is about public IPs.
  • Use Azure Bastion to connect through the portal. Its Developer tier is free in the regions that support it; check whether yours does. The Basic and Standard tiers are billed hourly, so delete them with the lab.
  • Or use the tools that don’t need a port at all: Run Command and the serial console reach the VM through the Azure control plane.
  • If you must open a port, restrict the NSG rule’s source to your own public IP, and remove the rule when you’re done.
# Find any NSG rule allowing SSH or RDP from anywhere
az network nsg list --query "[].{nsg:name, rg:resourceGroup, rules:securityRules[?access=='Allow' && direction=='Inbound' && (sourceAddressPrefix=='*' || sourceAddressPrefix=='Internet' || sourceAddressPrefix=='0.0.0.0/0') && (destinationPortRange=='22' || destinationPortRange=='3389')].name}" \
  -o json

6. Keep enough logging to answer “what happened?”

The Activity Log records every control-plane operation (who created, changed or deleted what) and Azure keeps it for 90 days at no charge. For a lab, that’s usually enough. If you want longer retention or to practise KQL, send it to a Log Analytics workspace with a diagnostic setting at subscription scope, and set a daily cap on the workspace so a noisy experiment can’t run up an ingestion bill.

// Who created or deleted things in the last week?
AzureActivity
| where TimeGenerated > ago(7d)
| where OperationNameValue endswith "/write" or OperationNameValue endswith "/delete"
| where ActivityStatusValue == "Success"
| summarize ops = count() by Caller, ResourceGroup, OperationNameValue
| order by ops desc

An unfamiliar Caller, or VM creations in a resource group you don’t recognize, is the moment to change your password and look harder.

7. Make cleanup a routine, not a resolution

The expires tag from step 3 pays off here. One Resource Graph query lists every lab past its date:

az graph query -q "
resourcecontainers
| where type == 'microsoft.resources/subscriptions/resourcegroups'
| extend expires = todatetime(tags['expires'])
| where isnotnull(expires) and expires < now()
| project name, expires
" -o table
  • One lab, one resource group. Deleting the group deletes the lab. No orphaned disks, IPs or NICs.
  • Build labs from code (Bicep or Terraform) so tearing down and rebuilding costs nothing but a few minutes. It’s also better exam practice than clicking.
  • Watch for the things that outlive their resource group’s purpose: soft-deleted Key Vaults (purge them, or the name stays taken), Recovery Services vault backups, and role assignments for identities that no longer exist.
  • Resource locks for the few things you keep. A CanNotDelete lock on a shared Log Analytics workspace stops a cleanup script from taking it out with everything else.

How this maps to the real thing

None of these are “lab tricks”. Each one is a small version of an enterprise landing zone control:

In the labIn the enterprise
Security defaults, one OwnerConditional Access, PIM, break-glass accounts
Budget and forecast alertsBudgets per subscription from vending, FinOps reporting
Allowed locations and SKUsPolicy initiatives at management group scope
expires tagRequired tags: owner, cost centre, environment, data classification
Foundational CSPMDefender CSPM, secure score targets, attack path analysis
Bastion, no public IPsCorp landing zones that deny public IPs, hub firewall
Activity Log to a capped workspaceCentral Log Analytics and a SIEM
One lab per resource group, built from codeSubscription vending and infrastructure as code

That’s the real benefit of doing this for a lab. By the time you’re studying for the AZ-104AZ-104 Microsoft Azure Administrator. The hands-on certification for running Azure: identity, networking, storage, compute and monitoring. or designing a landing zone at work, the guardrails aren’t new concepts from a slide. They’re things you’ve already lived with, been mildly annoyed by, and come to rely on.

The checklist

  1. Passkey or Authenticator on the owning Microsoft account; security defaults on in the tenant.
  2. One Owner. Automation gets least privilegeleast privilege Give every person, service and tool only the access it needs for its job, and nothing more. When something is compromised, the damage stays small. and no secrets.
  3. Monthly budget: 50/80/100% actual and 100% forecast alerts. Cost anomaly alerts on.
  4. Auto-shutdown on every VM.
  5. Policies: allowed locations, allowed VM sizes, required expires tag, no public blob access.
  6. Foundational CSPM reviewed after every lab; paid Defender plans only on purpose.
  7. No management ports on the internet: Bastion, Run Command or IP-restricted rules.
  8. Activity Log reviewed; any workspace has a daily cap.
  9. One lab per resource group, built from code, deleted on its expires date.

About an hour to set up, and then the subscription can be as messy as learning needs it to be, inside walls that keep the mess cheap.

ᛟ ᛟ ᛟ