2013-05-14 00:03:24 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2014-09-04 04:56:29 +00:00
|
|
|
if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
set -eu
|
2014-03-29 03:28:22 +00:00
|
|
|
set -o pipefail
|
2017-03-17 17:22:17 +00:00
|
|
|
|
2017-05-18 18:09:32 +00:00
|
|
|
SETFILES=$(type -p setfiles || true)
|
2015-04-16 18:47:19 +00:00
|
|
|
if [ -e /etc/selinux/targeted/contexts/files/file_contexts -a -x "${SETFILES}" ]; then
|
2017-03-17 17:22:17 +00:00
|
|
|
# get all mounpoints in the system
|
|
|
|
IFS='|' read -ra SPLIT_MOUNTS <<< "$DIB_MOUNTPOINTS"
|
|
|
|
for MOUNTPOINT in "${SPLIT_MOUNTS[@]}"; do
|
|
|
|
# Without fixing selinux file labels, sshd will run in the kernel_t domain
|
|
|
|
# instead of the sshd_t domain, making ssh connections fail with
|
|
|
|
# "Unable to get valid context for <user>" error message
|
|
|
|
if [ "${MOUNTPOINT}" != "/tmp/in_target.d" ] && [ "${MOUNTPOINT}" != "/dev" ]; then
|
2017-07-19 08:48:14 +00:00
|
|
|
# setfiles in > Fedora 26 added this flag:
|
|
|
|
# do not read /proc/mounts to obtain a list of
|
|
|
|
# non-seclabel mounts to be excluded from relabeling
|
|
|
|
# checks. Setting this option is useful where there is
|
|
|
|
# a non-seclabel fs mounted with a seclabel fs
|
|
|
|
# this describes our situation of being on a loopback device on
|
|
|
|
# an ubuntu system, say. See also
|
|
|
|
# https://bugzilla.redhat.com/show_bug.cgi?id=1472709
|
|
|
|
_dash_m=""
|
|
|
|
if [[ $DISTRO_NAME == "fedora" && $DIB_RELEASE -ge 26 ]]; then
|
|
|
|
_dash_m+="-m"
|
|
|
|
fi
|
|
|
|
$SETFILES ${_dash_m} /etc/selinux/targeted/contexts/files/file_contexts ${MOUNTPOINT}
|
2017-03-17 17:22:17 +00:00
|
|
|
fi
|
|
|
|
done
|
2014-01-23 12:21:58 +00:00
|
|
|
else
|
2014-07-21 13:31:55 +00:00
|
|
|
echo "Skipping SELinux relabel, since setfiles is not available."
|
|
|
|
echo "Touching /.autorelabel to schedule a relabel when the image boots."
|
|
|
|
touch /.autorelabel
|
2014-01-23 12:21:58 +00:00
|
|
|
fi
|
2017-03-17 17:22:17 +00:00
|
|
|
|