Commit 48c35a4b7123ab787e4aae3c74b060f751b7ef5c

Authored by Antonio Terceiro
1 parent 4216f9fb
Exists in master and in 90 other branches 3.x, add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup, backup_not_prod, cdtc_configuration, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev-lappis, dev_env_minimal, disable_email_dev, docs, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, performance, prezento, r3, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_backup_emails, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, stable-devel, support_docs, syslog, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

email relay configuration

config/roles/email_server.rb
1   -name 'database_server'
  1 +name 'email_server'
2 2 description 'E-mail server'
3   -run_list 'recipe[postfix]'
  3 +run_list 'recipe[email::relay]'
... ...
config/roles/server.rb
1 1 name 'server'
2 2 description 'Common configuration for all servers'
3   -run_list 'recipe[basics]'
  3 +run_list 'recipe[basics]', 'recipe[email::client]'
... ...
config/roles/social_server.rb
1 1 name 'database_server'
2 2 description 'Social networking server'
3   -run_list 'recipe[noosfero]'
  3 +#run_list 'recipe[noosfero]'
... ...
cookbooks/email/recipes/client.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +include_recipe 'email'
  2 +
  3 +execute 'postfix:configrelay' do
  4 + command "postconf relayhost=[#{node['peers']['email']}]"
  5 + notifies :reload, 'service[postfix]'
  6 +
  7 + # not on the relay host itself
  8 + not_if { node.hostname == 'email' }
  9 +end
... ...
cookbooks/email/recipes/default.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +include_recipe 'email'
  2 +
  3 +package 'postfix'
  4 +package 'mailx' # for testing, etc
  5 +
  6 +service 'postfix' do
  7 + action [:enable, :start]
  8 + supports :reload => true
  9 +end
... ...
cookbooks/email/recipes/relay.rb 0 → 100644
... ... @@ -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 22 supports :restart => true
23 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 26 command [
30 27 "postconf relay_domains=#{node['config']['lists_hostname']}",
31 28 "postconf transport_maps=hash:/etc/postfix/transport",
32 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 36 notifies :restart, 'service[postfix]'
35 37 end
36 38  
... ... @@ -69,6 +71,3 @@ ruby_block 'configure-mailman-transport' do
69 71 only_if { !system('grep', '^mailman', '/etc/postfix/master.cf')}
70 72 end
71 73  
72   -service 'postfix' do
73   - action [:enable, :reload]
74   -end
... ...
nodes.yaml
... ... @@ -14,6 +14,7 @@ vagrant@integration:
14 14 email_subject_prefix: '[spb]'
15 15 lists_hostname: listas.softwarepublico.dev
16 16 lists_admin: paulo@softwarelivre.org
  17 + relay_hostname: relay.softwarepublico.dev
17 18 peers: &PEERS
18 19 integration: 10.10.10.2
19 20 email: 10.10.10.3
... ...
test/bin/clear-email-queue 0 → 100755
... ... @@ -0,0 +1,5 @@
  1 +#!/bin/sh
  2 +
  3 +set -e
  4 +
  5 +sudo postsuper -d ALL >/dev/null 2>&1
... ...
test/bin/curl-host 0 → 100755
... ... @@ -0,0 +1,8 @@
  1 +#!/bin/sh
  2 +
  3 +set -eu
  4 +
  5 +host="$1"
  6 +shift
  7 +
  8 +$(dirname $0)/curl --header "Host: $host" "$@"
... ...
test/bin/wait-for-email-to 0 → 100755
... ... @@ -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 +
... ...
test/mail_relay_test.sh 0 → 100644
... ... @@ -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 +
... ...