2016-04-18 17:46:10 +02:00
|
|
|
{% from "openssh/map.jinja" import sshd_config with context %}
|
2014-04-24 00:29:11 +02:00
|
|
|
{#- 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 -%}
|
|
|
|
|
2017-01-23 19:17:51 +01:00
|
|
|
{#- macro for collapsing a list into a string -#}
|
|
|
|
{%- macro option_collapselist(keyword, sep) -%}
|
|
|
|
{%- do processed_options.append(keyword) -%}
|
|
|
|
{{keyword}} {{sshd_config.get(keyword)|join(sep)}}
|
|
|
|
{%- endmacro -%}
|
|
|
|
|
|
|
|
{#- macro for handling an option that can be specified as a list or a string -#}
|
|
|
|
{%- macro option_string_or_list(keyword, default, default_commented, sep=',') -%}
|
|
|
|
{%- if sshd_config.get(keyword, '') is string -%}
|
|
|
|
{%- if default_commented -%}
|
|
|
|
{{ option(keyword, default) }}
|
|
|
|
{%- else -%}
|
|
|
|
{{ option_default_uncommented(keyword, default) }}
|
|
|
|
{%- endif -%}
|
|
|
|
{%- else -%}
|
|
|
|
{{ option_collapselist(keyword, sep) }}
|
|
|
|
{%- endif -%}
|
|
|
|
{%- endmacro -%}
|
|
|
|
|
|
|
|
{%- if sshd_config.get('ConfigBanner', False) -%}
|
|
|
|
{{ sshd_config['ConfigBanner'] }}
|
|
|
|
{%- else -%}
|
2014-01-09 14:03:44 +01:00
|
|
|
# This file is managed by salt. Manual changes risk being overwritten.
|
2017-01-23 19:17:51 +01:00
|
|
|
{%- endif %}
|
2014-01-09 14:03:44 +01:00
|
|
|
# The contents of the original sshd_config are kept on the bottom for
|
|
|
|
# quick reference.
|
|
|
|
# See the sshd_config(5) manpage for details
|
|
|
|
|
2016-11-01 13:24:30 +01:00
|
|
|
# Specifies which address family should be used by sshd(8).
|
|
|
|
# Valid arguments are any, inet (use IPv4 only), or inet6 (use IPv6 only)
|
|
|
|
{{ option('AddressFamily', 'any') }}
|
|
|
|
|
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
|
2015-01-16 18:21:10 +01:00
|
|
|
{{ 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']) -}}
|
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) }}
|
2015-07-30 14:27:05 +02:00
|
|
|
{{ option_default_uncommented('ServerKeyBits', 1024) }}
|
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
|
|
|
|
2016-05-25 00:06:45 +02:00
|
|
|
# Session idle time out
|
|
|
|
{{ option_default_uncommented('ClientAliveInterval', 0) }}
|
|
|
|
{{ option_default_uncommented('ClientAliveCountMax', 3) }}
|
|
|
|
|
2014-04-27 00:22:17 +02:00
|
|
|
# Authentication:
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('LoginGraceTime', 120) }}
|
2015-10-01 17:21:16 +02:00
|
|
|
{{ option_default_uncommented('PermitRootLogin', 'yes') }}
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('StrictModes', 'yes') }}
|
2016-05-26 21:57:02 +02:00
|
|
|
{{ option_default_uncommented('MaxAuthTries', '6') }}
|
|
|
|
{{ option_default_uncommented('MaxSessions', '10') }}
|
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') }}
|
2016-10-01 20:53:44 +02:00
|
|
|
{{ option('AuthorizedKeysCommand', 'none') }}
|
|
|
|
{{ option('AuthorizedKeysCommandUser', 'nobody') }}
|
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') }}
|
2015-01-16 18:21:10 +01:00
|
|
|
{{ option('AuthenticationMethods', 'publickey,keyboard-interactive') }}
|
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') }}
|
2017-02-23 01:19:21 +01:00
|
|
|
{# Bug in FreeBSD 10.3 (?) See https://lists.freebsd.org/pipermail/freebsd-stable/2016-April/084501.html #}
|
2017-06-04 18:22:32 +02:00
|
|
|
{% if not (salt['grains.get']('os') == 'FreeBSD' and salt['grains.get']('osrelease')|float >= 10.3) -%}
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ option_default_uncommented('PrintLastLog', 'yes') }}
|
2017-02-23 01:19:21 +01:00
|
|
|
{% endif -%}
|
2014-04-24 00:29:11 +02:00
|
|
|
{{ 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
|
|
|
|
2017-01-15 00:38:37 +01:00
|
|
|
{% if not salt['grains.get']('os') == 'OpenBSD' -%}
|
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') }}
|
2017-01-15 00:38:37 +01:00
|
|
|
{%- endif %}
|
2014-04-24 00:29:11 +02:00
|
|
|
|
2014-07-22 07:35:11 +02:00
|
|
|
# DNS resolve and map remote IP addresses
|
|
|
|
{{ option('UseDNS', 'yes') }}
|
|
|
|
|
2015-01-16 22:56:59 +01:00
|
|
|
# Restricting Users and Hosts
|
|
|
|
# example:
|
2015-06-30 14:33:57 +02:00
|
|
|
# AllowUsers vader@10.0.0.1 maul@sproing.evil.com luke
|
2015-01-16 22:56:59 +01:00
|
|
|
# AllowGroups wheel staff
|
|
|
|
#
|
|
|
|
# Keep in mind that using AllowUsers or AllowGroups means that anyone
|
|
|
|
# not Matching one of the supplied patterns will be denied access by default.
|
|
|
|
# Also, in order for sshd to allow access based on full or partial hostnames it
|
|
|
|
# needs to to a DNS lookup
|
|
|
|
#
|
|
|
|
# DenyUsers
|
|
|
|
{{ option('DenyUsers', '') }}
|
|
|
|
# AllowUsers
|
|
|
|
{{ option('AllowUsers', '') }}
|
|
|
|
# DenyGroups
|
|
|
|
{{ option('DenyGroups', '') }}
|
|
|
|
# AllowGroups
|
|
|
|
{{ option('AllowGroups', '') }}
|
|
|
|
|
2015-06-30 14:33:57 +02:00
|
|
|
# Specifies the available KEX (Key Exchange) algorithms.
|
2017-01-23 19:17:51 +01:00
|
|
|
{{ option_string_or_list('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', True) }}
|
2015-06-30 14:33:57 +02:00
|
|
|
|
|
|
|
# Specifies the ciphers allowed for protocol version 2.
|
2017-01-23 19:17:51 +01:00
|
|
|
{{ option_string_or_list('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', True) }}
|
2015-06-30 14:33:57 +02:00
|
|
|
|
|
|
|
# Specifies the available MAC (message authentication code) algorithms.
|
2017-01-23 19:17:51 +01:00
|
|
|
{{ option_string_or_list('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', True) }}
|
2015-06-30 14:33:57 +02:00
|
|
|
|
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() %}
|
2015-10-01 17:21:16 +02:00
|
|
|
{#- Matches have to be at the bottom and should be handled differently -#}
|
2014-09-19 17:47:35 +02:00
|
|
|
{%- if not keyword in processed_options and keyword != 'matches' -%}
|
2014-11-18 23:58:57 +01:00
|
|
|
{#- send a blank default as it doesn't matter #}
|
2014-09-19 17:47:35 +02:00
|
|
|
{{ 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 %}
|
2017-01-23 19:17:51 +01:00
|
|
|
|
|
|
|
{#- vim: set ft=jinja : #}
|