Saltstack Official FirewallD Formula
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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