Saltstack Official OpenSSH Formula
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

6 лет назад
6 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. {% from "openssh/map.jinja" import openssh, ssh_config, sshd_config with context %}
  2. include:
  3. - openssh
  4. {% if sshd_config %}
  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. {%- if openssh.sshd_config_backup %}
  15. - backup: minion
  16. {%- endif %}
  17. - watch_in:
  18. - service: {{ openssh.service }}
  19. {% endif %}
  20. {% if ssh_config %}
  21. ssh_config:
  22. file.managed:
  23. - name: {{ openssh.ssh_config }}
  24. - source: {{ openssh.ssh_config_src }}
  25. - template: jinja
  26. - user: {{ openssh.ssh_config_user }}
  27. - group: {{ openssh.ssh_config_group }}
  28. - mode: {{ openssh.ssh_config_mode }}
  29. {%- if openssh.ssh_config_backup %}
  30. - backup: minion
  31. {%- endif %}
  32. {% endif %}
  33. {%- for keyType in openssh['host_key_algos'].split(',') %}
  34. {%- set keyFile = "/etc/ssh/ssh_host_" ~ keyType ~ "_key" %}
  35. {%- set keySize = openssh.get('generate_' ~ keyType ~ '_size', False) %}
  36. {%- if openssh.get('provide_' ~ keyType ~ '_keys', False) %}
  37. ssh_host_{{ keyType }}_key:
  38. file.managed:
  39. - name: {{ keyFile }}
  40. - contents_pillar: 'openssh:{{ keyType }}:private_key'
  41. - user: root
  42. - mode: 600
  43. {%- if sshd_config %}
  44. - require_in:
  45. - file: sshd_config
  46. {%- endif %}
  47. - watch_in:
  48. - service: {{ openssh.service }}
  49. ssh_host_{{ keyType }}_key.pub:
  50. file.managed:
  51. - name: {{ keyFile }}.pub
  52. - contents_pillar: 'openssh:{{ keyType }}:public_key'
  53. - user: root
  54. - mode: 600
  55. {%- if sshd_config %}
  56. - require_in:
  57. - file: sshd_config
  58. {%- endif %}
  59. - watch_in:
  60. - service: {{ openssh.service }}
  61. {%- elif openssh.get('generate_' ~ keyType ~ '_keys', False) %}
  62. {%- if keySize and openssh.get('enforce_' ~ keyType ~ '_size', False) %}
  63. ssh_remove_short_{{ keyType }}_key:
  64. cmd.run:
  65. - name: "rm -f {{ keyFile }} {{ keyFile }}.pub"
  66. - onlyif: "test -f {{ keyFile }}.pub && test `ssh-keygen -l -f {{ keyFile }}.pub 2>/dev/null | awk '{print $1}'` -lt {{ keySize }}"
  67. - require_in:
  68. - cmd: ssh_generate_host_{{ keyType }}_key
  69. {%- endif %}
  70. ssh_generate_host_{{ keyType }}_key:
  71. cmd.run:
  72. {%- set keySizePart = "-b {}".format(keySize) if keySize else "" %}
  73. - name: "rm {{ keyFile }}*; ssh-keygen -t {{ keyType }} {{ keySizePart }} -N '' -f {{ keyFile }}"
  74. - unless: "test -s {{ keyFile }}"
  75. - runas: root
  76. {%- if sshd_config %}
  77. - require_in:
  78. - file: sshd_config
  79. {%- endif %}
  80. - watch_in:
  81. - service: {{ openssh.service }}
  82. ssh_host_{{ keyType }}_key: # set permissions
  83. file.managed:
  84. - name: {{ keyFile }}
  85. - replace: false
  86. - mode: 0600
  87. - require:
  88. - cmd: ssh_generate_host_{{ keyType }}_key
  89. {%- if sshd_config %}
  90. - require_in:
  91. - file: sshd_config
  92. {%- endif %}
  93. {%- elif openssh.get('absent_' ~ keyType ~ '_keys', False) %}
  94. ssh_host_{{ keyType }}_key:
  95. file.absent:
  96. - name: {{ keyFile }}
  97. - watch_in:
  98. - service: {{ openssh.service }}
  99. ssh_host_{{ keyType }}_key.pub:
  100. file.absent:
  101. - name: {{ keyFile }}.pub
  102. - watch_in:
  103. - service: {{ openssh.service }}
  104. {%- endif %}
  105. {%- endfor %}
  106. {%- if sshd_config.get('UsePrivilegeSeparation', '')|lower == 'yes' %}
  107. /var/run/sshd:
  108. file.directory:
  109. - user: root
  110. - mode: 755
  111. - require_in:
  112. - file: sshd_config
  113. - watch_in:
  114. - service: {{ openssh.service }}
  115. {% endif %}