It has been about 6 years since the Automate IT² event organized by me and Gabriele Gerbino. During the event, Xavier Homes presented a case that fascinated me. Today we might call it: Firewall as Code.
My interest was not just in the elegance of the solution but also in the practical implications for operations and security.
For several years, I managed firewalls and now, as a consultant, I see many client implementations. All the installations I encounter have the same problems:
While there is software intended to solve the above problems, these solutions are often:
Let’s start from scratch by designing a process that addresses the problems described above, from which (and not the other way around) we derive a technology that allows us to manage our firewalls.
In the example shown, I used Palo Alto Networks firewalls. The reasons for this choice are:
The approach we will see should be applicable to all firewalls that meet these three properties.
The process I want to design is very simple:
Specifically, application managers must define network requirements through files and make them available along with the application’s code or documentation (Git would be a good tool, but not the only one). Daily or on request, the automation updates the policies.
As always, the modeling phase takes the most time. In the example, I assumed that:
networks.yml
and rules.yml
. The maintenance of both files is the responsibility of the application manager.Here’s an example:
# networks.yml
networks:
WWW:
- 10.20.1.7/32
APP:
- 10.20.2.15/32
DB:
- 10.20.2.23/32
The above file defines three objects: WWW
, APP
, DB
.
rules:
- destination-address: WWW
service: HTTP
description: |
Allow HTTP external traffic to exposed web server.
- destination-address: WWW
service: HTTPS
description: |
Allow HTTPS external traffic to exposed web server.
- source-address: WWW
destination-address: APP
service: HTTPS_8443
description: |
Allow traffic from exposed web server to application server.
- source-address: APP
destination-address: DB
service: MYSQL
description: |
Allow traffic from application server to database server.
The above file defines the rules for a specific application. Services are defined in the centralized services.yml
file:
services:
HTTP:
applications: web-browsing
HTTPS:
applications: ssl
HTTPS_8443:
protocol: tcp
port: 8443
applications: ssl
MYSQL:
applications: mysql
Security zones are mapped based on the rules defined in the network-zone_mapping.yml
file:
zones:
servers:
type: internal
networks:
- 10.20.2.0/24
dmz:
type: internal
networks:
- 10.20.1.0/24
# Internet (catch all)
internet:
type: external
networks:
- 0.0.0.0/0
To summarize the key points of the approach:
The most practical approach is therefore:
The advantage of this approach is clear: I never have to worry about checking if an object exists, if it is correct, or if it is in the right position. This greatly simplifies the implementation.
There are, of course, disadvantages or constraints:
Exceptions can obviously be made, but each special case will complicate the implementation.
Once the model is defined, a tool must be chosen to translate the model into an actual configuration. In my evaluation, I focused on:
pan-os-python
is based (interesting, isn’t it?)After some attempts with the official pan-os-python
library, I decided to take a different path because the library configures the firewall object by object, whereas my approach required manipulating the entire configuration file.
I then explored pan-python
, which seemed to do everything needed. However, due to poor documentation, I had to proceed by trial and error. I was almost at the point of writing my own library that directly invoked the native APIs.
Aerleon is a very interesting solution but did not reach the level of detail I needed. Using the CLI was unnecessary because Palo Alto Networks firewalls are fully manageable via native APIs.
Currently, the automation is implemented in a single Python file that:
The integration could be added to a CI/CD pipeline and customized based on needs.
There are still some things to manage:
Developing this automation took me about three days of work. Of course, the result is not production-ready but it is a good starting point.
The benefits of this approach are objective:
If you think this approach is futuristic, I must reveal that Xavier’s talk was based on a real installation at a fairly large international client.