Changeset - 7d9696a7b5cc
[Not reviewed]
0 7 0
Branko Majic (branko) - 5 years ago 2021-01-14 23:50:11
branko@majic.rs
MAR-151: Added support for Debian 10 Buster to mail_server role:

- Updated role reference documentaiton.
- Updated role meta information.
- Updated tests.
- Improve handling of configured IP in tests to avoid hard-coding the
value in the relevant test for Postfix configuration file content.
7 files changed with 99 insertions and 7 deletions:
0 comments (0 inline, 0 general)
docs/rolereference.rst
Show inline comments
 
@@ -1230,24 +1230,25 @@ Parameters
 
  List of networks from which mail relaying is allowed even without
 
  authentication. Each item in the list is a string defining a network. The
 
  format must be compatible with Postfix ``mynetworks`` setting (for example:
 
  ``192.168.1.0/24``, ``myhost.example.com`` etc).
 

	
 

	
 
Distribution compatibility
 
~~~~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
Role is compatible with the following distributions:
 

	
 
- Debian 9 (Stretch)
 
- Debian 10 (Buster)
 

	
 

	
 
Examples
 
~~~~~~~~
 

	
 
Here is an example configuration for setting-up XMPP server using Prosody:
 

	
 
.. code-block:: yaml
 

	
 
  ---
 

	
 
  mail_ldap_url: ldap://ldap.example.com/
roles/mail_server/meta/main.yml
Show inline comments
 
@@ -7,14 +7,14 @@ dependencies:
 
    backup_patterns_filename: "mail_server"
 
    backup_patterns:
 
      - "/var/{{ mail_user }}"
 

	
 
galaxy_info:
 
  author: Branko Majic
 
  description: Sets-up mail server with SMTP and IMAP services, using LDAP as source of allowed destinations (domains, mail addresses)
 
  license: BSD
 
  min_ansible_version: 2.9
 
  platforms:
 
    - name: Debian
 
      versions:
 
        - 8
 
        - 9
 
        - 10
roles/mail_server/molecule/default/group_vars/parameters-optional.yml
Show inline comments
 
@@ -19,27 +19,32 @@ imap_tls_certificate: "{{ lookup('file', 'tests/data/x509/server/{{ inventory_ho
 
imap_tls_key: "{{ lookup('file', 'tests/data/x509/server/{{ inventory_hostname }}_imap.key.pem') }}"
 
local_mail_aliases:
 
  root: "john.doe@domain1"
 
smtp_tls_certificate: "{{ lookup('file', 'tests/data/x509/server/{{ inventory_hostname }}_smtp.cert.pem') }}"
 
smtp_tls_key: "{{ lookup('file', 'tests/data/x509/server/{{ inventory_hostname }}_smtp.key.pem') }}"
 
imap_folder_separator: "."
 
smtp_rbl:
 
  - bl.spamcop.net
 
  - zen.spamhaus.org
 

	
 
mail_postmaster: "webmaster@parameters-optional"
 
smtp_allow_relay_from:
 
  - "10.31.127.22"
 
  - "{{ release_based_smtp_allow_relay_from[ansible_distribution_release] }}"
 
mail_message_size_limit: 20480001
 

	
 
# Variables dependant on distribution release.
 
release_based_smtp_allow_relay_from:
 
  stretch: "10.31.127.22"
 
  buster: "10.31.127.20"
 

	
 
# common
 
ca_certificates:
 
  testca: "{{ lookup('file', 'tests/data/x509/ca/level1.cert.pem') }}"
 

	
 
# backup_client (backup username should end in -s64 for Stretch).
 
enable_backup: true
 
backup_client_username: "bak-parameters-optional-{{ ansible_distribution_release[0] }}64"
 
backup_encryption_key: "{{ lookup('file', 'tests/data/gnupg/parameters-optional.asc') }}"
 
backup_server: ldap-server
 
backup_server_host_ssh_public_keys:
 
  - "{{ lookup('file', 'tests/data/ssh/server_rsa.pub') }}"
 
  - "{{ lookup('file', 'tests/data/ssh/server_ed25519.pub') }}"
