You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Simplify setup of encrypted RethinkDB clusters #3151
It would be great if we could make that easier, e.g. by providing some scripts to partially automate the setup process of an encrypted RethinkDB cluster.
I imagine the user experience to work somewhat like this:
Generate a key (-pair)
Copy the key to all RethinkDB servers
Provide the key to the RethinkDB instances through some configuration or command line option
Have some magic that sets up for example SSH tunnels as needed to get the cluster up
I'm not sure how practical this is, given that it would have to work in a lot of different environments, different versions of OpenSSH etc.
I think it's worth investigating though, as it would significantly improve the user experience for many people.
Maybe we can also do something to make encrypted client access easier to setup? (Edit: This is now tracked in #3158)
An issue came up in conversation this morning with @segphault, and I think the solutions could be related. He was working with someone that has multiple clusters of RethinkDB running at the same time on different virtual networks. It sounds like they had a problem with what computers were on what networks, and have IP address overlaps between the two. So when RethinkDB came up on one computer it was told to join to a computer that happened to be from the "wrong" cluster, and naturally started seeing (and backfilling) the "wrong" data.
This is all RethinkDB working as it is supposed to do, but if we did have a certificate (or something similar) associated with a cluster that all servers needed in order to connect, then this would allow sys-admins with multiple clusters to ensure that only the right machines joined the cluster.
I also keep thinking about MacOS's Local Kerberos Domain Controller (LKDC) that allows for secure transport on ad-hock networks. I don't know how we would implement something that worked across platform, but it does indicate that there are strategies to do this.
I've worked with libsodium before and it's a lovely library, using it for intra-cluster communication should definitely be considered.
Introducing the library as a dependency into every driver for secure communication on that front may be problematic though. SSL support on the other hand is present in almost every language already.
The situation seems to have improved considerably since I've last used it a year or so ago, which is great. It already was a great library back then, thus I'm in favour of using libsodium.
One argument in favor of libsodium is that NaCl, the library it is based on, had an interface deliberately designed to prevent you from doing something dangerous with crypto (which is almost every operation, it seems).
I think we should avoid libsodium because many of the bindings for libsodium seem incomplete, unmaintained or hard to install. For example the node-sodium project warns that "this a work in progress".
@AtnNn If we are talking about client<->server communication I think we all are in agreement that libsodium is not a good solution. But for server<->server communication I think it is still a contender.
I agree with @VeXocide that despite its obvious warts SSL is probably the best way to go for client<->server communications (especially since we are probably already doing to have to have SSL for the https side).
So the way i handle encryption for my cuslter is tinc. which works with all platforms but gives me a soild vpn with tun/tap on linux so its like having an extra interface.
Hi @jlhawn, nobody has started working on this as far as I know. Help on this would be awesome!
Your proposal sounds great to me. We can look into a bootstrapping mechanism later.
Good news everyone! It seems like I've made some progress:
$ openssl s_client -connect localhost:28015 -CAfile cert.pem
CONNECTED(00000003)
... [omitted for brevity] ...
---
No client certificate CA names sent
Peer signing digest: SHA512
Server Temp Key: ECDH, P-521, 521 bits
---
SSL handshake has read 1788 bytes and written 521 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: zlib compression
Expansion: zlib compression
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : ECDHE-RSA-AES256-GCM-SHA384
Session-ID: 9FE618C7C2EF9ED5F50F78AD61E309F2485C79D903D5A7F17E37217F21AE1EB8
Session-ID-ctx:
Master-Key: 12F35B3A99E8795A6CCB1E84ACCA982EC3CF1698F3D46033EC42DD415C764E9AAF662F2888F86875D2C536BF5D559AA7
Key-Arg : None
PSK identity: None
PSK identity hint: None
SRP username: None
TLS session ticket lifetime hint: 300 (seconds)
TLS session ticket:
0000 - 26 c4 42 48 80 f4 b0 8b-c5 a7 09 24 b9 3b 39 ea &.BH.......$.;9.
0010 - 5c 59 c1 22 c0 b8 d4 93-3a d9 94 7a 5a 4d 08 20 \Y."....:..zZM.
0020 - 05 b2 6b f1 c3 9f 1b b1-ec 21 06 da 8e bf c2 35 ..k......!.....5
0030 - fa 1f 5d 39 d2 6b 23 6d-13 5d d1 44 d3 93 5a 77 ..]9.k#m.].D..Zw
0040 - b5 2b bc ac 8d ef 1a 38-9b 26 9d 8e a6 0d 44 72 .+.....8.&....Dr
0050 - 2a c7 ec 64 f5 b2 a5 76-6f 43 02 22 57 9f 1f 5d *..d...voC."W..]
0060 - 91 25 3d cf 5c 54 85 7c-b7 45 7f 8a 97 73 ee 4d .%=.\T.|.E...s.M
0070 - f1 8e 7e cd ee 11 1e 70-37 32 33 c0 b2 35 f7 61 ..~....p723..5.a
0080 - 57 c0 f5 df de fd 24 ce-fe cd c9 c6 95 80 c5 24 W.....$........$
0090 - 8b 55 2f fb 3d 8b 3f 87-64 51 8a 96 bc bc 39 0c .U/.=.?.dQ....9.
Compression: 1 (zlib compression)
Start Time: 1454749556
Timeout : 300 (sec)
Verify return code: 0 (ok)
---
hello
ERROR: Received an unsupported protocol version. This port is for RethinkDB queries. Does your client driver version not match the server?
closed
So far I've only got the query server accepting TLS connections. In the above snippet you can see that after the TLS handshake I wrote hello to the server to which it responded with: ERROR: Received an unsupported protocol version. This port is for RethinkDB queries. Does your client driver version not match the server?. I also ran simple app that I have against the server to confirm that queries still work and they do!
Hooking up the intra-cluster connections shouldn't be too difficult now that most of the connection and read/write handling stuff is out of the way.
I've spent the past day or so figuring out how to add command line options for TLS (haven't looked into config file stuff yet) and I've come up with the following (this is what it prints out when you run rethinkdb --help):
TLS options:
--web-tls secure the web administration console
with TLS
--web-tls-key private key to use for web
administration console TLS
--web-tls-cert certificate to use for web
administration console TLS
--driver-tls secure client driver connections with
TLS
--driver-tls-key private key to use for client driver
connection TLS
--driver-tls-cert certificate to use for client driver
connection TLS
--driver-tls-ca CA certificate bundle used to verify
client certificates; TLS client
authentication disabled if omitted
--cluster-tls secure intra-cluster connections with
TLS
--cluster-tls-key private key to use for intra-cluster
connection TLS
--cluster-tls-cert certificate to use for intra-cluster
connection TLS
--cluster-tls-ca CA certificate bundle used to verify
cluster peer certificates
It's divided into 3 sections - one each for the Admin Web Interface, client driver connections, and intra-cluster connections. Each has a flag --{web|driver|cluster}-tls which if specified enables TLS for those connections. If any of those flags are given, then the rest of the flags in that section must also be specified. Each section has an option for specifying the key and certificate files. The driver section's --driver-tls-ca is optional (if you want mutual TLS for client drivers) but the --cluster-tls-ca is required as I figured you'd want mutual TLS for intra-cluster connections.
About the command line arguments:
Those look good to me.
We currently have options --driver-port, --cluster-port and --http-port, rather than --web-port.
However I actually prefer the web prefix over the http prefix, since http makes it sound as if we had an HTTP-based query API.
I actually think we should deprecate the --http-port option and rename it to --web-port as well. That will be a separate step though outside the TLS pull request.
@Tryneus what do you think about these command line option names?
Just a thought: Could there be a use case for binding the TLS listeners to separate ports in addition to the unencrypted ones? Probably this isn't too useful as long as the --bind parameters apply to all of them right?
One thing to consider is what happens if a non-TLS-enabled client, browser or cluster node connects to a TLS listener. We should at least test this. One thing we could probably do is using a different default port for the TLS listeners, so that it's harder to get mixups by accident.
(PS @jlhawn to clarify: by "we should" I mean the RethinkDB team, and this can happen after the PR)
I quickly tried joining a new node (without --cluster-tls) to another node (which was using --cluster-tls) and the new node exited immediately with a segmentation fault 😞
$ ~/workspace/rethinkdb/build/release_clang/rethinkdb --bind 127.0.0.1 -n rdb_02 --cluster-port 10201 --driver-port 10202 --join localhost:10101 --no-http-admin --canonical-address localhost
WARNING: ignoring --server-name because this server already has a name.
OpenSSL 1.0.2f 28 Jan 2016
Running rethinkdb 2.2.4-dirty (CLANG 7.0.2 (clang-700.1.81))...
Running on Darwin 14.5.0 x86_64
Loading data from directory /Users/jlhawn/rdb-02/rethinkdb_data
Listening for intracluster connections on port 10201
Version: rethinkdb 2.2.4-dirty (CLANG 7.0.2 (clang-700.1.81))
error: Error in src/arch/runtime/thread_pool.cc at line 359:
error: Segmentation fault from reading the address 0x0.
error: Backtrace:
error: Tue Feb 9 17:16:33 2016
error: Exiting.
Trace/BPT trap: 5
However, the existing node stayed up and just reported in the output that the TLS handshake failed.
@danielmewes Looks like that segmentation fault is actually an error from my added code. I forgot that in C/C++ struct fields are not automatically initialized with zero. I have been spoiled by this feature of Golang. I have some logic that is basically this:
My assumption was that if TLS is not configured then tls_ctx will be NULL. However, by default the value of tls_ctx is just arbitrary garbage data (not NULL) it would attempt to make a TLS connection with invalid context.
Since this issue is titled Simplify setup of encrypted RethinkDB clusters, it's probably a good idea to cross-post this gist that I put together which is now probably the simplest guide to setting up an encrypted RethinkDB cluster. It uses an experimental build of my pull request. @kevincox, you should try it out!
Activity
larkost commentedon Oct 8, 2014
An issue came up in conversation this morning with @segphault, and I think the solutions could be related. He was working with someone that has multiple clusters of RethinkDB running at the same time on different virtual networks. It sounds like they had a problem with what computers were on what networks, and have IP address overlaps between the two. So when RethinkDB came up on one computer it was told to join to a computer that happened to be from the "wrong" cluster, and naturally started seeing (and backfilling) the "wrong" data.
This is all RethinkDB working as it is supposed to do, but if we did have a certificate (or something similar) associated with a cluster that all servers needed in order to connect, then this would allow sys-admins with multiple clusters to ensure that only the right machines joined the cluster.
larkost commentedon Oct 8, 2014
I also keep thinking about MacOS's Local Kerberos Domain Controller (LKDC) that allows for secure transport on ad-hock networks. I don't know how we would implement something that worked across platform, but it does indicate that there are strategies to do this.
deontologician commentedon Oct 8, 2014
Another option is libsodium (a cross-platform fork of NaCL)
VeXocide commentedon Oct 8, 2014
I've worked with libsodium before and it's a lovely library, using it for intra-cluster communication should definitely be considered.
Introducing the library as a dependency into every driver for secure communication on that front may be problematic though. SSL support on the other hand is present in almost every language already.
deontologician commentedon Oct 8, 2014
There are bindings for most languages: http://doc.libsodium.org/bindings_for_other_languages/README.html.
But again, just something to consider
VeXocide commentedon Oct 8, 2014
The situation seems to have improved considerably since I've last used it a year or so ago, which is great. It already was a great library back then, thus I'm in favour of using libsodium.
gchpaco commentedon Oct 8, 2014
One argument in favor of libsodium is that NaCl, the library it is based on, had an interface deliberately designed to prevent you from doing something dangerous with crypto (which is almost every operation, it seems).
AtnNn commentedon Oct 8, 2014
I think we should avoid libsodium because many of the bindings for libsodium seem incomplete, unmaintained or hard to install. For example the node-sodium project warns that "this a work in progress".
larkost commentedon Oct 8, 2014
@AtnNn If we are talking about client<->server communication I think we all are in agreement that libsodium is not a good solution. But for server<->server communication I think it is still a contender.
I agree with @VeXocide that despite its obvious warts SSL is probably the best way to go for client<->server communications (especially since we are probably already doing to have to have SSL for the https side).
deontologician commentedon Oct 8, 2014
@larkost I was suggesting it for client/server, but in light of the maturity issues of bindings, I agree its a bad idea
srh commentedon Oct 9, 2014
There are also multiple
SSLTLS libraries to choose from.wojons commentedon Oct 12, 2014
So the way i handle encryption for my cuslter is tinc. which works with all platforms but gives me a soild vpn with tun/tap on linux so its like having an extra interface.
5 remaining items
danielmewes commentedon Feb 3, 2016
Hi @jlhawn, nobody has started working on this as far as I know. Help on this would be awesome!
Your proposal sounds great to me. We can look into a bootstrapping mechanism later.
Could you drop by on our Slack http://slack.rethinkdb.com and ping me there (my user is danielmewes)? I can connect you to our engineers to give you some pointers through the code and to help you with the implementation.
kevincox commentedon Feb 3, 2016
That proposal looks awesome, I hope you get the help you need!
jlhawn commentedon Feb 6, 2016
Good news everyone! It seems like I've made some progress:
So far I've only got the query server accepting TLS connections. In the above snippet you can see that after the TLS handshake I wrote
helloto the server to which it responded with:ERROR: Received an unsupported protocol version. This port is for RethinkDB queries. Does your client driver version not match the server?. I also ran simple app that I have against the server to confirm that queries still work and they do!Hooking up the intra-cluster connections shouldn't be too difficult now that most of the connection and read/write handling stuff is out of the way.
danielmewes commentedon Feb 8, 2016
👏 That's great news @jlhawn !
jlhawn commentedon Feb 10, 2016
I've spent the past day or so figuring out how to add command line options for TLS (haven't looked into config file stuff yet) and I've come up with the following (this is what it prints out when you run
rethinkdb --help):It's divided into 3 sections - one each for the Admin Web Interface, client driver connections, and intra-cluster connections. Each has a flag
--{web|driver|cluster}-tlswhich if specified enables TLS for those connections. If any of those flags are given, then the rest of the flags in that section must also be specified. Each section has an option for specifying the key and certificate files. The driver section's--driver-tls-cais optional (if you want mutual TLS for client drivers) but the--cluster-tls-cais required as I figured you'd want mutual TLS for intra-cluster connections.danielmewes commentedon Feb 10, 2016
@jlhawn this is amazing!
About the command line arguments:
Those look good to me.
We currently have options
--driver-port,--cluster-portand--http-port, rather than--web-port.However I actually prefer the
webprefix over thehttpprefix, sincehttpmakes it sound as if we had an HTTP-based query API.I actually think we should deprecate the
--http-portoption and rename it to--web-portas well. That will be a separate step though outside the TLS pull request.@Tryneus what do you think about these command line option names?
danielmewes commentedon Feb 10, 2016
Just a thought: Could there be a use case for binding the TLS listeners to separate ports in addition to the unencrypted ones? Probably this isn't too useful as long as the
--bindparameters apply to all of them right?One thing to consider is what happens if a non-TLS-enabled client, browser or cluster node connects to a TLS listener. We should at least test this. One thing we could probably do is using a different default port for the TLS listeners, so that it's harder to get mixups by accident.
(PS @jlhawn to clarify: by "we should" I mean the RethinkDB team, and this can happen after the PR)
jlhawn commentedon Feb 10, 2016
I quickly tried joining a new node (without
--cluster-tls) to another node (which was using--cluster-tls) and the new node exited immediately with a segmentation fault 😞However, the existing node stayed up and just reported in the output that the TLS handshake failed.
danielmewes commentedon Feb 10, 2016
@jlhawn Interesting. The segmentation fault is not good. We'll look into that.
jlhawn commentedon Feb 19, 2016
@danielmewes Looks like that segmentation fault is actually an error from my added code. I forgot that in C/C++ struct fields are not automatically initialized with zero. I have been spoiled by this feature of Golang. I have some logic that is basically this:
My assumption was that if TLS is not configured then
tls_ctxwill beNULL. However, by default the value oftls_ctxis just arbitrary garbage data (notNULL) it would attempt to make a TLS connection with invalid context.danielmewes commentedon Feb 19, 2016
@jlhawn Ah I see. Sorry I haven't gotten around to taking a deeper look at your code yet. I'll hopefully be able to do that soon.
(I originally posted this in #5381 (comment) because I got confused about the different threads)
jlhawn commentedon Feb 20, 2016
Since this issue is titled Simplify setup of encrypted RethinkDB clusters, it's probably a good idea to cross-post this gist that I put together which is now probably the simplest guide to setting up an encrypted RethinkDB cluster. It uses an experimental build of my pull request. @kevincox, you should try it out!