Open
Description
Some RPC commands should only be available to admins (for example submit_block
).
It would be nice to simply add something to an RPC interface to protect such methods:
#[rpc::rpc(server, client, namespace = "chainstate")]
trait ChainstateRpc {
/// Submit a block to be included in the chain
#[method(name = "submit_block", "admin_only")]
async fn submit_block(&self, block_hex: String) -> rpc::Result<()>;
It looks like jsonrpsee
does not support this. It should be possible to check credentials and method name using middleware (parsing request body). But it's ugly and won't work with WebSocket transport.
For reference, Bitcoin Core supports filtering RPC commands with rpcwhitelist
:
-rpcwhitelist=<whitelist>
Set a whitelist to filter incoming RPC calls for a specific user. The
field <whitelist> comes in the format: <USERNAME>:<rpc 1>,<rpc
2>,...,<rpc n>. If multiple whitelists are set for a given user,
they are set-intersected. See -rpcwhitelistdefault documentation
for information on default whitelist behavior.
The problem was originally reported by @TheQuantumPhysicist