2019-07-04 01:07:34 +02:00
|
|
|
{%- set tplroot = tpldir.split('/')[0] %}
|
2020-07-31 10:54:40 +02:00
|
|
|
{%- from tplroot ~ "/map.jinja" import mapdata with context %}
|
2019-07-04 01:07:34 +02:00
|
|
|
{%- from tplroot ~ "/libtofs.jinja" import files_switch %}
|
2020-07-31 10:54:40 +02:00
|
|
|
{%- set openssh = mapdata.openssh %}
|
|
|
|
{%- set sshd_config = mapdata.sshd_config %}
|
|
|
|
{%- set ssh_config = mapdata.ssh_config %}
|
2019-06-25 06:31:34 +02:00
|
|
|
|
2018-08-03 14:35:42 +02:00
|
|
|
|
2014-01-04 03:32:05 +01:00
|
|
|
include:
|
|
|
|
- openssh
|
|
|
|
|
2019-07-04 01:07:34 +02:00
|
|
|
{%- if sshd_config %}
|
2014-01-04 03:32:05 +01:00
|
|
|
sshd_config:
|
|
|
|
file.managed:
|
|
|
|
- name: {{ openssh.sshd_config }}
|
2019-07-04 01:07:34 +02:00
|
|
|
{#- Preserve backward compatibility using the `if` below #}
|
|
|
|
- source: {{ openssh.sshd_config_src if '://' in openssh.sshd_config_src
|
2019-06-25 06:31:34 +02:00
|
|
|
else files_switch( [openssh.sshd_config_src],
|
2019-07-04 01:07:34 +02:00
|
|
|
'sshd_config'
|
2019-06-25 06:31:34 +02:00
|
|
|
) }}
|
2014-01-09 13:57:00 +01:00
|
|
|
- template: jinja
|
2020-07-17 10:48:32 +02:00
|
|
|
- context:
|
2020-07-20 16:28:22 +02:00
|
|
|
sshd_config: {{ sshd_config | json }}
|
2017-02-23 22:42:16 +01:00
|
|
|
- user: {{ openssh.sshd_config_user }}
|
|
|
|
- group: {{ openssh.sshd_config_group }}
|
|
|
|
- mode: {{ openssh.sshd_config_mode }}
|
2017-05-16 12:28:22 +02:00
|
|
|
- check_cmd: {{ openssh.sshd_binary }} -t -f
|
2018-10-10 14:06:14 +02:00
|
|
|
{%- if openssh.sshd_config_backup %}
|
|
|
|
- backup: minion
|
|
|
|
{%- endif %}
|
2014-01-04 03:32:05 +01:00
|
|
|
- watch_in:
|
2017-03-04 12:41:28 +01:00
|
|
|
- service: {{ openssh.service }}
|
2019-07-04 01:07:34 +02:00
|
|
|
{%- endif %}
|
2014-01-04 03:32:05 +01:00
|
|
|
|
2019-07-04 01:07:34 +02:00
|
|
|
{%- if ssh_config %}
|
2015-10-01 17:21:16 +02:00
|
|
|
ssh_config:
|
|
|
|
file.managed:
|
|
|
|
- name: {{ openssh.ssh_config }}
|
2019-07-04 01:07:34 +02:00
|
|
|
{#- Preserve backward compatibility using the `if` below #}
|
|
|
|
- source: {{ openssh.ssh_config_src if '://' in openssh.ssh_config_src
|
2019-06-25 06:31:34 +02:00
|
|
|
else files_switch( [openssh.ssh_config_src],
|
2019-07-04 01:07:34 +02:00
|
|
|
'ssh_config'
|
2019-06-25 06:31:34 +02:00
|
|
|
) }}
|
2015-10-01 17:21:16 +02:00
|
|
|
- template: jinja
|
2020-07-17 10:48:32 +02:00
|
|
|
- context:
|
2020-07-20 16:28:22 +02:00
|
|
|
ssh_config: {{ ssh_config | json }}
|
2017-02-23 22:42:16 +01:00
|
|
|
- user: {{ openssh.ssh_config_user }}
|
|
|
|
- group: {{ openssh.ssh_config_group }}
|
|
|
|
- mode: {{ openssh.ssh_config_mode }}
|
2018-10-10 14:06:14 +02:00
|
|
|
{%- if openssh.ssh_config_backup %}
|
|
|
|
- backup: minion
|
|
|
|
{%- endif %}
|
2019-07-04 01:07:34 +02:00
|
|
|
{%- endif %}
|
2015-10-01 17:21:16 +02:00
|
|
|
|
2019-02-12 14:53:10 +01:00
|
|
|
{%- for keyType in openssh['host_key_algos'].split(',') %}
|
2017-03-04 12:41:28 +01:00
|
|
|
{%- set keyFile = "/etc/ssh/ssh_host_" ~ keyType ~ "_key" %}
|
2019-04-27 09:13:48 +02:00
|
|
|
{%- set keySize = openssh.get('generate_' ~ keyType ~ '_size', False) %}
|
|
|
|
{%- if openssh.get('provide_' ~ keyType ~ '_keys', False) %}
|
2017-10-15 22:55:44 +02:00
|
|
|
ssh_host_{{ keyType }}_key:
|
|
|
|
file.managed:
|
|
|
|
- name: {{ keyFile }}
|
|
|
|
- contents_pillar: 'openssh:{{ keyType }}:private_key'
|
|
|
|
- user: root
|
|
|
|
- mode: 600
|
2019-04-27 09:13:48 +02:00
|
|
|
{%- if sshd_config %}
|
2017-10-15 22:55:44 +02:00
|
|
|
- require_in:
|
|
|
|
- file: sshd_config
|
2018-08-03 14:35:42 +02:00
|
|
|
{%- endif %}
|
2017-10-15 22:55:44 +02:00
|
|
|
- watch_in:
|
|
|
|
- service: {{ openssh.service }}
|
|
|
|
|
|
|
|
ssh_host_{{ keyType }}_key.pub:
|
|
|
|
file.managed:
|
|
|
|
- name: {{ keyFile }}.pub
|
|
|
|
- contents_pillar: 'openssh:{{ keyType }}:public_key'
|
|
|
|
- user: root
|
|
|
|
- mode: 600
|
2019-04-27 09:13:48 +02:00
|
|
|
{%- if sshd_config %}
|
2017-10-15 22:55:44 +02:00
|
|
|
- require_in:
|
|
|
|
- file: sshd_config
|
2018-08-03 14:35:42 +02:00
|
|
|
{%- endif %}
|
2017-10-15 22:55:44 +02:00
|
|
|
- watch_in:
|
|
|
|
- service: {{ openssh.service }}
|
2019-04-27 09:13:48 +02:00
|
|
|
{%- elif openssh.get('generate_' ~ keyType ~ '_keys', False) %}
|
|
|
|
{%- if keySize and openssh.get('enforce_' ~ keyType ~ '_size', False) %}
|
2017-03-04 12:41:28 +01:00
|
|
|
ssh_remove_short_{{ keyType }}_key:
|
|
|
|
cmd.run:
|
|
|
|
- name: "rm -f {{ keyFile }} {{ keyFile }}.pub"
|
|
|
|
- onlyif: "test -f {{ keyFile }}.pub && test `ssh-keygen -l -f {{ keyFile }}.pub 2>/dev/null | awk '{print $1}'` -lt {{ keySize }}"
|
|
|
|
- require_in:
|
|
|
|
- cmd: ssh_generate_host_{{ keyType }}_key
|
|
|
|
{%- endif %}
|
2014-08-24 17:08:41 +02:00
|
|
|
ssh_generate_host_{{ keyType }}_key:
|
|
|
|
cmd.run:
|
2017-07-31 23:05:14 +02:00
|
|
|
{%- set keySizePart = "-b {}".format(keySize) if keySize else "" %}
|
|
|
|
- name: "rm {{ keyFile }}*; ssh-keygen -t {{ keyType }} {{ keySizePart }} -N '' -f {{ keyFile }}"
|
|
|
|
- unless: "test -s {{ keyFile }}"
|
2018-02-16 12:11:54 +01:00
|
|
|
- runas: root
|
2019-04-27 09:13:48 +02:00
|
|
|
{%- if sshd_config %}
|
2017-07-31 23:05:14 +02:00
|
|
|
- require_in:
|
|
|
|
- file: sshd_config
|
2018-08-03 14:35:42 +02:00
|
|
|
{%- endif %}
|
2017-03-04 12:41:28 +01:00
|
|
|
- watch_in:
|
|
|
|
- service: {{ openssh.service }}
|
2014-08-24 17:08:41 +02:00
|
|
|
|
2017-07-31 23:05:14 +02:00
|
|
|
ssh_host_{{ keyType }}_key: # set permissions
|
|
|
|
file.managed:
|
|
|
|
- name: {{ keyFile }}
|
|
|
|
- replace: false
|
2019-10-09 16:00:01 +02:00
|
|
|
- mode: '0600'
|
2017-07-31 23:05:14 +02:00
|
|
|
- require:
|
|
|
|
- cmd: ssh_generate_host_{{ keyType }}_key
|
2019-04-27 09:13:48 +02:00
|
|
|
{%- if sshd_config %}
|
2017-07-31 23:05:14 +02:00
|
|
|
- require_in:
|
|
|
|
- file: sshd_config
|
2018-08-03 14:35:42 +02:00
|
|
|
{%- endif %}
|
2017-07-31 23:05:14 +02:00
|
|
|
|
2019-04-27 09:13:48 +02:00
|
|
|
{%- elif openssh.get('absent_' ~ keyType ~ '_keys', False) %}
|
2015-06-07 20:37:33 +02:00
|
|
|
ssh_host_{{ keyType }}_key:
|
|
|
|
file.absent:
|
2017-03-04 12:41:28 +01:00
|
|
|
- name: {{ keyFile }}
|
|
|
|
- watch_in:
|
|
|
|
- service: {{ openssh.service }}
|
2015-06-07 20:37:33 +02:00
|
|
|
|
|
|
|
ssh_host_{{ keyType }}_key.pub:
|
|
|
|
file.absent:
|
2017-03-04 12:41:28 +01:00
|
|
|
- name: {{ keyFile }}.pub
|
|
|
|
- watch_in:
|
|
|
|
- service: {{ openssh.service }}
|
|
|
|
{%- endif %}
|
|
|
|
{%- endfor %}
|
2017-07-28 15:17:16 +02:00
|
|
|
|
2019-04-27 09:13:48 +02:00
|
|
|
{%- if sshd_config.get('UsePrivilegeSeparation', '')|lower == 'yes' %}
|
2017-07-28 15:17:16 +02:00
|
|
|
/var/run/sshd:
|
|
|
|
file.directory:
|
|
|
|
- user: root
|
|
|
|
- mode: 755
|
2017-07-31 23:05:14 +02:00
|
|
|
- require_in:
|
|
|
|
- file: sshd_config
|
2017-07-28 15:17:16 +02:00
|
|
|
- watch_in:
|
|
|
|
- service: {{ openssh.service }}
|
2019-07-04 01:07:34 +02:00
|
|
|
{%- endif %}
|