On 8/2/2021 1:38 μ.μ., Matus UHLAR - fantomas wrote:
that's not how milter works, unless you instructed amavisd-milter to
deliver
mail by server via "-D server" option.
The default is "-D client", which means, amavisd instructs postfix
what to
do with the mail - reject/quarantine/pass it, add/remove/modify the
headers
etc.
Hmm, I see. It seems it's running in client mode, because I don't see
any -D definition, so the default applies.
So, milter delivers mail back to postfix for final delivery?
1. does amavisd-new listen on port 10028?
Yes.
2. IIUC FILTER applies after message is queued - after milter was
applied.
Testing shows you are right, please read on.
again, FILTER applies after mail is received, so next lines in log should
show how the mail is delivered to amavis on port 10028
Next lines show that the mail is quarantined (it is an EICAR virus-test
message, which should be quarantined if it does not by-pass through port
10028, as desired); here is the whole session:
Feb 8 01:54:53 mailgw1 postfix/smtpd[202464]: connect from
hedgehog.birch.relay.mailchannels.net[23.83.209.81]
Feb 8 01:54:54 mailgw1 postfix/smtpd[202464]: Anonymous TLS connection
established from hedgehog.birch.relay.mailchannels.net[23.83.209.81]:
TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
Feb 8 01:54:55 mailgw1 postfix/smtpd[202464]: NOQUEUE: filter: RCPT
from hedgehog.birch.relay.mailchannels.net[23.83.209.81]:
<[email protected]>: Sender address triggers FILTER
smtp:[127.0.0.1]:10028; from=<[email protected]> to=<[email protected]>
proto=ESMTP helo=<hedgehog.birch.relay.mailchannels.net>
Feb 8 01:54:55 mailgw1 postfix/smtpd[202464]: 4DYmH36X5JzLlrw:
client=hedgehog.birch.relay.mailchannels.net[23.83.209.81]
Feb 8 01:54:56 mailgw1 postfix/cleanup[202468]: 4DYmH36X5JzLlrw:
message-id=<[email protected]>
Feb 8 01:54:56 mailgw1 postfix/cleanup[202468]: 4DYmH36X5JzLlrw:
milter-discard: END-OF-MESSAGE from
hedgehog.birch.relay.mailchannels.net[23.83.209.81]: milter triggers
DISCARD action; from=<[email protected]> to=<[email protected]>
proto=ESMTP helo=<hedgehog.birch.relay.mailchannels.net>
Feb 8 01:54:56 mailgw1 postfix/smtpd[202464]: disconnect from
hedgehog.birch.relay.mailchannels.net[23.83.209.81] ehlo=2 starttls=1
mail=1 rcpt=1 data=1 quit=1 commands=7
The message is not honoring the bypass and gets quarantined.
But if I don't send an infected message, the flow is clearer: First the
message is delivered via the milter, scanned via the normal policy bank,
and only AFTER that it is examined by the BYPASS policy bank! Here is a
log:
Feb 8 15:15:00 mailgw1 postfix/smtpd[219538]: connect from
black.elm.relay.mailchannels.net[23.83.212.19]
Feb 8 15:15:01 mailgw1 postfix/smtpd[219538]: Anonymous TLS connection
established from black.elm.relay.mailchannels.net[23.83.212.19]: TLSv1.2
with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
Feb 8 15:15:03 mailgw1 postfix/smtpd[219538]: NOQUEUE: filter: RCPT
from black.elm.relay.mailchannels.net[23.83.212.19]:
<[email protected]>: Sender address triggers FILTER
smtp:[127.0.0.1]:10028; from=<[email protected]> to=<[email protected]>
proto=ESMTP helo=<black.elm.relay.mailchannels.net>
Feb 8 15:15:03 mailgw1 postfix/smtpd[219538]: 4DZ62H32SKzLm4t:
client=black.elm.relay.mailchannels.net[23.83.212.19]
Feb 8 15:15:04 mailgw1 postfix/cleanup[219533]: 4DZ62H32SKzLm4t:
message-id=<[email protected]>
Feb 8 15:15:04 mailgw1 postfix/qmgr[202450]: 4DZ62H32SKzLm4t:
from=<[email protected]>, size=2167, nrcpt=1 (queue active)
Feb 8 15:15:04 mailgw1 postfix/smtpd[219538]: disconnect from
black.elm.relay.mailchannels.net[23.83.212.19] ehlo=2 starttls=1 mail=1
rcpt=1 data=1 quit=1 commands=7
Feb 8 15:15:04 mailgw1 postfix/smtp[219543]: 4DZ62H32SKzLm4t:
to=<[email protected]>, relay=127.0.0.1[127.0.0.1]:10028, delay=2.1,
delays=1.7/0.03/0.06/0.39, dsn=2.0.0, status=sent (250 2.0.0 from
MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 4DZ62J63CZzLm4w)
Feb 8 15:15:04 mailgw1 postfix/qmgr[202450]: 4DZ62H32SKzLm4t: removed
and in Amavis:
Feb 8 15:15:04 mailgw1 amavis[219136]: loaded policy bank "AM.PDP-SOCK"
Feb 8 15:15:04 mailgw1 amavis[219136]: process_request: fileno sock=19,
STDIN=0, STDOUT=1
Feb 8 15:15:04 mailgw1 amavis[219136]: policy protocol: request=AM.PDP
Feb 8 15:15:04 mailgw1 amavis[219136]: policy protocol:
queue_id=4DZ62H32SKzLm4t
Feb 8 15:15:04 mailgw1 amavis[219136]: policy protocol:
sender=<[email protected]>
Feb 8 15:15:04 mailgw1 amavis[219136]: policy protocol:
recipient=<[email protected]>
Feb 8 15:15:04 mailgw1 amavis[219136]: policy protocol:
tempdir=/var/spool/amavisd/tmp/afXXXXO7JePJ
Feb 8 15:15:04 mailgw1 amavis[219136]: policy protocol:
tempdir_removed_by=client
Feb 8 15:15:04 mailgw1 amavis[219136]: policy protocol:
mail_file=/var/spool/amavisd/tmp/afXXXXO7JePJ/email.txt
Feb 8 15:15:04 mailgw1 amavis[219136]: policy protocol:
delivery_care_of=client
Feb 8 15:15:04 mailgw1 amavis[219136]: policy protocol:
client_address=23.83.212.19
Feb 8 15:15:04 mailgw1 amavis[219136]: policy protocol:
client_name=black.elm.relay.mailchannels.net
Feb 8 15:15:04 mailgw1 amavis[219136]: policy protocol:
helo_name=black.elm.relay.mailchannels.net
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) Request: AM.PDP
/var/spool/amavisd/tmp/afXXXXO7JePJ: <[email protected]> ->
<[email protected]>
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) body hash:
85d118f616b01de828c13be8886578ad
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) trace: AM.PDP://x <
23.83.212.19 < ESMTP://127.0.0.1 < ESMTPA://100.105.161.48 <
158.69.52.184 <
esmtpsa___tls_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256://195.251.202.xxx
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) Checking:
rg-QauWQLn8U AM.PDP-SOCK [23.83.212.19] <[email protected]> ->
<[email protected]>
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) 2822.From:
<[email protected]>
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) p001 1 Content-Type:
text/plain, 7bit, size: 72, SHA1 digest:
cc20e534e6999e3114821fc0e8f6126b334b2ae8
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) Checking for banned
types and filenames
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) collect banned
table[0]: [email protected], tables:
DEFAULT=>Amavis::Lookup::RE=ARRAY(0x56549d366c68)
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) p.path
[email protected]: "P=p001,L=1,M=text/plain,T=asc"
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) presenting full
original message to scanners as
/var/spool/amavisd/tmp/afXXXXO7JePJ/parts/p002
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) run_av Using
(ClamAV-clamd): (code) CONTSCAN /var/spool/amavisd/tmp/afXXXXO7JePJ/parts\n
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) ClamAV-clamd:
Connecting to socket /var/run/clamd.amavisd/clamd.sock
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) new socket by
IO::Socket::UNIX to /var/run/clamd.amavisd/clamd.sock, timeout set to 10
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) ClamAV-clamd:
Sending CONTSCAN /var/spool/amavisd/tmp/afXXXXO7JePJ/parts\n to socket
/var/run/clamd.amavisd/clamd.sock
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) rw_loop read: got eof
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) run_av
(ClamAV-clamd): CLEAN
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) run_av
(ClamAV-clamd) result: clean
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) wbl: whitelisted
sender <[email protected]>
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) do_notify_and_quar:
ccat=CleanTag (1,1) ("1,1":CleanTag, "1":Clean, "0":CatchAll)
ccat_block=(), qar_mth=
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) delivery method is
1, recips: [email protected]
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) spam-tag,
<[email protected]> -> <[email protected]>, No, score=x
tagged_above=-999 required=3.4 WHITELISTED tests=[] autolearn=unavailable
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) status counters:
InMsgsStatus{Accepted,AcceptedInbound}
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) Passed CLEAN
{AcceptedInbound}, AM.PDP-SOCK [23.83.212.19] [195.251.202.xxx]
<[email protected]> -> <[email protected]>, Queue-ID: 4DZ62H32SKzLm4t,
Message-ID: <[email protected]>, mail_id:
rg-QauWQLn8U, Hits: -, size: 2117, 343 ms
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) mail checking ended:
version_server=2\nlog_id=219136-20\nsetreply=250 2.5.0
Ok,%20id=219136-20,%20continue%20delivery\ninsheader=0 X-Spam-Status
No,%20score=x%20tagged_above=-999%20required=3.4%20WHITELISTED%20tests=[]%0a%09autolearn=unavailable\ninsheader=0
X-Spam-Level \ninsheader=0 X-Spam-Score 0\ninsheader=0 X-Spam-Flag
NO\ninsheader=0 X-Virus-Scanned
amavisd-new%20at%20example.com\nreturn_value=continue\nexit_code=0
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) size: 2117, TIMING
[total 347 ms] - got data: 0.0 (0%)0, check_init: 1.2 (0%)0, digest_hdr:
0.8 (0%)1, digest_body_dkim: 0.2 (0%)1, collect_info: 2.2 (1%)1, mkdir
parts: 0.8 (0%)1, mime_decode: 4.7 (1%)3, get-file-type1: 6 (2%)5,
parts_decode: 0.1 (0%)5, check_header: 0.3 (0%)5, AV-scan-1: 319
(92%)97, spam-wb-list: 1.1 (0%)97, decide_mail_destiny: 0.7 (0%)97,
notif-quar: 0.5 (0%)97, prepare-dsn: 1.8 (1%)98, report: 1.2 (0%)98,
main_log_entry: 2.9 (1%)99, update_snmp: 1.2 (0%)99, rundown: 2.4 (1%)100
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) Requesting process
rundown after 20 tasks (and 20 sessions)
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) load: 5 %, total
idle 1656.274 s, busy 79.820 s
Feb 8 15:15:04 mailgw1 amavis[219136]: (219136-20) SA rundown_child (0)
Feb 8 15:15:04 mailgw1 amavis[219289]: loaded policy bank "BYPASS"
Feb 8 15:15:04 mailgw1 amavis[219289]: process_request: fileno sock=19,
STDIN=0, STDOUT=1
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) ESMTP
[127.0.0.1]:10028
/var/spool/amavisd/tmp/amavis-20210208T151504-219289-LAdhQtjY:
<[email protected]> -> <[email protected]> SIZE=2167 Received: from
mailgw1.example.com ([127.0.0.1]) by localhost (mailgw1.example.com
[127.0.0.1]) (amavisd-new, port 10028) with ESMTP for
<[email protected]>; Mon, 8 Feb 2021 15:15:04 +0200 (EET)
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) body hash:
85d118f616b01de828c13be8886578ad
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) trace:
ESMTP://[127.0.0.1]:40562 < ESMTPS://23.83.212.19 < ESMTP://127.0.0.1 <
ESMTPA://100.105.161.48 < 158.69.52.184 <
esmtpsa___tls_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256://195.251.202.xxx
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) client IP address
unknown, fetched from Received: 127.0.0.1
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) Checking:
zQ4_NwZGSDCQ BYPASS [127.0.0.1] <[email protected]> -> <[email protected]>
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) 2822.From:
<[email protected]>
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) p001 1 Content-Type:
text/plain, 7bit, size: 72, SHA1 digest:
cc20e534e6999e3114821fc0e8f6126b334b2ae8
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) Checking for banned
types and filenames
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) skipping banned
check: all recipients bypass banned checks
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) do_notify_and_quar:
ccat=Clean (1,0) ("1":Clean, "0":CatchAll) ccat_block=(), qar_mth=
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) delivery method is
1, recips: [email protected]
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) smtp session:
setting up a new session
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) new socket using
IO::Socket::IP to [127.0.0.1]:10025, timeout 35
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) smtp greeting: 220
mailgw1.example.com ESMTP NOA MAIL ICXC-NIKA, dt: 60.3 ms
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) smtp cmd> EHLO localhost
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) smtp resp to EHLO:
250 mailgw1.example.com\nPIPELINING\nSIZE
15728640\nETRN\nSTARTTLS\nENHANCEDSTATUSCODES\n8BITMIME\nDSN\nSMTPUTF8\nCHUNKING
Feb 8 15:15:04 mailgw1 amavis[202351]: sd_notify (no socket):
STATUS=Starting child process(es), ready for work.
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) AUTH not needed,
user='', MTA offers ''
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) smtp cmd> MAIL
FROM:<[email protected]> BODY=7BIT
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) smtp cmd> RCPT
TO:<[email protected]> ORCPT=rfc822;[email protected]
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) smtp cmd> DATA
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) smtp resp to MAIL
(pip): 250 2.1.0 Ok
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) smtp resp to RCPT
(pip) (<[email protected]>): 250 2.1.5 Ok
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) smtp resp to DATA:
354 End data with <CR><LF>.<CR><LF>
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) smtp resp to
data-dot (<[email protected]>): 250 2.0.0 Ok: queued as
4DZ62J63CZzLm4w, dt: 7.9 ms
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10)
Amavis::Out::SMTP::Session close, keeping connection
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) zQ4_NwZGSDCQ FWD
from <[email protected]> -> <[email protected]>, BODY=7BIT 250 2.0.0
from MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 4DZ62J63CZzLm4w
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) status counters:
InMsgsStatus{Relayed,RelayedUntagged,RelayedUntaggedInbound}
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) Passed CLEAN
{RelayedInbound}, BYPASS [127.0.0.1] [195.251.202.xxx]
<[email protected]> -> <[email protected]>, Message-ID:
<[email protected]>, mail_id:
zQ4_NwZGSDCQ, Hits: -, size: 2327, 423 ms
Feb 8 15:15:04 mailgw1 amavis[219289]: (219289-10) sending SMTP
response: "250 2.0.0 from MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok:
queued as 4DZ62J63CZzLm4w"
If I understand right, mail is delivered via milter, then returned to
postfix, re-sent to amavisd via port 10028 then received back on port
10025 and finally delivered.
So, the message always follows the default route / policy bank and only
additionally honors the bypass policy, thus invalidating its purpose.
What is your advice?
Cheers,
Nick