Repository navigation
feat(rspamd): add opt-in user rate limit - #358
Conversation
A stolen password is often used to send large amounts of spam through the mail server. Limit how many messages each authenticated user can send per hour. Messages over the limit get a temporary error: mail servers and applications retry them later, mail clients show the error. The limit is off unless RSPAMD_RL_HOURLY is a positive number. Users listed in ratelimit_bulk.map get the RSPAMD_RL_BULK_HOURLY limit; users in ratelimit_exempt.map are never limited. Refused messages are tagged with RATELIMIT_EXCEEDED for logs and metrics. Assisted-by: Claude Code:Opus 5.5
stephdl
left a comment
There was a problem hiding this comment.
Tested on a real cluster with RSPAMD_RL_HOURLY=12 and SMTP AUTH on 587. The 451 comes as expected, a message counts once whatever the number of recipients, and the exempt and bulk maps work, also with mixed case. Looks good to me.
Could we add a robot test in tests/50__smtp? It must send through SMTP, not rspamc. Rspamd skips the rate limit for rspamc requests, so such a test would never hit the limit.
| message in the outbox. Messages refused by the limit do not count. A | ||
| message counts once, regardless of the number of recipients. | ||
|
|
||
| The following map files list one user name per line. They are available |
There was a problem hiding this comment.
These maps show up in the Rspamd UI only when RSPAMD_RL_HOURLY is set. Otherwise the multimap rule and ratelimit.conf are not rendered. Should we say it here? An admin could try to fill the exempt list before enabling the limit.
There was a problem hiding this comment.
Good point, done in afbe07a: the README now says the maps show up in the Rspamd UI only once the rate limit is enabled, and explains how to fill them before, by editing the files inside the rspamd container.
The rate limit maps are loaded, and shown in the Rspamd UI, only when the rate limit is enabled. Explain how to fill them before enabling it. Assisted-by: Claude Code:Opus 5.5
Send messages through SMTP with authentication, because Rspamd skips the rate limit for rspamc requests. Check the burst limit of a default user, the bulk and exempt user lists, unauthenticated messages, and that removing the variable disables the limit. Assisted-by: Claude Code:Opus 5.5
|
Thanks @stephdl for testing it! I added the robot test in 0c2af90:
I ran the install, rate limit and uninstall suites on a test cluster with the branch image: all passed. |
A stolen password is often used to send thousands of spam messages through the mail server before anyone notices, and the antispam filter does not stop them because they look legitimate. This PR adds an optional limit on how many messages each authenticated user can send per hour. NethServer/dev#8381
The feature is off by default: existing installations do not change behavior. When enabled, messages over the limit get a temporary error (
451 Sending rate limit exceeded, try again later): mail servers and applications sending through an authenticated account retry later, mail clients show the error. Mail received from other servers and clients in Postfixmynetworksare not limited.state/rspamd.env:RSPAMD_RL_HOURLY(messages per hour, burst of 5 minutes of messages) andRSPAMD_RL_BULK_HOURLY(users that legitimately send more, default 10 times the base limit)/var/lib/rspamd/ratelimit_bulk.mapandratelimit_exempt.map, editable from the Rspamd UI and reloaded without restartRATELIMIT_EXCEEDEDsymbol, for logs and a future ns8-metrics alertHow to test
RSPAMD_RL_HOURLY=300tostate/rspamd.envand runsystemctl --user reload rspamd451error/var/lib/rspamd/ratelimit_exempt.map, wait a minute: all messages are accepted againratelimit_bulk.mapandRSPAMD_RL_BULK_HOURLYset to a low valueRSPAMD_RL_HOURLYand reload: no limit appliesGenerated by Claude Code:claude-opus-5-5 with nethserver-pr