Browse Source

Fixed key generation

- generate before running check_mk on the sshd_config
- set permissions on private key
- cope with empty keys
tags/v0.41.0
Alexander Weidinger 7 years ago
parent
commit
7afea021c6
1 changed files with 21 additions and 6 deletions
  1. +21
    -6
      openssh/config.sls

+ 21
- 6
openssh/config.sls View File

{%- endif %} {%- endif %}
ssh_generate_host_{{ keyType }}_key: ssh_generate_host_{{ keyType }}_key:
cmd.run: cmd.run:
{%- if keySize %}
- name: ssh-keygen -t {{ keyType }} -b {{ keySize }} -N '' -f {{ keyFile }}
{%- else %}
- name: ssh-keygen -t {{ keyType }} -N '' -f {{ keyFile }}
{%- endif %}
- creates: {{ keyFile }}
{%- set keySizePart = "-b {}".format(keySize) if keySize else "" %}
- name: "rm {{ keyFile }}*; ssh-keygen -t {{ keyType }} {{ keySizePart }} -N '' -f {{ keyFile }}"
- unless: "test -s {{ keyFile }}"
- user: root - user: root
- require_in:
- file: sshd_config
- watch_in: - watch_in:
- service: {{ openssh.service }} - service: {{ openssh.service }}


ssh_host_{{ keyType }}_key: # set permissions
file.managed:
- name: {{ keyFile }}
- replace: false
- mode: 0600
- require:
- cmd: ssh_generate_host_{{ keyType }}_key
- require_in:
- file: sshd_config

{%- elif salt['pillar.get']('openssh:absent_' ~ keyType ~ '_keys', False) %} {%- elif salt['pillar.get']('openssh:absent_' ~ keyType ~ '_keys', False) %}
ssh_host_{{ keyType }}_key: ssh_host_{{ keyType }}_key:
file.absent: file.absent:
- contents_pillar: 'openssh:{{ keyType }}:private_key' - contents_pillar: 'openssh:{{ keyType }}:private_key'
- user: root - user: root
- mode: 600 - mode: 600
- require_in:
- file: sshd_config
- watch_in: - watch_in:
- service: {{ openssh.service }} - service: {{ openssh.service }}


- contents_pillar: 'openssh:{{ keyType }}:public_key' - contents_pillar: 'openssh:{{ keyType }}:public_key'
- user: root - user: root
- mode: 600 - mode: 600
- require_in:
- file: sshd_config
- watch_in: - watch_in:
- service: {{ openssh.service }} - service: {{ openssh.service }}
{%- endif %} {%- endif %}
file.directory: file.directory:
- user: root - user: root
- mode: 755 - mode: 755
- require_in:
- file: sshd_config
- watch_in: - watch_in:
- service: {{ openssh.service }} - service: {{ openssh.service }}
{% endif %} {% endif %}

Loading…
Cancel
Save