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.
 
  20 default_action :create
 
  22 property :certificate, String, :name_property => true
 
  23 property :domains, [String, Array], :required => true
 
  26   node.default[:letsencrypt][:certificates][new_resource.certificate] = {
 
  27     :domains => Array(new_resource.domains)
 
  31     certificate = letsencrypt["certificate"]
 
  32     key = letsencrypt["key"]
 
  36     file "/etc/ssl/certs/#{new_resource.certificate}.pem" do
 
  42       manage_symlink_source false
 
  46     file "/etc/ssl/private/#{new_resource.certificate}.key" do
 
  52       manage_symlink_source false
 
  56     alt_names = new_resource.domains.collect { |domain| "DNS:#{domain}" }
 
  58     openssl_x509_certificate "/etc/ssl/certs/#{new_resource.certificate}.pem" do
 
  59       key_file "/etc/ssl/private/#{new_resource.certificate}.key"
 
  64       email "operations@osmfoundation.org"
 
  65       common_name new_resource.domains.first
 
  66       subject_alt_name alt_names
 
  67       extensions "keyUsage" => { "values" => %w[digitalSignature keyEncipherment], "critical" => true },
 
  68                  "extendedKeyUsage" => { "values" => %w[serverAuth clientAuth], "critical" => true }
 
  74   file "/etc/ssl/certs/#{new_resource.certificate}.pem" do
 
  78   file "/etc/ssl/private/#{new_resource.certificate}.key" do
 
  85     @letsencrypt ||= search(:letsencrypt, "id:#{new_resource.certificate}").first