]> git.openstreetmap.org Git - chef.git/blob - cookbooks/exim/recipes/default.rb
Tweak some tile sandboxes
[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 "munin"
21 include_recipe "networking"
22 include_recipe "prometheus"
23
24 package %w[
25   exim4
26   openssl
27   ssl-cert
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 node[:exim][:certificate_names].first do
51     template "apache.erb"
52     variables :aliases => node[:exim][:certificate_names].drop(1)
53   end
54
55   ssl_certificate node[:exim][:certificate_names].first do
56     domains node[:exim][:certificate_names]
57     notifies :restart, "service[exim4]"
58   end
59 else
60   openssl_x509_certificate "/etc/ssl/certs/exim.pem" do
61     key_file "/etc/ssl/private/exim.key"
62     owner "root"
63     group "ssl-cert"
64     mode "640"
65     org "OpenStreetMap"
66     email "postmaster@openstreetmap.org"
67     common_name node[:fqdn]
68     expire 3650
69     notifies :restart, "service[exim4]"
70   end
71 end
72
73 service "exim4" do
74   action [:enable, :start]
75   supports :status => true, :restart => true, :reload => true
76 end
77
78 relay_to_domains = node[:exim][:relay_to_domains]
79
80 node[:exim][:routes].each_value do |route|
81   relay_to_domains |= route[:domains] if route[:host]
82 end
83
84 relay_from_hosts = node[:exim][:relay_from_hosts]
85
86 if node[:exim][:smarthost_name]
87   search(:node, "exim_smarthost_via:#{node[:exim][:smarthost_name]}\\:*").each do |host|
88     relay_from_hosts |= host.ipaddresses(:role => :external)
89   end
90
91   domains = node[:exim][:certificate_names].select { |c| c =~ /^a\.mx\./ }.collect { |c| c.sub(/^a\.mx./, "") }
92   primary_domain = domains.first
93
94   directory "/srv/mta-sts.#{primary_domain}" do
95     owner "root"
96     group "root"
97     mode "755"
98   end
99
100   domains.each do |domain|
101     template "/srv/mta-sts.#{primary_domain}/#{domain}.txt" do
102       source "mta-sts.erb"
103       owner "root"
104       group "root"
105       mode "644"
106       variables :domain => domain
107     end
108   end
109
110   ssl_certificate "mta-sts.#{primary_domain}" do
111     domains domains.collect { |d| "mta-sts.#{d}" }
112     notifies :reload, "service[apache2]"
113   end
114
115   apache_site "mta-sts.#{primary_domain}" do
116     template "apache-mta-sts.erb"
117     directory "/srv/mta-sts.#{primary_domain}"
118     variables :domains => domains
119   end
120 end
121
122 file "/etc/exim4/blocked-senders" do
123   owner "root"
124   group "Debian-exim"
125   mode "644"
126 end
127
128 if node[:exim][:dkim_selectors]
129   keys = data_bag_item("exim", "dkim")
130
131   template "/etc/exim4/dkim-domains" do
132     owner "root"
133     source "dkim-domains.erb"
134     group "Debian-exim"
135     mode "644"
136   end
137
138   template "/etc/exim4/dkim-selectors" do
139     owner "root"
140     source "dkim-selectors.erb"
141     group "Debian-exim"
142     mode "644"
143   end
144
145   directory "/etc/exim4/dkim-keys" do
146     owner "root"
147     group "Debian-exim"
148     mode "755"
149   end
150
151   node[:exim][:dkim_selectors].each do |domain, _selector|
152     file "/etc/exim4/dkim-keys/#{domain}" do
153       content keys[domain].join("\n")
154       owner "root"
155       group "Debian-exim"
156       mode "640"
157     end
158   end
159 end
160
161 template "/etc/default/exim4" do
162   source "default.erb"
163   owner "root"
164   group "root"
165   mode "044"
166   notifies :restart, "service[exim4]"
167 end
168
169 template "/etc/exim4/exim4.conf" do
170   source "exim4.conf.erb"
171   owner "root"
172   group "Debian-exim"
173   mode "644"
174   variables :relay_to_domains => relay_to_domains.sort,
175             :relay_from_hosts => relay_from_hosts.sort
176   notifies :restart, "service[exim4]"
177 end
178
179 search(:accounts, "*:*").each do |account|
180   name = account["id"]
181   details = node[:accounts][:users][name] || {}
182
183   if details[:status] && account["email"]
184     node.default[:exim][:aliases][name] = account["email"]
185   end
186 end
187
188 if node[:exim][:private_aliases]
189   aliases = data_bag_item("exim", "aliases")
190
191   aliases[node[:exim][:private_aliases]].each do |name, address|
192     node.default[:exim][:aliases][name] = address
193   end
194 end
195
196 template "/etc/aliases" do
197   source "aliases.erb"
198   owner "root"
199   group "root"
200   mode "644"
201 end
202
203 remote_directory "/etc/exim4/noreply" do
204   source "noreply"
205   owner "root"
206   group "Debian-exim"
207   mode "755"
208   files_owner "root"
209   files_group "Debian-exim"
210   files_mode "755"
211   purge true
212 end
213
214 munin_plugin "exim_mailqueue"
215 munin_plugin "exim_mailstats"
216
217 prometheus_exporter "exim" do
218   port 9636
219 end
220
221 if node[:exim][:smarthost_name]
222   node[:exim][:daemon_smtp_ports].each do |port|
223     firewall_rule "accept-inbound-smtp-#{port}" do
224       action :accept
225       source "net"
226       dest "fw"
227       proto "tcp:syn"
228       dest_ports port
229       source_ports "1024:"
230     end
231   end
232 else
233   node[:exim][:daemon_smtp_ports].each do |port|
234     firewall_rule "accept-inbound-smtp-#{port}" do
235       action :accept
236       source "bm:mail.openstreetmap.org"
237       dest "fw"
238       proto "tcp:syn"
239       dest_ports port
240       source_ports "1024:"
241     end
242   end
243 end
244
245 if node[:exim][:smarthost_via]
246   firewall_rule "deny-outbound-smtp" do
247     action :reject
248     source "fw"
249     dest "net"
250     proto "tcp:syn"
251     dest_ports "smtp"
252   end
253 end