Building an Internet Kill Switch for Your Azure Platform

13 min read

At some point in the life of every large Azure estate, someone on a bridge call will ask a question the platform team should have answered months earlier: can we cut off the internet, right now, and how long will it take?

The trigger is usually one of three things. A confirmed compromise with data leaving the environment. A wormable exploit against an internet-facing component with no patch yet. Or a stolen credential or poisoned pipeline being actively abused. In each case the useful move is the same: buy time. Cut the attacker’s paths in and out while the humans work out what happened, rotate secrets, and rebuild what needs rebuilding.

If the first time anyone works out how to do that is during the incident, the answer is usually “an hour, maybe more, and we’re not sure what we’ll break.” This post is about turning that into a rehearsed procedure: a small set of pre-built, platform-owned, reversible controls that can be thrown in minutes by an authorized person, with a path that still works when your normal tooling doesn’t.

One scope note before we start. A kill switch is containment, not remediation. It doesn’t revoke credentials, it doesn’t remove an attacker who’s already inside, and it doesn’t touch traffic that travels over private paths such as peering, VPN or ExpressRoute. It’s a way to stop the bleeding, and it only helps if the rest of your incident response is ready to use the time it buys.

Design principles

Tiers, not a single big red button. “Turn off the internet” sounds like one action, but it’s at least four: isolating a single workload, cutting egress, cutting ingress, and closing the public endpoints of PaaS services. The right response to a compromised VM is not the right response to a zero-day in your edge, so build the levers separately and let the responder choose the scope.

Owned by the platform, not overridable by workload teams. This is the principle that decides which Azure features you can use. A kill switch built on NSGs fails it twice. Workload teams can edit their own NSGs, and NSG rule changes only apply to new connections: Microsoft’s documentation is explicit that modifying NSG rules affects new connections and existing ones aren’t re-evaluated. Better building blocks exist. Azure Virtual Network Manager security admin rules are evaluated before NSGs, and a Deny stops evaluation, so no NSG downstream can re-open the path. In Azure Firewall Policy, rule collection groups in a parent policy always take precedence over a child policy regardless of priority, and when a rule changes to deny previously allowed traffic, the firewall drops the relevant existing sessions.

Reversible, in code, and logged. Activation and restoration are two parameters of the same deployment, kept in the platform repo, reviewed like any other change, with an audit trail of who threw it and why.

Pre-staged, not pre-applied. Everything exists and has been tested before the incident. During the incident you change one value and deploy.

Responders keep a way in. Cutting the internet shouldn’t cut your own investigators off from the environment or blind your SIEM. Decide in advance which paths survive.

A trigger that doesn’t depend on what’s compromised. If your only way to throw the switch is a pipeline authenticating through an identity provider that may itself be part of the incident, you don’t have a kill switch. You need a second, out-of-band route.

The levers

LeverWhat it stopsWho can undo itMain caveats
Azure Firewall parent policy rule groupEgress through the hub firewallPlatform team only (parent policy)Policy updates take minutes; a second update can be rejected while one is in flight
AVNM security admin rulesEgress and ingress at the VNet, ahead of NSGsPlatform team onlySkips VNets containing SQL Managed Instance and Databricks by default; applies only to VNets in your network groups
Route blackhole (0.0.0.0/0 next hop None)Egress by dropping default-route trafficWhoever owns the route tablesOnly works if the platform owns the route tables; more specific routes still win
Edge WAF custom ruleInbound via Front Door and Application GatewayPlatform teamFront Door WAF changes can take up to around 20 minutes to propagate globally
PaaS public network access offPublic endpoints of storage, Key Vault, SQL and similarAnyone with write access to the resourceVNet-level levers don’t touch these at all

The rest of this post builds each of them.

Lever 1: egress at the hub firewall

In a hub-and-spoke landing zone, internet egress usually flows through Azure Firewall, so the firewall is the most natural single choke point. The platform-owned base policy carries a reserved rule collection group at the lowest allowed priority number, which makes it evaluated first and, because it lives in the parent policy, impossible for child policies to override.

One wrinkle: Azure Firewall network rules have no “Internet” destination tag. To deny everything that isn’t private, you express the destination as the complement of the private ranges. A small script generates it, and you commit its output with the IaC:

