10
10
# Update fstab entries and unmount/remount the volumes with secontext options
11
11
# when selinux is enabled in kernel
12
12
if [ -d /sys/fs/selinux ]; then
13
+ LABEL_BIN=" system_u:object_r:bin_t:s0"
14
+ LABEL_NFS=" system_u:object_r:nfs_t:s0"
13
15
# shellcheck disable=SC2013
14
16
for line in $( grep -n virtiofs < /etc/fstab | cut -d' :' -f1) ; do
15
17
OPTIONS=$( awk -v line=" $line " ' NR==line {print $4}' /etc/fstab)
18
+ TAG=$( awk -v line=" $line " ' NR==line {print $1}' /etc/fstab)
19
+ MOUNT_OPTIONS=$( mount | grep " ${TAG} " | awk ' {print $6}' )
16
20
if [[ ${OPTIONS} != * " context" * ]]; then
17
21
# #########################################################################################
18
22
# # When using vz & virtiofs, initially container_file_t selinux label
@@ -22,13 +26,33 @@ if [ -d /sys/fs/selinux ]; then
22
26
# # so keeping the label as nfs_t fits right. Package container-selinux by
23
27
# # default adds rules for nfs_t context which allows container workloads to work as well.
24
28
# # https://github.com/lima-vm/lima/pull/1965
29
+ # #
30
+ # # With integration[https://github.com/lima-vm/lima/pull/2474] with systemd-binfmt,
31
+ # # the existing "nfs_t" selinux label for Rosetta is causing issues while registering it.
32
+ # # This behaviour needs to be fixed by setting the label as "bin_t"
33
+ # # https://github.com/lima-vm/lima/pull/2630
25
34
# #########################################################################################
26
- sed -i -e " $line " " s/comment=cloudconfig/comment=cloudconfig,context=\" system_u:object_r:nfs_t:s0\" /g" /etc/fstab
27
- TAG=$( awk -v line=" $line " ' NR==line {print $1}' /etc/fstab)
28
- MOUNT_POINT=$( awk -v line=" $line " ' NR==line {print $2}' /etc/fstab)
29
- OPTIONS=$( awk -v line=" $line " ' NR==line {print $4}' /etc/fstab)
30
- umount " ${TAG} "
31
- mount -t virtiofs " ${TAG} " " ${MOUNT_POINT} " -o " ${OPTIONS} "
35
+ if [[ ${TAG} == * " rosetta" * ]]; then
36
+ label=${LABEL_BIN}
37
+ else
38
+ label=${LABEL_NFS}
39
+ fi
40
+ sed -i -e " $line " " s/comment=cloudconfig/comment=cloudconfig,context=\" $label \" /g" /etc/fstab
41
+ if [[ ${MOUNT_OPTIONS} != * " $label " * ]]; then
42
+ MOUNT_POINT=$( awk -v line=" $line " ' NR==line {print $2}' /etc/fstab)
43
+ OPTIONS=$( awk -v line=" $line " ' NR==line {print $4}' /etc/fstab)
44
+
45
+ # ########################################################
46
+ # # We need to migrate existing users of Fedora having
47
+ # # Rosetta mounted from nfs_t to bin_t by unregistering
48
+ # # it from binfmt before remounting
49
+ # ########################################################
50
+ if [[ ${TAG} == * " rosetta" * && ${MOUNT_OPTIONS} == * " ${LABEL_NFS} " * ]]; then
51
+ [ ! -f " /proc/sys/fs/binfmt_misc/rosetta" ] || echo -1 > /proc/sys/fs/binfmt_misc/rosetta
52
+ fi
53
+ umount " ${TAG} "
54
+ mount -t virtiofs " ${TAG} " " ${MOUNT_POINT} " -o " ${OPTIONS} "
55
+ fi
32
56
fi
33
57
done
34
58
fi
0 commit comments