Skip to content

Commit f6bb579

Browse files
mds/MDSAuthCaps: allow updating root_squash in entity's MDS cap
Command "ceph fs authorize" can update fsname, path and perm/spec in a MDS cap but it can't update "root_squash" in it. Add code to allow this. Specifically, "MDSAuthCaps::merge_one_cap_grant()" doesn't check if the value for "root_squash" needs an update while attempting to merge the new MDS cap into the list of MDS caps already held by an entity. It should do so to ensure correct behaviour. Fixes: https://tracker.ceph.com/issues/64417 Signed-off-by: Rishabh Dave <[email protected]>
1 parent 56e0f73 commit f6bb579

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

qa/tasks/cephfs/test_admin.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,7 @@ def test_adding_multiple_caps(self):
14861486
the entity's caps when multiple caps are passed to it in one go.
14871487
14881488
Tests: https://tracker.ceph.com/issues/64127
1489+
Tests: https://tracker.ceph.com/issues/64417
14891490
'''
14901491
DIR = 'dir1'
14911492
self.mount_a.run_shell(f'mkdir {DIR}')
@@ -1498,6 +1499,12 @@ def test_adding_multiple_caps(self):
14981499
# https://tracker.ceph.com/issues/64127 has been fixed
14991500
keyring = self.fs.authorize(self.client_id, FS_AUTH_CAPS)
15001501

1502+
# The fact that following lines passes means
1503+
# https://tracker.ceph.com/issues/64417 has been fixed.
1504+
mdscaps = (f'allow rw fsname={self.fs.name} root_squash, '
1505+
f'allow rw fsname={self.fs.name} path={DIR}')
1506+
self.assertIn(mdscaps, keyring)
1507+
15011508
self._remount_and_run_tests(FS_AUTH_CAPS, keyring)
15021509

15031510
def _remount_and_run_tests(self, fs_auth_caps, keyring):

src/mds/MDSAuthCaps.cc

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,18 +392,36 @@ bool MDSAuthCaps::merge_one_cap_grant(MDSCapGrant ng)
392392
// check if "ng" is already present in this cap object.
393393
for (auto& g : grants) {
394394
if (g.match.fs_name == ng.match.fs_name && g.match.path == ng.match.path) {
395-
if (g.spec.get_caps() == ng.spec.get_caps()) {
396-
// no update required. maintaining idempotency.
395+
if (g.spec.get_caps() == ng.spec.get_caps() &&
396+
g.match.root_squash == ng.match.root_squash) {
397+
// Since all components of MDS caps (fsname, path, perm/spec and
398+
// root_squash) matched, it means cap same as "ng" is present in MDS
399+
// cap grant list. No need to look further in MDS cap grant list.
400+
// No update is required. Maintain idempotency.
397401
return false;
398-
} else {
399-
// "ng" is present but perm/spec is different. update it.
402+
}
403+
404+
// fsname and path match but perm/spec is different. update the cap
405+
// with new perm/spec.
406+
if (g.spec.get_caps() != ng.spec.get_caps()) {
400407
g.spec.set_caps(ng.spec.get_caps());
401-
return true;
402408
}
409+
410+
// fsname and path match but value of root_squash is different. update
411+
// its value.
412+
if (g.match.root_squash != ng.match.root_squash) {
413+
g.match.root_squash = ng.match.root_squash;
414+
}
415+
416+
// Since fsname and path matched and either perm/spec or root_squash
417+
// or both has been updated, cap from "ng" has been incorporated
418+
// into this cap grant list. Time to return.
419+
return true;
403420
}
404421
}
405422

406-
// since "ng" is absent in this cap object, add it.
423+
// Since a cap grant like "ng" is absent in this cap object's grant list,
424+
// add "ng" to the cap grant list.
407425
grants.push_back(MDSCapGrant(
408426
MDSCapSpec(ng.spec.get_caps()),
409427
MDSCapMatch(ng.match.fs_name, ng.match.path, ng.match.root_squash),

0 commit comments

Comments
 (0)