nftables.conf.tmpl 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/usr/sbin/nft -f
  2. #
  3. # /etc/nftables.conf - FFHO packet filter configuration
  4. #
  5. {%- set roles = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
  6. {%- set acls = salt['pillar.get']('firewall:acls') %}
  7. {%- set admin_access = salt['pillar.get']('firewall:admin_access') %}
  8. {%- set ssh = salt['pillar.get']("firewall:ssh") %}
  9. {%- set services = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':services') %}
  10. {#- TODO: Get RR IPs from netbox #}
  11. {%- set bgp = { 4: { '10.132.255.1' : 'cr01.in.ffho.net',
  12. '10.132.255.2' : 'cr02.in.ffho.net',
  13. '10.132.255.3' : 'cr03.in.ffho.net', },
  14. 6: { '2a03:2260:2342:ffff::1' : 'cr01.in.ffho.net',
  15. '2a03:2260:2342:ffff::2' : 'cr02.in.ffho.net',
  16. '2a03:2260:2342:ffff::3' : 'cr03.in.ffho.net', }} %}
  17. flush ruleset
  18. table ip filter {
  19. chain input {
  20. type filter hook input priority 0; policy drop;
  21. iifname "lo" counter accept
  22. ip protocol icmp counter jump icmp_chain
  23. ct state invalid counter drop
  24. counter jump admin_access
  25. tcp dport 22 counter jump ssh
  26. {%- if 'router' in roles %}
  27. ip daddr { 224.0.0.5, 224.0.0.6 } meta l4proto ospf accept
  28. tcp dport 179 counter jump bgp
  29. {%- endif %}
  30. ct state related,established counter accept
  31. counter jump services
  32. limit rate 1/second burst 3 packets counter log prefix "netfilter: "
  33. limit rate 1/second burst 3 packets counter reject with icmp type admin-prohibited
  34. counter drop
  35. }
  36. chain icmp_chain {
  37. icmp type { echo-request, destination-unreachable, time-exceeded } counter accept
  38. }
  39. chain admin_access {
  40. {%- for pfx in admin_access[4].keys()|sort %}
  41. {%- set comment = admin_access[4][pfx] %}
  42. ip saddr {{ pfx }} counter accept comment "{{ comment }}"
  43. {%- endfor %}
  44. }
  45. {%- if 'router' in roles %}
  46. chain bgp {
  47. {%- for ip in bgp[4].keys()|sort %}
  48. {%- set comment = bgp[4][ip] %}
  49. ip saddr {{ ip }} counter accept comment "{{ comment }}"
  50. {%- endfor %}
  51. }
  52. {%- endif %}
  53. chain ssh {
  54. {%- for pfx in ssh[4].keys()|sort %}
  55. {%- set comment = ssh[4][pfx] %}
  56. ip saddr {{ pfx }} counter accept comment "{{ comment }}"
  57. {%- endfor %}
  58. }
  59. chain services {
  60. {%- for rule in salt['ffho_netfilter.generate_service_rules'](services, acls, 4) %}
  61. {{ rule }}
  62. {%- endfor %}
  63. }
  64. chain log-drop {
  65. limit rate 1/second burst 3 packets counter log prefix "netfilter: "
  66. counter drop
  67. }
  68. chain log-reject {
  69. limit rate 1/second burst 3 packets counter log prefix "netfilter: "
  70. limit rate 1/second burst 3 packets counter reject with icmp type admin-prohibited
  71. counter drop
  72. }
  73. }
  74. table ip6 filter {
  75. chain input {
  76. type filter hook input priority 0; policy drop;
  77. iifname "lo" counter accept
  78. ip6 nexthdr icmpv6 counter jump icmp_chain
  79. ct state invalid counter drop comment "Drop packets that do not make sense."
  80. counter jump admin_access
  81. tcp dport 22 counter jump ssh
  82. {%- if 'router' in roles %}
  83. ip6 saddr fe80::/64 ip6 daddr { ff02::5, ff02::6 } meta l4proto ospf accept
  84. tcp dport 179 counter jump bgp
  85. {%- endif %}
  86. ct state related,established counter accept comment "Allow established connections."
  87. counter jump services
  88. limit rate 1/second burst 3 packets counter log prefix "netfilter: "
  89. limit rate 1/second burst 3 packets counter reject with icmpv6 type admin-prohibited
  90. counter drop
  91. }
  92. chain icmp_chain {
  93. icmpv6 type { destination-unreachable, packet-too-big, time-exceeded, parameter-problem, echo-request, echo-reply } counter accept
  94. 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
  95. }
  96. chain admin_access {
  97. {%- for pfx in admin_access[6].keys()|sort %}
  98. {%- set comment = admin_access[6][pfx] %}
  99. ip6 saddr {{ pfx }} counter accept comment "{{ comment }}"
  100. {%- endfor %}
  101. }
  102. {%- if 'router' in roles %}
  103. chain bgp {
  104. {%- for ip in bgp[6].keys()|sort %}
  105. {%- set comment = bgp[6][ip] %}
  106. ip6 saddr {{ ip }} counter accept comment "{{ comment }}"
  107. {%- endfor %}
  108. }
  109. {%- endif %}
  110. chain ssh {
  111. {%- for pfx in ssh[6].keys()|sort %}
  112. {%- set comment = ssh[6][pfx] %}
  113. ip6 saddr {{ pfx }} counter accept comment "{{ comment }}"
  114. {%- endfor %}
  115. }
  116. chain services {
  117. {%- for rule in salt['ffho_netfilter.generate_service_rules'](services, acls, 6) %}
  118. {{ rule }}
  119. {%- endfor %}
  120. }
  121. chain log-drop {
  122. limit rate 1/second burst 3 packets counter log prefix "netfilter: "
  123. counter drop
  124. }
  125. chain log-reject {
  126. limit rate 1/second burst 3 packets counter log prefix "netfilter: "
  127. limit rate 1/second burst 3 packets counter reject with icmpv6 type admin-prohibited
  128. counter drop
  129. }
  130. }