From: Alfonso Martínez Date: Tue, 20 Aug 2019 08:35:06 +0000 (+0200) Subject: mgr/dashboard: change bucket owner between owners from same tenant X-Git-Tag: v14.2.5~153^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f26722530ef0900edf3fc7260e10e5895032fcf3;p=ceph.git mgr/dashboard: change bucket owner between owners from same tenant Since https://github.com/ceph/ceph/pull/28813 is in master, the bucket operations (with tenanted owners) behaviour has changed regarding nautilus, so this fix is applied to nautilus directly. Fixes: https://tracker.ceph.com/issues/41067 Signed-off-by: Alfonso Martínez --- diff --git a/qa/tasks/mgr/dashboard/test_rgw.py b/qa/tasks/mgr/dashboard/test_rgw.py index b4c0676b0dd..34f337f8df3 100644 --- a/qa/tasks/mgr/dashboard/test_rgw.py +++ b/qa/tasks/mgr/dashboard/test_rgw.py @@ -114,16 +114,22 @@ class RgwBucketTest(RgwTestCase): def setUpClass(cls): cls.create_test_user = True super(RgwBucketTest, cls).setUpClass() - # Create a tenanted user. + # Create tenanted users. cls._radosgw_admin_cmd([ 'user', 'create', '--tenant', 'testx', '--uid', 'teuth-test-user', '--display-name', 'tenanted teuth-test-user' ]) + cls._radosgw_admin_cmd([ + 'user', 'create', '--tenant', 'testx', '--uid', 'teuth-test-user2', + '--display-name', 'tenanted teuth-test-user 2' + ]) @classmethod def tearDownClass(cls): cls._radosgw_admin_cmd( ['user', 'rm', '--tenant', 'testx', '--uid=teuth-test-user']) + cls._radosgw_admin_cmd( + ['user', 'rm', '--tenant', 'testx', '--uid=teuth-test-user2']) super(RgwBucketTest, cls).tearDownClass() def test_all(self): @@ -232,7 +238,22 @@ class RgwBucketTest(RgwTestCase): self.assertEqual(data['tenant'], 'testx') self.assertEqual(data['bid'], 'testx/teuth-test-bucket') - # Update the bucket. + # Update bucket: different user from same tenant. + self._put( + '/api/rgw/bucket/{}'.format( + urllib.quote_plus('testx/teuth-test-bucket')), + params={ + 'bucket_id': data['id'], + 'uid': 'testx$teuth-test-user2' + }) + self.assertStatus(200) + data = self._get('/api/rgw/bucket/{}'.format( + urllib.quote_plus('testx/teuth-test-bucket'))) + self.assertStatus(200) + self.assertIn('owner', data) + self.assertEqual(data['owner'], 'testx$teuth-test-user2') + + # Update bucket: different user from empty tenant. self._put( '/api/rgw/bucket/{}'.format( urllib.quote_plus('testx/teuth-test-bucket')), diff --git a/src/pybind/mgr/dashboard/controllers/rgw.py b/src/pybind/mgr/dashboard/controllers/rgw.py index 871fa00fdf4..bd7a12b7be2 100644 --- a/src/pybind/mgr/dashboard/controllers/rgw.py +++ b/src/pybind/mgr/dashboard/controllers/rgw.py @@ -121,6 +121,26 @@ class RgwBucket(RgwRESTController): if bucket['tenant'] else bucket['bucket'] return bucket + @staticmethod + def strip_tenant_from_bucket_name(bucket_name, uid): + # type (str, str) => str + """ + When linking a bucket to a new user belonging to same tenant + as the previous owner, tenant must be removed from the bucket name. + >>> RgwBucket.strip_tenant_from_bucket_name('tenant/bucket-name', 'tenant$user1') + 'bucket-name' + >>> RgwBucket.strip_tenant_from_bucket_name('tenant/bucket-name', 'tenant2$user2') + 'tenant/bucket-name' + >>> RgwBucket.strip_tenant_from_bucket_name('bucket-name', 'user1') + 'bucket-name' + """ + bucket_tenant = bucket_name[:bucket_name.find('/')] if bucket_name.find('/') >= 0 else None + uid_tenant = uid[:uid.find('$')] if uid.find('$') >= 0 else None + if bucket_tenant and uid_tenant and bucket_tenant == uid_tenant: + return bucket_name[bucket_name.find('/') + 1:] + + return bucket_name + def list(self): return self.proxy('GET', 'bucket') @@ -137,7 +157,7 @@ class RgwBucket(RgwRESTController): def set(self, bucket, bucket_id, uid): result = self.proxy('PUT', 'bucket', { - 'bucket': bucket, + 'bucket': RgwBucket.strip_tenant_from_bucket_name(bucket, uid), 'bucket-id': bucket_id, 'uid': uid }, json_response=False) diff --git a/src/pybind/mgr/dashboard/tox.ini b/src/pybind/mgr/dashboard/tox.ini index d404d59abe1..b5daa9278e3 100644 --- a/src/pybind/mgr/dashboard/tox.ini +++ b/src/pybind/mgr/dashboard/tox.ini @@ -20,7 +20,7 @@ commands= py27: pip install -r {toxinidir}/requirements-py27.txt py3: pip install -r {toxinidir}/requirements-py3.txt cov: coverage erase - cov: {envbindir}/py.test --cov=. --cov-report= --junitxml=junit.{envname}.xml --doctest-modules controllers/rbd.py services/ tests/ tools.py + cov: {envbindir}/py.test --cov=. --cov-report= --junitxml=junit.{envname}.xml --doctest-modules controllers services/ tests/ tools.py cov: coverage combine {toxinidir}/{env:COVERAGE_FILE} cov: coverage report cov: coverage xml