Skip to content

Commit 3c1843e

Browse files
committed
Update selinux label for rosetta from nfs_t to bin_t
With recent integration with systemd-binfmt,the existing nfs_t selinux label for Rosetta is causing issues while registering it. This behaviour needs to be fixed by setting the label as bin_t Signed-off-by: T K Chandra Hasan <[email protected]>
1 parent 6163a26 commit 3c1843e

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

hack/test-selinux.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ NAME="$1"
2020
## so keeping the label as nfs_t fits right. Package container-selinux by
2121
## default adds rules for nfs_t context which allows container workloads to work as well.
2222
## https://github.com/lima-vm/lima/pull/1965
23+
##
24+
## With integration[https://github.com/lima-vm/lima/pull/2474] with systemd-binfmt,
25+
## the existing "nfs_t" selinux label for Rosetta is causing issues while registering it.
26+
## This behaviour needs to be fixed by setting the label as "bin_t"
27+
## https://github.com/lima-vm/lima/pull/2630
2328
##########################################################################################
24-
expected="context=system_u:object_r:nfs_t:s0"
29+
INFO "Testing secontext is set for rosetta"
30+
expected="context=system_u:object_r:bin_t:s0"
2531
#Skip Rosetta checks for x86 GHA mac runners
2632
if [[ "$(uname)" == "Darwin" && "$(arch)" == "arm64" ]]; then
2733
INFO "Testing secontext is set for rosetta mounts"
@@ -33,6 +39,7 @@ if [[ "$(uname)" == "Darwin" && "$(arch)" == "arm64" ]]; then
3339
fi
3440
fi
3541
INFO "Testing secontext is set for bind mounts"
42+
expected="context=system_u:object_r:nfs_t:s0"
3643
INFO "Checking in mounts"
3744
got=$(limactl shell "$NAME" mount | grep "$HOME" | awk '{print $6}')
3845
INFO "secontext ${HOME}: expected=${expected}, got=${got}"

pkg/cidata/cidata.TEMPLATE.d/boot/05-lima-mounts.sh

+30-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ fi
1010
# Update fstab entries and unmount/remount the volumes with secontext options
1111
# when selinux is enabled in kernel
1212
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"
1315
# shellcheck disable=SC2013
1416
for line in $(grep -n virtiofs </etc/fstab | cut -d':' -f1); do
1517
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}')
1620
if [[ ${OPTIONS} != *"context"* ]]; then
1721
##########################################################################################
1822
## When using vz & virtiofs, initially container_file_t selinux label
@@ -22,13 +26,33 @@ if [ -d /sys/fs/selinux ]; then
2226
## so keeping the label as nfs_t fits right. Package container-selinux by
2327
## default adds rules for nfs_t context which allows container workloads to work as well.
2428
## 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
2534
##########################################################################################
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
3256
fi
3357
done
3458
fi

0 commit comments

Comments
 (0)