11<a id =" top " ></a >
22
3- <h1 align =" center " >Apotropaios — Firewall Manager (Python Variant)</h1 >
3+ <h1 align =" center " >Apotropaios - Firewall Manager (Python Variant)</h1 >
44<p align =" center " >
55 A unified, security-focused firewall management framework for Linux<br >supporting five backends with zero external runtime dependencies.
66</p >
1313</p >
1414
1515<p align =" center " >
16- <img src =" https://img.shields.io/badge/mypy-strict%20passing-7B68EE?style=flat-square " alt =" mypy strict " >
17- <img src =" https://img.shields.io/badge/CI-passing-brightgreen?style=flat-square&logo=githubactions&logoColor=white " alt =" CI Tests " >
18- <img src =" https://img.shields.io/badge/pytest-230%20tests-blue?style=flat-square " alt =" 230 Tests " >
19- <img src =" https://img.shields.io/badge/security-15%20CWE%20checks-blueviolet?style=flat-square " alt =" 15 CWE Checks " >
16+ <a href =" https://github.com/Sandler73/Apotropaios-Firewall-Manager/actions/workflows/ci.yml " ><img src =" https://github.com/Sandler73/Apotropaios-Firewall-Manager/actions/workflows/ci.yml/badge.svg?branch=main " alt =" CI " ></a >
17+ <a href =" https://github.com/Sandler73/Apotropaios-Firewall-Manager/actions/workflows/security.yml " ><img src =" https://github.com/Sandler73/Apotropaios-Firewall-Manager/actions/workflows/security.yml/badge.svg?branch=main " alt =" Security " ></a >
18+ <a href =" https://github.com/Sandler73/Apotropaios-Firewall-Manager/actions/workflows/codeql.yml " ><img src =" https://github.com/Sandler73/Apotropaios-Firewall-Manager/actions/workflows/codeql.yml/badge.svg?branch=main " alt =" CodeQL " ></a >
19+ <a href =" https://github.com/Sandler73/Apotropaios-Firewall-Manager/actions/workflows/docs-validate.yml " ><img src =" https://github.com/Sandler73/Apotropaios-Firewall-Manager/actions/workflows/docs-validate.yml/badge.svg?branch=main " alt =" Docs Validate " ></a >
20+ </p >
21+
22+ <p align =" center " >
23+ <img src =" https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2FSandler73%2FApotropaios-Firewall-Manager%2Fbadges%2Fmypy.json&style=flat-square " alt =" mypy strict " >
24+ <img src =" https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2FSandler73%2FApotropaios-Firewall-Manager%2Fbadges%2Ftests.json&style=flat-square " alt =" pytest suite " >
25+ <img src =" https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2FSandler73%2FApotropaios-Firewall-Manager%2Fbadges%2Fcoverage.json&style=flat-square " alt =" coverage " >
26+ <img src =" https://img.shields.io/badge/dynamic/toml?url=https%3A%2F%2Fraw.githubusercontent.com%2FSandler73%2FApotropaios-Firewall-Manager%2Fmain%2Fpyproject.toml&query=%24.project.version&prefix=v&label=version&color=blue&style=flat-square " alt =" framework version " >
2027</p >
2128
2229<p align =" center " >
9299
93100## Overview
94101
95- Apotropaios (from Greek * apotropaios* — "turning away evil") is a zero-dependency Python 3.12+ framework for unified firewall management across multiple backends and Linux distributions. It wraps the complexity of five different firewall tools — ** iptables** , ** nftables** , ** firewalld** , ** ufw** , and ** ipset** — into a single, consistent interface with UUID-tracked rule lifecycle management, full backup/recovery, and defense-in-depth security controls at every layer.
102+ Apotropaios (from Greek * apotropaios* -- "turning away evil") is a zero-dependency Python 3.12+ framework for unified firewall management across multiple backends and Linux distributions. It wraps the complexity of five different firewall tools -- ** iptables** , ** nftables** , ** firewalld** , ** ufw** , and ** ipset** -- into a single, consistent interface with UUID-tracked rule lifecycle management, full backup/recovery, and defense-in-depth security controls at every layer.
96103
97- This is the ** Python variant** of the [ bash Apotropaios framework] ( https://github.com/Sandler73/Apotropaios-Firewall-Manager ) , targeting 100% feature parity with v1.1.10. The Python implementation uses strict typing (` mypy --strict ` with zero errors), a 5-layer architecture with enforced dependency ordering, and 230 automated tests across unit, integration, and security tiers.
104+ This is the ** Python variant** of the [ bash Apotropaios framework] ( https://github.com/Sandler73/Apotropaios-Firewall-Manager ) , targeting 100% feature parity with v1.1.10. The Python implementation uses strict typing (` mypy --strict ` with zero errors), a 5-layer architecture with enforced dependency ordering, and 322 automated tests across unit, integration, and security tiers.
98105
99- Every firewall rule created through Apotropaios receives a unique ** UUID** , is tracked in a persistent rule index, and supports full lifecycle operations: create, activate, deactivate, remove, and automatic TTL-based expiry. The framework handles the translation between its unified rule model and each backend's native syntax — compound actions like ` log,drop ` become separate LOG + terminal rules in iptables, single expressions in nftables, rich rule log clauses in firewalld, and extracted terminal actions in ufw.
106+ Every firewall rule created through Apotropaios receives a unique ** UUID** , is tracked in a persistent rule index, and supports full lifecycle operations: create, activate, deactivate, remove, and automatic TTL-based expiry. The framework handles the translation between its unified rule model and each backend's native syntax -- compound actions like ` log,drop ` become separate LOG + terminal rules in iptables, single expressions in nftables, rich rule log clauses in firewalld, and extracted terminal actions in ufw.
100107
101108The framework emphasizes security at every layer: 27 whitelist input validators, shell injection prevention via list-form subprocess calls (never ` shell=True ` ), secure file permissions (0o600/0o700), atomic file locking via ` fcntl.flock() ` , cryptographic integrity verification, and automatic masking of sensitive data in logs across four format families.
102109
@@ -108,18 +115,18 @@ The framework emphasizes security at every layer: 27 whitelist input validators,
108115
109116| | Feature | Description |
110117| ---| ---------| -------------|
111- | 🔥 | ** Five Firewall Backends** | iptables, nftables, firewalld, ufw, ipset — auto-detected and selectable |
118+ | 🔥 | ** Five Firewall Backends** | iptables, nftables, firewalld, ufw, ipset -- auto-detected and selectable |
112119| 🆔 | ** UUID Rule Tracking** | Every rule gets a UUID for lifecycle management: create, activate, deactivate, remove, expire |
113- | 🔀 | ** Compound Actions** | ` log,drop ` and ` log,accept ` translated natively per backend — no wrapper scripts |
120+ | 🔀 | ** Compound Actions** | ` log,drop ` and ` log,accept ` translated natively per backend -- no wrapper scripts |
114121| 📊 | ** Connection Tracking** | ` new ` , ` established ` , ` related ` , ` invalid ` , ` untracked ` states on any rule |
115- | ⏱️ | ** Rate Limiting** | ` 5/minute ` , ` 10/second ` , ` 100/hour ` with configurable burst — per-rule granularity |
122+ | ⏱️ | ** Rate Limiting** | ` 5/minute ` , ` 10/second ` , ` 100/hour ` with configurable burst -- per-rule granularity |
116123| 🖥️ | ** Interactive Menu** | 8-category guided interface with validation, cancel support, and ExpiryMonitor daemon |
117124| 💾 | ** Backup & Recovery** | Timestamped compressed archives, immutable ` chattr +i ` snapshots, SHA-256 verification |
118125| 📦 | ** Import / Export** | Portable rule configurations with integrity verification and dry-run preview |
119126| 🛡️ | ** Security-First Design** | 27 whitelist validators, CWE-mapped test suite, OWASP/NIST-aligned controls |
120127| 📝 | ** Structured Logging** | Correlation IDs, 4-family sensitive data masking, secure rotation |
121128| ❓ | ** Progressive Help** | Two-tier: global ` --help ` , per-command ` COMMAND --help ` (18 commands) |
122- | ⚡ | ** Zero Runtime Dependencies** | Python 3.12+ stdlib only — no pip packages required at runtime |
129+ | ⚡ | ** Zero Runtime Dependencies** | Python 3.12+ stdlib only -- no pip packages required at runtime |
123130| 🔒 | ** Type-Safe** | ` mypy --strict ` with zero errors across all 35 source files |
124131
125132<p align =" right " >(<a href =" #table-of-contents " >back to top</a >)</p >
@@ -133,7 +140,7 @@ The framework emphasizes security at every layer: 27 whitelist input validators,
133140- ** Unified multi-backend management** : Consistent CLI and menu across iptables, nftables, firewalld, ufw, and ipset
134141- ** Automatic backend detection** : Scans installed firewalls, auto-selects the best available, or lets you choose with ` --backend `
135142- ** UUID rule lifecycle** : Create, activate, deactivate, remove, and automatic TTL-based expiry with full audit trail
136- - ** Compound actions** : ` log,drop ` , ` log,accept ` , ` log,reject ` — translated to each backend's native representation
143+ - ** Compound actions** : ` log,drop ` , ` log,accept ` , ` log,reject ` -- translated to each backend's native representation
137144- ** Connection state tracking** : ` --conn-state new,established,related ` on any rule, mapped to conntrack/ct state per backend
138145- ** Rate limiting** : ` --limit 5/minute --limit-burst 10 ` for traffic shaping, translated to ` -m limit ` (iptables), ` limit rate ` (nftables), or rich rule limit (firewalld)
139146- ** Configuration portability** : Import/export rule sets with SHA-256 integrity verification and dry-run preview
@@ -145,7 +152,7 @@ The framework emphasizes security at every layer: 27 whitelist input validators,
145152### Input Validation and Security
146153
147154- 27 whitelist validators for all user-supplied data types (ports, IPs, CIDRs, protocols, hostnames, paths, chains, tables, table families, zones, interfaces, rule IDs, actions, connection states, rate limits, log levels, log prefixes, descriptions)
148- - Whitelist-based input sanitization — ` sanitize_input() ` keeps only known-safe characters via compiled regex
155+ - Whitelist-based input sanitization -- ` sanitize_input() ` keeps only known-safe characters via compiled regex
149156- Shell metacharacter rejection via O(1) frozenset intersection (` _contains_shell_meta() ` )
150157- Path traversal detection and null byte injection rejection on all file path parameters
151158- Maximum input length enforcement (4096 characters)
@@ -165,7 +172,7 @@ See [SECURITY.md](SECURITY.md) for the full security design, implemented control
165172- Sensitive data masking across four format families: key=value, key="quoted", JSON (` "key": "value" ` ), and HTTP Authorization headers
166173- Control character stripping prevents log injection
167174- Log files written with 0o600 permissions, log directories with 0o700
168- - Console handler removed before shutdown marker — no post-shutdown noise
175+ - Console handler removed before shutdown marker -- no post-shutdown noise
169176
170177<p align =" right " >(<a href =" #table-of-contents " >back to top</a >)</p >
171178
@@ -248,7 +255,7 @@ A compound action like `log,drop` is expressed differently by each backend:
248255| ** firewalld** | Rich rule with log clause: ` rule ... log prefix "..." level info drop ` |
249256| ** ufw** | Terminal action extracted for ufw verb; logging enabled via ` ufw logging ` |
250257
251- Removal mirrors the add logic exactly — for iptables, both the LOG rule and the terminal rule are deleted to prevent orphaned kernel rules.
258+ Removal mirrors the add logic exactly -- for iptables, both the LOG rule and the terminal rule are deleted to prevent orphaned kernel rules.
252259
253260<p align =" right " >(<a href =" #table-of-contents " >back to top</a >)</p >
254261
@@ -306,7 +313,7 @@ Removal mirrors the add logic exactly — for iptables, both the LOG rule and th
306313
307314- Root/sudo access for firewall operations (kernel-level packet filtering)
308315- Python 3.12+ for modern type annotation syntax (` X | None ` , ` dict[str, str] ` )
309- - No external runtime dependencies — stdlib only, no pip packages required
316+ - No external runtime dependencies -- stdlib only, no pip packages required
310317
311318<p align =" right " >(<a href =" #table-of-contents " >back to top</a >)</p >
312319
@@ -343,42 +350,42 @@ sudo python3 apotropaios.py backup pre-deploy
343350
344351Quick copy-paste examples for common operations. See the [ Usage Guide] ( USAGE_GUIDE.md ) for complete options and operational scenarios.
345352
346- ** Add rules** — Create firewall rules with various options:
353+ ** Add rules** -- Create firewall rules with various options:
347354``` bash
348355sudo python3 apotropaios.py add-rule --dst-port 443 --action accept --protocol tcp
349356sudo python3 apotropaios.py add-rule --src-ip 10.0.0.0/8 --action drop --direction inbound
350357sudo python3 apotropaios.py add-rule --dst-port 22 --action log,drop --conn-state new --limit 3/minute
351358sudo python3 apotropaios.py add-rule --dst-port 80 --action accept --duration temporary --ttl 3600
352359```
353360
354- ** Manage rules** — Lifecycle operations on existing rules:
361+ ** Manage rules** -- Lifecycle operations on existing rules:
355362``` bash
356363sudo python3 apotropaios.py list-rules # Show all tracked rules
357364sudo python3 apotropaios.py remove-rule < UUID> # Remove a specific rule
358365sudo python3 apotropaios.py deactivate-rule < UUID> # Deactivate (keep in index)
359366sudo python3 apotropaios.py activate-rule < UUID> # Reactivate a deactivated rule
360367```
361368
362- ** Import / Export** — Portable rule configurations:
369+ ** Import / Export** -- Portable rule configurations:
363370``` bash
364371sudo python3 apotropaios.py export /tmp/my-rules.conf # Export current rules
365372sudo python3 apotropaios.py import /tmp/my-rules.conf # Import rules from file
366373sudo python3 apotropaios.py import rules.conf --dry-run # Preview without applying
367374```
368375
369- ** Backup / Restore** — Protect your configuration:
376+ ** Backup / Restore** -- Protect your configuration:
370377``` bash
371378sudo python3 apotropaios.py backup pre-deploy # Create a named backup
372379sudo python3 apotropaios.py restore backup.tar.gz # Restore from specific backup
373380```
374381
375- ** Quick actions** — Emergency operations:
382+ ** Quick actions** -- Emergency operations:
376383``` bash
377384sudo python3 apotropaios.py block-all # Block all traffic
378385sudo python3 apotropaios.py allow-all # Allow all traffic
379386```
380387
381- ** System information** — Diagnostics:
388+ ** System information** -- Diagnostics:
382389``` bash
383390sudo python3 apotropaios.py detect # Scan OS and firewalls
384391sudo python3 apotropaios.py status # Show service state
@@ -714,10 +721,11 @@ apotropaios-python/ # Repository root
714721│ └── menu/ # Layer 5: Interactive Menu
715722│ ├── main.py # 8-category menu, ExpiryMonitor
716723│ └── help_system.py # Per-command help functions
717- ├── tests/ # 230 automated tests
718- │ ├── unit/ # 9 files, 204 tests
719- │ ├── integration/ # 2 files, 11 tests
720- │ └── security/ # 1 file, 15 tests
724+ ├── tests/ # 322 automated tests
725+ │ ├── unit/ # 12 files, 267 tests
726+ │ ├── integration/ # 2 files, 13 tests
727+ │ ├── security/ # 1 file, 15 tests
728+ │ └── ci/ # 1 file, 27 tests (workflow/template meta-tests)
721729├── docs/ # 12 documentation files + wiki
722730│ ├── wiki/ # 15 standalone wiki pages
723731│ └── LICENSE # MIT + 12 supplementary sections
@@ -777,13 +785,14 @@ See [TROUBLESHOOTING.md](TROUBLESHOOTING.md) for troubleshooting details.
777785
778786## Testing
779787
780- 230 automated tests across three tiers:
788+ 322 automated tests across four tiers:
781789
782790| Tier | Tests | Description |
783791| ------| -------| -------------|
784- | ** Unit** | 175 | Module-level testing of all 27 validators, error handling, logging, security, detection, backends, rule engine |
785- | ** Integration** | 11 | End-to-end CLI via subprocess, full rule lifecycle with MockBackend |
792+ | ** Unit** | 267 | Module-level testing of all 27 validators, error handling, logging, security, detection, backends, rule engine, backend re-validation, and audit regressions |
793+ | ** Integration** | 13 | End-to-end CLI via subprocess, base-directory isolation , full rule lifecycle with MockBackend |
786794| ** Security** | 15 | CWE-mapped injection prevention: shell, path traversal, XSS, hostname |
795+ | ** CI meta** | 27 | Workflow and issue-template validation (YAML, action pins, headers) |
787796
788797``` bash
789798make test # Full suite: lint + unit + integration + security
@@ -803,13 +812,13 @@ See `make help` for all 56 Makefile targets including individual per-module test
803812
804813Contributions are welcome. Before submitting:
805814
806- - Run ` make check ` (must pass: mypy --strict + 230 tests)
815+ - Run ` make check ` (must pass: mypy --strict + 322 tests)
807816- Follow coding standards in [ DEVELOPMENT_GUIDE.md] ( DEVELOPMENT_GUIDE.md )
808817- All user-supplied inputs must pass through existing validation functions
809818- New CLI commands must be added to the parser, help function, and at least one test
810819- Update ` CHANGELOG.md ` with your changes
811820- Read and follow the [ Code of Conduct] ( CODE_OF_CONDUCT.md )
812- - Report security vulnerabilities privately per [ SECURITY.md] ( SECURITY.md ) — do not open public issues for security bugs
821+ - Report security vulnerabilities privately per [ SECURITY.md] ( SECURITY.md ) -- do not open public issues for security bugs
813822
814823For the complete development guide including environment setup, test architecture, coding standards, and PR process, see [ CONTRIBUTING.md] ( CONTRIBUTING.md ) and [ DEVELOPMENT_GUIDE.md] ( DEVELOPMENT_GUIDE.md ) .
815824
@@ -849,15 +858,15 @@ Release-by-release details are maintained exclusively in [CHANGELOG.md](CHANGELO
849858
850859## Acknowledgments
851860
852- - ** [ netfilter.org] ( https://www.netfilter.org/ ) ** — iptables, nftables, and ipset — the kernel-level packet filtering framework this tool manages
853- - ** [ firewalld] ( https://firewalld.org/ ) ** — dynamic firewall management daemon with D-Bus interface
854- - ** [ ufw] ( https://launchpad.net/ufw ) ** — Ubuntu's Uncomplicated Firewall providing simplified iptables management
855- - ** [ pytest] ( https://pytest.org/ ) ** — Python testing framework used for the test suite
856- - ** [ mypy] ( https://mypy-lang.org/ ) ** — Static type checker for Python
857- - ** [ Contributor Covenant] ( https://www.contributor-covenant.org/ ) ** — code of conduct framework
858- - ** [ Keep a Changelog] ( https://keepachangelog.com/ ) ** — changelog format standard
859- - ** [ Shields.io] ( https://shields.io/ ) ** — badge generation service
860- - ** OWASP** and ** NIST** — security standards referenced throughout
861+ - ** [ netfilter.org] ( https://www.netfilter.org/ ) ** -- iptables, nftables, and ipset -- the kernel-level packet filtering framework this tool manages
862+ - ** [ firewalld] ( https://firewalld.org/ ) ** -- dynamic firewall management daemon with D-Bus interface
863+ - ** [ ufw] ( https://launchpad.net/ufw ) ** -- Ubuntu's Uncomplicated Firewall providing simplified iptables management
864+ - ** [ pytest] ( https://pytest.org/ ) ** -- Python testing framework used for the test suite
865+ - ** [ mypy] ( https://mypy-lang.org/ ) ** -- Static type checker for Python
866+ - ** [ Contributor Covenant] ( https://www.contributor-covenant.org/ ) ** -- code of conduct framework
867+ - ** [ Keep a Changelog] ( https://keepachangelog.com/ ) ** -- changelog format standard
868+ - ** [ Shields.io] ( https://shields.io/ ) ** -- badge generation service
869+ - ** OWASP** and ** NIST** -- security standards referenced throughout
861870
862871<p align =" right " >(<a href =" #table-of-contents " >back to top</a >)</p >
863872
@@ -883,7 +892,7 @@ This software is intended for authorized systems administration, network securit
883892
884893- ** Documentation** : Start with the [ Wiki] ( wiki/ ) and [ USAGE_GUIDE.md] ( USAGE_GUIDE.md )
885894- ** Built-in Help** : Run ` python3 apotropaios.py COMMAND --help ` for any of the 18 commands
886- - ** Security Issues** : See [ SECURITY.md] ( SECURITY.md ) — use private reporting for critical vulnerabilities
895+ - ** Security Issues** : See [ SECURITY.md] ( SECURITY.md ) -- use private reporting for critical vulnerabilities
887896
888897** Diagnostic Commands:**
889898
@@ -901,7 +910,7 @@ make check-deps # Check all depend
901910
902911<p align =" center " >
903912
904- ** Apotropaios** — * Turning away evil since v1.0.0 *
913+ ** Apotropaios** -- * Turning away evil*
905914
906915Made with focus on security, reliability, and simplicity.
907916
0 commit comments