Skip to content

Commit 7cb2b2e

Browse files
authored
Merge pull request #1965 from hasan4791/fix-selabel
Update selinux label from container_file_t to nfs_t
2 parents 3dff1ab + 81a4904 commit 7cb2b2e

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

hack/test-selinux.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ if [ "$#" -ne 1 ]; then
1212
fi
1313

1414
NAME="$1"
15-
expected="context=system_u:object_r:container_file_t:s0"
15+
##########################################################################################
16+
## When using vz & virtiofs, initially container_file_t selinux label
17+
## was considered which works perfectly for container work loads
18+
## but it might break for other work loads if the process is running with
19+
## different label. Also these are the remote mounts from the host machine,
20+
## so keeping the label as nfs_t fits right. Package container-selinux by
21+
## default adds rules for nfs_t context which allows container workloads to work as well.
22+
## https://github.com/lima-vm/lima/pull/1965
23+
##########################################################################################
24+
expected="context=system_u:object_r:nfs_t:s0"
1625
#Skip Rosetta checks for x86 GHA mac runners
1726
if [[ "$(uname)" == "Darwin" && "$(arch)" == "arm64" ]]; then
1827
INFO "Testing secontext is set for rosetta mounts"
@@ -38,7 +47,7 @@ if [[ $got != *$expected* ]]; then
3847
exit 1
3948
fi
4049
INFO "Checking in fstab file"
41-
expected='context="system_u:object_r:container_file_t:s0"'
50+
expected='context="system_u:object_r:nfs_t:s0"'
4251
got=$(limactl shell "$NAME" cat /etc/fstab | grep "$HOME" | awk '{print $4}')
4352
INFO "secontext ${HOME}: expected=${expected}, got=${got}"
4453
if [[ $got != *$expected* ]]; then

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ if [ -d /sys/fs/selinux ]; then
1414
for line in $(grep -n virtiofs </etc/fstab | cut -d':' -f1); do
1515
OPTIONS=$(awk -v line="$line" 'NR==line {print $4}' /etc/fstab)
1616
if [[ ${OPTIONS} != *"context"* ]]; then
17-
sed -i -e "$line""s/comment=cloudconfig/comment=cloudconfig,context=\"system_u:object_r:container_file_t:s0\"/g" /etc/fstab
17+
##########################################################################################
18+
## When using vz & virtiofs, initially container_file_t selinux label
19+
## was considered which works perfectly for container work loads
20+
## but it might break for other work loads if the process is running with
21+
## different label. Also these are the remote mounts from the host machine,
22+
## so keeping the label as nfs_t fits right. Package container-selinux by
23+
## default adds rules for nfs_t context which allows container workloads to work as well.
24+
## https://github.com/lima-vm/lima/pull/1965
25+
##########################################################################################
26+
sed -i -e "$line""s/comment=cloudconfig/comment=cloudconfig,context=\"system_u:object_r:nfs_t:s0\"/g" /etc/fstab
1827
TAG=$(awk -v line="$line" 'NR==line {print $1}' /etc/fstab)
1928
MOUNT_POINT=$(awk -v line="$line" 'NR==line {print $2}' /etc/fstab)
2029
OPTIONS=$(awk -v line="$line" 'NR==line {print $4}' /etc/fstab)

pkg/cidata/cidata.TEMPLATE.d/boot/05-rosetta-volume.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ mkdir -p /mnt/lima-rosetta
1414

1515
#Check selinux is enabled by kernel
1616
if [ -d /sys/fs/selinux ]; then
17-
mount -t virtiofs vz-rosetta /mnt/lima-rosetta -o context="system_u:object_r:container_file_t:s0"
17+
##########################################################################################
18+
## When using vz & virtiofs, initially container_file_t selinux label
19+
## was considered which works perfectly for container work loads
20+
## but it might break for other work loads if the process is running with
21+
## different label. Also these are the remote mounts from the host machine,
22+
## so keeping the label as nfs_t fits right. Package container-selinux by
23+
## default adds rules for nfs_t context which allows container workloads to work as well.
24+
## https://github.com/lima-vm/lima/pull/1965
25+
##########################################################################################
26+
mount -t virtiofs vz-rosetta /mnt/lima-rosetta -o context="system_u:object_r:nfs_t:s0"
1827
else
1928
mount -t virtiofs vz-rosetta /mnt/lima-rosetta
2029
fi

0 commit comments

Comments
 (0)