]> git.openstreetmap.org Git - chef.git/blob - cookbooks/dns/recipes/default.rb
Publish IP lists from dns.openstreetmap.org
[chef.git] / cookbooks / dns / recipes / default.rb
1 #
2 # Cookbook:: dns
3 # Recipe:: default
4 #
5 # Copyright:: 2011, OpenStreetMap Foundation
6 #
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
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
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.
18 #
19
20 include_recipe "accounts"
21 include_recipe "apache"
22 include_recipe "git"
23
24 geoservers = search(:node, "roles:geodns").collect(&:name).sort
25
26 passwords = data_bag_item("dns", "passwords")
27
28 package %w[
29   make
30   parallel
31   rsync
32   perl
33   libdigest-sha-perl
34   libjson-xs-perl
35   libwww-perl
36   libxml-treebuilder-perl
37   libxml-writer-perl
38   libyaml-perl
39   libyaml-libyaml-perl
40   lockfile-progs
41 ]
42
43 cache_dir = Chef::Config[:file_cache_path]
44
45 dnscontrol_version = "4.23.0"
46
47 dnscontrol_arch = if arm?
48                     "arm64"
49                   else
50                     "amd64"
51                   end
52
53 remote_file "#{cache_dir}/dnscontrol-#{dnscontrol_version}.deb" do
54   source "https://github.com/StackExchange/dnscontrol/releases/download/v#{dnscontrol_version}/dnscontrol-#{dnscontrol_version}.#{dnscontrol_arch}.deb"
55   owner "root"
56   group "root"
57   mode "644"
58   backup false
59 end
60
61 dpkg_package "dnscontrol" do
62   source "#{cache_dir}/dnscontrol-#{dnscontrol_version}.deb"
63   version dnscontrol_version
64 end
65
66 directory "/srv/dns.openstreetmap.org" do
67   owner "root"
68   group "root"
69   mode "755"
70 end
71
72 remote_directory "/srv/dns.openstreetmap.org/html" do
73   source "html"
74   owner "root"
75   group "root"
76   mode "755"
77   files_owner "root"
78   files_group "root"
79   files_mode "644"
80 end
81
82 link "/srv/dns.openstreetmap.org/html/ipv4.json" do
83   to "/var/lib/dns/src/ipv4.json"
84   owner "root"
85   group "root"
86 end
87
88 link "/srv/dns.openstreetmap.org/html/ipv6.json" do
89   to "/var/lib/dns/src/ipv6.json"
90   owner "root"
91   group "root"
92 end
93
94 zones = []
95
96 Dir.glob("/var/lib/dns/json/*.json").each do |kmlfile|
97   zone = File.basename(kmlfile, ".json")
98
99   template "/srv/dns.openstreetmap.org/html/#{zone}.html" do
100     source "zone.html.erb"
101     owner "root"
102     group "root"
103     mode "644"
104     variables :zone => zone
105   end
106
107   zones.push(zone)
108 end
109
110 template "/srv/dns.openstreetmap.org/html/index.html" do
111   source "index.html.erb"
112   owner "root"
113   group "root"
114   mode "644"
115   variables :zones => zones
116 end
117
118 ssl_certificate "dns.openstreetmap.org" do
119   domains ["dns.openstreetmap.org", "dns.osm.org"]
120   notifies :reload, "service[apache2]"
121 end
122
123 apache_site "dns.openstreetmap.org" do
124   template "apache.erb"
125   directory "/srv/dns.openstreetmap.org"
126   variables :aliases => ["dns.osm.org"]
127 end
128
129 template "/usr/local/bin/dns-update" do
130   source "dns-update.erb"
131   owner "root"
132   group "git"
133   mode "750"
134   variables :passwords => passwords, :geoservers => geoservers
135 end
136
137 execute "dns-update" do
138   action :nothing
139   command "/usr/local/bin/dns-update"
140   user "git"
141   group "git"
142 end
143
144 directory "/var/lib/dns" do
145   owner "git"
146   group "git"
147   mode "2775"
148   notifies :run, "execute[dns-update]"
149 end
150
151 template "/var/lib/dns/creds.json" do
152   source "creds.json.erb"
153   owner "git"
154   group "git"
155   mode "440"
156   variables :passwords => passwords
157 end
158
159 template "/var/lib/dns/include/geo.js" do
160   source "geo.js.erb"
161   owner "git"
162   group "git"
163   mode "440"
164   variables :geoservers => geoservers
165   only_if { ::Dir.exist?("/var/lib/dns/include") }
166 end
167
168 cookbook_file "#{node[:dns][:repository]}/hooks/post-receive" do
169   source "post-receive"
170   owner "git"
171   group "git"
172   mode "750"
173   only_if { ::Dir.exist?("#{node[:dns][:repository]}/hooks") }
174 end
175
176 template "/usr/local/bin/dns-check" do
177   source "dns-check.erb"
178   owner "root"
179   group "git"
180   mode "750"
181   variables :passwords => passwords, :geoservers => geoservers
182 end
183
184 systemd_service "dns-check" do
185   description "Rebuild DNS zones with GeoDNS changes"
186   exec_start "/usr/local/bin/dns-check"
187   user "git"
188   runtime_max_sec 90
189   sandbox :enable_network => true
190   proc_subset "all"
191   read_write_paths "/var/lib/dns"
192 end
193
194 systemd_timer "dns-check" do
195   description "Rebuild DNS zones with GeoDNS changes"
196   on_boot_sec "3m"
197   on_unit_active_sec "3m"
198 end
199
200 service "dns-check.timer" do
201   action [:enable, :start]
202 end