ferm.conf.j2 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. {% if ansible_controlled is defined and ansible_controlled != "" %}
  2. #
  3. # {{ ansible_controlled }}
  4. #
  5. {% endif %}
  6. #
  7. # Configuration file for ferm(1).
  8. #
  9. # Detecting network interface assiociated with default route
  10. {% if firewall_interface is defined and firewall_interface %}
  11. @def $NETDEV = {{ firewall_interface }};
  12. {% else %}
  13. @def $NETDEV = `ip route list | sed -r -n 's/^default\s+via\s+.*\s+dev\s+([a-z0-9]+).*$/\1/p'`;
  14. {% endif %}
  15. # Detecting list of bridge network interfaces
  16. @def $BRIDGES = `ip link show up | sed -r -n 's/^[0-9]+:\s+((xenbr|br|wg)[^:]+):\s+.*$/\1/p' | xargs`;
  17. # Default policies
  18. domain (ip ip6) {
  19. table filter {
  20. chain (INPUT FORWARD) policy DROP;
  21. chain OUTPUT policy ACCEPT;
  22. }
  23. }
  24. # Allow all on lo interface
  25. domain (ip ip6) table filter {
  26. chain INPUT interface lo ACCEPT;
  27. chain OUTPUT outerface lo ACCEPT;
  28. }
  29. # Allow ipv6 protocol specifics
  30. domain ip table filter chain (INPUT OUTPUT) protocol (ipv6 ipv6-icmp) ACCEPT;
  31. # Allow icmp-echo
  32. domain (ip ip6) table filter chain (INPUT OUTPUT) protocol icmp icmp-type echo-request ACCEPT;
  33. # Drop invalid packets
  34. domain (ip ip6) table filter chain INPUT mod state state INVALID DROP;
  35. # Established/related connections
  36. domain (ip ip6) table filter chain (INPUT OUTPUT) mod state state (ESTABLISHED RELATED) ACCEPT;
  37. domain (ip ip6) {
  38. table filter {
  39. chain INPUT {
  40. # standard ports we allow from the outside
  41. @if @not(@eq(@length(NETDEV),0)) {
  42. interface ($NETDEV) {
  43. proto (udp tcp) dport ({{ firewall_public | join(' ') }}) ACCEPT;
  44. }
  45. }
  46. {% if firewall_private is defined %}
  47. {% for fwconf in firewall_private %}
  48. interface {{ fwconf.interface }}{% if fwconf.networks is defined %} saddr ({{ fwconf.networks | join(' ') }}){% endif %} {
  49. proto (udp tcp) dport ({{ fwconf.ports | join(' ') }}) ACCEPT;
  50. }
  51. {% endfor %}
  52. {% endif %}
  53. {% if not firewall_debug %}#{% endif %}LOG log-prefix "ferm INPUT REJECT: " log-level warning;
  54. REJECT;
  55. }
  56. {% if firewall_private is defined %}
  57. chain OUTPUT {
  58. {% for fwconf in firewall_private %}
  59. {% if fwconf.users is defined %}
  60. outerface {{ fwconf.interface }} {
  61. mod owner uid-owner ({{ fwconf.users | join(' ') }}) ACCEPT;
  62. {% if not firewall_debug %}#{% endif %}LOG log-prefix "ferm OUTPUT REJECT: " log-level warning;
  63. REJECT;
  64. }
  65. {% endif %}
  66. {% endfor %}
  67. }
  68. {% endif %}
  69. chain FORWARD {
  70. @if @not(@eq(@length(BRIDGES),0)) {
  71. interface ($BRIDGES) {
  72. ACCEPT;
  73. }
  74. } @else {
  75. {% if not firewall_debug %}#{% endif %}LOG log-prefix "ferm FORWARD REJECT: " log-level warning;
  76. REJECT;
  77. }
  78. }
  79. }
  80. }