Saltstack Official OpenSSH Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.7KB

  1. {% from "openssh/map.jinja" import openssh with context %}
  2. include:
  3. - openssh
  4. {% if salt['pillar.get']('sshd_config', False) %}
  5. sshd_config:
  6. file.managed:
  7. - name: {{ openssh.sshd_config }}
  8. - source: {{ openssh.sshd_config_src }}
  9. - template: jinja
  10. - user: {{ openssh.sshd_config_user }}
  11. - group: {{ openssh.sshd_config_group }}
  12. - mode: {{ openssh.sshd_config_mode }}
  13. - check_cmd: {{ openssh.sshd_binary }} -t -f
  14. - watch_in:
  15. - service: {{ openssh.service }}
  16. {% endif %}
  17. {% if salt['pillar.get']('ssh_config', False) %}
  18. ssh_config:
  19. file.managed:
  20. - name: {{ openssh.ssh_config }}
  21. - source: {{ openssh.ssh_config_src }}
  22. - template: jinja
  23. - user: {{ openssh.ssh_config_user }}
  24. - group: {{ openssh.ssh_config_group }}
  25. - mode: {{ openssh.ssh_config_mode }}
  26. {% endif %}
  27. {%- for keyType in ['ecdsa', 'dsa', 'rsa', 'ed25519'] %}
  28. {%- set keyFile = "/etc/ssh/ssh_host_" ~ keyType ~ "_key" %}
  29. {%- set keySize = salt['pillar.get']('openssh:generate_' ~ keyType ~ '_size', False) %}
  30. {%- if salt['pillar.get']('openssh:generate_' ~ keyType ~ '_keys', False) %}
  31. {%- if keySize and salt['pillar.get']('openssh:enforce_' ~ keyType ~ '_size', False) %}
  32. ssh_remove_short_{{ keyType }}_key:
  33. cmd.run:
  34. - name: "rm -f {{ keyFile }} {{ keyFile }}.pub"
  35. - onlyif: "test -f {{ keyFile }}.pub && test `ssh-keygen -l -f {{ keyFile }}.pub 2>/dev/null | awk '{print $1}'` -lt {{ keySize }}"
  36. - require_in:
  37. - cmd: ssh_generate_host_{{ keyType }}_key
  38. {%- endif %}
  39. ssh_generate_host_{{ keyType }}_key:
  40. cmd.run:
  41. {%- if keySize %}
  42. - name: ssh-keygen -t {{ keyType }} -b {{ keySize }} -N '' -f {{ keyFile }}
  43. {%- else %}
  44. - name: ssh-keygen -t {{ keyType }} -N '' -f {{ keyFile }}
  45. {%- endif %}
  46. - creates: /etc/ssh/ssh_host_{{ keyType }}_key
  47. - user: root
  48. - watch_in:
  49. - service: {{ openssh.service }}
  50. {%- elif salt['pillar.get']('openssh:absent_' ~ keyType ~ '_keys', False) %}
  51. ssh_host_{{ keyType }}_key:
  52. file.absent:
  53. - name: {{ keyFile }}
  54. - watch_in:
  55. - service: {{ openssh.service }}
  56. ssh_host_{{ keyType }}_key.pub:
  57. file.absent:
  58. - name: {{ keyFile }}.pub
  59. - watch_in:
  60. - service: {{ openssh.service }}
  61. {%- elif salt['pillar.get']('openssh:provide_' ~ keyType ~ '_keys', False) %}
  62. ssh_host_{{ keyType }}_key:
  63. file.managed:
  64. - name: {{ keyFile }}
  65. - contents_pillar: 'openssh:{{ keyType }}:private_key'
  66. - user: root
  67. - mode: 600
  68. - watch_in:
  69. - service: {{ openssh.service }}
  70. ssh_host_{{ keyType }}_key.pub:
  71. file.managed:
  72. - name: {{ keyFile }}.pub
  73. - contents_pillar: 'openssh:{{ keyType }}:public_key'
  74. - user: root
  75. - mode: 600
  76. - watch_in:
  77. - service: {{ openssh.service }}
  78. {%- endif %}
  79. {%- endfor %}