Repository navigation
Description
Scope
This is a concrete proposal to address #1805 and #218 .
It does not address resource quotas, DoS attacks, and assumes generally benign users. It is hence not suitable for things like direct DB access from the browser, which I think is a separate problem with very different requirements that we should address separately.
This proposal addresses restricting access to data in settings where you're either concerned about access to sensitive data, or where you want to provide some extra protection against user mistakes that could otherwise damage important data.
Authentication
Instead of our current auth key, I propose that we have a list of user name+auth key pairs.
There is always one default user (let's call it "admin"). You cannot delete that user.
We should also add a command line option that resets the "admin" auth key to a new value in case you lose it.
The drivers are going to send a user name + auth key combination instead of just an auth key during the connection setup. Existing clients will have their auth key mapped to the "admin" user name implicitly.
Permissions
Each user with the exception of "admin" has a white list of permissions assigned to it.
An entry in the list is of the following form: (<scope>, <access>).
<scope> is one of:
database <uuid>Grants access to all tables in the given databasetable <uuid>Grants access to the given tableallGrants access to all tables
<access> is one of:
readallows reading documents from the tableswriteallows modifying documents in the tables. There is one exception: tables in therethinkdbdatabase do not become writeable through this, even if they're part of the<scope>.adminallows creating/dropping indexes, and runningreconfigure,rebalanceand writing to the result oftable.config(). If they are part of<scope>, this also grants write access to therethinkdbsystem tables. If the<scope>isallordatabase <uuid>, it also allows creating and dropping tables. If it isall, it also allows creating and dropping databases.
Each access level includes the lower ones.
The "admin" user always has the single permission (all, admin).
Enforcement
The following terms check permissions upon evaluation and throw an error if the required permissions are not met:
r.db(including implicit database terms through the default database)tableinsert,update,replace,deletereconfigure,rebalance(andconfigif it doesn't work automatically due to the checks on the write terms)r.httpThis is special, and is only allowed if the permissions are(all, admin). Otherwise firewall boundaries could be circumvented, and web UI access could be misused to escalate privileges.
Updating permissions
Permissions can be configured cluster-wide through the r.db('rethinkdb').table('cluster_config') table. This replaces the current auth key document. Alternatively we could introduce a new system table for this r.db('rethinkdb').table('users')?
When updating permissions, the new permissions will propagate to all servers in the cluster and apply to all existing connections eventually. However we don't guarantee when this takes place. In particular withdrawing permissions or changing an auth key is not guaranteed to take effect immediately, and if there is a network partition, the propagation might take an arbitrarily long time.
Implementation suggestion
We can use a semilattice to propagate the user and permission information (there are different options to how we resolve conflicts in it, I think this is of secondary concern).
The authentication data itself could get stored in the environment I guess, so that it can be accessed by ReQL terms.
For the write operations insert, update, replace and delete, we might need to add a way for them to identify the db+table that they are applied on if we don't have that yet.
Optional improvements
While we're at it, it would be nice if we could make the web UI require an authentication key as well. For simplicity, I think it should always use the "admin" user. To make that happen we would need to add auth key support to the HTTP protocol implementation, and add a modal or special page to the web UI itself to allow entering the password.
This would avoid the problem that you need to use a firewall to restrict web UI access even in a generally trusted network, if you want to make sure that the access permissions are met.
It would also be great if we could make the auth key exchange more secure on the protocol level. Here's one proposal:
- When connecting, the server generates a cryptographic random string and sends it to the client (the challenge).
- The client concatenates the string with the auth key and hashes it using a secure hash function
- The client transmits the hash to the server, which verifies it
This removes the problem that we're transmitting the auth key in plain text over the network.
I think it would be really amazing if we could get this into 2.2 since it would make RethinkDB more suitable for many large scale enterprise deployments out of the box.
Activity
marshall007 commentedon Jul 9, 2015
How would this affect
r.dbListanddb.tableList? Would you return a filtered list that only includes what you havereadaccess to?If the web UI authentication piece is implemented would that be optional? Keeping it behind a firewall and SSH tunneling like we do now seems easier to manage.
deontologician commentedon Jul 9, 2015
Depending on how this is implemented, this could still open us up to replays. For this to work, the server would need to send a challenge for every query, otherwise anyone listening on the network could replay the hashed challenge+authkey to run any queries they wanted.
Personally, I feel like if we're going in the authorization direction, it seems like a good time to implement SSL on the server. It's kind of awkward to explain "Well we restrict a user's access, but it's trivial to circumvent unless you do these extra steps". People will assume it's secure because they have to provide a key.
mlucy commentedon Jul 14, 2015
Permission Levels
I like the permission levels, but I think we should also add an append-only permission level for use in e.g. log tables (so people can log events but not delete things).
Permissions format
I don't really like the permissions format. I think it should use names instead of UUIDs and generally be more human-readable.
A row in the permissions table would have four fields:
user(the name of the account the permissions are for),access(a document describing access permissions),http_access(whether or not the user can user.http), andadmin(whether or not the user can do global configuration tasks like add other users). It would also have an auth key attached, maybe as an unreadable field?The access document would be a document that maps from database names to subdocuments. The subdocuments would map from table names to permission documents. Permission documents would be objects with the fields
write,read,admin, orappend. If the field is set to true that permission is granted, if it's set tonull,falseor is missing permission is denied.So, for example, here's a permissions document granting access to some tables in the production database and http access but not global admin access:
I think it's fine to use database/table names instead of UUIDs here. I don't think anyone would expect dropping a table and recreating a table with the same name to invalidate existing sets of permissions for that table.
Updating Permissions
I think a new system table is probably the best option.
I'm not sure whether or not it's OK to return from permissions updates before the new permissions have propagated to the whole cluster. If it's a lot easier than we should probably do that and only do something else if people complain.
Security
I agree with Josh, if we're going to be making authentication a bigger part of the product we should use a library designed for it rather than homerolling our own thing with hashing concatenated strings. SSL seems fine if it isn't too hard.
mlucy commentedon Jul 14, 2015
An advantage of the format I specified is you can write queries like:
Which is very natural.
VeXocide commentedon Jul 14, 2015
Authentication
Integrating into existing authentication systems such as LDAP and PAM is going to be important to enterprise clients and something we should support in my opinion. As @deontologician rightly the authentication should either be challenge-based or over a secure connection, with SSL being the obvious route.
We should also consider security the connections between the database instances if we're going to propagate the configuration via those.
Permissions
The listed scopes of
cluster,database <uuid>, andtable <uuid>make perfect sense but we should support more fine-grained<access>levels, and I'd like to propose the following.getallows reading of documents from<scope>insertallows documents to be inserted into<scope>but not modifiedupdateallows existing documents in<scope>to be modifieddeleteallows documents in<scope>to be deletedcreateallows the creation of tables and / or databases depending on<scope>, this could essentially be anadminthat allows rebalancing and reconfigurationconnectallows connections to the outside to be made, currently enablingr.http, as only enabling this on(all, admin)will lead to those access level to be granted unnecessarily to enabler.httpexecuteallows the execution of code, currently enablingr.jsMost importantly this allows
get,insert,update, anddeleteto be distinguished as you may commonly want to allow someone to insert documents but not modify or delete them. Secondly it adds an access level forr.jswhich I think is required due to the impact of a simple query such asr.js("while(true) {}").Last of all the question of how to deal with the
rethinkdbdatabase is an important one, and I'm not quite sure how we should go about this.NicolasLM commentedon Aug 5, 2015
👍 This proposal opens new use cases for RethinkDB. I'm not sure the integration with LDAP and PAM needs to be in the first iteration though.
PhilipGarnero commentedon Aug 5, 2015
👍
RubenKelevra commentedon Aug 16, 2015
Currently we use fastd and batman-adv for database-interconnections. It would be nice if it's possible to do it over clear-net in future. :)
👍 for user-authentications!
48 remaining items
danielmewes commentedon Dec 22, 2015
Ok I think that's a pretty strong argument.
I personally have a slight preference for the syntax without
$As far as I can tell, we're all at least ok with that syntax and a single table.
I'll wait another 1-2 hours in case there's strong opposition, but otherwise I'm going to mark this settled with:
One table with deeper-nested non-$ syntax.
danielmewes commentedon Dec 22, 2015
Oh what should we call the combined table? I suggest either
authorusers.mlucy commentedon Dec 22, 2015
@danielmewes -- OK, that works for me.
sontek commentedon Jan 8, 2016
Is there an ETA on this? :)
coffeemug commentedon Jan 8, 2016
We're shooting for end of February/beginning of March.
VeXocide commentedon Jan 18, 2016
Just a thought, extending the
conn.server()from #3934 to include the user the connection is currently logged in as.VeXocide commentedon Jan 18, 2016
Note to self, @nighelles just claimed 187 for
FOLDwhich I was using forGRANTinql2.proto, thus I need to change that when merging.jlhawn commentedon Feb 20, 2016
I want to mention that this is somewhat related to #3151. If TLS client authentication is used, it would be really cool if the user could be identified by the client certificate as an alternative to using a secret auth key.
danielmewes commentedon Feb 22, 2016
Using client certs for user authentication is an interesting thought.
I think we'll leave that to version 2 though, to keep things a bit simpler in the first release.
VeXocide commentedon Feb 22, 2016
X.509 is definitely on the list, but not for the first release as @danielmewes mentioned.
danielmewes commentedon Apr 4, 2016
It's in next! :)