]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/nfs: Check if pseudo path is absolute path or just '/'
authorVarsha Rao <varao@redhat.com>
Thu, 16 Jul 2020 10:50:36 +0000 (16:20 +0530)
committerVarsha Rao <varao@redhat.com>
Thu, 23 Jul 2020 07:33:38 +0000 (13:03 +0530)
Fixes: https://tracker.ceph.com/issues/46565
Signed-off-by: Varsha Rao <varao@redhat.com>
src/pybind/mgr/volumes/fs/nfs.py

index 279d73e30ed111eee263c4c94fe3ce34252ccb93..a08646d33655b9cda25ff872f7bfe48780473b91 100644 (file)
@@ -3,6 +3,7 @@ import json
 import logging
 from typing import List
 import socket
+from os.path import isabs, normpath
 
 from ceph.deployment.service_spec import NFSServiceSpec, PlacementSpec
 from rados import TimedOut
@@ -514,9 +515,9 @@ class FSExport(object):
 
     def format_path(self, path):
         if path:
-            path = path.strip()
-            if len(path) > 1 and path[-1] == '/':
-                path = path[:-1]
+            path = normpath(path.strip())
+            if path[:2] == "//":
+                path = path[1:]
         return path
 
     def check_fs(self, fs_name):
@@ -529,6 +530,11 @@ class FSExport(object):
             if not self.check_fs(fs_name):
                 return -errno.ENOENT, "", f"filesystem {fs_name} not found"
 
+            pseudo_path = self.format_path(pseudo_path)
+            if not isabs(pseudo_path) or pseudo_path == "/":
+                return -errno.EINVAL, "", f"pseudo path {pseudo_path} is invalid. "\
+                        "It should not be absolute path or just '/'."
+
             if cluster_id not in self.exports:
                 self.exports[cluster_id] = []
 
@@ -541,7 +547,7 @@ class FSExport(object):
                     access_type = "RO"
                 ex_dict = {
                         'path': self.format_path(path),
-                        'pseudo': self.format_path(pseudo_path),
+                        'pseudo': pseudo_path,
                         'cluster_id': cluster_id,
                         'access_type': access_type,
                         'fsal': {"name": "CEPH", "user_id": user_id,