How to disable read permission on couchdb database - nosql

The problem is I have multiple couchdb local clients databases say A_db, B_db, C_db which is replicating to a couchdb server master database says server_db. Now each client is creating a document say A_doc, B_doc, C_doc in their local db which automatically replicating to server_db. So now server_db will have 3 documents, one for each client.
Since every client can see all documents of server_db using
server_db/_all_docs?include_docs=true
But I want to restrict clients to read/write other client documents which is on server_db. And only server_db admin to view documents all documents.

Document level read restriction is not supported by CouchDB. I point you to a similar question:
The suggested pattern is to have a db per user or db per role as it seems you are doing.
You should restrict the access to server_db only to authorized users, not to clients.
Some helpful links:
Cloudant Envoy
Offile wep apps with CouchDB and PouchDB
DB per user

Related

Moodle asynchronous replication

I'm looking to deploy moodle in the cloud however I have some 50 odd sites which require access to this moodle possibly even temporarily offline. So I'm looking into replicating moodle down onto each site. From what I understand there are 2 data stores that require replication, moodledata and the database, postgresql in our case. moodledata if I'm not mistaken contains the multimedia data and the database among other things all the user records. Luckily the multimedia data will be centralized and is thus synched only one way down to the nodes, that seems doable. Where I'm stuck is how do I handle the Postgres database where the sync will need to be bidirectional?

MongoDB | How to find who updated a given document/record?

We are using Mongo DB to store different configuration objects that are used as input for execution; Often we get into soup when these configurations are modified by a user incorrectly by firing Mongo query instead of using custom exposed APIs.
In Mongo, is there any way to log user who last modified the document? Any system defined audit capability which can enable tracing the illegal entries quickly and make system failproof.
In case its not possible to do it at document level, is there an Admin control that can help track the IP and User who fired it easily?
Any help would be appreciated.
There is no audit on per-document level but enterprise version can audit user auth events with local and remote IP addresses and sessions. The full list of events is documented at https://docs.mongodb.com/manual/reference/audit-message/#std-label-audit-action-details-results
I reckon problem lies in
user incorrectly by firing Mongo query instead of using custom exposed APIs.
Don't expose mongodb to any users but API.

Recommendations for multi-user Ionic/CouchDB app

I need add multi-user capability to my single-page mobile app developed with Ionic 1, PouchDB and CouchDB. After reading many docs I am getting confused on what would be the best choice.
About my app:
it should be able to work offline, and then sync with the server when online (this why I am using PouchDB and CouchDB, working great so far)
it should let the user create an account with a username and password, which would then be stored within the app so that he does not have to log in again whenever he launches the app. This account will make sure his data are then synced on the server in a secure place so that other users cannot access it.
currently there is no need to have shared information between users
Based on what I have read I am considering the following:
on the server, have one database per user, storing his own data
on the server, have a master database, storing all the data of all users, plus the design docs. This makes it easy to change the design docs in a single place, and have them replicated on each user database (and then within the PouchDB database in the app). The synchronization of data, between the master and the user DBs, is done through a filter, so that only the docs belonging to one user (through some userId field) are replicated to this user's database only
use another module/plugin (SuperLogin? nolanlawson/pouchdb-authentication?) to manage the users from the app (user creation, login, logout, password reset, email notification for password lost, ...)
My questions:
do you think this architecture is appropriate, or do you have something better to recommend?
which software would you recommend for the users management? SuperLogin looks great but needs to run on a separate HTTP server, making the architecture more complex. Does it automatically create a new database for each new user (I don't think so)? Nolanlawson/pouchdb-authentication is client-only, but does it fit well with Ionic 1? Isn't there a LOT of things to develop around it, that come out of the box with SuperLogin? Do you have any other module in mind?
Many thanks in advance for your help!
This is an appropriate approach. The local PouchDBs will provide the data on the client side even if a client went offline. And the combination with a central CouchDB server is a great to keep data synchronized between server and clients.
You want to store the users credentials, so you will have to save this data somehow on your client side, which could be done in a separate PouchDB.
If you keep all your user data in a local PouchDB database and have one CouchDB database per user on the server, you can even omit the filter you mentioned, because the synchronization will only happen between this two user databases.
I recommend SuperLogin. Yes, you have to install NodeJS and some extra libraries (namely morgan, express, http, body-parser and cors), and you will have to open your server to at least one new port to provide this service. But SuperLogin is really powerful to manage user accounts and user databases on a CouchDB server.
For example, if a user registers, you just make a call to SuperLogin via http://server_address:port/auth/register, query the user name, password etc. and SuperLogin not only adds this new user to the user database, it also creates automatically a new database only for this user. Each user can have multiple databases (private or shared) and SuperLogin manages the access rights to all these databases. Moreover, SuperLogin can also send confirmation emails or resend forgotten passwords (an access token, respectively).
Sure, you will have to configure a lot (but, hey, at least you have all these options), and maybe you even have to write some additional API for functionality not covered by SuperLogin. But in general, SuperLogin saves a lot of pain regarding the development of a custom user management.
But if you are unsure about the server configuration, maybe a service such as Couchbase, Firebase etc. is a better solution. These services have also some user management capabilities, and you have to bother less with server security.

Meteor dynamic mongodb based on user

I develop a multi tenant application where each tenant has its own mongo db.
All tenants share the same UI.
I should have one mongo db for all users accounts and each mongo db for data.
I'm new in meteor and i would like to know how i can dynamically select the database when i publish the collections.
export const collects = new MongoObservable.Collection('collectionname',{
connection:DDP.connect('urltomongodb')
});
Any help please
As far as I know the DDP utilities are available for people who wish to connect to a Meteor server from a non-Meteor platform, either front end or server.
There is, of course, nothing to stop you using DDP.connect() to connect to another server, but you will also need to manage that connection, and any retries etc if it becomes unavailable.
I would suggest an easier path is to manage all of your data in one database - trying to separate them becomes non-trivial, because it is doing something that Meteor doesn't normally do. If you structure your data accordingly, it should be quite feasible to keep all the data in one database

Issue in Cloudant to Dash DB sync on bluemix: Documents lost in transit

Few documents have just vanished in sync between Cloudant to Dash DB. On Cloudant side, the count of messages in main & overflow table is different than the actual count in dash db tables. Any clue how to find those documents?
The best way for you to recover the lost documents would be by using the RESCAN function. That will re-load all documents currently in Cloudant to dashDB. Just beware that it will drop existing tables and records before it performs the reload.
If you want the Cloudant support team to investigate the specific cause for this loss, please open a ticket with support#cloudant.com and make sure to mention your account details!