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

193 lines
7.8KB

  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, default, config_dict=sshd_config) -%}
  7. {%- set value = config_dict.get(keyword, default) -%}
  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 according to present -#}
  21. {%- macro option_impl(keyword, default, present) -%}
  22. {%- if present -%}
  23. {%- do processed_options.append(keyword) -%}
  24. {%- set prefix='' -%}
  25. {%- else -%}
  26. {%- set prefix='#' -%}
  27. {%- endif -%}
  28. {#- add prefix to keyword -#}
  29. {%- set keyword = prefix ~ keyword -%}
  30. {{ render_option(keyword, default) }}
  31. {%- endmacro -%}
  32. {#- macros for render option commented by default -#}
  33. {%- macro option(keyword, default, present) -%}
  34. {{ option_impl(keyword, default, keyword in sshd_config) }}
  35. {%- endmacro -%}
  36. {#- macros for render option uncommented by default -#}
  37. {%- macro option_default_uncommented(keyword, default, present) -%}
  38. {{ option_impl(keyword, default, True) }}
  39. {%- endmacro -%}
  40. # This file is managed by salt. Manual changes risk being overwritten.
  41. # The contents of the original sshd_config are kept on the bottom for
  42. # quick reference.
  43. # See the sshd_config(5) manpage for details
  44. # What ports, IPs and protocols we listen for
  45. {{ option('Port', 22) }}
  46. # Use these options to restrict which interfaces/protocols sshd will bind to
  47. {{ option('ListenAddress', ['::', '0.0.0.0']) }}
  48. {{ option_default_uncommented('Protocol', 2) }}
  49. # HostKeys for protocol version 2
  50. {{ option_default_uncommented('HostKey', ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_dsa_key', '/etc/ssh/ssh_host_ecdsa_key', '/etc/ssh/ssh_host_ed25519_key']) -}}
  51. #Privilege Separation is turned on for security
  52. {{ option_default_uncommented('UsePrivilegeSeparation', 'yes') }}
  53. # Lifetime and size of ephemeral version 1 server key
  54. {{ option_default_uncommented('KeyRegenerationInterval', 3600) }}
  55. {{ option_default_uncommented('ServerKeyBits', 1024) }}
  56. # Logging
  57. {{ option_default_uncommented('SyslogFacility', 'AUTH') }}
  58. {{ option_default_uncommented('LogLevel', 'INFO') }}
  59. # Session idle time out
  60. {{ option_default_uncommented('ClientAliveInterval', 0) }}
  61. {{ option_default_uncommented('ClientAliveCountMax', 3) }}
  62. # Authentication:
  63. {{ option_default_uncommented('LoginGraceTime', 120) }}
  64. {{ option_default_uncommented('PermitRootLogin', 'yes') }}
  65. {{ option_default_uncommented('StrictModes', 'yes') }}
  66. {{ option_default_uncommented('MaxAuthTries', '6') }}
  67. {{ option_default_uncommented('MaxSessions', '10') }}
  68. {{ option('DSAAuthentication', 'yes') }}
  69. {{ option_default_uncommented('RSAAuthentication', 'yes') }}
  70. {{ option_default_uncommented('PubkeyAuthentication', 'yes') }}
  71. {{ option('AuthorizedKeysFile', '%h/.ssh/authorized_keys') }}
  72. {{ option('AuthorizedKeysCommand', 'none') }}
  73. {{ option('AuthorizedKeysCommandUser', 'nobody') }}
  74. # Don't read the user's ~/.rhosts and ~/.shosts files
  75. {{ option_default_uncommented('IgnoreRhosts', 'yes') }}
  76. # For this to work you will also need host keys in /etc/ssh_known_hosts
  77. {{ option_default_uncommented('RhostsRSAAuthentication', 'no') }}
  78. # similar for protocol version 2
  79. {{ option_default_uncommented('HostbasedAuthentication', 'no') }}
  80. # Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
  81. {{ option('IgnoreUserKnownHosts', 'yes') }}
  82. # To enable empty passwords, change to yes (NOT RECOMMENDED)
  83. {{ option_default_uncommented('PermitEmptyPasswords', 'no') }}
  84. # Change to yes to enable challenge-response passwords (beware issues with
  85. # some PAM modules and threads)
  86. {{ option_default_uncommented('ChallengeResponseAuthentication', 'no') }}
  87. {{ option('AuthenticationMethods', 'publickey,keyboard-interactive') }}
  88. # Change to no to disable tunnelled clear text passwords
  89. {{ option('PasswordAuthentication', 'yes') }}
  90. # Kerberos options
  91. {{ option('KerberosAuthentication', 'no') }}
  92. {{ option('KerberosGetAFSToken', 'no') }}
  93. {{ option('KerberosOrLocalPasswd', 'yes') }}
  94. {{ option('KerberosTicketCleanup', 'yes') }}
  95. # GSSAPI options
  96. {{ option('GSSAPIAuthentication', 'no') }}
  97. {{ option('GSSAPICleanupCredentials', 'yes') }}
  98. {{ option_default_uncommented('X11Forwarding', 'yes') }}
  99. {{ option('AllowTcpForwarding', 'yes') }}
  100. {{ option_default_uncommented('X11DisplayOffset', '10') }}
  101. {{ option_default_uncommented('PrintMotd', 'no') }}
  102. {{ option_default_uncommented('PrintLastLog', 'yes') }}
  103. {{ option_default_uncommented('TCPKeepAlive', 'yes') }}
  104. {{ option('UseLogin', 'no') }}
  105. {{ option('MaxStartups', '10:30:60') }}
  106. {{ option('Banner', '/etc/issue.net') }}
  107. # Allow client to pass locale environment variables
  108. {{ option_default_uncommented('AcceptEnv', 'LANG LC_*') }}
  109. {{ option_default_uncommented('Subsystem', 'sftp /usr/lib/openssh/sftp-server') }}
  110. # Set this to 'yes' to enable PAM authentication, account processing,
  111. # and session processing. If this is enabled, PAM authentication will
  112. # be allowed through the ChallengeResponseAuthentication and
  113. # PasswordAuthentication. Depending on your PAM configuration,
  114. # PAM authentication via ChallengeResponseAuthentication may bypass
  115. # the setting of "PermitRootLogin without-password".
  116. # If you just want the PAM account and session checks to run without
  117. # PAM authentication, then enable this but set PasswordAuthentication
  118. # and ChallengeResponseAuthentication to 'no'.
  119. {{ option_default_uncommented('UsePAM', 'yes') }}
  120. # DNS resolve and map remote IP addresses
  121. {{ option('UseDNS', 'yes') }}
  122. # Restricting Users and Hosts
  123. # example:
  124. # AllowUsers vader@10.0.0.1 maul@sproing.evil.com luke
  125. # AllowGroups wheel staff
  126. #
  127. # Keep in mind that using AllowUsers or AllowGroups means that anyone
  128. # not Matching one of the supplied patterns will be denied access by default.
  129. # Also, in order for sshd to allow access based on full or partial hostnames it
  130. # needs to to a DNS lookup
  131. #
  132. # DenyUsers
  133. {{ option('DenyUsers', '') }}
  134. # AllowUsers
  135. {{ option('AllowUsers', '') }}
  136. # DenyGroups
  137. {{ option('DenyGroups', '') }}
  138. # AllowGroups
  139. {{ option('AllowGroups', '') }}
  140. # Specifies the available KEX (Key Exchange) algorithms.
  141. {{ option('KexAlgorithms', 'ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1') }}
  142. # Specifies the ciphers allowed for protocol version 2.
  143. {{ option('Ciphers', 'aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se') }}
  144. # Specifies the available MAC (message authentication code) algorithms.
  145. {{ option('MACs', 'hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96') }}
  146. {# Handling unknown in salt template options #}
  147. {%- for keyword in sshd_config.keys() %}
  148. {#- Matches have to be at the bottom and should be handled differently -#}
  149. {%- if not keyword in processed_options and keyword != 'matches' -%}
  150. {#- send a blank default as it doesn't matter #}
  151. {{ render_option(keyword, '') }}
  152. {%- endif -%}
  153. {%- endfor %}
  154. {# Handle matches last as they need to go at the bottom #}
  155. {%- if 'matches' in sshd_config %}
  156. {%- for match in sshd_config['matches'].values() %}
  157. Match {{ match['type'].keys()[0] }} {{ match['type'].values()[0] }}
  158. {%- for keyword in match['options'].keys() %}
  159. {{ render_option(keyword, '', config_dict=match['options']) }}
  160. {%- endfor %}
  161. {%- endfor %}
  162. {%- endif %}