|
@@ -2,14 +2,24 @@
|
|
#
|
|
#
|
|
# /etc/nftables.conf - FFHO packet filter configuration
|
|
# /etc/nftables.conf - FFHO packet filter configuration
|
|
#
|
|
#
|
|
-{%- set roles = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
|
|
|
|
|
|
+{%- set node_config = salt['pillar.get']('nodes:' ~ grains['id']) %}
|
|
|
|
+{%- set nf_cc = node_config.get ('nftables', {}) %}
|
|
|
|
+{%- set roles = node_config.get ('roles', []) %}
|
|
|
|
+{%- set services = node_config.get ('services', []) %}
|
|
|
|
+
|
|
|
|
+{%- set fw_policy = salt['pillar.get']('firewall:policy', {}) %}
|
|
{%- set acls = salt['pillar.get']('firewall:acls') %}
|
|
{%- set acls = salt['pillar.get']('firewall:acls') %}
|
|
{%- set admin_access = salt['pillar.get']('firewall:admin_access') %}
|
|
{%- set admin_access = salt['pillar.get']('firewall:admin_access') %}
|
|
{%- set ssh = salt['pillar.get']("firewall:ssh") %}
|
|
{%- set ssh = salt['pillar.get']("firewall:ssh") %}
|
|
-{%- set services = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':services', []) %}
|
|
|
|
|
|
+
|
|
{%- set icinga2_queriers = salt['pillar.get']('monitoring:icinga2:queriers', []) %}
|
|
{%- set icinga2_queriers = salt['pillar.get']('monitoring:icinga2:queriers', []) %}
|
|
{%- set nms_list = salt['pillar.get']('globals:snmp:nms_list', []) %}
|
|
{%- set nms_list = salt['pillar.get']('globals:snmp:nms_list', []) %}
|
|
|
|
|
|
|
|
+{%- set forward = salt['ffho_netfilter.generate_forward_policy'](fw_policy, roles, nf_cc) %}
|
|
|
|
+{%- set nat_policy = salt['ffho_netfilter.generate_nat_policy'](roles, nf_cc) %}
|
|
|
|
+{%- set urpf = salt['ffho_netfilter.generate_urpf_policy'](node_config['ifaces']) %}
|
|
|
|
+{%- set allow_dhcp = salt['ffho_netfilter.allow_dhcp'](fw_policy, roles) %}
|
|
|
|
+
|
|
flush ruleset
|
|
flush ruleset
|
|
|
|
|
|
table ip filter {
|
|
table ip filter {
|
|
@@ -25,8 +35,11 @@ table ip filter {
|
|
chain input {
|
|
chain input {
|
|
type filter hook input priority 0; policy drop;
|
|
type filter hook input priority 0; policy drop;
|
|
iifname "lo" counter accept
|
|
iifname "lo" counter accept
|
|
- ip protocol icmp counter jump icmp_chain
|
|
|
|
|
|
+ udp dport 0 counter drop
|
|
tcp dport 7 counter drop comment "Ignore echo protocol queries"
|
|
tcp dport 7 counter drop comment "Ignore echo protocol queries"
|
|
|
|
+ udp dport 4789 jump vxlan
|
|
|
|
+ jump urpf
|
|
|
|
+ ip protocol icmp counter jump icmp_chain
|
|
ct state invalid counter drop
|
|
ct state invalid counter drop
|
|
counter jump admin_access
|
|
counter jump admin_access
|
|
counter jump monitoring
|
|
counter jump monitoring
|
|
@@ -37,11 +50,26 @@ table ip filter {
|
|
{%- endif %}
|
|
{%- endif %}
|
|
ct state related,established counter accept
|
|
ct state related,established counter accept
|
|
counter jump services
|
|
counter jump services
|
|
- limit rate 1/second burst 3 packets counter log prefix "netfilter: "
|
|
|
|
|
|
+ meta pkttype broadcast counter drop comment "Drop broadcasts before logging"
|
|
|
|
+ limit rate 1/second burst 3 packets counter log prefix "nf input: "
|
|
limit rate 1/second burst 3 packets counter reject with icmp type admin-prohibited
|
|
limit rate 1/second burst 3 packets counter reject with icmp type admin-prohibited
|
|
counter drop
|
|
counter drop
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ chain forward {
|
|
|
|
+ type filter hook forward priority 0; policy {{ forward['policy'] }}; # {{ forward['policy_reason'] }}
|
|
|
|
+ jump urpf
|
|
|
|
+{#- custom rules #}
|
|
|
|
+{%- for rule in forward['rules'].get ('4', []) %}
|
|
|
|
+ {{ rule }}
|
|
|
|
+{%- endfor %}
|
|
|
|
+
|
|
|
|
+{%- if forward['policy'] == 'drop' %}
|
|
|
|
+ limit rate 1/second burst 3 packets counter log prefix "nf forward: "
|
|
|
|
+ limit rate 1/second burst 3 packets counter reject with icmp type admin-prohibited
|
|
|
|
+{%- endif %}
|
|
|
|
+ }
|
|
|
|
+
|
|
chain icmp_chain {
|
|
chain icmp_chain {
|
|
icmp type { echo-request, destination-unreachable, time-exceeded } counter accept
|
|
icmp type { echo-request, destination-unreachable, time-exceeded } counter accept
|
|
}
|
|
}
|
|
@@ -77,11 +105,31 @@ table ip filter {
|
|
}
|
|
}
|
|
|
|
|
|
chain services {
|
|
chain services {
|
|
|
|
+{%- if allow_dhcp %}
|
|
|
|
+ udp dport 67 counter accept comment "DHCP"
|
|
|
|
+{%- endif %}
|
|
|
|
+
|
|
{%- for rule in salt['ffho_netfilter.generate_service_rules'](services, acls, 4) %}
|
|
{%- for rule in salt['ffho_netfilter.generate_service_rules'](services, acls, 4) %}
|
|
{{ rule }}
|
|
{{ rule }}
|
|
{%- endfor %}
|
|
{%- endfor %}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ chain urpf {
|
|
|
|
+{%- for iface_cfg in urpf %}
|
|
|
|
+ {%- for pfx in iface_cfg[4] %}
|
|
|
|
+ iif {{ iface_cfg['iface'] }} ip saddr {{ pfx }} return
|
|
|
|
+ {%- endfor %}
|
|
|
|
+ iif {{ iface_cfg['iface'] }} counter drop
|
|
|
|
+{%- endfor %}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ chain vxlan {
|
|
|
|
+{%- for iface in node_config['ifaces'] if node_config['ifaces'][iface].get ('batman_connect_sites') %}
|
|
|
|
+ iif {{ iface }} accept
|
|
|
|
+{%- endfor %}
|
|
|
|
+ counter drop
|
|
|
|
+ }
|
|
|
|
+
|
|
chain log-drop {
|
|
chain log-drop {
|
|
limit rate 1/second burst 3 packets counter log prefix "netfilter: "
|
|
limit rate 1/second burst 3 packets counter log prefix "netfilter: "
|
|
counter drop
|
|
counter drop
|
|
@@ -107,9 +155,11 @@ table ip6 filter {
|
|
chain input {
|
|
chain input {
|
|
type filter hook input priority 0; policy drop;
|
|
type filter hook input priority 0; policy drop;
|
|
iifname "lo" counter accept
|
|
iifname "lo" counter accept
|
|
- ip6 nexthdr icmpv6 counter jump icmp_chain
|
|
|
|
tcp dport 7 counter drop comment "Ignore echo protocol queries"
|
|
tcp dport 7 counter drop comment "Ignore echo protocol queries"
|
|
- ct state invalid counter drop comment "Drop packets that do not make sense."
|
|
|
|
|
|
+ udp dport 4789 jump vxlan
|
|
|
|
+ jump urpf
|
|
|
|
+ meta l4proto icmpv6 counter jump icmp_chain
|
|
|
|
+ ct state invalid counter drop
|
|
counter jump admin_access
|
|
counter jump admin_access
|
|
counter jump monitoring
|
|
counter jump monitoring
|
|
tcp dport 22 counter jump ssh
|
|
tcp dport 22 counter jump ssh
|
|
@@ -124,9 +174,24 @@ table ip6 filter {
|
|
counter drop
|
|
counter drop
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ chain forward {
|
|
|
|
+ type filter hook forward priority 0; policy {{ forward['policy'] }}; # {{ forward['policy_reason'] }}
|
|
|
|
+ jump urpf
|
|
|
|
+{#- custom rules #}
|
|
|
|
+{%- for rule in forward['rules'].get ('6', []) %}
|
|
|
|
+ {{ rule }}
|
|
|
|
+{%- endfor %}
|
|
|
|
+
|
|
|
|
+{%- if forward['policy'] == 'drop' %}
|
|
|
|
+ limit rate 1/second burst 3 packets counter log prefix "nf forward: "
|
|
|
|
+ limit rate 1/second burst 3 packets counter reject with icmp type admin-prohibited
|
|
|
|
+{%- endif %}
|
|
|
|
+ }
|
|
|
|
+
|
|
chain icmp_chain {
|
|
chain icmp_chain {
|
|
icmpv6 type { destination-unreachable, packet-too-big, time-exceeded, parameter-problem, echo-request, echo-reply } counter accept
|
|
icmpv6 type { destination-unreachable, packet-too-big, time-exceeded, parameter-problem, echo-request, echo-reply } counter accept
|
|
icmpv6 type { nd-router-solicit, nd-router-advert, nd-neighbor-solicit, nd-neighbor-advert, ind-neighbor-solicit, ind-neighbor-advert } ip6 hoplimit 255 counter accept
|
|
icmpv6 type { nd-router-solicit, nd-router-advert, nd-neighbor-solicit, nd-neighbor-advert, ind-neighbor-solicit, ind-neighbor-advert } ip6 hoplimit 255 counter accept
|
|
|
|
+ icmpv6 type { mld-listener-query, mld-listener-report } ip6 saddr fe80::/64 counter accept
|
|
}
|
|
}
|
|
|
|
|
|
chain admin_access {
|
|
chain admin_access {
|
|
@@ -163,6 +228,28 @@ table ip6 filter {
|
|
{%- for rule in salt['ffho_netfilter.generate_service_rules'](services, acls, 6) %}
|
|
{%- for rule in salt['ffho_netfilter.generate_service_rules'](services, acls, 6) %}
|
|
{{ rule }}
|
|
{{ rule }}
|
|
{%- endfor %}
|
|
{%- endfor %}
|
|
|
|
+
|
|
|
|
+{#- Allow respondd queries on gateways #}
|
|
|
|
+{%- if 'batman_gw' in roles %}
|
|
|
|
+ ip6 saddr fe80::/64 ip6 daddr ff05::2:1001 udp dport 1001 counter accept comment "responnd"
|
|
|
|
+{%- endif %}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ chain urpf {
|
|
|
|
+ ip6 saddr fe80::/64 return
|
|
|
|
+{%- for iface_cfg in urpf %}
|
|
|
|
+ {%- for pfx in iface_cfg[6] %}
|
|
|
|
+ iif {{ iface_cfg['iface'] }} ip6 saddr {{ pfx }} return
|
|
|
|
+ {%- endfor %}
|
|
|
|
+ iif {{ iface_cfg['iface'] }} counter drop
|
|
|
|
+{%- endfor %}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ chain vxlan {
|
|
|
|
+{%- for iface in node_config['ifaces'] if node_config['ifaces'][iface].get ('batman_connect_sites') %}
|
|
|
|
+ iif {{ iface }} accept
|
|
|
|
+{%- endfor %}
|
|
|
|
+ counter drop
|
|
}
|
|
}
|
|
|
|
|
|
chain log-drop {
|
|
chain log-drop {
|
|
@@ -176,3 +263,22 @@ table ip6 filter {
|
|
counter drop
|
|
counter drop
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+{#-
|
|
|
|
+ # NAT
|
|
|
|
+ #}
|
|
|
|
+{%- for af in [ 4, 6 ] %}
|
|
|
|
+ {%- if nat_policy[af] %}
|
|
|
|
+ {%- set af_name = "ip" if af == 4 else "ip6" %}
|
|
|
|
+table {{ af_name }} nat {
|
|
|
|
+ {%- for chain in ['output', 'prerouting', 'postrouting'] if chain in nat_policy[af] %}
|
|
|
|
+ chain {{ chain }} {
|
|
|
|
+ type nat hook {{ chain }} priority 0; policy accept;
|
|
|
|
+ {%- for rule in nat_policy[af][chain] %}
|
|
|
|
+ {{ rule }}
|
|
|
|
+ {%- endfor %}
|
|
|
|
+ }
|
|
|
|
+ {%- endfor %}
|
|
|
|
+}
|
|
|
|
+ {%- endif %}
|
|
|
|
+{%- endfor %}
|