10 pmgconfig - Proxmox Mail Gateway Configuration Management Toolkit
16 include::pmgconfig.1-synopsis.adoc[]
23 Configuration Management
24 ========================
28 {pmg} is usually configured using the web-based Graphical User
29 Interface (GUI), but it is also possible to directly edit the
30 configuration files, use the REST API over 'https'
31 or the command line tool `pmgsh`.
33 The command line tool `pmgconfig` is used to simplify some common
34 configuration tasks, i.e. to generate cerificates and to rewrite
35 service configuration files.
37 NOTE: We use a Postgres database to store mail filter rules and
38 statistic data. See chapter xref:chapter_pmgdb[Database Management]
42 Configuration files overview
43 ----------------------------
45 `/etc/network/interfaces`::
47 Network setup. We never modify this files directly. Instead, we write
48 changes to `/etc/network/interfaces.new`. When you reboot, we rename
49 the file to `/etc/network/interfaces`, so any changes gets activated
54 DNS search domain and nameserver setup.
58 The system's host name.
62 Static table lookup for hostnames.
66 Stores common administration options, i.e. the spam and mail proxy setup.
68 `/etc/pmg/cluster.conf`::
74 The list of relay domains.
76 `/etc/pmg/dkim/domains`::
78 The list of domains for outbound DKIM signing.
80 `/etc/pmg/fetchmailrc`::
82 Fetchmail configuration (POP3 and IMAP setup).
84 `/etc/pmg/ldap.conf`::
88 `/etc/pmg/mynetworks`::
90 List of local (trusted) networks.
92 `/etc/pmg/subscription`::
94 Stores your subscription key and status.
96 `/etc/pmg/tls_policy`::
98 TLS policy for outbound connections.
100 `/etc/pmg/transports`::
102 Message delivery transport setup.
104 `/etc/pmg/user.conf`::
106 GUI user configuration.
108 `/etc/mail/spamassassin/custom.cf`::
110 Custom {spamassassin} setup.
112 `/etc/mail/spamassassin/pmg-scores.cf`::
114 Custom {spamassassin} rule scores.
116 Keys and Certificates
117 ---------------------
119 `/etc/pmg/pmg-api.pem`::
121 Key and certificate (combined) used be the HTTPs server (API).
123 `/etc/pmg/pmg-authkey.key`::
125 Privat key use to generate authentication tickets.
127 `/etc/pmg/pmg-authkey.pub`::
129 Public key use to verify authentication tickets.
131 `/etc/pmg/pmg-csrf.key`::
133 Internally used to generate CSRF tokens.
135 `/etc/pmg/pmg-tls.pem`::
137 Key and certificate (combined) to encrypt mail traffic (TLS).
139 `/etc/pmg/dkim/<selector>.private`::
141 Key for DKIM signing mails with selector '<selector>'.
144 [[pmgconfig_template_engine]]
145 Service Configuration Templates
146 -------------------------------
148 {pmg} uses various services to implement mail filtering, for example
149 the {postfix} Mail Transport Agent (MTA), the {clamav} antivirus
150 engine and the Apache {spamassassin} project. Those services use
151 separate configuration files, so we need to rewrite those files when
152 configuration is changed.
154 We use a template based approach to generate those files. The {tts} is
155 a well known, fast and flexible template processing system. You can
156 find the default templates in `/var/lib/pmg/templates/`. Please do not
157 modify them directly, because your modification would get lost on the
158 next update. Instead, copy the template you wish to change to
159 `/etc/pmg/templates/`, then apply your changes there.
161 Templates can access any configuration setting, and you can use the
162 `pmgconfig dump` command to get a list of all variable names:
167 dns.domain = yourdomain.tld
169 ipconfig.int_ip = 192.168.2.127
170 pmg.admin.advfilter = 1
174 The same tool is used to force regeneration of all template based
175 configuration files. You need to run that after modifying a template,
176 or when you directly edit configuration files
179 # pmgconfig sync --restart 1
182 The above command also restarts services if the underlying configuration
183 files are changed. Please note that this is automatically done when
184 you change the configuration using the GUI or API.
186 NOTE: Modified templates from `/etc/pmg/templates/` are automatically
187 synced from the master node to all cluster members.
190 [[pmgconfig_systemconfig]]
198 [thumbnail="pmg-gui-network-config.png", big=1]
201 Normally the network and time is already configured when you visit the
202 GUI. The installer asks for those settings and sets up the correct
205 The default setup uses a single Ethernet adapter and static IP
206 assignment. The configuration is stored at '/etc/network/interfaces',
207 and the actual network setup is done the standard Debian way using
210 .Example network setup '/etc/network/interfaces'
212 source /etc/network/interfaces.d/*
215 iface lo inet loopback
218 iface ens18 inet static
219 address 192.168.2.127
220 netmask 255.255.240.0
226 Many tests to detect SPAM mails use DNS queries, so it is important to
227 have a fast and reliable DNS server. We also query some public
228 available DNS Blacklists. Most of them apply rate limits for clients,
229 so they simply will not work if you use a public DNS server (because
230 they are usually blocked). We recommend to use your own DNS server,
231 which need to be configured in 'recursive' mode.
238 [thumbnail="pmg-gui-system-options.png", big=1]
242 Those settings are saved to subsection 'admin' in `/etc/pmg/pmg.conf`,
243 using the following configuration keys:
245 include::pmg.admin-conf-opts.adoc[]
248 Mail Proxy Configuration
249 ------------------------
251 [[pmgconfig_mailproxy_relaying]]
256 [thumbnail="pmg-gui-mailproxy-relaying.png", big=1]
259 Those settings are saved to subsection 'mail' in `/etc/pmg/pmg.conf`,
260 using the following configuration keys:
262 include::pmg.mail-relaying-conf-opts.adoc[]
264 [[pmgconfig_mailproxy_relay_domains]]
269 [thumbnail="pmg-gui-mailproxy-relaydomains.png", big=1]
272 List of relayed mail domains, i.e. what destination domains this
273 system will relay mail to. The system will reject incoming mails to
277 [[pmgconfig_mailproxy_ports]]
282 [thumbnail="pmg-gui-mailproxy-ports.png", big=1]
285 Those settings are saved to subsection 'mail' in `/etc/pmg/pmg.conf`,
286 using the following configuration keys:
288 include::pmg.mail-ports-conf-opts.adoc[]
291 [[pmgconfig_mailproxy_options]]
296 [thumbnail="pmg-gui-mailproxy-options.png", big=1]
299 Those settings are saved to subsection 'mail' in `/etc/pmg/pmg.conf`,
300 using the following configuration keys:
302 include::pmg.mail-options-conf-opts.adoc[]
305 [[pmgconfig_mailproxy_before_after_queue]]
306 Before and After Queue scanning
307 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
309 Scanning email can happen at two different stages of mail-processing:
311 * During the SMTP Session after the complete message has been received (after
312 the 'DATA' command), known as 'before queue filtering'.
314 * After intially accepting the mail and putting it on a queue for further
315 processing, known as 'after queue filtering'.
317 The former has the advantage that the system can reject a mail (by sending a
318 permanent reject code '554'), and leave the task of notifying the original
319 sender to the other mailserver. This is of particular advantage if the
320 processed mail is a spam message or contains a virus and has a forged
321 sender-address. Sending out a notification in this situation leads so-called
322 'backscatter' mail, which might cause your server to get listed as spamming on
325 The latter has the advantage of providing faster delivery of mails for the
326 sending servers, since queueing mails is much faster than analyzing it for
329 If a mail is addressed to multiple recipients (e.g. when multiple addresses are
330 subscribed to the same mailinglist) the situation is more complicated: Your
331 mailserver can only reject or accept the mail for all recipients, after having
332 received the complete message, while your rule setup might accept the mail for
333 part of the recipients and reject it for others. This can be due to a
334 complicated rule setup, or if your users use the 'User White- and Blacklist'
337 If the resulting action of the rule system is the same for all recipients {pmg}
338 responds accordingly if configured for before queue filtering (sending '554'
339 for a blocked mail and '250' for an accepted or quarantined mail). If some
340 mailboxes accept the mail and some reject it the system has to accept the mail.
342 Whether {pmg} notifies the sender that delivery failed for some recipients by
343 sending a non-delivery report, depends on the 'ndr_on_block' setting in
344 '/etc/pmg/pmg.conf'. If enabled an NDR is sent. Keeping it disabled prevents
345 NDRs being sent to the (possibly forged) sender and thus minimizes the chance
346 of getting your IP listed on a RBL. However in certain environments it can be
347 unacceptable not to inform the sender about a rejected mail.
349 The setting has the same effect if after queue filtering is configured, with
350 the exception that an NDR is always sent out, even if all recipients block the
351 mail, since the mail already got accepted before being analyzed.
353 The details of integrating the mail proxy with {postfix} in both setups are
354 explained in {postfix_beforequeue} and {postfix_afterqueue} respectively.
356 NOTE: Since before queue filtering is currently incompatible with the
357 'Tracking Center' you need to enable it by manually
358 editing '/etc/pmg/pmg.conf'.
361 [[pmgconfig_mailproxy_transports]]
366 [thumbnail="pmg-gui-mailproxy-transports.png", big=1]
369 You can use {pmg} to send e-mails to different internal
370 e-mail servers. For example you can send e-mails addressed to
371 domain.com to your first e-mail server, and e-mails addressed to
372 subdomain.domain.com to a second one.
374 You can add the IP addresses, hostname, transport protocol (smtp/lmtp),
375 transport ports and mail domains (or just single email addresses)
376 of your additional e-mail servers. When transport protocol is set to `lmtp`,
377 the option 'Use MX' is useless and will be automatically set to 'No'.
380 [[pmgconfig_mailproxy_networks]]
385 [thumbnail="pmg-gui-mailproxy-networks.png", big=1]
388 You can add additional internal (trusted) IP networks or hosts.
389 All hosts in this list are allowed to relay.
391 NOTE: Hosts in the same subnet with Proxmox can relay by default and
392 it’s not needed to add them in this list.
395 [[pmgconfig_mailproxy_tls]]
400 [thumbnail="pmg-gui-mailproxy-tls.png", big=1]
403 Transport Layer Security (TLS) provides certificate-based
404 authentication and encrypted sessions. An encrypted session protects
405 the information that is transmitted with SMTP mail. When you activate
406 TLS, {pmg} automatically generates a new self signed
407 certificate for you (`/etc/pmg/pmg-tls.pem`).
409 {pmg} uses opportunistic TLS encryption by default. The SMTP transaction is
410 encrypted if the 'STARTTLS' ESMTP feature is supported by the remote
411 server. Otherwise, messages are sent in the clear.
412 You can set a different TLS policy per desitination domain, should you for
413 example need to prevent e-mail delivery without encryption, or to work around
414 a broken 'STARTTLS' ESMTP implementation. See {postfix_tls_readme} for details
415 on the supported policies.
419 To get additional information about SMTP TLS activity you can enable
420 TLS logging. That way information about TLS sessions and used
421 certificate’s is logged via syslog.
423 Add TLS received header::
425 Set this option to include information about the protocol and cipher
426 used as well as the client and issuer CommonName into the "Received:"
429 Those settings are saved to subsection 'mail' in `/etc/pmg/pmg.conf`,
430 using the following configuration keys:
432 include::pmg.mail-tls-conf-opts.adoc[]
435 [[pmgconfig_mailproxy_dkim]]
440 [thumbnail="pmg-gui-mailproxy-dkim.png", big=1]
443 DomainKeys Identified Mail (DKIM) Signatures (see {dkim_rfc}) is a method to
444 cryptographically authenticate a mail as originating from a particular domain.
445 Before sending the mail a hash over certain header fields and the body is
446 computed, signed with a private key and added in the `DKIM-Signature` header of
447 the mail. The 'selector' (a short identifier chosen by you, used to identify
448 which system and private key were used for signing) is also included in the
449 `DKIM-Signature` header.
451 The verification is done by the receiver: The public key is fetched
452 via DNS TXT lookup for `yourselector._domainkey.yourdomain.example` and used
453 for verifying the hash. You can publish multiple selectors for your domain,
454 each use by a system which sends e-mail from your domain, without the need to
455 share the private key.
457 {pmg} verifies DKIM Signatures for inbound mail in the Spam Filter by default.
459 Additionally it supports conditionally signing outbound mail if configured.
460 It uses one private key and selector per PMG deployment (all nodes in a cluster
461 use the same key). The key has a minimal size of 1024 bits and rsa-sha256 is
462 used as signing algorithm.
464 The headers included in the signature are taken from the list of
465 `Mail::DKIM::Signer`. Additionally `Content-Type` (if present), `From`, `To`,
466 `CC`, `Reply-To` and `Subject` get oversigned.
468 You can either sign all mails received on the internal port using the domain of
469 the envelope sender address or create a list of domains, for which e-mails
470 should be signed, defaulting to the list of relay domains.
473 Enable DKIM Signing::
475 Controls whether outbound mail should get DKIM signed.
479 The selector used for signing the mail. The private key used for signing is
480 saved under `/etc/pmg/dkim/yourselector.private`. You can display the DNS TXT
481 record which you need to add to all domains signed by {pmg} by clicking on the
482 'View DNS Record' Button.
484 Sign all Outgoing Mail::
486 Controls whether all outbound mail should get signed or only mails from domains
487 listed in `/etc/pmg/dkim/domains` if it exists and `/etc/pmg/domains` otherwise.
489 Those settings are saved to subsection 'admin' in `/etc/pmg/pmg.conf`,
490 using the following configuration keys:
492 include::pmg.admin-dkim-conf-opts.adoc[]
499 [thumbnail="pmg-gui-mailproxy-whitelist.png", big=1]
502 All SMTP checks are disabled for those entries (e. g. Greylisting,
505 NOTE: If you use a backup MX server (e.g. your ISP offers this service
506 for you) you should always add those servers here.
509 [[pmgconfig_spamdetector]]
510 Spam Detector Configuration
511 ---------------------------
517 [thumbnail="pmg-gui-spam-options.png", big=1]
520 {pmg} uses a wide variety of local and network tests to identify spam
521 signatures. This makes it harder for spammers to identify one aspect
522 which they can craft their messages to work around the spam filter.
524 Every single e-mail will be analyzed and gets a spam score
525 assigned. The system attempts to optimize the efficiency of the rules
526 that are run in terms of minimizing the number of false positives and
529 include::pmg.spam-conf-opts.adoc[]
532 [[pmgconfig_spamdetector_quarantine]]
537 [thumbnail="pmg-gui-spamquar-options.png", big=1]
540 Proxmox analyses all incoming e-mail messages and decides for each
541 e-mail if its ham or spam (or virus). Good e-mails are delivered to
542 the inbox and spam messages can be moved into the spam quarantine.
544 The system can be configured to send daily reports to inform users
545 about the personal spam messages received the last day. That report is
546 only sent if there are new messages in the quarantine.
548 Some options are only available in the config file `/etc/pmg/pmg.conf`,
549 and not in the webinterface.
551 include::pmg.spamquar-conf-opts.adoc[]
554 [[pmgconfig_spamdetector_customscores]]
555 Customization of Rulescores
556 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
559 [thumbnail="pmg-gui-spam-custom-scores.png", big=1]
562 While the default scoring of {spamassassin}'s ruleset provides very good
563 detection rates, sometimes your particular environment can benefit from
564 slightly adjusting the score of a particular rule. Two examples:
566 * Your system receives spam mails which are scored at 4.9 and you have
567 a rule which puts all mails above 5 in the quarantine. The one thing the
568 spam mails have in common is that they all hit 'URIBL_BLACK'. By increasing
569 the score of this rule by 0.2 points the spam mails would all be quarantined
570 instead of being sent to your users
572 * Your system tags many legitimate mails from a partner organization as spam,
573 because the organization has a policy that each mail has to start with
574 'Dear madam or sir' (generating 1.9 points through the rule
575 'DEAR_SOMETHING'). By setting the score of this rule to 0 you can disable
578 The system logs all rules which particular mail hits. Analyzing the logs can
579 lead to finding such a pattern in your environment.
581 You can adjust the score of a rule by creating a new 'Custom Rule Score' entry
584 NOTE: In general it is strongly recommended to not make large changes to the
589 Virus Detector Configuration
590 ----------------------------
592 [[pmgconfig_clamav_options]]
597 [thumbnail="pmg-gui-virus-options.png", big=1]
600 All mails are automatically passed to the included virus detector
601 ({clamav}). The default setting are considered safe, so it is usually
602 not required to change them.
604 {clamav} related settings are saved to subsection 'clamav' in `/etc/pmg/pmg.conf`,
605 using the following configuration keys:
607 include::pmg.clamav-conf-opts.adoc[]
610 [thumbnail="pmg-gui-clamav-database.png", big=1]
613 Please note that the virus signature database it automatically
614 updated. But you can see the database status on the GUI, and you can
615 trigger manual updates there.
618 [[pmgconfig_clamav_quarantine]]
623 [thumbnail="pmg-gui-virusquar-options.png", big=1]
626 Indentified virus mails are automatically moved to the virus
627 quarantine. The administartor can view those mails using the GUI, or
628 deliver them in case of false positives. {pmg} does not notify
629 individual users about received virus mails.
631 Virus quarantine related settings are saved to subsection 'virusquar'
632 in `/etc/pmg/pmg.conf`, using the following configuration keys:
634 include::pmg.virusquar-conf-opts.adoc[]
637 Custom SpamAssassin configuration
638 ---------------------------------
640 This is only for advanced users. {spamassassin}'s rules and their associated
641 scores get updated regularly and are trained on a huge corpus, which gets
642 classified by experts. In most cases adding a rule for matching a particular
643 keyword is the wrong approach, leading to many false positives. Usually bad
644 detection rates are better addressed by properly setting up DNS than by adding
645 a custom rule - watch out for matches to 'URIBL_BLOCKED' in the logs or
646 spam-headers - see the {spamassassin_dnsbl}.
648 To add or change the Proxmox {spamassassin} configuration please login to the
649 console via SSH. Change to the `/etc/mail/spamassassin/` directory. In this
650 directory there are several files (`init.pre`, `local.cf`, ...) - do not change
651 them, as `init.pre`, `v310.pre`, `v320.pre`, `local.cf` will be overwritten by
652 the xref:pmgconfig_template_engine[template engine], while the others can
653 get updated by any {spamassassin} package upgrade.
655 To add your special configuration, you have to create a new file and name it
656 `custom.cf` (in this directory), then add your configuration there. Make sure
657 to use the correct {spamassassin} syntax, and test with
660 # spamassassin -D --lint
663 If you run a cluster, the `custom.cf` file is synchronized from the
664 master node to all cluster members automatically.
666 Should you only wish to adjust the score assigned to a particular rule you
667 can also use the xref:pmgconfig_spamdetector_customscores[Custom Rule Score]
671 [[pmgconfig_custom_check]]
672 Custom Check Interface
673 ----------------------
675 For use cases which are not handled by the {pmg} Virus Detector and
676 {spamassassin} configuration, advanced users can create a custom check
677 executable which, if enabled will be called before the Virus Detector and before
678 passing an e-mail through the Rule System. The custom check API is kept as
679 simple as possible, while still providing a great deal of control over the
680 treatment of an e-mail. Its input is passed via two CLI arguments:
682 * the 'api-version' (currently `v1`) - for potential future change of the
685 * the 'queue-file-name' - a filename, which contains the complete e-mail as
688 The expected output need to be printed on STDOUT and consists of two lines:
690 * the 'api-version' (currently 'v1') - see above
692 * one of the following 3 results:
693 ** 'OK' - e-mail is ok
694 ** 'VIRUS: <virusdescription>' - e-mail is treated as if it contained a virus
695 (the virusdescription is logged and added to the e-mail's headers)
696 ** 'SCORE: <number>' - <number> is added (negative numbers are also possible)
697 to the e-mail's spamscore
699 The check is run with a 5 minute timeout - if it is exceeded the check
700 executable is killed and the e-mail is treated as OK.
702 All output written to STDERR by the check is written with priority 'err' to the
705 A simple sample script following the API (and yielding a random result) for
711 echo "called with $*" 1>&2
713 if [ "$#" -ne 2 ]; then
714 echo "usage: $0 APIVERSION QUEUEFILENAME" 1>&2
721 if [ "$apiver" != "v1" ]; then
722 echo "wrong APIVERSION: $apiver" 1>&2
730 choice=$(shuf -i 0-3 -n1)
740 echo VIRUS: Random Virus
743 for i in $(seq 1 7); do
744 echo "custom checking mail: $queue_file - minute $i" 1>&2
753 The custom check needs to be enabled in the admin section of `/etc/pmg/pmg.conf`
760 The location of the custom check executable can also be set there with the key
761 `custom_check_path` and defaults to `/usr/local/bin/pmg-custom-check`.
767 User management in {pmg} consists of three types of users/accounts:
770 [[pmgconfig_localuser]]
774 [thumbnail="pmg-gui-local-user-config.png", big=1]
776 Local users are used to manage and audit {pmg}. Those users can login on the
777 management web interface.
779 There are three roles:
783 Is allowed to manage settings of {pmg}, except some tasks like
784 network configuration and upgrading.
788 Is allowed to manage quarantines, blacklists and whitelists, but not other
789 settings. Has no right to view any other data.
793 With this role, the user is only allowed to view data and configuration, but
796 In addition there is always the 'root' user, which is used to perform special
797 system administrator tasks, such as updgrading a host or changing the
798 network configuration.
800 NOTE: Only pam users are able to login via the webconsole and ssh, which the
801 users created with the web interface are not. Those users are created for
802 {pmg} administration only.
804 Local user related settings are saved in `/etc/pmg/user.conf`.
806 For details of the fields see xref:pmg_user_configuration_file[user.conf]
809 LDAP/Active Directory
810 ~~~~~~~~~~~~~~~~~~~~~
812 [thumbnail="pmg-gui-ldap-user-config.png", big=1]
814 You can specify multiple LDAP/Active Directory profiles, so that you can
815 create rules matching those users and groups.
817 Creating a profile requires (at least) the following:
820 * protocol (LDAP or LDAPS; LDAPS is recommended)
821 * at least one server
822 * a user and password (if your server does not support anonymous binds)
824 All other fields should work with the defaults for most setups, but can be
825 used to customize the queries.
827 The settings are saved to `/etc/pmg/ldap.conf`. Details for the options
828 can be found here: xref:pmg_ldap_configuration_file[ldap.conf]
833 It is highly recommended that the user which you use for connecting to the
834 LDAP server only has the permission to query the server. For LDAP servers
835 (for example OpenLDAP or FreeIPA), the username has to be of a format like
836 'uid=username,cn=users,cn=accounts,dc=domain' , where the specific fields are
837 depending on your setup. For Active Directory servers, the format should be
838 like 'username@domain' or 'domain\username'.
843 {pmg} synchronizes the relevant user and group info periodically, so that
844 that information is available in a fast manner, even when the LDAP/AD server
845 is temporarily not accessible.
847 After a successfull sync, the groups and users should be visible on the web
848 interface. After that, you can create rules targeting LDAP users and groups.
851 [[pmgconfig_fetchmail]]
855 [thumbnail="pmg-gui-fetchmail-config.png", big=1]
857 Fetchmail is utility for polling and forwarding e-mails. You can define
858 e-mail accounts, which will then be fetched and forwarded to the e-mail
861 You have to add an entry for each account/target combination you want to
862 fetch and forward. Those will then be regularly polled and forwarded,
863 according to your configuration.
865 The API and web interface offer following configuration options:
867 include::fetchmail.conf.5-opts.adoc[]
871 include::pmg-copyright.adoc[]