1df6c8
From 02a93265fe4e78e7fc3fa8c6caa773cbe02f50b6 Mon Sep 17 00:00:00 2001
1df6c8
From: Anoop C S <anoopcs@redhat.com>
1df6c8
Date: Fri, 20 Dec 2019 16:01:59 +0530
1df6c8
Subject: [PATCH 344/344] Revert all fixes to include SELinux hook scripts
1df6c8
1df6c8
Following are the reverts included with this change:
1df6c8
1df6c8
Revert "extras/hooks: syntactical errors in SELinux hooks, scipt logic improved"
1df6c8
Revert "Revert "hooks: remove selinux hooks""
1df6c8
Revert "tests: subdir-mount.t is failing for brick_mux regrssion"
1df6c8
Revert "extras/hooks: Install and package newly added post add-brick hook script"
1df6c8
Revert "extras/hooks: Add SELinux label on new bricks during add-brick"
1df6c8
1df6c8
Label: DOWNSTREAM ONLY
1df6c8
1df6c8
See bug for more details.
1df6c8
1df6c8
Change-Id: I5c9b9e0e6446568ce16af17257fa39338198a827
1df6c8
BUG: 1686800
1df6c8
Signed-off-by: Anoop C S <anoopcs@redhat.com>
1df6c8
Reviewed-on: https://code.engineering.redhat.com/gerrit/188169
1df6c8
Tested-by: RHGS Build Bot <nigelb@redhat.com>
1df6c8
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
1df6c8
---
1df6c8
 configure.ac                                       |   4 -
1df6c8
 extras/hook-scripts/Makefile.am                    |   2 +-
1df6c8
 extras/hook-scripts/add-brick/post/Makefile.am     |   4 +-
1df6c8
 .../add-brick/post/S10selinux-label-brick.sh       | 100 ---------------------
1df6c8
 extras/hook-scripts/create/Makefile.am             |   1 -
1df6c8
 extras/hook-scripts/create/post/Makefile.am        |   6 --
1df6c8
 .../create/post/S10selinux-label-brick.sh          |  13 ++-
1df6c8
 extras/hook-scripts/delete/Makefile.am             |   1 -
1df6c8
 extras/hook-scripts/delete/pre/Makefile.am         |   6 --
1df6c8
 .../delete/pre/S10selinux-del-fcontext.sh          |  60 ++++++-------
1df6c8
 glusterfs.spec.in                                  |   3 -
1df6c8
 tests/bugs/glusterfs-server/bug-877992.t           |   4 +-
1df6c8
 tests/features/subdir-mount.t                      |  11 +--
1df6c8
 13 files changed, 37 insertions(+), 178 deletions(-)
1df6c8
 delete mode 100755 extras/hook-scripts/add-brick/post/S10selinux-label-brick.sh
1df6c8
 delete mode 100644 extras/hook-scripts/create/Makefile.am
1df6c8
 delete mode 100644 extras/hook-scripts/create/post/Makefile.am
1df6c8
 delete mode 100644 extras/hook-scripts/delete/Makefile.am
1df6c8
 delete mode 100644 extras/hook-scripts/delete/pre/Makefile.am
