Dovecot can authenticate users using a passwd-like file. This happens in two phases. First, users are looked up in the passdb
. If the user is found and authenticated, then the user is looked up again in the userdb
to get things like their UID/GID and home directory.
Now, this doesn’t allow for aliasing users in Dovecot. If the login is user@example.com
, then the defaults will lead to trying to find “user@example.com” in the passdb, then the userdb. Failure to have these configured correctly can result in different errors:
- User not found in the passdb: authentication fails. (Beware of fail2ban here.)
- User not found in the userdb: user can authenticate, but appears to have no mail!
For my own system, the virtual address needs to be resolved to a particular system user (aka Unix account.) I also want to share the password files with Postfix for outbound email authentication. This made Dovecot complicated: I want to log in as user@domain
, then have that processed as user
for both lookups in a file that is specific to the domain. I put the shortened user
in the passwd-file, and now I have to configure passdb
carefully:
# /etc/dovecot/local.conf snippet
passdb {
args username_format=%n /local/auth/%d/passwd
override_fields user=%n
driver = passwd-file
}
userdb {
args /local/auth/%d/passwd
driver = passwd-file
}
This makes passdb do the first lookup using the short username, %n
, with the args
setting. Then, that short username is returned by override_fields
for use in later lookups. After that, userdb can continue with no special settings; it will use the overridden user to look up the short name, and nothing special needs to happen.
I believe that the passwd-file can’t return a different username, because there’s only one username field (the first field), and it is also the lookup key. This is what requires us to use override_fields
for this scenario.