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")
32 directory "/etc/letsencrypt" do
38 directory "/var/lib/letsencrypt" do
44 directory "/var/log/letsencrypt" do
50 directory "/srv/acme.openstreetmap.org" do
56 directory "/srv/acme.openstreetmap.org/html" do
62 ssl_certificate "acme.openstreetmap.org" do
63 domains ["acme.openstreetmap.org", "acme.osm.org"]
64 notifies :reload, "service[apache2]"
67 apache_site "acme.openstreetmap.org" do
69 directory "/srv/acme.openstreetmap.org"
72 directory "/srv/acme.openstreetmap.org/config" do
78 directory "/srv/acme.openstreetmap.org/work" do
84 directory "/srv/acme.openstreetmap.org/logs" do
90 directory "/srv/acme.openstreetmap.org/.chef" do
96 file "/srv/acme.openstreetmap.org/.chef/client.pem" do
97 content keys["letsencrypt"].join("\n")
103 cookbook_file "/srv/acme.openstreetmap.org/.chef/knife.rb" do
110 remote_directory "/srv/acme.openstreetmap.org/bin" do
120 directory "/srv/acme.openstreetmap.org/requests" do
126 certificates = search(:node, "letsencrypt:certificates").each_with_object({}) do |n, c|
127 n[:letsencrypt][:certificates].each do |name, details|
128 c[name] ||= details.merge(:nodes => [])
132 :address => n.external_ipaddress || n.internal_ipaddress
137 certificates.each do |name, details|
138 template "/srv/acme.openstreetmap.org/requests/#{name}" do
146 execute "/srv/acme.openstreetmap.org/requests/#{name}" do
148 command "/srv/acme.openstreetmap.org/requests/#{name}"
149 cwd "/srv/acme.openstreetmap.org"
152 subscribes :run, "template[/srv/acme.openstreetmap.org/requests/#{name}]"
157 Dir.glob("*", :base => "/srv/acme.openstreetmap.org/requests") do |name|
158 next if certificates.include?(name)
160 file "/srv/acme.openstreetmap.org/requests/#{name}" do
164 execute "certbot-delete-#{name}" do
165 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}"
166 cwd "/srv/acme.openstreetmap.org"
172 template "/srv/acme.openstreetmap.org/bin/check-certificates" do
173 source "check-certificates.erb"
177 variables :certificates => certificates
180 cron_d "letencrypt-renew" do
184 command "/srv/acme.openstreetmap.org/bin/renew"
185 mailto "admins@openstreetmap.org"
188 cron_d "letencrypt-check" do
192 command "/srv/acme.openstreetmap.org/bin/check-certificates"
193 mailto "admins@openstreetmap.org"
196 template "/etc/logrotate.d/letsencrypt" do
197 source "logrotate.erb"