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

Implement simple password-based gRPC authentication #4189

Merged
merged 40 commits into from
Apr 29, 2020

Conversation

ghubstan
Copy link
Member

@ghubstan ghubstan commented Apr 22, 2020

A 2nd attempt at gRPC authentication after finding out in #4129 that TLS + Macaroons is too much overhead for :cli our purposes at this point (edit: @cbeams). Most of the changes not related to refactoring :cli are listed below.

  • Renamed CliCommand to RpcCommand, differentiating it from cmd
    string token(s)

  • Added new CliConfig, based on :common Config

  • Injected Config into CoreApi to make bisq.properties and cmd line
    args available to server

  • Added cleartext username:password BisqCallCredentials to :cli, and
    an AuthenticationInterceptor to :core (server)

  • Moved :daemon resources folder to expected location under src/main

  • Duplicated CompositeOptionSet, ConfigException and BisqException
    in :cli because they are not visible from :common. (TODO refactor?)
    CompositeOptionSet will be used to let command line parameters
    override params set in config file.

  • Removed outdated references to :cli in a couple of comments in
    :common Config

  • gRPC parameters & command names are lowercase to mimic bitcoind/rpc

TODO: Decide what rpc auth param names to use, to differentiate them from bitcoind rpc user/password param names. Until that decision is made, the existing bitcoind rpcUser/rpcPassword param names are used for gRPC authentication. As you know, you can define rpcUser/rpcPassword creds in bisq.properties and/or pass rpc login creds on command line:

./bisq-daemon --rpcUser=somebody --rpcPassword=password  getversion

 * Renamed CliCommand to RpcCommand, differentiating it from cmd
   string token(s)

 * Added new CliConfig, based on :common Config

 * Injected Config into CoreApi to make bisq.properties and cmd line
   args available to server

 * Added cleartext username:password BisqCallCredentials to :cli, and
   an AuthenticationInterceptor to :core (server)

 * Moved :daemon resources folder to expected location under src/main

 * Duplicated CompositeOptionSet, ConfigException and BisqException
   in :cli because they are not visible from :common.  (TODO refactor?)
   CompositeOptionSet will be used to let command line parameters
   override params set in config file.

 * Removed outdated references to :cli in a couple of comments in
   :common Config

 * gRPC parameters & command names are lowercase to mimic bitcoind/rpc

TBD

 * Decide what rpc auth param names to use, to differentiate them from
   bitcoind rpc user/passord param names
@ghubstan
Copy link
Member Author

TODO change rpcuser/rpcpassword params to grpcuser/grpcpassword, as per the request made by @cbeams to me in keybase

There is no need or benefit to injecting Config into CoreApi for the
purpose of accessing it indirectly through BisqGrpcServer.
Final fields should be favored wherever possible to advertise and
enforce immutability. Also as a matter of style, favor declaring fields
one per line instead of multiple on the same line. This style guideline
is not consistent throughout the codebase, but is favored because it
makes diffs / patches cleaner and is the more widely accepted style
througout most modern Java codebases.
@cbeams
Copy link
Member

cbeams commented Apr 23, 2020

Thanks, @ghubstan. Please hold off on further changes for the moment, I have a number of review commits incoming.

There is actually no use case for both username and password forming the
authentication token. This change simplifies the arrangement such that a
single token is passed.

--rpcUser and --rpcPassword are no longer used and are replaced by
--apiToken on both cli and daemon sides.
@cbeams
Copy link
Member

cbeams commented Apr 23, 2020

@ghubstan, you'll need to check the 'allow edits from maintainers' checkbox on this PR. Until then, I'm unable to push my review commits. See https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork. Thanks.

@ghubstan
Copy link
Member Author

ghubstan commented Apr 23, 2020

you'll need to check the 'allow edits from maintainers' checkbox on this PR. Until then, I'm unable to push my review commits.

@cbeams, 'allow edits from maintainers' was checked when I logged in a few minutes ago:
allow-edits

I wonder if the problem (or bug) has anything to do with this PR being created as a draft. I think the last time you pushed commits to one of my PRs, it had not yet been changed to a draft.

@ghubstan ghubstan marked this pull request as ready for review April 23, 2020 15:04
@ghubstan
Copy link
Member Author

@cbeams , I clicked "ready for review" to temporarily change this from a draft to a normal pull request to see if that will allow you to push changes.

@cbeams
Copy link
Member

cbeams commented Apr 23, 2020

@ghubstan the inability to push was an issue on my side with my local .git/hooks. I've solved it for the time being and pushed up my current set of commits. You'll see the last few are still in a WIP state, so please don't build anything on top of this just yet.