import ipaddress, json

private = [ipaddress.ip_network(p) for p in
           ("10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16")]

remaining = [ipaddress.ip_network("0.0.0.0/0")]
for p in private:
    nxt = []
    for net in remaining:
        if p.subnet_of(net):
            nxt.extend(net.address_exclude(p))
        elif not net.subnet_of(p):
            nxt.append(net)          # disjoint from p: keep as is
        # else: net lies entirely inside p, so drop it
    remaining = nxt

print(json.dumps([str(n) for n in remaining]))

Add any other ranges you use privately (CGNAT space, privately used public ranges) to the private list. Then the rule group, with a single active switch:

param firewallPolicyName string
param active bool = false
param nonPrivateRanges array              // output of the script above
param incidentResponseDestinations array  // SIEM / EDR addresses that must stay reachable

resource policy 'Microsoft.Network/firewallPolicies@2024-05-01' existing = {
  name: firewallPolicyName
}

resource killSwitch 'Microsoft.Network/firewallPolicies/ruleCollectionGroups@2024-05-01' = {
  parent: policy
  name: 'rcg-kill-switch'
  properties: {
    priority: 100
    ruleCollections: [
      {
        ruleCollectionType: 'FirewallPolicyFilterRuleCollection'
        name: 'allow-incident-response'
        priority: 100
        action: { type: 'Allow' }
        rules: [
          {
            ruleType: 'NetworkRule'
            name: 'ir-tooling'
            ipProtocols: [ 'Any' ]
            sourceAddresses: [ '*' ]
            destinationAddresses: incidentResponseDestinations
            destinationPorts: [ '*' ]
          }
        ]
      }
      {
        ruleCollectionType: 'FirewallPolicyFilterRuleCollection'
        name: 'deny-internet-egress'
        priority: 200
        action: { type: 'Deny' }
        rules: [
          {
            ruleType: 'NetworkRule'
            name: 'deny-all-non-private'
            ipProtocols: [ 'Any' ]
            sourceAddresses: [ '*' ]
            // Dormant state: deny only a documentation range that is never routed.
            destinationAddresses: active ? nonPrivateRanges : [ '192.0.2.0/24' ]
            destinationPorts: [ '*' ]
          }
        ]
      }
    ]
  }
}

A few design notes on this:

  • The dormant state is a real deployment, not an absence. Using the same rule group in both states means arming the switch is a small, well-understood change to something already in production, not the creation of a new object under pressure.
  • Network rules beat application rules. The firewall always processes network rules ahead of application rules regardless of collection or group priority, so this deny overrides FQDN-based allows further down. That’s what you want here, and it also means your incident-response allow-list has to be network rules, using IPs or service tags, not FQDNs.
  • It only touches traffic that reaches the firewall. Private east-west flows through the hub are deliberately not denied, so internal operations keep working. Traffic that doesn’t route through the firewall isn’t covered, which is why this is one lever of several.
  • Expect minutes, not seconds. Firewall policy updates are not instant, and Microsoft Q&A threads describe a second rule collection group update being rejected while the policy is still in an updating state. Measure it in your own environment. If the first attempt is slow, don’t pile retries on top; wait for the provisioning state to settle.

Lever 2: platform-wide guardrail with AVNM security admin rules

If you use Azure Virtual Network Manager, security admin rules are the strongest network lever available to a platform team, because they apply at the VNet level, run before NSGs, and a Deny terminates evaluation. An application team’s NSG, however permissive, never gets a say.

The pattern that works well is to keep the kill switch permanently deployed in your security admin configuration as a rule that’s dormant by default. A rule whose action is Allow simply hands traffic on to the NSGs, so it has no effect until you flip it to Deny:

param networkManagerName string
param networkGroupId string
param active bool = false
param incidentResponseCidr string      // security tooling that must stay reachable

resource avnm 'Microsoft.Network/networkManagers@2024-05-01' existing = {
  name: networkManagerName
}

resource config 'Microsoft.Network/networkManagers/securityAdminConfigurations@2024-05-01' existing = {
  parent: avnm
  name: 'platform-baseline'
}

resource coll 'Microsoft.Network/networkManagers/securityAdminConfigurations/ruleCollections@2024-05-01' = {
  parent: config
  name: 'kill-switch'
  properties: {
    appliesToGroups: [
      { networkGroupId: networkGroupId }
    ]
  }
}

