init.sls 3.0 KB

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