Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Simple Postfix token-bucket rate-limiter

License

NotificationsYou must be signed in to change notification settings

rkojedzinszky/postfix-ratelimiter

Repository files navigation

A simple policy daemon which rate-limits sending mails based on sasl_username. Recipient count is rate-limited.

Quick deployment in Kubernetes

Check outexamples.

Postfix configuration

A sample postfix configuration might look like:

smtpd_data_restrictions = ...    check_policy_service { inet:postfix-ratelimiter:10028, { default_action=dunno } },    permit

Legacy/standalone usage

$ ./postfix-ratelimiter -hUsage of ./postfix-ratelimiter:  -dbdriver="": Databasetypefor dynamic rate/burst lookups (mysql or postgresql)  -dbdsn="": Database DSNfor dynamic rate/burst lookup  -default-burst=60: Default burstfor policing  -default-rate=1: Default ratefor policing (recipient/seconds)  -policy-listen-address=":10028": Postfix Policy listen address  -querystring="": SQL Query returning dynamic (rate, burst) settingsfor a (local_part, domain) lookup  -web-listen-address=":9026": Exporter WEB listen address

The policy daemon will create a token-bucket rate-limiter for each sasl authenticated user. Rate-limits against unauthenticated mails are not enforced. The token-buckets will havedefault-rate rate anddefault-burst burst settings.

By default the daemon listens on:10028 for policy requests.

Statistics

Rejected recipient count is export in Prometheus format:

$ curl -s http://127.0.0.1:9026/metrics| grep postfix_ratelimiter_rejects# HELP postfix_ratelimiter_rejects Rejected recipient count# TYPE postfix_ratelimiter_rejects counterpostfix_ratelimiter_rejects{sasl_username="user@doma.in"} 8

Dynamic rate/burst

You can specify a database to look up rate/burst settings dynamically.

For this, you'll have to specify-dbdriver (mysql or postgres), the DSN the driver uses (mysql orpostgres), and the-querystring which must return one row with two columns:(rate, burst). The querystring is prepared, and during lookup,(local_part, domain) is passed as an argument.

Null returned for any of the columns is treated asInfinity.

Example with postgresql, minimal schema:

createtablerate_limits (    local_partvarchar(128),    domainvarchar(128),    rate float,    burst float,primary key (local_part, domain));
$ ./postfix-ratelimiter -dbdriver=postgres -dbdsn"postgres://localhost?sslmode=disable" -querystring='select rate, burst from rate_limits where local_part = $1 and domain = $2'

Containerized deployment

Configuration arguments are parsed usingflag, so they can be specified using capitalized environment variables too. For example, you can start the app as:

$ docker run -d --restart=always -p 10028:10028 -e DEFAULT_RATE=2 -e DEFAULT_BURST=100 ghcr.io/rkojedzinszky/postfix-ratelimiter

About

Simple Postfix token-bucket rate-limiter

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

[8]ページ先頭

©2009-2025 Movatter.jp