Editare

Quickstart: Deploy Azure Firewall for Containers with Azure Resource Manager

In this quickstart, you use an Azure Resource Manager (ARM) template to create a new Azure Kubernetes Service (AKS) cluster and Azure Firewall Premium for Azure Firewall for Containers. The template also configures managed identities, a firewall policy, and the network routing.

By default, the template deploys only Azure resources. You then install the Azure Firewall Controller and attach a sample security policy by following the template's README. An optional parameter also installs the controller, a sample policy, and test pods.

An Azure Resource Manager template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. The template uses declarative syntax. You describe your intended deployment without writing the sequence of programming commands to create the deployment.

Important

Azure Firewall for Containers is currently in public preview. See the Supplemental Terms of Use for Microsoft Azure Previews for legal terms that apply to Azure features that are in beta, preview, or otherwise not yet released into general availability.

If your environment meets the prerequisites, select Deploy to Azure. The template opens on the Custom deployment page in the Azure portal.

Button to deploy the ARM template to Azure.

Prerequisites

  • An Azure account with an active subscription. Create an account for free.
  • Access to Azure Firewall for Containers in a supported preview region.
  • The Microsoft.ContainerService and Microsoft.Network resource providers registered in the subscription.
  • Permission to create AKS, networking resources, managed identities, and role assignments in the resource group. Creating role assignments requires an appropriate role, such as Role Based Access Control Administrator, at the assignment scope.
  • Capacity and quota for the selected AKS node virtual machine size. The default deployment uses two nodes with size Standard_DS3_v2; this size must be available in your selected region.
  • The Azure CLI, kubectl, and Helm for the steps after deployment.

Use an isolated evaluation environment. The template creates a new cluster and routes the AKS subnet's outbound traffic through the firewall.

To leave the template's Location parameter at its default, select or create a resource group in one of these preview regions:

Region Azure region value
Central US EUAP centraluseuap
East US 2 EUAP eastus2euap
West Central US westcentralus
East Asia eastasia
UK South uksouth
Central US centralus

Review the template

