-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set secontext for bind volumes in selinux enabled distros
Fixes #1882 Signed-off-by: T K Chandra Hasan <[email protected]>
- Loading branch information
Showing
4 changed files
with
120 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu -o pipefail | ||
|
||
scriptdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
# shellcheck source=common.inc.sh | ||
source "${scriptdir}/common.inc.sh" | ||
|
||
if [ "$#" -ne 1 ]; then | ||
ERROR "Usage: $0 NAME" | ||
exit 1 | ||
fi | ||
|
||
NAME="$1" | ||
expected="context=system_u:object_r:container_file_t:s0" | ||
#Skip Rosetta checks for x86 GHA mac runners | ||
if [ "$(arch)" == "arm64" ]; then | ||
INFO "Testing secontext is set for rosetta mounts" | ||
got=$(limactl shell "$NAME" mount | grep "rosetta" | awk '{print $6}') | ||
INFO "secontext rosetta: expected=${expected}, got=${got}" | ||
if [[ $got != *$expected* ]]; then | ||
ERROR "secontext for rosetta mount is not set or Invalid" | ||
exit 1 | ||
fi | ||
fi | ||
INFO "Testing secontext is set for bind mounts" | ||
INFO "Checking in mounts" | ||
got=$(limactl shell "$NAME" mount | grep "$HOME" | awk '{print $6}') | ||
INFO "secontext ${HOME}: expected=${expected}, got=${got}" | ||
if [[ $got != *$expected* ]]; then | ||
ERROR "secontext for \"$HOME\" dir is not set or Invalid" | ||
exit 1 | ||
fi | ||
got=$(limactl shell "$NAME" mount | grep "/tmp/lima" | awk '{print $6}') | ||
INFO "secontext /tmp/lima: expected=${expected}, got=${got}" | ||
if [[ $got != *$expected* ]]; then | ||
ERROR 'secontext for "/tmp/lima" dir is not set or Invalid' | ||
exit 1 | ||
fi | ||
INFO "Checking in fstab file" | ||
expected='context="system_u:object_r:container_file_t:s0"' | ||
got=$(limactl shell "$NAME" cat /etc/fstab | grep "$HOME" | awk '{print $4}') | ||
INFO "secontext ${HOME}: expected=${expected}, got=${got}" | ||
if [[ $got != *$expected* ]]; then | ||
ERROR "secontext for \"$HOME\" dir is not set or Invalid" | ||
exit 1 | ||
fi | ||
got=$(limactl shell "$NAME" cat /etc/fstab | grep "/tmp/lima" | awk '{print $4}') | ||
INFO "secontext /tmp/lima: expected=${expected}, got=${got}" | ||
if [[ $got != *$expected* ]]; then | ||
ERROR 'secontext for "/tmp/lima" dir is not set or Invalid' | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
set -eux -o pipefail | ||
|
||
# Check if mount type is virtiofs and vm type as vz | ||
if ! [[ ${LIMA_CIDATA_VMTYPE} == "vz" && ${LIMA_CIDATA_MOUNTTYPE} == "virtiofs" ]]; then | ||
exit 0 | ||
fi | ||
|
||
# Update fstab entries and unmount/remount the volumes with secontext options | ||
# when selinux is enabled in kernel | ||
if [ -d /sys/fs/selinux ]; then | ||
# shellcheck disable=SC2013 | ||
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 | ||
TAG=$(awk -v line="$line" 'NR==line {print $1}' /etc/fstab) | ||
MOUNT_POINT=$(awk -v line="$line" 'NR==line {print $2}' /etc/fstab) | ||
OPTIONS=$(awk -v line="$line" 'NR==line {print $4}' /etc/fstab) | ||
umount "${TAG}" | ||
mount -t virtiofs "${TAG}" "${MOUNT_POINT}" -o "${OPTIONS}" | ||
fi | ||
done | ||
fi |