Return-Path: X-Original-To: apmail-couchdb-dev-archive@www.apache.org Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5679010966 for ; Wed, 19 Feb 2014 13:26:23 +0000 (UTC) Received: (qmail 50550 invoked by uid 500); 19 Feb 2014 13:26:21 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 50071 invoked by uid 500); 19 Feb 2014 13:26:20 -0000 Mailing-List: contact dev-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list dev@couchdb.apache.org Received: (qmail 50052 invoked by uid 99); 19 Feb 2014 13:26:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Feb 2014 13:26:18 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy includes SPF record at spf.trusted-forwarder.org) Received: from [80.244.253.218] (HELO mail.traeumt.net) (80.244.253.218) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Feb 2014 13:26:10 +0000 Received: from [192.168.2.122] (p5797A12E.dip0.t-ipconnect.de [87.151.161.46]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.traeumt.net (Postfix) with ESMTPSA id 18E88203F2 for ; Wed, 19 Feb 2014 14:26:46 +0100 (CET) From: Jan Lehnardt Content-Type: multipart/signed; boundary="Apple-Mail=_95299E6C-485A-404E-9172-BD4577FC8EC2"; protocol="application/pgp-signature"; micalg=pgp-sha512 Message-Id: <28526FBE-4BB3-4437-9F99-98149C946C2B@apache.org> Mime-Version: 1.0 (Mac OS X Mail 7.0 \(1812\)) Subject: Re: Capturing UserCtx automatically Date: Wed, 19 Feb 2014 14:25:49 +0100 References: <3AD8B31E-1BED-41CC-AEF6-D3A873E4CC28@apache.org> To: "dev@couchdb.apache.org Developers" In-Reply-To: X-Mailer: Apple Mail (2.1812) X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail=_95299E6C-485A-404E-9172-BD4577FC8EC2 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 On 19 Feb 2014, at 14:19 , Alexander Shorin wrote: > On Wed, Feb 19, 2014 at 5:15 PM, Jan Lehnardt wrote: >> On 19 Feb 2014, at 13:27 , Alexander Shorin wrote: >>=20 >>> On Wed, Feb 19, 2014 at 4:17 PM, Jan Lehnardt = wrote: >>>> On 19 Feb 2014, at 13:02 , Alexander Shorin = wrote: >>>>=20 >>>>> On Wed, Feb 19, 2014 at 3:59 PM, Jan Lehnardt = wrote: >>>>>> On 19 Feb 2014, at 11:42 , Alexander Shorin = wrote: >>>>>>=20 >>>>>>> On Wed, Feb 19, 2014 at 2:24 PM, Robert Samuel Newson >>>>>>> wrote: >>>>>>>> validate_doc_update(oldDoc, newDoc, userCtx) { >>>>>>>>=20 >>>>>>>> if (newDoc.audit_trail[0].user !=3D userCtx.name) { >>>>>>>> throw({forbidden: "You didn=92t add your name to the audit = trail!"}); >>>>>>>> } >>>>>>>> =85 >>>>>>>> } >>>>>>>=20 >>>>>>> There is one issue with such approach: replications. You will = not be >>>>>>> able to replicate documents which has different username in >>>>>>> audit_trail from those one who runs the replication. Or, to be = more >>>>>>> detailed, you'll replicate fine all documents till the design = document >>>>>>> which brings this validation function to your database and after = that >>>>>>> you'll only able to store documents which matches replication's = user. >>>>>>=20 >>>>>> You could add the replication user to the validation function and = keep >>>>>> the original author. >>>>>=20 >>>>> Sure, I could. But this would be tricky and unclear for other = users >>>>> that just wanted to grab the data from CouchDB. >>>>=20 >>>> how so? >>>=20 >>> Let's say we have some database where multiple users are = collaborating >>> upon some stuff. Let it be image hosting service based on CouchDB >>> where friends shares images between. Your users allowed to post new >>> docs with images, but they don't wanted to see how others users >>> changes docs that they owned. We forbidden such actions via >>> validate_doc_update function by checking if doc.author matches >>> userCtx.name. So, that's the case: you allowed to update own = documents >>> and only allow to read the others. >>>=20 >>> Now some user wanted to replicate this database to local CouchDB. He >>> already has his own personal credentials. And he'll use them in >>> replication and I wonder if he's able to recall another account to = use >>> for replications. Also, if I create special username which is able = to >>> bypass validation function ... well, that's a bug in the system - >>> what's the reason left to use restricted accounts when you have = access >>> to more powerful ones? >>=20 >> In this scenario, the other user would not be able to invoke a = replication >> with the replication-user credentials. >=20 > Which bypassed validation rules, right? And what stops him to use the > same credentials to push data back from local instance to public one? > If it workarounds validation rules, he'll be able to rewrite docs that > he shouldn't be able to. That's the problem. No, I mean in my scenario the person who could make a local change to a = doc they didn=92t create would *NOT* have the replicator user=92s = credentials, so they could NOT replicate things back elsewhere. You point is important though: you need to set these things up carefully = :) Best Jan --=20 --Apple-Mail=_95299E6C-485A-404E-9172-BD4577FC8EC2 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- iQIcBAEBCgAGBQJTBLDdAAoJENnuAeR4Uq7kK4QQAJvKovw0xGXsXhJRxSzmJ0Ih v9PouChWWKRshQQoC1KIMb9Q5u15uMweBJ5EsIfM8qWdTvqrX9ujiyZ1y/reCkoF ULBYV16IJsQ0hkqyBYZm6KhDlcn5O/sfv1RwQcb55XxDAzlfctyoDiYN2bdUv3HN 3LS6F6UbimrImeoJY2mw6srS5NCSAVOJXZs8iJt60LpgjtWODBzQfRlefSop7NKq b8xcjQyHSutfTyVMmdKzv5pGyDyKgzHSfantD/LPGTVsi1o+j7E0vLhT8d9KL1mo PAFJUUed3+7uOTjGfUmp+ui62V5BnxKSwGQ9eYfJHP4v20TAKn6wHNuoT4sbGMfT FpDq4E9KHyti33LT6vY98LkjaLnduF3HyK+egGYCwnU17hM6vY6FSk2U3xa9H92Z ylCAygiuGRC+PoZsiIMJPvFqm9ySqLbD3gJLWe3d/IxedDR6W3BqAkyARtV2h6tO EMz+3l3ZmMlqNRHbIe2djZOKrEBC81eEUETJzeRsrb0P9eD84tRWwyOsFdOe3gnh gju6Ec6h3P+d68mQiWlioRiW3uAFkvGbBP0WImfP4HzZI+JHzDjzmVRp8xelJ91l 3JguzZLg457+/OmayyX2ompy1AUGaHF6Wev4MLJOD19+RnXZxgZFxd2F3/Dnf3kf eQCQwAauiN1Jiov+RxMT =M6PM -----END PGP SIGNATURE----- --Apple-Mail=_95299E6C-485A-404E-9172-BD4577FC8EC2--