Consulting djbware Publications

10. Clustering, mini-qmail, QMQ, and Tapping

In this chapter some ideas are laid out how to setup s/qmail for larger sites and high mail volumes (> 100,000 mails/day). Distinguished domain specific settings given the hosting of serveral domains and clustering is also discussed.

Finally, the optional 'tapping' feature of s/qmail is introduced, since this might be a legal requirement.

  1. Bird's View on Clustering
  2. The Concept of Mini-qmail
  3. The Idea of Qmail-Multiple-Queues (QMQ)
  4. Controlling domain-specific Delivery and Email Tapping

10.1. Bird's View on Clustering

The main and single-instance setup of s/qmail is given in the 'big picture':

Figure: The s/qmail 'Big Picture' with one singel s/qmail instance serving as hub for SMTP and POP3 connections.

Here, several 'mini-qmail' Internet receiving instance of qmail can be setup while on is particular instance is in place to be responsible and to queue the ingress (incoming) and outgress (outgoing) email traffic. This setup might not be optimal for large sites:

A multi-tier architecture is needed to overcome those shortcomings and is available now at your fingertips.

10.2. The Concept of mini-qmail

Daniel J. Bernstein described the idea of 'mini-qmail' here: mini-qmail. However, at that point, the assumption is made, that qmail feeds local users. This assumption is only partially valid today:

Figure: Setup of 'mini-qmail' receiving mails from the Internet (ingress)
and delivering those to a central but redundant qmail system by means of qmail-qmqpc and qmail-qmqpd
on the receiving system while making use of tcpserver and its feature to control incoming connections via a cdb.

10.2.1 Setup of mini-qmail

Setting up a mini-qmail requires the following steps.

10.2.2 Advantages of mini-qmail

This setup has several advantages and can be expanded to even larger custers:

10.3. Idea of Qmail-Multiple-Queues (QMQ)

The idea for QMQ was raised while trying to improve reliable delivery to distinct downstream domains even in the case of general attack to the main receiving system.

One major load any qmail system is the us of an anti-virus scanner. Such a tool usually requires significant system resources and in particular I/O. s/qmail/ provides several means to include such a AV systems; but the principle problem still exists.

While adjusting qmail for the German government, it turned out, that different needs for such AV systems need to be accustomed; in particular what is called 'multi-tenancy'.

QMQ is the approach to provide this for downstream (responsible) domains without inflicting services for others. QMP (Qmail-Multiple-Queues) is thus the opposite of a 'mini-qmail': For one major qmail (receiving) instance, serveral egress instances are raised with individual queues and delivery schemes.

Figure: Setup of 'QMP' with several downstream instances - typically on the same MTA.

Which advantages can be expected with serveral Queues?

In a QMQ s/qmail system, typically one MTA is setup for several (small) s/qmail instances; however now with several queues for dedicated domains.

Those QMQ instances provide the following features:

10.3.1 Setup of QMQ

Within s/qmail the following means are available to setup distinct queuing:

Once you have made of sketch of your desired delivery scheme, this will potentially include:

These settings need to be reflected in conf-qmq which provides the initial default dummy settings:

# conf-qmq environment settings # Here, you may change some global settings # Example for multiple s/qmail directories: # 01:instance1 02:instance2 10:INTERNET 98:SPAM 99:BACKUP # Use meaningful names for 'instance1' etc.; they will be used in 'me' export SERVICE_BASEDIR="/service" # must exist; could be dummy for systemd # export SKELETON_CONCURRENCYREMOTE="120" export SKELETON_QUEUELIFETIME="1440" # 24 Hours export SKELETON_PORT="1000" # high ports for QMQ export SKELETON_ME=`hostname`

At that point, lets assume, all other s/qmail settings work out. The QMQ setup can be done anytime later!

The next steps are the following:

  1. Move to the scripts directory and do a make. At that point, all scripts will be provissioned with your given setup.
  2. Call the generated multi-queue script!
  3. It will tell you to use the steps build, conf or all. Proceed as required.

Now, the s/qmail installation starts for the given QMQ instances and perhaps populate ('conf') those with a minimal setup.

This does not impact your running system. The QMQ instances are raised in your given high-level prefix (typically 'var) at conf-qmail with queues setup at conf-queue (if different). Futher, the /service might be populated.
All this can be purged or modified on demand.

Though QMQ (along with s/qmail) takes advantage of DJB's supervise, any other tool can be used; though of course requiring additional attention.

Now it is time, to investigate the raised QMQ instances. Those instances are minimalistic, just have the directories and binaries required to serve the domainstream (egress) MTA together with the queue. There are serveral things to check:

10.3.2 Provisioning Domains in QMQ

While the ingress communication from the Internet is realized by the primary QMQ instance, the outgress delivery is subject of each QMQ instance, making use of the following control files:

In addition, it is possible to define own SPF and/or DKIM rules for the ingress SMTP data traffic here.

10.3.3 Special and Dorming Domains

Given SPAM and perhaps DoS attacks not matter of general rules or general rules can not be applied due to a local policy, ingress mails - given a certain pattern - can be forwarded to a dorming QMQ instance and now qmail-smtpd or qmail-qmptd is activated. In the above sample it carries the instance number 98.

The dorming domain only receives those mails (by SMTP or QMTP) but does not process the mails in the queue. Thus, the qmail-send service is still sleeping. Thus, the emails are queued and subject of investigation.

The very same setup can be used for honeypots, if required. This obfuscates for any attacker the processing chain, which is important for further forensic analysis.

10.4. Controlling domain-specific Delivery and Email Tapping

For a large organziation, or given a require policy, particular rules may be applied to control email delivery. While DKIM and SPF can be used for ingress SMTP traffic now the focus changes to egress traffic, i.e. the delivery of emails to an downstream domain or MTA.

Further, starting with s/qmail 4.4, it is possible to provide TAPPING for email, thus duplicating those and delivering them to a catch-up receipient.

10.4.1 Controlling

Egress data traffic is subject of qmail-remote. Here we have three major 'knobs' to be used:

However, even emails accepted for local delivery (in our Unix MTA) can be subject of further delivery instructions. Here, we can use:

All these commands are subject to be invokded by a dot-qmail file and scheduled by the qmail-command.

More helpers are available from my mess822x package.

10.4.2 Tapping

s/qmail 4.4 includes an embedded email tapping facility as part of its qmail-queue implementation. However, this needs to be build during compile time while enabling it in conf-cc.

10.4.3 Quotas

Quotas are currently not supported by s/qmail. Thus the size user's mailbox is checked upon delivery. This holds for local as well as virtual domains and users. This may be subject of change in later implementations.