[WIP] Enable rpc TLS and macaroon authentication #4129
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change adds the simplest macaroon authentication scheme
with no caveats (analog to ACLs). A macaroon is created in the
app data dir by BisqSetup, if needed, and all :cli calls include
that hex encoded macaroon to the server for authentication.
To enable TLS, a temporary certificate and pkcs8 key were manually
generated by a bash script in new temp folder (cert). The cert &
key are installed in the same temporary folder. The server depends
on both the cert and key, the client on the cert.
More specific code changes to support tls/auth:
Added macaroons dependency to :core and :cli.
Build grpc server instance with useTransportSecurity(cert,key).
Inject Config into CoreApi so it can pass the appDataDir to
the grpc AuthenticationInterceptor.
Bakes new macaroon in a new MacaroonOven during server startup
(if not present).
Other changes:
Daemon resources folder was moved to the expected location under
src/main.
Added -XX:MaxRAM=4g jvm option to bisq-daemon and bisq-cli startup
scripts. This cuts :daemon's resident memory consumption by 4 GB.
(This option should probably be added to all startup scripts.)
A few comments not included in commit...
In general, I am attempting to imitate the way Lightning Network's lnd project uses macaroons. For an intro, see
Some of the next problems to solve are
The appDataDir is not available to :cli, as Config is not in the classpath. There is
a temporary hack to find the default appDataDir (where the macaroon lives) on
OSX and Linux, but not Windows.
The end-user needs to be informed that his TLS certificate and macaroon need
to be copied to his :cli host, if different than :daemon host.
A hard coded macaroon secretKey is passed from BisqSetup to the MacaroonOven
in maybeCreateMacaroon().
Not sure about proper way to create certificate and key for TLS,
currently using the bash script in cert folder to generate cert & key
for development.
The certificate+key and macaroon need to be created for correct hostname(s),
for now only works for 'localhost'.
GrpcServer has hard coded paths to temporary cert & pkcs8 key:
Need to find a TLS cert encryption algo "thought" not to be broken
by the NSA & Co., and choices are limited by what Netty supports.