Skip to content

Proposal: User accounts + access permissions #4519

Closed

Description

@danielmewes

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 database
  • table <uuid> Grants access to the given table
  • all Grants access to all tables

<access> is one of:

  • read allows reading documents from the tables
  • write allows modifying documents in the tables. There is one exception: tables in the rethinkdb database do not become writeable through this, even if they're part of the <scope>.
  • admin allows creating/dropping indexes, and running reconfigure, rebalance and writing to the result of table.config(). If they are part of <scope>, this also grants write access to the rethinkdb system tables. If the <scope> is all or database <uuid>, it also allows creating and dropping tables. If it is all, 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)
  • table
  • insert, update, replace, delete
  • reconfigure, rebalance (and config if it doesn't work automatically due to the checks on the write terms)
  • r.http This 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:

  1. When connecting, the server generates a cryptographic random string and sends it to the client (the challenge).
  2. The client concatenates the string with the auth key and hashes it using a secure hash function
  3. 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

  1. added this to the 2.2 milestone on Jul 9, 2015
  2. marshall007 commented on Jul 9, 2015

    @marshall007
    Contributor

    How would this affect r.dbList and db.tableList? Would you return a filtered list that only includes what you have read access 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.

  3. deontologician commented on Jul 9, 2015

    @deontologician
    Contributor

    It would also be great if we could make the auth key exchange more secure on the protocol level. Here's one proposal:

    1. When connecting, the server generates a cryptographic random string and sends it to the client (the challenge).
    2. The client concatenates the string with the auth key and hashes it using a secure hash function
    3. 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.

    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.

  4. mlucy commented on Jul 14, 2015

    @mlucy
    Member

    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 use r.http), and admin (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, or append. If the field is set to true that permission is granted, if it's set to null, false or 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:

    {
      user: 'danielmewes',
      auth_key: <hidden>,
      access: {
        production: {customers: {read: true}, orders: {read: true, write: true}, logs: {append: true}},
      },
      http_access: true,
      admin: false
    }

    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.

  5. mlucy commented on Jul 14, 2015

    @mlucy
    Member

    An advantage of the format I specified is you can write queries like:

    r.table('rethinkdb').table('permissions').get('danielmewes').update(
      {access: {production: {orders: {write: false}}}}
    )

    Which is very natural.

  6. VeXocide commented on Jul 14, 2015

    @VeXocide
    Member

    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>, and table <uuid> make perfect sense but we should support more fine-grained <access> levels, and I'd like to propose the following.

    • get allows reading of documents from <scope>
    • insert allows documents to be inserted into <scope> but not modified
    • update allows existing documents in <scope> to be modified
    • delete allows documents in <scope> to be deleted
    • create allows the creation of tables and / or databases depending on <scope>, this could essentially be an admin that allows rebalancing and reconfiguration
    • connect allows connections to the outside to be made, currently enabling r.http, as only enabling this on (all, admin) will lead to those access level to be granted unnecessarily to enable r.http
    • execute allows the execution of code, currently enabling r.js

    Most importantly this allows get, insert, update, and delete to 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 for r.js which I think is required due to the impact of a simple query such as r.js("while(true) {}").

    Last of all the question of how to deal with the rethinkdb database is an important one, and I'm not quite sure how we should go about this.

  7. NicolasLM commented on Aug 5, 2015

    @NicolasLM

    👍 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.

  8. PhilipGarnero commented on Aug 5, 2015

    @PhilipGarnero

    👍

  9. RubenKelevra commented on Aug 16, 2015

    @RubenKelevra

    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!

  10. modified the milestones: subsequent, 2.2 on Aug 27, 2015
  11. removed this from the subsequent milestone on Nov 9, 2015
  12. 48 remaining items

  13. danielmewes commented on Dec 22, 2015

    @danielmewes
    MemberAuthor

    Another advantage of a single table is that it will let you create a new user with certain permissions and a certain password in a single ReQL command.

    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.

  14. danielmewes commented on Dec 22, 2015

    @danielmewes
    MemberAuthor

    Oh what should we call the combined table? I suggest either auth or users.

  15. mlucy commented on Dec 22, 2015

    @mlucy
    Member

    @danielmewes -- OK, that works for me.

  16. sontek commented on Jan 8, 2016

    @sontek
    Contributor

    Is there an ETA on this? :)

  17. coffeemug commented on Jan 8, 2016

    @coffeemug
    Contributor

    We're shooting for end of February/beginning of March.

  18. VeXocide commented on Jan 18, 2016

    @VeXocide
    Member

    Just a thought, extending the conn.server() from #3934 to include the user the connection is currently logged in as.

  19. VeXocide commented on Jan 18, 2016

    @VeXocide
    Member

    Note to self, @nighelles just claimed 187 for FOLD which I was using for GRANT in ql2.proto, thus I need to change that when merging.

  20. jlhawn commented on Feb 20, 2016

    @jlhawn

    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.

  21. danielmewes commented on Feb 22, 2016

    @danielmewes
    MemberAuthor

    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.

  22. VeXocide commented on Feb 22, 2016

    @VeXocide
    Member

    X.509 is definitely on the list, but not for the first release as @danielmewes mentioned.

  23. danielmewes commented on Apr 4, 2016

    @danielmewes
    MemberAuthor

    It's in next! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions