Merged conflicts
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
FROM alpine:3.7
|
||||
FROM alpine:3.8
|
||||
|
||||
RUN apk add --no-cache postfix postfix-sqlite postfix-pcre rsyslog python py-jinja2
|
||||
RUN apk add --no-cache postfix postfix-pcre rsyslog \
|
||||
python3 py3-pip \
|
||||
&& pip3 install --upgrade pip \
|
||||
&& pip3 install jinja2 podop tenacity
|
||||
|
||||
COPY conf /conf
|
||||
COPY start.py /start.py
|
||||
|
||||
EXPOSE 25/tcp 10025/tcp
|
||||
VOLUME ["/data"]
|
||||
|
||||
CMD /start.py
|
||||
|
||||
@@ -19,8 +19,8 @@ mynetworks = 127.0.0.1/32 [::1]/128 {{ RELAYNETS }}
|
||||
# Empty alias list to override the configuration variable and disable NIS
|
||||
alias_maps =
|
||||
|
||||
# SQLite configuration
|
||||
sql = sqlite:${config_directory}/
|
||||
# Podop configuration
|
||||
podop = socketmap:unix:/tmp/podop.socket:
|
||||
|
||||
# Only accept virtual emails
|
||||
mydestination =
|
||||
@@ -56,13 +56,14 @@ smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
|
||||
|
||||
# The alias map actually returns both aliases and local mailboxes, which is
|
||||
# required for reject_unlisted_sender to work properly
|
||||
virtual_alias_maps = ${sql}sqlite-virtual_alias_maps.cf
|
||||
virtual_mailbox_domains = ${sql}sqlite-virtual_mailbox_domains.cf
|
||||
virtual_mailbox_maps = $virtual_alias_maps
|
||||
virtual_alias_domains =
|
||||
virtual_alias_maps = ${podop}alias
|
||||
virtual_mailbox_domains = ${podop}domain
|
||||
virtual_mailbox_maps = ${podop}mailbox
|
||||
|
||||
# Mails are transported if required, then forwarded to Dovecot for delivery
|
||||
relay_domains = ${sql}sqlite-transport.cf
|
||||
transport_maps = ${sql}sqlite-transport.cf
|
||||
relay_domains = ${podop}transport
|
||||
transport_maps = ${podop}transport
|
||||
virtual_transport = lmtp:inet:{{ HOST_LMTP }}
|
||||
|
||||
# In order to prevent Postfix from running DNS query, enforce the use of the
|
||||
@@ -82,15 +83,20 @@ smtpd_sender_login_maps = $virtual_alias_maps
|
||||
# Restrictions for incoming SMTP, other restrictions are applied in master.cf
|
||||
smtpd_helo_required = yes
|
||||
|
||||
smtpd_recipient_restrictions =
|
||||
smtpd_client_restrictions =
|
||||
permit_mynetworks,
|
||||
check_sender_access ${sql}sqlite-reject-spoofed.cf,
|
||||
check_sender_access ${podop}sender,
|
||||
reject_non_fqdn_sender,
|
||||
reject_unknown_sender_domain,
|
||||
reject_unknown_recipient_domain,
|
||||
reject_unverified_recipient,
|
||||
permit
|
||||
|
||||
smtpd_relay_restrictions =
|
||||
permit_mynetworks,
|
||||
permit_sasl_authenticated,
|
||||
reject_unauth_destination
|
||||
|
||||
unverified_recipient_reject_reason = Address lookup failure
|
||||
|
||||
###############
|
||||
|
||||
@@ -7,7 +7,8 @@ smtp inet n - n - - smtpd
|
||||
# Internal SMTP service
|
||||
10025 inet n - n - - smtpd
|
||||
-o smtpd_sasl_auth_enable=yes
|
||||
-o smtpd_recipient_restrictions=reject_unlisted_sender,reject_authenticated_sender_login_mismatch,permit
|
||||
-o smtpd_client_restrictions=reject_unlisted_sender,reject_authenticated_sender_login_mismatch,permit
|
||||
-o smtpd_reject_unlisted_recipient={% if REJECT_UNLISTED_RECIPIENT %}{{ REJECT_UNLISTED_RECIPIENT }}{% else %}no{% endif %}
|
||||
-o cleanup_service_name=outclean
|
||||
outclean unix n - n - 0 cleanup
|
||||
-o header_checks=pcre:/etc/postfix/outclean_header_filter.cf
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
dbpath = /data/main.db
|
||||
query =
|
||||
SELECT 'REJECT' FROM domain WHERE name='%s'
|
||||
UNION
|
||||
SELECT 'REJECT' FROM alternative WHERE name='%s'
|
||||
@@ -1,3 +0,0 @@
|
||||
dbpath = /data/main.db
|
||||
query =
|
||||
SELECT 'smtp:['||smtp||']' FROM relay WHERE name='%s'
|
||||
@@ -1,23 +0,0 @@
|
||||
dbpath = /data/main.db
|
||||
query =
|
||||
SELECT destination
|
||||
FROM
|
||||
(SELECT destination, email, wildcard, localpart, localpart||'@'||alternative.name AS alt_email FROM alias LEFT JOIN alternative ON alias.domain_name = alternative.domain_name
|
||||
UNION
|
||||
SELECT (CASE WHEN forward_enabled=1 THEN (CASE WHEN forward_keep=1 THEN email||',' ELSE '' END)||forward_destination ELSE email END) AS destination, email, 0 as wildcard, localpart, localpart||'@'||alternative.name as alt_email FROM user LEFT JOIN alternative ON user.domain_name = alternative.domain_name
|
||||
UNION
|
||||
SELECT '@'||domain_name as destination, '@'||name as email, 0 as wildcard, '' as localpart, NULL AS alt_email FROM alternative)
|
||||
WHERE
|
||||
(
|
||||
wildcard = 0
|
||||
AND
|
||||
(email = '%s' OR alt_email = '%s')
|
||||
) OR (
|
||||
wildcard = 1
|
||||
AND
|
||||
'%s' LIKE email
|
||||
)
|
||||
ORDER BY
|
||||
wildcard ASC,
|
||||
length(localpart) DESC
|
||||
LIMIT 1
|
||||
@@ -1,5 +0,0 @@
|
||||
dbpath = /data/main.db
|
||||
query =
|
||||
SELECT name FROM domain WHERE name='%s'
|
||||
UNION
|
||||
SELECT name FROM alternative WHERE name='%s'
|
||||
@@ -1,15 +1,35 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python3
|
||||
|
||||
import jinja2
|
||||
import os
|
||||
import socket
|
||||
import glob
|
||||
import shutil
|
||||
|
||||
import tenacity
|
||||
import multiprocessing
|
||||
|
||||
from tenacity import retry
|
||||
from podop import run_server
|
||||
|
||||
|
||||
def start_podop():
|
||||
os.setuid(100)
|
||||
run_server(3 if "DEBUG" in os.environ else 0, "postfix", "/tmp/podop.socket", [
|
||||
("transport", "url", "http://admin/internal/postfix/transport/§"),
|
||||
("alias", "url", "http://admin/internal/postfix/alias/§"),
|
||||
("domain", "url", "http://admin/internal/postfix/domain/§"),
|
||||
("mailbox", "url", "http://admin/internal/postfix/mailbox/§"),
|
||||
("sender", "url", "http://admin/internal/postfix/sender/§")
|
||||
])
|
||||
|
||||
convert = lambda src, dst: open(dst, "w").write(jinja2.Template(open(src).read()).render(**os.environ))
|
||||
|
||||
@retry(stop=tenacity.stop_after_attempt(100), wait=tenacity.wait_random(min=2, max=5))
|
||||
def resolve():
|
||||
os.environ["FRONT_ADDRESS"] = socket.gethostbyname(os.environ.get("FRONT_ADDRESS", "front"))
|
||||
|
||||
# Actual startup script
|
||||
os.environ["FRONT_ADDRESS"] = socket.gethostbyname(os.environ.get("FRONT_ADDRESS", "front"))
|
||||
resolve()
|
||||
os.environ["HOST_ANTISPAM"] = os.environ.get("HOST_ANTISPAM", "antispam:11332")
|
||||
os.environ["HOST_LMTP"] = os.environ.get("HOST_LMTP", "imap:2525")
|
||||
|
||||
@@ -32,7 +52,8 @@ for map_file in glob.glob("/overrides/*.map"):
|
||||
|
||||
convert("/conf/rsyslog.conf", "/etc/rsyslog.conf")
|
||||
|
||||
# Run postfix
|
||||
# Run Podop and Postfix
|
||||
multiprocessing.Process(target=start_podop).start()
|
||||
if os.path.exists("/var/run/rsyslogd.pid"):
|
||||
os.remove("/var/run/rsyslogd.pid")
|
||||
os.system("/usr/lib/postfix/post-install meta_directory=/etc/postfix create-missing")
|
||||
|
||||
Reference in New Issue
Block a user