X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/90a99a9591ff08a70463403ad1dba1a2d7939881..cad29d0634cd10b0ee94e5e4974210e0ca01ae6f:/cookbooks/letsencrypt/recipes/default.rb?ds=sidebyside diff --git a/cookbooks/letsencrypt/recipes/default.rb b/cookbooks/letsencrypt/recipes/default.rb index 34e9be8f7..92c78a51d 100644 --- a/cookbooks/letsencrypt/recipes/default.rb +++ b/cookbooks/letsencrypt/recipes/default.rb @@ -1,14 +1,14 @@ # -# Cookbook Name:: letsencrypt +# Cookbook:: letsencrypt # Recipe:: default # -# 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. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -17,7 +17,9 @@ # limitations under the License. # +include_recipe "accounts" include_recipe "apache" +include_recipe "chef::knife" keys = data_bag_item("chef", "keys") @@ -29,31 +31,31 @@ package %w[ directory "/etc/letsencrypt" do owner "letsencrypt" group "letsencrypt" - mode 0o755 + mode "755" end directory "/var/lib/letsencrypt" do owner "letsencrypt" group "letsencrypt" - mode 0o755 + mode "755" end directory "/var/log/letsencrypt" do owner "letsencrypt" group "letsencrypt" - mode 0o700 + mode "700" end directory "/srv/acme.openstreetmap.org" do owner "letsencrypt" group "letsencrypt" - mode 0o755 + mode "755" end directory "/srv/acme.openstreetmap.org/html" do owner "letsencrypt" group "letsencrypt" - mode 0o755 + mode "755" end ssl_certificate "acme.openstreetmap.org" do @@ -69,62 +71,65 @@ end directory "/srv/acme.openstreetmap.org/config" do owner "letsencrypt" group "letsencrypt" - mode 0o755 + mode "755" end directory "/srv/acme.openstreetmap.org/work" do owner "letsencrypt" group "letsencrypt" - mode 0o755 + mode "755" end directory "/srv/acme.openstreetmap.org/logs" do owner "letsencrypt" group "letsencrypt" - mode 0o700 + mode "700" end directory "/srv/acme.openstreetmap.org/.chef" do owner "letsencrypt" group "letsencrypt" - mode 0o2775 + mode "2775" end file "/srv/acme.openstreetmap.org/.chef/client.pem" do content keys["letsencrypt"].join("\n") owner "letsencrypt" group "letsencrypt" - mode 0o660 + mode "660" end cookbook_file "/srv/acme.openstreetmap.org/.chef/knife.rb" do source "knife.rb" owner "letsencrypt" group "letsencrypt" - mode 0o660 + mode "660" end remote_directory "/srv/acme.openstreetmap.org/bin" do source "bin" owner "root" group "root" - mode 0o755 + mode "755" files_owner "root" files_group "root" - files_mode 0o755 + files_mode "755" end directory "/srv/acme.openstreetmap.org/requests" do owner "root" group "root" - mode 0o755 + mode "755" end certificates = search(:node, "letsencrypt:certificates").each_with_object({}) do |n, c| n[:letsencrypt][:certificates].each do |name, details| c[name] ||= details.merge(:nodes => []) - c[name][:nodes] << { :name => n[:fqdn], :address => n[:ipaddress] } + c[name][:nodes] << { + :name => n[:fqdn], + :address => n.external_ipaddress || n.internal_ipaddress + } end end @@ -133,7 +138,7 @@ certificates.each do |name, details| source "request.erb" owner "root" group "letsencrypt" - mode 0o754 + mode "754" variables details end @@ -144,6 +149,22 @@ certificates.each do |name, details| user "letsencrypt" group "letsencrypt" subscribes :run, "template[/srv/acme.openstreetmap.org/requests/#{name}]" + not_if { kitchen? } + end +end + +Dir.glob("*", :base => "/srv/acme.openstreetmap.org/requests") do |name| + next if certificates.include?(name) + + file "/srv/acme.openstreetmap.org/requests/#{name}" do + action :delete + end + + execute "certbot-delete-#{name}" do + command "/usr/bin/certbot delete --config-dir /srv/acme.openstreetmap.org/config --work-dir /srv/acme.openstreetmap.org/work --logs-dir /srv/acme.openstreetmap.org/logs --cert-name #{name}" + cwd "/srv/acme.openstreetmap.org" + user "letsencrypt" + group "letsencrypt" end end @@ -151,13 +172,29 @@ template "/srv/acme.openstreetmap.org/bin/check-certificates" do source "check-certificates.erb" owner "root" group "root" - mode 0o755 + mode "755" variables :certificates => certificates end -template "/etc/cron.d/letsencrypt" do - source "cron.erb" +cron_d "letencrypt-renew" do + minute "00" + hour "*/12" + user "letsencrypt" + command "/srv/acme.openstreetmap.org/bin/renew" + mailto "admins@openstreetmap.org" +end + +cron_d "letencrypt-check" do + minute "30" + hour "*/12" + user "letsencrypt" + command "/srv/acme.openstreetmap.org/bin/check-certificates" + mailto "admins@openstreetmap.org" +end + +template "/etc/logrotate.d/letsencrypt" do + source "logrotate.erb" owner "root" group "root" - mode 0o644 + mode "644" end