ferm.conf.j2 2.7 KB

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