You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Pascal Dennerly <dn...@gmail.com> on 2014/02/27 23:40:38 UTC

Enforcing creating documents using an update handler in a CouchApp

Hi,

I've been struggling with how I might lock down PUT and POST to a DB so I
can enforce a model. Now using an update handler would be ideal, but I'm
struggling to find a way of preventing changes to documents directly.

If validation_doc_update had context about the request, I could block any
requests that didn't come through an update handler there.

Does anyone have any ideas how to do this? Am I missing something?

Thanks,
Pascal

Re: Enforcing creating documents using an update handler in a CouchApp

Posted by Robert Samuel Newson <rn...@apache.org>.
update handlers and validate_doc_update go hand-in-hand for model validation.

The validate_doc_update enforces your model, the update handler makes it easier on clients to send valid updates. The update handler is often unnecessary, though.

I say you have it backwards, it’s the validate_doc_update function you want to focus on.

B.

On 27 Feb 2014, at 23:09, Stanley Iriele <si...@gmail.com> wrote:

> Use a proxy to say no posts and puts matching that.... Or...just don't call
> it. :-) I exclusively use update handlers to update my docs unless I move
> them in bulk
> On Feb 27, 2014 2:46 PM, "Alexander Shorin" <kx...@gmail.com> wrote:
> 
>> How you suppose to deal with replication which stores documents
>> directly without triggering any update handles?
>> --
>> ,,,^..^,,,
>> 
>> 
>> On Fri, Feb 28, 2014 at 2:40 AM, Pascal Dennerly <dn...@gmail.com> wrote:
>>> Hi,
>>> 
>>> I've been struggling with how I might lock down PUT and POST to a DB so I
>>> can enforce a model. Now using an update handler would be ideal, but I'm
>>> struggling to find a way of preventing changes to documents directly.
>>> 
>>> If validation_doc_update had context about the request, I could block any
>>> requests that didn't come through an update handler there.
>>> 
>>> Does anyone have any ideas how to do this? Am I missing something?
>>> 
>>> Thanks,
>>> Pascal
>> 


Re: Enforcing creating documents using an update handler in a CouchApp

Posted by Stanley Iriele <si...@gmail.com>.
Use a proxy to say no posts and puts matching that.... Or...just don't call
it. :-) I exclusively use update handlers to update my docs unless I move
them in bulk
On Feb 27, 2014 2:46 PM, "Alexander Shorin" <kx...@gmail.com> wrote:

> How you suppose to deal with replication which stores documents
> directly without triggering any update handles?
> --
> ,,,^..^,,,
>
>
> On Fri, Feb 28, 2014 at 2:40 AM, Pascal Dennerly <dn...@gmail.com> wrote:
> > Hi,
> >
> > I've been struggling with how I might lock down PUT and POST to a DB so I
> > can enforce a model. Now using an update handler would be ideal, but I'm
> > struggling to find a way of preventing changes to documents directly.
> >
> > If validation_doc_update had context about the request, I could block any
> > requests that didn't come through an update handler there.
> >
> > Does anyone have any ideas how to do this? Am I missing something?
> >
> > Thanks,
> > Pascal
>

Re: Enforcing creating documents using an update handler in a CouchApp

Posted by Alexander Shorin <kx...@gmail.com>.
How you suppose to deal with replication which stores documents
directly without triggering any update handles?
--
,,,^..^,,,


On Fri, Feb 28, 2014 at 2:40 AM, Pascal Dennerly <dn...@gmail.com> wrote:
> Hi,
>
> I've been struggling with how I might lock down PUT and POST to a DB so I
> can enforce a model. Now using an update handler would be ideal, but I'm
> struggling to find a way of preventing changes to documents directly.
>
> If validation_doc_update had context about the request, I could block any
> requests that didn't come through an update handler there.
>
> Does anyone have any ideas how to do this? Am I missing something?
>
> Thanks,
> Pascal

Re: Enforcing creating documents using an update handler in a CouchApp

Posted by Robert Samuel Newson <rn...@apache.org>.
Nothing forces your clients to use your update handler, so you can’t enforce anything there.

In validate_doc_update you can insist that new documents (where !oldDoc) have a timestamp field that reflects system clock time (within some delta). An update handler can add the current time, making it easy for clients to get it right, but a client could add the current time itself.

Rewrite handlers restrict nothing, no client is required to use them.

