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.

71 lines
1.9KB

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