Skip to content

feat: store disabled mailboxes in pcdb - #356

Merged
DavidePrincipi merged 6 commits into
mainfrom
bug-8185
Nov 26, 2026
Merged

DavidePrincipi merged 6 commits into
mainfrom
bug-8185

Conversation

@DavidePrincipi

@DavidePrincipi DavidePrincipi commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Some installations disable many mailboxes, even in bulk, but the list was a single environment variable: each change rewrote it and reloaded Postfix and Dovecot. Mail to disabled mailboxes and group members was also bounced to possibly forged senders (NethServer/dev#8185, NethServer/dev#8205). Part of Mail 2.0 (NethServer/dev#8267).

Disabled mailboxes move to a table of the Postfix database, with an optional description. Postfix and Dovecot read it at each lookup: changes apply at once, with no reload and no escaping. Their addresses are now unknown (rejected, or sent to the catch-all), groups skip them, remaining copies are dropped without a bounce, and login is denied. Mailbox contents are kept, Dovecot still lists them (e.g. for doveadm -A jobs), and master users can still log in.

  • Postfix filters the LDAP user, group and alias results through a SQL query; Dovecot denies login with a read-only SQL database.
  • A new pcdb-init unit creates the database before Postfix and Dovecot start; after a restore it loads the backup dump, so the services never run on an empty or replaced database.
  • The old DOVECOT_DISABLED_USERS variable is migrated on update.

How to test

  • Disable a mailbox: its addresses are rejected and its login fails; enable it: both work again at once.
  • A group whose members are all disabled is rejected.
  • Run the robot suites, including the new disabled mailbox SMTP suite.

See also


Generated by Claude Code:claude-opus-5-5 with nethserver-pr

@DavidePrincipi DavidePrincipi self-assigned this Nov 24, 2026
Store the users with a disabled mailbox in a table of the Postfix
configuration DB, instead of an environment variable: each row is one
user, with an optional description. Postfix and Dovecot can read it at
each lookup, so a change applies without a reload, and a bulk change
is a single transaction.

Assisted-by: Claude Code:claude-opus-5-5
Mail to a disabled mailbox was accepted, then refused by Dovecot and
bounced to a possibly forged sender.

Chain the LDAP user, group and alias maps with a SQL query that drops
disabled and masked users from their results. Their addresses become
unknown, like any address that is not assigned: Postfix rejects them,
or delivers them to the catch-all. A group skips its disabled members,
and is unknown if none is left. Copies that still reach a disabled
mailbox through SQL aliases are discarded, and its forwards ignored.

The masked users are the system accounts of the user domain, like
krbtgt. They replace DOVECOT_DISABLED_USERS in discovery.env, and only
names that need no escaping are accepted.

Assisted-by: Claude Code:claude-opus-5-5
Mount the Postfix configuration DB read-only, and deny the login of
users with a disabled mailbox with a SQL passdb, before the LDAP one.
Their mailbox is kept and still listed by the userdb. Only the masked
users stay out of the LDAP filters.

Assisted-by: Claude Code:claude-opus-5-5
Actions read and write the disabled_mailboxes table, and no longer
reload Postfix and Dovecot. set-mailbox-enabled accepts an optional
description, and list-user-mailboxes returns it. import-module
describes the mailboxes it disables.

An update moves DOVECOT_DISABLED_USERS to the table before the
containers restart, then removes the variable.

Assisted-by: Claude Code:claude-opus-5-5
Add the disabled mailbox SMTP suite and its keywords. A group whose
members are all disabled is unknown, or goes to the catch-all. Check
the description of a disabled mailbox in the API.

Assisted-by: Claude Code:claude-opus-5-5
@DavidePrincipi
DavidePrincipi marked this pull request as ready for review November 25, 2026 10:50
Dovecot keeps its SQLite connection to pcdb open. When restore-module
replaced the file after the services had started, Dovecot kept reading
the removed one: restored disabled mailboxes could log in until its next
reload. They could also log in while the services ran on the empty DB,
before the restored one was loaded.

Create pcdb in a separate pcdb-init container, started by a unit that
Postfix and Dovecot require. If pcdb.sqlite is missing, it loads the
restored backup dump, or creates the initial DB; the services then start
with the final DB, and restore-module no longer replaces it. A failed
load leaves no DB, so the services do not start on a wrong one.

Assisted-by: Claude Code:claude-opus-5-5

@stephdl stephdl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I tested this branch on a node with an AD user domain. A disabled user with a mixed case name is rejected with "User unknown in virtual alias table", in both cases of the address, like an address that does not exist. Enabled users are still accepted, and copies to the disabled mailbox go to discard:. The change applies at once, without a reload.

All my points from #348 are addressed: no LDAP filter escaping in Dovecot anymore, the restore loads the pcdb dump before Postfix and Dovecot start, and the tests wait for the log lines instead of a fixed sleep.

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