]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
qa: add test for checking access in client side of root_squash
authorXiubo Li <xiubli@redhat.com>
Wed, 2 Nov 2022 01:12:16 +0000 (09:12 +0800)
committerXiubo Li <xiubli@redhat.com>
Mon, 11 Sep 2023 01:29:46 +0000 (09:29 +0800)
Test the 'chown' and 'truncate', which will call the setattr and
'cat' will open the files. Before each testing will open the file
by non-root user and keep it to make sure the Fxw caps are issued,
and then user the 'sudo' do to the tests, which will set the uid/gid
to 0/0.

Fixes: https://tracker.ceph.com/issues/57154
Signed-off-by: Xiubo Li <xiubli@redhat.com>
qa/tasks/cephfs/caps_helper.py
qa/tasks/cephfs/test_admin.py

index bf6e2f9278f39f31b2c9a7029ad59bd2084d361d..f083c788337aea699aa35867d0c8cf53e35cd831 100644 (file)
@@ -268,10 +268,10 @@ class MdsCapTester:
         else:
             raise RuntimeError(f'perm = {perm}\nIt should be "r" or "rw".')
 
-    def conduct_pos_test_for_read_caps(self):
+    def conduct_pos_test_for_read_caps(self, sudo_read=False):
         log.info(f'test read perm: read file {self.path} and expect data '
                  f'"{self.data}"')
-        contents = self.mount.read_file(self.path)
+        contents = self.mount.read_file(self.path, sudo_read)
         assert_equal(self.data, contents)
         log.info(f'read perm was tested successfully: "{self.data}" was '
                  f'successfully read from path {self.path}')
@@ -318,3 +318,34 @@ class CapTester(MonCapTester, MdsCapTester):
     def run_cap_tests(self, fs, client_id, perm, mntpt=None):
         self.run_mon_cap_tests(fs, client_id)
         self.run_mds_cap_tests(perm, mntpt)
+
+    def _conduct_neg_test_for_root_squash_caps(self, _cmdargs, sudo_write=False):
+        possible_errmsgs = ('permission denied', 'operation not permitted')
+        cmdargs = ['sudo'] if sudo_write else ['']
+        cmdargs += _cmdargs
+
+        log.info(f'test absence of {_cmdargs[0]} perm: expect failure {self.path}.')
+
+        # open the file and hold it. The MDS will issue CEPH_CAP_EXCL_*
+        # to mount
+        proc = self.mount.open_background(self.path)
+
+        cmdargs.append(self.path)
+        self.mount.negtestcmd(args=cmdargs, retval=1, errmsgs=possible_errmsgs)
+        cmdargs.pop(-1)
+
+        self.mount._kill_background(proc)
+
+        log.info(f'absence of {_cmdargs[0]} perm was tested successfully')
+
+    def conduct_neg_test_for_chown_caps(self, sudo_write=True):
+        # flip ownership to nobody. assumption: nobody's id is 65534
+        cmdargs = ['chown', '-h', '65534:65534']
+        self._conduct_neg_test_for_root_squash_caps(cmdargs, sudo_write)
+
+    def conduct_neg_test_for_truncate_caps(self, sudo_write=True):
+        cmdargs = ['truncate', '-s', '10GB']
+        self._conduct_neg_test_for_root_squash_caps(cmdargs, sudo_write)
+
+    def conduct_pos_test_for_open_caps(self, sudo_read=True):
+        self.conduct_pos_test_for_read_caps(sudo_read)
index 3bb02400279892810ec11899caf7bd723bef60e0..219ce59ca2c5e78f622f165eb8e80560054ebc24 100644 (file)
@@ -1259,7 +1259,10 @@ class TestFsAuthorize(CephFSTestCase):
         # Since root_squash is set in client caps, client can read but not
         # write even thought access level is set to "rw".
         self.captester.conduct_pos_test_for_read_caps()
+        self.captester.conduct_pos_test_for_open_caps()
         self.captester.conduct_neg_test_for_write_caps(sudo_write=True)
+        self.captester.conduct_neg_test_for_chown_caps()
+        self.captester.conduct_neg_test_for_truncate_caps()
 
     def test_single_path_authorize_on_nonalphanumeric_fsname(self):
         """