The template is from Azure Quickstart Templates.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.48.1.52935",
      "templateHash": "16522364362503515072"
    }
  },
  "parameters": {
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources. Must be an Azure Firewall for Containers preview region (centraluseuap, eastus2euap, westcentralus, eastasia, uksouth, centralus)."
      }
    },
    "namePrefix": {
      "type": "string",
      "defaultValue": "afc",
      "maxLength": 12,
      "metadata": {
        "description": "Prefix used to name the resources."
      }
    },
    "nodeVmSize": {
      "type": "string",
      "defaultValue": "Standard_DS3_v2",
      "metadata": {
        "description": "VM size for the AKS nodes. Must be available in the selected region."
      }
    },
    "nodeCount": {
      "type": "int",
      "defaultValue": 2,
      "minValue": 1,
      "maxValue": 10,
      "metadata": {
        "description": "Number of AKS nodes."
      }
    },
    "controllerVersion": {
      "type": "string",
      "defaultValue": "20261109.1",
      "metadata": {
        "description": "Azure Firewall for Containers controller Helm chart version."
      }
    },
    "controllerNamespace": {
      "type": "string",
      "defaultValue": "firewall-namespace",
      "metadata": {
        "description": "Kubernetes namespace for the controller. Used in the workload identity federated credential subject."
      }
    },
    "deployControllerAndSample": {
      "type": "bool",
      "defaultValue": false,
      "metadata": {
        "description": "false (default): deploy Azure resources only; the outputs contain the remaining commands. true: also run a deployment script that installs the controller and applies a sample security policy, attachment, and test pods. The script needs a storage account with shared key access, so it fails where Azure Policy denies shared key access."
      }
    },
    "azCliVersion": {
      "type": "string",
      "defaultValue": "2.61.0",
      "metadata": {
        "description": "Azure CLI version used by the deployment script."
      }
    },
    "utcValue": {
      "type": "string",
      "defaultValue": "[utcNow()]",
      "metadata": {
        "description": "Unique suffix that forces the deployment script to rerun on each deployment. Leave the default."
      }
    }
  },
  "variables": {
    "$fxv#0": "#!/bin/bash\n# Runs inside Microsoft.Resources/deploymentScripts (Azure CLI container, signed in with the script identity).\n# Installs the Azure Firewall for Containers controller and applies a sample policy, attachment, and test pods.\nset -euo pipefail\n\necho \"Getting cluster credentials for ${CLUSTER_NAME}\"\naz aks get-credentials --resource-group \"$RESOURCE_GROUP\" --name \"$CLUSTER_NAME\" --admin --file ./kubeconfig --overwrite-existing --only-show-errors\nchmod 600 ./kubeconfig\nexport KUBECONFIG=\"$PWD/kubeconfig\"\n\ndownload() { # url dest; the Azure CLI container image may not include curl\n  if command -v curl >/dev/null 2>&1; then curl -fsSL \"$1\" -o \"$2\"\n  elif command -v wget >/dev/null 2>&1; then wget -qO \"$2\" \"$1\"\n  else python3 -c \"import sys, urllib.request; urllib.request.urlretrieve(sys.argv[1], sys.argv[2])\" \"$1\" \"$2\"\n  fi\n}\n\necho \"Installing kubectl and helm\"\naz aks install-cli --install-location /usr/local/bin/kubectl --kubelogin-install-location /usr/local/bin/kubelogin --only-show-errors >/dev/null\ndownload https://get.helm.sh/helm-v3.16.2-linux-amd64.tar.gz /tmp/helm.tar.gz\ntar -xzf /tmp/helm.tar.gz -C /tmp\ninstall /tmp/linux-amd64/helm /usr/local/bin/helm\n\necho \"Installing controller ${CONTROLLER_VERSION}\"\nhelm upgrade --install azfw-controller \\\n  oci://mcr.microsoft.com/firewall/charts/azurefirewall-controller \\\n  --namespace \"$CONTROLLER_NAMESPACE\" \\\n  --create-namespace \\\n  --version \"$CONTROLLER_VERSION\" \\\n  --set \"azfwController.podIdentity.clientID=${CONTROLLER_CLIENT_ID}\" \\\n  --wait --timeout 10m\nkubectl wait --for=condition=Available deploy --all --namespace \"$CONTROLLER_NAMESPACE\" --timeout=10m\nkubectl wait --for=condition=Established crd/securitypolicyattachments.firewall.networking.azure.io --timeout=5m\n\necho \"Applying sample security policy and attachment\"\nkubectl apply -f - <<EOF\napiVersion: firewall.networking.azure.io/v1alpha1\nkind: SecurityPolicy\nmetadata:\n  name: example-securitypolicy-rules\n  namespace: default\nspec:\n  applicationRuleCollections:\n    - name: test-application-rules\n      refs:\n        - podSelector:\n            matchLabels:\n              role: developer\n      action: Allow\n      egress:\n        - name: allow-test-destinations\n          toPortProtocol:\n            - protocolType: HTTPS\n              port: 443\n          to:\n            - fqdn:\n                - \"*.microsoft.com\"\n                - \"*.google.com\"\n---\napiVersion: firewall.networking.azure.io/v1alpha1\nkind: SecurityPolicyAttachment\nmetadata:\n  name: example-attachment\n  namespace: default\nspec:\n  securityPolicyRefs:\n    - name: example-securitypolicy-rules\n      namespace: default\n  firewallRef:\n    id: ${FIREWALL_ID}\n  aksWorkloadSubnets:\n    - ${AKS_SUBNET_ID}\nEOF\n\necho \"Waiting for the attachment to deploy\"\nkubectl wait --for=jsonpath='{.status.conditions[?(@.type==\"Deployment\")].reason}'=Ready \\\n  securitypolicyattachment/example-attachment --namespace default --timeout=40m\nkubectl get securitypolicyattachment example-attachment --namespace default \\\n  -o jsonpath='{range .status.conditions[*]}{.type}={.status} {.reason}{\"\\n\"}{end}'\n\necho \"Creating test pods\"\nkubectl apply -f - <<'EOF'\napiVersion: v1\nkind: Pod\nmetadata:\n  name: developer-pod\n  namespace: default\n  labels:\n    role: developer\nspec:\n  containers:\n    - name: developer\n      image: mcr.microsoft.com/azure-cli:latest\n      command: [\"sleep\", \"infinity\"]\n---\napiVersion: v1\nkind: Pod\nmetadata:\n  name: other-pod\n  namespace: default\n  labels:\n    role: other\nspec:\n  containers:\n    - name: other\n      image: mcr.microsoft.com/azure-cli:latest\n      command: [\"sleep\", \"infinity\"]\nEOF\nkubectl wait --for=condition=Ready pod/developer-pod pod/other-pod --namespace default --timeout=10m\n\nATTACH_STATUS=$(kubectl get securitypolicyattachment example-attachment --namespace default \\\n  -o jsonpath='{.status.conditions[?(@.type==\"Deployment\")].reason}')\ncat > \"$AZ_SCRIPTS_OUTPUT_PATH\" <<EOF\n{\"controllerVersion\": \"${CONTROLLER_VERSION}\", \"attachmentDeployment\": \"${ATTACH_STATUS}\"}\nEOF\necho \"Done\"\n",
    "vnetName": "[format('{0}-vnet', parameters('namePrefix'))]",
    "aksSubnetName": "aks-subnet",
    "vnetAddressPrefix": "10.224.0.0/12",
    "aksSubnetPrefix": "10.224.0.0/16",
    "firewallSubnetPrefix": "10.225.0.0/26",
    "firewallMgmtSubnetPrefix": "10.225.1.0/26",
    "clusterName": "[format('{0}-aks', parameters('namePrefix'))]",
    "firewallName": "[format('{0}-firewall', parameters('namePrefix'))]",
    "firewallPolicyName": "[format('{0}-firewall-policy', parameters('namePrefix'))]",
    "routeTableName": "[format('{0}-aks-rt', parameters('namePrefix'))]",
    "controllerServiceAccount": "azurefirewall-controller-sa",
    "networkContributorRoleId": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '4d97b98b-1d4f-4787-a291-c67834d212e7')]",
    "aksClusterAdminRoleId": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '0ab0b1a8-8aac-4efd-b8c2-3ee1fb270be8')]",
    "aksSubnetId": "[format('{0}/subnets/{1}', resourceId('Microsoft.Network/virtualNetworks', variables('vnetName')), variables('aksSubnetName'))]"
  },
  "resources": [
    {
      "type": "Microsoft.ManagedIdentity/userAssignedIdentities",
      "apiVersion": "2024-11-30",
      "name": "[format('{0}-aks-identity', parameters('namePrefix'))]",
      "location": "[parameters('location')]"
    },
    {
      "type": "Microsoft.ManagedIdentity/userAssignedIdentities",
      "apiVersion": "2024-11-30",
      "name": "[format('{0}-controller-identity', parameters('namePrefix'))]",
      "location": "[parameters('location')]"
    },
    {
      "type": "Microsoft.Network/virtualNetworks",
      "apiVersion": "2025-05-01",
      "name": "[variables('vnetName')]",
      "location": "[parameters('location')]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[variables('vnetAddressPrefix')]"
          ]
        },
        "subnets": [
          {
            "name": "[variables('aksSubnetName')]",
            "properties": {
              "addressPrefix": "[variables('aksSubnetPrefix')]",
              "defaultOutboundAccess": false
            }
          },
          {
            "name": "AzureFirewallSubnet",
            "properties": {
              "addressPrefix": "[variables('firewallSubnetPrefix')]",
              "defaultOutboundAccess": false
            }
          },
          {
            "name": "AzureFirewallManagementSubnet",
            "properties": {
              "addressPrefix": "[variables('firewallMgmtSubnetPrefix')]",
              "defaultOutboundAccess": false
            }
          }
        ]
      }
    },
    {
      "type": "Microsoft.Authorization/roleAssignments",
      "apiVersion": "2022-04-01",
      "scope": "[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]",
      "name": "[guid(resourceId('Microsoft.Network/virtualNetworks', variables('vnetName')), resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-aks-identity', parameters('namePrefix'))), variables('networkContributorRoleId'))]",
      "properties": {
        "roleDefinitionId": "[variables('networkContributorRoleId')]",
        "principalId": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-aks-identity', parameters('namePrefix'))), '2024-11-30').principalId]",
        "principalType": "ServicePrincipal"
      },
      "dependsOn": [
        "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-aks-identity', parameters('namePrefix')))]",
        "[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]"
      ]
    },
    {
      "type": "Microsoft.Network/publicIPAddresses",
      "apiVersion": "2025-05-01",
      "name": "[format('{0}-fw-ip', parameters('namePrefix'))]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Standard"
      },
      "properties": {
        "publicIPAllocationMethod": "Static",
        "publicIPAddressVersion": "IPv4"
      }
    },
    {
      "type": "Microsoft.Network/publicIPAddresses",
      "apiVersion": "2025-05-01",
      "name": "[format('{0}-fw-mgmt-ip', parameters('namePrefix'))]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Standard"
      },
      "properties": {
        "publicIPAllocationMethod": "Static",
        "publicIPAddressVersion": "IPv4"
      }
    },
    {
      "type": "Microsoft.Network/firewallPolicies",
      "apiVersion": "2025-05-01",
      "name": "[variables('firewallPolicyName')]",
      "location": "[parameters('location')]",
      "properties": {
        "sku": {
          "tier": "Premium"
        },
        "threatIntelMode": "Alert"
      }
    },
    {
      "type": "Microsoft.Network/firewallPolicies/ruleCollectionGroups",
      "apiVersion": "2025-05-01",
      "name": "[format('{0}/{1}', variables('firewallPolicyName'), 'default-allow-aks-controlplane')]",
      "properties": {
        "priority": 100,
        "ruleCollections": [
          {
            "ruleCollectionType": "FirewallPolicyFilterRuleCollection",
            "name": "AllowAksControlPlaneNetwork",
            "priority": 100,
            "action": {
              "type": "Allow"
            },
            "rules": [
              {
                "ruleType": "NetworkRule",
                "name": "Allow_AKS_ControlPlane_Network",
                "ipProtocols": [
                  "TCP"
                ],
                "sourceAddresses": [
                  "*"
                ],
                "destinationAddresses": [
                  "AzureKubernetesService"
                ],
                "destinationPorts": [
                  "443"
                ]
              }
            ]
          },
          {
            "ruleCollectionType": "FirewallPolicyFilterRuleCollection",
            "name": "AllowAksControlPlaneApp",
            "priority": 101,
            "action": {
              "type": "Allow"
            },
            "rules": [
              {
                "ruleType": "ApplicationRule",
                "name": "Allow_AKS_ControlPlane_App",
                "sourceAddresses": [
                  "*"
                ],
                "fqdnTags": [
                  "AzureKubernetesService"
                ],
                "protocols": [
                  {
                    "protocolType": "Https",
                    "port": 443
                  }
                ]
              },
              {
                "ruleType": "ApplicationRule",
                "name": "Allow_AFC_Service",
                "sourceAddresses": [
                  "*"
                ],
                "targetFqdns": [
                  "*.afc.azure.com"
                ],
                "protocols": [
                  {
                    "protocolType": "Https",
                    "port": 443
                  }
                ]
              }
            ]
          }
        ]
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/firewallPolicies', variables('firewallPolicyName'))]"
      ]
    },
    {
      "type": "Microsoft.Network/azureFirewalls",
      "apiVersion": "2025-05-01",
      "name": "[variables('firewallName')]",
      "location": "[parameters('location')]",
      "properties": {
        "sku": {
          "name": "AZFW_VNet",
          "tier": "Premium"
        },
        "firewallPolicy": {
          "id": "[resourceId('Microsoft.Network/firewallPolicies', variables('firewallPolicyName'))]"
        },
        "ipConfigurations": [
          {
            "name": "data-ipconfig",
            "properties": {
              "subnet": {
                "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vnetName'), 'AzureFirewallSubnet')]"
              },
              "publicIPAddress": {
                "id": "[resourceId('Microsoft.Network/publicIPAddresses', format('{0}-fw-ip', parameters('namePrefix')))]"
              }
            }
          }
        ],
        "managementIpConfiguration": {
          "name": "mgmt-ipconfig",
          "properties": {
            "subnet": {
              "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vnetName'), 'AzureFirewallManagementSubnet')]"
            },
            "publicIPAddress": {
              "id": "[resourceId('Microsoft.Network/publicIPAddresses', format('{0}-fw-mgmt-ip', parameters('namePrefix')))]"
            }
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/firewallPolicies/ruleCollectionGroups', variables('firewallPolicyName'), 'default-allow-aks-controlplane')]",
        "[resourceId('Microsoft.Network/publicIPAddresses', format('{0}-fw-mgmt-ip', parameters('namePrefix')))]",
        "[resourceId('Microsoft.Network/firewallPolicies', variables('firewallPolicyName'))]",
        "[resourceId('Microsoft.Network/publicIPAddresses', format('{0}-fw-ip', parameters('namePrefix')))]",
        "[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]"
      ]
    },
    {
      "type": "Microsoft.ContainerService/managedClusters",
      "apiVersion": "2025-07-01",
      "name": "[variables('clusterName')]",
      "location": "[parameters('location')]",
      "identity": {
        "type": "UserAssigned",
        "userAssignedIdentities": {
          "[format('{0}', resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-aks-identity', parameters('namePrefix'))))]": {}
        }
      },
      "properties": {
        "dnsPrefix": "[variables('clusterName')]",
        "agentPoolProfiles": [
          {
            "name": "nodepool1",
            "mode": "System",
            "count": "[parameters('nodeCount')]",
            "vmSize": "[parameters('nodeVmSize')]",
            "osType": "Linux",
            "type": "VirtualMachineScaleSets",
            "vnetSubnetID": "[variables('aksSubnetId')]"
          }
        ],
        "networkProfile": {
          "networkPlugin": "azure",
          "outboundType": "loadBalancer",
          "loadBalancerSku": "standard",
          "serviceCidr": "10.240.0.0/16",
          "dnsServiceIP": "10.240.0.10"
        },
        "oidcIssuerProfile": {
          "enabled": true
        },
        "securityProfile": {
          "workloadIdentity": {
            "enabled": true
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-aks-identity', parameters('namePrefix')))]",
        "[extensionResourceId(resourceId('Microsoft.Network/virtualNetworks', variables('vnetName')), 'Microsoft.Authorization/roleAssignments', guid(resourceId('Microsoft.Network/virtualNetworks', variables('vnetName')), resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-aks-identity', parameters('namePrefix'))), variables('networkContributorRoleId')))]",
        "[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]"
      ]
    },
    {
      "type": "Microsoft.Authorization/roleAssignments",
      "apiVersion": "2022-04-01",
      "name": "[guid(resourceGroup().id, resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix'))), variables('networkContributorRoleId'))]",
      "properties": {
        "roleDefinitionId": "[variables('networkContributorRoleId')]",
        "principalId": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix'))), '2024-11-30').principalId]",
        "principalType": "ServicePrincipal"
      },
      "dependsOn": [
        "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix')))]"
      ]
    },
    {
      "type": "Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials",
      "apiVersion": "2024-11-30",
      "name": "[format('{0}/{1}', format('{0}-controller-identity', parameters('namePrefix')), 'azurefirewall-controller')]",
      "properties": {
        "issuer": "[reference(resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName')), '2025-07-01').oidcIssuerProfile.issuerURL]",
        "subject": "[format('system:serviceaccount:{0}:{1}', parameters('controllerNamespace'), variables('controllerServiceAccount'))]",
        "audiences": [
          "api://AzureADTokenExchange"
        ]
      },
      "dependsOn": [
        "[resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName'))]",
        "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix')))]"
      ]
    },
    {
      "type": "Microsoft.Network/routeTables",
      "apiVersion": "2025-05-01",
      "name": "[variables('routeTableName')]",
      "location": "[parameters('location')]",
      "properties": {
        "routes": [
          {
            "name": "to-firewall",
            "properties": {
              "addressPrefix": "0.0.0.0/0",
              "nextHopType": "VirtualAppliance",
              "nextHopIpAddress": "[reference(resourceId('Microsoft.Network/azureFirewalls', variables('firewallName')), '2025-05-01').ipConfigurations[0].properties.privateIPAddress]"
            }
          }
        ]
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/azureFirewalls', variables('firewallName'))]"
      ]
    },
    {
      "type": "Microsoft.Network/virtualNetworks/subnets",
      "apiVersion": "2025-05-01",
      "name": "[format('{0}/{1}', variables('vnetName'), variables('aksSubnetName'))]",
      "properties": {
        "addressPrefix": "[variables('aksSubnetPrefix')]",
        "defaultOutboundAccess": false,
        "routeTable": {
          "id": "[resourceId('Microsoft.Network/routeTables', variables('routeTableName'))]"
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName'))]",
        "[resourceId('Microsoft.Network/routeTables', variables('routeTableName'))]",
        "[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]"
      ]
    },
    {
      "condition": "[parameters('deployControllerAndSample')]",
      "type": "Microsoft.ManagedIdentity/userAssignedIdentities",
      "apiVersion": "2024-11-30",
      "name": "[format('{0}-script-identity', parameters('namePrefix'))]",
      "location": "[parameters('location')]"
    },
    {
      "condition": "[parameters('deployControllerAndSample')]",
      "type": "Microsoft.Authorization/roleAssignments",
      "apiVersion": "2022-04-01",
      "scope": "[resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName'))]",
      "name": "[guid(resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName')), format('{0}-script-identity', parameters('namePrefix')), variables('aksClusterAdminRoleId'))]",
      "properties": {
        "roleDefinitionId": "[variables('aksClusterAdminRoleId')]",
        "principalId": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-script-identity', parameters('namePrefix'))), '2024-11-30').principalId]",
        "principalType": "ServicePrincipal"
      },
      "dependsOn": [
        "[resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName'))]",
        "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-script-identity', parameters('namePrefix')))]"
      ]
    },
    {
      "condition": "[parameters('deployControllerAndSample')]",
      "type": "Microsoft.Resources/deploymentScripts",
      "apiVersion": "2023-08-01",
      "name": "[format('{0}-install-controller', parameters('namePrefix'))]",
      "location": "[parameters('location')]",
      "kind": "AzureCLI",
      "identity": {
        "type": "UserAssigned",
        "userAssignedIdentities": {
          "[format('{0}', resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-script-identity', parameters('namePrefix'))))]": {}
        }
      },
      "properties": {
        "azCliVersion": "[parameters('azCliVersion')]",
        "timeout": "PT1H",
        "retentionInterval": "P1D",
        "cleanupPreference": "OnSuccess",
        "forceUpdateTag": "[parameters('utcValue')]",
        "environmentVariables": [
          {
            "name": "RESOURCE_GROUP",
            "value": "[resourceGroup().name]"
          },
          {
            "name": "CLUSTER_NAME",
            "value": "[variables('clusterName')]"
          },
          {
            "name": "CONTROLLER_VERSION",
            "value": "[parameters('controllerVersion')]"
          },
          {
            "name": "CONTROLLER_NAMESPACE",
            "value": "[parameters('controllerNamespace')]"
          },
          {
            "name": "CONTROLLER_CLIENT_ID",
            "value": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix'))), '2024-11-30').clientId]"
          },
          {
            "name": "FIREWALL_ID",
            "value": "[resourceId('Microsoft.Network/azureFirewalls', variables('firewallName'))]"
          },
          {
            "name": "AKS_SUBNET_ID",
            "value": "[variables('aksSubnetId')]"
          }
        ],
        "scriptContent": "[variables('$fxv#0')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName'))]",
        "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vnetName'), variables('aksSubnetName'))]",
        "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials', format('{0}-controller-identity', parameters('namePrefix')), 'azurefirewall-controller')]",
        "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix')))]",
        "[resourceId('Microsoft.Authorization/roleAssignments', guid(resourceGroup().id, resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix'))), variables('networkContributorRoleId')))]",
        "[resourceId('Microsoft.Network/azureFirewalls', variables('firewallName'))]",
        "[extensionResourceId(resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName')), 'Microsoft.Authorization/roleAssignments', guid(resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName')), format('{0}-script-identity', parameters('namePrefix')), variables('aksClusterAdminRoleId')))]",
        "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-script-identity', parameters('namePrefix')))]",
        "[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]"
      ]
    }
  ],
  "outputs": {
    "clusterName": {
      "type": "string",
      "value": "[variables('clusterName')]"
    },
    "firewallId": {
      "type": "string",
      "value": "[resourceId('Microsoft.Network/azureFirewalls', variables('firewallName'))]"
    },
    "firewallPrivateIp": {
      "type": "string",
      "value": "[reference(resourceId('Microsoft.Network/azureFirewalls', variables('firewallName')), '2025-05-01').ipConfigurations[0].properties.privateIPAddress]"
    },
    "firewallPolicyId": {
      "type": "string",
      "value": "[resourceId('Microsoft.Network/firewallPolicies', variables('firewallPolicyName'))]"
    },
    "aksSubnetId": {
      "type": "string",
      "value": "[variables('aksSubnetId')]"
    },
    "controllerIdentityClientId": {
      "type": "string",
      "value": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix'))), '2024-11-30').clientId]"
    },
    "getCredentialsCommand": {
      "type": "string",
      "value": "[format('az aks get-credentials --resource-group {0} --name {1}', resourceGroup().name, variables('clusterName'))]"
    },
    "helmInstallCommand": {
      "type": "string",
      "value": "[format('helm install azfw-controller oci://mcr.microsoft.com/firewall/charts/azurefirewall-controller --namespace {0} --create-namespace --version {1} --set azfwController.podIdentity.clientID={2}', parameters('controllerNamespace'), parameters('controllerVersion'), reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix'))), '2024-11-30').clientId)]"
    },
    "attachmentFirewallRef": {
      "type": "string",
      "value": "[format('firewallRef: {{ id: {0} }}', resourceId('Microsoft.Network/azureFirewalls', variables('firewallName')))]"
    },
    "controllerAndSampleInstalled": {
      "type": "bool",
      "value": "[parameters('deployControllerAndSample')]"
    }
  }
}

The template creates these resources:

Resource Purpose
Virtual network and subnets Provide an AKS subnet, AzureFirewallSubnet, and AzureFirewallManagementSubnet
AKS cluster Run workloads with Azure CNI, an OIDC issuer, and workload identity
Azure Firewall Premium and public IP addresses Inspect the cluster's egress traffic
Firewall policy and rule collection group Allow required AKS outbound traffic and HTTPS to *.afc.azure.com
Route table and subnet association Route the AKS subnet's outbound traffic through the firewall
Managed identities, role assignments, and a federated identity credential Authorize AKS networking and the Azure Firewall Controller
Optional deployment script and its identity Install the controller, sample policy, attachment, and test pods when Deploy Controller And Sample is true

Deploy the template

Keep Deploy Controller And Sample set to false unless your environment permits the optional deployment script.

  1. Select Deploy to Azure at the end of the introduction and sign in to Azure. The portal opens the Custom deployment page.

  2. Configure these settings:

    Setting Value
    Subscription Select the subscription for the evaluation
    Resource group Select or create a resource group; a new, dedicated resource group makes cleanup safer
    Region Use a preview region listed in Prerequisites
    Name Prefix Use the default afc, or enter a prefix for the resource names
    Node Vm Size Use Standard_DS3_v2 only if it's available in the selected region; otherwise, enter an available size
    Deploy Controller And Sample Leave false to deploy Azure resources only, then follow the README's installation steps. Set true only if shared key access is permitted for the deployment script

    Note

    With Deploy Controller And Sample set to true, the template runs a deployment script that requires a storage account with shared key access. If the built-in Azure Policy Storage accounts should prevent shared key access is assigned with the Deny effect, the deployment fails. Keep the default (false) and follow the install steps, or see the template README to check for the policy and request an exemption.

  3. Leave the other parameters at their defaults. Select Review + create and review the validation results.

  4. Select Create.

Allow about 10-15 minutes for the Azure resources to deploy, or 30-45 minutes with Deploy Controller And Sample set to true. Deployment time can vary.

Review deployed resources

  1. In the Azure portal, open the resource group and select Deployments. Open the template deployment and confirm that it succeeded.

  2. Review the deployed AKS cluster, Azure Firewall, firewall policy, virtual network, routing, and identities. Select Outputs to find the cluster name, firewall resource ID, and commands for the next steps.

  3. Complete the controller and policy setup for your deployment option:

    Deployment option Next action
    Deploy Controller And Sample is false Follow Install the controller and attach a policy. Use the getCredentialsCommand and helmInstallCommand deployment outputs instead of the README's example commands. Use the resource IDs in the outputs when creating the sample firewall reference and policy attachment
    Deploy Controller And Sample is true The deployment script installs the controller, sample policy, attachment, and test pods. Run getCredentialsCommand to connect from your own environment. Skip the README's controller installation and pod-creation commands so that you don't recreate existing resources

Before running Azure CLI commands, sign in and select the subscription used for this deployment. If you changed Name Prefix, use deployment outputs such as clusterName, firewallId, aksSubnetId, and controllerIdentityClientId rather than the README's default resource names.

Use the README's traffic tests to verify the sample policy's allow and deny behavior. If the deployment script already created the test pods, use the test commands for those existing pods. A successful Azure deployment alone doesn't verify traffic filtering.

Clean up resources

If you created a resource group exclusively for this quickstart, delete it when you finish evaluating the deployment:

  1. In the Azure portal, open the resource group and review its resources. Confirm that it contains no resources you need to keep.
  2. Select Delete resource group.
  3. Enter the resource group name and confirm the deletion.

Deleting the resource group removes all resources in it. If you reused a resource group, don't delete the group. Remove only resources you created for this evaluation. Follow the controller cleanup guidance if you need to remove individual policies or attachments.

Next steps