Saltstack Official IPTables Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.0KB

  1. {% from "iptables/map.jinja" import service with context %}
  2. {%- if pillar.iptables.service.enabled %}
  3. iptables_packages:
  4. pkg.installed:
  5. - names: {{ service.pkgs }}
  6. iptables_services:
  7. service.dead:
  8. - enable: true
  9. - name: {{ service.service }}
  10. - sig: test -e /etc/iptables/rules.v4
  11. - require:
  12. - pkg: iptables_packages
  13. {%- for chain_name, chain in service.get('chain', {}).iteritems() %}
  14. {%- if chain.policy is defined %}
  15. iptables_{{ chain_name }}_policy:
  16. iptables.set_policy:
  17. - chain: {{ chain_name }}
  18. - policy: {{ chain.policy }}
  19. {%- endif %}
  20. {%- for rule_name, rule in chain.get('rule', {}).iteritems() %}
  21. iptables_{{ chain_name }}_{{ rule_name }}:
  22. iptables.insert:
  23. {%- if rule.position is defined %}
  24. - position: {{ rule.position }}
  25. {%- endif %}
  26. {%- if rule.table is defined %}
  27. - table: {{ rule.table }}
  28. {%- endif %}
  29. - chain: {{ chain_name }}
  30. {%- if rule.jump is defined %}
  31. - jump: {{ rule.jump }}
  32. {%- endif %}
  33. {%- if rule.match is defined %}
  34. - match: {{ rule.match }}
  35. {%- endif %}
  36. {%- if rule.connection_state is defined %}
  37. - connstate: {{ rule.connection_state }}
  38. {%- endif %}
  39. {%- if rule.protocol is defined %}
  40. - proto: {{ rule.protocol }}
  41. {%- endif %}
  42. {%- if rule.destination_port is defined %}
  43. - dport: {{ rule.destination_port }}
  44. {%- endif %}
  45. {%- if rule.source_port is defined %}
  46. - sport: {{ rule.source_port }}
  47. {%- endif %}
  48. {%- if rule.in_interface is defined %}
  49. - in-interface: {{ rule.in_interface }}
  50. {%- endif %}
  51. {%- if rule.out_interface is defined %}
  52. - out-interface: {{ rule.out_interface }}
  53. {%- endif %}
  54. {%- if rule.to_destination is defined %}
  55. - to-destination: {{ rule.to_destination }}
  56. {%- endif %}
  57. {%- if rule.source_network is defined %}
  58. - source: {{ rule.source_network }}
  59. {%- endif %}
  60. {%- if rule.destination_network is defined %}
  61. - destination: {{ rule.destination_network }}
  62. {%- endif %}
  63. - save: True
  64. {%- endfor %}
  65. {%- endfor %}
  66. {%- else %}
  67. iptables_services:
  68. service.dead:
  69. - enable: false
  70. - name: {{ service.service }}
  71. {%- endif %}