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.

147 lines
5.5KB

  1. {%- set sshd_config = pillar.get('sshd_config', {}) -%}
  2. {#- present in sshd_config and known in actual file options -#}
  3. {%- set processed_options = [] -%}
  4. {#- macros for render option according to present -#}
  5. {%- macro option_impl(keyword, default, present) -%}
  6. {%- if present -%}
  7. {%- do processed_options.append(keyword) -%}
  8. {%- set prefix='' -%}
  9. {%- else -%}
  10. {%- set prefix='#' -%}
  11. {%- endif -%}
  12. {%- set value = sshd_config.get(keyword, default) -%}
  13. {%- if value is sameas true -%}
  14. {{ prefix }}{{ keyword }} yes
  15. {%- elif value is sameas false -%}
  16. {{ prefix }}{{ keyword }} no
  17. {%- elif value is string or value is number -%}
  18. {{ prefix }}{{ keyword }} {{ value }}
  19. {%- else -%}
  20. {%- for single_value in value -%}
  21. {{ prefix }}{{ keyword }} {{ single_value }}
  22. {% endfor -%}
  23. {%- endif -%}
  24. {%- endmacro -%}
  25. {#- macros for render option commented by default -#}
  26. {%- macro option(keyword, default, present) -%}
  27. {{ option_impl(keyword, default, keyword in sshd_config) }}
  28. {%- endmacro -%}
  29. {#- macros for render option uncommented by default -#}
  30. {%- macro option_default_uncommented(keyword, default, present) -%}
  31. {{ option_impl(keyword, default, True) }}
  32. {%- endmacro -%}
  33. # This file is managed by salt. Manual changes risk being overwritten.
  34. # The contents of the original sshd_config are kept on the bottom for
  35. # quick reference.
  36. # See the sshd_config(5) manpage for details
  37. # What ports, IPs and protocols we listen for
  38. {{ option('Port', 22) }}
  39. # Use these options to restrict which interfaces/protocols sshd will bind to
  40. {{ option('ListenAddress', ['::', '0.0.0.0']) -}}
  41. {{ option_default_uncommented('Protocol', 2) }}
  42. # HostKeys for protocol version 2
  43. {{ option_default_uncommented('HostKey', ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_dsa_key', '/etc/ssh/ssh_host_ecdsa_key']) -}}
  44. #Privilege Separation is turned on for security
  45. {{ option_default_uncommented('UsePrivilegeSeparation', 'yes') }}
  46. # Lifetime and size of ephemeral version 1 server key
  47. {{ option_default_uncommented('KeyRegenerationInterval', 3600) }}
  48. {{ option_default_uncommented('ServerKeyBits', 768) }}
  49. # Logging
  50. {{ option_default_uncommented('SyslogFacility', 'AUTH') }}
  51. {{ option_default_uncommented('LogLevel', 'INFO') }}
  52. # Authentication:
  53. {{ option_default_uncommented('LoginGraceTime', 120) }}
  54. {{ option_default_uncommented('PermitRootLogin', 'no') }}
  55. {{ option_default_uncommented('StrictModes', 'yes') }}
  56. {{ option('DSAAuthentication', 'yes') }}
  57. {{ option_default_uncommented('RSAAuthentication', 'yes') }}
  58. {{ option_default_uncommented('PubkeyAuthentication', 'yes') }}
  59. {{ option('AuthorizedKeysFile', '%h/.ssh/authorized_keys') }}
  60. # Don't read the user's ~/.rhosts and ~/.shosts files
  61. {{ option_default_uncommented('IgnoreRhosts', 'yes') }}
  62. # For this to work you will also need host keys in /etc/ssh_known_hosts
  63. {{ option_default_uncommented('RhostsRSAAuthentication', 'no') }}
  64. # similar for protocol version 2
  65. {{ option_default_uncommented('HostbasedAuthentication', 'no') }}
  66. # Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
  67. {{ option('IgnoreUserKnownHosts', 'yes') }}
  68. # To enable empty passwords, change to yes (NOT RECOMMENDED)
  69. {{ option_default_uncommented('PermitEmptyPasswords', 'no') }}
  70. # Change to yes to enable challenge-response passwords (beware issues with
  71. # some PAM modules and threads)
  72. {{ option_default_uncommented('ChallengeResponseAuthentication', 'no') }}
  73. # Change to no to disable tunnelled clear text passwords
  74. {{ option('PasswordAuthentication', 'yes') }}
  75. # Kerberos options
  76. {{ option('KerberosAuthentication', 'no') }}
  77. {{ option('KerberosGetAFSToken', 'no') }}
  78. {{ option('KerberosOrLocalPasswd', 'yes') }}
  79. {{ option('KerberosTicketCleanup', 'yes') }}
  80. # GSSAPI options
  81. {{ option('GSSAPIAuthentication', 'no') }}
  82. {{ option('GSSAPICleanupCredentials', 'yes') }}
  83. {{ option_default_uncommented('X11Forwarding', 'yes') }}
  84. {{ option('AllowTcpForwarding', 'yes') }}
  85. {{ option_default_uncommented('X11DisplayOffset', '10') }}
  86. {{ option_default_uncommented('PrintMotd', 'no') }}
  87. {{ option_default_uncommented('PrintLastLog', 'yes') }}
  88. {{ option_default_uncommented('TCPKeepAlive', 'yes') }}
  89. {{ option('UseLogin', 'no') }}
  90. {{ option('MaxStartups', '10:30:60') }}
  91. {{ option('Banner', '/etc/issue.net') }}
  92. # Allow client to pass locale environment variables
  93. {{ option_default_uncommented('AcceptEnv', 'LANG LC_*') }}
  94. {{ option_default_uncommented('Subsystem', 'sftp /usr/lib/openssh/sftp-server') }}
  95. # Set this to 'yes' to enable PAM authentication, account processing,
  96. # and session processing. If this is enabled, PAM authentication will
  97. # be allowed through the ChallengeResponseAuthentication and
  98. # PasswordAuthentication. Depending on your PAM configuration,
  99. # PAM authentication via ChallengeResponseAuthentication may bypass
  100. # the setting of "PermitRootLogin without-password".
  101. # If you just want the PAM account and session checks to run without
  102. # PAM authentication, then enable this but set PasswordAuthentication
  103. # and ChallengeResponseAuthentication to 'no'.
  104. {{ option_default_uncommented('UsePAM', 'yes') }}
  105. # DNS resolve and map remote IP addresses
  106. {{ option('UseDNS', 'yes') }}
  107. {# Handling unknown in salt template options #}
  108. {%- for keyword, argument in sshd_config.iteritems() %}
  109. {%- if not keyword in processed_options -%}
  110. {%- if argument is sameas true %}
  111. {{ keyword }} yes
  112. {%- elif argument is sameas false %}
  113. {{ keyword }} no
  114. {%- elif argument is string or argument is number %}
  115. {{ keyword }} {{ argument }}
  116. {%- else %}
  117. {%- for item in argument %}
  118. {{ keyword }} {{ item }}
  119. {%- endfor %}
  120. {%- endif %}
  121. {%- endif -%}
  122. {%- endfor %}