2 # Cookbook:: letsencrypt
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 include_recipe "accounts"
21 include_recipe "apache"
23 keys = data_bag_item("chef", "keys")
30 directory "/etc/letsencrypt" do
36 directory "/var/lib/letsencrypt" do
42 directory "/var/log/letsencrypt" do
48 directory "/srv/acme.openstreetmap.org" do
54 directory "/srv/acme.openstreetmap.org/html" do
60 ssl_certificate "acme.openstreetmap.org" do
61 domains ["acme.openstreetmap.org", "acme.osm.org"]
62 notifies :reload, "service[apache2]"
65 apache_site "acme.openstreetmap.org" do
67 directory "/srv/acme.openstreetmap.org"
70 directory "/srv/acme.openstreetmap.org/config" do
76 directory "/srv/acme.openstreetmap.org/work" do
82 directory "/srv/acme.openstreetmap.org/logs" do
88 directory "/srv/acme.openstreetmap.org/.chef" do
94 file "/srv/acme.openstreetmap.org/.chef/client.pem" do
95 content keys["letsencrypt"].join("\n")
101 cookbook_file "/srv/acme.openstreetmap.org/.chef/knife.rb" do
108 remote_directory "/srv/acme.openstreetmap.org/bin" do
118 directory "/srv/acme.openstreetmap.org/requests" do
124 certificates = search(:node, "letsencrypt:certificates").each_with_object({}) do |n, c|
125 n[:letsencrypt][:certificates].each do |name, details|
126 c[name] ||= details.merge(:nodes => [])
130 :address => n.external_ipaddress || n.internal_ipaddress
135 certificates.each do |name, details|
136 template "/srv/acme.openstreetmap.org/requests/#{name}" do
144 execute "/srv/acme.openstreetmap.org/requests/#{name}" do
146 command "/srv/acme.openstreetmap.org/requests/#{name}"
147 cwd "/srv/acme.openstreetmap.org"
150 subscribes :run, "template[/srv/acme.openstreetmap.org/requests/#{name}]"
151 not_if { ENV["TEST_KITCHEN"] }
155 Dir.glob("*", :base => "/srv/acme.openstreetmap.org/requests") do |name|
156 next if certificates.include?(name)
158 file "/srv/acme.openstreetmap.org/requests/#{name}" do
162 execute "certbot-delete-#{name}" do
163 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}"
164 cwd "/srv/acme.openstreetmap.org"
170 template "/srv/acme.openstreetmap.org/bin/check-certificates" do
171 source "check-certificates.erb"
175 variables :certificates => certificates
178 cron_d "letencrypt-renew" do
182 command "/srv/acme.openstreetmap.org/bin/renew"
183 mailto "admins@openstreetmap.org"
186 cron_d "letencrypt-check" do
190 command "/srv/acme.openstreetmap.org/bin/check-certificates"
191 mailto "admins@openstreetmap.org"