Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've been doing more research and testing, and I want to summarize where I've gotten to, and what still isn't working for me.</p> <p>First off, apologies for those who read this question: I was looking for ways to set permissions for people to write, not read, the database. It turns out be be a big difference: the techniques for creating a "reader" are entirely different from creating a "writer" (that term actually doesn't exist, though I wonder why).</p> <p>In brief: you have to add a user to the _users database, which is a list of the users that have access to any database in your CouchDB instance. I was able to do that by issuing a command similar to:</p> <pre><code>curl -X PUT http://admin:password@localhost:5984/_users/org.couchdb.user:username -d '{"type":"user", "hashed_password":"2bf184a2d152aad139dc4facd7710ee848c2af27", "name":"username", "roles":[]}' </code></pre> <p>Note you need to apparently namespace the user name with the "org.couchdb.user" prefix. I used a Ruby hashing method to get the hashed_password value:</p> <pre><code>require 'digest/sha1' pass_hash = Digest::SHA1.hexdigest(password) </code></pre> <p>This gets an apparently valid user into the database. The next step is to assign that user as a "writer" (ha, there it is again!) for the new database that I created. So I might do something like:</p> <pre><code>curl -X PUT http://admin:password@localhost:5984/newdatabase </code></pre> <p>and then</p> <pre><code>curl -X PUT http://admin:password@localhost:5984/newdatabase/_design/security -d @security.json </code></pre> <p>That .json file contains a Javascript function for the "validate_doc_update" key, and that function looks like this:</p> <pre><code>function(new_doc, old_doc, userCtx) { if(userCtx.name != username) { throw({forbidden: "Please log in first."}); } } </code></pre> <p>It's roundabout, but it makes sense. However, I now am running into a problem: apparently the userCtx variable doesn't get populated until the user is authenticated. <a href="http://blog.couchone.com/post/1027100082/whats-new-in-couchdb-1-0-part-4-securityn-stuff" rel="noreferrer">This article</a> suggests that all you have to do is pass the credentials through an HTTP request to a special _session database, like so:</p> <pre><code>curl -X POST http://username:password@localhost:5984/_session </code></pre> <p>I can do that for my admin user, and the userCtx var will be populated. But for my newly-created user, it fails:</p> <pre><code>$ curl http://org.couchdb.user:username:password@localhost:5984/_session {"ok":true,"userCtx":{"name":null,"roles":[]},"info":{"authentication_db":"_users","authentication_handlers":["cookie","oauth","default"]}} </code></pre> <p>Note the userCtx hash is null. I wonder if that namespace thing is causing the problem? It's got a freakin' colon in it, so maybe there's some confusion about the password? I've tried making it without the namespace, and it doesn't work at all; at least here my request appears to be hitting the database and getting a response.</p> <p>I'm stuck at this point. If anyone can check my assumptions and progress thus far, I hope we can all figure out how to make this work.</p> <p>Thanks!</p> <p>Aaron.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload