]> git.openstreetmap.org Git - chef.git/blob - cookbooks/exim/recipes/default.rb
Avoid accessing form data for OPTIONS requests
[chef.git] / cookbooks / exim / recipes / default.rb
1 #
2 # Cookbook:: exim
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 "networking"
21 include_recipe "prometheus"
22
23 package %w[
24   exim4
25   openssl
26   ssl-cert
27   mailutils
28 ]
29
30 package "exim4-daemon-heavy" do
31   only_if { ::File.exist?("/var/run/clamav/clamd.ctl") }
32 end
33
34 group "Debian-exim" do
35   action :modify
36   members "clamav"
37   append true
38   only_if { ::File.exist?("/var/run/clamav/clamd.ctl") }
39 end
40
41 group "ssl-cert" do
42   action :modify
43   members "Debian-exim"
44   append true
45 end
46
47 if node[:exim][:certificate_names]
48   include_recipe "apache"
49
50   apache_site "default" do
51     action [:disable]
52   end
53
54   apache_site node[:exim][:certificate_names].first do
55     template "apache.erb"
56     variables :aliases => node[:exim][:certificate_names].drop(1)
57   end
58
59   ssl_certificate node[:exim][:certificate_names].first do
60     domains node[:exim][:certificate_names]
61     notifies :restart, "service[exim4]"
62   end
63 else
64   openssl_x509_certificate "/etc/ssl/certs/exim.pem" do
65     key_file "/etc/ssl/private/exim.key"
66     owner "root"
67     group "ssl-cert"
68     mode "640"
69     org "OpenStreetMap"
70     email "postmaster@openstreetmap.org"
71     common_name node[:fqdn]
72     expire 3650
73     notifies :restart, "service[exim4]"
74   end
75 end
76
77 service "exim4" do
78   action [:enable, :start]
79   supports :status => true, :restart => true, :reload => true
80 end
81
82 relay_to_domains = node[:exim][:relay_to_domains]
83
84 node[:exim][:routes].each_value do |route|
85   relay_to_domains |= route[:domains] if route[:host]
86 end
87
88 relay_from_hosts = node[:exim][:relay_from_hosts]
89
90 if node[:exim][:smarthost_name]
91   search(:node, "exim_smarthost_via:*?").each do |host|
92     relay_from_hosts |= host.ipaddresses(:role => :external)
93   end
94
95   domains = node[:exim][:certificate_names].select { |c| c =~ /^a\.mx\./ }.collect { |c| c.sub(/^a\.mx./, "") }
96   primary_domain = domains.first
97
98   directory "/srv/mta-sts.#{primary_domain}" do
99     owner "root"
100     group "root"
101     mode "755"
102   end
103
104   domains.each do |domain|
105     template "/srv/mta-sts.#{primary_domain}/#{domain}.txt" do
106       source "mta-sts.erb"
107       owner "root"
108       group "root"
109       mode "644"
110       variables :domain => domain
111     end
112   end
113
114   ssl_certificate "mta-sts.#{primary_domain}" do
115     domains domains.collect { |d| "mta-sts.#{d}" }
116     notifies :reload, "service[apache2]"
117   end
118
119   apache_site "mta-sts.#{primary_domain}" do
120     template "apache-mta-sts.erb"
121     directory "/srv/mta-sts.#{primary_domain}"
122     variables :domains => domains
123   end
124 end
125
126 file "/etc/exim4/blocked-senders" do
127   owner "root"
128   group "Debian-exim"
129   mode "644"
130 end
131
132 file "/etc/exim4/blocked-sender-domains" do
133   owner "root"
134   group "Debian-exim"
135   mode "644"
136 end
137
138 file "/etc/exim4/detaint" do
139   owner "root"
140   group "Debian-exim"
141   mode "644"
142   content "*"
143 end
144
145 if node[:exim][:dkim_selectors]
146   keys = data_bag_item("exim", "dkim")
147
148   template "/etc/exim4/dkim-domains" do
149     owner "root"
150     source "dkim-domains.erb"
151     group "Debian-exim"
152     mode "644"
153   end
154
155   template "/etc/exim4/dkim-selectors" do
156     owner "root"
157     source "dkim-selectors.erb"
158     group "Debian-exim"
159     mode "644"
160   end
161
162   directory "/etc/exim4/dkim-keys" do
163     owner "root"
164     group "Debian-exim"
165     mode "755"
166   end
167
168   node[:exim][:dkim_selectors].each_key do |domain|
169     file "/etc/exim4/dkim-keys/#{domain}" do
170       content keys[domain].join("\n")
171       owner "root"
172       group "Debian-exim"
173       mode "640"
174     end
175   end
176 end
177
178 template "/etc/default/exim4" do
179   source "default.erb"
180   owner "root"
181   group "root"
182   mode "044"
183   notifies :restart, "service[exim4]"
184 end
185
186 template "/etc/exim4/exim4.conf" do
187   source "exim4.conf.erb"
188   owner "root"
189   group "Debian-exim"
190   mode "644"
191   variables :relay_to_domains => relay_to_domains.sort,
192             :relay_from_hosts => relay_from_hosts.sort
193   notifies :restart, "service[exim4]"
194 end
195
196 search(:accounts, "*:*").each do |account|
197   name = account["id"]
198   details = node[:accounts][:users][name] || {}
199
200   if details[:status] && account["email"]
201     node.default[:exim][:aliases][name] = account["email"]
202   end
203 end
204
205 if node[:exim][:private_aliases]
206   aliases = data_bag_item("exim", "aliases")
207
208   aliases[node[:exim][:private_aliases]].each do |name, address|
209     node.default[:exim][:aliases][name] = address
210   end
211 end
212
213 template "/etc/aliases" do
214   source "aliases.erb"
215   owner "root"
216   group "root"
217   mode "644"
218 end
219
220 remote_directory "/etc/exim4/noreply" do
221   source "noreply"
222   owner "root"
223   group "Debian-exim"
224   mode "755"
225   files_owner "root"
226   files_group "Debian-exim"
227   files_mode "755"
228   purge true
229 end
230
231 template "/etc/mail.rc" do
232   source "mail.rc.erb"
233   owner "root"
234   group "root"
235   mode "644"
236 end
237
238 prometheus_exporter "exim" do
239   port 9636
240   user "Debian-exim"
241   protect_proc "default"
242 end
243
244 if node[:exim][:smarthost_name]
245   firewall_rule "accept-inbound-smtp" do
246     action :accept
247     context :incoming
248     protocol :tcp
249     dest_ports node[:exim][:daemon_smtp_ports]
250     source_ports "1024-65535"
251   end
252 else
253   smarthosts = []
254
255   search(:node, "exim_smarthost_name:*?").each do |host|
256     smarthosts |= host.ipaddresses(:role => :external)
257   end
258
259   firewall_rule "accept-inbound-smtp" do
260     action :accept
261     context :incoming
262     protocol :tcp
263     source smarthosts
264     dest_ports node[:exim][:daemon_smtp_ports]
265     source_ports "1024-65535"
266     not_if { smarthosts.empty? }
267   end
268 end
269
270 if node[:exim][:smarthost_via]
271   firewall_rule "deny-outbound-smtp" do
272     action :reject
273     context :outgoing
274     protocol :tcp
275     dest_ports "smtp"
276   end
277 end