Skip to content

Latest commit

Β 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”₯ Firewall Policy Automator

Python Palo Alto FortiGate License

Enterprise-grade firewall policy automation for Palo Alto and FortiGate platforms

Features β€’ Installation β€’ Usage β€’ Examples β€’ Documentation


Python Β Β Β  Palo Alto

🎯 Overview

The Firewall Policy Automator eliminates manual firewall rule management by providing a Python-based solution for automated policy deployment, validation, and compliance checking across multi-vendor environments.

Key Capabilities

Feature Description
πŸ”„ Multi-Vendor Support Unified API for Palo Alto PAN-OS and FortiGate FortiOS
πŸ“ Policy as Code Define firewall rules in YAML/JSON format
βœ… Pre-deployment Validation Syntax checking, conflict detection, shadowed rule analysis
πŸ“Š Compliance Reporting Generate audit-ready compliance reports
πŸ”™ Rollback Support Automatic backup and one-click rollback
πŸ“ˆ Bulk Operations Deploy hundreds of rules in seconds

⚑ Features

πŸ›‘οΈ Supported Platforms

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  PALO ALTO NETWORKS           β”‚  FORTINET                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β€’ PAN-OS 9.x, 10.x, 11.x     β”‚  β€’ FortiOS 6.x, 7.x        β”‚
β”‚  β€’ Panorama (Device Groups)    β”‚  β€’ FortiManager Support     β”‚
β”‚  β€’ VM-Series, PA-Series        β”‚  β€’ Virtual & Hardware       β”‚
β”‚  β€’ XML API & REST API          β”‚  β€’ REST API                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”§ Core Functions

  • Create - Deploy new security policies from templates
  • Read - Export existing policies to YAML/JSON/CSV
  • Update - Modify rules with change tracking
  • Delete - Safe removal with dependency checking
  • Validate - Pre-flight checks before deployment
  • Audit - Compliance verification against baselines

πŸ“¦ Installation

# Clone the repository
git clone https://github.com/tamersaid2022/firewall-policy-automator.git
cd firewall-policy-automator

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Linux/Mac
# venv\Scripts\activate   # Windows

# Install dependencies
pip install -r requirements.txt

Requirements

pan-os-python>=1.8.0
requests>=2.28.0
pyyaml>=6.0
jinja2>=3.1.0
rich>=13.0.0
python-dotenv>=1.0.0

πŸš€ Usage

Quick Start

from firewall_automator import FirewallAutomator

# Initialize connection
fw = FirewallAutomator(
    platform="paloalto",
    host="192.168.1.1",
    api_key="your-api-key"
)

# Deploy policy from YAML
fw.deploy_policy("policies/web-server-rules.yaml")

# Validate before commit
if fw.validate():
    fw.commit()

Command Line Interface

# Deploy policies
python firewall_automator.py deploy --config policies/production.yaml

# Export current rules
python firewall_automator.py export --format yaml --output backup/

# Validate configuration
python firewall_automator.py validate --config policies/new-rules.yaml

# Generate compliance report
python firewall_automator.py audit --baseline compliance/pci-dss.yaml

πŸ“‹ Examples

Policy Definition (YAML)

# policies/web-server-rules.yaml
---
policy_name: "Web-Server-Access"
description: "Allow HTTPS traffic to web servers"
rules:
  - name: "Allow-HTTPS-Inbound"
    source_zone: "untrust"
    destination_zone: "dmz"
    source_ip: ["any"]
    destination_ip: ["10.10.10.0/24"]
    application: ["ssl", "web-browsing"]
    service: ["application-default"]
    action: "allow"
    log_end: true
    profile_group: "strict-security"
    
  - name: "Allow-Web-to-DB"
    source_zone: "dmz"
    destination_zone: "trust"
    source_ip: ["10.10.10.0/24"]
    destination_ip: ["10.20.20.0/24"]
    application: ["mysql", "postgresql"]
    service: ["application-default"]
    action: "allow"
    log_end: true

Bulk Deployment Script

from firewall_automator import FirewallAutomator
from pathlib import Path

# Connect to Panorama
panorama = FirewallAutomator(
    platform="panorama",
    host="panorama.company.com",
    api_key=os.getenv("PAN_API_KEY")
)

# Deploy to multiple device groups
device_groups = ["DC-East", "DC-West", "Branch-Offices"]
policy_file = "policies/corporate-standard.yaml"

for dg in device_groups:
    print(f"Deploying to {dg}...")
    panorama.deploy_policy(policy_file, device_group=dg)
    
# Validate all changes
validation = panorama.validate_all()
if validation.success:
    panorama.commit_all(device_groups)
    print("βœ… Deployment successful!")
else:
    print(f"❌ Validation failed: {validation.errors}")
    panorama.rollback()

πŸ“Š Sample Output

╔══════════════════════════════════════════════════════════════╗
β•‘           FIREWALL POLICY DEPLOYMENT REPORT                  β•‘
╠══════════════════════════════════════════════════════════════╣
β•‘  Target:     PA-5260 (192.168.1.1)                          β•‘
β•‘  Policy:     Web-Server-Access                               β•‘
β•‘  Rules:      12 rules processed                              β•‘
β•‘  Status:     βœ… SUCCESS                                      β•‘
╠══════════════════════════════════════════════════════════════╣
β•‘  VALIDATION RESULTS                                          β•‘
β•‘  β”œβ”€ Syntax Check:        βœ… PASSED                          β•‘
β•‘  β”œβ”€ Conflict Detection:  βœ… NO CONFLICTS                    β•‘
β•‘  β”œβ”€ Shadow Analysis:     ⚠️  2 WARNINGS                     β•‘
β•‘  └─ Compliance Check:    βœ… PCI-DSS COMPLIANT               β•‘
╠══════════════════════════════════════════════════════════════╣
β•‘  CHANGES APPLIED                                             β•‘
β•‘  β”œβ”€ Rules Created:  8                                        β•‘
β•‘  β”œβ”€ Rules Modified: 3                                        β•‘
β•‘  β”œβ”€ Rules Deleted:  1                                        β•‘
β•‘  └─ Commit ID:      a3f7c2d1                                 β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

πŸ—οΈ Architecture

firewall-policy-automator/
β”œβ”€β”€ firewall_automator.py    # Main automation script
β”œβ”€β”€ config/
β”‚   └── settings.yaml        # Connection settings
β”œβ”€β”€ policies/
β”‚   β”œβ”€β”€ templates/           # Jinja2 policy templates
β”‚   └── production/          # Production policies
β”œβ”€β”€ compliance/
β”‚   β”œβ”€β”€ pci-dss.yaml        # PCI-DSS baseline
β”‚   └── nist-800-53.yaml    # NIST baseline
β”œβ”€β”€ reports/
β”‚   └── audit_YYYYMMDD.html # Generated reports
└── requirements.txt

πŸ” Security Best Practices

Practice Implementation
API Key Storage Use environment variables or vault
Least Privilege Create dedicated API user with minimal permissions
Audit Logging All operations logged with timestamps
Change Approval Optional approval workflow integration
Backup Automatic config backup before changes

πŸ“š Documentation

Document Description
API Reference Complete API documentation
Configuration Guide Setup and configuration
Troubleshooting Common issues and solutions
Contributing How to contribute

🀝 Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.


πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘¨β€πŸ’» Author

Tamer Khalifa - Network Automation Engineer

CCIE LinkedIn GitHub


⭐ Star this repo if you find it useful! ⭐

About

Automated firewall policy management for Palo Alto and FortiGate with CRUD operations, compliance auditing (PCI-DSS & NIST 800-53), pre-deployment validation, and rollback support

Topics

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages