Network automation in practice lab 4 of 11

Firewall policy as code - FortiOS REST and PAN-OS XML API

Keep Fenwick Rail's monitoring rule in one YAML file and make a FortiGate and a Palo Alto Networks firewall hold exactly that, through their own APIs: FortiOS REST with a session login, PAN-OS XML with an API key, a candidate configuration and a commit job. Every object is read before it is written, so the second run changes nothing and commits nothing.

Run this lab

It needs Standard: its 3 nodes are set to 4 vCPU and 9,728 MB in total. It is ready about 17 minutes after you start it. It starts already set up, with nothing to paste before the first task.

In your workspace: Shared, then Network Automation in Practice - multi-vendor professional guided labs, then 04 - Firewall policy as code - FortiOS REST and PAN-OS XML API

Run it on Standard from £5 a day

  • About 17 min to be ready
  • About 75 min of tasks

The free demo isn’t offered for this lab: it is Lite size, with 6 vCPU and 8 GB, and this lab’s nodes need 4 vCPU and 9,728 MB together. Every lab plan includes every guided lab.

Level
Advanced
How you work
CLI-led
Nodes need
4 vCPU, 9,728 MB
Smallest plan
Standard

The scenario

Fenwick Rail runs two firewall vendors: a FortiGate at the depots and a Palo Alto Networks firewall in the York data centre. The monitoring server (10.20.0.10) needs HTTPS on port 8443 to the new freight-booking servers (10.60.0.0/24) through both. In the past someone clicked it into each GUI, slightly differently each time. From today the rule lives in rules.yaml, and fwpolicy.py makes both firewalls hold exactly that.

fwapi.py already talks to both APIs. Two pieces are missing: the logic that decides whether an object needs writing, and the PAN-OS commit.

Start-up and waits. Click Start all. fgt1 is ready in about a minute. pa1 boots from its bootstrap disk, which sets its management address, the netops login and the zones inside and servers: its web interface and API answer after about 8 to 10 minutes, and a commit then takes 2 to 6 minutes on this virtual firewall. Do Tasks 1 and 2 on fgt1 while pa1 boots. Measured on our servers: the whole lab was ready for its first task about 17 minutes after Start all, with every device booted.

What you’ll practise

  • Sign in to FortiOS's REST API and PAN-OS's XML API from Python
  • Read, create and replace address objects, services and security rules on both
  • Compare objects in one neutral shape so the same policy logic drives two vendors
  • Commit PAN-OS only when its candidate has pending changes, and follow the commit job
  • Prove idempotence: a second run reports 0 changes and no commit

The tasks

  1. Talk to both APIs by hand
  2. Decide what to write
  3. Commit only when there is something to commit
  4. Apply, then look
  5. Prove it

The Lab Tasks pane has the scenario, these tasks, the checks to run, hints and the full solution.

Topology and devices

The network as it opens in EVE-NG, drawn from the lab’s own canvas, and the image each node runs.

Topology of Firewall policy as code - FortiOS REST and PAN-OS XML API3 nodes and 1 network, 3 links. Every link is listed as text below the diagram.devboxfgt1pa1Mgmteth0port1mgmt
3 nodes and 1 network, with the interface names each link uses. On a narrow screen, scroll the diagram sideways.
Nodes in Firewall policy as code - FortiOS REST and PAN-OS XML API, with the image each runs and the vCPU and RAM it’s set to
NodeDeviceImage in Add NodeSet to
devboxCloudLabBox code workstation (Docker)CloudLabBox’s own workstation image, with a browser code editor1 vCPU, 2,048 MB
fgt1Fortinet FortiGatefortinet-FGT-v7.0.17.M-build06821 vCPU, 2,048 MB
pa1Palo Alto Networks VM-Series (PAN-OS)paloalto-11.2.52 vCPU, 5,632 MB

How to open this lab

  1. Sign in to your workspace at lab.cloudlabbox.com.

  2. In File Manager, open Shared, then the folder Network Automation in Practice - multi-vendor professional guided labs.

  3. Open 04 - Firewall policy as code - FortiOS REST and PAN-OS XML API and start its nodes, then open Lab Tasks for the scenario and the steps.

The lab is read-only. You can start the nodes and configure the devices, but changes to the topology can’t be saved. To change it, rebuild it in your own folder.

More Network automation in practice labs

All Network automation in practice labs

Related labs in other courses

CloudLabBox is independent of Arista Networks, Cisco, Fortinet, Juniper Networks and Palo Alto Networks. The lab follows exam topics and isn’t vendor training material; vendor names identify the exams and the images in the workspace.