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.

On 08.02.21 16:28, Nikolaos Milas wrote:
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?

no, milter (usually) just tells postfix what to do with mail. default is 
"accept".
that's why there's just one mail and one mail ID visible in postfix logs,
when mail is processed with milters.

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:

wrapping log lines is not a good idea...

Feb  8 01:54:53 mailgw1 postfix/smtpd[202464]: connect from 
hedgehog.birch.relay.mailchannels.net[23.83.209.81]

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

this milter told postfix to discard the mail, so amavis/milter are
responsible for what happens next to mail. I think this happens when "-D server" is used with amavisd-milter.

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

Milter actions not logged here, which means milter let mail to pass.

then I see that the mail is sent to [127.0.0.1]:10028, which further reports
mail delivered back to postfix at [127.0.0.1]:10025

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]>

this is the milter handling the mail (AM.PDP-SOCK)...

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) 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

... which instructed postfix to accept the mail.

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)

and this is the mail processing via FILTER on [127.0.0.1]:10028

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"

... sent back to postfix.


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.

if you need to bypass milter, you should either instruct milter not to
handle the mail or postfix not to use the milter.

You can do the first by configuring amavis policy bank "AM.PDP-SOCK".

However, what's the point of not processing mail with milter?


--
Matus UHLAR - fantomas, [email protected] ; http://www.fantomas.sk/
Warning: I wish NOT to receive e-mail advertising to this address.
Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
- Holmes, what kind of school did you study to be a detective?
- Elementary, Watkins.  -- Daffy Duck & Porky Pig

Reply via email to