2014-01-04 03:32:05 +01:00
|
|
|
{% from "openssh/map.jinja" import openssh with context %}
|
|
|
|
|
|
|
|
include:
|
|
|
|
- openssh
|
|
|
|
|
2017-02-24 21:13:52 +01:00
|
|
|
{% if salt['pillar.get']('sshd_config', False) %}
|
2014-01-04 03:32:05 +01:00
|
|
|
sshd_config:
|
|
|
|
file.managed:
|
|
|
|
- name: {{ openssh.sshd_config }}
|
|
|
|
- source: {{ openssh.sshd_config_src }}
|
2014-01-09 13:57:00 +01:00
|
|
|
- template: jinja
|
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
|
2014-01-04 03:32:05 +01:00
|
|
|
- watch_in:
|
2017-03-04 12:41:28 +01:00
|
|
|
- service: {{ openssh.service }}
|
2017-02-24 21:13:52 +01:00
|
|
|
{% endif %}
|
2014-01-04 03:32:05 +01:00
|
|
|
|
2017-02-24 21:13:52 +01:00
|
|
|
{% if salt['pillar.get']('ssh_config', False) %}
|
2015-10-01 17:21:16 +02:00
|
|
|
ssh_config:
|
|
|
|
file.managed:
|
|
|
|
- name: {{ openssh.ssh_config }}
|
|
|
|
- source: {{ openssh.ssh_config_src }}
|
|
|
|
- template: jinja
|
2017-02-23 22:42:16 +01:00
|
|
|
- user: {{ openssh.ssh_config_user }}
|
|
|
|
- group: {{ openssh.ssh_config_group }}
|
|
|
|
- mode: {{ openssh.ssh_config_mode }}
|
2017-02-24 21:13:52 +01:00
|
|
|
{% endif %}
|
2015-10-01 17:21:16 +02:00
|
|
|
|
2017-03-04 12:41:28 +01:00
|
|
|
{%- for keyType in ['ecdsa', 'dsa', 'rsa', 'ed25519'] %}
|
|
|
|
{%- set keyFile = "/etc/ssh/ssh_host_" ~ keyType ~ "_key" %}
|
|
|
|
{%- set keySize = salt['pillar.get']('openssh:generate_' ~ keyType ~ '_size', False) %}
|
|
|
|
{%- if salt['pillar.get']('openssh:generate_' ~ keyType ~ '_keys', False) %}
|
|
|
|
{%- if keySize and salt['pillar.get']('openssh:enforce_' ~ keyType ~ '_size', False) %}
|
|
|
|
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-03-04 12:41:28 +01:00
|
|
|
{%- if keySize %}
|
|
|
|
- name: ssh-keygen -t {{ keyType }} -b {{ keySize }} -N '' -f {{ keyFile }}
|
2015-07-12 18:09:26 +02:00
|
|
|
{%- else %}
|
2017-03-04 12:41:28 +01:00
|
|
|
- name: ssh-keygen -t {{ keyType }} -N '' -f {{ keyFile }}
|
2015-07-12 18:09:26 +02:00
|
|
|
{%- endif %}
|
2017-07-04 22:47:02 +02:00
|
|
|
- creates: {{ keyFile }}
|
2014-08-24 17:08:41 +02:00
|
|
|
- user: root
|
2017-03-04 12:41:28 +01:00
|
|
|
- watch_in:
|
|
|
|
- service: {{ openssh.service }}
|
2014-08-24 17:08:41 +02:00
|
|
|
|
2017-03-04 12:41:28 +01:00
|
|
|
{%- elif salt['pillar.get']('openssh: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 }}
|
2015-06-07 20:37:33 +02:00
|
|
|
|
2017-03-04 12:41:28 +01:00
|
|
|
{%- elif salt['pillar.get']('openssh:provide_' ~ keyType ~ '_keys', False) %}
|
2014-08-24 12:50:36 +02:00
|
|
|
ssh_host_{{ keyType }}_key:
|
2014-03-17 23:17:04 +01:00
|
|
|
file.managed:
|
2017-03-04 12:41:28 +01:00
|
|
|
- name: {{ keyFile }}
|
2014-08-24 12:50:36 +02:00
|
|
|
- contents_pillar: 'openssh:{{ keyType }}:private_key'
|
2014-03-17 23:17:04 +01:00
|
|
|
- user: root
|
|
|
|
- mode: 600
|
2017-03-04 12:41:28 +01:00
|
|
|
- watch_in:
|
2014-03-17 23:17:04 +01:00
|
|
|
- service: {{ openssh.service }}
|
|
|
|
|
2014-08-24 12:50:36 +02:00
|
|
|
ssh_host_{{ keyType }}_key.pub:
|
2014-03-17 23:17:04 +01:00
|
|
|
file.managed:
|
2017-03-04 12:41:28 +01:00
|
|
|
- name: {{ keyFile }}.pub
|
2014-08-24 12:50:36 +02:00
|
|
|
- contents_pillar: 'openssh:{{ keyType }}:public_key'
|
2014-03-17 23:17:04 +01:00
|
|
|
- user: root
|
|
|
|
- mode: 600
|
2017-03-04 12:41:28 +01:00
|
|
|
- watch_in:
|
2014-03-17 23:17:04 +01:00
|
|
|
- service: {{ openssh.service }}
|
2017-03-04 12:41:28 +01:00
|
|
|
{%- endif %}
|
|
|
|
{%- endfor %}
|