Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPC Whitelist #202

Merged
merged 4 commits into from
Jul 28, 2020
Merged

RPC Whitelist #202

merged 4 commits into from
Jul 28, 2020

Conversation

nixbitcoin
Copy link
Member

This PR changes bitcoind rpc authentication to the rpcauth feature with HMAC-SHA-256 hashed passwords. It implements an rpcwhitelist of harmless rpc calls for services with rpc access (clightning, lnd, liquidd, and electrs).

Right now, I transfer the HMAC's from the /secrets directory by replacing a placeholder inside bitcoin.conf via sed in the systemd.services.bitcoind.preStart. I'm not sure if this is the optimal solution.

Closes #191
Closes #183

Copy link

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that if this is used for NBXplorer it will break PayJoin in BTCPayServer, so I'd recommend documenting it.

See MetacoSA/NBitcoin#864 for details.

"estimatefee"
"estimatepriority"
"estimatesmartfee"
"estimatesmartpriority"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few more harmless calls to consider:

  • validateaddress
  • testmempoolaccept
  • signrawtransactionwithkey - the key is provided in the call, so stealing is not possible
  • scantxoutset - I assume this operation takes some time, so maybe it could be used for DoS, but probably not too huge issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorporated these harmless calls in 88c7348. Thank you for the suggestions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

estimatepriority and estimatesmartpriority were removed in 0.15.

@nixbitcoin
Copy link
Member Author

Rebased

@nixbitcoin
Copy link
Member Author

Rebased, expanded tests, removed deprecated rpc calls

@Kixunil
Copy link

Kixunil commented Jul 28, 2020

FYI, I found yesterday that NBXplorer/BTCPayServer don't work without getpeerifo on regtest.

If you have regtest packages, then you may want to special-case this.

@@ -1,6 +1,9 @@
{ pkgs }: with pkgs;

let
rpcauth = pkgs.callPackage ./rpcauth { };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can replace this with:

  rpcauth = pkgs.writeScriptBin "rpcauth" (builtins.readFile ./rpcauth/rpcauth.py);

(mind the indentation) and remove rpcauth/default.nix

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fb94d19

@@ -266,7 +267,9 @@ in {
readOnly = true;
type = types.package;
default = pkgs.writeScriptBin "bitcoin-cli" ''
exec ${cfg.package}/bin/bitcoin-cli -datadir='${cfg.dataDir}' "$@"
exec ${cfg.package}/bin/bitcoin-cli \
-rpcuser=${cfg.rpc.users.privileged.name} -rpcpassword=$(cat ${secretsDir}/bitcoin-rpcpassword-privileged) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps better to leave the rpcuser and rpcpassword in the bitcoin.conf so we don't have to specify them here

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-rpcpassword being entered from command line is actually insecure. bitcoin-cli has an option -stdinrpcpass to solve this problem - just read it from that file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fb94d19
I think it's even better to use the config file than -stdinrpcpass

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, this is just defense in depth since we already forbid users from viewing other's commands with hidepid

@jonasnick
Copy link
Member

Here's an exhaustive list of the RPCs I'd consider "public" from bitcoin 0.21.0:

# Blockchain
"getbestblockhash"
"getblock"
"getblockchaininfo"
"getblockcount"
"getblockfilter"
"getblockhash"
"getblockheader"
"getblockstats"
"getchaintips"
"getchaintxstats"
"getdifficulty"
"getmempoolancestors"
"getmempooldescendants"
"getmempoolentry"
"getmempoolinfo"
"getrawmempool"
"gettxout"
"gettxoutproof"
"gettxoutsetinfo"
"scantxoutset"
"verifytxoutproof"
# Mining
"getblocktemplate"
"getmininginfo"
"getnetworkhashps"
# Network
"getnetworkinfo"
# Rawtransactions
"analyzepsbt"
"combinepsbt"
"combinerawtransaction"
"converttopsbt"
"createpsbt"
"createrawtransaction"
"decodepsbt"
"decoderawtransaction"
"decodescript"
"finalizepsbt"
"fundrawtransaction"
"getrawtransaction"
"joinpsbts"
"sendrawtransaction"
"signrawtransactionwithkey"
"testmempoolaccept"
"utxoupdatepsbt"
# Util
"createmultisig"
"deriveaddresses"
"estimatesmartfee"
"getdescriptorinfo"
"signmessagewithprivkey"
"validateaddress"
"verifymessage"
# Zmq
"getzmqnotifications"

Every time we update bitcoind we can check for new public RPCs and add them to the list.

@nixbitcoin
Copy link
Member Author

Rebased, fix nits, and Jonas Nick public rpc call list implemented

@nixbitcoin
Copy link
Member Author

@Kixunil We're taking note of all the NBXplorer issues here and will get to them when we merge BTCPayserver

Includes bitcoind's `share/rpcauth` to convert apg generated passwords
into salted HMAC-SHA-256 hashed passwords.
Default behavior for rpc whitelisting is set to 0, which means that
rpcwhitelisting is only enforced for rpc users for whom an `rpcwhitelist`
exists.
Copy link
Member

@jonasnick jonasnick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 5086fc3

@jonasnick jonasnick merged commit 9e453ba into fort-nix:master Jul 28, 2020
@nixbitcoin nixbitcoin deleted the rpcwhitelist branch March 3, 2021 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bitcoind RPC whitelist bitcoind should use RPC cookie auth not user/password
3 participants