Request class-read object_prefix rbd_children perm

When using ceph as a backend request the additional privilege
class-read on rbd_children. This fixes bug 1696073.

Change-Id: Ie4341eb834ae6fe02424c75e31f16f1cf5411f21
Closes-Bug: #1696073
Depends-On: Icf844ec7d33f2e558dee7935fe5fa3d7f08e0d59
This commit is contained in:
Liam Young 2017-12-14 14:15:32 +00:00
parent b95ad9c023
commit 4b9e5c393b
4 changed files with 28 additions and 9 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ trusty
.idea
.stestr
func-results.json
__pycache__

View File

@ -1064,14 +1064,24 @@ class CephBrokerRq(object):
self.ops = []
def add_op_request_access_to_group(self, name, namespace=None,
permission=None, key_name=None):
permission=None, key_name=None,
object_prefix_permissions=None):
"""
Adds the requested permissions to the current service's Ceph key,
allowing the key to access only the specified pools
allowing the key to access only the specified pools or
object prefixes. object_prefix_permissions should be a dictionary
keyed on the permission with the corresponding value being a list
of prefixes to apply that permission to.
{
'rwx': ['prefix1', 'prefix2'],
'class-read': ['prefix3']}
"""
self.ops.append({'op': 'add-permissions-to-key', 'group': name,
'namespace': namespace, 'name': key_name or service_name(),
'group-permission': permission})
self.ops.append({
'op': 'add-permissions-to-key', 'group': name,
'namespace': namespace,
'name': key_name or service_name(),
'group-permission': permission,
'object-prefix-permissions': object_prefix_permissions})
def add_op_create_pool(self, name, replica_count=3, pg_num=None,
weight=None, group=None, namespace=None):
@ -1107,7 +1117,10 @@ class CephBrokerRq(object):
def _ops_equal(self, other):
if len(self.ops) == len(other.ops):
for req_no in range(0, len(self.ops)):
for key in ['replicas', 'name', 'op', 'pg_num', 'weight']:
for key in [
'replicas', 'name', 'op', 'pg_num', 'weight',
'group', 'group-namespace', 'group-permission',
'object-prefix-permissions']:
if self.ops[req_no].get(key) != other.ops[req_no].get(key):
return False
else:

View File

@ -307,8 +307,10 @@ def get_ceph_request():
rq.add_op_create_pool(name=service, replica_count=replicas,
weight=weight, group='images')
if config('restrict-ceph-pools'):
rq.add_op_request_access_to_group(name="images",
permission='rwx')
rq.add_op_request_access_to_group(
name="images",
object_prefix_permissions={'class-read': ['rbd_children']},
permission='rwx')
return rq

View File

@ -485,7 +485,10 @@ class GlanceRelationTests(CharmTestCase):
mock_create_pool.assert_called_with(name='glance', replica_count=3,
weight=6, group='images')
mock_request_access.assert_has_calls([
call(name='images', permission='rwx'),
call(
name='images',
object_prefix_permissions={'class-read': ['rbd_children']},
permission='rwx'),
])
@patch.object(relations, 'get_ceph_request')