Saltstack Official IPTables Formula
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

89 linhas
2.1KB

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