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.

78 lines
1.9KB

  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. {%- for rule_name, rule in chain.get('rule', {}).iteritems() %}
  15. iptables_{{ chain_name }}_{{ rule_name }}:
  16. iptables.insert:
  17. {%- if rule.position is defined %}
  18. - position: {{ rule.position }}
  19. {%- endif %}
  20. {%- if rule.table is defined %}
  21. - table: {{ rule.table }}
  22. {%- endif %}
  23. - chain: {{ chain_name }}
  24. {%- if rule.jump is defined %}
  25. - jump: {{ rule.jump }}
  26. {%- endif %}
  27. {%- if rule.match is defined %}
  28. - match: {{ rule.match }}
  29. {%- endif %}
  30. {%- if rule.connection_state is defined %}
  31. - connstate: {{ rule.connection_state }}
  32. {%- endif %}
  33. {%- if rule.protocol is defined %}
  34. - proto: {{ rule.protocol }}
  35. {%- endif %}
  36. {%- if rule.destination_port is defined %}
  37. - dport: {{ rule.destination_port }}
  38. {%- endif %}
  39. {%- if rule.source_port is defined %}
  40. - sport: {{ rule.source_port }}
  41. {%- endif %}
  42. {%- if rule.in_interface is defined %}
  43. - in-interface: {{ rule.in_interface }}
  44. {%- endif %}
  45. {%- if rule.out_interface is defined %}
  46. - out-interface: {{ rule.out_interface }}
  47. {%- endif %}
  48. {%- if rule.to_destination is defined %}
  49. - to-destination: {{ rule.to_destination }}
  50. {%- endif %}
  51. {%- if rule.source_network is defined %}
  52. - source: {{ rule.source_network }}
  53. {%- endif %}
  54. {%- if rule.destination_network is defined %}
  55. - destination: {{ rule.destination_network }}
  56. {%- endif %}
  57. - save: True
  58. {%- endfor %}
  59. {%- endfor %}
  60. {%- else %}
  61. iptables_services:
  62. service.dead:
  63. - enable: false
  64. - name: {{ service.service }}
  65. {%- endif %}