Debian exim/dovecot email server with Saltstack – Installation

I develop the Salt scripts against a local VM. Once it is time to deploy remotely the process is as follows:

  1. Start up the VM with provider of choice (I use and recommend Bytemark)
  2. Log in via SSH
  3. Add the appropriate Saltstack Package Repoisitory
  4. apt-get update
  5. apt-get upgrade
  6. apt-get install salt-minion
  7. Configure the SaltStack Minion to run masterless: edit /etc/salt/minion and ensure that file_client: local is set.
  8. Tar up the SaltStack configuration files you’ve created, scp them across to the server, and tar xzf them out into /srv/salt/
  9. salt-call --local state.apply
  10. Now wait a bit. Hopefully there won’t be any errors.
  11. /usr/sbin/update-exim4.conf
  12. systemctl restart exim4
Continue reading

Debian exim/dovecot email server with Saltstack – Security

A couple of basic security utilities: fail2ban and logcheck.

srv/salt/fail2ban.sls

Fail2ban scans the SSHD log files looking for failed login attempts. After a few attempts from one IP address it adds a firewall rule to block that IP address from further connections. Given that any SSHD exposed to the Internet will receive a continuous stream of connection attempts within seconds of going online, protection of this kind is very necessary.

Continue reading

Debian exim/dovecot email server with Saltstack – SSL Certificates

I’m going to install a couple of services – SMTP (exim) and IMAP (dovecot) – and I want to share the SSL key and certificate between them. Having separate certificates for each is additional hassle when it comes to updating them.

Thus I’ve got a sslcerts.sls file to manage the certificate installation which I can share between exim.sls and dovecot.sls.

Continue reading

Debian exim/dovecot email server with Saltstack – Dovecot IMAP

I use Dovecot as my IMAP/IMAPS server – it has always worked very reliably for me.

srv/salt/dovecot.sls

First, this file needs to include sslcerts.sls to make sure that the certificates are installed. Dovecot starts as root so it doesn’t need any special groups to get access to the key.

Once the packages are installed there is a bit of configuration to set up:

  • Configure the system to use Maildir format;
  • Get rid of any configuration to use mbox format;
  • Ensure that SSL is turned on and that the ssl_cert and ssl_key values are set correctly;
  • Ensure that SSL isn’t turned off.
Continue reading

Debian exim/dovecot email server with Saltstack – Exim

srv/salt/exim.sls

This YAML file is responsible for installing and configuring exim. First thing is to install SASL to handle authentication – exim needs access to the passwords and SASL is one of the standard ways to do this.

As discussed previously I’ve chosen to install the SSL certificates centrally in /etc/ssl; I’ve set up a group ssl-cert to allow access to these. Exim also needs to run under the sasl group to get access to the authentication daemon.

Debian uses a complex configuration system for exim. This makes it easy to configure with Saltstack – we can just add our configuration to the default and Debian will put it all together for us. However it must be noted that there appears to be a bug in Saltstack at present – it should be able to tell Debian to update the configuration when a file changes but at present I’m getting infinite recursion so that bit is commented out for now.

Continue reading

Debian exim/dovecot email server with Saltstack – Introduction

I’ve needed to update my email server for a while. This time I wanted to do the installation with Saltstack:

  • Saltstack is fun
  • It means I have an easy-to-read document about what is on the server and how it is installed.

Tools like Saltstack are not just for when you’ve got lots of servers. Having a simple set of files that show exactly what has been changed from default and why is invaluable.

Ok – there are a few parts to this system.

  • exim4 handles the SMTP part – incoming and outgoing email;
  • SpamAssassin will do the SPAM filtering;
  • dovecot will handle reading email via IMAP

Plus we need various security bits and pieces, user accounts and so on.

I’ll be running SaltStack in masterless mode – there isn’t any point in running a dedicated Salt Master server.

Continue reading