RPC: Request rate limiting based on size/process time budget (hardening pt.3) - #685
Open
SyntheticBird45 wants to merge 3 commits into
Open
RPC: Request rate limiting based on size/process time budget (hardening pt.3)#685SyntheticBird45 wants to merge 3 commits into
SyntheticBird45 wants to merge 3 commits into
Conversation
This commit adds a new struct called RpcServer that is used to accept new TCP connections and serving them through hyper and axum. This replaces axum::serve. A new async IO timeout wrapper called StreamTimeout is added to each new connections. The read_timeout and send_timeout configuration keys are used to set the duration for which, if elapsed, the client is disconnected if no bytes has been received or sent respectively.
Add a per-IP connection limit layer to the RPC servers. Every type (public, private or loopback) of IP addresses have a configurable maximum amount of simultaneous connection. The node also have a configurable total maximum amount of simultaneous connections. Whenever one limit is exceeded, the connection is dropped. Add a short-ban mechanism against IP addresses which fails to be served more than 15 times. This is a protection against malicious clients spamming garbage instead of parseable HTTP requests.
…Axum Adds a new ratelimit.rs file containing an Axum middleware for rate limiting requests based on a response size and processing time budget. Clients that have exceeded either of these two budgets are not served and are responded with a `429 Too many requests` error response. The budget is refilled with an income. Both the maximum budgets and incomes are configurable. This commit also modifies RpcCacheLimit::remove_connection to return a boolean indicating whether the last connection for this IP has been terminated. This is used to start an eviction task that will delete the IP entry from the rate limiting state after a period of time (or be cancelled if the IP reconnected in the mean time). Assisted-by: Boog900 <boog900@tutanota.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
This PR follows and is based upon #684
It adds a new Axum middleware for rate limiting requests based on a processing time and response size budget. Each clients (IP address) is allocated a configurable process time budget and response size budget. These budgets are substracted when response is processed. Whenever the budget is below zero the clients is greeted with a
429 Too many requestserror. Budgets are refilled following an income variable.The reasoning behind this system is limiting clients from using resource heavy requests, while permitting the quick use of cheap requests.
Original idea from @Boog900