14f8ab
From 4a2441e76f4240568093080769ede07bb7fb2016 Mon Sep 17 00:00:00 2001
14f8ab
From: Kotresh HR <khiremat@redhat.com>
14f8ab
Date: Sun, 20 Oct 2019 01:01:39 +0530
14f8ab
Subject: [PATCH 311/313] geo-rep: Fix Permission denied traceback on non root
14f8ab
 setup
14f8ab
14f8ab
Problem:
14f8ab
While syncing rename of directory in hybrid crawl, geo-rep
14f8ab
crashes as below.
14f8ab
14f8ab
Traceback (most recent call last):
14f8ab
  File "/usr/local/libexec/glusterfs/python/syncdaemon/repce.py", line 118, in worker
14f8ab
    res = getattr(self.obj, rmeth)(*in_data[2:])
14f8ab
  File "/usr/local/libexec/glusterfs/python/syncdaemon/resource.py", line 588, in entry_ops
14f8ab
    src_entry = get_slv_dir_path(slv_host, slv_volume, gfid)
14f8ab
  File "/usr/local/libexec/glusterfs/python/syncdaemon/syncdutils.py", line 687, in get_slv_dir_path
14f8ab
    [ENOENT], [ESTALE])
14f8ab
  File "/usr/local/libexec/glusterfs/python/syncdaemon/syncdutils.py", line 546, in errno_wrap
14f8ab
    return call(*arg)
14f8ab
PermissionError: [Errno 13] Permission denied: '/bricks/brick1/b1/.glusterfs/8e/c0/8ec0fcd4-d50f-4a6e-b473-a7943ab66640'
14f8ab
14f8ab
Cause:
14f8ab
Conversion of gfid to path for a directory uses readlink on backend
14f8ab
.glusterfs gfid path. But this fails for non root user with
14f8ab
permission denied.
14f8ab
14f8ab
Fix:
14f8ab
Use gfid2path interface to get the path from gfid
14f8ab
14f8ab
Backport of:
14f8ab
 > Patch: https://review.gluster.org/23570
14f8ab
 > Change-Id: I9d40c713a1b32cea95144cbc0f384ada82972222
14f8ab
 > fixes: bz#1763439
14f8ab
 > Signed-off-by: Kotresh HR <khiremat@redhat.com>
14f8ab
14f8ab
Change-Id: I9d40c713a1b32cea95144cbc0f384ada82972222
14f8ab
BUG: 1763412
14f8ab
Signed-off-by: Kotresh HR <khiremat@redhat.com>
14f8ab
Reviewed-on: https://code.engineering.redhat.com/gerrit/183665
14f8ab
Tested-by: RHGS Build Bot <nigelb@redhat.com>
14f8ab
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
14f8ab
---
14f8ab
 geo-replication/syncdaemon/gsyncd.py               |  3 +-
14f8ab
 geo-replication/syncdaemon/syncdutils.py           | 35 ++++++++++++++++------
14f8ab
 tests/00-geo-rep/00-georep-verify-non-root-setup.t | 30 +++++++++++++++----
14f8ab
 3 files changed, 52 insertions(+), 16 deletions(-)
14f8ab
14f8ab
diff --git a/geo-replication/syncdaemon/gsyncd.py b/geo-replication/syncdaemon/gsyncd.py
14f8ab
index 7b48d82..8940384 100644
14f8ab
--- a/geo-replication/syncdaemon/gsyncd.py
14f8ab
+++ b/geo-replication/syncdaemon/gsyncd.py
14f8ab
@@ -231,7 +231,8 @@ def main():
14f8ab
     # Set default path for config file in that case
14f8ab
     # If an subcmd accepts config file then it also accepts
14f8ab
     # master and Slave arguments.
