New version of salt-formula from Saltstack
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

124 行
3.6KB

  1. {%- from "salt/map.jinja" import minion with context %}
  2. {%- if minion.enabled %}
  3. {%- for cert_name,cert in minion.get('cert', {}).iteritems() %}
  4. {%- set rowloop = loop %}
  5. {%- set key_file = cert.get('key_file', '/etc/ssl/private/' + cert.common_name + '.key') %}
  6. {%- set cert_file = cert.get('cert_file', '/etc/ssl/certs/' + cert.common_name + '.crt') %}
  7. {%- set ca_file = cert.get('ca_file', '/etc/ssl/certs/ca-' + cert.authority + '.crt') %}
  8. {%- set key_dir = key_file|replace(key_file.split('/')[-1], "") %}
  9. {%- set cert_dir = cert_file|replace(cert_file.split('/')[-1], "") %}
  10. {%- set ca_dir = ca_file|replace(ca_file.split('/')[-1], "") %}
  11. {# Only ensure directories exists, don't touch permissions, etc. #}
  12. salt_minion_cert_{{ cert_name }}_dirs:
  13. file.directory:
  14. - names:
  15. - {{ key_dir }}
  16. - {{ cert_dir }}
  17. - {{ ca_dir }}
  18. - makedirs: true
  19. - replace: false
  20. {{ key_file }}:
  21. x509.private_key_managed:
  22. - bits: {{ cert.get('bits', 4096) }}
  23. require:
  24. - file: salt_minion_cert_{{ cert_name }}_dirs
  25. {{ key_file }}_key_permissions:
  26. file.managed:
  27. - name: {{ key_file }}
  28. - mode: {{ cert.get("mode", 0600) }}
  29. {%- if salt['user.info'](cert.get("user", "root")) %}
  30. - user: {{ cert.get("user", "root") }}
  31. {%- endif %}
  32. {%- if salt['group.info'](cert.get("group", "root")) %}
  33. - group: {{ cert.get("group", "root") }}
  34. {%- endif %}
  35. - replace: false
  36. - watch:
  37. - x509: {{ key_file }}
  38. {{ cert_file }}:
  39. x509.certificate_managed:
  40. - ca_server: {{ cert.host }}
  41. - signing_policy: {{ cert.authority }}_{{ cert.signing_policy }}
  42. - public_key: {{ key_file }}
  43. - CN: "{{ cert.common_name }}"
  44. {%- if cert.alternative_names is defined %}
  45. - subjectAltName: "{{ cert.alternative_names }}"
  46. {%- endif %}
  47. - days_remaining: 30
  48. - backup: True
  49. - watch:
  50. - x509: {{ key_file }}
  51. {{ cert_file }}_cert_permissions:
  52. file.managed:
  53. - name: {{ cert_file }}
  54. - mode: {{ cert.get("mode", 0600) }}
  55. {%- if salt['user.info'](cert.get("user", "root")) %}
  56. - user: {{ cert.get("user", "root") }}
  57. {%- endif %}
  58. {%- if salt['group.info'](cert.get("group", "root")) %}
  59. - group: {{ cert.get("group", "root") }}
  60. {%- endif %}
  61. - replace: false
  62. - watch:
  63. - x509: {{ cert_file }}
  64. {%- for ca_path,ca_cert in salt['mine.get'](cert.host, 'x509.get_pem_entries').get(cert.host, {}).iteritems() %}
  65. {%- if '/etc/pki/ca/'+cert.authority in ca_path %}
  66. {{ ca_file }}_{{ rowloop.index }}:
  67. x509.pem_managed:
  68. - name: {{ ca_file }}
  69. - text: {{ ca_cert|replace('\n', '') }}
  70. - watch:
  71. - x509: {{ cert_file }}
  72. {%- if cert.all_file is defined %}
  73. - watch_in:
  74. - cmd: salt_minion_cert_{{ cert_name }}_all
  75. {%- endif %}
  76. {{ ca_file }}_cert_permissions:
  77. file.managed:
  78. - name: {{ ca_file }}
  79. - mode: 0644
  80. - watch:
  81. - x509: {{ ca_file }}
  82. {%- endif %}
  83. {%- endfor %}
  84. {%- if cert.all_file is defined %}
  85. salt_minion_cert_{{ cert_name }}_all:
  86. cmd.wait:
  87. - name: cat {{ key_file }} {{ cert_file }} {{ ca_file }} > {{ cert.all_file }}
  88. - watch:
  89. - x509: {{ key_file }}
  90. - x509: {{ cert_file }}
  91. {{ cert.all_file }}_cert_permissions:
  92. file.managed:
  93. - name: {{ cert.all_file }}
  94. - mode: {{ cert.get("mode", 0600) }}
  95. {%- if salt['user.info'](cert.get("user", "root")) %}
  96. - user: {{ cert.get("user", "root") }}
  97. {%- endif %}
  98. {%- if salt['group.info'](cert.get("group", "root")) %}
  99. - group: {{ cert.get("group", "root") }}
  100. {%- endif %}
  101. - replace: false
  102. - watch:
  103. - cmd: salt_minion_cert_{{ cert_name }}_all
  104. {%- endif %}
  105. {%- endfor %}
  106. {%- endif %}