Shorter: The only place in couchdb where you can validate your document updates is validate_doc_update.

B.

On 28 Feb 2014, at 21:57, Pascal Dennerly <dn...@gmail.com> wrote:

> The specific problem I'm trying to solve is requiring that a creation
> timestamp is put in the document when it is created in the database. Yes
> yes, it's a fairly trivial thing that I was hoping to keep server side. But
> it does suggest that there could be other instances where you might want
> to do something similar. And it got me thinking.
> 
> As the document being stored can't be modified in validate_doc_update I
> obviously looked to the update handler. Good if for some reason you don't
> trust the client to add the correct data.
> 
> Rewrite handlers are good for restricting access to a design document but
> I'm not sure it will suffice to restrict updates to other documents. I
> would definitely use validate_doc_update for enforcing
> user/replication/model constraints once the data is created - it's just
> restricting access.
> 
> I could use a proxy in front of my Couch instance - but I was hoping for
> something handled by CouchDB itself.
> 
> 
> On 28 February 2014 08:56, James Dingwall <ja...@zynstra.com>wrote:
> 
>> Pascal Dennerly wrote:
>> 
>>> I've been struggling with how I might lock down PUT and POST to a DB so I
>>> can enforce a model. Now using an update handler would be ideal, but I'm
>>> struggling to find a way of preventing changes to documents directly.
>>> 
>>> If validation_doc_update had context about the request, I could block any
>>> requests that didn't come through an update handler there.
>>> 
>>> Does anyone have any ideas how to do this? Am I missing something?
>>> 
>> With a proxy in front of CouchDB you can limit the HTTP verbs which will
>> be passed through therefore preventing PUTs.  To restrict POST you could
>> force everything through a _rewrite on the design document and only allow
>> POST requests when the url matches ^/<db>/_design/<ddoc>/_rewrite/<stuff>.
>> 
>> James
>> 


Re: Enforcing creating documents using an update handler in a CouchApp

Posted by Pascal Dennerly <dn...@gmail.com>.
The specific problem I'm trying to solve is requiring that a creation
timestamp is put in the document when it is created in the database. Yes
yes, it's a fairly trivial thing that I was hoping to keep server side. But
it does suggest that there could be other instances where you might want
to do something similar. And it got me thinking.

As the document being stored can't be modified in validate_doc_update I
obviously looked to the update handler. Good if for some reason you don't
trust the client to add the correct data.

Rewrite handlers are good for restricting access to a design document but
I'm not sure it will suffice to restrict updates to other documents. I
would definitely use validate_doc_update for enforcing
user/replication/model constraints once the data is created - it's just
restricting access.

I could use a proxy in front of my Couch instance - but I was hoping for
something handled by CouchDB itself.


On 28 February 2014 08:56, James Dingwall <ja...@zynstra.com>wrote:

> Pascal Dennerly wrote:
>
>> I've been struggling with how I might lock down PUT and POST to a DB so I
>> can enforce a model. Now using an update handler would be ideal, but I'm
>> struggling to find a way of preventing changes to documents directly.
>>
>> If validation_doc_update had context about the request, I could block any
>> requests that didn't come through an update handler there.
>>
>> Does anyone have any ideas how to do this? Am I missing something?
>>
> With a proxy in front of CouchDB you can limit the HTTP verbs which will
> be passed through therefore preventing PUTs.  To restrict POST you could
> force everything through a _rewrite on the design document and only allow
> POST requests when the url matches ^/<db>/_design/<ddoc>/_rewrite/<stuff>.
>
> James
>

Re: Enforcing creating documents using an update handler in a CouchApp

Posted by James Dingwall <ja...@zynstra.com>.
Pascal Dennerly wrote:
> I've been struggling with how I might lock down PUT and POST to a DB so I
> can enforce a model. Now using an update handler would be ideal, but I'm
> struggling to find a way of preventing changes to documents directly.
>
> If validation_doc_update had context about the request, I could block any
> requests that didn't come through an update handler there.
>
> Does anyone have any ideas how to do this? Am I missing something?
With a proxy in front of CouchDB you can limit the HTTP verbs which will 
be passed through therefore preventing PUTs.  To restrict POST you could 
force everything through a _rewrite on the design document and only 
allow POST requests when the url matches 
^/<db>/_design/<ddoc>/_rewrite/<stuff>.

James