Início rápido: Implante o Firewall do Azure para Containers com o Azure Resource Manager

Neste início rápido, você usa um modelo Azure Resource Manager (ARM) para criar um novo cluster AKS (Serviço de Kubernetes do Azure) e Firewall do Azure Premium for Firewall do Azure for Containers. O modelo também configura identidades gerenciadas, uma política de firewall e o roteamento da rede.

Por padrão, o template implanta apenas recursos do Azure. Você então instala o Firewall do Azure Controller e anexa uma política de segurança de exemplo seguindo o README do modelo. Um parâmetro opcional também instala o controlador, uma política de exemplo e pods de teste.

Um modelo Azure Resource Manager é um arquivo JSON (JavaScript Object Notation) que define a infraestrutura e a configuração do projeto. O modelo usa sintaxe declarativa. Você descreve a implantação pretendida sem escrever a sequência de comandos de programação para criar a implantação.

Importante

Firewall do Azure for Containers está atualmente em pré-visualização pública. Veja os Termos de Uso Complementares para Versões Prévias do Microsoft Azure para obter termos legais que se aplicam aos recursos do Azure que estão em versão beta, versão prévia ou que, de outra forma, ainda não foram lançados em disponibilidade geral.

Se seu ambiente atender aos pré-requisitos, selecione Implantar no Azure. O modelo será aberto na página Implantação personalizada no portal do Azure.

Botão para implantar o modelo ARM no Azure.

Prerequisites

  • Uma conta do Azure com uma assinatura ativa. Crie uma conta gratuitamente.
  • Acesso ao Firewall do Azure for Containers em uma região de visualização prévia com suporte.
  • Os provedores de recursos Microsoft.ContainerService e Microsoft.Network estão registrados na assinatura.
  • Permissão para criar AKS, recursos de rede, identidades gerenciadas e atribuições de funções no grupo de recursos. Criar atribuições de função requer um papel apropriado, como Administrador de Controle de Acesso Baseado em Papel, no escopo da atribuição.
  • Capacidade e quota para o tamanho da máquina virtual do nó AKS selecionado. A implantação padrão usa dois nós com tamanho Standard_DS3_v2; esse tamanho deve estar disponível na região selecionada.
  • A CLI do Azure, kubectl e Helm são necessários para as etapas após a implantação.

Use um ambiente de avaliação isolado. O template cria um novo cluster e direciona o tráfego de saída da sub-rede AKS através do firewall.

Para deixar o parâmetro Localização do modelo no padrão, selecione ou crie um grupo de recursos em uma destas regiões de visualização:

Region Valor da região Azure
EUA Central EUAP centraluseuap
Leste dos EUA 2 EUAP eastus2euap
Centro-oeste dos EUA westcentralus
Ásia Oriental eastasia
Sul do Reino Unido uksouth
EUA Central centralus

Examinar o modelo

O modelo é do 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')]"
    }
  }
}

O template cria estes recursos:

Resource Purpose
Rede virtual e sub-redes Forneça uma sub-rede AKS, AzureFirewallSubnet, e AzureFirewallManagementSubnet
Cluster do AKS Execute cargas de trabalho com Azure CNI, um emissor OIDC e identidade de carga de trabalho
Firewall do Azure Premium e endereços IP públicos Inspecionar o tráfego de saída do cluster
Política de firewall e grupo de coleção de regras Permitir que o tráfego de saída necessário do AKS e o HTTPS para *.afc.azure.com
Tabela de rotas e associação de sub-rede Rotear o tráfego de saída da sub-rede AKS através do firewall
Identidades gerenciadas, atribuições de funções e uma credencial de identidade federada Autorizar a rede do AKS e o Firewall do Azure Controller
Script de implantação opcional e sua identidade Instale o controlador, a política de exemplo, o anexo e os pods de teste quando Deploy Controller And Sample for true

Implantar o modelo

