Saltstack Official OpenSSH Formula
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

233 lines
8.2KB

  1. {% from "openssh/map.jinja" import sshd_config with context %}
  2. {#- present in sshd_config and known in actual file options -#}
  3. {%- set processed_options = [] -%}
  4. {#- generic renderer used for sshd matches, known options, -#}
  5. {#- and unknown options -#}
  6. {%- macro render_option(keyword, config_dict=sshd_config) -%}
  7. {%- set value = config_dict.get(keyword) -%}
  8. {%- if value is sameas true -%}
  9. {{ keyword }} yes
  10. {% elif value is sameas false -%}
  11. {{ keyword }} no
  12. {% elif value is string or value is number -%}
  13. {{ keyword }} {{ value }}
  14. {% else -%}
  15. {%- for single_value in value -%}
  16. {{ keyword }} {{ single_value }}
  17. {% endfor -%}
  18. {%- endif -%}
  19. {%- endmacro -%}
  20. {#- macros for render option if present -#}
  21. {%- macro option(keyword, present) -%}
  22. {%- if keyword in sshd_config -%}
  23. {%- do processed_options.append(keyword) -%}
  24. {{ render_option(keyword) }}
  25. {%- endif -%}
  26. {%- endmacro -%}
  27. {#- macro for collapsing a list into a string -#}
  28. {%- macro option_collapselist(keyword, sep, config_dict=None) -%}
  29. {%- if config_dict is sameas None -%}
  30. {%- do processed_options.append(keyword) -%}
  31. {%- set config_dict = sshd_config -%}
  32. {%- endif -%}
  33. {{ keyword }} {{ config_dict.get(keyword) | join(sep) }}
  34. {% endmacro -%}
  35. {#- macro for handling an option that can be specified as a list or a string -#}
  36. {%- macro option_string_or_list(keyword, sep=',') -%}
  37. {%- if sshd_config.get(keyword, '') is string -%}
  38. {{ option(keyword) }}
  39. {%- else -%}
  40. {{ option_collapselist(keyword, sep) }}
  41. {%- endif -%}
  42. {%- endmacro -%}
  43. {#- macro for conditionally joining a string, list or dict(keys) to just a string -#}
  44. {%- macro join_to_string(src, keyword, sep=',') -%}
  45. {%- set srcval = src.get(keyword, '') -%}
  46. {%- if srcval is string -%}
  47. {{ srcval }}
  48. {%- elif srcval is mapping -%}
  49. {{ srcval.keys() | sort | join(sep) }}
  50. {%- else -%}
  51. {{ srcval | join(sep) }}
  52. {%- endif -%}
  53. {%- endmacro -%}
  54. {%- if sshd_config.get('ConfigBanner', False) -%}
  55. {%- do processed_options.append('ConfigBanner') -%}
  56. {{ sshd_config['ConfigBanner'] }}
  57. {%- else -%}
  58. # This file is managed by salt. Manual changes risk being overwritten.
  59. {%- endif %}
  60. {%- set global_src_url = salt ['pillar.get']('__formulas:print_template_url', None) %}
  61. {%- set local_src_url = salt ['pillar.get']('openssh-formula:print_template_url', None) %}
  62. {%- if (global_src_url and local_src_url is none) or local_src_url %}
  63. #
  64. # Template used to generate this file:
  65. # {{ source }}
  66. #
  67. {%- endif %}
  68. # The contents of the original sshd_config are kept on the bottom for
  69. # quick reference.
  70. # See the sshd_config(5) manpage for details
  71. {# Specifies which address family should be used by sshd(8). -#}
  72. {#- Valid arguments are any, inet (use IPv4 only), or inet6 (use IPv6 only) -#}
  73. {{- option('AddressFamily') -}}
  74. {#- What ports, IPs and protocols we listen for -#}
  75. {{- option('Port') -}}
  76. {#- Use these options to restrict which interfaces/protocols sshd will bind to -#}
  77. {{- option('ListenAddress') -}}
  78. {{- option('Protocol') -}}
  79. {#- HostKeys for protocol version 2 -#}
  80. {{- option('HostKey') -}}
  81. {#- Privilege Separation is turned on for security -#}
  82. {{- option('UsePrivilegeSeparation') -}}
  83. {#- Logging -#}
  84. {{- option('SyslogFacility') -}}
  85. {{- option('LogLevel') -}}
  86. {#- Session idle time out -#}
  87. {{- option('ClientAliveInterval') -}}
  88. {{- option('ClientAliveCountMax') -}}
  89. {#- Authentication: -#}
  90. {{- option('LoginGraceTime') -}}
  91. {{- option('PermitRootLogin') -}}
  92. {{- option('StrictModes') -}}
  93. {{- option('MaxAuthTries') -}}
  94. {{- option('MaxSessions') -}}
  95. {{- option('PubkeyAuthentication') -}}
  96. {{- option('AuthorizedKeysFile') -}}
  97. {{- option('AuthorizedKeysCommand') -}}
  98. {{- option('AuthorizedKeysCommandUser') -}}
  99. {#- Don't read the user's ~/.rhosts and ~/.shosts files -#}
  100. {{- option('IgnoreRhosts') -}}
  101. {#- similar for protocol version 2 -#}
  102. {{- option('HostbasedAuthentication') -}}
  103. {#- Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication -#}
  104. {{- option('IgnoreUserKnownHosts') -}}
  105. {#- To enable empty passwords, change to yes (NOT RECOMMENDED) -#}
  106. {{- option('PermitEmptyPasswords') -}}
  107. {#- Change to yes to enable challenge-response passwords (beware issues with -#}
  108. {#- some PAM modules and threads) -#}
  109. {{- option('ChallengeResponseAuthentication') -}}
  110. {{- option('AuthenticationMethods') -}}
  111. {#- Change to no to disable tunnelled clear text passwords -#}
  112. {{- option('PasswordAuthentication') -}}
  113. {#- Kerberos options -#}
  114. {{- option('KerberosAuthentication') -}}
  115. {{- option('KerberosGetAFSToken') -}}
  116. {{- option('KerberosOrLocalPasswd') -}}
  117. {{- option('KerberosTicketCleanup') -}}
  118. {#- GSSAPI options -#}
  119. {{- option('GSSAPIAuthentication') -}}
  120. {{- option('GSSAPICleanupCredentials') -}}
  121. {{- option('X11Forwarding') -}}
  122. {{- option('AllowTcpForwarding') -}}
  123. {{- option('X11DisplayOffset') -}}
  124. {{- option('PrintMotd') -}}
  125. {#- Bug in FreeBSD 10.3 (?) See https://lists.freebsd.org/pipermail/freebsd-stable/2016-April/084501.html -#}
  126. {% if not (salt['grains.get']('os') == 'FreeBSD' and salt['grains.get']('osrelease')|float >= 10.3) -%}
  127. {{- option('PrintLastLog') -}}
  128. {% endif -%}
  129. {{- option('TCPKeepAlive') -}}
  130. {{- option('UseLogin') -}}
  131. {{- option('MaxStartups') -}}
  132. {{- option('Banner') -}}
  133. {#- Allow client to pass locale environment variables -#}
  134. {{- option('AcceptEnv') -}}
  135. {{- option('Subsystem') -}}
  136. {% if not salt['grains.get']('os') == 'OpenBSD' -%}
  137. {#- Set this to 'yes' to enable PAM authentication, account processing, -#}
  138. {#- and session processing. If this is enabled, PAM authentication will -#}
  139. {#- be allowed through the ChallengeResponseAuthentication and -#}
  140. {#- PasswordAuthentication. Depending on your PAM configuration, -#}
  141. {#- PAM authentication via ChallengeResponseAuthentication may bypass -#}
  142. {#- the setting of "PermitRootLogin without-password". -#}
  143. {#- If you just want the PAM account and session checks to run without -#}
  144. {#- PAM authentication, then enable this but set PasswordAuthentication -#}
  145. {#- and ChallengeResponseAuthentication to 'no'. -#}
  146. {{- option('UsePAM') -}}
  147. {%- endif %}
  148. {#- DNS resolve and map remote IP addresses -#}
  149. {{- option('UseDNS') -}}
  150. {#- Restricting Users and Hosts -#}
  151. {#- example: -#}
  152. {#- AllowUsers vader@10.0.0.1 maul@sproing.evil.com luke -#}
  153. {#- AllowGroups wheel staff -#}
  154. {#- Keep in mind that using AllowUsers or AllowGroups means that anyone -#}
  155. {#- not Matching one of the supplied patterns will be denied access by default. -#}
  156. {#- Also, in order for sshd to allow access based on full or partial hostnames it -#}
  157. {#- needs to to a DNS lookup -#}
  158. {# DenyUsers -#}
  159. {{- option_string_or_list('DenyUsers', sep=' ') }}
  160. {# AllowUsers -#}
  161. {{- option_string_or_list('AllowUsers', sep=' ') }}
  162. {# DenyGroups -#}
  163. {{- option_string_or_list('DenyGroups', sep=' ') }}
  164. {# AllowGroups -#}
  165. {{- option_string_or_list('AllowGroups', sep=' ') }}{{ "\n" -}}
  166. {#- Specifies the available KEX (Key Exchange) algorithms. -#}
  167. {{- option_string_or_list('KexAlgorithms') -}}
  168. {#- Specifies the ciphers allowed for protocol version 2. -#}
  169. {{- option_string_or_list('Ciphers') -}}
  170. {#- Specifies the available MAC (message authentication code) algorithms. -#}
  171. {{- option_string_or_list('MACs') -}}
  172. {#- Handling unknown in salt template options -#}
  173. {%- for keyword in sshd_config.keys() %}
  174. {#- Matches have to be at the bottom and should be handled differently -#}
  175. {%- if not keyword in processed_options and keyword != 'matches' -%}
  176. {{- render_option(keyword) -}}
  177. {% endif -%}
  178. {%- endfor %}
  179. {#- Handle matches last as they need to go at the bottom -#}
  180. {%- if 'matches' in sshd_config %}
  181. {%- for name, match in sshd_config['matches']|dictsort(true) %}
  182. Match
  183. {#- Set up the match criteria -#}
  184. {%- for criteria in match['type'].keys()|sort() -%}
  185. {{ ' ' -}}{{criteria }} {{ join_to_string(match['type'], criteria) }}
  186. {%- endfor %} #{{- name }}
  187. {# Set up the applied options -#}
  188. {%- for keyword in match['options'].keys()|sort() -%}
  189. {%- if keyword in ['AllowUsers', 'DenyUsers', 'AllowGroups', 'DenyGroups'] -%}
  190. {{ option_collapselist(keyword, ' ', config_dict=match['options']) | indent(4, true) }}
  191. {% else -%}
  192. {{ render_option(keyword, config_dict=match['options']) | indent(4, true) }}
  193. {% endif -%}
  194. {%- endfor %}
  195. {%- endfor %}
  196. {%- endif %}
  197. {#- vim: set ft=jinja : -#}