1df6c8
1df6c8
diff --git a/configure.ac b/configure.ac
1df6c8
index 98ee311..327733e 100644
1df6c8
--- a/configure.ac
1df6c8
+++ b/configure.ac
1df6c8
@@ -221,10 +221,6 @@ AC_CONFIG_FILES([Makefile
1df6c8
                 extras/hook-scripts/add-brick/Makefile
1df6c8
                 extras/hook-scripts/add-brick/pre/Makefile
1df6c8
                 extras/hook-scripts/add-brick/post/Makefile
1df6c8
-                extras/hook-scripts/create/Makefile
1df6c8
-                extras/hook-scripts/create/post/Makefile
1df6c8
-                extras/hook-scripts/delete/Makefile
1df6c8
-                extras/hook-scripts/delete/pre/Makefile
1df6c8
                 extras/hook-scripts/start/Makefile
1df6c8
                 extras/hook-scripts/start/post/Makefile
1df6c8
                 extras/hook-scripts/set/Makefile
1df6c8
diff --git a/extras/hook-scripts/Makefile.am b/extras/hook-scripts/Makefile.am
1df6c8
index 26059d7..771b37e 100644
1df6c8
--- a/extras/hook-scripts/Makefile.am
1df6c8
+++ b/extras/hook-scripts/Makefile.am
1df6c8
@@ -1,5 +1,5 @@
1df6c8
 EXTRA_DIST = S40ufo-stop.py S56glusterd-geo-rep-create-post.sh
1df6c8
-SUBDIRS = add-brick create delete set start stop reset
1df6c8
+SUBDIRS = add-brick set start stop reset
1df6c8
 
1df6c8
 scriptsdir = $(GLUSTERD_WORKDIR)/hooks/1/gsync-create/post/
1df6c8
 if USE_GEOREP
1df6c8
diff --git a/extras/hook-scripts/add-brick/post/Makefile.am b/extras/hook-scripts/add-brick/post/Makefile.am
1df6c8
index 9b236df..bfc0c1c 100644
1df6c8
--- a/extras/hook-scripts/add-brick/post/Makefile.am
1df6c8
+++ b/extras/hook-scripts/add-brick/post/Makefile.am
1df6c8
@@ -1,6 +1,6 @@
1df6c8
-EXTRA_DIST = disabled-quota-root-xattr-heal.sh S10selinux-label-brick.sh S13create-subdir-mounts.sh
1df6c8
+EXTRA_DIST = disabled-quota-root-xattr-heal.sh S13create-subdir-mounts.sh
1df6c8
 
1df6c8
 hookdir = $(GLUSTERD_WORKDIR)/hooks/1/add-brick/post/
1df6c8
 if WITH_SERVER
1df6c8
-hook_SCRIPTS = disabled-quota-root-xattr-heal.sh S10selinux-label-brick.sh S13create-subdir-mounts.sh
1df6c8
+hook_SCRIPTS = disabled-quota-root-xattr-heal.sh S13create-subdir-mounts.sh
1df6c8
 endif
1df6c8
diff --git a/extras/hook-scripts/add-brick/post/S10selinux-label-brick.sh b/extras/hook-scripts/add-brick/post/S10selinux-label-brick.sh
1df6c8
deleted file mode 100755
1df6c8
index 4a17c99..0000000
1df6c8
--- a/extras/hook-scripts/add-brick/post/S10selinux-label-brick.sh
1df6c8
+++ /dev/null
1df6c8
@@ -1,100 +0,0 @@
1df6c8
-#!/bin/bash
1df6c8
-#
1df6c8
-# Install to hooks/<HOOKS_VER>/add-brick/post
1df6c8
-#
1df6c8
-# Add an SELinux file context for each brick using the glusterd_brick_t type.
1df6c8
-# This ensures that the brick is relabeled correctly on an SELinux restart or
1df6c8
-# restore. Subsequently, run a restore on the brick path to set the selinux
1df6c8
-# labels.
1df6c8
-#
1df6c8
-###
1df6c8
-
1df6c8
-PROGNAME="Sselinux"
1df6c8
-OPTSPEC="volname:,version:,gd-workdir:,volume-op:"
1df6c8
-VOL=
1df6c8
-
1df6c8
-parse_args () {
1df6c8
-  ARGS=$(getopt -o '' -l ${OPTSPEC} -n ${PROGNAME} -- "$@")
1df6c8
-  eval set -- "${ARGS}"
1df6c8
-
1df6c8
-  while true; do
1df6c8
-    case ${1} in
1df6c8
-      --volname)
1df6c8
-        shift
1df6c8
-        VOL=${1}
1df6c8
-        ;;
1df6c8
-      --gd-workdir)
1df6c8
-          shift
1df6c8
-          GLUSTERD_WORKDIR=$1
1df6c8
-          ;;
1df6c8
-      --version)
1df6c8
-          shift
1df6c8
-          ;;
1df6c8
-      --volume-op)
1df6c8
-          shift
1df6c8
-          ;;
1df6c8
-      *)
1df6c8
-          shift
1df6c8
-          break
1df6c8
-          ;;
1df6c8
-    esac
1df6c8
-    shift
1df6c8
-  done
1df6c8
-}
1df6c8
-
1df6c8
-set_brick_labels()
1df6c8
-{
1df6c8
-  local volname="${1}"
1df6c8
-  local fctx
1df6c8
-  local list=()
1df6c8
-
1df6c8
-  fctx="$(semanage fcontext --list -C)"
1df6c8
-
1df6c8
-  # wait for new brick path to be updated under
1df6c8
-  # ${GLUSTERD_WORKDIR}/vols/${volname}/bricks/
1df6c8
-  sleep 5
1df6c8
-
1df6c8
-  # grab the path for each local brick
1df6c8
-  brickpath="${GLUSTERD_WORKDIR}/vols/${volname}/bricks/"
1df6c8
-  brickdirs=$(
1df6c8
-    find "${brickpath}" -type f -exec grep '^path=' {} \; | \
1df6c8
-    cut -d= -f 2 | \
1df6c8
-    sort -u
1df6c8
-  )
1df6c8
-
1df6c8
-  # create a list of bricks for which custom SELinux
1df6c8
-  # label doesn't exist
1df6c8
-  for b in ${brickdirs}; do
1df6c8
-    pattern="${b}(/.*)?"
1df6c8
-    echo "${fctx}" | grep "^${pattern}\s" >/dev/null
1df6c8
-    if [[ $? -ne 0 ]]; then
1df6c8
-      list+=("${pattern}")
1df6c8
-    fi
1df6c8
-  done
1df6c8
-
1df6c8
-  # Add a file context for each brick path in the list and associate with the
1df6c8
-  # glusterd_brick_t SELinux type.
1df6c8
-  for p in ${list[@]}
1df6c8
-  do
1df6c8
-    semanage fcontext --add -t glusterd_brick_t -r s0 "${p}"
1df6c8
-  done
1df6c8
-
1df6c8
-  # Set the labels for which SELinux label was added above
1df6c8
-  for b in ${brickdirs}
1df6c8
-  do
1df6c8
-    echo "${list[@]}" | grep "${b}" >/dev/null
1df6c8
-    if [[ $? -eq 0 ]]; then
1df6c8
-      restorecon -R "${b}"
1df6c8
-    fi
1df6c8
-  done
1df6c8
-}
1df6c8
-
1df6c8
-SELINUX_STATE=$(which getenforce && getenforce)
1df6c8
-[ "${SELINUX_STATE}" = 'Disabled' ] && exit 0
1df6c8
-
1df6c8
-parse_args "$@"
1df6c8
-[ -z "${VOL}" ] && exit 1
1df6c8
-
1df6c8
-set_brick_labels "${VOL}"
1df6c8
-
1df6c8
-exit 0
1df6c8
diff --git a/extras/hook-scripts/create/Makefile.am b/extras/hook-scripts/create/Makefile.am
1df6c8
deleted file mode 100644
1df6c8
index b083a91..0000000
1df6c8
--- a/extras/hook-scripts/create/Makefile.am
1df6c8
+++ /dev/null
1df6c8
@@ -1 +0,0 @@
1df6c8
-SUBDIRS = post
1df6c8
diff --git a/extras/hook-scripts/create/post/Makefile.am b/extras/hook-scripts/create/post/Makefile.am
1df6c8
deleted file mode 100644
1df6c8
index 919801a..0000000
1df6c8
--- a/extras/hook-scripts/create/post/Makefile.am
1df6c8
+++ /dev/null
1df6c8
@@ -1,6 +0,0 @@
1df6c8
-EXTRA_DIST = S10selinux-label-brick.sh
1df6c8
-
1df6c8
-scriptsdir = $(GLUSTERD_WORKDIR)/hooks/1/create/post/
1df6c8
-if WITH_SERVER
1df6c8
-scripts_SCRIPTS = S10selinux-label-brick.sh
1df6c8
-endif
1df6c8
diff --git a/extras/hook-scripts/create/post/S10selinux-label-brick.sh b/extras/hook-scripts/create/post/S10selinux-label-brick.sh
1df6c8
index f9b4b1a..de242d2 100755
1df6c8
--- a/extras/hook-scripts/create/post/S10selinux-label-brick.sh
1df6c8
+++ b/extras/hook-scripts/create/post/S10selinux-label-brick.sh
1df6c8
@@ -34,21 +34,18 @@ parse_args () {
1df6c8
 
1df6c8
 set_brick_labels()
1df6c8
 {
1df6c8
-  volname="${1}"
1df6c8
+  volname=${1}
1df6c8
 
1df6c8
   # grab the path for each local brick
1df6c8
-  brickpath="/var/lib/glusterd/vols/${volname}/bricks/"
1df6c8
-  brickdirs=$(
1df6c8
-    find "${brickpath}" -type f -exec grep '^path=' {} \; | \
1df6c8
-    cut -d= -f 2 | \
1df6c8
-    sort -u
1df6c8
-  )
1df6c8
+  brickpath="/var/lib/glusterd/vols/${volname}/bricks/*"
1df6c8
+  brickdirs=$(grep '^path=' "${brickpath}" | cut -d= -f 2 | sort -u)
1df6c8
 
1df6c8
   for b in ${brickdirs}; do
1df6c8
     # Add a file context for each brick path and associate with the
1df6c8
     # glusterd_brick_t SELinux type.
1df6c8
-    pattern="${b}(/.*)?"
1df6c8
+    pattern="${b}\(/.*\)?"
1df6c8
     semanage fcontext --add -t glusterd_brick_t -r s0 "${pattern}"
1df6c8
+
1df6c8
     # Set the labels on the new brick path.
1df6c8
     restorecon -R "${b}"
1df6c8
   done
1df6c8
diff --git a/extras/hook-scripts/delete/Makefile.am b/extras/hook-scripts/delete/Makefile.am
1df6c8
deleted file mode 100644
1df6c8
index c98a05d..0000000
1df6c8
--- a/extras/hook-scripts/delete/Makefile.am
1df6c8
+++ /dev/null
1df6c8
@@ -1 +0,0 @@
1df6c8
-SUBDIRS = pre
1df6c8
diff --git a/extras/hook-scripts/delete/pre/Makefile.am b/extras/hook-scripts/delete/pre/Makefile.am
1df6c8
deleted file mode 100644
1df6c8
index 93a6b85..0000000
1df6c8
--- a/extras/hook-scripts/delete/pre/Makefile.am
1df6c8
+++ /dev/null
1df6c8
@@ -1,6 +0,0 @@
1df6c8
-EXTRA_DIST = S10selinux-del-fcontext.sh
1df6c8
-
1df6c8
-scriptsdir = $(GLUSTERD_WORKDIR)/hooks/1/delete/pre/
1df6c8
-if WITH_SERVER
1df6c8
-scripts_SCRIPTS = S10selinux-del-fcontext.sh
1df6c8
-endif
1df6c8
diff --git a/extras/hook-scripts/delete/pre/S10selinux-del-fcontext.sh b/extras/hook-scripts/delete/pre/S10selinux-del-fcontext.sh
1df6c8
index e7f4e8f..6eba66f 100755
1df6c8
--- a/extras/hook-scripts/delete/pre/S10selinux-del-fcontext.sh
1df6c8
+++ b/extras/hook-scripts/delete/pre/S10selinux-del-fcontext.sh
1df6c8
@@ -15,55 +15,45 @@ OPTSPEC="volname:"
1df6c8
 VOL=
1df6c8
 
1df6c8
 function parse_args () {
1df6c8
-  ARGS=$(getopt -o '' -l ${OPTSPEC} -n ${PROGNAME} -- "$@")
1df6c8
-  eval set -- "${ARGS}"
1df6c8
-
1df6c8
-  while true; do
1df6c8
-    case ${1} in
1df6c8
-      --volname)
1df6c8
-        shift
1df6c8
-        VOL=${1}
1df6c8
-      ;;
1df6c8
-      *)
1df6c8
+        ARGS=$(getopt -o '' -l $OPTSPEC -n $PROGNAME -- "$@")
1df6c8
+        eval set -- "$ARGS"
1df6c8
+
1df6c8
+        while true; do
1df6c8
+        case $1 in
1df6c8
+        --volname)
1df6c8
+         shift
1df6c8
+         VOL=$1
1df6c8
+         ;;
1df6c8
+        *)
1df6c8
+         shift
1df6c8
+         break
1df6c8
+         ;;
1df6c8
+        esac
1df6c8
         shift