Mantenha Deploy Controller And Sample configurado como false , a menos que seu ambiente permita o script de implantação opcional.

  1. Selecione Implantar no Azure ao final da introdução e faça login no Azure. O portal abre a página Custom deployment.

  2. Configure estas definições:

    Setting Valor
    Subscription Selecione a assinatura para a avaliação
    Grupo de recursos Selecione ou crie um grupo de recursos; um novo grupo de recursos dedicado torna a limpeza mais segura
    Região Use uma região de visualização listada em "Pré-requisitos"
    Prefixo do nome Use o padrão afc ou insira um prefixo para os nomes dos recursos
    Tamanho da VM do nó Use Standard_DS3_v2 somente se estiver disponível na região selecionada; caso contrário, insira um tamanho disponível
    Implantar o Controlador e a Amostra Deixe false para implantar apenas recursos do Azure e, em seguida, siga os passos de instalação do README. Defina true somente se o acesso à chave compartilhada for permitido para o script de implantação

    Note

    Com Deploy Controller And Sample configurado como true, o template executa um script de implantação que requer uma conta de armazenamento com acesso compartilhado à chave. Se as contas embutidas do Azure Policy Storage impedirem que o acesso à chave compartilhada seja atribuído com o efeito Negação, a implantação falha. Mantenha o padrão (false) e siga os passos de instalação, ou consulte o modelo README para verificar a política e solicitar uma isenção.

  3. Deixe os outros parâmetros nos seus valores padrão. Selecione Revisar + criar e revisar os resultados da validação.

  4. Selecione Criar.

Espere cerca de 10-15 minutos para os recursos do Azure serem implantados, ou 30-45 minutos com Deploy Controller And Sample configurado como true. O tempo de implantação pode variar.

Examinar os recursos implantados

  1. No portal Azure, abra o grupo de recursos e selecione Implantações. Abra a implantação do modelo e confirme que ela foi bem-sucedida.

  2. Revise o cluster AKS implantado, o Firewall do Azure, a política de firewall, a rede virtual, o roteamento e as identidades. Selecione Saídas para encontrar o nome do cluster, o ID do recurso do firewall e os comandos para os próximos passos.

  3. Complete a configuração do controlador e da política para sua opção de implantação:

    Opção de implantação Próxima ação
    Deploy Controller And Sample é false Siga Instalar o controlador e anexe uma política. Use as getCredentialsCommand saídas de deployment helmInstallCommand e em vez dos comandos de exemplo do README. Use os IDs de recursos nas saídas ao criar a referência de firewall de exemplo e o anexo de política
    Implantar controlador e exemplo é true O script de implantação instala o controlador, a política de exemplo, o anexo e os pods de teste. Execute getCredentialsCommand para se conectar no seu próprio ambiente. Ignore os comandos de instalação do controlador e criação de pods do README para que você não recrie recursos existentes

Antes de executar os comandos do CLI do Azure, faça login e selecione a assinatura usada para esta implantação. Se você alterou o Prefixo de Nome, use saídas de implantação como clusterName, firewallId, aksSubnetId, e controllerIdentityClientId em vez dos nomes padrão dos recursos do README.

Use os testes de tráfego do README para verificar o comportamento de permitir e negar da política de exemplo. Se o script de implantação já criou os pods de teste, use os comandos de teste para esses pods existentes. Uma implantação bem-sucedida do Azure sozinha não verifica a filtragem de tráfego.

Limpar os recursos

Se você criou um grupo de recursos exclusivamente para este quickstart, exclua-o quando terminar de avaliar a implantação:

  1. No portal Azure, abra o grupo de recursos e revise seus recursos. Confirme que ele não contém recursos que você precise manter.
  2. Selecione Excluir grupo de recursos.
  3. Digite o nome do grupo de recursos e confirme a exclusão.

Excluir o grupo de recursos remove todos os recursos nele. Se você reutilizou um grupo de recursos, não exclua o grupo. Remova apenas os recursos que você criou para esta avaliação. Siga as instruções de limpeza do controlador se precisar remover políticas ou vínculos individuais.

Próximas Etapas