Skip to content

Commit 332d5de

Browse files
committed
DLPX-89763-3Apr copy
1 parent baa0f5b commit 332d5de

3 files changed

Lines changed: 97 additions & 6 deletions

File tree

files/common/lib/systemd/system/delphix-platform.service

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2019 Delphix
2+
# Copyright 2019, 2026 Delphix
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ Before=rsync.service docker.service
2424
Type=oneshot
2525
ExecStart=/var/lib/delphix-platform/ansible/apply
2626
ExecStart=/var/lib/delphix-platform/dynamic-debug
27+
ExecStart=/var/lib/delphix-platform/export-home
2728
RemainAfterExit=yes
2829

2930
#

files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2018, 2023 Delphix
2+
# Copyright 2018, 2026 Delphix
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
2222
# it below; otherwise that task will fail.
2323
#
2424
- file:
25-
path: /export/home
25+
path: /home
2626
state: directory
2727
mode: 0755
2828

@@ -35,7 +35,7 @@
3535
shell: /bin/bash
3636
create_home: yes
3737
comment: Delphix User
38-
home: /export/home/delphix
38+
home: /home/delphix
3939

4040
#
4141
# In order for this locale to be used (e.g. by virtualization) we need
@@ -104,7 +104,7 @@
104104
# found in this directory, but also used by upgrade-scripts stored in
105105
# the appliace-build repository (which generates the upgrade image).
106106
# Thus, we need to be careful if/when changing this, as we'll need to
107-
# coordinate the change with the appliance-build upgrade-scripts.
107+
# coordinate the change with the appliance-build upgrade-scripts.aws
108108
#
109109
- file:
110110
path: /var/dlpx-update
@@ -637,7 +637,7 @@
637637
638638
- name: Source bash completion
639639
blockinfile:
640-
dest: "/export/home/delphix/.bashrc"
640+
dest: "/home/delphix/.bashrc"
641641
block: |
642642
. /etc/bash_completion.d/systemctl
643643
. /etc/bash_completion.d/zfs
@@ -654,6 +654,27 @@
654654
# Set default umask value.
655655
umask 027
656656
657+
#
658+
# Add nodev,nosuid to the /home fstab entry for security hardening (CIS).
659+
# New VMs have this handled during fresh provisioning; this covers upgrades
660+
# where the entry may lack these options.
661+
#
662+
- name: Check if /home fstab entry needs nodev,nosuid
663+
shell: |
664+
grep -qE '^[^#].*\s/home\s' /etc/fstab && \
665+
(! grep -qE '^[^#].*\s/home\s.*nodev' /etc/fstab || \
666+
! grep -qE '^[^#].*\s/home\s.*nosuid' /etc/fstab)
667+
register: home_fstab_needs_update
668+
failed_when: false
669+
changed_when: false
670+
671+
- name: Add nodev,nosuid to /home fstab entry
672+
replace:
673+
path: /etc/fstab
674+
regexp: '(^[^#].*\s/home\s.*)defaults'
675+
replace: '\1defaults,nodev,nosuid'
676+
when: home_fstab_needs_update.rc == 0
677+
657678
- name: Mount /dev/shm with noexec,nosuid,nodev
658679
ansible.posix.mount:
659680
path: /dev/shm
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2026 by Delphix. All rights reserved.
4+
#
5+
6+
#
7+
# This script ensures that the /export/home is a symlink
8+
# to /home.
9+
#
10+
11+
# If /export/home is already a symlink to /home, do nothing
12+
if [ -L /export/home ]; then
13+
echo '/export/home is already exists. Nothing to do.'
14+
exit 0
15+
fi
16+
17+
# if /export/home and /home both are mounted - Dont do anything
18+
# Since during the next boot /export/home will not be mounted
19+
# Since /export/home is there all tests will be passes
20+
if mountpoint -q /export/home; then
21+
echo '/export/home is still mounted. Check if /home is also mounted'
22+
if mountpoint -q /home; then
23+
echo '/home is also mounted. Since during the next boot /export/home will not be mounted, exiting safely.'
24+
exit 0
25+
else
26+
echo '/home is not mounted. Aborting!!'
27+
exit 1
28+
fi
29+
fi
30+
31+
# /export/home is not mounted, check if /home is mounted
32+
if mountpoint -q /home; then
33+
echo "/home is mounted. Proceeding with /export/home cleanup."
34+
# If /export/home exists
35+
if [ -d /export/home ]; then
36+
echo "/export/home exists. Attempting to remove it..."
37+
rmdir /export/home 2>/dev/null
38+
if [ $? -eq 0 ]; then
39+
echo "/export/home directory removed successfully."
40+
else
41+
# If rmdir fails, it means /export/home is not empty
42+
# Move contents to a backup location for a seamless user experience.
43+
echo "/export/home is not empty. Moving contents to /export/home.backup before cleanup..."
44+
backup_dir="/export/home.backup.$(date +%Y%m%d_%H%M%S)"
45+
mv /export/home "$backup_dir"
46+
if [ $? -ne 0 ]; then
47+
echo "Failed to move /export/home contents to backup. Manual intervention required."
48+
exit 1
49+
fi
50+
echo "Contents of /export/home moved successfully to: $backup_dir"
51+
fi
52+
fi
53+
else
54+
echo "/home is not mounted. Aborting to avoid risk of data loss."
55+
exit 1
56+
fi
57+
58+
# Ensure /export exists
59+
mkdir -p /export
60+
61+
# Create symlink
62+
echo "Creating symlink: /export/home -> /home"
63+
ln -s /home /export/home
64+
if [ $? -eq 0 ]; then
65+
echo "Symlink created successfully."
66+
else
67+
echo "Failed to create symlink. Please check permissions and try again."
68+
exit 1
69+
fi

0 commit comments

Comments
 (0)