Skip to content

Instantly share code, notes, and snippets.

View chpatton013's full-sized avatar

Christopher Patton chpatton013

View GitHub Profile
@chpatton013
chpatton013 / README.md
Created July 8, 2019 05:31
iptables template for router with stateful firewall

router iptables

The template iptables.sh.j2 is mostly derived from following this arch-wiki page on creating a stateful firewall, though I modified it a bit to reduce complexity. Their guide used four custom chains, but I think it's easier to reason about these rules by combining the first two of their custom chains and just eliminating the later two (leaving us with one).

Variables for the template (vars.yaml) are tracked as the Ansible vars file for the associated role. The variable router_root_dir is defined by inventory group_vars, and has a value of /opt/router.

The file iptables.sh is generated by running Jinja2 against the template iptables.sh.j2 with the variables defined in vars.yaml.

The file rules.v4 is generated by running iptables-converter -s iptables.sh.

[
["f", "Show next/latest diffs", "setProposedDiffBounds()"],
[null, "Next unreviewed file", "nextUnreviewedFile()"],
[null, "Previous unreviewed file", "prevUnreviewedFile()"],
["n", "Next personally unreviewed file", "nextPersonallyUnreviewedFile()"],
["p", "Previous personally unreviewed file", "prevPersonallyUnreviewedFile()"],
["shift+n", "Next changed file", "nextChangedFile()"],
["shift+p", "Previous changed file", "prevChangedFile()"],
[null, "Next visible file", "nextVisibleFile()"],