Repository navigation
Conversation
Postfix accepted mail for disabled mailboxes and hidden accounts, then Dovecot refused it at delivery and a bounce went back to the sender, often forged. Apply the same LDAP exclusion as Dovecot and reload Postfix when a mailbox is enabled or disabled.
Drop disabled mailboxes from SQL aliases, forwards, catch-all and LDAP mail aliases. An address that leads only to disabled mailboxes is now rejected at RCPT time. A disabled mailbox keeps its forward, and its local copy is dropped instead of bounced.
Filtering disabled users out of the alias maps made their addresses fall through to the domain catch-all. Check the unfiltered maps at RCPT time so these addresses are rejected, while unknown ones still reach the catch-all.
DavidePrincipi
left a comment
There was a problem hiding this comment.
Thanks for the thorough work and the tests! While reviewing, I tried to reduce the Postfix changes and the number of test cases. Here's a proposal that covers the same goal with less configuration.
Semantics
Let's keep two cases apart:
- Disabled LDAP account (user locked in the directory): it still receives mail, and its forwards still work. This PR already leaves it alone, good.
- Disabled mailbox: nothing is delivered to it. Direct mail is rejected at RCPT time. Copies that come through aliases, groups or forwards are discarded silently.
With this definition, a disabled mailbox doesn't need to keep its forward. The admin can lock the LDAP account instead. A catch-all pointing to a disabled mailbox is an admin mistake, and it's better caught in alter-domain or the UI than in Postfix.
Proposal
In reload-config, generate two texthash tables from DOVECOT_DISABLED_USERS, with lowercase keys:
# /etc/postfix/disabled_mailboxes_rcpt -- access style
u2@ 550 5.1.1 User unknown
# /etc/postfix/disabled_mailboxes -- transport style
u2@<vdomain> discard:
1. Reject at RCPT time, only for domains with "add users" enabled, using a restriction class:
smtpd_restriction_classes = disabled_mailboxes
disabled_mailboxes = check_recipient_access texthash:${S}meta_directory/disabled_mailboxes_rcpt
smtpd_recipient_restrictions =
...
check_recipient_access inline:{ { dom1 = disabled_mailboxes }, { dom2 = disabled_mailboxes } },
The domain list comes from tmpl_laddusers_domains. All tables are indexed, so Postfix also handles address extensions: u2+tag@dom1 falls back to u2@.
I first tried a pipemap with a regexp: stage. It loses the extension fallback, because a pipemap takes the pattern-table flags of its first table (dict_pipe.c), and Postfix tries user@domain without the extension only on indexed tables (mail_addr_find.c, see also the "REGULAR EXPRESSION TABLES" section of access(5)).
2. Discard any copy delivered to a disabled mailbox. This is what #314 does, with a file instead of the inline map:
transport_maps = texthash:${S}meta_directory/disabled_mailboxes, sqlite:${S}meta_directory/relaydest.cf
Postfix looks up transport_maps after alias expansion, so this covers SQL aliases, wildcards, LDAP mail aliases, groups, forwards with a kept copy, and the catch-all. With around 100 disabled users, a file also keeps main.cf readable. Since both points share the same generated list, I'd fold #314 into this PR.
What can be dropped from this PR
- the disabled-user filter in the LDAP templates (
laddusers-*,laddaliases-*) tmpl_disabled_users_sqland the filters inaliases.cfanduserforwards.cf, soaliases.cfcan stay where it is- the
*-all.cfmaps and the twocheck_recipient_access pipemap:{unionmap…}lines - the
domain =change inuserforwards.cf
The reload of postfix in set-mailbox-enabled and import-module stays.
Known limit (accepted)
An address that expands only to disabled mailboxes (SQL alias, LDAP mail alias, group) is accepted and then discarded, not rejected. #314 already has the same limit for groups, so the behaviour is consistent. The 550 still covers the most common case: mail sent directly to the user.
For future enhancements
The forward settings of a disabled mailbox now do nothing. A hint in the mailbox form would avoid confusion. The UI could also warn when the mailbox being disabled is the destination of a catch-all or of postmaster@*, since mail to those addresses would then be discarded silently.
Suggested robot cases
[email protected]→ 550[email protected]→ 550[email protected]→ 550u2@<domain without "add users">→ the usual "User unknown in virtual alias table"- alias / group / forward with a kept copy to
u2→ the other recipients get it,u2doesn't, no bounce (from #314) MixedCaseUseras destination → discarded (from #314)- mailbox enabled again → accepted
What do you think?
Replace the LDAP and SQL filters with two tables generated from DOVECOT_DISABLED_USERS. In domains with user addresses, a restriction class rejects mail sent directly to a disabled mailbox at RCPT time. A transport_maps entry discards copies that come through aliases, groups, forwards or the catch-all, so no bounce goes back to the sender.
Move the group, alias and forward cases of the expansion suite into the disabled mailbox suite. Addresses that lead only to disabled mailboxes are now accepted and dropped without a bounce.
The generic unknown user reject also starts with "User unknown", so the disabled mailbox checks passed even without the new table. Also share the user domain switch keyword between suites.
|
Thanks Davide, I followed your proposal and folded #314 into this PR. QEMU tests are green and I also tested on a real node. I found two regressions compared to main. First, the inline domain map also matches subdomains, because of parent_domain_matches_subdomains. With Second, an SQL alias named like a disabled user is rejected too. |
An SQL alias, a wildcard alias or a public mailbox with the name of a disabled user must still be delivered, as on main. A subdomain configured on its own must not get the disabled mailbox reject.
A domain key in the RCPT check also matched subdomains, and the local part key rejected SQL aliases named like a disabled user. Write full user@domain keys for domains with user addresses and skip those with an alias. Address actions now reload postfix to keep the table current.
|
Update: I fixed both regressions without leaving the texthash approach. 69b0ecb adds robot cases for an exact alias, a wildcard alias and a public mailbox named like a disabled user, and for a separate subdomain without "add users". 3ae05f9 writes full Tested on QEMU and on a real node. Is the extra reload on address actions fine for you? |
Imported aliases are inserted after the domain step reloaded postfix. The disabled mailbox table then missed them, and an alias named like a hidden or disabled user stayed rejected until the next reload.
Build both disabled mailbox tables from DOVECOT_DISABLED_USERS in a single awk run, and shorten the comments.
|
lets close this one, the implementation is at #348 |
Postfix accepted mail for disabled mailboxes and for hidden accounts like krbtgt or ldapservice. Dovecot then refused the message at delivery, and Postfix sent a bounce to the sender. The sender is often forged, so this created backscatter. When an address expanded to several mailboxes, like a group or an alias, the copy for the disabled mailbox bounced too.
Refs NethServer/dev#8185 NethServer/dev#8205
reload-config now writes two texthash tables from DOVECOT_DISABLED_USERS. Mail sent directly to a disabled mailbox gets "550 5.1.1 User unknown" during the SMTP session, in domains with "add users". The keys are full
user@domainaddresses, so a subdomain is not affected, and an SQL alias with the same name as a disabled user still wins. Copies that reach a disabled mailbox through an alias, a group, a forward or the catch-all are discarded in transport_maps, without a bounce. Postfix is reloaded when a mailbox is enabled or disabled, and when an address or a public mailbox is added or removed.A disabled mailbox no longer applies its forward. A user locked in the directory is not affected: it still receives mail and its forward works. An address that leads only to disabled mailboxes is accepted and then discarded, not rejected.
This PR replaces #314.
How to test
The suite
tests/50__smtp/00__disabled_mailbox.robotcovers these cases on AD and OpenLDAP. To check by hand:RCPT TOon port 25 for the user,user+tagandkrbtgt(AD) gets 550.RCPT TOis accepted.