-
Notifications
You must be signed in to change notification settings - Fork 600
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
Set secontext for bind volumes in selinux enabled distros #1942
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 [[ "$(uname)" == "Darwin" && "$(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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should check
limactl shell "$NAME" getenforce
, not the nameThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getenforce would be available on fedro based distros, hence the name is used. For other distros, we need to handle the command being not found error.