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.

64 lines
1.7KB

  1. {% from "iptables/map.jinja" import service with context %}
  2. {%- for chain_name, chain in service.get('chain', {}).iteritems() %}
  3. iptables_{{ chain_name }}:
  4. iptables.chain_present:
  5. - family: ipv4
  6. - name: {{ chain_name }}
  7. - table: filter
  8. {%- if grains.ipv6|default(False) and service.ipv6|default(True) %}
  9. iptables_{{ chain_name }}_ipv6:
  10. iptables.chain_present:
  11. - family: ipv6
  12. - name: {{ chain_name }}
  13. - table: filter
  14. - require_in:
  15. - iptables: iptables_{{ chain_name }}_ipv6_policy
  16. {%- endif %}
  17. {%- if chain.policy is defined %}
  18. iptables_{{ chain_name }}_policy:
  19. iptables.set_policy:
  20. - family: ipv4
  21. - chain: {{ chain_name }}
  22. - policy: {{ chain.policy }}
  23. - table: filter
  24. - require:
  25. - iptables: iptables_{{ chain_name }}
  26. {%- if grains.ipv6|default(False) and service.ipv6|default(True) %}
  27. iptables_{{ chain_name }}_ipv6_policy:
  28. iptables.set_policy:
  29. - family: ipv6
  30. - chain: {{ chain_name }}
  31. - policy: {{ chain.policy }}
  32. - table: filter
  33. - require:
  34. - iptables: iptables_{{ chain_name }}_ipv6
  35. {%- endif %}
  36. {%- endif %}
  37. {%- for service_name, service in pillar.items() %}
  38. {%- if service.get('_support', {}).get('iptables', {}).get('enabled', False) %}
  39. {%- set grains_fragment_file = service_name+'/meta/iptables.yml' %}
  40. {%- macro load_grains_file() %}{% include grains_fragment_file %}{% endmacro %}
  41. {%- set grains_yaml = load_grains_file()|load_yaml %}
  42. {%- for rule in grains_yaml.iptables.rules %}
  43. {%- set rule_name = service_name+'_'+loop.index|string %}
  44. {% include "iptables/_rule.sls" %}
  45. {%- endfor %}
  46. {%- endif %}
  47. {%- endfor %}
  48. {%- for rule in chain.get('rules', []) %}
  49. {%- set rule_name = loop.index %}
  50. {% include "iptables/_rule.sls" %}
  51. {%- endfor %}
  52. {%- endfor %}