14f8ab
-    if config_file is None and hasattr(args, "config_file"):
14f8ab
+    if config_file is None and hasattr(args, "config_file") \
14f8ab
+        and args.subcmd != "slave":
14f8ab
         config_file = "%s/geo-replication/%s_%s_%s/gsyncd.conf" % (
14f8ab
             GLUSTERD_WORKDIR,
14f8ab
             args.master,
14f8ab
diff --git a/geo-replication/syncdaemon/syncdutils.py b/geo-replication/syncdaemon/syncdutils.py
14f8ab
index aadaebd..b08098e 100644
14f8ab
--- a/geo-replication/syncdaemon/syncdutils.py
14f8ab
+++ b/geo-replication/syncdaemon/syncdutils.py
14f8ab
@@ -57,6 +57,7 @@ from hashlib import sha256 as sha256
14f8ab
 
14f8ab
 # auxiliary gfid based access prefix
14f8ab
 _CL_AUX_GFID_PFX = ".gfid/"
14f8ab
+ROOT_GFID = "00000000-0000-0000-0000-000000000001"
14f8ab
 GF_OP_RETRIES = 10
14f8ab
 
14f8ab
 GX_GFID_CANONICAL_LEN = 37  # canonical gfid len + '\0'
14f8ab
@@ -670,6 +671,7 @@ def get_slv_dir_path(slv_host, slv_volume, gfid):
14f8ab
     global slv_bricks
14f8ab
 
14f8ab
     dir_path = ENOENT
14f8ab
+    pfx = gauxpfx()
14f8ab
 
14f8ab
     if not slv_bricks:
14f8ab
         slv_info = Volinfo(slv_volume, slv_host, master=False)
14f8ab
@@ -683,15 +685,30 @@ def get_slv_dir_path(slv_host, slv_volume, gfid):
14f8ab
                                gfid[2:4],
14f8ab
                                gfid], [ENOENT], [ESTALE])
14f8ab
         if dir_path != ENOENT:
14f8ab
-            realpath = errno_wrap(os.readlink, [dir_path],
14f8ab
-                                  [ENOENT], [ESTALE])
14f8ab
-            if not isinstance(realpath, int):
14f8ab
-                realpath_parts = realpath.split('/')
14f8ab
-                pargfid = realpath_parts[-2]
14f8ab
-                basename = realpath_parts[-1]
14f8ab
-                pfx = gauxpfx()
14f8ab
-                dir_entry = os.path.join(pfx, pargfid, basename)
14f8ab
-                return dir_entry
14f8ab
+            try:
14f8ab
+                realpath = errno_wrap(os.readlink, [dir_path],
14f8ab
+                                      [ENOENT], [ESTALE])
14f8ab
+                if not isinstance(realpath, int):
14f8ab
+                    realpath_parts = realpath.split('/')
14f8ab
+                    pargfid = realpath_parts[-2]
14f8ab
+                    basename = realpath_parts[-1]
14f8ab
+                    dir_entry = os.path.join(pfx, pargfid, basename)
14f8ab
+                    return dir_entry
14f8ab
+            except OSError:
14f8ab
+                # .gfid/GFID
14f8ab
+                gfidpath = unescape_space_newline(os.path.join(pfx, gfid))
14f8ab
+                realpath = errno_wrap(Xattr.lgetxattr_buf,
14f8ab
+                      [gfidpath, 'glusterfs.gfid2path'], [ENOENT], [ESTALE])
14f8ab
+                if not isinstance(realpath, int):
14f8ab
+                    basename = os.path.basename(realpath).rstrip('\x00')
14f8ab
+                    dirpath = os.path.dirname(realpath)
14f8ab
+                    if dirpath is "/":
14f8ab
+                        pargfid = ROOT_GFID
14f8ab
+                    else:
14f8ab
+                        dirpath = dirpath.strip("/")
14f8ab
+                        pargfid = get_gfid_from_mnt(dirpath)
14f8ab
+                    dir_entry = os.path.join(pfx, pargfid, basename)
14f8ab
+                    return dir_entry
14f8ab
 
14f8ab
     return None
14f8ab
 
14f8ab
diff --git a/tests/00-geo-rep/00-georep-verify-non-root-setup.t b/tests/00-geo-rep/00-georep-verify-non-root-setup.t
14f8ab
index e753c1f..c9fd8b2 100644
14f8ab
--- a/tests/00-geo-rep/00-georep-verify-non-root-setup.t
14f8ab
+++ b/tests/00-geo-rep/00-georep-verify-non-root-setup.t
14f8ab
@@ -118,8 +118,8 @@ clean_lock_files
14f8ab
 TEST /usr/sbin/groupadd $grp
