2014-04-24 00:29:11 +02:00
|
|
|
{%- set sshd_config = pillar.get('sshd_config', {}) -%}
|
|
|
|
{#- present in sshd_config and known in actual file options -#}
|
|
|
|
{%- set processed_options = [] -%}
|
|
|
|
|
2014-09-19 17:47:35 +02:00
|
|
|
{#- generic renderer used for sshd matches, known options, -#}
|
|
|
|
{#- and unknown options -#}
|
|
|
|
{%- macro render_option(keyword, default, config_dict=sshd_config) -%}
|
|
|
|
{%- set value = config_dict.get(keyword, default) -%}
|
2014-04-24 00:29:11 +02:00
|
|
|
{%- if value is sameas true -%}
|
2014-09-19 17:55:19 +02:00
|
|
|
{{ keyword }} yes
|
2014-04-24 00:29:11 +02:00
|
|
|
{%- elif value is sameas false -%}
|
2014-09-19 17:55:19 +02:00
|
|
|
{{ keyword }} no
|
2014-04-24 00:29:11 +02:00
|
|
|
{%- elif value is string or value is number -%}
|
2014-09-19 17:55:19 +02:00
|
|
|
{{ keyword }} {{ value }}
|
2014-04-24 00:29:11 +02:00
|
|
|
{%- else -%}
|
|
|
|
{%- for single_value in value -%}
|
2014-09-19 17:55:19 +02:00
|
|
|
{{ keyword }} {{ single_value }}
|
2014-04-24 00:29:11 +02:00
|
|
|
{% endfor -%}
|
|
|
|
{%- endif -%}
|
|
|
|
{%- endmacro -%}
|
|
|
|
|
2014-09-19 17:47:35 +02:00
|
|
|
{#- macros for render option according to present -#}
|
|
|
|
{%- macro option_impl(keyword, default, present) -%}
|
|
|
|
{%- if present -%}
|
|
|
|
{%- do processed_options.append(keyword) -%}
|
|
|
|
{%- set prefix='' -%}
|
|
|
|
{%- else -%}
|
|
|
|
{%- set prefix='#' -%}
|
|
|
|
{%- endif -%}
|
2014-09-19 19:01:57 +02:00
|
|
|
{#- add prefix to keyword -#}
|
2014-09-19 18:19:37 +02:00
|
|
|
{%- set keyword = prefix ~ keyword -%}
|
2014-09-19 17:47:35 +02:00
|
|
|
{{ render_option(keyword, default) }}
|
|
|
|
{%- endmacro -%}
|
|
|
|
|
2014-04-24 00:29:11 +02:00
|
|
|
{#- macros for render option commented by default -#}
|
|
|
|
{%- macro option(keyword, default, present) -%}
|
|
|
|
{{ option_impl(keyword, default, keyword in sshd_config) }}
|
|
|
|
{%- endmacro -%}
|
|
|
|
|
|
|
|
{#- macros for render option uncommented by default -#}
|
|
|
|
{%- macro option_default_uncommented(keyword, default, present) -%}
|
|
|
|
{{ option_impl(keyword, default, True) }}
|
|
|
|
{%- endmacro -%}
|
|
|
|
|
2014-01-09 14:03:44 +01:00
|
|
|
# This file is managed by salt. Manual changes risk being overwritten.
|
|
|
|
# The contents of the original sshd_config are kept on the bottom for
|
|
|
|
# quick reference.
|
|
|
|
# See the sshd_config(5) manpage for details
|
|
|
|
|
2014-04-27 00:22:17 +02:00
|
|
|
# What ports, IPs and protocols we listen for
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option('Port', 22) }}
|
2014-04-27 00:22:17 +02:00
|
|
|
# Use these options to restrict which interfaces/protocols sshd will bind to
|
2014-10-26 20:27:11 +01:00
|
|
|
{{ option('ListenAddress', ['::', '0.0.0.0']) }}
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('Protocol', 2) }}
|
2014-04-27 00:22:17 +02:00
|
|
|
|
|
|
|
# HostKeys for protocol version 2
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('HostKey', ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_dsa_key', '/etc/ssh/ssh_host_ecdsa_key']) -}}
|
2014-04-27 00:22:17 +02:00
|
|
|
|
|
|
|
#Privilege Separation is turned on for security
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('UsePrivilegeSeparation', 'yes') }}
|
2014-04-27 00:22:17 +02:00
|
|
|
|
|
|
|
# Lifetime and size of ephemeral version 1 server key
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('KeyRegenerationInterval', 3600) }}
|
|
|
|
{{ option_default_uncommented('ServerKeyBits', 768) }}
|
2014-04-27 00:22:17 +02:00
|
|
|
|
|
|
|
# Logging
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('SyslogFacility', 'AUTH') }}
|
|
|
|
{{ option_default_uncommented('LogLevel', 'INFO') }}
|
2014-04-27 00:22:17 +02:00
|
|
|
|
|
|
|
# Authentication:
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('LoginGraceTime', 120) }}
|
|
|
|
{{ option_default_uncommented('PermitRootLogin', 'no') }}
|
|
|
|
{{ option_default_uncommented('StrictModes', 'yes') }}
|
2014-04-27 00:22:17 +02:00
|
|
|
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option('DSAAuthentication', 'yes') }}
|
|
|
|
{{ option_default_uncommented('RSAAuthentication', 'yes') }}
|
|
|
|
{{ option_default_uncommented('PubkeyAuthentication', 'yes') }}
|
|
|
|
{{ option('AuthorizedKeysFile', '%h/.ssh/authorized_keys') }}
|
2014-04-27 00:22:17 +02:00
|
|
|
|
|
|
|
# Don't read the user's ~/.rhosts and ~/.shosts files
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('IgnoreRhosts', 'yes') }}
|
2014-04-27 00:22:17 +02:00
|
|
|
# For this to work you will also need host keys in /etc/ssh_known_hosts
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('RhostsRSAAuthentication', 'no') }}
|
2014-04-27 00:22:17 +02:00
|
|
|
# similar for protocol version 2
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('HostbasedAuthentication', 'no') }}
|
2014-04-27 00:22:17 +02:00
|
|
|
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option('IgnoreUserKnownHosts', 'yes') }}
|
2014-04-27 00:22:17 +02:00
|
|
|
|
|
|
|
# To enable empty passwords, change to yes (NOT RECOMMENDED)
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('PermitEmptyPasswords', 'no') }}
|
2014-04-27 00:22:17 +02:00
|
|
|
|
|
|
|
# Change to yes to enable challenge-response passwords (beware issues with
|
|
|
|
# some PAM modules and threads)
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('ChallengeResponseAuthentication', 'no') }}
|
2014-04-27 00:22:17 +02:00
|
|
|
|
|
|
|
# Change to no to disable tunnelled clear text passwords
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option('PasswordAuthentication', 'yes') }}
|
2014-04-27 00:22:17 +02:00
|
|
|
|
|
|
|
# Kerberos options
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option('KerberosAuthentication', 'no') }}
|
|
|
|
{{ option('KerberosGetAFSToken', 'no') }}
|
|
|
|
{{ option('KerberosOrLocalPasswd', 'yes') }}
|
|
|
|
{{ option('KerberosTicketCleanup', 'yes') }}
|
2014-04-27 00:22:17 +02:00
|
|
|
|
|
|
|
# GSSAPI options
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option('GSSAPIAuthentication', 'no') }}
|
|
|
|
{{ option('GSSAPICleanupCredentials', 'yes') }}
|
2014-04-27 00:22:17 +02:00
|
|
|
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('X11Forwarding', 'yes') }}
|
|
|
|
{{ option('AllowTcpForwarding', 'yes') }}
|
|
|
|
{{ option_default_uncommented('X11DisplayOffset', '10') }}
|
|
|
|
{{ option_default_uncommented('PrintMotd', 'no') }}
|
|
|
|
{{ option_default_uncommented('PrintLastLog', 'yes') }}
|
|
|
|
{{ option_default_uncommented('TCPKeepAlive', 'yes') }}
|
|
|
|
{{ option('UseLogin', 'no') }}
|
2014-04-27 00:22:17 +02:00
|
|
|
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option('MaxStartups', '10:30:60') }}
|
|
|
|
{{ option('Banner', '/etc/issue.net') }}
|
2014-04-27 00:22:17 +02:00
|
|
|
|
|
|
|
# Allow client to pass locale environment variables
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('AcceptEnv', 'LANG LC_*') }}
|
2014-04-27 00:22:17 +02:00
|
|
|
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('Subsystem', 'sftp /usr/lib/openssh/sftp-server') }}
|
2014-04-27 00:22:17 +02:00
|
|
|
|
|
|
|
# Set this to 'yes' to enable PAM authentication, account processing,
|
|
|
|
# and session processing. If this is enabled, PAM authentication will
|
|
|
|
# be allowed through the ChallengeResponseAuthentication and
|
|
|
|
# PasswordAuthentication. Depending on your PAM configuration,
|
|
|
|
# PAM authentication via ChallengeResponseAuthentication may bypass
|
|
|
|
# the setting of "PermitRootLogin without-password".
|
|
|
|
# If you just want the PAM account and session checks to run without
|
|
|
|
# PAM authentication, then enable this but set PasswordAuthentication
|
|
|
|
# and ChallengeResponseAuthentication to 'no'.
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('UsePAM', 'yes') }}
|
|
|
|
|
2014-07-22 07:35:11 +02:00
|
|
|
# DNS resolve and map remote IP addresses
|
|
|
|
{{ option('UseDNS', 'yes') }}
|
|
|
|
|
2014-04-24 00:29:11 +02:00
|
|
|
{# Handling unknown in salt template options #}
|
2014-09-19 17:47:35 +02:00
|
|
|
{%- for keyword in sshd_config.keys() %}
|
|
|
|
{#- Matches have to be at the bottem and should be handled differently -#}
|
|
|
|
{%- if not keyword in processed_options and keyword != 'matches' -%}
|
|
|
|
{#- send a blank default as it doesn't matter -#}
|
|
|
|
{{ render_option(keyword, '') }}
|
2014-04-24 00:29:11 +02:00
|
|
|
{%- endif -%}
|
|
|
|
{%- endfor %}
|
2014-09-19 17:47:35 +02:00
|
|
|
|
|
|
|
{# Handle matches last as they need to go at the bottom #}
|
|
|
|
{%- if 'matches' in sshd_config %}
|
|
|
|
{%- for match in sshd_config['matches'].values() %}
|
2014-09-19 18:16:58 +02:00
|
|
|
Match {{ match['type'].keys()[0] }} {{ match['type'].values()[0] }}
|
2014-09-19 17:47:35 +02:00
|
|
|
{%- for keyword in match['options'].keys() %}
|
2014-09-19 18:26:10 +02:00
|
|
|
{{ render_option(keyword, '', config_dict=match['options']) }}
|
2014-09-19 17:47:35 +02:00
|
|
|
{%- endfor %}
|
|
|
|
{%- endfor %}
|
|
|
|
{%- endif %}
|