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.

157 lines
6.0KB

  1. {%- set sshd_config = pillar.get('sshd_config', {}) -%}
  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']) -}}
  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', 768) }}
  56. # Logging
  57. {{ option_default_uncommented('SyslogFacility', 'AUTH') }}
  58. {{ option_default_uncommented('LogLevel', 'INFO') }}
  59. # Authentication:
  60. {{ option_default_uncommented('LoginGraceTime', 120) }}
  61. {{ option_default_uncommented('PermitRootLogin', 'no') }}
  62. {{ option_default_uncommented('StrictModes', 'yes') }}
  63. {{ option('DSAAuthentication', 'yes') }}
  64. {{ option_default_uncommented('RSAAuthentication', 'yes') }}
  65. {{ option_default_uncommented('PubkeyAuthentication', 'yes') }}
  66. {{ option('AuthorizedKeysFile', '%h/.ssh/authorized_keys') }}
  67. # Don't read the user's ~/.rhosts and ~/.shosts files
  68. {{ option_default_uncommented('IgnoreRhosts', 'yes') }}
  69. # For this to work you will also need host keys in /etc/ssh_known_hosts
  70. {{ option_default_uncommented('RhostsRSAAuthentication', 'no') }}
  71. # similar for protocol version 2
  72. {{ option_default_uncommented('HostbasedAuthentication', 'no') }}
  73. # Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
  74. {{ option('IgnoreUserKnownHosts', 'yes') }}
  75. # To enable empty passwords, change to yes (NOT RECOMMENDED)
  76. {{ option_default_uncommented('PermitEmptyPasswords', 'no') }}
  77. # Change to yes to enable challenge-response passwords (beware issues with
  78. # some PAM modules and threads)
  79. {{ option_default_uncommented('ChallengeResponseAuthentication', 'no') }}
  80. # Change to no to disable tunnelled clear text passwords
  81. {{ option('PasswordAuthentication', 'yes') }}
  82. # Kerberos options
  83. {{ option('KerberosAuthentication', 'no') }}
  84. {{ option('KerberosGetAFSToken', 'no') }}
  85. {{ option('KerberosOrLocalPasswd', 'yes') }}
  86. {{ option('KerberosTicketCleanup', 'yes') }}
  87. # GSSAPI options
  88. {{ option('GSSAPIAuthentication', 'no') }}
  89. {{ option('GSSAPICleanupCredentials', 'yes') }}
  90. {{ option_default_uncommented('X11Forwarding', 'yes') }}
  91. {{ option('AllowTcpForwarding', 'yes') }}
  92. {{ option_default_uncommented('X11DisplayOffset', '10') }}
  93. {{ option_default_uncommented('PrintMotd', 'no') }}
  94. {{ option_default_uncommented('PrintLastLog', 'yes') }}
  95. {{ option_default_uncommented('TCPKeepAlive', 'yes') }}
  96. {{ option('UseLogin', 'no') }}
  97. {{ option('MaxStartups', '10:30:60') }}
  98. {{ option('Banner', '/etc/issue.net') }}
  99. # Allow client to pass locale environment variables
  100. {{ option_default_uncommented('AcceptEnv', 'LANG LC_*') }}
  101. {{ option_default_uncommented('Subsystem', 'sftp /usr/lib/openssh/sftp-server') }}
  102. # Set this to 'yes' to enable PAM authentication, account processing,
  103. # and session processing. If this is enabled, PAM authentication will
  104. # be allowed through the ChallengeResponseAuthentication and
  105. # PasswordAuthentication. Depending on your PAM configuration,
  106. # PAM authentication via ChallengeResponseAuthentication may bypass
  107. # the setting of "PermitRootLogin without-password".
  108. # If you just want the PAM account and session checks to run without
  109. # PAM authentication, then enable this but set PasswordAuthentication
  110. # and ChallengeResponseAuthentication to 'no'.
  111. {{ option_default_uncommented('UsePAM', 'yes') }}
  112. # DNS resolve and map remote IP addresses
  113. {{ option('UseDNS', 'yes') }}
  114. {# Handling unknown in salt template options #}
  115. {%- for keyword in sshd_config.keys() %}
  116. {#- Matches have to be at the bottem and should be handled differently -#}
  117. {%- if not keyword in processed_options and keyword != 'matches' -%}
  118. {#- send a blank default as it doesn't matter #}
  119. {{ render_option(keyword, '') }}
  120. {%- endif -%}
  121. {%- endfor %}
  122. {# Handle matches last as they need to go at the bottom #}
  123. {%- if 'matches' in sshd_config %}
  124. {%- for match in sshd_config['matches'].values() %}
  125. Match {{ match['type'].keys()[0] }} {{ match['type'].values()[0] }}
  126. {%- for keyword in match['options'].keys() %}
  127. {{ render_option(keyword, '', config_dict=match['options']) }}
  128. {%- endfor %}
  129. {%- endfor %}
  130. {%- endif %}