HTTPS feedback gateway
The companion service exposes a small API for training and its own exact-sender policy. It does not require PMG administrator credentials and never executes commands supplied by clients. Install it on the same host as the Rspamd controller; it deliberately restricts the learner to loopback.
Prepare the host
Requirements: Python 3.10+, an installed Rspamd with Redis/Valkey Bayesian statistics, systemd for the example service, and a TLS certificate whose SAN covers the configured gateway hostname. The optional consensus checker also needs /usr/bin/curl.
Create a dedicated system user and install the reviewed source as root-owned files:
useradd --system --home-dir /var/lib/spamfeedback --shell /usr/sbin/nologin spamfeedback
install -d -o root -g root -m 0755 /opt/spamfeedback
cp -a gateway /opt/spamfeedback/
chown -R root:root /opt/spamfeedback
chmod 0755 /opt/spamfeedback/gateway/consensus.py
install -d -o spamfeedback -g spamfeedback -m 0750 /etc/spamfeedback
install -d -o spamfeedback -g spamfeedback -m 0750 /var/lib/spamfeedback
If the account or directories already exist, inspect and reuse them; do not recreate or recursively change unrelated ownership. Place all live configuration outside the source/release directory.
Create a random token without printing it or putting it in shell history:
python3 - <<'PY'
import os, secrets
path = '/etc/spamfeedback/helpdesk.token'
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
with os.fdopen(fd, 'w') as out:
out.write(secrets.token_urlsafe(48) + '\n')
PY
chown spamfeedback:spamfeedback /etc/spamfeedback/helpdesk.token
Transfer this value to OFORK's protected token file through your normal secure channel. Do not email it, commit it or place it in a URL. Give each independent helpdesk/source its own token entry and source name.
TLS and configuration
Copy gateway/gateway.example.json to /etc/spamfeedback/gateway.json and configure:
listen: a private interface address reachable only from the helpdesk. The default is loopback; IPv4 and IPv6 literals are supported. Use a firewall restriction to the intended helpdesk source addresses.port: normally 9443, distinct from PMG management port 8006.certificateandprivate_key: PEM files readable by the service. Use a trusted public certificate or an internal CA trusted explicitly by OFORK. Never turn off certificate validation.token_files: map stable source names to protected token-file paths.rspamd_url: normallyhttp://127.0.0.1:11334. Keep the controller bound to loopback; do not publish it or its WebUI as this API.- Optional
rspamd_password_file: protected file containing the controller's write password when loopback authentication is required. It is read by the service, not sent to OFORK. sender_policy_enabled: leave false until the PMG policy adapter is installed and verified. False disables sender mutations while allowing spam/ham reporting.
Use mode 0600 for tokens and private keys. The service configuration contains paths, not credentials. Ensure the certificate-renewal process updates the files and restarts this feedback service; TLS is loaded at startup. Restarting this independent service does not require restarting SMTP, although reports are briefly unavailable.
Install and start the service:
install -m 0644 gateway/spamfeedback.service /etc/systemd/system/spamfeedback.service
systemctl daemon-reload
systemctl enable --now spamfeedback.service
systemctl status spamfeedback.service --no-pager
The service is unprivileged and can write only its state directory. Its example unit limits memory and disables privilege escalation. It processes requests serially so learning corrections and sender updates are ordered. Restrict access at the network firewall as well as with bearer authentication; do not expose this administrative feedback API to the public Internet.
Test TLS and authentication from OFORK using the application configuration. An unauthenticated /v1/health request must get 401. A valid token and trusted hostname must get {"status":"ok","protocol":1}. An untrusted certificate must fail verification. Health is service liveness, not proof that sufficient Bayesian training exists or that all PMG rules are correctly configured.
Enable supervised learning
Merge gateway/classifier-bayes.conf.example into Rspamd's local.d/classifier-bayes.conf. Preserve an existing classifier's name, Redis database and learned corpus. Set the Redis server explicitly if it is not already inherited. Retain the installed standard learn_condition so duplicates and reclassification work.
Run rspamadm configtest before reloading Rspamd. Keep autolearn=false for both the Bayesian classifier and the GPT plugin: only reviewed human examples should enter this workflow. Maintain Redis persistence and include its statistical data in backups.
A normal default is 200 spam and 200 ham examples before Bayesian scoring becomes useful. The consensus policy treats missing Bayes output as uncertain. Do not lower this threshold simply to make an untrained classifier look ready. The isolated test harness uses a threshold of one only in its disposable database; that is not a production recommendation. Rspamd statistics documentation
Training uses the controller's /learnspam and /learnham endpoints. It does not call an external spam-reporting network or fine-tune an AI model. API acknowledgement establishes that Rspamd accepted the request or recognised an already-learned example; it does not guarantee accuracy on future mail. Rspamd protocol
Storage and failures
feedback.sqlite contains request IDs, source, actor/ticket/article identifiers, message hashes, sender, action, status and result. Original messages are processed in memory and passed to Rspamd; they are not stored by this service. Rspamd's learned tokens are still sensitive data and belong in protected backups.
senders.json is an atomically generated policy file, mode 0640; the database stays 0600. Only the service writes the policy. Give the PMG filter user read access via the dedicated group when enabling consensus. The service-state directory must then be 0750. Do not make the directory or database world-readable.
An identical request ID with identical content returns its original accepted result. The same ID with different content is refused. A timeout retains a pending event; resubmit the same ID to reconcile it. Rspamd's duplicate-learning protection handles the case where the learner succeeded before the response was lost. An older pending classification cannot supersede a newer report of that message. Sender updates carry an expected revision and are transactional; stale decisions must be reviewed again.
There is no automatic mail retry daemon in OFORK in this version. Agents explicitly retry pending reports. The gateway logs no original message, token, sender URL or raw upstream exception. Its private audit database is the source for diagnosis. Back it up consistently using SQLite's backup API or after stopping this feedback service; do not copy a changing database blindly.
Protocol for other helpdesks
Authenticate with Authorization: Bearer <token> over verified HTTPS. POST /v1/feedback accepts JSON:
{
"id": "64 lowercase hexadecimal characters",
"action": "spam",
"ticket": 123,
"article": 456,
"actor": 7,
"message": "base64 of the original RFC822 bytes",
"sender": "sender@example.org",
"sender_revision": 0
}
Allowed actions are spam, ham, whitelist, blacklist, remove_sender. Generate a stable ID for one logical event, preserve it across retries, and create a new ID for a later deliberate correction. Sender actions must match the single From mailbox parsed from the original message. GET /v1/sender?address=sender%40example.org returns policy, revision and enabled. Review this revision before a sender update.
Successful responses contain the matching id, status: accepted, action and result. Check all of these, not just HTTP 200. A 400 means invalid input or a conflict; reopen/review instead of blindly changing the ID. A 503 means unconfirmed, not necessarily unapplied. The maximum original message size is 20 MiB. Do not submit email content in query parameters or logs.