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