Skip to main content

Firewalls Configuration

Centralized management and deployment of firewalld configurations for Gentoo Linux systems, packaged and managed with Poetry.


🗂️ Project Structure

The public repository contains the CLI deployment tool, log streaming monitors, connectivity probes, and a clean template configuration (example/). Machine-specific configurations (private workstations, production servers) can be maintained in a separate private repository or external directory:

firewalls/
├── pyproject.toml                # Poetry package configuration and dependencies
├── firewalls/                    # Python package containing CLI tools
│   ├── __init__.py
│   ├── cli.py                    # Deployment and service control
│   ├── log_control.py            # Dynamic runtime LogDenied manager
│   ├── monitor.py                # Live real-time dashboard
│   ├── log_ingress.py            # Inbound blocked traffic monitor
│   ├── log_egress.py             # Outbound blocked traffic monitor
│   └── probes.py                 # Network connectivity probes
├── AI_PROMPT.md                  # Master prompt and guide for generating configurations with AI
├── README.md
└── example/                      # Clean machine configuration template
    ├── EXAMPLE.md                # Functional documentation of rules and services
    ├── post_deploy.sh.example    # Optional post-deployment script template
    └── etc/
        ├── firewalld/
        │   ├── firewalld.conf    # Main firewalld configuration
        │   ├── lockdown-whitelist.xml
        │   ├── zones/            # Zone definitions (e.g. public.xml)
        │   ├── services/         # Custom service definitions
        │   ├── ipsets/           # IPSet definitions (e.g. trusted-dns.xml)
        │   ├── icmptypes/        # ICMP type definitions
        │   ├── helpers/          # Connection helpers
        │   └── policies/         # Egress and inter-zone policies (egress-policy.xml)
        ├── syslog-ng/conf.d/     # Log routing into /var/log/firewalld/
        ├── logrotate.d/          # Log rotation configuration
        └── sysctl.d/             # Kernel network hardening (rp_filter, anti-spoofing)

🤖 Generating Machine Configurations with AI

To easily generate a customized firewall configuration using an AI assistant (Claude, Gemini, ChatGPT, Antigravity, etc.), refer to AI_PROMPT.md. It provides a master prompt ready to customize with your machine's role, network interfaces, and allowed services.


🚀 Usage

All commands are managed through Poetry:

1. Deploying a Machine Configuration

Machine configurations can reside in any local directory or private git repository:

  1. Direct path (absolute or relative):

    poetry run firewalls_deploy /path/to/my-firewalls/my_machine
    
  2. Using the --configs-dir (-d) option:

    poetry run firewalls_deploy my_machine --configs-dir /path/to/my-firewalls
    
  3. Using the environment variable (Recommended):

    export FIREWALLS_DIR="$HOME/my-firewalls"
    poetry run firewalls_deploy my_machine
    
  4. Template or repository machines (also checks ~/.config/firewalls/machines/):

    poetry run firewalls_deploy example
    

2. Stopping the firewalld Service

poetry run firewalls_deploy stop

What firewalls_deploy Does:

  1. Resolves and validates the machine configuration across search paths (--configs-dir, $FIREWALLS_DIR, ~/.config/firewalls/machines/, direct path, or local directory).
  2. Verifies root privileges.
  3. Synchronizes <machine>/etc/ into system /etc/ preserving permissions, symlinks, and directory structure.
  4. Enforces root:root ownership and secure permissions (0750 directories, 0644 files) strictly on files written under /etc/firewalld, without modifying parent directory permissions of /etc.
  5. Re-applies kernel network security parameters from /etc/sysctl.d/ if present.
  6. Configures and restarts/reloads syslog-ng to isolate firewall logs into /var/log/firewalld/.
  7. Reloads firewalld rules via firewall-cmd --reload (or starts the service with OpenRC / systemd if stopped).
  8. Automatically executes the optional post_deploy.sh script if present in the machine folder.

📊 Real-Time Monitoring and Log Analysis

You can monitor, tally, or summarize blocked events with the built-in CLI tools:

# Monitor blocked incoming connections (Ingress)
poetry run firewalls_log_ingress
poetry run firewalls_log_ingress --summary   # Displays ranked summary

# Monitor blocked outgoing connections (Egress)
poetry run firewalls_log_egress
poetry run firewalls_log_egress --summary    # Displays ranked summary

# Live interactive dashboard (Ingress + Egress with reverse DNS PTR)
poetry run firewalls_monitor                            # Default refresh (3s), top 20 rankings, DNS resolution
poetry run firewalls_monitor -n 2 -p 5                  # Refresh every 2s showing top 5 entries
poetry run firewalls_monitor --no-resolve               # Show raw IP addresses without reverse DNS

🧪 Connectivity Probes (firewalls_probes)

The firewalls_probes command tests connectivity for both outgoing (egress) and incoming (ingress / listen) traffic to validate that firewall policies work as expected.

Command Options

Parameter Short Description Default
--host -H Target hostname or IP address for outbound probes kde.org
--port -p Port number to probe 1555
--protocol -proto Transport protocol (tcp or udp) tcp
--timeout -t Maximum socket timeout in seconds 5.0
--count -c Number of probe iterations 1
--listen -l Listen Mode (Ingress): Opens port locally to wait for incoming connections Disabled (Outbound)
--bind -b Local interface IP address to bind in listen mode 0.0.0.0

