5 # Copyright:: 2011, 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 "munin"
21 include_recipe "networking"
22 include_recipe "prometheus"
31 package "exim4-daemon-heavy" do
32 only_if { ::File.exist?("/var/run/clamav/clamd.ctl") }
35 group "Debian-exim" do
39 only_if { ::File.exist?("/var/run/clamav/clamd.ctl") }
48 if node[:exim][:certificate_names]
49 include_recipe "apache"
51 apache_site node[:exim][:certificate_names].first do
53 variables :aliases => node[:exim][:certificate_names].drop(1)
56 ssl_certificate node[:exim][:certificate_names].first do
57 domains node[:exim][:certificate_names]
58 notifies :restart, "service[exim4]"
61 openssl_x509_certificate "/etc/ssl/certs/exim.pem" do
62 key_file "/etc/ssl/private/exim.key"
67 email "postmaster@openstreetmap.org"
68 common_name node[:fqdn]
70 notifies :restart, "service[exim4]"
75 action [:enable, :start]
76 supports :status => true, :restart => true, :reload => true
79 relay_to_domains = node[:exim][:relay_to_domains]
81 node[:exim][:routes].each_value do |route|
82 relay_to_domains |= route[:domains] if route[:host]
85 relay_from_hosts = node[:exim][:relay_from_hosts]
87 if node[:exim][:smarthost_name]
88 search(:node, "exim_smarthost_via:*?").each do |host|
89 relay_from_hosts |= host.ipaddresses(:role => :external)
92 domains = node[:exim][:certificate_names].select { |c| c =~ /^a\.mx\./ }.collect { |c| c.sub(/^a\.mx./, "") }
93 primary_domain = domains.first
95 directory "/srv/mta-sts.#{primary_domain}" do
101 domains.each do |domain|
102 template "/srv/mta-sts.#{primary_domain}/#{domain}.txt" do
107 variables :domain => domain
111 ssl_certificate "mta-sts.#{primary_domain}" do
112 domains domains.collect { |d| "mta-sts.#{d}" }
113 notifies :reload, "service[apache2]"
116 apache_site "mta-sts.#{primary_domain}" do
117 template "apache-mta-sts.erb"
118 directory "/srv/mta-sts.#{primary_domain}"
119 variables :domains => domains
123 file "/etc/exim4/blocked-senders" do
129 if node[:exim][:dkim_selectors]
130 keys = data_bag_item("exim", "dkim")
132 template "/etc/exim4/dkim-domains" do
134 source "dkim-domains.erb"
139 template "/etc/exim4/dkim-selectors" do
141 source "dkim-selectors.erb"
146 directory "/etc/exim4/dkim-keys" do
152 node[:exim][:dkim_selectors].each do |domain, _selector|
153 file "/etc/exim4/dkim-keys/#{domain}" do
154 content keys[domain].join("\n")
162 template "/etc/default/exim4" do
167 notifies :restart, "service[exim4]"
170 template "/etc/exim4/exim4.conf" do
171 source "exim4.conf.erb"
175 variables :relay_to_domains => relay_to_domains.sort,
176 :relay_from_hosts => relay_from_hosts.sort
177 notifies :restart, "service[exim4]"
180 search(:accounts, "*:*").each do |account|
182 details = node[:accounts][:users][name] || {}
184 if details[:status] && account["email"]
185 node.default[:exim][:aliases][name] = account["email"]
189 if node[:exim][:private_aliases]
190 aliases = data_bag_item("exim", "aliases")
192 aliases[node[:exim][:private_aliases]].each do |name, address|
193 node.default[:exim][:aliases][name] = address
197 template "/etc/aliases" do
204 remote_directory "/etc/exim4/noreply" do
210 files_group "Debian-exim"
215 template "/etc/mail.rc" do
222 munin_plugin "exim_mailqueue"
223 munin_plugin "exim_mailstats"
225 prometheus_exporter "exim" do
228 protect_proc "default"
231 if node[:exim][:smarthost_name]
232 node[:exim][:daemon_smtp_ports].each do |port|
233 firewall_rule "accept-inbound-smtp-#{port}" do
239 source_ports "1024-65535"
244 smarthosts_inet6 = []
246 search(:node, "exim_smarthost_name:*?").each do |host|
247 smarthosts_inet |= host.ipaddresses(:role => :external, :family => :inet)
248 smarthosts_inet6 |= host.ipaddresses(:role => :external, :family => :inet6)
251 node[:exim][:daemon_smtp_ports].each do |port|
252 firewall_rule "accept-inbound-smtp-#{port}" do
255 source "net:#{smarthosts_inet.sort.join(',')}"
259 source_ports "1024-65535"
260 not_if { smarthosts_inet.empty? }
263 firewall_rule "accept-inbound-smtp-#{port}" do
266 source "net:#{smarthosts_inet6.sort.join(',')}"
270 source_ports "1024-65535"
271 not_if { smarthosts_inet6.empty? }
276 if node[:exim][:smarthost_via]
277 firewall_rule "deny-outbound-smtp" do