Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update selinux label from container_file_t to nfs_t #1965

Merged
merged 1 commit into from
Oct 30, 2023

Conversation

hasan4791
Copy link
Contributor

When using vz & virtiofs, initially container_file_t selinux label was considered which works perfectly for container work loads but it might break for other work loads if the process is running with different label. Also these are the remote mounts from the host machine, keeping the label as nfs_t fits right. Package "container-selinux" by default adds rules for nfs_t context which allows container workloads to work as well.

@AkihiroSuda AkihiroSuda added this to the v1.0 milestone Oct 30, 2023
@AkihiroSuda AkihiroSuda added guest/el8 Guest: CentOS 8 / Rocky Linux 8 / Alma Linux 8 guest/fedora Guest: Fedora podman guest/el9 labels Oct 30, 2023
AkihiroSuda
AkihiroSuda previously approved these changes Oct 30, 2023
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@@ -12,7 +12,7 @@ if [ "$#" -ne 1 ]; then
fi

NAME="$1"
expected="context=system_u:object_r:container_file_t:s0"
expected="context=system_u:object_r:nfs_t:s0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment to explain why nfs_t?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use the same comment as in description?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also when compared with 9p on qemu, it also using nfs_t. So I think we're using this label as all those mounts are remote mounts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

@@ -14,7 +14,7 @@ if [ -d /sys/fs/selinux ]; then
for line in $(grep -n virtiofs </etc/fstab | cut -d':' -f1); do
OPTIONS=$(awk -v line="$line" 'NR==line {print $4}' /etc/fstab)
if [[ ${OPTIONS} != *"context"* ]]; then
sed -i -e "$line""s/comment=cloudconfig/comment=cloudconfig,context=\"system_u:object_r:container_file_t:s0\"/g" /etc/fstab
sed -i -e "$line""s/comment=cloudconfig/comment=cloudconfig,context=\"system_u:object_r:nfs_t:s0\"/g" /etc/fstab
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment to explain why nfs_t?

@@ -14,7 +14,7 @@ mkdir -p /mnt/lima-rosetta

#Check selinux is enabled by kernel
if [ -d /sys/fs/selinux ]; then
mount -t virtiofs vz-rosetta /mnt/lima-rosetta -o context="system_u:object_r:container_file_t:s0"
mount -t virtiofs vz-rosetta /mnt/lima-rosetta -o context="system_u:object_r:nfs_t:s0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment to explain why nfs_t?

When using vz & virtiofs, initially container_file_t selinux label
was considered which works perfectly for container work loads
but it might break for other work loads if the process is running with
different label. Also these are the remote mounts from the host machine,
so keeping the label as nfs_t fits right. Package container-selinux by
default adds rules for nfs_t context which allows container workloads to work as well.

Signed-off-by: T K Chandra Hasan <t.k.chandra.hasan@ibm.com>
@@ -14,7 +14,16 @@ if [ -d /sys/fs/selinux ]; then
for line in $(grep -n virtiofs </etc/fstab | cut -d':' -f1); do
OPTIONS=$(awk -v line="$line" 'NR==line {print $4}' /etc/fstab)
if [[ ${OPTIONS} != *"context"* ]]; then
sed -i -e "$line""s/comment=cloudconfig/comment=cloudconfig,context=\"system_u:object_r:container_file_t:s0\"/g" /etc/fstab
##########################################################################################
## When using vz & virtiofs, initially container_file_t selinux label
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation seems broken

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint looks ok 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, looks like just a glitch of github web UI

@AkihiroSuda AkihiroSuda merged commit 7cb2b2e into lima-vm:master Oct 30, 2023
24 checks passed
@AkihiroSuda AkihiroSuda modified the milestones: v1.0, v0.18.1 Oct 30, 2023
@hasan4791 hasan4791 deleted the fix-selabel branch September 18, 2024 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guest/el8 Guest: CentOS 8 / Rocky Linux 8 / Alma Linux 8 guest/el9 guest/fedora Guest: Fedora podman
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants