Skip to content

Commit 271dde1

Browse files
committed
As per latest comments from Prakash incorporating debian/preinst changes here
1 parent 8cbe3e3 commit 271dde1

3 files changed

Lines changed: 58 additions & 49 deletions

File tree

upgrade/upgrade-scripts/common.sh

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -530,32 +530,3 @@ function fix_and_migrate_services() {
530530
telegraf.service
531531
EOF
532532
}
533-
534-
535-
function update_fstab_for_upgrade() {
536-
# shellcheck disable=SC2155
537-
fstab_backup="/etc/fstab.bak.$(date +%s)"
538-
539-
# Backup current fstab
540-
cp /etc/fstab "$fstab_backup" || die "failed to backup /etc/fstab to $fstab_backup"
541-
542-
# Update legacy /export/home paths to /home
543-
sed -i 's|/export/home|/home|g' /etc/fstab /etc/passwd || warn "failed to update legacy /export/home paths"
544-
545-
# Ensure /home directory exists
546-
mkdir -p /home || die "failed to create /home directory"
547-
548-
# Attempt to mount /home with new flags
549-
if ! mount /home 2>/dev/null; then
550-
warn "failed to mount /home with new fstab configuration"
551-
fi
552-
553-
# Validate the entire fstab by attempting to mount all entries
554-
if ! mount -a 2>/dev/null; then
555-
warn "fstab validation failed, restoring backup"
556-
cp "$fstab_backup" /etc/fstab || die "failed to restore fstab backup from $fstab_backup"
557-
die "fstab modification failed validation; backup restored"
558-
fi
559-
560-
echo "Successfully updated /etc/fstab with security compliance flags (nodev,nosuid)"
561-
}

upgrade/upgrade-scripts/execute

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,6 @@ if [[ -n "$CURRENT_VERSION" ]]; then
183183
[[ -n "$ROOTFS_CONTAINER" ]] ||
184184
die "unable to determine currently mounted rootfs container"
185185

186-
#
187-
# Update fstab for security compliance before performing any upgrade
188-
# operations. This ensures the system is properly configured before
189-
# package installation and snapshot creation.
190-
#
191-
update_fstab_for_upgrade
192-
193186
#
194187
# It's possible for this script to be run multiple times,
195188
# and each time this script is run, we want to keep a
@@ -228,6 +221,32 @@ if [[ -n "$CURRENT_VERSION" ]]; then
228221
"$ROOTFS_CONTAINER" "$ROOTFS_CONTAINER@execute-upgrade.$UNIQUE"
229222
fi
230223

224+
#
225+
# Home directories were previously mounted under /export/home, and this was
226+
# changed to /home. This upgrade logic updates the /etc/fstab and /etc/passwd
227+
# files to reflect that change.
228+
#
229+
# Home directories will be mounted in both /export/home and /home until the
230+
# system is rebooted to ensure that running processes referencing the old
231+
# /export/home paths continue to function while also enabling new logins
232+
# under /home to work.
233+
#
234+
# This check only runs outside a container and during upgrades, consistent
235+
# with the pattern used for the GRUB and nodev/nosuid updates.
236+
#
237+
if [[ -n "$CURRENT_VERSION" ]] && ! systemd-detect-virt -qc; then
238+
if grep -q "/export/home" /etc/fstab; then
239+
sed -i 's|/export/home|/home|g' /etc/fstab ||
240+
die "failed to update /export/home to /home in /etc/fstab"
241+
mount /home || die "failed to mount /home"
242+
fi
243+
244+
if grep -q "/export/home" /etc/passwd; then
245+
sed -i 's|/export/home|/home|g' /etc/passwd ||
246+
die "failed to update /export/home to /home in /etc/passwd"
247+
fi
248+
fi
249+
231250
#
232251
# Delete the central /etc/apt/sources.list and also all files in
233252
# /etc/apt/sources.list.d/ because only the Delphix repository
@@ -761,6 +780,25 @@ if ! systemd-detect-virt -qc; then
761780
die "failed to set-bootfs '$ROOTFS_CONTAINER'"
762781
fi
763782

783+
#
784+
# Ensure nodev and nosuid mount options are present for the /home entry
785+
# in /etc/fstab on the running host system. This is required for CIS
786+
# compliance on systems being upgraded that predate this hardening.
787+
# New upgrade containers already have these options set by upgrade-container.
788+
# This check is idempotent and only runs outside a container, consistent
789+
# with the pattern used for the GRUB update above.
790+
#
791+
if ! systemd-detect-virt -qc; then
792+
if grep -qE '^[^#].*[[:space:]]/home[[:space:]]' /etc/fstab; then
793+
if ! grep -qE '^[^#].*[[:space:]]/home[[:space:]].*nodev' /etc/fstab ||
794+
! grep -qE '^[^#].*[[:space:]]/home[[:space:]].*nosuid' /etc/fstab; then
795+
sed -i '/^[^#].*[[:space:]]\/home[[:space:]]/ s/defaults/defaults,nodev,nosuid/' \
796+
/etc/fstab ||
797+
die "failed to add nodev,nosuid to /home entry in /etc/fstab"
798+
fi
799+
fi
800+
fi
801+
764802
systemctl reload delphix-platform.service ||
765803
die "failed to reload delphix-platform.service"
766804

upgrade/upgrade-scripts/upgrade-container

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -212,19 +212,19 @@ function create_upgrade_container() {
212212
# associated with that rootfs dataset. The mounts need to happen
213213
# before the zfs-import service is run.
214214
#
215-
cat <<-EOF >"$DIRECTORY/etc/fstab"
216-
rpool/ROOT/$CONTAINER/home /home zfs defaults,nodev,nosuid,x-systemd.before=zfs-import-cache.service 0 0
217-
rpool/ROOT/$CONTAINER/data /var/delphix zfs defaults,x-systemd.before=zfs-import-cache.service 0 0
218-
rpool/ROOT/$CONTAINER/log /var/log zfs defaults,x-systemd.before=zfs-import-cache.service 0 0
219-
rpool/crashdump /var/crash zfs defaults,x-systemd.before=zfs-import-cache.service,x-systemd.before=kdump-tools.service 0 0
220-
EOF
221-
222-
if $TMP_DATASETS_EXIST; then
223-
cat <<-EOF >>"$DIRECTORY/etc/fstab"
224-
rpool/ROOT/$CONTAINER/tmp /tmp zfs defaults,nosuid,nodev,exec,x-systemd.before=zfs-import-cache.service 0 0
225-
rpool/ROOT/$CONTAINER/vartmp /var/tmp zfs defaults,nosuid,nodev,exec,x-systemd.before=zfs-import-cache.service 0 0
226-
EOF
227-
fi
215+
cat <<-EOF >"$DIRECTORY/etc/fstab"
216+
rpool/ROOT/$CONTAINER/home /home zfs defaults,nodev,nosuid,x-systemd.before=zfs-import-cache.service 0 0
217+
rpool/ROOT/$CONTAINER/data /var/delphix zfs defaults,x-systemd.before=zfs-import-cache.service 0 0
218+
rpool/ROOT/$CONTAINER/log /var/log zfs defaults,x-systemd.before=zfs-import-cache.service 0 0
219+
rpool/crashdump /var/crash zfs defaults,x-systemd.before=zfs-import-cache.service,x-systemd.before=kdump-tools.service 0 0
220+
EOF
221+
222+
if $TMP_DATASETS_EXIST; then
223+
cat <<-EOF >>"$DIRECTORY/etc/fstab"
224+
rpool/ROOT/$CONTAINER/tmp /tmp zfs defaults,nosuid,nodev,exec,x-systemd.before=zfs-import-cache.service 0 0
225+
rpool/ROOT/$CONTAINER/vartmp /var/tmp zfs defaults,nosuid,nodev,exec,x-systemd.before=zfs-import-cache.service 0 0
226+
EOF
227+
fi
228228

229229
#
230230
# DLPX-75089 - Since older versions of Delphix did not properly

0 commit comments

Comments
 (0)