Skip to content

fix(postfix): reject and discard disabled mailboxes - #312

Closed
stephdl wants to merge 14 commits into
mainfrom
fix-8185-disabled-rcpt
Closed

stephdl wants to merge 14 commits into
mainfrom
fix-8185-disabled-rcpt

Conversation

@stephdl

@stephdl stephdl commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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@domain addresses, 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.robot covers these cases on AD and OpenLDAP. To check by hand:

  1. Disable the mailbox of a user. RCPT TO on port 25 for the user, user+tag and krbtgt (AD) gets 550.
  2. Send to a group or an alias with that user and another one. The other user gets the message, no bounce is sent.
  3. Add an alias with the same name as the disabled user, pointing to another user. The message is delivered.
  4. Enable the mailbox again. RCPT TO is accepted.

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.
@stephdl stephdl self-assigned this Oct 5, 2026
@stephdl
stephdl marked this pull request as draft October 5, 2026 14:42
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 DavidePrincipi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_sql and the filters in aliases.cf and userforwards.cf, so aliases.cf can stay where it is
  • the *-all.cf maps and the two check_recipient_access pipemap:{unionmap…} lines
  • the domain = change in userforwards.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] → 550
  • u2@<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, u2 doesn't, no bounce (from #314)
  • MixedCaseUser as 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.
@stephdl

stephdl commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

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 sub.rocky9-pve.org as its own domain without "add users", [email protected] gets the 550. I can fix it in the same texthash table with full u2@dom keys, dropping the restriction class. Domain actions already reload postfix.

Second, an SQL alias named like a disabled user is rejected too. [email protected] pointing to admin gets the 550, while on main the alias wins. A generated table cannot skip it, because add-address does not reload postfix. Is it OK as a known limit, or should I use a live sqlite lookup for the RCPT check?

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.
@stephdl

stephdl commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

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 user@domain keys for the "add users" domains, skipping the ones that have an alias in destmap. The restriction class and the inline map are gone. To keep the table current, add-address, remove-address, add-public-mailbox and remove-public-mailbox now reload postfix, like the domain actions already do.

Tested on QEMU and on a real node. Is the extra reload on address actions fine for you?

@stephdl stephdl changed the title fix(postfix): reject disabled mailboxes at RCPT fix(postfix): reject and discard disabled mailboxes Nov 3, 2026
stephdl and others added 3 commits November 3, 2026 15:34
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.

@DavidePrincipi DavidePrincipi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephdl i made a step back in this PR #348
I think it's a good balance between my doubts and your earlier implementation. I asked your review there, what do you think?

@stephdl

stephdl commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

lets close this one, the implementation is at #348

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants