init.sls 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #
  2. # SSL Certificates
  3. #
  4. openssl:
  5. pkg.installed:
  6. - name: openssl
  7. update_ca_certificates:
  8. cmd.wait:
  9. - name: /usr/sbin/update-ca-certificates
  10. - watch: []
  11. # Install FFHO internal CA into Debian CA certificate mangling mechanism so
  12. # libraries (read: openssl) can use the CA cert when validating internal
  13. # service certificates. By installing the cert into the local ca-certificates
  14. # directory and calling update-ca-certificates two symlinks will be installed
  15. # into /etc/ssl/certs which will both point to the crt file:
  16. # * ffho-cacert.pem
  17. # * <cn-hash>.pem
  18. # The latter is use by openssl for validation.
  19. /usr/local/share/ca-certificates/ffho-cacert.crt:
  20. file.managed:
  21. - source: salt://certs/ffho-cacert.pem
  22. - user: root
  23. - group: root
  24. - mode: 644
  25. - watch_in:
  26. - cmd: update_ca_certificates
  27. /usr/local/share/ca-certificates/StartSSL_Class1_CA.crt:
  28. file.managed:
  29. - source: salt://certs/StartSSL_Class1_CA.pem
  30. - user: root
  31. - group: root
  32. - mode: 644
  33. - watch_in:
  34. - cmd: update_ca_certificates
  35. /usr/local/share/ca-certificates/StartSSL_Class2_CA.crt:
  36. file.managed:
  37. - source: salt://certs/StartSSL_Class2_CA.pem
  38. - user: root
  39. - group: root
  40. - mode: 644
  41. - watch_in:
  42. - cmd: update_ca_certificates
  43. {% set certs = {} %}
  44. # Are there any certificates defined or referenced in the node pillar?
  45. {% set node_config = salt['pillar.get']('nodes:' ~ grains['id']) %}
  46. {% for cn, cert_config in node_config.get ('certs', {}).items () %}
  47. {% set pillar_name = None %}
  48. {# "cert" and "privkey" provided in node config? #}
  49. {% if 'cert' in cert_config and 'privkey' in cert_config %}
  50. {% set pillar_name = 'nodes:' ~ grains['id'] ~ ':certs:' ~ cn %}
  51. {# <cn> only referenced in node config and cert/privkey stored in "cert" pillar? #}
  52. {% elif cert_config.get ('install', False) == True %}
  53. {% set pillar_name = 'cert:' ~ cn %}
  54. {% endif %}
  55. {% if pillar_name != None %}
  56. {% do certs.update ({ cn : pillar_name }) %}
  57. {% endif %}
  58. {% endfor %}
  59. # Are there any cert defined or referenced for this node or roles of this node?
  60. {% set node_roles = node_config.get ('roles', []) %}
  61. {% for cn, cert_config in salt['pillar.get']('cert', {}).items () %}
  62. {% for role in cert_config.get ('apply', {}).get ('roles', []) %}
  63. {% if role in node_roles %}
  64. {% do certs.update ({ cn : 'cert:' ~ cn }) %}
  65. {% endif %}
  66. {% endfor %}
  67. {% endfor %}
  68. # Install found certificates
  69. {% for cn, pillar_name in certs.items () %}
  70. /etc/ssl/certs/{{ cn }}.cert.pem:
  71. file.managed:
  72. {% if salt['pillar.get'](pillar_name ~ ':cert') == "file" %}
  73. - source: salt://certs/certs/{{ cn }}.cert.pem
  74. {% else %}
  75. - contents_pillar: {{ pillar_name }}:cert
  76. {% endif %}
  77. - user: root
  78. - group: root
  79. - mode: 644
  80. /etc/ssl/private/{{ cn }}.key.pem:
  81. file.managed:
  82. - contents_pillar: {{ pillar_name }}:privkey
  83. - user: root
  84. - group: ssl-cert
  85. - mode: 440
  86. {% endfor %}