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.

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