New version of salt-formula from Saltstack
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. {%- from "salt/map.jinja" import minion with context %}
  2. {%- if minion.enabled %}
  3. include:
  4. - salt.minion.service
  5. {%- set all_ca_certs_dir = '/etc/pki/all_cas' %}
  6. {%- for ca_name,ca in minion.ca.iteritems() %}
  7. {%- set ca_file = ca.get('ca_file', '/etc/pki/ca/' ~ ca_name ~ '/ca.crt') %}
  8. {%- set ca_key_file = ca.get('ca_key_file', '/etc/pki/ca/' ~ ca_name ~ '/ca.key') %}
  9. {%- set ca_key_usage = ca.get('key_usage',"critical,cRLSign,keyCertSign") %}
  10. {%- set ca_dir = salt['file.dirname'](ca_file) %}
  11. {%- set ca_key_dir = salt['file.dirname'](ca_key_file) %}
  12. {%- set ca_certs_dir = ca_dir ~ '/certs' %}
  13. salt_minion_cert_{{ ca_name }}_dirs:
  14. file.directory:
  15. - names:
  16. - {{ ca_dir }}
  17. - {{ ca_key_dir }}
  18. - {{ ca_certs_dir }}
  19. - makedirs: true
  20. {{ ca_key_file }}:
  21. x509.private_key_managed:
  22. - bits: 4096
  23. - backup: True
  24. - require:
  25. - file: {{ ca_certs_dir }}
  26. # TODO: Squash this with the previous state after switch to Salt version >= 2016.11.2
  27. {{ ca_name }}_key_permissions:
  28. file.managed:
  29. - name: {{ ca_key_file }}
  30. - mode: {{ ca.get("mode", 0600) }}
  31. {%- if salt['user.info'](ca.get("user", "root")) %}
  32. - user: {{ ca.get("user", "root") }}
  33. {%- endif %}
  34. {%- if salt['group.info'](ca.get("group", "root")) %}
  35. - group: {{ ca.get("group", "root") }}
  36. {%- endif %}
  37. - replace: false
  38. - require:
  39. - x509: {{ ca_key_file }}
  40. {{ ca_file }}:
  41. x509.certificate_managed:
  42. - signing_private_key: {{ ca_key_file }}
  43. - CN: "{{ ca.common_name }}"
  44. {%- if ca.country is defined %}
  45. - C: {{ ca.country }}
  46. {%- endif %}
  47. {%- if ca.state is defined %}
  48. - ST: {{ ca.state }}
  49. {%- endif %}
  50. {%- if ca.locality is defined %}
  51. - L: {{ ca.locality }}
  52. {%- endif %}
  53. {%- if ca.organization is defined %}
  54. - O: {{ ca.organization }}
  55. {%- endif %}
  56. {%- if ca.organization_unit is defined %}
  57. - OU: {{ ca.organization_unit }}
  58. {%- endif %}
  59. - basicConstraints: "critical,CA:TRUE"
  60. - keyUsage: {{ ca_key_usage }}
  61. - subjectKeyIdentifier: hash
  62. - authorityKeyIdentifier: keyid,issuer:always
  63. - days_valid: {{ ca.days_valid.authority }}
  64. - days_remaining: 0
  65. - backup: True
  66. - require:
  67. - x509: {{ ca_key_file }}
  68. {%- if grains['saltversioninfo'][0] >= 2017 %}
  69. - retry:
  70. attepmts: 5
  71. until: True
  72. interval: 60
  73. {%- endif %}
  74. # TODO: Squash this with the previous state after switch to Salt version >= 2016.11.2
  75. {{ ca_name }}_cert_permissions:
  76. file.managed:
  77. - name: {{ ca_file }}
  78. - mode: 0644
  79. {%- if salt['user.info'](ca.get("user", "root")) %}
  80. - user: {{ ca.get("user", "root") }}
  81. {%- endif %}
  82. {%- if salt['group.info'](ca.get("group", "root")) %}
  83. - group: {{ ca.get("group", "root") }}
  84. {%- endif %}
  85. - require:
  86. - x509: {{ ca_file }}
  87. copy_to_{{all_ca_certs_dir}}/{{ ca_name }}:
  88. file.copy:
  89. - name: {{ all_ca_certs_dir }}/{{ ca_name }}.crt
  90. - source: {{ ca_file }}
  91. - makedirs: True
  92. - force: True
  93. - unless:
  94. - diff -q {{ ca_file }} {{ all_ca_certs_dir }}/{{ ca_name }}.crt
  95. - require:
  96. - x509: {{ ca_file }}
  97. {%- endfor %}
  98. salt_system_ca_mine_send_ca:
  99. module.run:
  100. - name: mine.send
  101. - func: x509.get_pem_entries
  102. - kwargs:
  103. mine_function: x509.get_pem_entries
  104. glob_path: {{ all_ca_certs_dir }}/*
  105. {%- endif %}