Saltstack Official IPTables Formula
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. {%- from "iptables/map.jinja" import defaults,service,tables with context %}
  2. {%- if service.v4.enabled -%}
  3. # Generated by salt v{{ grains['saltversion'] }}
  4. {%- if not defaults.v4.metadata_rules %}
  5. {%- for s_name, svc in pillar.items() %}
  6. {%- if svc is mapping %}
  7. {%- if svc.get('_support', {}).get('iptables', {}).get('enabled', False) %}
  8. {%- macro load_grains_file() %}{% include s_name + '/meta/iptables.yml' %}{% endmacro %}
  9. {%- set grains_yaml = load_grains_file()|load_yaml %}
  10. {%- if grains_yaml is iterable %}
  11. {%- set grains_tables = grains_yaml.get('iptables', {}).get('tables', {}).get('v4', {}) %}
  12. {%- if grains_tables is iterable %}
  13. {%- for gt_name, gt in grains_tables.items() %}
  14. {%- if gt_name not in tables.v4 %}
  15. {%- do tables.v4.update( { gt_name: gt } ) %}
  16. {%- else %}
  17. {%- for gc_name, gc in gt.chains.items() %}
  18. {%- set gt_obj = tables.v4.get(gt_name) %}
  19. {%- if gc_name not in gt_obj.chains %}
  20. {%- do gt_obj.chains.update( { gc_name: gc } ) %}
  21. {%- else %}
  22. {%- set gc_obj = gt_obj.chains.get(gc_name) %}
  23. {%- if gc.ruleset is defined %}
  24. {%- if gc_obj.ruleset is not defined %}
  25. {%- do gc_obj.update( { 'ruleset': {} } ) %}
  26. {%- endif %}
  27. {%- for grule_id, gr in gc.ruleset.items()|sort %}
  28. {%- if grule_id not in gc_obj.ruleset %}
  29. {%- do gc_obj.ruleset.update( { grule_id: gr } ) %}
  30. {%- endif %}
  31. {%- endfor %}
  32. {%- endif %}
  33. {%- endif %}
  34. {%- endfor %}
  35. {%- endif %}
  36. {%- endfor %}
  37. {%- endif %}
  38. {%- endif %}
  39. {%- endif %}
  40. {%- endif %}
  41. {%- endfor %}
  42. {%- endif %}
  43. {%- for t_name, t in tables.v4.items() %}
  44. *{{ t_name }}
  45. {%- for c_name, c in t.chains.items() %}
  46. {%- if c_name in ('INPUT','FORWARD','OUTPUT','PREROUTING','POSTROUTING') %}
  47. {%- set policy = c.get('policy', defaults.v4.policy) %}
  48. {%- else %}
  49. {%- set policy = "- [0:0]" %}
  50. {%- endif %}
  51. :{{ c_name }} {{ policy }}
  52. {%- endfor %}
  53. {%- for c_name, c in t.chains.items() %}
  54. {%- for rule_id, r in c.get('ruleset', {}).items()|sort %}
  55. {%- set rule = r.get('rule', defaults.v4.ruleset.rule) %}
  56. {%- set action = r.get('action', defaults.v4.ruleset.action) %}
  57. {%- set params = r.get('params', defaults.v4.ruleset.params) %}
  58. {%- if rule != "" %}
  59. {%- set rule = " " + rule %}
  60. {%- endif %}
  61. {%- if action != "" %}
  62. {%- set action = " -j " + action %}
  63. {%- endif %}
  64. {%- if params != "" %}
  65. {%- set params = " " + params %}
  66. {%- endif %}
  67. -A {{ c_name }}{{ rule }}{{ action }}{{ params }}
  68. {%- endfor %}
  69. {%- endfor %}
  70. COMMIT
  71. {%- endfor %}
  72. {%- endif %}