]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: check the cephx mds auth access for open
authorXiubo Li <xiubli@redhat.com>
Fri, 9 Sep 2022 04:32:17 +0000 (12:32 +0800)
committerXiubo Li <xiubli@redhat.com>
Wed, 27 Mar 2024 00:42:41 +0000 (08:42 +0800)
Before opening the file locally we need to check the cephx access.

Fixes: https://tracker.ceph.com/issues/57154
Signed-off-by: Xiubo Li <xiubli@redhat.com>
(cherry picked from commit ce216595c0391fc4b7e3c0f5b3be88aa4f67d245)

src/client/Client.cc

index 7c23c52bdc76458ad88cd056b8eab331fbe675f6..f05b898dc69880198fd2c9249f5633a6d0bca088 100644 (file)
@@ -10258,11 +10258,31 @@ int Client::_open(Inode *in, int flags, mode_t mode, Fh **fhp,
 
   in->get_open_ref(cmode);  // make note of pending open, since it effects _wanted_ caps.
 
+  int do_sync = true;
   if ((flags & O_TRUNC) == 0 && in->caps_issued_mask(want)) {
-    // update wanted?
-    check_caps(in, CHECK_CAPS_NODELAY);
-  } else {
+    int mask = MAY_READ;
+
+    if (cmode & CEPH_FILE_MODE_WR) {
+      mask |= MAY_WRITE;
+    }
+
+    std::string path;
+    int result = in->make_path_string(path);
+    if (result) {
+      ldout(cct, 20) << __func__ << " absolute path: " << path << dendl;
+      if (path.length())
+        path = path.substr(1);    // drop leading /
+      result = mds_check_access(path, perms, mask);
+      if (result) {
+        return result;
+      }
+      // update wanted?
+      check_caps(in, CHECK_CAPS_NODELAY);
+      do_sync = false;
+    }
+  }
 
+  if (do_sync) {
     MetaRequest *req = new MetaRequest(CEPH_MDS_OP_OPEN);
     filepath path;
     in->make_nosnap_relative_path(path);