Skip to content

Commit 7688a81

Browse files
committed
[BACKPORT 2025.1.2][PLAT-18631] Ssh broken through yugabyte user on onprem auto provisioning for RHEL 9
Summary: Original diff: https://phorge.dev.yugabyte.com/D47122 (532a20f) Selinux prevents accessing .ssh folder if the home is a non-standard location like /yb-user-home. This change labels the path to allow access. Test Plan: Manually tested with the AMI ami-0d35d4245140392e8. Used to fail before this change. ``` LYYPVYV909:my-utilities nkhogen$ ssh -i /opt/yugaware/keys/ff4224f9-9fe7-43c3-8d70-9b16a9dcc708/yb-dev-aws.pem -ostricthostkeychecking=no -p 22 [email protected] Register this system with Red Hat Insights: insights-client --register Create an account or view all your systems at https://red.ht/insights-dashboard Last login: Wed Oct 1 02:02:51 2025 [yugabyte@ip-10-9-77-220 ~]$ cat /etc/os-release NAME="Red Hat Enterprise Linux" VERSION="9.4 (Plow)" ID="rhel" ID_LIKE="fedora" VERSION_ID="9.4" PLATFORM_ID="platform:el9" PRETTY_NAME="Red Hat Enterprise Linux 9.4 (Plow)" ANSI_COLOR="0;31" LOGO="fedora-logo-icon" CPE_NAME="cpe:/o:redhat:enterprise_linux:9::baseos" HOME_URL="https://www.redhat.com/" DOCUMENTATION_URL="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9" BUG_REPORT_URL="https://bugzilla.redhat.com/" REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 9" REDHAT_BUGZILLA_PRODUCT_VERSION=9.4 REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux" REDHAT_SUPPORT_PRODUCT_VERSION="9.4" [yugabyte@ip-10-9-77-220 ~]$ echo $HOME /yb-db-user ``` For the home path matching test: 1. Wrong home path ``` 2025-10-02 10:43:33,300 INFO exec_command:ssh.py:443: Executing command /tmp/preflight_checks.sh --type provision --yb_home_dir /yb-db-user/fake-home --mount_points /mnt/d0 --ports_to_check 7000,7100,9000,9100,14000,18018,12000,9042,13000,5433,9300 --sudo_pass_file /tmp/.yb_sudo_pass.sh --tmp_dir /tmp --cleanup --install_node_exporter { "SSH Connection": true, "Try Ansible Command": true, "Home directory is clean": true, "Home directory matches": false, "Data directory is clean": true, "Sudo Access to Python": true, "Internet Connection": true, "(Prometheus) No Pre-existing Node Exporter Running": true, "(Prometheus) /opt/prometheus is writable": true, "(Prometheus) /etc/prometheus is writable": true, "(Prometheus) /var/log/prometheus is writable": true, "(Prometheus) /var/run/prometheus is writable": true, "(Prometheus) /var/lib/prometheus is writable": true, "(Prometheus) /lib/systemd/system/node_exporter.service is writable": true, "/opt/prometheus has free space of 100 MB ": true, "/tmp has free space of 100 MB ": true, "(PAM Limits) /etc/security/limits.conf is writable": true, "NTP time synchronization set up": true, "ntp_skew": true, "(Mount Point) /mnt/d0 is writable": true, "Port 7000 is available": true, "Port 7100 is available": true, "Port 9000 is available": true, "Port 9100 is available": true, "Port 14000 is available": true, "Port 18018 is available": true, "Port 12000 is available": true, "Port 9042 is available": true, "Port 13000 is available": true, "Port 5433 is available": true, "Port 9300 is available": true, "Yugabyte User in Yugabyte Group": true, "/yb-db-user/fake-home has free space of 2048 MB ": true, "locale_present": true } ``` 2. Matching home path ``` 2025-10-02 10:45:05,509 INFO exec_command:ssh.py:443: Executing command /tmp/preflight_checks.sh --type provision --yb_home_dir /yb-db-user --mount_points /mnt/d0 --ports_to_check 7000,7100,9000,9100,14000,18018,12000,9042,13000,5433,9300 --sudo_pass_file /tmp/.yb_sudo_pass.sh --tmp_dir /tmp --cleanup --install_node_exporter { "SSH Connection": true, "Try Ansible Command": true, "Home directory is clean": true, "Home directory matches": true, "Data directory is clean": true, "Sudo Access to Python": true, "Internet Connection": true, "(Prometheus) No Pre-existing Node Exporter Running": true, "(Prometheus) /opt/prometheus is writable": true, "(Prometheus) /etc/prometheus is writable": true, "(Prometheus) /var/log/prometheus is writable": true, "(Prometheus) /var/run/prometheus is writable": true, "(Prometheus) /var/lib/prometheus is writable": true, "(Prometheus) /lib/systemd/system/node_exporter.service is writable": true, "/opt/prometheus has free space of 100 MB ": true, "/tmp has free space of 100 MB ": true, "(PAM Limits) /etc/security/limits.conf is writable": true, "NTP time synchronization set up": true, "ntp_skew": true, "(Mount Point) /mnt/d0 is writable": true, "Port 7000 is available": true, "Port 7100 is available": true, "Port 9000 is available": true, "Port 9100 is available": true, "Port 14000 is available": true, "Port 18018 is available": true, "Port 12000 is available": true, "Port 9042 is available": true, "Port 13000 is available": true, "Port 5433 is available": true, "Port 9300 is available": true, "Yugabyte User in Yugabyte Group": true, "/yb-db-user has free space of 2048 MB ": true, "locale_present": true } ``` Reviewers: anijhawan, skhilar, nbhatia, vkumar, dshubin Reviewed By: skhilar Subscribers: yugaware, nikhil Differential Revision: https://phorge.dev.yugabyte.com/D48355
1 parent 4e281a7 commit 7688a81

