add config options to disable a domain and to disable logins for an account

to facilitate migrations from/to other mail setups.

a domain can be added in "disabled" mode (or can be disabled/enabled later on).
you can configure a disabled domain, but incoming/outgoing messages involving
the domain are rejected with temporary error codes (as this may occur during a
migration, remote servers will try again, hopefully to the correct machine or
after this machine has been configured correctly). also, no acme tls certs will
be requested for disabled domains (the autoconfig/mta-sts dns records may still
point to the current/previous machine). accounts with addresses at disabled
domains can still login, unless logins are disabled for their accounts.

an account now has an option to disable logins. you can specify an error
message to show. this will be shown in smtp, imap and the web interfaces. it
could contain a message about migrations, and possibly a URL to a page with
information about how to migrate. incoming/outgoing email involving accounts
with login disabled are still accepted/delivered as normal (unless the domain
involved in the messages is disabled too). account operations by the admin,
such as importing/exporting messages still works.

in the admin web interface, listings of domains/accounts show if they are disabled.
domains & accounts can be enabled/disabled through the config file, cli
commands and admin web interface.

for issue #175 by RobSlgm
This commit is contained in:
Mechiel Lukkien
2025-01-25 20:39:20 +01:00
parent 132efdd9fb
commit 2d3d726f05
67 changed files with 1078 additions and 231 deletions

View File

@ -765,7 +765,7 @@ func deliverHost(log mlog.Log, resolver dns.Resolver, dialer smtpclient.Dialer,
// Update (overwite) last known starttls/requiretls support for recipient domain.
func updateRecipientDomainTLS(ctx context.Context, log mlog.Log, senderAccount string, rdt store.RecipientDomainTLS) error {
acc, err := store.OpenAccount(log, senderAccount)
acc, err := store.OpenAccount(log, senderAccount, false)
if err != nil {
return fmt.Errorf("open account: %w", err)
}

View File

@ -354,9 +354,9 @@ func deliverDSN(log mlog.Log, m Msg, remoteMTA dsn.NameIP, secodeOpt, errmsg str
// senderAccount should already by postmaster, but doesn't hurt to ensure it.
senderAccount = mox.Conf.Static.Postmaster.Account
}
acc, err := store.OpenAccount(log, senderAccount)
acc, err := store.OpenAccount(log, senderAccount, false)
if err != nil {
acc, err = store.OpenAccount(log, mox.Conf.Static.Postmaster.Account)
acc, err = store.OpenAccount(log, mox.Conf.Static.Postmaster.Account, false)
if err != nil {
qlog("looking up postmaster account after sender account was not found", err)
return

View File

@ -25,7 +25,7 @@ func TestHookIncoming(t *testing.T) {
acc, cleanup := setup(t)
defer cleanup()
accret, err := store.OpenAccount(pkglog, "retired")
accret, err := store.OpenAccount(pkglog, "retired", false)
tcheck(t, err, "open account for retired")
defer func() {
accret.Close()
@ -121,7 +121,7 @@ func TestFromIDIncomingDelivery(t *testing.T) {
acc, cleanup := setup(t)
defer cleanup()
accret, err := store.OpenAccount(pkglog, "retired")
accret, err := store.OpenAccount(pkglog, "retired", false)
tcheck(t, err, "open account for retired")
defer func() {
accret.Close()
@ -129,7 +129,7 @@ func TestFromIDIncomingDelivery(t *testing.T) {
}()
// Account that only gets webhook calls, but no retired webhooks.
acchook, err := store.OpenAccount(pkglog, "hook")
acchook, err := store.OpenAccount(pkglog, "hook", false)
tcheck(t, err, "open account for hook")
defer func() {
acchook.Close()

View File

@ -1391,6 +1391,16 @@ func deliver(log mlog.Log, resolver dns.Resolver, m0 Msg) {
var remoteMTA dsn.NameIP // Zero value, will not be included in DSN. ../rfc/3464:1027
// If domain of sender is currently disabled, fail the delivery attempt.
if domConf, _ := mox.Conf.Domain(m0.SenderDomain.Domain); domConf.Disabled {
failMsgsTx(qlog, xtx, []*Msg{&m0}, m0.DialedIPs, backoff, remoteMTA, fmt.Errorf("domain of sender temporarily disabled"))
err = xtx.Commit()
qlog.Check(err, "commit processing failure to deliver messages")
xtx = nil
kick()
return
}
// Check if recipient is on suppression list. If so, fail delivery.
path := smtp.Path{Localpart: m0.RecipientLocalpart, IPDomain: m0.RecipientDomain}
baseAddr := baseAddress(path).XString(true)

View File

@ -67,7 +67,7 @@ func setup(t *testing.T) (*store.Account, func()) {
tcheck(t, err, "mtastsdb init")
err = tlsrptdb.Init()
tcheck(t, err, "tlsrptdb init")
acc, err := store.OpenAccount(log, "mjl")
acc, err := store.OpenAccount(log, "mjl", false)
tcheck(t, err, "open account")
err = acc.SetPassword(log, "testtest")
tcheck(t, err, "set password")