Blame SOURCES/bz1692960-mysql-galera-runuser-su-to-avoid-dac_override.patch

b4b3ce
From db6d12f4b7b10e214526512abe35307270f81c03 Mon Sep 17 00:00:00 2001
b4b3ce
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
b4b3ce
Date: Thu, 8 Aug 2019 14:48:13 +0200
b4b3ce
Subject: [PATCH] mysql/mariadb/galera: use runuser/su to avoid using SELinux
b4b3ce
 DAC_OVERRIDE
b4b3ce
b4b3ce
---
b4b3ce
 heartbeat/galera          | 11 ++++++-----
b4b3ce
 heartbeat/mysql-common.sh | 16 ++++++++++++----
b4b3ce
 2 files changed, 18 insertions(+), 9 deletions(-)
b4b3ce
b4b3ce
diff --git a/heartbeat/galera b/heartbeat/galera
b4b3ce
index 9b9fe5569..056281fb8 100755
b4b3ce
--- a/heartbeat/galera
b4b3ce
+++ b/heartbeat/galera
b4b3ce
@@ -624,8 +624,7 @@ detect_last_commit()
b4b3ce
     local recover_args="--defaults-file=$OCF_RESKEY_config \
b4b3ce
                         --pid-file=$OCF_RESKEY_pid \
b4b3ce
                         --socket=$OCF_RESKEY_socket \
b4b3ce
-                        --datadir=$OCF_RESKEY_datadir \
b4b3ce
-                        --user=$OCF_RESKEY_user"
b4b3ce
+                        --datadir=$OCF_RESKEY_datadir"
b4b3ce
     local recovery_file_regex='s/.*WSREP\:.*position\s*recovery.*--log_error='\''\([^'\'']*\)'\''.*/\1/p'
b4b3ce
     local recovered_position_regex='s/.*WSREP\:\s*[R|r]ecovered\s*position.*\:\(.*\)\s*$/\1/p'
b4b3ce
 
b4b3ce
@@ -654,7 +653,8 @@ detect_last_commit()
b4b3ce
 
b4b3ce
         ocf_log info "now attempting to detect last commit version using 'mysqld_safe --wsrep-recover'"
b4b3ce
 
b4b3ce
-        ${OCF_RESKEY_binary} $recover_args --wsrep-recover --log-error=$tmp 2>/dev/null
b4b3ce
+        $SU - $OCF_RESKEY_user -s /bin/sh -c \
b4b3ce
+        "${OCF_RESKEY_binary} $recover_args --wsrep-recover --log-error=$tmp 2>/dev/null"
b4b3ce
 
b4b3ce
         last_commit="$(cat $tmp | sed -n $recovered_position_regex | tail -1)"
b4b3ce
         if [ -z "$last_commit" ]; then
b4b3ce
@@ -670,8 +670,9 @@ detect_last_commit()
b4b3ce
                     # we can only rollback the transaction, but that's OK
b4b3ce
                     # since the DB will get resynchronized anyway
b4b3ce
                     ocf_log warn "local node <${NODENAME}> was not shutdown properly. Rollback stuck transaction with --tc-heuristic-recover"
b4b3ce
-                    ${OCF_RESKEY_binary} $recover_args --wsrep-recover \
b4b3ce
-                                         --tc-heuristic-recover=rollback --log-error=$tmp 2>/dev/null
b4b3ce
+                    $SU - $OCF_RESKEY_user -s /bin/sh -c \
b4b3ce
+                    "${OCF_RESKEY_binary} $recover_args --wsrep-recover \
b4b3ce
+                                         --tc-heuristic-recover=rollback --log-error=$tmp 2>/dev/null"
b4b3ce
 
b4b3ce
                     last_commit="$(cat $tmp | sed -n $recovered_position_regex | tail -1)"
b4b3ce
                     if [ ! -z "$last_commit" ]; then
b4b3ce
diff --git a/heartbeat/mysql-common.sh b/heartbeat/mysql-common.sh
b4b3ce
index d5ac972cd..65db9bf85 100755
b4b3ce
--- a/heartbeat/mysql-common.sh
b4b3ce
+++ b/heartbeat/mysql-common.sh
b4b3ce
@@ -2,6 +2,13 @@
b4b3ce
 
b4b3ce
 #######################################################################
b4b3ce
 
b4b3ce
+# Use runuser if available for SELinux.
b4b3ce
+if [ -x /sbin/runuser ]; then
b4b3ce
+	SU=runuser
b4b3ce
+else
b4b3ce
+	SU=su
b4b3ce
+fi
b4b3ce
+
b4b3ce
 # Attempt to detect a default binary
b4b3ce
 OCF_RESKEY_binary_default=$(which mysqld_safe 2> /dev/null)
b4b3ce
 if [ "$OCF_RESKEY_binary_default" = "" ]; then
b4b3ce
@@ -207,7 +214,7 @@ mysql_common_prepare_dirs()
b4b3ce
     # already existed, check whether it is writable by the configured
b4b3ce
     # user
b4b3ce
     for dir in $pid_dir $socket_dir; do
b4b3ce
-        if ! su -s /bin/sh - $OCF_RESKEY_user -c "test -w $dir"; then
b4b3ce
+        if ! $SU -s /bin/sh - $OCF_RESKEY_user -c "test -w $dir"; then
b4b3ce
             ocf_exit_reason "Directory $dir is not writable by $OCF_RESKEY_user"
b4b3ce
             exit $OCF_ERR_PERM;
b4b3ce
         fi
b4b3ce
@@ -219,14 +226,15 @@ mysql_common_start()
b4b3ce
     local mysql_extra_params="$1"
b4b3ce
     local pid
b4b3ce
 
b4b3ce
-    ${OCF_RESKEY_binary} --defaults-file=$OCF_RESKEY_config \
b4b3ce
+    $SU - $OCF_RESKEY_user -s /bin/sh -c \
b4b3ce
+    "${OCF_RESKEY_binary} --defaults-file=$OCF_RESKEY_config \
b4b3ce
     --pid-file=$OCF_RESKEY_pid \
b4b3ce
     --socket=$OCF_RESKEY_socket \
b4b3ce
     --datadir=$OCF_RESKEY_datadir \
b4b3ce
     --log-error=$OCF_RESKEY_log \
b4b3ce
-    --user=$OCF_RESKEY_user $OCF_RESKEY_additional_parameters \
b4b3ce
+    $OCF_RESKEY_additional_parameters \
b4b3ce
     $mysql_extra_params >/dev/null 2>&1 &
b4b3ce
-    pid=$!
b4b3ce
+    pid=$!"
b4b3ce
 
b4b3ce
     # Spin waiting for the server to come up.
b4b3ce
     # Let the CRM/LRM time us out if required.