1df6c8
-        break
1df6c8
-      ;;
1df6c8
-    esac
1df6c8
-    shift
1df6c8
-  done
1df6c8
+        done
1df6c8
 }
1df6c8
 
1df6c8
 function delete_brick_fcontext()
1df6c8
 {
1df6c8
-  volname="${1}"
1df6c8
-
1df6c8
-  # grab the path for each local brick
1df6c8
-  brickpath="/var/lib/glusterd/vols/${volname}/bricks/"
1df6c8
-  brickdirs=$(
1df6c8
-    find "${brickpath}" -type f -exec grep '^path=' {} \; | \
1df6c8
-    cut -d= -f 2 | \
1df6c8
-    sort -u
1df6c8
-  )
1df6c8
-
1df6c8
-  for b in ${brickdirs}
1df6c8
-  do
1df6c8
-    # remove the file context associated with the brick path
1df6c8
-    pattern="${b}(/.*)?"
1df6c8
-    semanage fcontext --delete "${pattern}"
1df6c8
+        volname=$1
1df6c8
 
1df6c8
-    # remove the labels on brick path.
1df6c8
-    restorecon -R "${b}"
1df6c8
- done
1df6c8
+        # grab the path for each local brick
1df6c8
+        brickdirs=$(grep '^path=' /var/lib/glusterd/vols/${volname}/bricks/* | cut -d= -f 2)
1df6c8
 
1df6c8
+        for b in $brickdirs
1df6c8
+        do
1df6c8
+                # remove the file context associated with the brick path
1df6c8
+                semanage fcontext --delete $b\(/.*\)?
1df6c8
+        done
1df6c8
 }
1df6c8
 
1df6c8
 SELINUX_STATE=$(which getenforce && getenforce)
1df6c8
 [ "${SELINUX_STATE}" = 'Disabled' ] && exit 0
1df6c8
 
1df6c8
 parse_args "$@"
1df6c8
-[ -z "${VOL}" ] && exit 1
1df6c8
+[ -z "$VOL" ] && exit 1
1df6c8
 
1df6c8
-delete_brick_fcontext "${VOL}"
1df6c8
+delete_brick_fcontext $VOL
1df6c8
 
1df6c8
 # failure to delete the fcontext is not fatal
1df6c8
 exit 0
1df6c8
diff --git a/glusterfs.spec.in b/glusterfs.spec.in
1df6c8
index 012989a..671ee27 100644
1df6c8
--- a/glusterfs.spec.in
1df6c8
+++ b/glusterfs.spec.in
1df6c8
@@ -1447,13 +1447,11 @@ exit 0
1df6c8
        %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/add-brick
1df6c8
        %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/add-brick/post
1df6c8
             %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/add-brick/post/disabled-quota-root-xattr-heal.sh
1df6c8
-            %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/add-brick/post/S10selinux-label-brick.sh
1df6c8
             %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/add-brick/post/S13create-subdir-mounts.sh
1df6c8
        %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/add-brick/pre
1df6c8
             %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/add-brick/pre/S28Quota-enable-root-xattr-heal.sh
1df6c8
        %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/create
1df6c8
        %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/create/post
1df6c8
-            %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/create/post/S10selinux-label-brick.sh
1df6c8
 %ghost %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/create/pre
1df6c8
 %ghost %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/copy-file
1df6c8
 %ghost %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/copy-file/post
1df6c8
@@ -1462,7 +1460,6 @@ exit 0
1df6c8
        %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/delete/post
1df6c8
                             %{_sharedstatedir}/glusterd/hooks/1/delete/post/S57glusterfind-delete-post
1df6c8
        %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/delete/pre
1df6c8
-            %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/delete/pre/S10selinux-del-fcontext.sh
1df6c8
 %ghost %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/remove-brick
1df6c8
 %ghost %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/remove-brick/post
1df6c8
 %ghost %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/remove-brick/pre
1df6c8
diff --git a/tests/bugs/glusterfs-server/bug-877992.t b/tests/bugs/glusterfs-server/bug-877992.t
1df6c8
index 300000b..aeb73ed 100755
1df6c8
--- a/tests/bugs/glusterfs-server/bug-877992.t
1df6c8
+++ b/tests/bugs/glusterfs-server/bug-877992.t
1df6c8
@@ -46,9 +46,7 @@ TEST $CLI volume create $V0 $H0:$B0/${V0}1;
1df6c8
 EXPECT "$V0" volinfo_field $V0 'Volume Name';
1df6c8
 EXPECT 'Created' volinfo_field $V0 'Status';
1df6c8
 EXPECT 'createPre' cat /tmp/pre.out;
1df6c8
-# Spost.sh comes after S10selinux-label-brick.sh under create post hook script
1df6c8
-# list. So consider the delay in setting SELinux context on bricks
1df6c8
-EXPECT_WITHIN 5 'createPost' cat /tmp/post.out;
1df6c8
+EXPECT 'createPost' cat /tmp/post.out;
1df6c8
 hooks_cleanup 'create'
1df6c8
 
1df6c8
 
1df6c8
diff --git a/tests/features/subdir-mount.t b/tests/features/subdir-mount.t
1df6c8
index a02bd6b..8401946 100644
1df6c8
--- a/tests/features/subdir-mount.t
1df6c8
+++ b/tests/features/subdir-mount.t
1df6c8
@@ -85,17 +85,12 @@ TEST $CLI volume start $V0
1df6c8
 TEST $GFS --subdir-mount /subdir1/subdir1.1/subdir1.2 -s $H0 --volfile-id $V0 $M2
1df6c8
 TEST stat $M2
1df6c8
 
1df6c8
-initcnt=`grep -i create-subdir-mounts /var/log/glusterfs/glusterd.log  | wc -l`
1df6c8
 # mount shouldn't fail even after add-brick
1df6c8
 TEST $CLI volume add-brick $V0 replica 2 $H0:$B0/${V0}{5,6};
1df6c8
 
1df6c8
-# Wait to execute create-subdir-mounts.sh script by glusterd
1df6c8
-newcnt=`grep -i create-subdir-mounts /var/log/glusterfs/glusterd.log  | wc -l`
1df6c8
-while [ $newcnt -eq $initcnt ]
1df6c8
-do
1df6c8
-   newcnt=`grep -i create-subdir-mounts /var/log/glusterfs/glusterd.log  | wc -l`
1df6c8
-   sleep 1
1df6c8
-done
1df6c8
+# Give time for client process to get notified and use the new
1df6c8
+# volfile after add-brick
1df6c8
+sleep 1
1df6c8
 
1df6c8
 # Existing mount should still be active
1df6c8
 mount_inode=$(stat --format "%i" "$M2")
1df6c8
-- 
1df6c8
1.8.3.1
1df6c8