ADR-025: A Deployment-Wide Budget for Sign-In Mail¶
Status: Accepted Deciders: @grokify Relates to: ADR-003 (verified email via omnimail), ADR-023 (email code sign-in)
Context¶
Email code sign-in (ADR-023) lets anyone who can reach the sign-in page make SystemAuth send mail. The per-address and per-client limits bound what one address or one client can cause, but not what many clients together can: a botnet that spreads its requests across addresses and client addresses stays under both limits and still sends without bound.
Mail is not free to send without bound. Providers cap volume (a daily or monthly quota, or a sending rate) and judge a domain by its bounces and complaints. Mail sent to addresses nobody asked for spends the quota that real sign-ins need and damages the sending domain's reputation, which harms every message the deployment sends, not only sign-in codes.
When that happens the operator should hear about it at once and decide what to do, rather than find out from people who stopped receiving codes.
Decision¶
- A budget for sign-in mail across the deployment.
mail.sign_in_budgetsets how many sign-in messages SystemAuth sends per hour and per day, across all addresses and clients:
mail:
sign_in_budget:
per_hour: 20
per_day: 40
alert:
email: [[email protected]]
webhook_url: ${SYSTEMAUTH_ALERT_WEBHOOK_URL}
Sign-in mail is what a person who is not signed in can cause: email sign-in codes, and the links that verify an unverified provider email during a social sign-in. Mail to signed-in people (the email change confirmation and notice) is not counted, and neither is mail an application sends through its own sender. A message counts only when the per-address and per-client limits have let it through. Without the section there is no budget, as before.
-
Using up the budget halts sign-in mail until the operator clears it. The send that would exceed either window is not sent, and SystemAuth records a halt in the database: which window ran out, its count and when. While the halt stands:
-
the sign-in page leaves out the email method, and its pages answer 503 with a page that offers the other methods;
- discovery leaves
emailout ofsf_sign_in_methods_supported; - a social sign-in that needs its email verified by mail is refused with the same explanation;
- everything else works: social sign-in with a verified email, existing sessions, and mail that is not sign-in mail.
The halt does not lift when the window rolls over. Abuse that used up one
window will use up the next, so the operator lifts it after looking,
with systemauth mail halt clear --by <name> (an embedding application
mounts the same commands from identity/systemauth/mailcmd). Clearing
records who cleared it and when, and keeps the halt's record; each
replica resets the budget's counts when it sees the halt cleared.
systemauth mail halt status shows the standing halt and recent ones. A
halt survives restarts; each replica reads it from the database, caching
it for at most 30 seconds.
-
A halt alerts the operator once. Recording the halt is an insert that only one replica wins; the winner sends the alert:
-
Email to each
alert.emailaddress, through the deployment's mail sender and outside the budget. It is a single message per halt, so it cannot be used to send more. - Webhook: a notice posted to
alert.webhook_urlthrough omnichat'snotifypackage, which picks Slack's or Discord's incoming webhook form by the URL's host (and a generic JSON form for any other host), so moving the alert between services changes only the URL. The URL is a secret: it lives in the environment, never in the file. - Security event
systemauth.mail.halted, andsystemauth.mail.resumedwhen cleared, through the security event log and OCSF emitter. - Go hook
WithMailHaltHandler, for an embedding application that alerts another way.
An alert names the window, its limit, the time, and the command
that clears the halt. It never holds an address or a code. A failed
delivery is logged as an error and does not lift the halt. With neither
alert.email nor alert.webhook_url set, configuration validation fails:
a halt nobody hears about only looks like an outage.
- Counts live in the rate limit storage; the halt lives in the database.
The windows use the same storage as the other limits, so replicas share
them when they share that storage. With in-memory storage a restart resets
the counts, which can let one more window's worth through; a recorded halt
is never lost. If recording a halt fails, the instance stays halted on its
own, alerts once, and retries until the halt is recorded; a restart before
then forgets it. Halts are a new table,
sf_mail_halts, created by the schema migration; a partial unique index allows one standing halt per scope.
Consequences¶
- An attack on email sign-in stops at a window's budget instead of draining the provider's quota. It is not a strict cap over any 24 hours: across a window boundary up to twice the daily budget can go out, and a restart with in-memory counts adds more.
- Anyone who can use up the budget can turn email sign-in off until an
operator clears the halt.
per_clientshould be well belowper_hour, so that takes several client addresses. - While halted, people without a social account cannot sign in or sign up. That is the trade: a deliberate, visible outage of one method instead of a silent one of all mail.
- A busy deployment must set the budget above its real peak. The security
event log's
systemauth.email_code.sentevents show the real volume. - Operators need an alert destination before they can turn the budget on.
Alternatives considered¶
- Lift the halt when the window rolls over. Needs no operator, but abuse resumes on schedule and the operator may never look.
- Keep sending and only alert. The quota is spent before anyone reads the alert.
- A CAPTCHA before sending. Raises the cost of each request but needs a third-party service and does not bound the total; it may be added later alongside the budget.
- One budget for all mail. Would stop the mail of signed-in people, and later application notifications, because of anonymous abuse.