Difference between revisions of "Rate limiting"

From Halon, SMTP software for hosting providers
Jump to: navigation, search
m
m
Line 7: Line 7:
 
== Implementation ==
 
== Implementation ==
 
Rate limits may be "hit" using the [[HSL]]
 
Rate limits may be "hit" using the [[HSL]]
[[HSL_core_functions#rate|rate]]() function. It returns true as long as
+
[[HSL_core_functions#rate|rate]]() function, and sometimes using the graphical blocks in the flows. It returns true as long as
the rate() call interval is less than it's rate limit. And false when
+
the <tt>rate()</tt> call interval is less than its rate limit, but false when
 
exceeded. If the <tt>count</tt> parameter is zero, the current rate is
 
exceeded. If the <tt>count</tt> parameter is zero, the current rate is
 
returned instead.
 
returned instead.
  
 
<hsl>
 
<hsl>
if (rate("failed-login:saslusername", $saslusername, 0, 60) >= 3) {
+
// get the rate limit number, without increasing
     Reject("Too many login attempts, please try later (rate limit)");
+
if (rate("failed-login:saslusername", $saslusername, 0, 60) >= 3)
}
+
     Reject("Too many failed logins");
  
// test login
+
// increase, and reject if exceeded
 
+
if (rate("failed-login:saslusername", $saslusername, 3, 60) == false)
rate("failed-login:saslusername", $saslusername, 3, 60);
+
  Reject("Too many failed logins");
Reject();
 
 
</hsl>
 
</hsl>
  
 
== Clustering ==
 
== Clustering ==
Rate limits may be synchronized in the cluster and will be done so if a
+
Rate limits are synchronized in the cluster if a
 
HMAC-SHA1 key is specified on the system settings page. The protocol is
 
HMAC-SHA1 key is specified on the system settings page. The protocol is
 
based on UDP and uses port 13131. In terms of security it may be wise to
 
based on UDP and uses port 13131. In terms of security it may be wise to
only activate this feature on LAN as the HMAC-SHA1 only serves as a
+
only activate this feature on local networks, as the HMAC-SHA1 only serves as a
packet-authenticity firewall. And does not protect against reply-attacks
+
packet-authenticity firewall. It does not provide encryption nor protect against reply attacks. It
nor that the fact that the protocol sent its rate hits in plain-text. It
+
should probably be protected by other means such as a VPN tunnel or psychical
may be protected by other means such as a VPN tunnel or psychical
 
 
security (DMZ).
 
security (DMZ).
  
 
== Performance ==
 
== Performance ==
The rate limits performance is roughly O(log N + log M) and lookups are currently implemented as a std::multimap (c++).
+
The rate limits performance is roughly O(log N + log M) and lookups are currently implemented as a std::multi map (C++).

Revision as of 10:55, 31 October 2013

Rate limiting is a crucial defense method against service misuse. We have implemented a global rate controlling service called rated. It handles rate limiting for all processes, based on an "items per time interval" algorithm. Our implementation features a sliding rate limit (in contrast to leaking bucket; which has a fixed output rate regardless of exactly when the rate was exceeded).

Implementation

Rate limits may be "hit" using the HSL rate() function, and sometimes using the graphical blocks in the flows. It returns true as long as the rate() call interval is less than its rate limit, but false when exceeded. If the count parameter is zero, the current rate is returned instead.

// get the rate limit number, without increasing
if (rate("failed-login:saslusername"$saslusername060) >= 3)
    
Reject("Too many failed logins");

// increase, and reject if exceeded
if (rate("failed-login:saslusername"$saslusername360) == false)
  
Reject("Too many failed logins"); 

Clustering

Rate limits are synchronized in the cluster if a HMAC-SHA1 key is specified on the system settings page. The protocol is based on UDP and uses port 13131. In terms of security it may be wise to only activate this feature on local networks, as the HMAC-SHA1 only serves as a packet-authenticity firewall. It does not provide encryption nor protect against reply attacks. It should probably be protected by other means such as a VPN tunnel or psychical security (DMZ).

Performance

The rate limits performance is roughly O(log N + log M) and lookups are currently implemented as a std::multi map (C++).