Saltstack Official FirewallD Formula
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

190 lines
6.5KB

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. This file is managed/generated by salt.
  4. Do not edit this file manually, it will be overwritten!
  5. Modify the salt pillar for firewalld instead
  6. -->
  7. <zone{%- if 'target' in zone %} target="{{ zone.target }}"{%- endif %}>
  8. {% if 'short' in zone %}<short>{{ zone.short }}</short>{% else %}<short>{{ name }}</short>{% endif %}
  9. {% if 'description' in zone %}<description>{{ zone.description }}</description>{% endif %}
  10. {%- if 'interfaces' in zone %}
  11. {%- for v in zone.interfaces %}
  12. <interface name="{{ v }}" />
  13. {%- endfor %}
  14. {%- endif %}
  15. {%- if 'sources' in zone %}
  16. {%- for v in zone.sources %}
  17. {%- if 'comment' in v %}
  18. <!-- {{ v.comment }} -->
  19. <source address="{{ v.source }}" />
  20. {%- else %}
  21. <source address="{{ v }}" />
  22. {%- endif %}
  23. {%- endfor %}
  24. {%- endif %}
  25. {%- if 'ipsets' in zone %}
  26. {%- for v in zone.ipsets %}
  27. {%- if 'comment' in v %}
  28. <!-- {{ v.comment }} -->
  29. <source ipset="{{ v.ipset }}" />
  30. {%- else %}
  31. <source ipset="{{ v }}" />
  32. {%- endif %}
  33. {%- endfor %}
  34. {%- endif %}
  35. {%- for k,val in zone.items() %}
  36. {%- if k.endswith("services") %}
  37. {%- for v in val %}
  38. <service name="{{ v }}" />
  39. {%- endfor %}
  40. {%- endif %}
  41. {%- endfor %}
  42. {%- if 'ports' in zone %}
  43. {%- for v in zone.ports %}
  44. {%- if 'comment' in v %}
  45. <!-- {{ v.comment }} -->
  46. {%- endif %}
  47. <port port="{{ v.port }}" protocol="{{ v.protocol }}" />
  48. {%- endfor %}
  49. {%- endif %}
  50. {%- if 'protocols' in zone %}
  51. {%- for v in zone.protocols %}
  52. <protocol value="{{ v }}" />
  53. {%- endfor %}
  54. {%- endif %}
  55. {%- if 'icmp_blocks' in zone %}
  56. {%- for v in zone.icmp_blocks %}
  57. <icmp-block name="{{ v }}" />
  58. {%- endfor %}
  59. {%- endif %}
  60. {%- if 'icmp_block_inversion' in zone and zone.icmp_block_inversion %}
  61. <icmp-block-inversion />
  62. {%- endif %}
  63. {%- if 'masquerade' in zone %}
  64. {%- if zone.masquerade %}
  65. <masquerade/>
  66. {%- endif %}
  67. {%- endif %}
  68. {%- if 'forward_ports' in zone %}
  69. {%- for v in zone.forward_ports %}
  70. {%- if 'comment' in v %}
  71. <!-- {{ v.comment }} -->
  72. {%- endif %}
  73. <forward-port port="{{ v.portid }}" protocol="{{ v.protocol }}"{%- if 'to_port' in v %} to-port="{{ v.to_port }}"{%- endif %}{%- if 'to_addr' in v %} to-addr="{{ v.to_addr }}"{%- endif %} />
  74. {%- endfor %}
  75. {%- endif %}
  76. {%- if 'source_ports' in zone %}
  77. {%- for v in zone.source_ports %}
  78. {%- if 'comment' in v %}
  79. <!-- {{ v.comment }} -->
  80. {%- endif %}
  81. <source-port port="{{ v.port }}" protocol="{{ v.protocol }}" />
  82. {%- endfor %}
  83. {%- endif %}
  84. {%- macro rich_rule(rule) -%}
  85. {%- if 'family' in rule %}
  86. <rule family="{{ rule.family }}">
  87. {%- else %}
  88. <rule>
  89. {%- endif %}
  90. {%- if 'ipset' in rule %}
  91. <source ipset="{{ rule.ipset.name }}" />
  92. {%- endif %}
  93. {%- if 'source' in rule %}
  94. <source address="{{ rule.source.address }}" {%- if 'invert' in rule.source %}invert="{{ rule.source.invert }}"{%- endif %} />
  95. {%- endif %}
  96. {%- if 'destination' in rule %}
  97. <destination address="{{ rule.destination.address }}" {%- if 'invert' in rule.destination %}invert="{{ rule.destination.invert }}"{%- endif %} />
  98. {%- endif %}
  99. {%- if 'service' in rule %}
  100. <service name="{{ rule.service }}" />
  101. {%- endif %}
  102. {%- if 'port' in rule %}
  103. <port port="{{ rule.port.portid }}" protocol="{{ rule.port.protocol }}" />
  104. {%- endif %}
  105. {%- if 'protocol' in rule %}
  106. <protocol value="{{ rule.protocol }}" />
  107. {%- endif %}
  108. {%- if 'icmp_block' in rule %}
  109. <icmp-block name="{{ rule.icmp_block }}" />
  110. {%- endif %}
  111. {%- if 'icmp_type' in rule %}
  112. <icmp-type name="{{ rule.icmp_type }}" />
  113. {%- endif %}
  114. {%- if 'masquerade' in rule %}
  115. {%- if rule.masquerade %}<masquerade/>{%- endif %}
  116. {%- endif %}
  117. {%- if 'forward_port' in rule %}
  118. {%- if 'comment' in rule.forward_port %}
  119. <!-- {{ rule.forward_port.comment }} -->
  120. {%- endif %}
  121. <forward-port port="{{ rule.forward_port.portid }}" protocol="{{ rule.forward_port.protocol }}"{%- if 'to_port' in rule.forward_port %} to-port="{{ rule.forward_port.to_port }}"{%- endif %}{%- if 'to_addr' in rule.forward_port %} to-addr="{{ rule.forward_port.to_addr }}"{%- endif %} />
  122. {%- endif %}
  123. {%- if 'source_port' in rule %}
  124. {%- if 'comment' in rule.source_port %}
  125. <!-- {{ rule.source_port.comment }} -->
  126. {%- endif %}
  127. <source-port port="{{ rule.source_port.portid }}" protocol="{{ rule.source_port.protocol }}"{%- if 'to_port' in rule.source_port %} to-port="{{ rule.source_port.to_port }}"{%- endif %}{%- if 'to_addr' in rule.source_port %} to-addr="{{ rule.source_port.to_addr }}"{%- endif %} />
  128. {%- endif %}
  129. {%- if 'log' in rule %}
  130. <log{%- if 'prefix' in rule.log %} prefix="{{ rule.log.prefix }}"{%- endif %}{%- if 'level' in rule.log %} level="{{ rule.log.level }}"{%- endif %}>
  131. {%- if 'limit' in rule.log %}
  132. <limit value="{{ rule.log.limit }}"/>
  133. {%- endif %}
  134. </log>
  135. {%- endif %}
  136. {%- if 'audit' in rule %}
  137. <audit>{%- if 'limit' in rule.audit %} <limit value="{{ rule.audit.limit }}"/>{%- endif %}</audit>
  138. {%- endif %}
  139. {%- if 'accept' in rule %}
  140. <accept/>
  141. {%- endif %}
  142. {%- if 'reject' in rule %}
  143. <reject{%- if 'type' in rule.reject %} type="{{ rule.reject.type }}"{%- endif %} />
  144. {%- endif %}
  145. {%- if 'drop' in rule %}
  146. <drop/>
  147. {%- endif %}
  148. </rule>
  149. {%- endmacro %}
  150. {%- if 'rich_rules' in zone %}
  151. {%- if zone.rich_rules is list %}
  152. {%- set rich_rules = zone.rich_rules %}
  153. {%- else %}
  154. {%- set expanded_ipset_rules = [] %}
  155. {%- for name,rule in zone.rich_rules|dictsort %}
  156. {%- if 'ipsets' in rule %}
  157. {%- for ipset in rule.ipsets %}
  158. {%- set tmp_rule = {} %}
  159. {%- set _dummy = tmp_rule.update(rule) %}
  160. {%- set _dummy = tmp_rule.update({'ipset':{'name':ipset}}) %}
  161. {%- set _dummy = expanded_ipset_rules.append(tmp_rule) %}
  162. {%- endfor %}
  163. {%- else %}
  164. {%- set _dummy = expanded_ipset_rules.append(rule) %}
  165. {%- endif %}
  166. {%- endfor %}
  167. {%- set rich_rules = [] %}
  168. {%- for rule in expanded_ipset_rules %}
  169. {%- if 'services' in rule %}
  170. {%- for service in rule.services %}
  171. {%- set tmp_rule = {} %}
  172. {%- set _dummy = tmp_rule.update(rule) %}
  173. {%- set _dummy = tmp_rule.update({'service':service}) %}
  174. {%- set _dummy = rich_rules.append(tmp_rule) %}
  175. {%- endfor %}
  176. {%- else %}
  177. {%- set _dummy = rich_rules.append(rule) %}
  178. {%- endif %}
  179. {%- endfor %}
  180. {%- endif %}
  181. {%- for rule in rich_rules %}
  182. {{ rich_rule(rule) }}
  183. {%- endfor %}
  184. {%- endif %}
  185. </zone>