Dovecot/Imapsieve: Unterschied zwischen den Versionen
Keine Bearbeitungszusammenfassung |
|||
| (25 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
<noinclude> | |||
<!-- | |||
---- | |||
{{Navigation|<zurück>|<nachste>}} | |||
---- | |||
--> | |||
'''Dovecot/Imapsieve''' Dovecot ''[[imap_sieve]]'' erweitern | |||
</noinclude> | |||
== Beschreibung == | |||
* | ; Verschieben von Nachricht | ||
* | * nach ''[[Junk]]'' wird diese an [[Rspamd]] als [[Spam]] gemeldet | ||
* aus ''[[Junk]]'' in einen normalen Ordner wird diese an [[Rspamd]] als [[Ham]] gemeldet | |||
; Konfiguration für [[Dovecot]] 2.4 | |||
== Konfiguration == | |||
; ISPConfig-Template | |||
Custom-Konfiguration | |||
* Bleib bei späteren Reconfigure-/Update-Vorgängen erhalten | |||
; /usr/local/ispconfig/server/conf-custom/install/dovecot_custom.conf.master | ; /usr/local/ispconfig/server/conf-custom/install/dovecot_custom.conf.master | ||
<syntaxhighlight lang="bash" copy line> | |||
<syntaxhighlight lang=" | |||
protocol imap { | protocol imap { | ||
mail_plugins { | mail_plugins { | ||
| Zeile 44: | Zeile 57: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Die ISPConfig-Custom-Konfiguration wird in die aktive Dovecot-Konfiguration übernommen | |||
<syntaxhighlight lang="bash" highlight="1" copy line> | <syntaxhighlight lang="bash" highlight="1" copy line> | ||
| Zeile 60: | Zeile 73: | ||
<syntaxhighlight lang="console" copy line> | <syntaxhighlight lang="console" copy line> | ||
require ["vnd.dovecot.pipe", "copy", "imapsieve"]; | require ["vnd.dovecot.pipe", "copy", "imapsieve"]; | ||
pipe :copy "rspamd-learn-spam.sh"; | pipe :copy "rspamd-learn-spam.sh"; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
; /etc/dovecot/sieve/report-ham.sieve | ; /etc/dovecot/sieve/report-ham.sieve | ||
Dieses Sieve-Skript wird ausgeführt, wenn eine Nachricht aus ''Junk'' in einen anderen IMAP-Ordner kopiert wird | |||
* Kopien nach ''Trash'', ''Deleted Messages'' oder erneut nach ''Junk'' werden ignoriert | * Kopien nach ''Trash'', ''Deleted Messages'' oder erneut nach ''Junk'' werden ignoriert | ||
* Alle anderen Kopien werden per Pipe an ''rspamd-learn-ham.sh'' übergeben | * Alle anderen Kopien werden per Pipe an ''rspamd-learn-ham.sh'' übergeben | ||
| Zeile 84: | Zeile 96: | ||
; /etc/dovecot/sieve/rspamd-learn-spam.sh | ; /etc/dovecot/sieve/rspamd-learn-spam.sh | ||
Das Pipe-Skript übergibt die Nachricht an Rspamd und trainiert sie als Spam | |||
<syntaxhighlight lang="bash" copy line> | <syntaxhighlight lang="bash" copy line> | ||
| Zeile 92: | Zeile 104: | ||
; /etc/dovecot/sieve/rspamd-learn-ham.sh | ; /etc/dovecot/sieve/rspamd-learn-ham.sh | ||
Das Pipe-Skript übergibt die Nachricht an Rspamd und trainiert sie als Ham | |||
<syntaxhighlight lang="bash" copy line> | <syntaxhighlight lang="bash" copy line> | ||
#!/bin/sh | #!/bin/sh | ||
| Zeile 98: | Zeile 110: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Die Pipe-Skripte müssen für Dovecot ausführbar sein | |||
<syntaxhighlight lang="bash" highlight="1-2" copy line> | <syntaxhighlight lang="bash" highlight="1-2" copy line> | ||
chmod 0755 /etc/dovecot/sieve/rspamd-learn-spam.sh /etc/dovecot/sieve/rspamd-learn-ham.sh | chmod 0755 /etc/dovecot/sieve/rspamd-learn-spam.sh /etc/dovecot/sieve/rspamd-learn-ham.sh | ||
| Zeile 104: | Zeile 116: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Die Sieve-Skripte werden kompiliert, damit Dovecot sie direkt verwenden kann | |||
<syntaxhighlight lang="bash" highlight="1-2" copy line> | <syntaxhighlight lang="bash" highlight="1-2" copy line> | ||
sievec /etc/dovecot/sieve/report-spam.sieve | sievec /etc/dovecot/sieve/report-spam.sieve | ||
| Zeile 110: | Zeile 122: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Abschließend wird die Dovecot-Konfiguration geprüft und der Dienst neu geladen | |||
<syntaxhighlight lang="bash" highlight="1-2" copy line> | <syntaxhighlight lang="bash" highlight="1-2" copy line> | ||
dovecot -n | dovecot -n | ||
| Zeile 116: | Zeile 128: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==== | == Ordnernamen == | ||
* | * Der Ordnername ''Junk'' muss dem tatsächlichen IMAP-Ordnernamen entsprechen | ||
** Der | ** Mögliche abweichende Namen sind z. B. ''Spam'' | ||
** | * Bei abweichendem Ordnernamen müssen beide Dovecot-Blöcke angepasst werden | ||
** Zusätzlich muss die Ausschlussliste im Ham-Skript angepasst werden | |||
; Beispiel mit ''Spam'' | |||
<syntaxhighlight lang="console" copy line> | |||
mailbox Spam { | |||
sieve_script report-spam { | |||
type = before | |||
cause = copy | |||
path = /etc/dovecot/sieve/report-spam.sieve | |||
} | |||
} | |||
imapsieve_from Spam { | |||
sieve_script report-ham { | |||
type = before | |||
cause = copy | |||
path = /etc/dovecot/sieve/report-ham.sieve | |||
} | |||
} | |||
</syntaxhighlight> | |||
== Sicherheit == | |||
* Die Pipe-Skripte werden durch Dovecot ausgeführt und müssen daher kontrolliert verwaltet werden | |||
** ''/etc/dovecot/sieve'' darf nicht durch Mailbenutzer beschreibbar sein | |||
* Der Rspamd-Controller sollte nur aus vertrauenswürdigen Netzen erreichbar sein | |||
* Bei Verwendung eines Passworts sollte dieses nicht in allgemein lesbaren Dateien abgelegt werden | |||
; Rspamd-Controller mit enable_password | |||
* ''password'' schützt lesende Controller-Kommandos | |||
** Wird nur ''password'' gesetzt, kann dieses Passwort auch für privilegierte Kommandos verwendet werden | |||
* ''enable_password'' schützt privilegierte Kommandos, z. B. Learning und Konfigurationsänderungen | |||
** Wird zusätzlich ''enable_password'' gesetzt, sollte für IMAPSieve-Learning nur dieses Passwort verwendet werden | |||
; Passwort-Hash erzeugen | |||
* Der Hash wird auf dem Rspamd-Host erzeugt | |||
* Der Parameter ''-p'' sollte nicht verwendet werden, da das Passwort sonst in der Shell-History oder Prozessliste sichtbar werden kann | |||
<syntaxhighlight lang="bash" highlight="1" copy line> | |||
rspamadm pw -q | |||
</syntaxhighlight> | |||
; /etc/rspamd/local.d/worker-controller.inc | |||
* Der erzeugte Hash wird als ''enable_password'' eingetragen | |||
** Optional kann zusätzlich ein separates ''password'' für lesende Zugriffe gesetzt werden | |||
* Der Controller sollte nur auf einer internen Adresse oder localhost gebunden werden | |||
<syntaxhighlight lang="text" copy line> | |||
bind_socket = "10.2.2.8:11334"; | |||
password = "$2$READONLY_PASSWORD_HASH"; | |||
enable_password = "$2$ENABLE_PASSWORD_HASH"; | |||
secure_ip = ["127.0.0.1", "::1"]; | |||
</syntaxhighlight> | |||
; Rspamd-Konfiguration prüfen | |||
<syntaxhighlight lang="bash" highlight="1-2" copy line> | |||
rspamadm configtest | |||
systemctl restart rspamd | |||
</syntaxhighlight> | |||
; Passwortdatei für rspamc | |||
* Die Passwortdatei wird auf dem Dovecot-Host angelegt | |||
** Die Datei enthält den Klartext des ''enable_password'' | |||
* ''rspamc'' kann das Passwort über ''-P'' direkt aus dieser Datei lesen | |||
** Dadurch erscheint das Passwort nicht als Kommandozeilenargument in der Prozessliste | |||
<syntaxhighlight lang="bash" highlight="1-3" copy line> | |||
printf '%s\n' 'ENABLE_PASSWORD_KLARTEXT' > /etc/dovecot/sieve/rspamd-controller.pass | |||
chmod 0640 /etc/dovecot/sieve/rspamd-controller.pass | |||
chown root:vmail /etc/dovecot/sieve/rspamd-controller.pass | |||
</syntaxhighlight> | |||
; /etc/dovecot/sieve/rspamd-learn-spam.sh | |||
<syntaxhighlight lang="bash" copy line> | |||
#!/bin/sh | |||
exec /usr/bin/rspamc -h 10.0.0.8:11334 -P /etc/dovecot/sieve/rspamd-controller.pass learn_spam | |||
</syntaxhighlight> | |||
; /etc/dovecot/sieve/rspamd-learn-ham.sh | |||
<syntaxhighlight lang="bash" copy line> | |||
#!/bin/sh | |||
exec /usr/bin/rspamc -h 10.0.0.8:11334 -P /etc/dovecot/sieve/rspamd-controller.pass learn_ham | |||
</syntaxhighlight> | |||
; Berechtigungen erneut prüfen | |||
<syntaxhighlight lang="bash" highlight="1-4" copy line> | |||
chown -R root:root /etc/dovecot/sieve | |||
chown root:vmail /etc/dovecot/sieve/rspamd-controller.pass | |||
chmod 0755 /etc/dovecot/sieve | |||
chmod 0640 /etc/dovecot/sieve/rspamd-controller.pass | |||
</syntaxhighlight> | |||
; Zugriff testen | |||
<syntaxhighlight lang="bash" highlight="1" copy line> | |||
rspamc -h 10.0.0.8:11334 -P /etc/dovecot/sieve/rspamd-controller.pass stat | |||
</syntaxhighlight> | |||
== Test == | |||
; Konfiguration prüfen | |||
* Die geladene Dovecot-Konfiguration muss die IMAPSieve- und Extprograms-Optionen enthalten | |||
<syntaxhighlight lang="bash" highlight="1" copy line> | |||
doveconf -n | grep -E 'imap_sieve|sieve_imapsieve|sieve_extprograms|sieve_pipe_bin_dir' | |||
</syntaxhighlight> | |||
; Rspamd-Verbindung prüfen | |||
* Der Dovecot-Host muss den Rspamd-Controller erreichen können | |||
<syntaxhighlight lang="bash" highlight="1" copy line> | |||
rspamc -h <published_ip>:11334 stat | |||
</syntaxhighlight> | |||
; Logs beobachten | |||
* Während des Tests sollten Dovecot- und Rspamd-Logs beobachtet werden | |||
<syntaxhighlight lang="bash" highlight="1-2" copy line> | |||
journalctl -u dovecot -u rspamd -f | |||
tail -f /var/log/roundcube/error.log /var/log/roundcube/error.log.1 | |||
</syntaxhighlight> | |||
{| class="wikitable options big" | |||
! Testfall | |||
! Aktion | |||
! Erwartung | |||
|- | |||
| Spam | |||
| Nachricht nach ''Junk'' kopieren | |||
| ''learn_spam'' wird ausgeführt | |||
|- | |||
| Ham | |||
| Nachricht aus ''Junk'' nach ''INBOX'' kopieren | |||
| ''learn_ham'' wird ausgeführt | |||
|- | |||
| Trash | |||
| Nachricht aus ''Junk'' nach ''Trash'' kopieren | |||
| Kein Ham-Learning | |||
|- | |||
| Wiederholung | |||
| Dieselbe Nachricht erneut lernen | |||
| Rspamd kann ''already learned'' melden | |||
|} | |||
== Fehleranalyse == | |||
{| class="wikitable options big" | |||
! Symptom | |||
! Mögliche Ursache | |||
! Prüfung | |||
|- | |||
| Kein Learning beim Verschieben | |||
| IMAPSieve-Plugin nicht geladen | |||
| ''doveconf -n'' prüfen | |||
|- | |||
| Kein Learning beim Verschieben nach Spam | |||
| Ordnername stimmt nicht mit ''Junk'' überein | |||
| IMAP-Ordnernamen prüfen | |||
|- | |||
| ''Permission denied'' | |||
| Pipe-Skript nicht ausführbar oder falsche Rechte | |||
| Rechte unter ''/etc/dovecot/sieve'' prüfen | |||
|- | |||
| ''rspamc: connection refused'' | |||
| Rspamd-Controller nicht erreichbar | |||
| Host, Port und Firewall prüfen. Socket in der Konfiguration prüfen | |||
|- | |||
| ''authentication failed'' | |||
| Controller-Zugriff nicht erlaubt | |||
| ''secure_ip'' oder ''enable_password'' prüfen | |||
|- | |||
| ''already learned'' | |||
| Nachricht wurde bereits trainiert | |||
| Kein Fehler, erneutes Lernen wurde übersprungen | |||
|- | |||
| ''contains less tokens than required'' | |||
| Nachricht ist für Bayes-Learning zu kurz | |||
| ''min_tokens'' prüfen | |||
|- | |||
| Bayes-Symbol erscheint nicht im Scan-Ergebnis | |||
| Zu wenige gelernte Spam- oder Ham-Nachrichten | |||
| ''min_learns'' prüfen | |||
|} | |||
== Bayes == | |||
; Bayes Hinweise | |||
Sehr kurze Nachrichten werden von Rspamd nicht für Bayes-Learning verwendet | |||
* Der Standardwert ''min_tokens = 11'' bedeutet, dass mindestens 11 statistische Tokens vorhanden sein müssen | |||
Bei zu kurzen Nachrichten erscheint im Log sinngemäß eine Meldung wie: | |||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
contains less tokens than required: 9 < 11 | contains less tokens than required: 9 < 11 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Bayes wirkt nicht unmittelbar nach den ersten gelernten Nachrichten | |||
* Der Standardwert ''min_learns = 200'' bedeutet, dass für Spam und Ham jeweils genügend gelernte Nachrichten vorhanden sein müssen, bevor die Bayes-Klassifizierung aktiv in die Bewertung einfließt | |||
Rspamd speichert dafür gelernte IDs bzw. Signaturen im Cache und kann dann eine Meldung wie ''already learned'' zurückgeben. | |||
{| class="wikitable options big" | {| class="wikitable options big" | ||
| Zeile 148: | Zeile 346: | ||
; Variablen anzeigen | ; Variablen anzeigen | ||
Die aktuell wirksamen Rspamd-Parameter können über ''rspamadm configdump'' geprüft werden | |||
<syntaxhighlight lang="bash" highlight="1" copy line> | <syntaxhighlight lang="bash" highlight="1" copy line> | ||
rspamadm configdump | rspamadm configdump | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Die Standardkonfiguration befindet sich in ''/etc/rspamd/statistic.conf'' | |||
* Diese Datei sollte nicht direkt angepasst werden, da sie zur Paketkonfiguration gehört | |||
; Eigene Werte setzen | ; Eigene Werte setzen | ||
Eigene Bayes-Parameter werden üblicherweise in ''/etc/rspamd/local.d/classifier-bayes.conf'' gesetzt | |||
* Die Datei ergänzt oder überschreibt die Standardwerte aus der Rspamd-Konfiguration | |||
; /etc/rspamd/local.d/classifier-bayes.conf | ; /etc/rspamd/local.d/classifier-bayes.conf | ||
| Zeile 167: | Zeile 365: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Nach der Änderung wird die Rspamd-Konfiguration geprüft | |||
<syntaxhighlight lang="bash" highlight="1" copy line> | <syntaxhighlight lang="bash" highlight="1" copy line> | ||
rspamadm configtest | rspamadm configtest | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Anschließend wird Rspamd neu gestartet, damit die geänderten Werte aktiv werden | |||
<syntaxhighlight lang="bash" highlight="1" copy line> | <syntaxhighlight lang="bash" highlight="1" copy line> | ||
systemctl restart rspamd | systemctl restart rspamd | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Installation == | |||
<syntaxhighlight lang="bash" highlight="1" line copy> | |||
</syntaxhighlight> | |||
== Aufruf == | |||
<syntaxhighlight lang="bash" highlight="1" line copy> | |||
</syntaxhighlight> | |||
=== Optionen === | |||
{| class="wikitable sortable options gnu big" | |||
|- | |||
! Unix !! GNU !! Parameter !! Beschreibung | |||
|- | |||
| || || || | |||
|- | |||
|} | |||
=== Parameter === | |||
=== Umgebungsvariablen === | |||
=== Exit-Status === | |||
{| class="wikitable options col1center big" | |||
|- | |||
! Wert !! Beschreibung | |||
|- | |||
| 0 || Erfolg | |||
|- | |||
| >0 || Fehler | |||
|} | |||
== Anwendung == | |||
<syntaxhighlight lang="bash" highlight="1" line copy> | |||
</syntaxhighlight> | |||
<!-- output --> | |||
<syntaxhighlight lang="bash" highlight="" line> | |||
</syntaxhighlight> | |||
=== Problembehebung === | |||
== Konfiguration == | |||
=== Dateien === | |||
{| class="wikitable options big" | |||
|- | |||
! Datei !! Beschreibung | |||
|- | |||
| || | |||
|- | |||
| || | |||
|} | |||
<noinclude> | |||
<!-- | |||
---- | |||
{{Navigation|<zurück>|<nachste>}} | |||
---- | |||
--> | |||
== Anhang == | |||
=== Siehe auch === | |||
<div style="column-count:2"> | |||
<categorytree hideroot=on mode="pages">{{BASEPAGENAME}}</categorytree> | |||
</div> | |||
---- | |||
{{Special:PrefixIndex/{{BASEPAGENAME}}/}} | |||
=== Dokumentation === | |||
<!-- | |||
; Man-Page | |||
# [https://manpages.debian.org/stable/procps/pgrep.1.de.html prep(1)] | |||
; Info-Pages | |||
--> | |||
=== Links === | |||
==== Projekt ==== | |||
==== Weblinks ==== | |||
<!-- | |||
{{DEFAULTSORT:new}} | |||
{{DISPLAYTITLE:new}} | |||
--> | |||
[[Kategorie:Dovecot/Spam]] | [[Kategorie:Dovecot/Spam]] | ||
</noinclude> | |||
Aktuelle Version vom 27. Juli 2026, 08:50 Uhr
Dovecot/Imapsieve Dovecot imap_sieve erweitern
Beschreibung
- Verschieben von Nachricht
- nach Junk wird diese an Rspamd als Spam gemeldet
- aus Junk in einen normalen Ordner wird diese an Rspamd als Ham gemeldet
- Konfiguration für Dovecot 2.4
Konfiguration
- ISPConfig-Template
Custom-Konfiguration
- Bleib bei späteren Reconfigure-/Update-Vorgängen erhalten
- /usr/local/ispconfig/server/conf-custom/install/dovecot_custom.conf.master
protocol imap {
mail_plugins {
imap_sieve = yes
}
}
sieve_plugins {
sieve_imapsieve = yes
sieve_extprograms = yes
}
sieve_global_extensions {
vnd.dovecot.pipe = yes
vnd.dovecot.environment = yes
}
sieve_pipe_bin_dir = /etc/dovecot/sieve
mailbox Junk {
sieve_script report-spam {
type = before
cause = copy
path = /etc/dovecot/sieve/report-spam.sieve
}
}
imapsieve_from Junk {
sieve_script report-ham {
type = before
cause = copy
path = /etc/dovecot/sieve/report-ham.sieve
}
}
Die ISPConfig-Custom-Konfiguration wird in die aktive Dovecot-Konfiguration übernommen
cp /usr/local/ispconfig/server/conf-custom/install/dovecot_custom.conf.master /etc/dovecot/conf.d/99-ispconfig-custom-config.conf
- Create sieve scripts folder
mkdir -p /etc/dovecot/sieve
- /etc/dovecot/sieve/report-spam.sieve
- Die Nachricht wird per Pipe an rspamd-learn-spam.sh übergeben
require ["vnd.dovecot.pipe", "copy", "imapsieve"];
pipe :copy "rspamd-learn-spam.sh";
- /etc/dovecot/sieve/report-ham.sieve
Dieses Sieve-Skript wird ausgeführt, wenn eine Nachricht aus Junk in einen anderen IMAP-Ordner kopiert wird
- Kopien nach Trash, Deleted Messages oder erneut nach Junk werden ignoriert
- Alle anderen Kopien werden per Pipe an rspamd-learn-ham.sh übergeben
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
if environment :matches "imap.mailbox" "*" {
set "mailbox" "${1}";
}
if string "${mailbox}" ["Trash", "Deleted Messages", "Junk"] {
stop;
}
pipe :copy "rspamd-learn-ham.sh";
- /etc/dovecot/sieve/rspamd-learn-spam.sh
Das Pipe-Skript übergibt die Nachricht an Rspamd und trainiert sie als Spam
#!/bin/sh
exec /usr/bin/rspamc -h 10.0.0.8:11334 learn_spam
- /etc/dovecot/sieve/rspamd-learn-ham.sh
Das Pipe-Skript übergibt die Nachricht an Rspamd und trainiert sie als Ham
#!/bin/sh
exec /usr/bin/rspamc -h 10.0.0.8:11334 learn_ham
Die Pipe-Skripte müssen für Dovecot ausführbar sein
chmod 0755 /etc/dovecot/sieve/rspamd-learn-spam.sh /etc/dovecot/sieve/rspamd-learn-ham.sh
chmod +x /etc/dovecot/sieve/rspamd-learn-spam.sh /etc/dovecot/sieve/rspamd-learn-ham.sh
Die Sieve-Skripte werden kompiliert, damit Dovecot sie direkt verwenden kann
sievec /etc/dovecot/sieve/report-spam.sieve
sievec /etc/dovecot/sieve/report-ham.sieve
Abschließend wird die Dovecot-Konfiguration geprüft und der Dienst neu geladen
dovecot -n
systemctl reload dovecot
Ordnernamen
- Der Ordnername Junk muss dem tatsächlichen IMAP-Ordnernamen entsprechen
- Mögliche abweichende Namen sind z. B. Spam
- Bei abweichendem Ordnernamen müssen beide Dovecot-Blöcke angepasst werden
- Zusätzlich muss die Ausschlussliste im Ham-Skript angepasst werden
- Beispiel mit Spam
mailbox Spam {
sieve_script report-spam {
type = before
cause = copy
path = /etc/dovecot/sieve/report-spam.sieve
}
}
imapsieve_from Spam {
sieve_script report-ham {
type = before
cause = copy
path = /etc/dovecot/sieve/report-ham.sieve
}
}
Sicherheit
- Die Pipe-Skripte werden durch Dovecot ausgeführt und müssen daher kontrolliert verwaltet werden
- /etc/dovecot/sieve darf nicht durch Mailbenutzer beschreibbar sein
- Der Rspamd-Controller sollte nur aus vertrauenswürdigen Netzen erreichbar sein
- Bei Verwendung eines Passworts sollte dieses nicht in allgemein lesbaren Dateien abgelegt werden
- Rspamd-Controller mit enable_password
- password schützt lesende Controller-Kommandos
- Wird nur password gesetzt, kann dieses Passwort auch für privilegierte Kommandos verwendet werden
- enable_password schützt privilegierte Kommandos, z. B. Learning und Konfigurationsänderungen
- Wird zusätzlich enable_password gesetzt, sollte für IMAPSieve-Learning nur dieses Passwort verwendet werden
- Passwort-Hash erzeugen
- Der Hash wird auf dem Rspamd-Host erzeugt
- Der Parameter -p sollte nicht verwendet werden, da das Passwort sonst in der Shell-History oder Prozessliste sichtbar werden kann
rspamadm pw -q
- /etc/rspamd/local.d/worker-controller.inc
- Der erzeugte Hash wird als enable_password eingetragen
- Optional kann zusätzlich ein separates password für lesende Zugriffe gesetzt werden
- Der Controller sollte nur auf einer internen Adresse oder localhost gebunden werden
bind_socket = "10.2.2.8:11334";
password = "$2$READONLY_PASSWORD_HASH";
enable_password = "$2$ENABLE_PASSWORD_HASH";
secure_ip = ["127.0.0.1", "::1"];
- Rspamd-Konfiguration prüfen
rspamadm configtest
systemctl restart rspamd
- Passwortdatei für rspamc
- Die Passwortdatei wird auf dem Dovecot-Host angelegt
- Die Datei enthält den Klartext des enable_password
- rspamc kann das Passwort über -P direkt aus dieser Datei lesen
- Dadurch erscheint das Passwort nicht als Kommandozeilenargument in der Prozessliste
printf '%s\n' 'ENABLE_PASSWORD_KLARTEXT' > /etc/dovecot/sieve/rspamd-controller.pass
chmod 0640 /etc/dovecot/sieve/rspamd-controller.pass
chown root:vmail /etc/dovecot/sieve/rspamd-controller.pass
- /etc/dovecot/sieve/rspamd-learn-spam.sh
#!/bin/sh
exec /usr/bin/rspamc -h 10.0.0.8:11334 -P /etc/dovecot/sieve/rspamd-controller.pass learn_spam
- /etc/dovecot/sieve/rspamd-learn-ham.sh
#!/bin/sh
exec /usr/bin/rspamc -h 10.0.0.8:11334 -P /etc/dovecot/sieve/rspamd-controller.pass learn_ham
- Berechtigungen erneut prüfen
chown -R root:root /etc/dovecot/sieve
chown root:vmail /etc/dovecot/sieve/rspamd-controller.pass
chmod 0755 /etc/dovecot/sieve
chmod 0640 /etc/dovecot/sieve/rspamd-controller.pass
- Zugriff testen
rspamc -h 10.0.0.8:11334 -P /etc/dovecot/sieve/rspamd-controller.pass stat
Test
- Konfiguration prüfen
- Die geladene Dovecot-Konfiguration muss die IMAPSieve- und Extprograms-Optionen enthalten
doveconf -n | grep -E 'imap_sieve|sieve_imapsieve|sieve_extprograms|sieve_pipe_bin_dir'
- Rspamd-Verbindung prüfen
- Der Dovecot-Host muss den Rspamd-Controller erreichen können
rspamc -h <published_ip>:11334 stat
- Logs beobachten
- Während des Tests sollten Dovecot- und Rspamd-Logs beobachtet werden
journalctl -u dovecot -u rspamd -f
tail -f /var/log/roundcube/error.log /var/log/roundcube/error.log.1
| Testfall | Aktion | Erwartung |
|---|---|---|
| Spam | Nachricht nach Junk kopieren | learn_spam wird ausgeführt |
| Ham | Nachricht aus Junk nach INBOX kopieren | learn_ham wird ausgeführt |
| Trash | Nachricht aus Junk nach Trash kopieren | Kein Ham-Learning |
| Wiederholung | Dieselbe Nachricht erneut lernen | Rspamd kann already learned melden |
Fehleranalyse
| Symptom | Mögliche Ursache | Prüfung |
|---|---|---|
| Kein Learning beim Verschieben | IMAPSieve-Plugin nicht geladen | doveconf -n prüfen |
| Kein Learning beim Verschieben nach Spam | Ordnername stimmt nicht mit Junk überein | IMAP-Ordnernamen prüfen |
| Permission denied | Pipe-Skript nicht ausführbar oder falsche Rechte | Rechte unter /etc/dovecot/sieve prüfen |
| rspamc: connection refused | Rspamd-Controller nicht erreichbar | Host, Port und Firewall prüfen. Socket in der Konfiguration prüfen |
| authentication failed | Controller-Zugriff nicht erlaubt | secure_ip oder enable_password prüfen |
| already learned | Nachricht wurde bereits trainiert | Kein Fehler, erneutes Lernen wurde übersprungen |
| contains less tokens than required | Nachricht ist für Bayes-Learning zu kurz | min_tokens prüfen |
| Bayes-Symbol erscheint nicht im Scan-Ergebnis | Zu wenige gelernte Spam- oder Ham-Nachrichten | min_learns prüfen |
Bayes
- Bayes Hinweise
Sehr kurze Nachrichten werden von Rspamd nicht für Bayes-Learning verwendet
- Der Standardwert min_tokens = 11 bedeutet, dass mindestens 11 statistische Tokens vorhanden sein müssen
Bei zu kurzen Nachrichten erscheint im Log sinngemäß eine Meldung wie:
contains less tokens than required: 9 < 11
Bayes wirkt nicht unmittelbar nach den ersten gelernten Nachrichten
- Der Standardwert min_learns = 200 bedeutet, dass für Spam und Ham jeweils genügend gelernte Nachrichten vorhanden sein müssen, bevor die Bayes-Klassifizierung aktiv in die Bewertung einfließt
Rspamd speichert dafür gelernte IDs bzw. Signaturen im Cache und kann dann eine Meldung wie already learned zurückgeben.
| Parameter | Standardwert | Bedeutung |
|---|---|---|
| min_tokens | 11 | Mindestanzahl statistischer Tokens, damit eine Nachricht für Bayes verarbeitet wird |
| min_learns | 200 | Mindestanzahl gelernter Nachrichten pro Klasse, bevor Bayes für die Klassifizierung verwendet wird |
| cache_prefix | learned_ids | Prefix für gespeicherte IDs bereits gelernter Nachrichten |
- Variablen anzeigen
Die aktuell wirksamen Rspamd-Parameter können über rspamadm configdump geprüft werden
rspamadm configdump
Die Standardkonfiguration befindet sich in /etc/rspamd/statistic.conf
- Diese Datei sollte nicht direkt angepasst werden, da sie zur Paketkonfiguration gehört
- Eigene Werte setzen
Eigene Bayes-Parameter werden üblicherweise in /etc/rspamd/local.d/classifier-bayes.conf gesetzt
- Die Datei ergänzt oder überschreibt die Standardwerte aus der Rspamd-Konfiguration
- /etc/rspamd/local.d/classifier-bayes.conf
min_tokens = 11;
min_learns = 200;
cache_prefix = "learned_ids";
Nach der Änderung wird die Rspamd-Konfiguration geprüft
rspamadm configtest
Anschließend wird Rspamd neu gestartet, damit die geänderten Werte aktiv werden
systemctl restart rspamd
Installation
Aufruf
Optionen
| Unix | GNU | Parameter | Beschreibung |
|---|---|---|---|
Parameter
Umgebungsvariablen
Exit-Status
| Wert | Beschreibung |
|---|---|
| 0 | Erfolg |
| >0 | Fehler |
Anwendung
Problembehebung
Konfiguration
Dateien
| Datei | Beschreibung |
|---|---|
Anhang
Siehe auch
Dokumentation
Links
Projekt
Weblinks