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