Package: postfix-mta-sts-resolver
postfix-mta-sts-resolverDaemon which provides TLS client policy for Postfix via socketmap, according to domain MTA-STS policy.Current support ofRFC 8461is limited:MTA-STS policy overrides DANE TLS authenticationagainstRFC 8461, 2.Daemon lacks some minor features:Fetch error reporting.Fetch ratelimit (but actual fetch rate partially restricted withcache_graceconfig option).Server has configurable cache backend which allows to store cached STS policies in memory (internal), file (sqlite) or in Redis database (redis).RequirementsPostfix 3.4+ (or Postfix 2.10+ if missing Postfix SNI feature is tolerable. In that case you have to set zone optionrequire_snitofalsein MTA-STS daemon config)Python 3.5.3+ (see"Systems without Python 3.5+"below if you haven't one, or use Docker installation method)aiodnsaiohttpaiosqliteredis-pyPyYAML(optional) uvloopAll dependency packages installed automatically if this package is installed via pip.InstallationMethod 1. System-wide install from PyPI (recommended for humans)Run:sudopython3-mpipinstallpostfix-mta-sts-resolver[redis,sqlite,postgres]If you don't needredisorsqlitesupport, you may omit one of them in square brackets. If you don't need any of them and you plan to use internal cache without persistence, you should also omit square brackets.Package scripts shall be available in standard executable locations upon completion.pip user installAll pip invocations can be run with--useroption ofpipinstaller. In this case superuser privileges are not required and package(s) are getting installed into user home directory. Usually, script executables will appear in~/.local/bin.Method 2. System-wide install from project sourceRun in project directory:sudopython3-mpipinstall.[redis,sqlite,postgres]If you don't needredis,sqliteorpostgressupport, you may omit one of them in square brackets. If you don't need any of them and you plan to use internal cache without persistence, you should also omit square brackets.Package scripts shall be available in standard executable locations upon completion.Method 3. Install into virtualenvSee"Building virtualenv"Method 4. DockerRundockervolumecreatemta-sts-cache
dockerrun-d\--security-optno-new-privileges\-vmta-sts-cache:/var/lib/mta-sts\-p127.0.0.1:8461:8461\--restartunless-stopped\--namepostfix-mta-sts-resolver\yarmak/postfix-mta-sts-resolverDaemon will be up and running, listening on local interface on port 8461. Default configuration baked into docker image uses SQLite for cache stored in persistent docker volume. You may override this configuration with your own config file by mapping it into container with option-v my_config.yml:/etc/mta-sta-daemon.yml.Method 5. Snap Storesudosnapinstallpostfix-mta-sts-resolverNOTE: in snap layoutmta-sta-daemonprogram is namedpostfix-mta-sts-resolver.daemonandmta-sts-queryis namedpostfix-mta-sts-resolver.query.Common installation notesSee alsocontrib/README.mdfor RHEL/OEL/Centos and FreeBSD notes.Seecontrib/for example of systemd unit file suitable to run daemon under systemd control.RunningThis package provides two executables available after installation in respective locations.mta-sts-querymta-sts-queryis a command line tool which fetches and outputs domain MTA-STS policies. Intended to be used for debug purposes.Synopsis:$ mta-sts-query --help
usage: mta-sts-query [-h] [-v {debug,info,warn,error,fatal}]
                     domain [known_version]

positional arguments:
  domain                domain to fetch MTA-STS policy from
  known_version         latest known version (default: None)

optional arguments:
  -h, --help            show this help message and exit
  -v {debug,info,warn,error,fatal}, --verbosity {debug,info,warn,error,fatal}
                        logging verbosity (default: warn)mta-sts-daemonmta-sts-daemonis a daemon which provides externalTLS policy for Postfix SMTP clientviasocketmap interface.You may find useful systemd unit file to run daemon incontrib/.Synopsis:$ mta-sts-daemon --help
usage: mta-sts-daemon [-h] [-v {debug,info,warn,error,fatal}] [-c FILE]
                      [-l FILE] [--disable-uvloop]

optional arguments:
  -h, --help            show this help message and exit
  -v {debug,info,warn,error,fatal}, --verbosity {debug,info,warn,error,fatal}
                        logging verbosity (default: info)
  -c FILE, --config FILE
                        config file location (default: /etc/mta-sts-
                        daemon.yml)
  -l FILE, --logfile FILE
                        log file location (default: None)
  --disable-uvloop      do not use uvloop even if it is available (default:
                        False)Seamless restart/upgrade/reload and load balancingBy default mta-sts-daemon allows its multiple instances to share same port (on Linux/FreeBSD/Windows). Therefore, restart or upgrade of daemon can be performed seamlessly. Set of unit files for systemd incontrib/directory implements "reload" by mean of running backup instance when main instance is getting restarted.Also on Linux and FreeBSD, load distributed across all processes (with SO_REUSEPORT and SO_REUSEPORT_LB respectively).MTA-STS Daemon configurationSeeconfiguration man pageandconfig_examples/directory. Default config location is:/etc/mta-sts-daemon.yml, but it can be overridden with command line option-c FILE.All options is self-explanatory, only exception isstrict_testingoption. If set totrue, STS policy will be enforced even if domain announcestestingMTA-STS mode. Useful for premature incorporation of MTA-STS against domains hesitating to goenforce. Please use with caution.Postfix configurationSMTP client of your Postfix instance must be able to validate peer certificates. In order to achieve that, you have to ensuresmtp_tls_CAfileorsmtp_tls_CApathpoints to system CA bundle. Otherwise you'll getUnverified TLS connectioneven for peers with valid certificate, and delivery failures for MTA-STS-enabled destinations. Also note: even enabledtls_append_default_CAwill not work alone if bothsmtp_tls_CAfileandsmtp_tls_CApathare empty.Once certificate validation is enabled and your Postfix log shows "Trusted TLS connection ... " for destinations with valid certificates signed by public CA, you may enable MTA-STS by adding following line tomain.cf:smtp_tls_policy_maps = socketmap:inet:127.0.0.1:8461:postfixIf your configuration already has some TLS policy maps, just add MTA-STS socketmap to list of configured maps accordingly tosmtp_tls_policy_mapssyntax. TLS policy tables are searched in the specified order until a match is found, so you may have table with local overrides of TLS policy prior to MTA-STS socketmap. This may be useful for skipping network lookup for well-known destinations or relaxing security for broken destinations, announcing MTA-STS support.Reload Postfix after reconfiguration.Warning: MTA-STS policy overrides DANE TLS authenticationDue to Postfix's limitations, a resolved MTA-STS policy overrides DANE TLS authentication (RFC 6698), because DANE is an internal feature of Postfix, and the postfix-mta-sts-resolver always responds with a (smtp_tls_policy_maps) lookup resultsecureforSecure server certificate verification.The resulting behaviour is againstRFC 8461, 2:However, MTA-STS is designed not to interfere with DANE deployments when the two overlap; in particular, senders who implement MTA-STS validation MUST NOT allow MTA-STS Policy validation to override a failing DANE validation.Domains implementing both MTA-STS and DANE probably want DANE to be preferred:DANE allows strict binding of certificates; the policy can authorize only a certain certificate or certificates from a certain CA. With MTA-STS, a certificate from any trusted CA is automatically trusted;RFC 8461, 10.1:SMTP MTA-STS relies on certificate validation via PKIX-based TLS identity checking [RFC6125].  Attackers who are able to obtain a
valid certificate for the targeted recipient mail service (e.g., by compromising a CA) are thus able to circumvent STS authentication.Based on DNSSEC, DANE not vulnerable to downgrade attack that could prevent policy discovery. MTA-STS security considerations acknowledges this weakness inRFC 8461, 10.2:Since MTA-STS uses DNS TXT records for policy discovery, an attacker who is able to block DNS responses can suppress the discovery of an
MTA-STS Policy, making the Policy Domain appear not to have an MTA-STS Policy.Resistance to downgrade attacks of this nature -- due to the ability to authoritatively determine "lack of a record" even for non-participating recipients -- is a feature of DANE, due to its use of DNSSEC for policy discovery.The postfix-mta-sts-resolver does not intent to implement policy lookups for DANE, and responses other thansecurewithmatch=would not verify the TLS certificate as required byRFC 8461, 4,2.If you wish to meet this requirement:List a DANE policy resolver responding withdane-only(forMandatory DANE) before postfix-mta-sts-resolver insmtp_tls_policy_mapslookup table list.Alternatively, you could use a static lookup table for domains known to implement both MTA-STS & DANE, e.g.,smtp_tls_policy_maps = hash:/etc/postfix/tls_policy,socketmap:inet:127.0.0.1:8461:postfixOperability checkAssuming default MTA-STA daemon configuration. Following command:/usr/sbin/postmap-qdismail.desocketmap:inet:127.0.0.1:8461:postfixshould return something like:secure match=mx1.dismail.dePostfix log should showVerified TLS connection established to ...instead ofUntrusted ...orTrusted TLS connection established to ...when mail is getting sent to MTA-STS-enabled domain.Special cases of deploymentSystems without Python 3.5+Some people may find convenient to install latest python from source into/optdirectory. This way you can have separate python installation not interfering with system packages by any means. Download latest python source frompython.org, unpack and run in unpacked source directory:./configure--prefix=/opt--enable-optimizations&&make-j$[$(nproc)+1]&&maketest&&sudomakeinstallPython binaries will be available in/opt/bin, includingpip3. You may installpostfix-mta-sts-resolverusing/opt/bin/pip3without interference with any system packages:sudo/opt/bin/pip3installpostfix-mta-sts-resolver[sqlite,redis]Executable files ofpostfix-mta-sts-resolverwill be available in/opt/bin/mta-sts-queryand/opt/bin/mta-sts-daemonBuilding virtualenvRunmakein project directory in order to build virtualenv. As result of it, new directoryvenvshall appear.venvcontains interpreter and all required dependencies, i.e. encloses package with dependencies in separate environment. It is possible to specify alternative path where virtualenv directory shall be placed. Specify VENV variable formakecommand. Example:makeVENV=~/postfix-mta-sts-resolverSuch virtual environment can be moved to another machine of similar type (as far python interpreter is compatible with new environment). If virtualenv is placed into same location on new machine, application can be run this way:venv/bin/mta-sts-daemonOtherwise, some hacks required. First option - explicitly call virtualenv interpreter:venv/bin/pythonvenv/bin/mta-sts-daemonSecond option - specify new path in shebang of scripts installed in virtualenv. It is recommended to build virtualenv at same location which app shall occupy on target system.CreditsInspired bythis forum thread.