-
Notifications
You must be signed in to change notification settings - Fork 37.7k
RPC: Allow rpcauth configs to specify a 4th parameter naming a specific wallet #10615
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK b77b2f254cc365728790f345deedbed1204964bb.
Needs updated documentation, also would be good to have python tests.
Tested with:
bitcoind -regtest -wallet=w1.dat -wallet=w2.dat -debug=1
bitcoin-cli -regtest -rpcuser=user1 -rpcpassword=V6CGvawtTWCHzt51knRvFfTejjjfy06UzSt_FiB3Fxw= getwalletinfo
bitcoin-cli -regtest -rpcuser=user2 -rpcpassword=V6CGvawtTWCHzt51knRvFfTejjjfy06UzSt_FiB3Fxw= getwalletinfo
bitcoin-cli -regtest -rpcuser=user3 -rpcpassword=V6CGvawtTWCHzt51knRvFfTejjjfy06UzSt_FiB3Fxw= getwalletinfo
And $HOME/.bitcoin/bitcoin.conf
:
rpcauth=user1:51902a7be9c9911079af388a927f$22904ad1bfec659ee1e61d1b3dd73f7b552c6d2d0d1e9f71f6ee833954d062da:w1.dat
rpcauth=user2:51902a7be9c9911079af388a927f$22904ad1bfec659ee1e61d1b3dd73f7b552c6d2d0d1e9f71f6ee833954d062da:w2.dat
rpcauth=user3:51902a7be9c9911079af388a927f$22904ad1bfec659ee1e61d1b3dd73f7b552c6d2d0d1e9f71f6ee833954d062da:-
src/rpc/server.h
Outdated
#endif | ||
|
||
JSONRPCRequest() : id(NullUniValue), params(NullUniValue), fHelp(false) | ||
#ifdef ENABLE_WALLET |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "RPC: Pass wallet through JSONRPCRequest"
Could drop this ifdef also.
src/httprpc.cpp
Outdated
@@ -119,14 +122,17 @@ static bool multiUserAuthorized(std::string strUserPass) | |||
std::string strHashFromPass = HexStr(hexvec); | |||
|
|||
if (TimingResistantEqual(strHashFromPass, strHash)) { | |||
if (vFields.size() > 3) { | |||
walletNameOut = vFields[3]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "RPC: Allow rpcauth configs to specify..."
Should update -rpcauth
documentation to mention the new field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add a test for the new parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a lot of objection at last IRC meeting (https://botbot.me/freenode/bitcoin-core-dev/msg/87311878/) to choosing wallet based on RPC username & password, mostly for security reasons ("securing RPC for multiple users is absolutely a nightmare").
Personally, I don't like the choosing wallet based on username because I think it makes for a clumsy UI. Adding support for a simple -wallet=
option to bitcoin-cli
and working with regular cookie authentication just seems a lot more user-friendly than having to deal with -rpcauth
, the share/rpcuser
script, and all of that.
ACKing this PR though because it makes multiwallet usable, and the implementation is pretty clean. If we don't want to use rpcauth for wallet security, we could allow all users to access all wallets and just interpret the new rpcauth wallet option as the default wallet for the user.
src/httprpc.cpp
Outdated
@@ -119,14 +122,17 @@ static bool multiUserAuthorized(std::string strUserPass) | |||
std::string strHashFromPass = HexStr(hexvec); | |||
|
|||
if (TimingResistantEqual(strHashFromPass, strHash)) { | |||
if (vFields.size() > 3) { | |||
walletNameOut = vFields[3]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "RPC: Allow rpcauth configs to specify..."
I think instead of interpreting the 4th rpcauth field as a wallet filename field, it might be better to treat it as a generic options field (similar to the field in fstab
files for mount options). E.g. instead of:
rpcauth=user:salt:hash:filename.dat
You would write:
rpcauth=user:salt:hash:wallet=filename.dat
This would be more extensible, also more readable.
Multi-user for multiwallet is definitely a very useful feature and one that we should be aiming for long-term, so this is good to see. I think the implementation some more work before its ready:
So, definite concept ACK that we should do this, but I think it should be sequenced after wallet separation. That would make the implementation a lot cleaner and make it easier to provide an implementation that is secure and safe for users. |
src/httprpc.cpp
Outdated
@@ -119,14 +122,17 @@ static bool multiUserAuthorized(std::string strUserPass) | |||
std::string strHashFromPass = HexStr(hexvec); | |||
|
|||
if (TimingResistantEqual(strHashFromPass, strHash)) { | |||
if (vFields.size() > 3) { | |||
walletNameOut = vFields[3]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add a test for the new parameter?
src/httprpc.cpp
Outdated
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
static bool RPCAuthorized(const std::string& strAuth, std::string& strAuthUsernameOut) | ||
static bool RPCAuthorized(const std::string& strAuth, std::string& strAuthUsernameOut, std::string& walletNameOut) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wallet_name
?
src/httprpc.cpp
Outdated
@@ -162,7 +168,8 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &) | |||
} | |||
|
|||
JSONRPCRequest jreq; | |||
if (!RPCAuthorized(authHeader.second, jreq.authUser)) { | |||
std::string walletName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wallet_name
.
94ecb7a
to
6a20988
Compare
6a20988
to
370d336
Compare
eef48ee
to
43b92a9
Compare
Rebased |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
Concept ACK. I still have a few concerns about RPC security and the level of coupling between RPC users and wallets. I think the first thing to do is add release notes explaining the exact model, and update the PR description to match. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC this limits one wallet per user (auth)?
This is incomplete now that there's dynamic support for wallets:
- there should be a way to dynamically update access credentials?
- rpcauth.py should be updated?
- probably there's issues with external wallets (paths) and other characters?
- already mentioned, needs tests.
Alternatively it could whitelist RPC categories (not wallets) by user/auth: For instance:
rpcauth=promag:ec94a02...$07e90e0...:blockchain,rawtransactions
Needs rebase |
This seems to have been inactive for a long time, and it was controversial in the first place, closing. |
Simple rebase of current RPC stuff. No endpoints yet.