CouchDB / PouchDB partial syncs with limited rights

梦想的初衷 提交于 2019-12-11 13:46:37

问题


I just stumbled across CouchDB and PouchDB sync features. Typically web applications have an application server implementing authentication, rights and business logic allowing to limit users access to specific resources/records. This brought up several questions in my mind:

  1. Is it possible to limit access to records within couch db. Eg. a super-admin sees everything, a department-manager everything of his department and a simple user only his own records or e.g. tasks assigned to him?
  2. Is CouchDB + PouchDB have the ability to only do partial syncs. e.g. sync all tasks I'm responsible for?
  3. Would you use CouchDB for user authentication and rights storage (for the above use case)? It seems anyhow weird me since the user DB gonna be accessible from everyone as far as it seems to me.

回答1:


Is it possible to limit access to records within couch db. Eg. a super-admin sees everything, a department-manager everything of his department and a simple user only his own records or e.g. tasks assigned to him?

Nope. You can't do this with a single DB and using only CouchDB. But there are a few ways you can realize this, for instance:

  • use a database per project/user group/user. This would probably in most cases be the preferred method. Creating databases is easy in CouchDB. It would also be best for syncing
  • create a smart proxy that wraps all documents with the user credentials and filters all results
  • encrypt documents on a per user basis
  • use validate_doc_read and validate_doc_update functions

More info here: https://wiki.apache.org/couchdb/PerDocumentAuthorization




回答2:


Is it possible to limit access to records within couch db. Eg. an super-admin sees everything, a department-manager everything of his department and a simple user only his own records or e.g. tasks assigned to him?

Off-the-shelf security policies are very basic, but you can do a lot of things with advanced features.

What you want to do could be done simply with a show function that would generate a different output depending on req.userCtx.

In different settings (authorization based on user/method/URI, with or without third party authentication), because CouchDB is fully REST compliant, you can also use an HTTP reverse proxy for security related features.

Is CouchDB + PouchDB have the ability to only to partial syncs. e.g. sync all tasks I'm responsible for?

In CouchDB, this is called "filtered replications".

Seems anyhow weird me since the user DB gonna be accessible from everyone as far as it seems to me.

Of course not. In normal mode (not "admin party"), other users have only access to "public" attributes, and, of course, only the user herself can update her user document (see documentation).



来源:https://stackoverflow.com/questions/36901918/couchdb-pouchdb-partial-syncs-with-limited-rights

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!