This repository has been archived by the owner. It is now read-only.
Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Database-level security.
This patch builds on the DB-admins feature to store lists of database admin and reader names and roles, as well as a security object which can be used for configuration in validation functions. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@905436 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
8 changed files
with
228 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<!-- | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed | ||
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
--> | ||
<form action="" method="post"> | ||
<h2>Admins and Readers</h2> | ||
<p class="help"> | ||
Each database contains lists of admins and readers. | ||
Admins and readers are each defined by <tt>names</tt> and <tt>roles</tt>, which are lists of strings. For example, if the readers is defined by <tt>names ["jane", "mike"]</tt> and roles <tt>["bbq"]</tt> then anyone with a <tt>"bbq"</tt> role can read the database. Yummy! | ||
</p> | ||
<fieldset> | ||
<h3>Admins</h3> | ||
<p class="help">Database admins can update design documents and edit the readers list.</p> | ||
<table summary=""><tbody><tr> | ||
<th><label>Names:</label></th> | ||
<td><input type="text" name="admin_names" size="40"></td> | ||
</tr><tr> | ||
<th><label>Roles:</label></th> | ||
<td><input type="text" name="admin_roles" size="40"></td> | ||
</tr> | ||
</tbody></table> | ||
</fieldset> | ||
<fieldset> | ||
<h3>Readers</h3> | ||
<p class="help">Database readers can access the database. If no readers are defined, the database is public. When readers are defined, only they may read or write to the database.</p> | ||
<table summary=""><tbody><tr> | ||
<th><label>Names:</label></th> | ||
<td><input type="text" name="reader_names" size="40"></td> | ||
</tr><tr> | ||
<th><label>Roles:</label></th> | ||
<td><input type="text" name="reader_roles" size="40"></td> | ||
</tr> | ||
</tbody></table> | ||
|
||
</fieldset> | ||
<div class="buttons"> | ||
<button type="submit">Update</button> | ||
<button type="button" class="cancel">Cancel</button> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
// use this file except in compliance with the License. You may obtain a copy | ||
// of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations under | ||
// the License. | ||
|
||
couchTests.reader_acl = function(debug) { | ||
// this tests read access control | ||
|
||
var usersDb = new CouchDB("test_suite_users", {"X-Couch-Full-Commit":"false"}); | ||
var secretDb = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"false"}); | ||
function testFun() { | ||
try { | ||
usersDb.deleteDb(); | ||
usersDb.createDb(); | ||
secretDb.deleteDb(); | ||
secretDb.createDb(); | ||
|
||
// create a user with top-secret-clearance | ||
var jchrisUserDoc = CouchDB.prepareUserDoc({ | ||
name: "jchris@apache.org", | ||
roles : ["top-secret"] | ||
}, "funnybone"); | ||
T(usersDb.save(jchrisUserDoc).ok); | ||
|
||
T(CouchDB.session().userCtx.name == null); | ||
|
||
// set secret db to be read controlled | ||
T(secretDb.save({_id:"baz",foo:"bar"}).ok); | ||
T(secretDb.open("baz").foo == "bar"); | ||
|
||
T(secretDb.setDbProperty("_readers", { | ||
roles : ["super-secret-club"], | ||
names : ["joe","barb"]}).ok); | ||
// can't read it as jchris | ||
T(CouchDB.login("jchris@apache.org", "funnybone").ok); | ||
T(CouchDB.session().userCtx.name == "jchris@apache.org"); | ||
|
||
try { | ||
secretDb.open("baz"); | ||
T(false && "can't open a doc from a secret db") ; | ||
} catch(e) { | ||
T(true) | ||
} | ||
|
||
CouchDB.logout(); | ||
|
||
// admin now adds the top-secret role to the db's readers | ||
T(CouchDB.session().userCtx.roles.indexOf("_admin") != -1); | ||
|
||
T(secretDb.setDbProperty("_readers", { | ||
roles : ["super-secret-club", "top-secret"], | ||
names : ["joe","barb"]}).ok); | ||
|
||
// now top-secret users can read it | ||
T(secretDb.open("baz").foo == "bar"); | ||
T(CouchDB.login("jchris@apache.org", "funnybone").ok); | ||
T(secretDb.open("baz").foo == "bar"); | ||
|
||
CouchDB.logout(); | ||
|
||
// can't set non string reader names or roles | ||
try { | ||
T(!secretDb.setDbProperty("_readers", { | ||
roles : ["super-secret-club", {"top-secret":"awesome"}], | ||
names : ["joe","barb"]}).ok); | ||
T(false && "only string roles"); | ||
} catch (e) {} | ||
|
||
try { | ||
T(!secretDb.setDbProperty("_readers", { | ||
roles : ["super-secret-club", "top-secret"], | ||
names : ["joe",22]}).ok); | ||
T(false && "only string names"); | ||
} catch (e) {} | ||
} finally { | ||
CouchDB.logout(); | ||
} | ||
} | ||
|
||
run_on_modified_server( | ||
[{section: "httpd", | ||
key: "authentication_handlers", | ||
value: "{couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}"}, | ||
{section: "couch_httpd_auth", | ||
key: "authentication_db", value: "test_suite_users"}], | ||
testFun | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters