SpamFeedback downloads

Optional incoming-mail consensus policy

This component implements the requested policy: exact whitelist/blacklist first, otherwise Bayesian spam AND AI spam. It is optional and separate from the OFORK package and learning gateway. A site can use reporting alone while retaining its existing filtering policy.

Decision table

Sender policy / classifier result Spam decision
Explicit whitelist Skip Bayes/AI; no consensus spam tag
Explicit blacklist Skip Bayes/AI; apply the configured native blacklist action
Bayes spam probability at least 0.95 AND GPT_SPAM Consensus spam; apply the configured native spam action
Strong Bayes ham AND GPT_HAM Consensus ham
Missing/untrained Bayes, weak evidence, disagreement, timeout, busy AI or invalid response Uncertain; no consensus spam action

The Bayesian probability threshold is configurable, default 0.95. The AI plugin must emit GPT_SPAM only at its configured confidence threshold (0.75 in the tested installation), and emit GPT_HAM for legitimate mail. Both classifiers run for messages without an exact sender-list hit. Do not retain GPT's usual “skip when BAYES_SPAM is present” shortcut. No AI-only result trains Bayes automatically.

Malware detection and dangerous-content handling remain native PMG rules. Whitelisting suppresses the consensus spam decision; it must never disable virus scanning. From addresses can be spoofed: this is an explicit address policy, not proof of sender authentication. Existing SMTP recipient/relay restrictions, malware rules and unrelated PMG rules remain independent.

Why a PMG adapter is needed

The standard custom-check protocol returns a numeric score, which PMG combines with other spam scores. Returning zero on disagreement is insufficient: a separate baseline score could still trigger the normal spam rule. Raising the numerical threshold would only hide this problem.

PMG::SpamFeedback wraps PMG::RuleDB::Spam::what_match_targets for explicitly selected WHAT object-group IDs and gates those rules on the custom-check decision. It does not edit a vendor file, alter malware classes or change outbound matching. Native PMG actions remain responsible for tagging, quarantining or blocking.

This uses a PMG Perl interface, not a vendor-guaranteed extension API. It was tested against PMG 9.1.4 classes. Recheck it after PMG upgrades and before restarting the filter. Installing the OFORK add-on does not automatically install or enable this adapter.

Prepare and inspect

Back up native PMG configuration/rule database, the current custom-check program, Rspamd configuration, existing systemd overrides and the learning/policy state. Record the current service unit and custom-check settings. Use your normal maintenance coordination and alert suppression for any required filter restart.

Inspect the effective rule table in PMG and identify:

  • All active inbound spam rules, their WHAT groups and actions. Every rule that could independently tag/quarantine/block spam must be gated or deliberately disabled for strict agreement.
  • The virus and dangerous-content rules. Keep them active and ahead of any accept action.
  • Existing native sender lists. Resolve conflicting policies deliberately; this add-on never erases unrelated native entries.
  • The action you want for a managed blacklist hit and for consensus spam. For initial rollout, subject tagging for consensus spam is easier to review than rejecting mail. Explicit blacklist can use a native Block action.

Useful read-only commands include pmgsh get /config/ruledb/rules, pmgsh get /config/ruledb/what and pmgsh get /config/ruledb/what/ID/objects. Use pmgsh help PATH --verbose for the installed API schema. Do not assume example IDs match your gateway.

Configure Rspamd and the custom check

First complete the learning gateway setup. Configure a working Rspamd AI plugin with local or approved inference, bounded timeouts, no automatic training, and GPT_SPAM/GPT_HAM output. This package does not download a model, supply an inference API key or replace an existing AI plugin.

For the installed GPT plugin, configure the equivalent of:

autolearn = false;
allow_ham = true;
allow_passthrough = true;
symbols_to_except = {};
condition = "return function(task) return true end";

Check the options supported by your installed version. An unconditional condition ensures the AI step is not skipped merely because Bayes is confident. Exact-sender bypass happens in the outer checker. Keep timeouts and concurrency appropriate for the inference server; timeout/busy/missing symbols produce an uncertain decision. Do not enable both stock GPT and another plugin that registers the same GPT symbols. Rspamd GPT documentation

Copy gateway/consensus.example.json to /etc/spamfeedback/consensus.json and set received_by to the exact hostname in the first locally prepended Received header. received_marker defaults to PMG-Inbound. The checker uses this local header to distinguish inbound mail; it ignores lower sender-supplied Received headers.

Your Postfix inbound listener must generate that distinct marker, while outbound/trusted listeners must not. Use a supported PMG Postfix template override for that listener and verify it survives pmgconfig regeneration. Inspect the effective master service options before changing them. Do not simply search all Received headers or trust a user-supplied X header as the direction marker. Test both inbound and outbound paths; an unmatched direction safely skips consensus.

