[Feature Proposal] Pull Request to add support for Erlang-only validate_doc_read functions
- Dominant language
- Erlang
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 9
Description
# Overview
## Context
This is not really a feature request because we do have this functionality implemented in our CouchDB 2.x fork. However I consider this feature to be a good fit for upstream repository and I decided to open a discussional issue first instead. Let me know if it is better to directly submit a PR with this functionality.
## Background and strategic fit
CouchDB already has support for [validate_doc_update](http://docs.couchdb.org/en/2.2.0/ddocs/ddocs.html#validatefun) functions which if defined in the ddoc can be used to prevent invalid or unauthorized document update requests from being stored. In other words document-level write security. I'm proposing a patch which adds the same type of security but for all document reads. This functionality have been used in our production cluster and proved to be useful. There are a lot of valid use case scenarios akin to "Some particular user may only read documents he created" and so on. This also may alleviate overhead caused by alternative solutions such as per-user DBs.
## Implementation details
First things first. This feature can lay waste to read performance if `validate_doc_read` functions will be implemented in JS due to notorious external query server and serialisation/deserialisation and standard I/O overhead. Thereby I propose to impose a limitation on these functions namely they have to be implemented only in Erlang and marked as advanced functionality. Perhaps they have to be available solely by means of some additional config such as `validate_doc_read = true`. Therefore this **will not** in any case affect default CouchDB setup but might be useful for advanced users. When implemented as Erlang ones potential overhead of these functions is negligible but benefits are perceptible. In a nutshell implementation extends `load_validation_funs` to also find, load and parse `validate_doc_read` functions from design documents and then make appropriate calls in the end of `make_doc()`. Unauthorised exception will be thrown and status code 403 returned from the `chttpd` handler when some invariants in `validate_doc_read` logic are violated.
## Conclusions
I've decided to create this issue instead of directly sending a PR because at first I would like to gather feedback from core Apache and Cloudant maintainers regarding the usefulness and expediency of this feature. In case of a more or less positive one I would be glad to submit a PR which will shed more light on the technical part (which is pretty straightforward) as well as open a discussion about potential improvements.
Contributor guide
Research direction
Read the existing load_validation_funs and make_doc() paths described in the proposal, then inspect how the chttpd handler handles unauthorized exceptions. The issue is seeking maintainer feedback on design and configuration before implementation, so completion depends on an agreed upstream approach and the proposed read-validation behavior returning 403 when authorization fails.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- erlang
- Domain
- authorization, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100