MTPOLICYD(1p)

πŸ’– MTPOLICYD πŸ’–

okay bestie, welcome to mtpolicyd(1p) β€” that's the User Contributed Perl Documentation section, and yes we're reading man pages for fun now, that's just who we are πŸ’…

this page is literally about mtpolicyd, the executable. she's the main character.


✨ NAME ✨

mtpolicyd β€” the mtpolicyd executable. that's it, that's her πŸŽ€


🌸 VERSION 🌸

version 2.05 ✨ (she's grown, she's thriving)


πŸ¦‹ DESCRIPTION πŸ¦‹

so like, mtpolicyd is a policy daemon for postfix access delegation. that's the whole vibe.

you can configure her to accept connections on several ports from a postfix MTA. and for each port a VirtualHost can be configured, and for each VirtualHost several Plugins can be configured. it's giving layered, it's giving modular, it's giving organized queen πŸ‘‘


πŸŽ€ NAME πŸŽ€

mtpolicyd β€” a modular policy daemon for postfix. (yes bestie there are two NAME sections, the original said so, we don't question the ancients πŸ™ˆ)


🌈 EXAMPLE 🌈

In postfix main.cf:

smtpd_recipient_restrictions = check_policy_service inet:127.0.0.1:12345

In mtpolicyd.conf:

# listen on port 12345 (multiple ports can be separated by ',')
port="127.0.0.1:12345"

# defined host for this port
<VirtualHost 12345>
  name=example_vhost
  <Plugin spamhaus_bl>
    module="RBL"
    domain="sbl.spamhaus.org"
    mode=reject
  </Plugin>
</VirtualHost>

this check will execute a simple RBL lookup against dbl.spamhaus.org. no cap. ✨


πŸ’… COMMANDLINE OPTIONS πŸ’…

mtpolicyd
  [-h|--help]
  [-c|--config=<file>]
  [-f|--foreground]
  [-l|--loglevel=<level>]
  [-d|--dump_vhosts]
  • -h, --help β€” show available command line options. she's helpful like that 🫢
  • -c, --config=<file> β€” specify the path to the configuration file. (default: /etc/mtpolicyd/mtpolicyd.conf)
  • -f, --foreground β€” do not fork to background and log to stdout. stay right there in front of me, bestie 😭
  • -l, --loglevel=<level> β€” overwrite the log level specified in the configuration with the specified level. yes ma'am, overriding πŸŽ€
  • -d, --dump_vhosts β€” parse VirtualHosts configuration, print it to stdout and exit. show me everything and then dip πŸ’€

🧚 CONFIGURATION FILE 🧚

the configuration file is implementend with Config::General which allows apache style configuration files. (yes "implementend", we keep it exactly, don't @ me πŸ“)

mtpolicyd accepts global configuration parameters in the style:

key=value

comments begin with '#'. iconic, classic, timeless ⭐

VirtualHosts must be configured with VirtualHost sections:

<VirtualHost <portnumber>>
  name=<name of the vhost>
</VirtualHost>

each VirtualHost should contain at least on Plugin. (again, verbatim, love that for us πŸ’–)

<VirtualHost <portnumber>>
  name=<name of the vhost>
  <Plugin <name of check> >
    module = "<name of plugin>"
    # plugin options
    key=value
  </Plugin>
</VirtualHost>

for individual plugin configuration options see the man page of the plugin:

Mail::MtPolicyd::Plugin::<name of plugin>

πŸ‘‘ GLOBAL CONFIGURATION OPTIONS πŸ‘‘

  • user β€” user id to run as
  • group β€” group id to run as
  • pid_file β€” location of the pid file
  • log_level β€” verbosity of logging: 0=>'err', 1=>'warning', 2=>'notice', 3=>'info', 4=>'debug'
  • host β€” ip address to bind to.
  • port β€” comma separated list of ports to listen on.
  • min_servers β€” the minimum number of client processes to start. (default: 4)
  • min_spare_servers β€” the minimum number of client processes that should hanging around idle and wait for new connections. (default: 4)

if the number of free processes is below this threshold mtpolicyd will start to create new child processes.

  • max_spare_servers β€” the maximum number of idle processes. (default: 12)

if the number of idle processes is over this threshold mtpolicyd will start to shutdown child processes.

  • max_servers β€” the absolute maximum number of child processes to start. (default: 25)
  • max_requests (default: 1000)
  • max_keepalive (default: 0) β€” number of requests after that mtpolicyd closes the connection or no limit if set to zero.

should be the same value as smtpd_policy_service_reuse_count_limit (postfix >2.12) in postfix/smtpd configuration. match your bestie's energy fr fr 🫢

  • vhost_by_policy_context β€” select VirtualHost by 'policy_context' request field. (default: 0)

the policy_context will be matched against the 'name' field of the VirtualHost.

for example in postfix main.cf use advanced syntax:

check_policy_service { inet:localhost:12345, policy_context=reputation }
...
check_policy_service { inet:localhost:12345, policy_context=accounting }

In mtpolicyd.conf:

port="127.0.0.1:12345" # only 1 port
vhost_by_policy_context=1
<VirtualHost 12345>
  name=reputation
  ... plugins ...
</VirtualHost>

<VirtualHost 12345>
  name=accounting
  ... plugins ...
</VirtualHost>

the policy_context feature will be available in postfix 3.1 and later.

if you just need small differentiations consider using the Mail::MtPolicyd::Plugin::Condition plugin to match against plugin_context field. (yep, plugin_context β€” that's what it says, don't come for me πŸ™ˆ)

  • request_timeout β€” maximum total time for one request.

πŸ”₯ CONFIGURE CONNECTIONS πŸ”₯

mtpolicyd has a global per process connection pool. (a whole pool, a whole vibe 🏊)

connections could be registered within the connection pool using a <Connection> block within the configuration. you must at least specify the name of the connection and the module for the connection type.

<Connection [name of connection]>
  module = "[connection type]"
  # ... addditional parameters
</Connection>

connection modules may require additional parameters.

currently supported connection modules:

  • Sql β€” Perl DBI based connections for SQL databases.

Mail::MtPolicyd::Connection::Sql

  • Memcached β€” connection to a memcached server/cluster.

Mail::MtPolicyd::Connection::Memcached

  • Ldap β€” connection to an LDAP directory server.

Mail::MtPolicyd::Connection::Ldap


🌟 SESSION MANAGEMENT 🌟

mtpolicyd implements session managemend to cache data across different checks for requests with the same instance id.

mtpolicy is able to generate a session for each mail passed to it and store it within the session cache. the attached session information will be available to all following plugins across child processes, virtual hosts and ports. it's giving sharing is caring πŸ’–

plugins will use this session information to cache lookup etc. across multiple requests for the same mail. Postfix will send a query for each recipient and for each configured check_policy_service call.

to enable the SessionCache specify a <SessionCache> block within your configuration:

<SessionCache>
  module = "Memcached"
  expire = "300"
  lock_wait=50
  lock_max_retry=50
  lock_timeout=10
</SessionCache>

the example requires that a connection of type "Memcached" and the name "memcached" is configured within the connection pool. for details read Mail::MtPolicyd::SessionCache::Memcached.

as of version 2.00 it is possible to implement different session caches. glow up era ✨

currently there are 2 session cache modules:

  • Mail::MtPolicyd::SessionCache::Memcached
  • Mail::MtPolicyd::SessionCache::Redis

⭐ PROCESSING OF REQUEST ⭐

the policy daemon will process all plugins in the order they appear in the configuration file. it will stop as soon as a plugin returns an action and will return this action to the MTA. first come, first served, and then she's done πŸ’…


🎯 SCORING 🎯

most plugins can be configured to not return an action if the performed check matched. (passive queen behavior)

for example the RBL module could be set to passive mode and instead a score could be applied to the request:

<Plugin spamhaus>
  module = "RBL"
  mode = "passive"
  domain="zen.spamhaus.org"
  score=5
</Plugin>

check the documentation of the plugin for certain score/mode parameters. plugin may provide more than one mode/score parameters if they do several checks.

now if you configure more than one RBL check the score will add up. later an action can be taken based on the score. the ScoreAction plugin will return an action based on the score and the AddScoreHeader plugin will prepend the score as a header to the mail:

<Plugin ScoreReject>
  module = "ScoreAction"
  threshold = 15
  action = "reject sender ip %IP% is blocked (score=%SCORE%%SCORE_DETAIL%)"
</Plugin>
<Plugin ScoreTag>
  module = "AddScoreHeader"
  spam_score=5
</Plugin>

math is mathing, scores are scoring πŸ”₯


🌸 UPGRADING 🌸

πŸ’œ FROM 1.x to 2.x

with mtpolicyd 2.x configuration of connections and session cache has been changed. glow up, but make it a breaking change 😭

Database Connections

in mtpolicyd 2.00 the connections defined globaly in the configuration file have been replaced by a dynamic connection pool.

the global options db_* ldap_* and memcached_* have been removed. (gone, deceased, no longer with us πŸ’€)

instead connections are registered within a connection pool.

you can define them using <Connection> blocks:

<Connection myconn>
  module = "<adapter>"
  # parameter = "value"
  # ...
</Connection>

In mtpolicyd 1.x:

db_dsn=DBI:mysql:mtpolicyd
db_user=mtpolicyd
db_password=secret

In mtpolicyd 2.x:

<Connection db>
   dsn = "DBI:mysql:mtpolicyd"
   user = "mtpolicyd"
   password = "secret"
</Connection>

all SQL modules will by default use the connection registered as "db".

see modules in Mail::MtPolicyd::Connection::* for available connection adapters.

Session Cache

starting with mtpolicyd 2.x it is possible to use other session caches then memcached. (again: "then", not "than" β€” we copy exactly, we don't fix, that's the rule πŸŽ€)

the global session_* parameters have been removed.

instead the session cache is defined by a <SessionCache> block:

<SessionCache>
  module = "<module>"
  # parameter = "value"
  # ...
</SessionCache>

a memcached session cache in mtpolicyd v1.x:

memcached_servers="127.0.0.1:11211"

session_lock_wait=50
session_lock_max_retry=50
session_lock_timeout=10

In mtpolicyd 2.x:

<Connection memcached>
  servers = "127.0.0.1:11211"
</Connection>

<SessionCache>
  module = "Memcached"
  # defaults to connection "memcached"
  # memcached = "memcached"
  lock_wait = "50"
  lock_max_retry = "50"
  lock_timeout = "10"
</SessionCache>

if no <SessionCache> is defined it will default to the dummy session cache module "None".

see modules in Mail::MtPolicyd::SessionCache::* for available session cache modules.


🫢 AUTHOR 🫢

Markus Benning <ich@markusbenning.de> β€” legend behavior, honestly πŸ‘‘


this software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>.

this is free software, licensed under:

The GNU General Public License, Version 2, June 1991

⚠️ bestie, real talk: everything above is verbatim what the page says. if a config block or option isn't here, it isn't a thing β€” don't invent flags, don't guess behavior, and definitely don't skip the warnings. she's free software, but she's still software πŸ’–

and that's the whole page, you ate it, no crumbs left. this was documented by perl v5.38.2 on 2024-05-26 β€” shoutout to the toolchain, and shoutout to you for reading a man page for fun. periodt. πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from