1. Outgoing Permitted Traffic (Egress - Expected Success)

  • Standard Web Traffic (HTTP/HTTPS):
    poetry run firewalls_probes -H kde.org -p 80 -proto tcp
    poetry run firewalls_probes -H kde.org -p 443 -proto tcp
    
  • Gentoo Portage Sync (rsync):
    poetry run firewalls_probes -H rsync.gentoo.org -p 873 -proto tcp
    
  • DNS Resolution and Time Sync (NTP):
    poetry run firewalls_probes -H 1.1.1.1 -p 53 -proto udp
    poetry run firewalls_probes -H pool.ntp.org -p 123 -proto udp
    

2. Outgoing Blocked Traffic (Zero Trust - Expected Drop)

  • Unauthorized outbound port (e.g., TCP 1555):

    poetry run firewalls_probes -H kde.org -p 1555 -proto tcp -t 3.0
    

    Expected result: [FAILED] due to Connection timed out.

  • Outbound SSH to external host (TCP 22):

    poetry run firewalls_probes -H github.com -p 22 -proto tcp -t 3.0
    

    Expected result: [FAILED] (if outbound SSH is not explicitly allowed).

3. Incoming Traffic (Ingress / Listen Mode)

  • Test if a local port accepts incoming connections:
    # Listens on port 8080 locally for up to 10 seconds waiting for an incoming connection
    poetry run firewalls_probes -l -p 8080 -t 10.0
    
  • Listen on local UDP port:
    poetry run firewalls_probes -l -p 51820 -proto udp -t 10.0
    

4. Integrated Verification with Live Monitor

To visually confirm that packet drops are recorded accurately:

  1. In one terminal, launch the live dashboard:
    poetry run firewalls_monitor -a
    
  2. In a second terminal, execute a blocked probe:
    poetry run firewalls_probes -H kde.org -p 1555
    
  3. Observe the denial registered in real time under the DENIED OUTGOING (EGRESS) panel, complete with destination IP and reverse DNS PTR hostname.

🔒 Log Architecture and dmesg Protection

To prevent firewall drop logs from flooding the kernel ring buffer (dmesg) and /var/log/messages:

  1. On-Demand Drop Logging (LogDenied=off by default):

    • Traditionally, setting LogDenied=all in firewalld triggers printk() calls at the kernel level via nf_log_syslog, polluting dmesg with local network broadcast and drop packets.
    • Dynamic Solution: In firewalld.conf, LogDenied is set to off permanently. During normal operation, the firewall operates completely silently.
    • Automatic CLI Activation:
      • When starting firewalls_log_ingress, firewalls_log_egress, or firewalls_monitor (run as root), they dynamically invoke:
        firewall-cmd --set-log-denied=all
        
      • Upon exiting or pressing Ctrl+C, the signal handler immediately restores:
        firewall-cmd --set-log-denied=off
        
      • Kernel drop logging only takes place while an administrator is actively monitoring traffic.
  2. syslog-ng Routing:

    • syslog-ng captures firewall drops and routes them exclusively to /var/log/firewalld/denied.log.
    • Includes a throttle(30) directive to prevent disk exhaustion from log flooding attacks.
    • firewalls_deploy automatically configures @include "/etc/syslog-ng/conf.d/*.conf" before catch-all rules, guaranteeing with flags(final); that firewall drops do not leak into /var/log/messages.

➕ Adding a New Machine

  1. Use the instructions and master prompt in AI_PROMPT.md with an AI assistant, or copy the example/ template:
    mkdir -p ~/my-firewalls/server1
    cp -r example/* ~/my-firewalls/server1/
    
  2. Customize the XML files in ~/my-firewalls/server1/etc/firewalld/ for your host.
  3. Deploy with:
    poetry run firewalls_deploy ~/my-firewalls/server1
    # Or with FIREWALLS_DIR exported:
    poetry run firewalls_deploy server1
    

Metadata

Release files for firewalls 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for firewalls 0.1.0
File Size Uploaded Provenance Actions
firewalls-0.1.0.tar.gz 68.3 kB Without provenance Details for firewalls-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for firewalls 0.1.0
File Interpreter ABI Platform Actions
firewalls-0.1.0-py3-none-any.whl Python 3 none any Details for firewalls-0.1.0-py3-none-any.whl

Total release size: 178.4 kB

Release files / firewalls-0.1.0.tar.gz

Download URL firewalls-0.1.0.tar.gz
Size 68.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1aa7a86905c569ab8897194879b34b47cbe4354e4114191463a9c494a7e4c52e
BLAKE2b-256 checksum
How to use checksums
bdcc6cf33c247b5ee936c7c46a2f1ac5575d63edc9db55a84a0576e89f7c9771
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.2 CPython/3.14.9 Linux/7.3.0-gentoo

Release files / firewalls-0.1.0-py3-none-any.whl

Download URL firewalls-0.1.0-py3-none-any.whl
Size 110.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
34675a3607731d9f3b7c12d5db3911c11c02c7ffd3ccfc6f562212dbc084233f
BLAKE2b-256 checksum
How to use checksums
fa427776f1e71eef1aa2f66f5e7ade414811c01bff3ab3dfdd119135b0c37027
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.2 CPython/3.14.9 Linux/7.3.0-gentoo

Security for firewalls 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page