// Priority 10: responders always get through, whatever the NSGs say.
resource alwaysAllowIr 'Microsoft.Network/networkManagers/securityAdminConfigurations/ruleCollections/rules@2024-05-01' = {
  parent: coll
  name: 'always-allow-incident-response'
  kind: 'Custom'
  properties: {
    access: 'AlwaysAllow'
    direction: 'Outbound'
    priority: 10
    protocol: 'Any'
    sources: [ { addressPrefixType: 'IPPrefix', addressPrefix: '*' } ]
    destinations: [ { addressPrefixType: 'IPPrefix', addressPrefix: incidentResponseCidr } ]
    sourcePortRanges: [ '0-65535' ]
    destinationPortRanges: [ '0-65535' ]
  }
}

resource denyEgress 'Microsoft.Network/networkManagers/securityAdminConfigurations/ruleCollections/rules@2024-05-01' = {
  parent: coll
  name: 'deny-internet-egress'
  kind: 'Custom'
  properties: {
    access: active ? 'Deny' : 'Allow'
    direction: 'Outbound'
    priority: 100
    protocol: 'Any'
    sources: [ { addressPrefixType: 'IPPrefix', addressPrefix: '*' } ]
    destinations: [ { addressPrefixType: 'ServiceTag', addressPrefix: 'Internet' } ]
    sourcePortRanges: [ '0-65535' ]
    destinationPortRanges: [ '0-65535' ]
  }
}

resource denyIngress 'Microsoft.Network/networkManagers/securityAdminConfigurations/ruleCollections/rules@2024-05-01' = {
  parent: coll
  name: 'deny-internet-ingress'
  kind: 'Custom'
  properties: {
    access: active ? 'Deny' : 'Allow'
    direction: 'Inbound'
    priority: 110
    protocol: 'Any'
    sources: [ { addressPrefixType: 'ServiceTag', addressPrefix: 'Internet' } ]
    destinations: [ { addressPrefixType: 'IPPrefix', addressPrefix: '*' } ]
    sourcePortRanges: [ '0-65535' ]
    destinationPortRanges: [ '0-65535' ]
  }
}

Updating the rule isn’t enough on its own. A security admin configuration takes effect when you deploy (commit) it to a region:

az network manager post-commit \
  --network-manager-name avnm-platform \
  --resource-group rg-network-governance \
  --commit-type SecurityAdmin \
  --configuration-ids "<platform-baseline configuration resource ID>" \
  --target-locations westeurope northeurope

Things to verify before you trust this lever:

  • Skipped VNets. By default, security admin rules aren’t applied to virtual networks containing Azure SQL Managed Instance or Azure Databricks. Check the current list in the documentation, and treat those VNets as covered by other levers.
  • Scope. The rules only reach VNets that are members of the network groups you target. A VNet outside your AVNM scope is outside the kill switch, which is worth a Resource Graph query to confirm.
  • One configuration per region. Deploying a different security admin configuration to a region may replace the one already there, which is why the sketch above adds the kill switch as a rule collection inside the existing baseline configuration instead of a competing one. Confirm how your tenant behaves before relying on it.
  • Established flows. NSG changes only affect new connections. Whether security admin rule changes terminate flows that are already established isn’t something I’d assume from a blog post. Test it, including during the game day below.
  • Newly created resources get the rules with a delay, according to the documentation. Anything created mid-incident may be briefly uncovered.

The Internet service tag covers public address space outside the VNet, including Azure-owned public IPs, so denying it also cuts access to PaaS services over their public endpoints. That’s usually acceptable in an emergency, and it’s one reason private endpoints matter.

Lever 3: blackhole the default route

As a belt-and-braces fallback, and the right tool if the firewall itself is the thing you don’t trust, change the default route on the spoke route tables so that traffic has nowhere to go. Azure’s None next hop type drops traffic rather than forwarding it, and a user-defined route for 0.0.0.0/0 overrides the system default:

# Activate: drop everything that would have gone to the firewall or the internet
az network route-table route update \
  --resource-group rg-spoke-prod \
  --route-table-name rt-spoke-prod \
  --name default-to-firewall \
  --next-hop-type None

