From 6ef6aa8d628b0c7eeeec37d0c5b43df6d87f8b33 Mon Sep 17 00:00:00 2001 From: Niklas Yann Wettengel Date: Wed, 12 Jul 2017 00:49:47 +0200 Subject: iptables: use template --- roles/configure_iptables/files/ip6tables.rules | 43 ------------------- roles/configure_iptables/files/iptables.rules | 50 ---------------------- roles/configure_iptables/tasks/main.yml | 4 +- roles/configure_iptables/templates/ip6tables.rules | 37 ++++++++++++++++ roles/configure_iptables/templates/iptables.rules | 44 +++++++++++++++++++ 5 files changed, 83 insertions(+), 95 deletions(-) delete mode 100644 roles/configure_iptables/files/ip6tables.rules delete mode 100644 roles/configure_iptables/files/iptables.rules create mode 100644 roles/configure_iptables/templates/ip6tables.rules create mode 100644 roles/configure_iptables/templates/iptables.rules diff --git a/roles/configure_iptables/files/ip6tables.rules b/roles/configure_iptables/files/ip6tables.rules deleted file mode 100644 index 764e05b..0000000 --- a/roles/configure_iptables/files/ip6tables.rules +++ /dev/null @@ -1,43 +0,0 @@ -*filter -:INPUT DROP [0:0] -:FORWARD DROP [0:0] -:OUTPUT ACCEPT [0:0] --A INPUT -i lo -j ACCEPT --A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT --A INPUT -p icmpv6 -j ACCEPT - -# SSH-Server --A INPUT -p tcp -m tcp --dport 22 -j ACCEPT -# dns --A INPUT -p tcp -m tcp --dport 53 -j ACCEPT --A INPUT -p udp -m udp --dport 53 -j ACCEPT -# ntp --A INPUT -p udp -m udp --dport 123 -j ACCEPT -# fastd --A INPUT -p udp -m udp --dport 10010:10021 -j ACCEPT -# wireguard_mesh --A INPUT -p udp -m udp --dport 10110 -j ACCEPT --A INPUT -p udp -m udp --dport 10112 -j ACCEPT --A INPUT -p udp -m udp --dport 10114 -j ACCEPT --A INPUT -p udp -m udp --dport 10116 -j ACCEPT --A INPUT -p udp -m udp --dport 10118 -j ACCEPT --A INPUT -p udp -m udp --dport 10120 -j ACCEPT --A INPUT -s fdff:4157:bb::/48 -p gre -j ACCEPT --A INPUT -s fdff:434f:43bb::/48 -p gre -j ACCEPT --A INPUT -s fdff:454d:53bb::/48 -p gre -j ACCEPT --A INPUT -s fdff:4b4f:bb::/48 -p gre -j ACCEPT --A INPUT -s fdff:4d59:bb::/48 -p gre -j ACCEPT --A INPUT -s fdff:5349:4dbb::/48 -p gre -j ACCEPT -# MOSH --A INPUT -p udp -m udp --dport 60000:61000 -j ACCEPT -# LOG --A INPUT -m limit --limit 2/min -j LOG --log-prefix "IP6Tables-Dropped input: " --log-level 4 - --A FORWARD -i bataw -p udp --dport 10010:10021 -j REJECT --A FORWARD -i batcoc -p udp --dport 10010:10021 -j REJECT --A FORWARD -i batems -p udp --dport 10010:10021 -j REJECT --A FORWARD -i batko -p udp --dport 10010:10021 -j REJECT --A FORWARD -i batmy -p udp --dport 10010:10021 -j REJECT --A FORWARD -i batsim -p udp --dport 10010:10021 -j REJECT --A FORWARD -m limit --limit 2/min -j LOG --log-prefix "IP6Tables-Dropped forward: " --log-level 4 -COMMIT diff --git a/roles/configure_iptables/files/iptables.rules b/roles/configure_iptables/files/iptables.rules deleted file mode 100644 index 24b82e3..0000000 --- a/roles/configure_iptables/files/iptables.rules +++ /dev/null @@ -1,50 +0,0 @@ -*mangle -:PREROUTING ACCEPT [0:0] -:INPUT ACCEPT [0:0] -:FORWARD ACCEPT [0:0] -:OUTPUT ACCEPT [0:0] -:POSTROUTING ACCEPT [0:0] --A PREROUTING -i bataw -j MARK --set-xmark 0x1/0xffffffff --A PREROUTING -i batcoc -j MARK --set-xmark 0x1/0xffffffff --A PREROUTING -i batems -j MARK --set-xmark 0x1/0xffffffff --A PREROUTING -i batko -j MARK --set-xmark 0x1/0xffffffff --A PREROUTING -i batmy -j MARK --set-xmark 0x1/0xffffffff --A PREROUTING -i batsim -j MARK --set-xmark 0x1/0xffffffff -COMMIT -*filter -:INPUT DROP [0:0] -:FORWARD DROP [0:0] -:OUTPUT ACCEPT [0:0] --A INPUT -s 127.0.0.1/32 -j ACCEPT --A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT --A INPUT -p icmp -j ACCEPT - -# SSH-Server --A INPUT -p tcp -m tcp --dport 22 -j ACCEPT -# dns --A INPUT -p tcp -m tcp --dport 53 -j ACCEPT --A INPUT -p udp -m udp --dport 53 -j ACCEPT -#dhcp --I INPUT -i bat0 -p udp --dport 67:68 --sport 67:68 -j ACCEPT -# ntp --A INPUT -p udp -m udp --dport 123 -j ACCEPT -# fastd --A INPUT -p udp -m udp --dport 10010:10021 -j ACCEPT -# MOSH --A INPUT -p udp -m udp --dport 60000:61000 -j ACCEPT --A INPUT -m limit --limit 2/min -j LOG --log-prefix "IPTables-Dropped input: " --log-level 4 - --A FORWARD -i bataw -p udp --dport 10010:10021 -j REJECT --A FORWARD -i batcoc -p udp --dport 10010:10021 -j REJECT --A FORWARD -i batems -p udp --dport 10010:10021 -j REJECT --A FORWARD -i batko -p udp --dport 10010:10021 -j REJECT --A FORWARD -i batmy -p udp --dport 10010:10021 -j REJECT --A FORWARD -i batsim -p udp --dport 10010:10021 -j REJECT --A FORWARD -m limit --limit 2/min -j LOG --log-prefix "IPTables-Dropped forward: " --log-level 4 -COMMIT -*nat -:PREROUTING ACCEPT [0:0] -:INPUT ACCEPT [0:0] -:OUTPUT ACCEPT [0:0] -:POSTROUTING ACCEPT [0:0] -COMMIT diff --git a/roles/configure_iptables/tasks/main.yml b/roles/configure_iptables/tasks/main.yml index e0e6625..846eefe 100644 --- a/roles/configure_iptables/tasks/main.yml +++ b/roles/configure_iptables/tasks/main.yml @@ -1,6 +1,6 @@ --- - name: copy iptables.rules - copy: + template: src: iptables.rules dest: /etc/iptables/iptables.rules notify: reload iptables @@ -12,7 +12,7 @@ state: started - name: copy ip6tables.rules - copy: + template: src: ip6tables.rules dest: /etc/iptables/ip6tables.rules notify: reload ip6tables diff --git a/roles/configure_iptables/templates/ip6tables.rules b/roles/configure_iptables/templates/ip6tables.rules new file mode 100644 index 0000000..3ae179f --- /dev/null +++ b/roles/configure_iptables/templates/ip6tables.rules @@ -0,0 +1,37 @@ +*filter +:INPUT DROP [0:0] +:FORWARD DROP [0:0] +:OUTPUT ACCEPT [0:0] +-A INPUT -i lo -j ACCEPT +-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT +-A INPUT -p icmpv6 -j ACCEPT + +# SSH-Server +-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT +# dns +-A INPUT -p tcp -m tcp --dport 53 -j ACCEPT +-A INPUT -p udp -m udp --dport 53 -j ACCEPT +# ntp +-A INPUT -p udp -m udp --dport 123 -j ACCEPT +# fastd +-A INPUT -p udp -m udp --dport 10010:10021 -j ACCEPT +# wireguard_mesh +{% for site in sites %} +-A INPUT -p udp -m udp --dport {{ site.wireguard_mesh_port }} -j ACCEPT +-A INPUT -s {{ site.wireguard_mesh_address }}/48 -p gre -j ACCEPT +{% endfor %} +# wireguard_backbone +-A INPUT -s fdff:4d59:4bbb::/48 -p gre -j ACCEPT +{% for peer in wireguard_bb_peers %} +-A INPUT -i bb{{ peer.name }} -p udp --dport 6696 -j ACCEPT +{% endfor %} +# MOSH +-A INPUT -p udp -m udp --dport 60000:61000 -j ACCEPT +# LOG +-A INPUT -m limit --limit 2/min -j LOG --log-prefix "IP6Tables-Dropped input: " --log-level 4 + +{% for site in sites %} +-A FORWARD -i bat{{ site.name }} -p udp --dport 10010:10021 -j REJECT +{% endfor %} +-A FORWARD -m limit --limit 2/min -j LOG --log-prefix "IP6Tables-Dropped forward: " --log-level 4 +COMMIT diff --git a/roles/configure_iptables/templates/iptables.rules b/roles/configure_iptables/templates/iptables.rules new file mode 100644 index 0000000..2ae5610 --- /dev/null +++ b/roles/configure_iptables/templates/iptables.rules @@ -0,0 +1,44 @@ +*mangle +:PREROUTING ACCEPT [0:0] +:INPUT ACCEPT [0:0] +:FORWARD ACCEPT [0:0] +:OUTPUT ACCEPT [0:0] +:POSTROUTING ACCEPT [0:0] +{% for site in sites %} +-A PREROUTING -i bat{{ site.name }} -j MARK --set-xmark 0x1/0xffffffff +{% endfor %} +COMMIT +*filter +:INPUT DROP [0:0] +:FORWARD DROP [0:0] +:OUTPUT ACCEPT [0:0] +-A INPUT -s 127.0.0.1/32 -j ACCEPT +-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT +-A INPUT -p icmp -j ACCEPT + +# SSH-Server +-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT +# dns +-A INPUT -p tcp -m tcp --dport 53 -j ACCEPT +-A INPUT -p udp -m udp --dport 53 -j ACCEPT +#dhcp +-I INPUT -i bat0 -p udp --dport 67:68 --sport 67:68 -j ACCEPT +# ntp +-A INPUT -p udp -m udp --dport 123 -j ACCEPT +# fastd +-A INPUT -p udp -m udp --dport 10010:10021 -j ACCEPT +# MOSH +-A INPUT -p udp -m udp --dport 60000:61000 -j ACCEPT +-A INPUT -m limit --limit 2/min -j LOG --log-prefix "IPTables-Dropped input: " --log-level 4 + +{% for site in sites %} +-A FORWARD -i bat{{ site.name }} -p udp --dport 10010:10021 -j REJECT +{% endfor %} +-A FORWARD -m limit --limit 2/min -j LOG --log-prefix "IPTables-Dropped forward: " --log-level 4 +COMMIT +*nat +:PREROUTING ACCEPT [0:0] +:INPUT ACCEPT [0:0] +:OUTPUT ACCEPT [0:0] +:POSTROUTING ACCEPT [0:0] +COMMIT -- cgit v1.2.3-54-g00ecf