Skip to main content

nftgen

ci

A small, nftables-only firewall-as-code generator: YAML definitions + host policies → one native .nft ruleset per host, applied with nft -f.

  • It mirrors nftables. Tables → chains → rules, sets, maps: you write your own chains, and the YAML reads like the ruleset it becomes.
  • Definitions (networks, services, interfaces) compose by name, per site; nftgen derives set types, splits rules per address family and keeps each port with its protocol.
  • Strict. Unknown keys, undefined names and values of the wrong shape fail the build; nothing is guessed, optimized or injected.
  • Deterministic. The same input gives the same bytes, so a diff of the output is a real rule change.
  • raw: reaches anything nft can do that has no key yet.

Example

# definitions/networks.yaml
networks:
  mgmt: [192.168.9.0/24, fd00:9::/64]
# definitions/services.yaml
services:
  ssh: [22/tcp]
# policies/hosts/gw1.yaml
tables:
  - family: inet
    name: filter
    chains:
      - name: input
        hook: input
        rules:
          - ct: [established, related]
            action: accept
          - saddr: mgmt
            proto: tcp
            dport: ssh
            action: accept

nftgen build . → generated/gw1.nft:

table inet filter {
    chain input {
        type filter hook input priority 0; policy drop;
        ct state established,related accept
        ip saddr 192.168.9.0/24 tcp dport 22 accept
        ip6 saddr fd00:9::/64 tcp dport 22 accept
    }
}

Use

pip install nftgen

nftgen build <root>                       # every host → <root>/generated/
nftgen build <root> --host gw1 --stdout   # one host to stdout, write nothing
nftgen build <root> --check               # also validate each file with nft -c

Each output is a complete file (flush ruleset + the host's tables) that ships as /etc/nftables.conf. With Ansible, the ansible-firewall collection renders from inventory variables instead and applies behind a rollback timer (DEPLOYMENT.md).

Docs

Develop

make install-dev   # .venv with nftgen (editable), linters, pre-commit hook
make verify        # lint + tests — put nft and ip on PATH, see docs/testing.md

License

MIT (see LICENSE). The definitions model reimplements concepts from Aerleon (Apache-2.0) clean-room — no Aerleon code is used; the acknowledgment is courtesy, not a license obligation.

Metadata

Release files for nftgen 1.0.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 nftgen 1.0.0
File Size Uploaded Provenance Actions
nftgen-1.0.0.tar.gz 106.8 kB With provenance Details for nftgen-1.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 147.7 kB

Release files / nftgen-1.0.0.tar.gz

Download URL nftgen-1.0.0.tar.gz
Size 106.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5bf55e6ded98eb2703b8b6839b7a51ec33a484cf17e8a1c4044f90501c7ef599
BLAKE2b-256 checksum
How to use checksums
b215497e11bc5d83c5bfccd3143bb92b10e58e51f8dd8001d1040d0c260b340c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

Release files / nftgen-1.0.0-py3-none-any.whl

Download URL nftgen-1.0.0-py3-none-any.whl
Size 40.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4978cf1f744f1af605cdd0ccea59f1a341d9f7268918fbd9acb990178edf5645
BLAKE2b-256 checksum
How to use checksums
b1093834182f0c4922d1856517da8a1d1a9d6ea9b56fbf60a3767ab8075e6035
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

Security for nftgen 1.0.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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nftgen-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

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.

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