summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2015-10-26 18:50:20 -0300
committerVictor Shyba <victor.shyba@gmail.com>2015-10-28 18:13:40 -0300
commitf8d38125098829fe50199725545365d6d2a889a6 (patch)
tree9edab8dc323606e675a31eb141d1d42ca1e72c99 /server
parent55548cf947966bcbb9a496e523a3f802b0f0b55f (diff)
[feat] read security doc from configuration
LEAP Platform needs to granularly allow access on user database for other services, like mx. This is now possible by editing soledad-server.conf file. A new section 'database-security' was added and it is parsed during 'create-user-db' to be set on security design document, present on every per-user database.
Diffstat (limited to 'server')
-rwxr-xr-xserver/pkg/create-user-db7
-rw-r--r--server/src/leap/soledad/server/__init__.py34
2 files changed, 30 insertions, 11 deletions
diff --git a/server/pkg/create-user-db b/server/pkg/create-user-db
index 7eafc945..28d1cbd0 100755
--- a/server/pkg/create-user-db
+++ b/server/pkg/create-user-db
@@ -31,7 +31,8 @@ This is meant to be used by Soledad Server.
parser = argparse.ArgumentParser(description=description)
parser.add_argument('dbname', metavar='user-d34db33f', type=str,
help='database name on the format user-{uuid4}')
-NETRC_PATH = load_configuration('/etc/soledad/soledad-server.conf')['admin_netrc']
+CONF = load_configuration('/etc/soledad/soledad-server.conf')
+NETRC_PATH = CONF['soledad-server']['admin_netrc']
def url_for_db(dbname):
@@ -54,7 +55,9 @@ if __name__ == '__main__':
print ("Invalid name! %s" % args.dbname)
sys.exit(1)
url = url_for_db(args.dbname)
+ db_security = CONF['database-security']
db = CouchDatabase.open_database(url=url, create=True,
- replica_uid=None, ensure_ddocs=True)
+ replica_uid=None, ensure_ddocs=True,
+ database_security=db_security)
print ('success! Created %s, replica_uid: %s' %
(db._dbname, db.replica_uid))
diff --git a/server/src/leap/soledad/server/__init__.py b/server/src/leap/soledad/server/__init__.py
index f64d07bf..4d03c82a 100644
--- a/server/src/leap/soledad/server/__init__.py
+++ b/server/src/leap/soledad/server/__init__.py
@@ -272,6 +272,20 @@ http_app.HTTPInvocationByMethodWithBody = HTTPInvocationByMethodWithBody
# ----------------------------------------------------------------------------
# Auxiliary functions
# ----------------------------------------------------------------------------
+CONFIG_DEFAULTS = {
+ 'soledad-server': {
+ 'couch_url': 'http://localhost:5984',
+ 'create_cmd': None,
+ 'admin_netrc': '/etc/couchdb/couchdb-admin.netrc',
+ },
+ 'database-security': {
+ 'members': ['soledad'],
+ 'members_roles': [],
+ 'admins': [],
+ 'admins_roles': []
+ }
+}
+
def load_configuration(file_path):
"""
@@ -283,17 +297,18 @@ def load_configuration(file_path):
@return: A dictionary with the configuration.
@rtype: dict
"""
- defaults = {
- 'couch_url': 'http://localhost:5984',
- 'create_cmd': None,
- 'admin_netrc': '/etc/couchdb/couchdb-admin.netrc',
- }
+ defaults = dict(CONFIG_DEFAULTS)
config = configparser.ConfigParser()
config.read(file_path)
- if 'soledad-server' in config:
- for key in defaults:
- if key in config['soledad-server']:
- defaults[key] = config['soledad-server'][key]
+ for section in defaults.keys():
+ if section in config:
+ for key in defaults[section]:
+ if key in config[section]:
+ defaults[section][key] = config[section][key]
+ for key, value in defaults['database-security'].iteritems():
+ if type(value) is not unicode: continue
+ defaults['database-security'][key] = \
+ [item.strip() for item in value.split(',')]
# TODO: implement basic parsing/sanitization of options comming from
# config file.
return defaults
@@ -305,6 +320,7 @@ def load_configuration(file_path):
def application(environ, start_response):
conf = load_configuration('/etc/soledad/soledad-server.conf')
+ conf = conf['soledad-server']
state = CouchServerState(conf['couch_url'], create_cmd=conf['create_cmd'])
# WSGI application that may be used by `twistd -web`
application = GzipMiddleware(