It's worth looking through each of the commits, in some of them I've explained exactly why changes were made.

Overall, though, the idea is to radically simplify things. One of the main purposes of the cli is to serve as a reference client for working with Bisq's rpc api, and as such it should be dead simple to understand. It's probably a bit too simple now, I would do some additional refactoring to reduce certain redundant code, but I wouldn't go very far here. The implementation will certainly need to get more sophisticated as we go implementing all the endpoints, but we can do that on an as-needed basis.

Hope this helps / makes sense. Let me know if you have questions / feedback. It might be a little bit before I get back to this, Monday possibly.

By the way, here's how you can invoke bisq-cli now:

./bisq-cli -auth=mytoken getversion

Where mytoken was provided on the bisqd side as:

./bisq-daemon --apiToken=mytoken

The apiToken naming will change further, it's still WIP, but as you can see, rpcuser / rpcpassword are out of the picture now (and can return to their existing use for talking to bitcoind).

@cbeams
Copy link
Member

cbeams commented Apr 23, 2020

And you can / should change this PR back to a draft now. Thanks.

@ghubstan ghubstan marked this pull request as draft April 23, 2020 17:08
@ghubstan
Copy link
Member Author

@cbeams, Thanks for the feedback, notes on style conventions and new commits. Glad this work can gain some momentum now... The only remark I have is that the reason I broke main into RpcCommand, CliConfig & CommandParser was to avoid the main class from getting very large (a personal itch), but of course I want to follow the conventions.

cbeams and others added 7 commits April 26, 2020 19:38
No StatusRuntimeException can be thrown from this code, so it is not
necessary to include in the try block.
Co-authored-by: ghubstan <36207203+ghubstan@users.noreply.github.com>
 - Ensure script runs from root directory regardless of where it is
   invoked from

 - Touch up documentation and whitespace
Don't instruct the user to create a fresh data directory every time, as
this takes quite a bit longer to initialize the wallet than running
against the same data directory repeatedly. Just be clear that the
requirement is an unencrypted wallet with 0 BTC balance.
@cbeams
Copy link
Member

cbeams commented Apr 26, 2020

@ghubstan, you'll see I've added a number of additional commits, including adding your expect-based test suite. Please give everything a look and give a thumbs-up from your side and we'll get this committed. It's an ACK from my side.

cbeams
cbeams previously approved these changes Apr 26, 2020
Stop attempting to align Option and Method description columns with one
another. It's a moving target as we add options and method names, and
this help output format will probably change in the future anyway.
This is a partial reversion of the earlier commit. Marking the password
option as required at the parser level made it impossible to run
./bisq-cli without options or arguments and get the help text. This is a
useful thing to do, and not worth creating a bad user experience to get
the free required option error handling and error messaging.
Copy link
Member

@cbeams cbeams left a comment

Choose a reason for hiding this comment

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

ACK (again) from my side after a couple additional commits.

cbeams
cbeams previously approved these changes Apr 26, 2020
@ghubstan
Copy link
Member Author

ACK

cbeams
cbeams previously approved these changes Apr 27, 2020
Copy link
Member

@cbeams cbeams left a comment

Choose a reason for hiding this comment

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

ACK. @bisq-network/bisq-maintainers, can we get this merged asap? I have additional changes that build on these commits, and I'd like to get them available to @ghubstan in a separate PR.

We might want to discuss allowing me to merge these gRPC-related PRs after peer review with @ghubstan. I'm not sure if it's worth the wait to have one of you go through them as well. I've debated doing this work together in my own fork to speed stuff up, but I like the idea of keeping it all here in the main repo, and doing everything incrementally in small PRs. Just not sure if the normal review process will keep up with that. Thoughts?

@ghubstan
Copy link
Member Author

The redundant "Review required" happened because of a commit (ac87c23) I reverted (ce17200).
The test.sh migration from expect to bats will go into a new PR.

@cbeams
Copy link
Member

cbeams commented Apr 29, 2020

I just removed the bats commit and its reversion and force pushed the branch back to its original state when I gave my final ACK.

Copy link
Member

@cbeams cbeams left a comment

Choose a reason for hiding this comment

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

ACK

@sqrrm
Copy link
Member

sqrrm commented Apr 29, 2020

I'm good with @cbeams merging this work

@cbeams cbeams merged commit e03c461 into bisq-network:master Apr 29, 2020
@ghubstan ghubstan deleted the simple-rpc-auth branch May 19, 2020 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants