X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/18e12b0e123fc3e5f344682f884feabc12da0f5a..df6b53394011fe72217ac3019daeef975430b2c8:/cookbooks/ssl/resources/certificate.rb diff --git a/cookbooks/ssl/resources/certificate.rb b/cookbooks/ssl/resources/certificate.rb index facb59ad7..f2fb4784c 100644 --- a/cookbooks/ssl/resources/certificate.rb +++ b/cookbooks/ssl/resources/certificate.rb @@ -1,8 +1,8 @@ # -# Cookbook Name:: ssl +# Cookbook:: ssl # Resource:: ssl_certificate # -# Copyright 2017, OpenStreetMap Foundation +# Copyright:: 2017, OpenStreetMap Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,14 +17,16 @@ # limitations under the License. # +unified_mode true + default_action :create property :certificate, String, :name_property => true -property :domains, [String, Array], :required => true +property :domains, [String, Array], :required => [:create] action :create do node.default[:letsencrypt][:certificates][new_resource.certificate] = { - :domains => Array(new_resource.domains) + :domains => domains } if letsencrypt @@ -36,7 +38,7 @@ action :create do file "/etc/ssl/certs/#{new_resource.certificate}.pem" do owner "root" group "root" - mode 0o444 + mode "444" content certificate backup false manage_symlink_source false @@ -46,32 +48,26 @@ action :create do file "/etc/ssl/private/#{new_resource.certificate}.key" do owner "root" group "ssl-cert" - mode 0o440 + mode "440" content key backup false manage_symlink_source false force_unlink true end else - template "/tmp/#{new_resource.certificate}.ssl.cnf" do - cookbook "ssl" - source "ssl.cnf.erb" - owner "root" - group "root" - mode 0o644 - variables :domains => Array(new_resource.domains) - not_if do - ::File.exist?("/etc/ssl/certs/#{new_resource.certificate}.pem") && ::File.exist?("/etc/ssl/private/#{new_resource.certificate}.key") - end - end + alt_names = domains.collect { |domain| "DNS:#{domain}" } - execute "/etc/ssl/certs/#{new_resource.certificate}.pem" do - command "openssl req -x509 -newkey rsa:2048 -keyout /etc/ssl/private/#{new_resource.certificate}.key -out /etc/ssl/certs/#{new_resource.certificate}.pem -days 365 -nodes -config /tmp/#{new_resource.certificate}.ssl.cnf" - user "root" + openssl_x509_certificate "/etc/ssl/certs/#{new_resource.certificate}.pem" do + key_file "/etc/ssl/private/#{new_resource.certificate}.key" + owner "root" group "ssl-cert" - not_if do - ::File.exist?("/etc/ssl/certs/#{new_resource.certificate}.pem") && ::File.exist?("/etc/ssl/private/#{new_resource.certificate}.key") - end + mode "640" + org "OpenStreetMap" + email "operations@osmfoundation.org" + common_name domains.first + subject_alt_name alt_names + extensions "keyUsage" => { "values" => %w[digitalSignature keyEncipherment], "critical" => true }, + "extendedKeyUsage" => { "values" => %w[serverAuth clientAuth], "critical" => true } end end end @@ -90,4 +86,8 @@ action_class do def letsencrypt @letsencrypt ||= search(:letsencrypt, "id:#{new_resource.certificate}").first end + + def domains + Array(new_resource.domains) + end end