ferm.conf.j2 2.8 KB

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