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"
 
  30 package "exim4-daemon-heavy" do
 
  31   only_if { ::File.exist?("/var/run/clamav/clamd.ctl") }
 
  40 if node[:exim][:certificate_names]
 
  41   include_recipe "apache"
 
  43   apache_site node[:exim][:certificate_names].first do
 
  45     variables :aliases => node[:exim][:certificate_names].drop(1)
 
  48   ssl_certificate node[:exim][:certificate_names].first do
 
  49     domains node[:exim][:certificate_names]
 
  50     notifies :restart, "service[exim4]"
 
  53   openssl_x509_certificate "/etc/ssl/certs/exim.pem" do
 
  54     key_file "/etc/ssl/private/exim.key"
 
  59     email "postmaster@openstreetmap.org"
 
  60     common_name node[:fqdn]
 
  62     notifies :restart, "service[exim4]"
 
  67   action [:enable, :start]
 
  68   supports :status => true, :restart => true, :reload => true
 
  71 relay_to_domains = node[:exim][:relay_to_domains]
 
  73 node[:exim][:routes].each_value do |route|
 
  74   relay_to_domains |= route[:domains] if route[:host]
 
  77 relay_from_hosts = node[:exim][:relay_from_hosts]
 
  79 if node[:exim][:smarthost_name]
 
  80   search(:node, "roles:gateway") do |gateway|
 
  81     allowed_ips = gateway.interfaces(:role => :internal).map do |interface|
 
  82       "#{interface[:network]}/#{interface[:prefix]}"
 
  85     node.default[:networking][:wireguard][:peers] << {
 
  86       :public_key => gateway[:networking][:wireguard][:public_key],
 
  87       :allowed_ips => allowed_ips,
 
  88       :endpoint => "#{gateway.name}:51820"
 
  92   search(:node, "exim_smarthost_via:#{node[:exim][:smarthost_name]}\\:*").each do |host|
 
  93     relay_from_hosts |= host.ipaddresses(:role => :external)
 
  96   domains = node[:exim][:certificate_names].select { |c| c =~ /^a\.mx\./ }.collect { |c| c.sub(/^a\.mx./, "") }
 
  97   primary_domain = domains.first
 
  99   directory "/srv/mta-sts.#{primary_domain}" do
 
 105   domains.each do |domain|
 
 106     template "/srv/mta-sts.#{primary_domain}/#{domain}.txt" do
 
 111       variables :domain => domain
 
 115   ssl_certificate "mta-sts.#{primary_domain}" do
 
 116     domains domains.collect { |d| "mta-sts.#{d}" }
 
 117     notifies :reload, "service[apache2]"
 
 120   apache_site "mta-sts.#{primary_domain}" do
 
 121     template "apache-mta-sts.erb"
 
 122     directory "/srv/mta-sts.#{primary_domain}"
 
 123     variables :domains => domains
 
 127 file "/etc/exim4/blocked-senders" do
 
 133 if node[:exim][:dkim_selectors]
 
 134   keys = data_bag_item("exim", "dkim")
 
 136   template "/etc/exim4/dkim-domains" do
 
 138     source "dkim-domains.erb"
 
 143   template "/etc/exim4/dkim-selectors" do
 
 145     source "dkim-selectors.erb"
 
 150   directory "/etc/exim4/dkim-keys" do
 
 156   node[:exim][:dkim_selectors].each do |domain, _selector|
 
 157     file "/etc/exim4/dkim-keys/#{domain}" do
 
 158       content keys[domain].join("\n")
 
 166 template "/etc/default/exim4" do
 
 171   notifies :restart, "service[exim4]"
 
 174 template "/etc/exim4/exim4.conf" do
 
 175   source "exim4.conf.erb"
 
 179   variables :relay_to_domains => relay_to_domains.sort,
 
 180             :relay_from_hosts => relay_from_hosts.sort
 
 181   notifies :restart, "service[exim4]"
 
 184 search(:accounts, "*:*").each do |account|
 
 186   details = node[:accounts][:users][name] || {}
 
 188   if details[:status] && account["email"]
 
 189     node.default[:exim][:aliases][name] = account["email"]
 
 193 if node[:exim][:private_aliases]
 
 194   aliases = data_bag_item("exim", "aliases")
 
 196   aliases[node[:exim][:private_aliases]].each do |name, address|
 
 197     node.default[:exim][:aliases][name] = address
 
 201 template "/etc/aliases" do
 
 208 remote_directory "/etc/exim4/noreply" do
 
 214   files_group "Debian-exim"
 
 219 munin_plugin "exim_mailqueue"
 
 220 munin_plugin "exim_mailstats"
 
 222 prometheus_exporter "exim" do
 
 226 if node[:exim][:smarthost_name]
 
 227   node[:exim][:daemon_smtp_ports].each do |port|
 
 228     firewall_rule "accept-inbound-smtp-#{port}" do
 
 238   node[:exim][:daemon_smtp_ports].each do |port|
 
 239     firewall_rule "accept-inbound-smtp-#{port}" do
 
 241       source "bm:mail.openstreetmap.org"
 
 250 if node[:exim][:smarthost_via]
 
 251   firewall_rule "deny-outbound-smtp" do