New version of salt-formula from Saltstack
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 8 Jahren
vor 8 Jahren
vor 8 Jahren
vor 8 Jahren
vor 8 Jahren
vor 8 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. {%- from "salt/map.jinja" import minion with context %}
  2. {%- if minion.enabled %}
  3. {%- if grains.os_family == 'RedHat' %}
  4. {%- set cacerts_dir='/etc/pki/ca-trust/source/anchors' %}
  5. {%- else %}
  6. {%- set cacerts_dir='/usr/local/share/ca-certificates' %}
  7. {%- endif %}
  8. {%- if minion.cert is defined %}
  9. {%- set created_ca_files = [] %}
  10. {%- for cert_name,cert in minion.get('cert', {}).iteritems() %}
  11. {%- set rowloop = loop %}
  12. {%- set key_file = cert.get('key_file', '/etc/ssl/private/' + cert.common_name + '.key') %}
  13. {%- set cert_file = cert.get('cert_file', '/etc/ssl/certs/' + cert.common_name + '.crt') %}
  14. {%- set ca_file = cert.get('ca_file', '/etc/ssl/certs/ca-' + cert.authority + '.crt') %}
  15. {%- set key_dir = salt['file.dirname'](key_file) %}
  16. {%- set cert_dir = salt['file.dirname'](cert_file) %}
  17. {%- set ca_dir = salt['file.dirname'](ca_file) %}
  18. {# Only ensure directories exists, don't touch permissions, etc. #}
  19. salt_minion_cert_{{ cert_name }}_dirs:
  20. file.directory:
  21. - names:
  22. - {{ key_dir }}
  23. - {{ cert_dir }}
  24. - {{ ca_dir }}
  25. - makedirs: true
  26. - replace: false
  27. {{ key_file }}:
  28. x509.private_key_managed:
  29. - bits: {{ cert.get('bits', 4096) }}
  30. - require:
  31. - file: salt_minion_cert_{{ cert_name }}_dirs
  32. {%- if cert.all_file is defined %}
  33. - watch_in:
  34. - cmd: salt_minion_cert_{{ cert_name }}_all
  35. {%- endif %}
  36. # TODO: Squash this with the previous state after switch to Salt version >= 2016.11.2
  37. {{ key_file }}_key_permissions:
  38. file.managed:
  39. - name: {{ key_file }}
  40. - mode: {{ cert.get("mode", 0600) }}
  41. {%- if salt['user.info'](cert.get("user", "root")) %}
  42. - user: {{ cert.get("user", "root") }}
  43. {%- endif %}
  44. {%- if salt['group.info'](cert.get("group", "root")) %}
  45. - group: {{ cert.get("group", "root") }}
  46. {%- endif %}
  47. - replace: false
  48. - require:
  49. - x509: {{ key_file }}
  50. {{ cert_file }}:
  51. x509.certificate_managed:
  52. {% if cert.host is defined %}- ca_server: {{ cert.host }}{%- endif %}
  53. {% if cert.authority is defined and cert.signing_policy is defined %}
  54. - signing_policy: {{ cert.authority }}_{{ cert.signing_policy }}
  55. {%- endif %}
  56. - public_key: {{ key_file }}
  57. - CN: "{{ cert.common_name }}"
  58. {% if cert.state is defined %}- ST: {{ cert.state }}{%- endif %}
  59. {% if cert.country is defined %}- C: {{ cert.country }}{%- endif %}
  60. {% if cert.locality is defined %}- L: {{ cert.locality }}{%- endif %}
  61. {% if cert.organization is defined %}- O: {{ cert.organization }}{%- endif %}
  62. {% if cert.signing_private_key is defined and cert.signing_cert is defined %}
  63. - signing_private_key: "{{ cert.signing_private_key }}"
  64. - signing_cert: "{{ cert.signing_cert }}"
  65. {%- endif %}
  66. {% if cert.alternative_names is defined %}
  67. - subjectAltName: "{{ cert.alternative_names }}"
  68. {%- endif %}
  69. {%- if cert.extended_key_usage is defined %}
  70. - extendedKeyUsage: "{{ cert.extended_key_usage }}"
  71. {%- endif %}
  72. {%- if cert.key_usage is defined %}
  73. - keyUsage: "{{ cert.key_usage }}"
  74. {%- endif %}
  75. - days_remaining: 30
  76. - backup: True
  77. - watch:
  78. - x509: {{ key_file }}
  79. {%- if cert.all_file is defined %}
  80. - watch_in:
  81. - cmd: salt_minion_cert_{{ cert_name }}_all
  82. {%- endif %}
  83. # TODO: Squash this with the previous state after switch to Salt version >= 2016.11.2
  84. {{ cert_file }}_cert_permissions:
  85. file.managed:
  86. - name: {{ cert_file }}
  87. - mode: {{ cert.get("mode", 0600) }}
  88. {%- if salt['user.info'](cert.get("user", "root")) %}
  89. - user: {{ cert.get("user", "root") }}
  90. {%- endif %}
  91. {%- if salt['group.info'](cert.get("group", "root")) %}
  92. - group: {{ cert.get("group", "root") }}
  93. {%- endif %}
  94. - replace: false
  95. - require:
  96. - x509: {{ cert_file }}
  97. {%- if cert.host is defined and ca_file not in created_ca_files %}
  98. {%- for ca_path,ca_cert in salt['mine.get'](cert.host, 'x509.get_pem_entries').get(cert.host, {}).iteritems() %}
  99. {%- if '/etc/pki/ca/'+cert.authority in ca_path %}
  100. {{ ca_file }}:
  101. x509.pem_managed:
  102. - name: {{ ca_file }}
  103. - text: {{ ca_cert|replace('\n', '') }}
  104. - watch:
  105. - x509: {{ cert_file }}
  106. {%- if cert.all_file is defined %}
  107. - watch_in:
  108. - cmd: salt_minion_cert_{{ cert_name }}_all
  109. {%- endif %}
  110. # TODO: Squash this with the previous state after switch to Salt version >= 2016.11.2
  111. {{ ca_file }}_cert_permissions:
  112. file.managed:
  113. - name: {{ ca_file }}
  114. - mode: 0644
  115. {%- if salt['user.info'](cert.get("user", "root")) %}
  116. - user: {{ cert.get("user", "root") }}
  117. {%- endif %}
  118. {%- if salt['group.info'](cert.get("group", "root")) %}
  119. - group: {{ cert.get("group", "root") }}
  120. {%- endif %}
  121. - require:
  122. - x509: {{ ca_file }}
  123. {%- endif %}
  124. {%- endfor %}
  125. {%- do created_ca_files.append(ca_file) %}
  126. {%- endif %}
  127. {%- if cert.all_file is defined %}
  128. salt_minion_cert_{{ cert_name }}_all:
  129. cmd.wait:
  130. - name: cat {{ key_file }} {{ cert_file }} {{ ca_file }} > {{ cert.all_file }}
  131. {{ cert.all_file }}_cert_permissions:
  132. file.managed:
  133. - name: {{ cert.all_file }}
  134. - mode: {{ cert.get("mode", 0600) }}
  135. {%- if salt['user.info'](cert.get("user", "root")) %}
  136. - user: {{ cert.get("user", "root") }}
  137. {%- endif %}
  138. {%- if salt['group.info'](cert.get("group", "root")) %}
  139. - group: {{ cert.get("group", "root") }}
  140. {%- endif %}
  141. - replace: false
  142. - require:
  143. - cmd: salt_minion_cert_{{ cert_name }}_all
  144. {%- endif %}
  145. {%- endfor %}
  146. {%- endif %}
  147. salt_ca_certificates_packages:
  148. pkg.installed:
  149. - names: {{ minion.cert_pkgs }}
  150. salt_update_certificates:
  151. cmd.wait:
  152. {%- if grains.os_family == 'Debian' %}
  153. - name: "update-ca-certificates{% if minion.get('ca_certificates_cleanup') %} --fresh {% endif %}"
  154. {%- elif grains.os_family == 'RedHat' %}
  155. - name: "update-ca-trust extract"
  156. {%- else %}
  157. - name: true
  158. {%- endif %}
  159. - require:
  160. - pkg: salt_ca_certificates_packages
  161. {%- if minion.get('trust_salt_ca', True) %}
  162. {%- for trusted_ca_minion in minion.get('trusted_ca_minions', []) %}
  163. {%- for ca_host, certs in salt['mine.get'](trusted_ca_minion+'*', 'x509.get_pem_entries').iteritems() %}
  164. {%- for ca_path, ca_cert in certs.iteritems() %}
  165. {%- if ca_path.endswith('ca.crt') %}
  166. {# authority name can be obtained only from a cacert path in case of mine.get #}
  167. {%- set ca_authority = ca_path.split("/")[-2] %}
  168. {%- set cacert_file="%s/ca-%s.crt" % (cacerts_dir,ca_authority) %}
  169. salt_trust_ca_{{ cacert_file }}:
  170. x509.pem_managed:
  171. - name: {{ cacert_file }}
  172. - text: {{ ca_cert|replace('\n', '') }}
  173. - watch_in:
  174. - file: salt_trust_ca_{{ cacert_file }}_permissions
  175. - cmd: salt_update_certificates
  176. salt_trust_ca_{{ cacert_file }}_permissions:
  177. file.managed:
  178. - name: {{ cacert_file }}
  179. - mode: 0444
  180. {%- endif %}
  181. {%- endfor %}
  182. {%- endfor %}
  183. {%- endfor %}
  184. {%- endif %}
  185. {%- endif %}