Saltstack Official FirewallD Formula
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

183 Zeilen
6.6KB

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