AleoNet / snarkOS

A Decentralized Operating System for ZK Applications
http://snarkos.org
Apache License 2.0
4.32k stars 2.62k forks source link

[Feature] RPC rate limiter #1597

Open howardwu opened 2 years ago

howardwu commented 2 years ago

🚀 Feature

  1. Add controls that allow snarkOS to adjust 2 rates: a. The rate that RPC requests from all IP addresses are processed b. The rate that RPC requests from a single IP address is processed

  2. Add a "restricted_peers" list for RPC IP addresses that exceed the rate.

Motivation

Some IP addresses are spamming the sync node RPC endpoints.

ljedrz commented 2 years ago

Note: jsonrpsee just declared that it's more or less stable a few days ago; I'll check it out, it might be the time to close https://github.com/AleoHQ/snarkOS/issues/754 as well.

ljedrz commented 2 years ago

Oh, and just so that no one else tackles it in parallel, I'm already working on this.

howardwu commented 2 years ago

What's the status on this?

ljedrz commented 2 years ago

Let's consider the the things we've used the RPC server for so far:

And some of the related issues we've encountered:

Having all the above in mind, I'd like to propose to start shifting towards dedicating the RPC server to local/restricted use; this means:

This proposal would completely resolve any concerns related to malicious RPC use; even if we used per-IP bans, a well-organized malicious actor could still set up a lot of RPC clients that would individually send requests at a rate right above the one we permit.

Cc https://github.com/AleoHQ/snarkOS/issues/1381

ljedrz commented 2 years ago

One extra point for limiting RPC access as a policy: if we add private endpoints again, we would need to have a way of securely inputting and transmitting passwords in the headers, otherwise they'd be visible in command line history and transmitted in plaintext, which is very insecure.

Cc https://github.com/AleoHQ/snarkOS/issues/1583