3 # Resource:: ssl_certificate
5 # Copyright:: 2017, OpenStreetMap Foundation
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # https://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
22 default_action :create
24 property :certificate, String, :name_property => true
25 property :domains, [String, Array], :required => [:create]
28 node.default[:letsencrypt][:certificates][new_resource.certificate] = {
33 certificate = letsencrypt["certificate"]
34 key = letsencrypt["key"]
38 file "/etc/ssl/certs/#{new_resource.certificate}.pem" do
44 manage_symlink_source false
48 file "/etc/ssl/private/#{new_resource.certificate}.key" do
54 manage_symlink_source false
58 alt_names = domains.collect { |domain| "DNS:#{domain}" }
60 openssl_x509_certificate "/etc/ssl/certs/#{new_resource.certificate}.pem" do
61 key_file "/etc/ssl/private/#{new_resource.certificate}.key"
66 email "operations@osmfoundation.org"
67 common_name domains.first
68 subject_alt_name alt_names
69 extensions "keyUsage" => { "values" => %w[digitalSignature keyEncipherment], "critical" => true },
70 "extendedKeyUsage" => { "values" => %w[serverAuth clientAuth], "critical" => true }
76 file "/etc/ssl/certs/#{new_resource.certificate}.pem" do
80 file "/etc/ssl/private/#{new_resource.certificate}.key" do
87 @letsencrypt ||= search(:letsencrypt, "id:#{new_resource.certificate}").first
91 Array(new_resource.domains)