]> git.openstreetmap.org Git - chef.git/blob - cookbooks/exim/recipes/default.rb
6b20f5181592f7c7213069fd129b086ca61f85bc
[chef.git] / cookbooks / exim / recipes / default.rb
1 #
2 # Cookbook Name:: 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
22 package %w[
23   exim4
24   openssl
25   ssl-cert
26 ]
27
28 package "exim4-daemon-heavy" if File.exist?("/var/run/clamav/clamd.ctl")
29
30 group "ssl-cert" do
31   action :modify
32   members "Debian-exim"
33   append true
34 end
35
36 openssl_x509_certificate "/etc/ssl/certs/exim.pem" do
37   key_file "/etc/ssl/private/exim.key"
38   owner "root"
39   group "ssl-cert"
40   mode 0o640
41   org "OpenStreetMap"
42   email "postmaster@openstreetmap.org"
43   common_name node[:fqdn]
44   expire 3650
45 end
46
47 service "exim4" do
48   action [:enable, :start]
49   supports :status => true, :restart => true, :reload => true
50   subscribes :restart, "execute[/etc/ssl/certs/exim.pem]"
51 end
52
53 relay_to_domains = node[:exim][:relay_to_domains]
54
55 node[:exim][:routes].each_value do |route|
56   relay_to_domains |= route[:domains] if route[:host]
57 end
58
59 relay_from_hosts = node[:exim][:relay_from_hosts]
60
61 if node[:exim][:smarthost_name]
62   search(:node, "exim_smarthost_via:#{node[:exim][:smarthost_name]}\\:*").each do |host|
63     relay_from_hosts |= host.ipaddresses(:role => :external)
64   end
65 end
66
67 file "/etc/exim4/blocked-senders" do
68   owner "root"
69   group "Debian-exim"
70   mode 0o644
71 end
72
73 template "/etc/exim4/exim4.conf" do
74   source "exim4.conf.erb"
75   owner "root"
76   group "Debian-exim"
77   mode 0o644
78   variables :relay_to_domains => relay_to_domains.sort,
79             :relay_from_hosts => relay_from_hosts.sort
80   notifies :restart, "service[exim4]"
81 end
82
83 search(:accounts, "*:*").each do |account|
84   name = account["id"]
85   details = node[:accounts][:users][name] || {}
86
87   if details[:status] && account["email"]
88     node.default[:exim][:aliases][name] = account["email"]
89   end
90 end
91
92 if node[:exim][:private_aliases]
93   aliases = data_bag_item("exim", "aliases")
94
95   aliases[node[:exim][:private_aliases]].each do |name, address|
96     node.default[:exim][:aliases][name] = address
97   end
98 end
99
100 template "/etc/aliases" do
101   source "aliases.erb"
102   owner "root"
103   group "root"
104   mode 0o644
105 end
106
107 remote_directory "/etc/exim4/noreply" do
108   source "noreply"
109   owner "root"
110   group "Debian-exim"
111   mode 0o755
112   files_owner "root"
113   files_group "Debian-exim"
114   files_mode 0o755
115   purge true
116 end
117
118 munin_plugin "exim_mailqueue"
119 munin_plugin "exim_mailstats"
120
121 if node[:exim][:smarthost_name]
122   node[:exim][:daemon_smtp_ports].each do |port|
123     firewall_rule "accept-inbound-smtp-#{port}" do
124       action :accept
125       source "net"
126       dest "fw"
127       proto "tcp:syn"
128       dest_ports port
129       source_ports "1024:"
130     end
131   end
132 else
133   node[:exim][:daemon_smtp_ports].each do |port|
134     firewall_rule "accept-inbound-smtp-#{port}" do
135       action :accept
136       source "bm:mail.openstreetmap.org"
137       dest "fw"
138       proto "tcp:syn"
139       dest_ports port
140       source_ports "1024:"
141     end
142   end
143 end
144
145 if node[:exim][:smarthost_via] # ~FC023
146   firewall_rule "deny-outbound-smtp" do
147     action :reject
148     source "fw"
149     dest "net"
150     proto "tcp:syn"
151     dest_ports "smtp"
152   end
153 end