Saltstack Official FirewallD 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.

188 lines
6.7KB

  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 'forward' in zone %}
  126. {%- if zone.forward %}
  127. <forward/>
  128. {%- endif %}
  129. {%- endif %}
  130. {%- if 'masquerade' in zone %}
  131. {%- if zone.masquerade %}
  132. <masquerade/>
  133. {%- endif %}
  134. {%- endif %}
  135. {%- if 'forward_ports' in zone %}
  136. {%- for v in zone.forward_ports %}
  137. {%- if 'comment' in v %}
  138. <!-- {{ v.comment }} -->
  139. {%- endif %}
  140. <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 %} />
  141. {%- endfor %}
  142. {%- endif %}
  143. {%- if 'source_ports' in zone %}
  144. {%- for v in zone.source_ports %}
  145. {%- if 'comment' in v %}
  146. <!-- {{ v.comment }} -->
  147. {%- endif %}
  148. <source-port port="{{ v.port }}" protocol="{{ v.protocol }}" />
  149. {%- endfor %}
  150. {%- endif %}
  151. {%- if 'rich_rules' in zone %}
  152. {%- if zone.rich_rules is list %}
  153. {%- set rich_rules = zone.rich_rules %}
  154. {%- else %}
  155. {%- set expanded_ipset_rules = [] %}
  156. {%- for name,rule in zone.rich_rules|dictsort %}
  157. {%- if 'ipsets' in rule %}
  158. {%- for ipset in rule.ipsets %}
  159. {%- set tmp_rule = {} %}
  160. {%- set _dummy = tmp_rule.update(rule) %}
  161. {%- set _dummy = tmp_rule.update({'ipset':{'name':ipset}}) %}
  162. {%- set _dummy = expanded_ipset_rules.append(tmp_rule) %}
  163. {%- endfor %}
  164. {%- else %}
  165. {%- set _dummy = expanded_ipset_rules.append(rule) %}
  166. {%- endif %}
  167. {%- endfor %}
  168. {%- set rich_rules = [] %}
  169. {%- for rule in expanded_ipset_rules %}
  170. {%- if 'services' in rule %}
  171. {%- for service in rule.services %}
  172. {%- set tmp_rule = {} %}
  173. {%- set _dummy = tmp_rule.update(rule) %}
  174. {%- set _dummy = tmp_rule.update({'service':service}) %}
  175. {%- set _dummy = rich_rules.append(tmp_rule) %}
  176. {%- endfor %}
  177. {%- else %}
  178. {%- set _dummy = rich_rules.append(rule) %}
  179. {%- endif %}
  180. {%- endfor %}
  181. {%- endif %}
  182. {%- for rule in rich_rules %}
  183. {{- rich_rule(rule) }}
  184. {%- endfor %}
  185. {%- endif %}
  186. </zone>