File tree

3 files changed

+63
-14
lines changed

3 files changed

+63
-14
lines changed

managed/devops/opscli/ybops/data/preflight_checks.sh

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ preflight_configure_check() {
149149
fi
150150
update_result_json "Yugabyte Group" "$user_status"
151151

152-
# Check home directory exists.
153-
check_filepath "Home Directory" "$yb_home_dir" false
154-
155152
# Check virtual memory max map limit.
156153
vm_max_map_count=$(cat /proc/sys/vm/max_map_count 2> /dev/null)
157154
test ${vm_max_map_count:-0} -ge $VM_MAX_MAP_COUNT
@@ -176,8 +173,10 @@ preflight_all_checks() {
176173
yb_home_dir_clean=false
177174
fi
178175
fi
179-
update_result_json "yb_home_dir_clean" "$yb_home_dir_clean"
176+
update_result_json "Home Directory Clean" "$yb_home_dir_clean"
180177

178+
# Check home directory exists and verify if it matches the expected home directory.
179+
check_yugabyte_user_home_if_exists
181180

182181
# Check whether files in data directory are cleaned up.
183182
data_dir_clean=true
@@ -199,7 +198,7 @@ preflight_all_checks() {
199198
fi
200199
done
201200
done
202-
update_result_json "data_dir_clean" "$data_dir_clean"
201+
update_result_json "Data Directory Clean" "$data_dir_clean"
203202
}
204203

205204
# Checks for an available python executable
@@ -213,6 +212,28 @@ check_python() {
213212
update_result_json "Sudo Access to Python" "$python_status"
214213
}
215214

215+
# Checks if the home directory exists for yugabyte and is correct.
216+
check_yugabyte_user_home_if_exists() {
217+
# Check only if yugabyte user exists.
218+
if id -u "yugabyte" >/dev/null 2>&1; then
219+
# Get the local home directory
220+
# Output looks like yugabyte:x:1001:1001::/home/yugabyte:/bin/bash
221+
actual_home_dir=$(getent passwd yugabyte | cut -d: -f6 2>&1)
222+
if [[ -z "$actual_home_dir" ]]; then
223+
update_result_json "Home Directory Exists" false
224+
else
225+
update_result_json "Home Directory Exists" true
226+
# Normalize path.
227+
actual_home_dir=$(readlink -m "$actual_home_dir" 2>&1)
228+
if [[ "$actual_home_dir" != "$yb_home_dir" ]]; then
229+
update_result_json "Home Directory Matches" false
230+
else
231+
update_result_json "Home Directory Matches" true
232+
fi
233+
fi
234+
fi
235+
}
236+
216237
# Checks if given filepath is writable.
217238
check_filepath() {
218239
test_type="$1"
@@ -393,6 +414,8 @@ while [[ $# -gt 0 ]]; do
393414
;;
394415
--yb_home_dir)
395416
yb_home_dir="$2"
417+
# Normalize the path.
418+
yb_home_dir=$(readlink -m "$yb_home_dir" 2>&1)
396419
shift
397420
;;
398421
--tmp_dir)

managed/node-agent/resources/preflight_check.sh

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,27 @@ check_yugabyte_user() {
201201
update_result_json "user_group" "$result"
202202
}
203203

204+
check_yugabyte_user_home_if_exists() {
205+
# Check only if yugabyte user exists.
206+
if id -u "yugabyte" >/dev/null 2>&1; then
207+
# Get the local home directory
208+
# Output looks like yugabyte:x:1001:1001::/home/yugabyte:/bin/bash
209+
actual_home_dir=$(getent passwd yugabyte | cut -d: -f6 2>&1)
210+
if [[ -z "$actual_home_dir" ]]; then
211+
update_result_json "home_dir_exists" false
212+
else
213+
update_result_json "home_dir_exists" true
214+
# Normalize path.
215+
actual_home_dir=$(readlink -m "$actual_home_dir" 2>&1)
216+
if [[ "$actual_home_dir" != "$yb_home_dir" ]]; then
217+
update_result_json "home_dir_matches" false
218+
else
219+
update_result_json "home_dir_matches" true
220+
fi
221+
fi
222+
fi
223+
}
224+
204225
check_packages_installed() {
205226

206227
check_package_installed "openssl" # Required.
@@ -292,12 +313,8 @@ preflight_all_checks() {
292313
fi
293314
update_result_json "python_version" "$result"
294315

295-
# Check home directory exists.
296-
if [[ -d "$yb_home_dir" ]]; then
297-
update_result_json "home_dir_exists" true
298-
else
299-
update_result_json "home_dir_exists" false
300-
fi
316+
# Check home directory exists and verify if it matches the expected home directory.
317+
check_yugabyte_user_home_if_exists
301318

302319
# Check all the communication ports
303320
check_port "master_http_port" "$master_http_port"
@@ -569,6 +586,8 @@ while [[ $# -gt 0 ]]; do
569586
;;
570587
--yb_home_dir)
571588
yb_home_dir=${2//\'/}
589+
# Normalize the path.
590+
yb_home_dir=$(readlink -m "$yb_home_dir" 2>&1)
572591
shift
573592
;;
574593
--cleanup)

managed/node-agent/resources/ynp/modules/provision/yugabyte/templates/run.j2

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,28 @@ fi
3434
# Determine the PLATFORM_ID
3535
platform_id=$(grep -oP '(?<=^PLATFORM_ID=).+' /etc/os-release | tr -d '"' || echo "unknown")
3636

37-
if [[ "$platform_id" == "platform:el8" ]]; then
37+
if [[ "{{ os_family }}" == "RedHat" ]]; then
3838
# Check SELinux status
3939
SELINUX_STATUS=$(sestatus | grep 'SELinux status' | awk '{print $3}')
4040
if [[ "$SELINUX_STATUS" == "enabled" ]]; then
4141
# Configuring the correct SELinux context
4242
current_context=$(ls -Zd "{{ yb_home_dir }}" | awk '{print $1}' | cut -d: -f3)
4343
if [[ "$current_context" != "ssh_home_t" ]]; then
44-
chcon -R -t ssh_home_t "{{ yb_home_dir }}"
44+
if command -v semanage >/dev/null 2>&1; then
45+
echo "semanage command found, using semanage"
46+
semanage fcontext -a -t ssh_home_t "{{ yb_home_dir }}(/.*)?"
47+
restorecon -ir "{{ yb_home_dir }}"
48+
else
49+
echo "semanage command not found, using chcon"
50+
chcon -R -t ssh_home_t "{{ yb_home_dir }}"
51+
fi
4552
echo "SELinux context for {{ yb_home_dir }} changed to ssh_home_t"
4653
else
4754
echo "SELinux context for {{ yb_home_dir }} is already set to ssh_home_t"
4855
fi
4956
fi
5057
else
51-
echo "el8 not detected, skipping changing selinux context"
58+
echo "RedHat not detected, skipping changing selinux context"
5259
fi
5360

5461
{% if cloud_type is defined and cloud_type != '' %}

0 commit comments

Comments
 (0)