14f8ab
 
14f8ab
 clean_lock_files
14f8ab
-##Create non-root user and assign it to newly created group
14f8ab
-
14f8ab
+##Del if exists and create non-root user and assign it to newly created group
14f8ab
+userdel -r -f $usr
14f8ab
 TEST /usr/sbin/useradd -G $grp $usr
14f8ab
 
14f8ab
 ##Modify password for non-root user to have control over distributing ssh-key
14f8ab
@@ -140,8 +140,6 @@ TEST killall_gluster;
14f8ab
 TEST glusterd;
14f8ab
 TEST pidof glusterd;
14f8ab
 
14f8ab
-
14f8ab
-
14f8ab
 ##Create, start and mount meta_volume
14f8ab
 TEST $CLI volume create $META_VOL replica 3 $H0:$B0/${META_VOL}{1,2,3};
14f8ab
 TEST $CLI volume start $META_VOL
14f8ab
@@ -225,6 +223,26 @@ TEST $GEOREP_CLI  $master $slave_url resume
14f8ab
 #Validate failure of volume stop when geo-rep is running
14f8ab
 TEST ! $CLI volume stop $GMV0
14f8ab
 
14f8ab
+#Hybrid directory rename test BZ#1763439
14f8ab
+TEST $GEOREP_CLI $master $slave_url config change_detector xsync
14f8ab
+mkdir ${master_mnt}/dir1
14f8ab
+mkdir ${master_mnt}/dir1/dir2
14f8ab
+mkdir ${master_mnt}/dir1/dir3
14f8ab
+mkdir ${master_mnt}/hybrid_d1
14f8ab
+
14f8ab
+EXPECT_WITHIN $GEO_REP_TIMEOUT 0 directory_ok ${slave_mnt}/hybrid_d1
14f8ab
+EXPECT_WITHIN $GEO_REP_TIMEOUT 0 directory_ok ${slave_mnt}/dir1
14f8ab
+EXPECT_WITHIN $GEO_REP_TIMEOUT 0 directory_ok ${slave_mnt}/dir1/dir2
14f8ab
+EXPECT_WITHIN $GEO_REP_TIMEOUT 0 directory_ok ${slave_mnt}/dir1/dir3
14f8ab
+
14f8ab
+mv ${master_mnt}/hybrid_d1 ${master_mnt}/hybrid_rn_d1
14f8ab
+mv ${master_mnt}/dir1/dir2 ${master_mnt}/rn_dir2
14f8ab
+mv ${master_mnt}/dir1/dir3 ${master_mnt}/dir1/rn_dir3
14f8ab
+
14f8ab
+EXPECT_WITHIN $GEO_REP_TIMEOUT 0 directory_ok ${slave_mnt}/hybrid_rn_d1
14f8ab
+EXPECT_WITHIN $GEO_REP_TIMEOUT 0 directory_ok ${slave_mnt}/rn_dir2
14f8ab
+EXPECT_WITHIN $GEO_REP_TIMEOUT 0 directory_ok ${slave_mnt}/dir1/rn_dir3
14f8ab
+
14f8ab
 #Stop Geo-rep
14f8ab
 TEST $GEOREP_CLI $master $slave_url stop
14f8ab
 
14f8ab
@@ -232,8 +250,8 @@ TEST $GEOREP_CLI $master $slave_url stop
14f8ab
 TEST $GEOREP_CLI $master $slave_url delete
14f8ab
 
14f8ab
 #Cleanup authorized_keys
14f8ab
-sed -i '/^command=.*SSH_ORIGINAL_COMMAND#.*/d' ~/.ssh/authorized_keys
14f8ab
-sed -i '/^command=.*gsyncd.*/d' ~/.ssh/authorized_keys
14f8ab
+sed -i '/^command=.*SSH_ORIGINAL_COMMAND#.*/d' /home/$usr/.ssh/authorized_keys
14f8ab
+sed -i '/^command=.*gsyncd.*/d' /home/$usr/.ssh/authorized_keys
14f8ab
 
14f8ab
 #clear mountbroker
14f8ab
 gluster-mountbroker remove --user $usr
14f8ab
-- 
14f8ab
1.8.3.1
14f8ab