Saltstack Official IPTables Formula
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

72 lines
2.0KB

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