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

Make --disable-selinux work on hosts that have selinux=0 #340

Merged
merged 2 commits into from
Feb 14, 2024

Conversation

ckyrouac
Copy link
Contributor

@ckyrouac ckyrouac commented Feb 13, 2024

Prior to this fix the selinux_enabled function would always return true, even if selinux was set to disabled or permissive.

fixed #303

Copy link
Collaborator

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

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

For testing coverage...a bit tricky right now as we'd need to boot a system with your case of selinux=0 and run an install from it. We have a legacy here of using the coreos "kola" testing framework, and I am hoping that we can eventually align with what's happening in
https://gitlab.com/bootc-org/tests

I'm OK without an integration test here for this for now, it's not like we're likely to regress on normal pull requests.

lib/src/lsm.rs Outdated
let path = "/proc/1/root/sys/fs/selinux/enforce";
if Path::new(path).exists() {
let enabled = std::fs::read_to_string(path)?;
return Ok(enabled.eq("1"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a bit more idiomatic to do enabled == "1"

However...I think we actually should work even if enforce == 0. So this check can probably just boil down to

Path::new("/proc/1/root/sys/fs/selinux/enforce").try_exists().map_err(Into::into)

or so right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

However...I think we actually should work even if enforce == 0

To elaborate slightly, this is the current case in Anaconda - it boots with enforcing=0. Our existing install logic should work just fine in this case.

It's really the case of selinux=0 (fully disabled at runtime) that we need a fallback behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah that makes sense, if the labels exist then bootc should work. For some reason that is not the case right now (i.e. the labels are broken on the image when installing from a host with selinux set to permissive), I guess that is what @bcrochet is working on?

I fixed the first commit with your suggestions. I also added a second commit to prioritize the --disable-selinux flag. It seems wrong to silently ignore the flag if the host has selinux enabled. I'm probably missing something though. Flipping those if statements makes install to-disk --disable-selinuc work from a host with selinux set to permissive though.

@github-actions github-actions bot added the area/install Issues related to `bootc install` label Feb 13, 2024
@cgwalters
Copy link
Collaborator

cgwalters commented Feb 13, 2024

Looks generally good, just two nits:

First commit maybe:

lsm: Look for selinuxfs mounted on host

This ensures we handle the case where SELinux is compiled in the kernel (e.g. Fedora)
but where it's disabled at runtime via selinux=0.

And the second commit for example:

install: Make --disable-selinux always override host state

If the user explicitly disables SELinux, we should always honor that and not
care about the host state.

or so?

This ensures we handle the case where SELinux is compile in the kernel
(e.g. Fedora) but where it's disabled at runtime via selinux=0.

fixes containers#303

Signed-off-by: ckyrouac <[email protected]>
If the user disables SELinux, we should always honor that and not care
about the host state.

fixes: containers#303

Signed-off-by: ckyrouac <[email protected]>
Copy link
Collaborator

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

@cgwalters cgwalters enabled auto-merge February 14, 2024 13:41
@ckyrouac
Copy link
Contributor Author

thanks for the reviews!

@cgwalters cgwalters changed the title Fix selinux_enabled function Make --disable-selinux work on hosts that have selinux=0 Feb 14, 2024
@cgwalters cgwalters merged commit 92adf21 into containers:main Feb 14, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/install Issues related to `bootc install`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bootc install to-disk --disable-selinux does not disable selinux when the host has selinux disabled
2 participants