roles/mail_server/molecule/default/host_vars/ldap-server.yml
Show inline comments
 
@@ -34,19 +34,19 @@ ldap_client_config:
 
    value: dc=local
 
  - comment: URI
 
    option: URI
 
    value: ldapi:///
 

	
 
# backup_server role
 
backup_host_ssh_private_keys:
 
  rsa: "{{ lookup('file', 'tests/data/ssh/server_rsa') }}"
 
  ed25519: "{{ lookup('file', 'tests/data/ssh/server_ed25519') }}"
 
  ecdsa: "{{ lookup('file', 'tests/data/ssh/server_ecdsa') }}"
 
backup_clients:
 

	
 
  - server: parameters-optional-j64
 
    ip: 10.31.127.31
 
    public_key: "{{ lookup('file', 'tests/data/ssh/parameters-optional.pub') }}"
 

	
 
  - server: parameters-optional-s64
 
    ip: 10.31.127.33
 
    public_key: "{{ lookup('file', 'tests/data/ssh/parameters-optional.pub') }}"
 

	
 
  - server: parameters-optional-b64
 
    ip: 10.31.127.31
 
    public_key: "{{ lookup('file', 'tests/data/ssh/parameters-optional.pub') }}"
roles/mail_server/molecule/default/molecule.yml
Show inline comments
 
@@ -71,24 +71,80 @@ platforms:
 
    groups:
 
      - parameters-optional
 
      - stretch
 
    box: debian/contrib-stretch64
 
    memory: 1536
 
    cpus: 1
 
    interfaces:
 
      - auto_config: true
 
        ip: 10.31.127.33
 
        network_name: private_network
 
        type: static
 

	
 
  - name: client1-buster
 
    groups:
 
      - client
 
      - client-relay-allowed
 
      - buster
 
      - smtp-server-requiring-tls
 
    box: debian/contrib-buster64
 
    memory: 256
 
    cpus: 1
 
    interfaces:
 
      - auto_config: true
 
        ip: 10.31.127.20
 
        network_name: private_network
 
        type: static
 

	
 
  - name: client2-buster
 
    groups:
 
      - client
 
      - client-relay-forbidden
 
      - buster
 
      - smtp-server-refusing-tls
 
    box: debian/contrib-buster64
 
    memory: 256
 
    cpus: 1
 
    interfaces:
 
      - auto_config: true
 
        ip: 10.31.127.21
 
        network_name: private_network
 
        type: static
 

	
 
  - name: parameters-mandatory-buster64
 
    groups:
 
      - parameters-mandatory
 
      - buster
 
    box: debian/contrib-buster64
 
    memory: 1536
 
    cpus: 1
 
    interfaces:
 
      - auto_config: true
 
        ip: 10.31.127.30
 
        network_name: private_network
 
        type: static
 

	
 
  - name: parameters-optional-buster64
 
    groups:
 
      - parameters-optional
 
      - buster
 
    box: debian/contrib-buster64
 
    memory: 1536
 
    cpus: 1
 
    interfaces:
 
      - auto_config: true
 
        ip: 10.31.127.31
 
        network_name: private_network
 
        type: static
 

	
 
provisioner:
 
  name: ansible
 
  playbooks:
 
    cleanup: cleanup.yml
 
  config_options:
 
    defaults:
 
      force_valid_group_names: "ignore"
 
      interpreter_python: "/usr/bin/python3"
 
    ssh_connection:
 
      pipelining: "True"
 
  lint:
 
    name: ansible-lint
roles/mail_server/molecule/default/prepare.yml
Show inline comments
 