# Restore
az network route-table route update \
  --resource-group rg-spoke-prod \
  --route-table-name rt-spoke-prod \
  --name default-to-firewall \
  --next-hop-type VirtualAppliance \
  --next-hop-ip-address 10.0.0.4

This lever is blunt, but it’s fast to reason about and it doesn’t depend on a firewall policy update completing. It has real limits. It only works where the platform owns the route tables, which in a CAF-style landing zone it should, enforced by policy so workload teams can’t edit them. More specific routes still take precedence over 0.0.0.0/0, so traffic with specific routes, such as service-endpoint traffic, isn’t dropped by this. And because it affects the whole subnet’s default path, it will break return paths for inbound flows too, so treat it as a hammer, not a scalpel.

Lever 4: the edge

Inbound web traffic arrives through Front Door or Application Gateway, not through your VNets, so VNet-level controls don’t stop it. The edge lever is a WAF custom rule that blocks everything, kept in the policy at the top priority and flipped between Log and Block the same way as the others. Remember that Front Door WAF changes propagate globally: Microsoft’s guidance is that most deployments finish in under 20 minutes, and the policy takes effect when the update completes across all edge locations. If your threat is an exploit against an internet-facing app, this is also the lever to rehearse most carefully, because it’s the slowest.

Beyond the WAF, the edge also includes DNAT rules on the firewall, public IPs attached directly to VMs, and anything else with a public front door. Know what exists before you need to switch it off. This query lists every public IP in use and what it’s attached to:

resources
| where type =~ 'microsoft.network/publicipaddresses'
| where isnotempty(properties.ipConfiguration) or isnotempty(properties.natGateway)
| project name, resourceGroup, subscriptionId,
          ip = tostring(properties.ipAddress),
          attachedTo = tostring(properties.ipConfiguration.id)

Lever 5: PaaS public endpoints

Storage accounts, Key Vaults, SQL servers and many other services have public endpoints that sit entirely outside your VNets. Everything above does nothing to stop a stolen credential being used against a storage account from anywhere. If the incident involves data access, this is the lever that matters.

The prevention side belongs to Azure Policy: deny new resources with public network access enabled, so the estate is mostly private before any emergency. The kill-switch side is a script that snapshots the current state first, so restoration re-enables only what was open before and not everything:

# 1. Snapshot what is currently public (this is also your restore list)
az graph query --management-groups mg-prod --first 1000 -o json -q "
  resources
  | where type in~ ('microsoft.storage/storageaccounts', 'microsoft.keyvault/vaults')
  | where tostring(properties.publicNetworkAccess) =~ 'Enabled'
  | project id, type" > paas-public-snapshot.json

# 2. Close them
jq -r '.data[] | select(.type=="microsoft.storage/storageaccounts") | .id' paas-public-snapshot.json |
  while read -r id; do
    az storage account update --ids "$id" --public-network-access Disabled
  done

jq -r '.data[] | select(.type=="microsoft.keyvault/vaults") | .id' paas-public-snapshot.json |
  while read -r id; do
    az keyvault update --ids "$id" --public-network-access Disabled
  done

Add the other services in your estate the same way. Because this touches resources owned by workload teams, anyone with write access to those resources can reverse it, so it’s the one lever here that isn’t tamper-proof against a determined insider or a compromised team credential. That’s another argument for fixing the baseline with policy first.

Keeping a way in for responders

The single most common design mistake is building a switch that blinds the people who need to use it. Decide, in advance and in writing, what must survive:

  • Private administrative access. ExpressRoute, VPN and Bastion over private paths aren’t affected by an Internet deny. Make sure your responders actually use those, not a public jump host.
  • Telemetry. If logs reach Log Analytics over a public endpoint, cutting egress ends your visibility at the worst possible moment. Private Link for monitoring keeps ingestion working with the internet off.
  • The incident-response allow-list. The parameters in the firewall and AVNM templates above exist for this: a short, reviewed list of EDR and SIEM destinations that stay reachable. Keep it short, since every entry is a potential exfiltration path.
  • DNS. Internal name resolution has to keep working or everything else becomes harder to diagnose.

The trigger: two entry points, one implementation

