This article is contributed. See the original author and article here.

Azure Firewall is a managed stateful network security service that recently became generally available for premium features across most Azure regions, providing capabilities such as TLS inspection, URL filtering and more


Across the different virtual networks and subscriptions, rules are created for network segmentation and access control. Managing the network traffic may require you to audit rules for utilization, flow hit count or require a previous working configuration.


This runbook will help create instantaneous back-up copies of Azure Firewall with the Firewall Policy and when scheduled with an automation account, you can take daily/weekly snapshots and store them in a specified path.


For this runbook, Azure blob storage will be used to store Azure Firewall configuration for both network infrastructure and firewall policy at the time of the dump. You can edit the template to specify another storage method. We also discuss how to redeploy a firewall to a known configuration using one of the backed-up templates. For more information on other network resources that you may like to adapt to this runbook, please see the Export-AzResourceGroup module.



Requirements



  • Automation account

  • Storage Account

  • Runbook


 


Set up Automation account


Go to the Search bar and type Automation account. Create a New Automation account. When done, go to the Automation account and in the Settings blade, under Account settings, create a “Run As” account. This provide the service principal access that will be used to auto-login into our script later.


tobiotolorin_0-1642610140453.png


This runbook is a PowerShell module and we need to confirm that we have access to network and resources modules. On the Automation account blade which you have just created, go to Modules and then search the Gallery to import the following three requisites:


– Az.Account


– Az.Network


– Az.Resources


tobiotolorin_1-1642610193540.png


Create Storage account


Next, we create a storage account to store each back-up created in Azure Blob storage. Go to the search bar for resources and search for Storage Account. Create a Storage account. Select Cool storage mode


tobiotolorin_2-1642610219475.png


Next, we create the Runbook.


On the Automation account blade, click on Runbooks and create one. Here below, I have created AzFwBackUp.


tobiotolorin_3-1642610262929.png


 


After creating the runbook, copy the code from our Azure Network Security Github repository and paste it in line one. This code has three functions: 1. Create storage, 2. Export the firewall configuration, and save in the storage, and 3. Purge the older backups. It uses the Get-AzFirewall and Get-AzFirewallPolicy cmdlet to create snapshot instances.


 


Click Save and then click on Test Plane.


tobiotolorin_4-1642610311710.png


 


On the next page, you will be prompted for a few parameters which you have set up earlier:



  • Provide the resource group name, Azure Firewall name and Firewall Policy name, obtainable in your Resource group

  • Provide storage account name that was created in the step earlier above and the storage key.  The storage key can be obtained under “Access Keys” in the Storage Account blade (see image below).

  • Give it a Blob container name and specify a retention date. Back-ups older than this date will be deleted at next run.


tobiotolorin_5-1642610351313.png


 


Test the script


Click Start to begin the dry run to confirm you can store a copy of the current configuration. Once done, you can then proceed to create a schedule to make this run periodically.


tobiotolorin_7-1642610388322.png


 The back-up should be available in your Storage -> Container in .json format.


 


Create a schedule


To create a schedule, go to the Runbook that was created, at the Runbook blade, select Schedules -> Add a Schedule. Give it a name and select “RecurringConfigure for every week or month.


tobiotolorin_8-1642610470056.png


Click to “Link the schedule to the runbook.” Select the runbook you have created and then click “Configure parameters and run settings,” Fill this form as done earlier.


The Runbook should now be all set to create back-ups in. json template that may be used to restore the firewall to an earlier configuration. The storage account should now store your back-ups as specified.


tobiotolorin_9-1642610536508.png


 


Restore Azure Firewall


To restore an Azure firewall (firewall infrastructure and firewall policy) to an earlier configuration, run the following syntax in your Cloud shell:


 

New-AzResourceGroupDeployment -name $azurefirewallname -ResourceGroupName $resourcegroupname -TemplateFile $filepath

 


 


Note that Rule Collection Groups or RCGs are treated as dependency objects and these objects cannot be deployed in parallel. Collection groups all reference the policy as dependant (dependsOn in the arm template).


This means it will first update policy and then try to update all rule collection groups in parallel. This may fail due to the policy dependency issue. (This is currently by ARM (Azure Resource Manager) design and a roadmap item).


Hence, rule collection groups must be deployed one after the other using the “depends on” tag in your firewall backup file.


As an example, the Rule Collection Group would have to be edited using the rule processing order.


The format is to first specify the Firewall Policy name, then Policy RCG object.


 


 

      "type": "Microsoft.Network/firewallPolicies/ruleCollectionGroups",

      "apiVersion": "2020-11-01",

      "name": "SOC-NS-FWPolicy_premium/DefaultNetworkRuleCollectionGroup",

      "location": "westus2",

      "dependsOn": [

        "[resourceId('Microsoft.Network/firewallPolicies', 'SOC-NS-FWPolicy_premium')]",

   "[resourceId('Microsoft.Network/firewallPolicies/ruleCollectionGroups', 'SOC-NS-FWPolicy_premium','DefaultDnatRuleCollectionGroup')]"

      ]

 


 


(Also, confirm that the KeyVault information is not missing after the redeployment is complete)


 


In summary, you may need to export firewall settings when creating child policies, restoring from a wrong configuration, auditing rules etc. By setting up frequent back up schedule, you can create a historical record of your configuration.
For more information about Azure firewall use cases and governance information, see the Azure Network Security TechCommunity blog  





Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.