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

Set secontext for bind volumes in selinux enabled distros #1942

Merged
merged 1 commit into from
Oct 27, 2023

Conversation

hasan4791
Copy link
Contributor

@hasan4791 hasan4791 commented Oct 24, 2023

Fixes #1882
Signed-off-by: T K Chandra Hasan [email protected]

The approach taken here is, once the mounts are created using the parameters in user-data, we would be unmounting the existing mounts and remounting with secontext options for selinux enabled distros. It would update the /etc/fstab file also. The context type we have taken here is container_file_t, as it would be easier to mount those directories inside the container.

@hasan4791 hasan4791 force-pushed the issue-1882 branch 2 times, most recently from 8e4c047 to bbcf83f Compare October 24, 2023 10:58
@hasan4791 hasan4791 changed the title Set secontext for bind volumes in selinux enabled distros WIP: Set secontext for bind volumes in selinux enabled distros Oct 24, 2023
@hasan4791 hasan4791 force-pushed the issue-1882 branch 3 times, most recently from db6121a to 83ca1f3 Compare October 24, 2023 13:30
@hasan4791
Copy link
Contributor Author

@AkihiroSuda Could you please help me with the tests.
Upgrade test seems to pass sometime also fails sometime.
I've added a new test, "test-vz-fedora" which seems to be skipped. Not sure whats going on.

@AkihiroSuda
Copy link
Member

Upgrade test seems to pass sometime also fails sometime.

This one seems flaky.

I've added a new test, "test-vz-fedora" which seems to be skipped. Not sure whats going on.

macos-13 runner for vz is known to be flaky and does not produce error logs 😞

matrix:
template:
- templates/experimental/vz.yaml
- hack/test-templates/test-vz-fedora.yaml
Copy link
Member

Choose a reason for hiding this comment

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

Can we just use templates/fedora.yaml ?

test-templates.sh can be modified to receive --vm-type=vz via arg or env

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't know we can use like this. I'll update.

@@ -24,3 +24,42 @@ if [ "$got" != "$expected" ]; then
ERROR "Home directory is not shared?"
exit 1
fi

if [ "${NAME}" == "test-vz-fedora" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

Probably this should be split to hack/test-selinux.sh

@hasan4791 hasan4791 force-pushed the issue-1882 branch 3 times, most recently from 0ab4aef to f10c3aa Compare October 25, 2023 02:55
@hasan4791 hasan4791 changed the title WIP: Set secontext for bind volumes in selinux enabled distros Set secontext for bind volumes in selinux enabled distros Oct 25, 2023
@hasan4791
Copy link
Contributor Author

@AkihiroSuda PTAL

@AkihiroSuda
Copy link
Member

vz (Fedora) CI seems failing in TEST| [INFO] Testing secontext is set for rosetta mounts
https://github.com/lima-vm/lima/actions/runs/6635170336/job/18026648710?pr=1942

WARNING "Relaxing systemd tests for vz-fedora (For avoiding CI failure)"
CHECKS["systemd-strict"]=
CHECKS["vz-selinux"]=1
LIMACTL_SUBCMDS=(--vm-type vz --mount-type virtiofs --rosetta --network vzNAT)
Copy link
Member

Choose a reason for hiding this comment

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

Can we provide this via env var?

@hasan4791 hasan4791 force-pushed the issue-1882 branch 3 times, most recently from 92e3c21 to 3936c02 Compare October 25, 2023 10:19
@hasan4791
Copy link
Contributor Author

Uff, vz ci jobs are too much flaky.

@hasan4791
Copy link
Contributor Author

Finally 🥳

- name: Make
run: make
- name: Install
run: make install
- name: Install test dependencies
run: brew install qemu bash coreutils
- name: Test
run: ./hack/test-templates.sh templates/experimental/vz.yaml
env:
ARGS: "--vm-type vz --mount-type virtiofs --rosetta --network vzNAT"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ARGS: "--vm-type vz --mount-type virtiofs --rosetta --network vzNAT"
LIMACTL_CREATE_ARGS: "--vm-type vz --mount-type virtiofs --rosetta --network vzNAT"

Copy link
Member

Choose a reason for hiding this comment

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

(These args will no longer be needed after merging:

- template: experimental/vz.yaml
name: default
- template: fedora.yaml
name: vz-fedora
Copy link
Member

Choose a reason for hiding this comment

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

"name" is not needed IIUC

@@ -389,6 +407,10 @@ if [[ -n ${CHECKS["snapshot-offline"]} ]]; then
limactl start "$NAME"
fi

if [[ -n ${CHECKS["vz-selinux"]} ]]; then
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to run this only for vz based VMs and so we filter the check based on the vm name.

Copy link
Member

Choose a reason for hiding this comment

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

Can we just check limactl ls --json "$NAME" | jq -r .vmType ?

@AkihiroSuda AkihiroSuda added this to the v1.0 (tentative) milestone Oct 26, 2023
@AkihiroSuda AkihiroSuda added guest/el8 Guest: CentOS 8 / Rocky Linux 8 / Alma Linux 8 guest/fedora Guest: Fedora guest/el9 labels Oct 26, 2023
NAME="$1"
expected="context=system_u:object_r:container_file_t:s0"
#Skip Rosetta checks for x86 GHA mac runners
if [ "$(arch)" == "arm64" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if [ "$(arch)" == "arm64" ]; then
if [ "$(uname)" == "Darwin" ] && [ "$(arch)" == "arm64" ]; then

@@ -223,7 +230,7 @@ if [[ -n ${CHECKS["port-forwards"]} ]]; then
if [ "${NAME}" = "debian" ]; then
limactl shell "$NAME" sudo apt-get install -y netcat-openbsd
fi
if [ "${NAME}" = "fedora" ]; then
if [[ ${NAME} == *"fedora"* ]]; then
Copy link
Member

Choose a reason for hiding this comment

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

No longer needed

@@ -389,6 +396,10 @@ if [[ -n ${CHECKS["snapshot-offline"]} ]]; then
limactl start "$NAME"
fi

if [[ $NAME == "fedora" && "$(limactl ls --json "$NAME" | jq -r .vmType)" == "vz" ]]; then
Copy link
Member

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 name

Copy link
Contributor Author

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.

AkihiroSuda
AkihiroSuda previously approved these changes Oct 26, 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

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

@AkihiroSuda AkihiroSuda merged commit dddbb71 into lima-vm:master Oct 27, 2023
24 checks passed
@AkihiroSuda AkihiroSuda modified the milestones: v1.0, v0.18.1 Oct 30, 2023
@hasan4791 hasan4791 deleted the issue-1882 branch September 19, 2024 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/vz guest/el8 Guest: CentOS 8 / Rocky Linux 8 / Alma Linux 8 guest/el9 guest/fedora Guest: Fedora
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vz: podman "Permission denied" on bind mounts
2 participants