Put the actual logic in scripts in the platform repo, one for each lever, taking activate or restore. Then give them two ways in.

The pipeline. A manually dispatched workflow with an environment that requires approval from security on-call, an identity scoped to exactly the resources the switch touches, and an incident ID recorded on every run:

name: Internet kill switch

on:
  workflow_dispatch:
    inputs:
      action:
        description: 'activate or restore'
        type: choice
        options: [activate, restore]
        required: true
      scope:
        description: 'Which levers'
        type: choice
        options: [egress, ingress, paas, all]
        required: true
      incident_id:
        description: 'Incident reference'
        type: string
        required: true

permissions:
  id-token: write
  contents: read

jobs:
  throw:
    runs-on: ubuntu-latest
    environment: kill-switch     # required reviewers: security on-call
    steps:
      - uses: actions/checkout@v4

      - uses: azure/login@v2
        with:
          client-id: ${{ secrets.KILLSWITCH_CLIENT_ID }}
          tenant-id: ${{ secrets.AZURE_TENANT_ID }}
          subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

      - name: Run
        env:
          ACTION: ${{ inputs.action }}
          SCOPE: ${{ inputs.scope }}
          INCIDENT_ID: ${{ inputs.incident_id }}
        run: ./killswitch/run.sh "$ACTION" "$SCOPE" "$INCIDENT_ID"

Note that the inputs reach the script through environment variables rather than being interpolated into the shell command, which avoids script injection through the free-text incident field.

The break-glass path. The same run.sh, executable by a small number of designated people from Cloud Shell or a hardened workstation using emergency access accounts, with a copy of the repo’s killswitch/ directory stored somewhere that doesn’t depend on GitHub or your normal identity flow. Two entry points calling one implementation means the break-glass path is exercised every time the pipeline is, and doesn’t rot.

Then make the use of it loud. Alert on writes to the kill-switch objects (the rule group, the AVNM commit, the route changes) so that activation is visible to everyone who needs to know, including after the fact.

On automation: wiring a SIEM detection straight to Tier 2 or 3 is tempting and dangerous, because a false positive becomes a self-inflicted outage. A reasonable compromise is to automate only workload isolation (the narrowest tier, for example quarantining a single VM’s network access) and keep the wider levers human-approved.

Drill it

An untested kill switch is a hypothesis. Run it, ideally quarterly, against a production-like environment, and measure:

  • Time to effect for each lever, from decision to traffic actually stopped. Every number in this post is a number to replace with your own.
  • Existing connections. Do established sessions die, or only new ones? This differs by lever, and the answer changes how you use them.
  • What breaks. Patching, agent and signature updates, container image pulls from public registries, certificate revocation checks, time sync, anything calling an external API. Your list will differ from anyone else’s, and building it is the point of the exercise. Pre-approve the exceptions you can live with, and document the rest as accepted collateral damage.
  • Restore. Time how long it takes to put everything back, in what order, and what needs checking afterward. Restore ingress last, once you’re confident of what you’re letting back in.
  • The break-glass path, by actually using it with the pipeline unavailable.

Who gets to decide

Technical readiness is half of it. Agree in advance who can authorize each tier, what evidence justifies it (confirmed active exfiltration, a critical unpatched exploit against an exposed component, compromise of a pipeline or identity under active abuse), and who gets told. The business cost of a platform-wide internet cut is real, and the people authorizing it need the decision framed before the incident, not drafted during it. Record the decision, the incident ID and the times in the pipeline run, so the post-incident review has facts.

The platform engineering takeaway

An internet kill switch isn’t a feature of any single Azure service. It’s a design stance: that the platform team owns a small set of un-overridable, reversible, rehearsed containment controls, and treats the ability to use them as part of the landing zone, not an afterthought of incident response. Use the strongest available lever at each layer (parent firewall policy, AVNM security admin rules, platform-owned routes, edge WAF, and a PaaS baseline enforced by policy), keep a way in for responders, and test it until the time-to-effect numbers are yours and not someone else’s. Then hope you never have to use it, and know how long it will take if you do.


Discover more from ksharp

Subscribe to get the latest posts sent to your email.

Leave a Reply

Your email address will not be published. Required fields are marked *

Discover more from ksharp

Subscribe now to keep reading and get access to the full archive.

Continue reading