@@ -25,24 +25,32 @@
 
          - "{{ item.fqdn[:item.fqdn.rfind('-')] }}"
 
      with_items:
 
        - name: ldap-server_ldap
 
          fqdn: ldap-server
 
        - name: parameters-mandatory-stretch64_imap
 
          fqdn: parameters-mandatory-stretch64
 
        - name: parameters-mandatory-stretch64_smtp
 
          fqdn: parameters-mandatory-stretch64
 
        - name: parameters-optional-stretch64_imap
 
          fqdn: parameters-optional-stretch64
 
        - name: parameters-optional-stretch64_smtp
 
          fqdn: parameters-optional-stretch64
 
        - name: parameters-mandatory-buster64_imap
 
          fqdn: parameters-mandatory-buster64
 
        - name: parameters-mandatory-buster64_smtp
 
          fqdn: parameters-mandatory-buster64
 
        - name: parameters-optional-buster64_imap
 
          fqdn: parameters-optional-buster64
 
        - name: parameters-optional-buster64_smtp
 
          fqdn: parameters-optional-buster64
 

	
 
    - name: Set-up link to generated X.509 material
 
      file:
 
        src: ".gimmecert"
 
        dest: "tests/data/x509"
 
        state: link
 

	
 
- name: Prepare
 
  hosts: all
 
  gather_facts: false
 
  tasks:
 
    - name: Install python for Ansible
 
@@ -77,24 +85,44 @@
 
        line: "{{ item.key }} {{ item.value }}"
 
        owner: root
 
        group: root
 
        mode: 0644
 
        state: present
 
      with_dict:
 
        10.31.127.10: "ldap-server backup-server"
 
        10.31.127.22: "client1 smtp-server-requiring-tls"
 
        10.31.127.23: "client2 smtp-server-refusing-tls"
 
        10.31.127.32: "parameters-mandatory parameters-mandatory-stretch64"
 
        10.31.127.33: "parameters-optional parameters-optional-stretch64"
 

	
 
- hosts: buster
 
  become: true
 
  tasks:
 

	
 
    - name: Set-up the hosts file
 
      lineinfile:
 
        path: /etc/hosts
 
        regexp: "^{{ item.key }}"
 
        line: "{{ item.key }} {{ item.value }}"
 
        owner: root
 
        group: root
 
        mode: 0644
 
        state: present
 
      with_dict:
 
        10.31.127.10: "ldap-server backup-server"
 
        10.31.127.20: "client1 smtp-server-requiring-tls"
 
        10.31.127.21: "client2 smtp-server-refusing-tls"
 
        10.31.127.30: "parameters-mandatory parameters-mandatory-buster64"
 
        10.31.127.31: "parameters-optional parameters-optional-buster64"
 

	
 
- hosts: client
 
  become: true
 
  tasks:
 

	
 
    - name: Install SWAKS for testing SMTP capability
 
      apt:
 
        name: swaks
 
        state: present
 

	
 
    - name: Install pip
 
      apt:
 
        name: python3-pip
roles/mail_server/molecule/default/tests/test_optional.py
Show inline comments
 
@@ -21,25 +21,27 @@ def test_mailname_file_content(host):
 

	
 
    mailname = host.file('/etc/mailname')
 
    hostname = host.run('hostname').stdout.strip()
 

	
 
    assert mailname.content_string == hostname
 

	
 

	
 
def test_postfix_main_cf_file_content(host):
 
    """
 
    Tests if the Postfix main configuration file content is correct.
 
    """
 

	
 
    allow_relay_from_ip = "10.31.127.22"
 
    host_variables = host.ansible.get_variables()
 

	
 
    allow_relay_from_ip = host_variables["smtp_allow_relay_from"]
 

	
 
    hostname = host.run('hostname').stdout.strip()
 

	
 
    config = host.file('/etc/postfix/main.cf')
 
    config_lines = config.content_string.split("\n")
 

	
 
    assert "myhostname = %s" % hostname in config_lines
 
    assert "mydestination = %s, %s, localhost.localdomain, localhost" % (hostname, hostname) in config_lines
 
    assert "mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 %s" % allow_relay_from_ip in config_lines
 
    assert "smtpd_tls_cert_file = /etc/ssl/certs/%s_smtp.pem" % hostname in config_lines
 
    assert "smtpd_tls_key_file = /etc/ssl/private/%s_smtp.key" % hostname in config_lines
 
    assert "  reject_rbl_client bl.spamcop.net" in config_lines
0 comments (0 inline, 0 general)