Repository navigation
Closed
Description
Adding user accounts per #4519 will require us to change the client protocol to what's proposed below. The authentication aspect is based on https://tools.ietf.org/html/rfc5802#section-5.
C→S: the magic versionV0_5whose value has yet to be determined in a bike shed, I propose0xd27951cc.C→S: a JSON object terminated by a null byte. This JSON object MAY contain a member"authentication"describing the authentication mechanism used, we currently support"SCRAM-SHA-256". If this is used it MUST also contain a member"user"containing the username, and a"nonce"containing a nonce per the above RFC.S→C: the server responds with a JSON object terminated by a null byte which MUST contain a member"version"containing the server version encoded as a string. Upon failure the object MUST contain the member"success"set to the valuefalse, and MAY contain a member"error"containing a description of the error. Upon success the object MUST contain the member"success"set totrue. If authentication is enabled the object MUST also contain"nonce"set to the extended nonce,"salt"containing the salt, and"iterations"set to the iteration count represented as a number.
The connection should be terminated if this was not successful. Otherwise, if authentication is not enabled this is the end of the exchange and the connection is now ready for use, else it is continued as follows.
C→S: a JSON object terminated by a null byte which MUST contain the members"nonce"with the above nonce, and"proof", a base64 encoded ClientProof.S→C: a JSON object terminated by a null byte which MUST contain a member"success"indicating whether this was success with a boolean. If not successful it MAY contain a member"error"containing a description of the error. However, if successful it MUST contain a member"signature"containing the ServerSignature, again as described in the RFC.
Again, the connection should be terminated if this was not successful, otherwise the connection is ready for use assuming the signature is valid.
Activity
mlucy commentedon Feb 17, 2016
This looks good to me. The only thing that comes to mind is that maybe the client should also send a version in the second step so that we don't have to bump the magic number every time we want to make a backwards-incompatible change. (I think the magic number should only change if the wire format changes, not if e.g. the fields in the JSON objects change.)
danielmewes commentedon Feb 18, 2016
Oh right. We were talking about the client version the other day and didn't know what it should be, but indeed it should send something akin to the different magic numbers that we currently have I think.
Maybe just "{protocol_version: }", where the integer would be 1 for now, and could be incremented in the future if we ever change the handshake again?
One more remark: "and MAY contain a member "error" containing a description of the error. " / "If not successful it MAY contain a member "error""
I think both of these should be "MUST contain". The error being optional just adds an additional case that all clients will need to handle.
VeXocide commentedon Feb 18, 2016
I'm in favour of requiring the member
"error"in failure cases, it simplifies the protocol marginally and an error message makes it easier to debug what's failing.Instead of the version I'd like to propose an optional member
"capabilities"in the first message from the client to the server containing an array of strings with capabilities that the client supports. We may need to do this server to client as well.mlucy commentedon Feb 18, 2016
I think a protocol version would be better than capabilities.
Capabilities make sense when you have an extremely complicated ecosystem with multiple providers that have wildly different feature sets (e.g. C++ compilers). They also make sense when it's reasonable for a client to only support a subset of functionality. Neither of those are really true here.
In this case I think they'd add extra complexity for not much gain, and everyone who wrote a client would have to think about what their capabilities are, instead of just coding exactly to a protocol spec and specifying that they follow that protocol.
I suppose now that we offer encryption it mightmake sense to let clients specify what encryption algorithms they support or something, so it might make sense to have a capabilities array for something like that, but if we do that I think it should exist in addition to a protocol version.
mlucy commentedon Feb 18, 2016
@VeXocide and I talked about this a little bit offline, and he mentioned another thing, which is that it's probably a good idea to have the server report what protocol versions it supports before the client requests a particular protocol version, because that allows you to write clients that can connect to older versions of the server.
We decided that it's probably a good idea to require the client to specify a protocol version in the first JSON object it sends to the server. He convinced me that we probably need a capabilities array eventually for things like supported encryption/compression options, whether or not a client can print its own backtraces, etc., but it seems better to leave it out of the first version since the server wouldn't actually do anything differently based on what's in the array right now. Later when we add support for things like that, we can bump the protocol version field and say that that new protocol version requires a capabilities array.
(We also talked a bit about the idea of leaving off the protocol version and adding it later, with the convention that an unspecified protocol version is protocol v0, but that seems like a bad idea because you can't distinguish between a third party client that forgot to specify a protocol version and one written to the spec of the very first protocol, which might make debugging confusing for people.)
(We also talked a bit about why we would have both a protocol version and a magic number: in my mind the magic number should be bumped when the gross format of the exchange changes. So large changes like the current one where we go from sending plaintext back and forth to sending JSON objects would involve bumping the magic number. I think that if the semantics of the JSON objects we're sending back and forth changes, that shouldn't require bumping the magic number and you should bump the protocol version instead.)
mlucy commentedon Feb 18, 2016
So the current proposal is:
C -> S
0xd27951ccC <- S
C -> S
C <- S
or
C -> S
C <- S
or
C -> S
Queries and stuff.
danielmewes commentedon Feb 18, 2016
Could we merge this message:
into this one:
...to reduce the latency for connection setup a bit? The client would have to send the authentication data before it has heard from the server about the supported protocol versions, but my impression is that that wouldn't be an issue.
The exception I can think of is if we later want to add additional authentication protocols and the client needs to automatically pick which one to use based on the server's supported variants. That might not be necessary though. We could have the authentication method configurable by the user instead, and if the client tries using an unsupported one, the server will reject the connection in the next step. I think that's probably what we would want anyway, since we typically don't want to silently fall back to a less secure method anyway.
VeXocide commentedon Feb 18, 2016
We'll definitely want to add additional authentication protocols like x.509 later. Another upside of this setup is that monitoring tools can simply send the magic version and have the server report that it's still good.
mlucy commentedon Feb 18, 2016
Merging the messages seems bad. You want the server to say what protocols it speaks before the client starts talking to it, I think.
One way we could change the protocol to allow lower latency is we could say that if the client asks for a protocol the server doesn't support, the server responds with an error but keeps listening for another protocol request. (So instead of erring out it goes back to waiting for step 3.) Then the client could send the magic number and optimistically send the protocol request, and if the server doesn't support that protocol then the client can send the "correct" protocol request after receiving the server version and swallow the first error.
deontologician commentedon Feb 18, 2016
Why can't the client send this stuff together?
It seems like an unnecessary round trip. If the server doesn't support the protocol version or authentication method it can just error as its first response.
VeXocide commentedon Feb 18, 2016
@deontologician -- we want to have the client select the highest protocol version that both the client and server support, allowing a client to talk to an older server.
deontologician commentedon Feb 18, 2016
Ah, ok I missed that clients would support more than one protocol. Sorry
danielmewes commentedon Feb 18, 2016
@mlucy I think allowing for the extra roundtrip in case the protocol isn't supported by the server might be better. It makes the protocol slightly more complex, but removes a round trip. I've seen lots of benchmarks and simple applications where a new connection is opened for each request, so I think connection setup latency does matter.
In practice, most users are going to run servers that match the client version and hence the fallback case where the authentication protocol isn't supported by the server is going to be very rare.
3 remaining items
danielmewes commentedon Feb 19, 2016
VeXocide commentedon Feb 23, 2016
I guess it's time to bike shed about the
V0_5constant, Protobuf uses a signed integer thus it complains withInteger out of range.on my proposed constant.VeXocide commentedon Feb 23, 2016
We're going with
0x34c2bdc3.deontologician commentedon Feb 23, 2016
No way, 0x34c2bdd5 is way better.
mglukhovsky commentedon Feb 23, 2016
@deontologician: taking bike-shedding to a whole new level. 🚲
danielmewes commentedon Feb 23, 2016
Continue this sequence:
0x3f61ba36, 0x723081e1, 0x5f75e83e, 0x400c2d20, ...
And the answer:
Step 1: Converting the numbers to decimal http://www.wolframalpha.com/input/?i=0x3f61ba36,+0x723081e1,+0x5f75e83e,+0x400c2d20+to+decimal
Step 2: Continuing the sequence http://www.wolframalpha.com/input/?i=1063369270,+1915781601,+1601562686,+1074539505,+...
"no form found in terms of holonomic sequences" :-(
deontologician commentedon Feb 23, 2016
https://oeis.org/search?q=1063369270%2C+1915781601%2C+1601562686%2C+1074539505&language=english&go=Search
danielmewes commentedon Feb 23, 2016
Sounds like a plan.
VeXocide commentedon Feb 24, 2016
Note to self,
vexocide/5406is branched off ofvexocide/4519.danielmewes commentedon Apr 4, 2016
It's in next.
Implementing #5406 for javascript driver.
C# DRIVER NEW AUTH IMPELMENTED: rethinkdb/rethinkdb#5461 and rethinkd…
Implementing rethinkdb#5406 for javascript driver.