Repository navigation
fix(postfix): hide disabled mailboxes in LDAP maps - #348
DavidePrincipi wants to merge 19 commits into
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.
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.
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.
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.
Filter disabled and hidden users out of the LDAP user and mail attribute maps. Their addresses become unknown, like any other address that is not assigned: Postfix rejects them during the SMTP session, or the domain catch-all gets them. Disabling a mailbox is meant for system and device accounts; a person who leaves is disabled in LDAP instead, so the catch-all is the expected destination. This replaces the generated RCPT table and its SQL alias exceptions: SQL aliases and public mailboxes are not filtered, so they still win. Postfix no longer needs a reload when addresses change. Copies that come through aliases, groups and the catch-all are still discarded by the transport table, now without duplicate keys, which make a texthash table unusable and stop all deliveries. Forwards of a disabled mailbox no longer apply to such copies. Co-authored-by: Stephane de Labrusse <[email protected]> Assisted-by: Claude Code:claude-sonnet-5-5
Direct mail to a disabled mailbox now gets the usual unknown user error, or goes to the catch-all. Cover the LDAP mail address and the forward of group copies, and drop the cases of the removed RCPT table. Assisted-by: Claude Code:claude-sonnet-5-5
|
I tested this branch on a live node with an OpenLDAP user domain. Disabled addresses are rejected as unknown, copies through aliases and the catch-all are dropped with no bounce, and enabling the user again restores delivery. It works for me. One point outside this PR. Postfix now escapes the names from DOVECOT_DISABLED_USERS in the LDAP filter, but dovecot/usr/local/bin/reload-config builds the same NOT clause without escaping. If a disabled or hidden name contains |
| echo "${DOVECOT_DISABLED_USERS}" | awk -F , -v "vdomain=${tmpl_vdomain}" '{ | ||
| for (i = 1; i <= NF; i++) { | ||
| user = tolower($i) | ||
| if (user != "" && !seen[user]++) print user "@" tolower(vdomain) " discard:" |
There was a problem hiding this comment.
The texthash line is written as is, with no check on whitespace. An AD sAMAccountName can contain a space. For a disabled user "john doe" the line becomes john doe@vdomain discard:, so the key is john and the copy to the real mailbox is not discarded. The LDAP clause escapes the name, but this table does not. Should we skip or log names with whitespace here?
| ... expect_curl_exitcode= | ||
| Should return SMTP error 550 5.1.1 <${address}>: Recipient address rejected: User unknown in virtual alias table | ||
|
|
||
| Should not send bounce |
There was a problem hiding this comment.
The fixed 2s sleep can let the test pass on a slow node before the bounce is logged. Could we first wait with Wait Until Keyword Succeeds for the discard or delivery log line, then check there is no bounce?
Dovecot copied the names of disabled and hidden users into its LDAP filter as they are. A "*" in a name hid every user, and a parenthesis broke the filter, so nobody could log in. Postfix escapes the same names, so the two containers could disagree on who has a mailbox. Escape the names in Dovecot like in Postfix, and skip empty and repeated names. Both containers also escape spaces, quotes and "#", which are valid LDAP filter escapes and safe in the configuration syntax. Assisted-by: Claude Code:claude-opus-5-5
A user name with a space, possible in Active Directory, split the texthash line: the key became the first word only, and copies to that mailbox were not discarded. Quote the names that are not a plain local part, like Postfix quotes the address it looks up. Assisted-by: Claude Code:claude-opus-5-5
A fixed 2 second sleep let the bounce check pass on a slow node before the bounce was logged. Postfix logs a bounce before it removes the message from the queue, so wait for the removal instead. The queue ID of the last message was kept in a local variable only, so the journal checks of other keywords matched any message. Store it as a test variable. Assisted-by: Claude Code:claude-opus-5-5
stephdl
left a comment
There was a problem hiding this comment.
Thanks, both points are addressed. The quoted keys in the discard map match how Postfix looks up the address, and waiting for the queue removal is better than what I suggested. A test with a disabled AD user whose name has a space would be nice, but it does not block.
|
Replaced by #356, which keeps the same mail behavior with the disabled mailboxes stored in a table of the Postfix configuration DB instead of the environment variable and LDAP filters. |
Mail sent to a disabled mailbox was accepted, then refused by Dovecot, so Postfix sent a bounce back, often to a forged sender (NethServer/dev#8185). Copies of a message that reach a disabled mailbox through aliases, groups and the catch-all must also be dropped without a bounce (NethServer/dev#8205). This draft is a simpler alternative to #312: it builds on its commits and replaces the generated RCPT reject table with an LDAP query filter.
A disabled mailbox address now behaves like any address that is not assigned: Postfix rejects it during the SMTP session with the usual "User unknown in virtual alias table", or the domain catch-all gets it. Disabling a mailbox is meant for system and device accounts that do not need mail; a person who leaves is disabled at LDAP level instead, so the catch-all is the expected destination. Copies that come through aliases, groups and the catch-all are still discarded without a bounce.
disabled_mailboxestransport table has no duplicate keys anymore: a user listed twice, for example both disabled and hidden, made the table unusable and stopped all deliveries.How to test
50__smtprobot suites; all pass on a test node with this branch image.See also
Generated by Claude Code:claude-haiku-5-5 with nethserver-pr