From 379450308a0876f1be73d7f2310e65555e9a4c03 Mon Sep 17 00:00:00 2001 From: Valentin Date: Mon, 3 Nov 2014 15:05:19 +0000 Subject: [PATCH] first commit --- LICENSE | 21 ++++++++ Makefile | 11 +++++ README.md | 66 +++++++++++++++++++++++++ dovecot/Dockerfile | 84 ++++++++++++++++++++++++++++++++ dovecot/dovecot.auth | 14 ++++++ dovecot/dovecot.imap | 3 ++ dovecot/dovecot.lda | 5 ++ dovecot/dovecot.logging | 2 + dovecot/dovecot.mail | 19 ++++++++ dovecot/dovecot.master | 34 +++++++++++++ dovecot/dovecot.ssl | 5 ++ dovecot/example/aliases | 2 + dovecot/example/domains | 1 + dovecot/example/passwords | 2 + dovecot/postfix.main.cf | 74 ++++++++++++++++++++++++++++ dovecot/postfix.master.cf.append | 15 ++++++ dovecot/process_settings | 24 +++++++++ 17 files changed, 382 insertions(+) create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 dovecot/Dockerfile create mode 100644 dovecot/dovecot.auth create mode 100644 dovecot/dovecot.imap create mode 100644 dovecot/dovecot.lda create mode 100644 dovecot/dovecot.logging create mode 100644 dovecot/dovecot.mail create mode 100644 dovecot/dovecot.master create mode 100644 dovecot/dovecot.ssl create mode 100644 dovecot/example/aliases create mode 100644 dovecot/example/domains create mode 100644 dovecot/example/passwords create mode 100644 dovecot/postfix.main.cf create mode 100644 dovecot/postfix.master.cf.append create mode 100644 dovecot/process_settings diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a67f2b5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Benno Evers + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a2c0da6 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +all: dovecot + +.PHONY: dovecot + +dovecot: + cd dovecot; docker build -t dovecot_made_special:2.1.7 . + +run-dovecot: + docker run -d -p 25:25 -p 587:587 -p 143:143 -v /opt/dockermail/settings:/mail_settings -v /opt/dockermail/vmail:/vmail dovecot_made_special:2.1.7 + +run-all: run-dovecot diff --git a/README.md b/README.md new file mode 100644 index 0000000..bb2e763 --- /dev/null +++ b/README.md @@ -0,0 +1,66 @@ +docker-made-special-mail +========== + +Based on https://github.com/lava/dockermail + +A secure, minimal-configuration mail server in a docker container. + +This repository is tailored to small private servers, where you own some domain(s) and +want to receive the mail for and send mail from this domain: + +The SMTP and IMAP server. This container uses postfix as MTA and dovecot as IMAP server. +All incoming mail to your own domains is accepted. For outgoing mail, only authenticated +(logged in with username and password) clients can send messages via STARTTLS on port 587. +In theory it works with all mail clients, but it was only tested with Thunderbird. + + +Setup +===== +Create 2 folders: one for mail configuration (`/opt/dockermail/settings`), another for mail storage (`/opt/dockermail/vmail`). + + +1) Add all domains you want to receive mail for to the file `/opt/dockermail/settings/domains`, like this: + + example.org + example.net + +2) Add user aliases to the file `/opt/dockermail/settings/aliases`, like + + johndoe@example.org john.doe@example.org + john.doe@example.org john.doe@example.org + admin@forum.example.org forum-admin@example.org + @example.net catch-all@example.net + +An IMAP mail account is created for each entry on the right hand side. +Every mail sent to one of the addresses in the left column will +be delivered to the corresponding account in the right column. + +3) Add user passwords to the file `/opt/dockermail/settings/passwords` like this + + john.doe@example.org:{PLAIN}password123 + admin@example.org:{SHA256-CRYPT}$5$ojXGqoxOAygN91er$VQD/8dDyCYOaLl2yLJlRFXgl.NSrB3seZGXBRMdZAr6 + +To get the hash values, you can either install dovecot locally or use lxc-attach to attach to the running +container and run `doveadm pw -s ` inside. + +4) Build container + + make + +5) Run container and map ports 25 and 143 from the host to the container. + To store your mail outside the container, map `/opt/dockermail/vmail/` to + a directory on your host. (This is recommended, otherwise + you have to remember to backup your mail when you want to restart the container) + + `docker run -d -p 25:25 -p 587:587 -p 143:143 -v /opt/dockermail/settings:/mail_settings -v /opt/dockermail/vmail:/vmail dovecot_made_special/2.1.7` + +6) Enjoy. + + +Known issues / Todo / Wishlist +============================== +- HELO isn't set correctly, which can lead to problems with outgoing mail on some servers + +- It would be nice to have a way of catching mail to all subdomains. + +Patches welcome! diff --git a/dovecot/Dockerfile b/dovecot/Dockerfile new file mode 100644 index 0000000..25733e0 --- /dev/null +++ b/dovecot/Dockerfile @@ -0,0 +1,84 @@ +FROM ubuntu:14.04 + +ENV DEBIAN_FRONTEND noninteractive + +RUN echo 'deb http://archive.ubuntu.com/ubuntu/ trusty main' | tee /etc/apt/sources.list +RUN echo 'deb-src http://archive.ubuntu.com/ubuntu/ trusty main' | tee -a /etc/apt/sources.list +RUN echo 'deb http://archive.ubuntu.com/ubuntu/ trusty-updates main' | tee -a /etc/apt/sources.list +RUN echo 'deb-src http://archive.ubuntu.com/ubuntu/ trusty-updates main' | tee -a /etc/apt/sources.list +RUN echo 'deb http://archive.ubuntu.com/ubuntu/ trusty universe' | tee -a /etc/apt/sources.list +RUN echo 'deb-src http://archive.ubuntu.com/ubuntu/ trusty universe' | tee -a /etc/apt/sources.list +RUN echo 'deb http://archive.ubuntu.com/ubuntu/ trusty-updates universe' | tee -a /etc/apt/sources.list +RUN echo 'deb-src http://archive.ubuntu.com/ubuntu/ trusty-updates universe' | tee -a /etc/apt/sources.list +RUN echo 'deb http://archive.ubuntu.com/ubuntu/ trusty multiverse' | tee -a /etc/apt/sources.list +RUN echo 'deb-src http://archive.ubuntu.com/ubuntu/ trusty multiverse' | tee -a /etc/apt/sources.list +RUN echo 'deb http://archive.ubuntu.com/ubuntu/ trusty-updates multiverse' | tee -a /etc/apt/sources.list +RUN echo 'deb-src http://archive.ubuntu.com/ubuntu/ trusty-updates multiverse' | tee -a /etc/apt/sources.list +RUN echo 'deb http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse' | tee -a /etc/apt/sources.list +RUN echo 'deb-src http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse' | tee -a /etc/apt/sources.list +RUN echo 'deb http://security.ubuntu.com/ubuntu trusty-security main' | tee -a /etc/apt/sources.list +RUN echo 'deb-src http://security.ubuntu.com/ubuntu trusty-security main' | tee -a /etc/apt/sources.list +RUN echo 'deb http://security.ubuntu.com/ubuntu trusty-security universe' | tee -a /etc/apt/sources.list +RUN echo 'deb-src http://security.ubuntu.com/ubuntu trusty-security universe' | tee -a /etc/apt/sources.list +RUN echo 'deb http://security.ubuntu.com/ubuntu trusty-security multiverse' | tee -a /etc/apt/sources.list +RUN echo 'deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse' | tee -a /etc/apt/sources.list + +RUN locale-gen en_GB en_GB.UTF-8 && dpkg-reconfigure locales + +RUN apt-get update + +RUN apt-get -y -q autoclean +RUN apt-get -y -q autoremove +RUN apt-get clean + +# prerequisites +RUN apt-get update + +# install self-signed ssl certs +RUN apt-get install -y --force-yes ssl-cert + +# Install postfix as MTA +RUN apt-get install -y --force-yes postfix + +# Install dovecot as IMAP server +RUN apt-get install -y --force-yes dovecot-imapd + +# postfix configuration +RUN echo "mail.docker.container" > /etc/mailname +ADD ./postfix.main.cf /etc/postfix/main.cf +ADD ./postfix.master.cf.append /etc/postfix/master-additional.cf +RUN cat /etc/postfix/master-additional.cf >> /etc/postfix/master.cf + +# configure settings script +VOLUME ["/mail_config"] +COPY process_settings /process_settings +RUN chmod 755 /process_settings + +# add user vmail who own all mail folders +VOLUME ["/vmail"] +RUN groupadd -g 5000 vmail +RUN useradd -g vmail -u 5000 vmail -d /vmail -m + +# dovecot configuration +ADD ./dovecot.mail /etc/dovecot/conf.d/10-mail.conf +ADD ./dovecot.ssl /etc/dovecot/conf.d/10-ssl.conf +ADD ./dovecot.auth /etc/dovecot/conf.d/10-auth.conf +ADD ./dovecot.master /etc/dovecot/conf.d/10-master.conf +ADD ./dovecot.lda /etc/dovecot/conf.d/15-lda.conf +ADD ./dovecot.imap /etc/dovecot/conf.d/20-imap.conf +# add verbose logging +#ADD ./internal/dovecot.logging /etc/dovecot/conf.d/10-logging.conf + +# smtp port for incoming mail +EXPOSE 25 +# imap port +EXPOSE 143 +# smtp port for outgoing +EXPOSE 587 + +# todo: enable port 587 for outgoing mail, separate ports 25 and 587 +# http://www.synology-wiki.de/index.php/Zusaetzliche_Ports_fuer_Postfix + +# start necessary services for operation (dovecot -F starts dovecot in the foreground to prevent container exit) +ENTRYPOINT /process_settings; service rsyslog start; service postfix start; dovecot -F + diff --git a/dovecot/dovecot.auth b/dovecot/dovecot.auth new file mode 100644 index 0000000..fbff5fe --- /dev/null +++ b/dovecot/dovecot.auth @@ -0,0 +1,14 @@ +auth_mechanisms = plain login + +passdb { + driver = passwd-file + args = /etc/dovecot/passwd +} + + +userdb { + driver = static + args = uid=vmail gid=vmail home=/vmail/%d/%n allow_all_users=yes +} + + diff --git a/dovecot/dovecot.imap b/dovecot/dovecot.imap new file mode 100644 index 0000000..1df8585 --- /dev/null +++ b/dovecot/dovecot.imap @@ -0,0 +1,3 @@ +protocol imap { + imap_client_workarounds = tb-extra-mailbox-sep +} diff --git a/dovecot/dovecot.lda b/dovecot/dovecot.lda new file mode 100644 index 0000000..b075d2f --- /dev/null +++ b/dovecot/dovecot.lda @@ -0,0 +1,5 @@ +protocol lda { + hostname = mail.docker.container + postmaster_address = postmaster@mail.docker.container + mail_plugin_dir = /usr/lib/dovecot/modules/lda +} diff --git a/dovecot/dovecot.logging b/dovecot/dovecot.logging new file mode 100644 index 0000000..e272aa5 --- /dev/null +++ b/dovecot/dovecot.logging @@ -0,0 +1,2 @@ +auth_verbose = yes +auth_debug = yes diff --git a/dovecot/dovecot.mail b/dovecot/dovecot.mail new file mode 100644 index 0000000..aa09e2b --- /dev/null +++ b/dovecot/dovecot.mail @@ -0,0 +1,19 @@ +mail_location = maildir:/vmail/%d/%n:LAYOUT=fs + +namespace inbox { + inbox = yes + + # set these to autocreate or else thunderbird will complain + mailbox Trash { + auto = create + special_use = \Trash + } + mailbox Drafts { + auto = subscribe + special_use = \Drafts + } + mailbox Sent { + auto = subscribe # autocreate and autosubscribe the Sent mailbox + special_use = \Sent + } + } diff --git a/dovecot/dovecot.master b/dovecot/dovecot.master new file mode 100644 index 0000000..226be08 --- /dev/null +++ b/dovecot/dovecot.master @@ -0,0 +1,34 @@ +service imap-login { + inet_listener imap { + + } + + #disable imaps since we use TLS connections through the standard imap + inet_listener imaps { + port = 0 + } +} + +service imap { + +} + +# not sure if this is needed +service lmtp { + unix_listener /var/spool/postfix/private/dovecot-lmtp { + group = vmail + mode = 0660 + user = postfix + } +} + +service auth { + unix_listener /var/spool/postfix/private/auth { + mode = 0660 + user = postfix + group = vmail + } +} + +service auth-worker { +} diff --git a/dovecot/dovecot.ssl b/dovecot/dovecot.ssl new file mode 100644 index 0000000..4f86889 --- /dev/null +++ b/dovecot/dovecot.ssl @@ -0,0 +1,5 @@ +ssl = required +disable_plaintext_auth = yes +ssl_cert = /etc/postfix/tmp/virtual-receivers +sed -r 's,(.+)@(.+),\2/\1/,' /etc/postfix/tmp/virtual-receivers > /etc/postfix/tmp/virtual-receiver-folders +paste /etc/postfix/tmp/virtual-receivers /etc/postfix/tmp/virtual-receiver-folders > /etc/postfix/virtual-mailbox-maps + +# give postfix the ownership of his files +chown -R postfix:postfix /etc/postfix + +# map virtual aliases and user/filesystem mappings +postmap /etc/postfix/virtual +postmap /etc/postfix/virtual-mailbox-maps +chown -R postfix:postfix /etc/postfix + +# make user vmail own all mail folders +chown -R vmail:vmail /vmail +chmod u+w /vmail + +# Add password file +cp /mail_settings/passwords /etc/dovecot/passwd \ No newline at end of file