The checker accepts a maximum 20 MiB message. Rspamd scanning has a 65-second HTTP total deadline with a 70-second outer process limit. The normal-worker endpoint is restricted to loopback port 11333. Missing policy files do not produce a whitelist: messages fall back to classification, and unavailable classification yields uncertain. Keep the sender-policy file readable and monitor failures.

The PMG service normally runs as pmg-smtp-filter. Verify your actual service user. Give it read access to the policy through the dedicated group:

usermod -aG spamfeedback pmg-smtp-filter

The service restart must pick up the new supplementary group. Keep /var/lib/spamfeedback mode 0750, senders.json mode 0640, and its SQLite database 0600. Verify policy reading as the actual filter account before cutover.

Configure native rules and the gate

In PMG's rule editor, reuse or create a WHAT group with a Spam Filter object for the consensus rule. Create a separate WHAT group containing a Spam Filter object for the managed-blacklist rule. These are distinct from WHO address lists. The gate checks the decision code, not the spam-level threshold inside these selected objects.

Attach the consensus WHAT group to an inbound subject-tagging rule, and the blacklist WHAT group to an inbound rule with the desired blacklist action. Keep malware handling ahead of whitelist/accept decisions. Do not enable duplicate ungated spam actions in parallel.

Create /etc/spamfeedback/pmg-gate.json, root-owned and readable by the filter account. Map the actual WHAT group IDs, for example:

{"groups": {"123": "consensus", "124": "blacklist"}}

123 and 124 are placeholders. They are not Rule IDs, individual Object IDs or WHO group IDs. Map other active inbound Spam Filter groups to consensus if retaining their rules, or disable those rules deliberately. A single unmapped spam rule can still act on baseline scores and defeat the intended agreement policy.

Install gateway/pmg-gate.service.conf.example as a reviewed systemd drop-in for pmg-smtp-filter. It loads the adapter with:

PERL5OPT=-I/opt/spamfeedback/gateway -MPMG::SpamFeedback

Merge any existing PERL5OPT; do not silently overwrite another extension. Run perl tests/pmg-native-gate.pl on this PMG version before activation. Also verify that the gate configuration can be read by the filter account:

sudo -u pmg-smtp-filter perl -I/opt/spamfeedback/gateway -MPMG::SpamFeedback -e 'PMG::SpamFeedback::modes(); print "configuration readable\n"'

Configure PMG's admin.custom_check=1 and admin.custom_check_path=/opt/spamfeedback/gateway/consensus.py through the native API/GUI for your version. The program must be executable and its source/configuration must be root-owned. Activate the checker, selected rules and Perl gate as one coordinated change: the adapter's decision codes must never be mixed with an unrelated custom-check program.

The protocol codes are 7 for consensus spam, 8 for managed blacklist, -1 for whitelist, -2 for consensus ham, and 0 for uncertain/skipped. They are internal transport values, not probabilities. The adapter adds/replaces X-SpamFeedback-Decision with an informational label and matches only the appropriate code. It never trusts an incoming copy of that header.

Run rspamadm configtest, validate the service configuration, and carry out the coordinated filter restart. A reload alone does not reliably load a new systemd environment variable or supplementary group. Check service logs and actual rule behaviour before enabling sender_policy_enabled=true in the feedback service and exposing sender buttons to agents.

Acceptance and rollback

Use non-delivery PMG tests or an isolated lab. Verify these cases through the native action stage, not just a JSON result:

  • Both spam: selected spam action; both ham: no spam action.
  • Conflicting, weak or missing Bayes/AI: delivery without consensus spam marking, even with a high baseline score.
  • Whitelist: no consensus spam action; an antivirus test fixture still hits the native malware policy.
  • Blacklist: the chosen blacklist action; removal restores normal classification.
  • Forged decision/Received headers cannot force an allow decision.
  • Outbound behaviour is unchanged, and feedback/gateway outages do not hold mail for unbounded periods.

The provided native adapter test forces a baseline score of 100 and verifies that it cannot bypass agreement. It does not replace an end-to-end SMTP, antivirus or production load test.

Rollback is a coordinated restoration of the previous custom-check path/settings, rule configuration and systemd environment, followed by the required reload/restart and delivery checks. Removing only the gate while keeping the new numerical checker is not a correct rollback. Disable sender-policy changes in the feedback service while restoring old filtering. Retain feedback history, policies and learned data for reconciliation; do not erase the database to roll back a program version.

Monitor the gateway service, pending reports, classifier training counts, uncertain/error rates, policy-file readability and certificate expiry. The checker logs outcome/reason/timing without addresses or bodies. This release includes no automatic monitoring-system provisioning and no guaranteed detection rate.