init.sls 2.8 KB

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