Commit 48c35a4b7123ab787e4aae3c74b060f751b7ef5c
1 parent
4216f9fb
Exists in
master
and in
90 other branches
email relay configuration
Showing
12 changed files
with
156 additions
and
12 deletions
Show diff stats
config/roles/email_server.rb
config/roles/server.rb
config/roles/social_server.rb
| @@ -0,0 +1,48 @@ | @@ -0,0 +1,48 @@ | ||
| 1 | +include_recipe 'email' | ||
| 2 | + | ||
| 3 | +# smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem | ||
| 4 | +# smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key | ||
| 5 | + | ||
| 6 | +postfix_config = { | ||
| 7 | + | ||
| 8 | + myhostname: node['config']['relay_hostname'], | ||
| 9 | + | ||
| 10 | + relay_domains: [ | ||
| 11 | + node['config']['lists_hostname'], | ||
| 12 | + node['config']['external_hostname'], | ||
| 13 | + ].join(', '), | ||
| 14 | + | ||
| 15 | + transport_maps: 'hash:/etc/postfix/transport', | ||
| 16 | + | ||
| 17 | + mynetworks: '127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 ' + node['peers'].values.sort.join(' '), | ||
| 18 | + | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +execute 'postfix:relay:config' do | ||
| 22 | + command postfix_config.map { |k,v| "postconf #{k}='#{v}'" }.join(' ; ') | ||
| 23 | + notifies :reload, 'service[postfix]' | ||
| 24 | +end | ||
| 25 | + | ||
| 26 | +execute 'postfix:interfaces:all' do | ||
| 27 | + command "postconf inet_interfaces=all" | ||
| 28 | + notifies :restart, 'service[postfix]' | ||
| 29 | + not_if { system('grep -q "inet_interfaces\s*=\s*all" /etc/postfix/main.cf') } | ||
| 30 | +end | ||
| 31 | + | ||
| 32 | +transport = { | ||
| 33 | + node['config']['lists_hostname'] => node['peers']['integration'], | ||
| 34 | + node['config']['external_hostname'] => node['peers']['integration'], | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +file '/etc/postfix/transport' do | ||
| 38 | + owner 'root' | ||
| 39 | + group 'root' | ||
| 40 | + mode 0644 | ||
| 41 | + content transport.map { |domain,ip| "#{domain}\tsmtp:[#{ip}]\n" }.join | ||
| 42 | + notifies :run, 'execute[transport:postmap]' | ||
| 43 | +end | ||
| 44 | + | ||
| 45 | +execute 'transport:postmap' do | ||
| 46 | + command "postmap /etc/postfix/transport" | ||
| 47 | + action :nothing | ||
| 48 | +end |
cookbooks/mailman/recipes/default.rb
| @@ -22,15 +22,17 @@ service 'mailman' do | @@ -22,15 +22,17 @@ service 'mailman' do | ||
| 22 | supports :restart => true | 22 | supports :restart => true |
| 23 | end | 23 | end |
| 24 | 24 | ||
| 25 | -package 'postfix' | ||
| 26 | -package 'mailx' # for testing, etc | ||
| 27 | - | ||
| 28 | -execute 'postfix-config' do | 25 | +execute 'postfix:config' do |
| 29 | command [ | 26 | command [ |
| 30 | "postconf relay_domains=#{node['config']['lists_hostname']}", | 27 | "postconf relay_domains=#{node['config']['lists_hostname']}", |
| 31 | "postconf transport_maps=hash:/etc/postfix/transport", | 28 | "postconf transport_maps=hash:/etc/postfix/transport", |
| 32 | ].join(' && ') | 29 | ].join(' && ') |
| 33 | - only_if { !system('grep', node['config']['lists_hostname'], '/etc/postfix/main.cf') } | 30 | + notifies :reload, 'service[postfix]' |
| 31 | +end | ||
| 32 | + | ||
| 33 | +execute 'postfix:interfaces' do | ||
| 34 | + command "postconf inet_interfaces=\"$(cat /etc/hostname), localhost\"" | ||
| 35 | + not_if { system('postconf inet_interfaces | grep -q \'=\s*localhost\s*$\'') } | ||
| 34 | notifies :restart, 'service[postfix]' | 36 | notifies :restart, 'service[postfix]' |
| 35 | end | 37 | end |
| 36 | 38 | ||
| @@ -69,6 +71,3 @@ ruby_block 'configure-mailman-transport' do | @@ -69,6 +71,3 @@ ruby_block 'configure-mailman-transport' do | ||
| 69 | only_if { !system('grep', '^mailman', '/etc/postfix/master.cf')} | 71 | only_if { !system('grep', '^mailman', '/etc/postfix/master.cf')} |
| 70 | end | 72 | end |
| 71 | 73 | ||
| 72 | -service 'postfix' do | ||
| 73 | - action [:enable, :reload] | ||
| 74 | -end |
nodes.yaml
| @@ -14,6 +14,7 @@ vagrant@integration: | @@ -14,6 +14,7 @@ vagrant@integration: | ||
| 14 | email_subject_prefix: '[spb]' | 14 | email_subject_prefix: '[spb]' |
| 15 | lists_hostname: listas.softwarepublico.dev | 15 | lists_hostname: listas.softwarepublico.dev |
| 16 | lists_admin: paulo@softwarelivre.org | 16 | lists_admin: paulo@softwarelivre.org |
| 17 | + relay_hostname: relay.softwarepublico.dev | ||
| 17 | peers: &PEERS | 18 | peers: &PEERS |
| 18 | integration: 10.10.10.2 | 19 | integration: 10.10.10.2 |
| 19 | email: 10.10.10.3 | 20 | email: 10.10.10.3 |
| @@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
| 1 | +#!/bin/sh | ||
| 2 | + | ||
| 3 | +set -eu | ||
| 4 | + | ||
| 5 | +to="$1" | ||
| 6 | + | ||
| 7 | +waited=0 | ||
| 8 | + | ||
| 9 | +while [ $waited -lt 10 ]; do | ||
| 10 | + if (sudo postqueue -p | grep -q "$to"); then | ||
| 11 | + sudo postqueue -p | grep -c "$to" | ||
| 12 | + exit | ||
| 13 | + fi | ||
| 14 | + sleep 1 | ||
| 15 | + waited=$(($waited + 1)) | ||
| 16 | +done | ||
| 17 | + | ||
| 18 | +echo "E: no message for $to arrived at the mail realy" >&2 | ||
| 19 | +echo 0 | ||
| 20 | +exit 1 | ||
| 21 | + |
| @@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
| 1 | +. $(dirname $0)/test_helper.sh | ||
| 2 | + | ||
| 3 | +test_inbound_mail() { | ||
| 4 | + run_on integration create-list mylist foo@example.com | ||
| 5 | + | ||
| 6 | + # sending FROM EMAIL RELAY HOST | ||
| 7 | + run_on email send-email foo@example.com mylist@listas.softwarepublico.dev | ||
| 8 | + | ||
| 9 | + messages=$(run_on integration wait-for-messages mylist) | ||
| 10 | + | ||
| 11 | + run_on integration remove-list mylist | ||
| 12 | + | ||
| 13 | + assertEquals 'Message arrives at the mailing list' '1' "$messages" | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +_test_outbound_email() { | ||
| 17 | + machine="$1" | ||
| 18 | + | ||
| 19 | + run_on email clear-email-queue | ||
| 20 | + | ||
| 21 | + run_on $machine send-email sender@example.com receiver@example.com | ||
| 22 | + | ||
| 23 | + messages=$(run_on email wait-for-email-to receiver@example.com) | ||
| 24 | + | ||
| 25 | + run_on email clear-email-queue | ||
| 26 | + | ||
| 27 | + assertEquals 'Message delivered through relay' 1 "$messages" | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +test_outbound_email_integration() { | ||
| 31 | + _test_outbound_email integration | ||
| 32 | +} | ||
| 33 | +test_outbound_email_database() { | ||
| 34 | + _test_outbound_email database | ||
| 35 | +} | ||
| 36 | +test_outbound_email_social() { | ||
| 37 | + _test_outbound_email social | ||
| 38 | +} | ||
| 39 | +test_outbound_email_reverseproxy() { | ||
| 40 | + _test_outbound_email reverseproxy | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +. shunit2 | ||
| 44 | + |