Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Add users db security rules on clustered interface #12

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

mikewallace1979
Copy link
Contributor

Apply authentication_db security rules when authentication_db is on the clustered interface (5984).

COUCHDB-2452

The process of writing documents to the authentication DB varies
depending whether the authentication DB is on the admin or the
clustered interface. Authentication handlers should therefore
abstract the details away and provide a generic update_doc
function.

This commit adds an update_auth_doc function to the chttpd auth
cache which proxies to fabric:update_doc/3.

COUCHDB-2452 2/5
A _users DB on the admin interface will strip non-public fields
from documents in the _all_docs view when include_docs=true.

This commit creates the same behaviour when the _users DB is on
the clustered interface by using the appropriate callback in
couch_mrview_http.

COUCHDB-2452 3/5
When couch_httpd_auth/users_db_public is set to false and the
_users DB is on the admin interface (5986) only admins can read
the _all_docs view.

This commit creates the same behaviour on the clustered interface
(5984) when chttpd_auth/users_db_public is set to false.

Note: This duplicates code in
couch_db:maybe_add_sys_db_callbacks/2 and couch_mrview_http:all_docs/3.

COUCHDB-2452 4/5
The check for admin when opening a design document in the
authentication DB was previously being carried out in a callback
function called when the document was read from the shard. In
order to allow admins to access the design document via the
clustered interface it is necessary to either modify the
chttpd/fabric plumbing so that the user context can be passed
through for all design document calls, or alternatively move the
check to the http layer where we already have the user context.

Due to the number of places we would need to modify fabric to
allow the option to be passed through the latter approach is
taken.

This commit checks for admin in the http layer for requests
which access design documents in the authentication DB.

The couch internals part of that work can be found in related
commit:

    couchdb-couch/6266b95415f8c8d8cde49a8ce221e9d31ebf18b8

COUCHDB-2452 5/5
Previously if chttpd_auth/authentication_db was changed in the
config then a changes listener would not be started for the new
authentication DB until the current changes request timed out.
During that time any changes to the users DB (e.g. password
changes) would not take effect. This is primarily a problem when
running share/www/script/test/users_db_security.js however it could
conceivably become a problem under normal running conditions.

This commit adds a config listener which causes the current changes
listener to be killed when the chttpd_auth/authentication_db config
value is changed. It will then be restarted via the existing
handle_info/2 clause.
get_db_options(DbName) ->
IsReplicatorDb = DbName == config:get("replicator", "db", "_replicator"),
IsUsersDb = DbName ==config:get("chttpd_auth", "authentication_db", "_users") orelse
binary_to_list(mem3:dbname(DbName)) == config:get("chttpd_auth", "authentication_db", "_users"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely need to be simplified: no need to get the same config value twice. Also, without indention this a bit confuses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this line is quite horrible. I'll figure out a better way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kxepal I was looking at tidying this up and realised I made two mistakes here. Firstly, there is no need for the binary_to_list(mem3:dbname(DbName)) comparison because that would only be necessary if DbName was for an individual shard - that will never be the case here so that check can be removed.

Secondly, there is no need to check for the replicator DB here because chttpd does nothing with that information.

I'll add some commits to fix those things up.

I realised the second part of the orelse is not needed here.
Because this code is in chttpd we will only be dealing with the
cluster-level DB name, not internal shard names, so there is
never a need to call mem3:dbname. We still need to convert from
binary to list though.

The replication DB check is also removed as that information is
not used here.

To squash into 9b5406b
@davisp
Copy link
Member

davisp commented Mar 24, 2015

+1 to squerge

@kxepal
Copy link
Member

kxepal commented Mar 25, 2015

@hubot hubot deleted the 2452-users-db-security-on-clustered-interface branch April 28, 2017 15:18
@hubot hubot restored the 2452-users-db-security-on-clustered-interface branch April 28, 2017 20:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants