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

Add selinuxfs to be mounted in the container #344

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

bcrochet
Copy link
Contributor

As a follow-on to #302, we want to also mount the selinuxfs special filesystem if the host also has that filesystem mounted.

Related #303

@github-actions github-actions bot added the area/install Issues related to `bootc install` label Feb 14, 2024
@@ -865,37 +865,42 @@ pub(crate) fn setup_tmp_mounts() -> Result<()> {
#[context("Ensuring sys mounts")]
pub(crate) fn setup_sys_mounts() -> Result<()> {
tracing::debug!("Setting up sys mounts");
let filesystems = vec![
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor nit, we don't need to allocate here, dropping the vec! will get us a static slice.

@@ -865,37 +865,42 @@ pub(crate) fn setup_tmp_mounts() -> Result<()> {
#[context("Ensuring sys mounts")]
pub(crate) fn setup_sys_mounts() -> Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Offhand this looks sane, but we can also now drop the code elsewhere which was mounting selinuxfs right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this just become a function that takes a /sys subpath instead of looping? That seems to make more sense now that I look at it... Or as you said, we can just drop the other code that does this, and just make sure this is called ahead of where that was done before.

];
for (fstype, fspath) in filesystems {
let rootfs = format!("/proc/1/root/{fspath}");
// Does efivars even exist in the host? If not, we are
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment is outdated now, how about e.g. // Does this mountpoint exist on the host?

if inspect.is_ok() {
tracing::trace!("Already have efivarfs {root_efivars}");
return Ok(());
// First of all, does the container already have the mount?
Copy link
Collaborator

Choose a reason for hiding this comment

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

So I like the change conceptually to checking for a mountpoint...but unfortunately the is_mountpoint we have here right now is not 100% reliable.

Perhaps the simplest thing really is to check if the directory is non-empty here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.

@@ -750,7 +756,7 @@ pub(crate) fn reexecute_self_for_selinux_if_needed(
// already queried by something else (e.g. glib's constructor), we would also need
// to re-exec. But, selinux_ensure_install does that unconditionally right now too,
// so let's just fall through to that.
crate::lsm::container_setup_selinux()?;
let _ = setup_sys_mount("selinuxfs", SELINUXFS)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The let _ here looks unnecessary.

lib/src/lsm.rs Outdated
@@ -123,6 +123,7 @@ pub(crate) fn selinux_ensure_install_or_setenforce() -> Result<Option<SetEnforce

/// Ensure that /sys/fs/selinux is mounted, and ensure we're running
/// as install_t.
#[allow(dead_code)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can delete this function instead of marking it dead, no?

@@ -1002,7 +1001,7 @@ async fn prepare_install(
super::cli::ensure_self_unshared_mount_namespace().await?;
}

setup_sys_mounts()?;
let _ = setup_sys_mount("efivarfs", EFIVARFS)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto here.

// Check that the path that should be mounted is even populated.
// Since we are dealing with /sys mounts here, if it's populated,
// we can be at least a little certain that it's mounted.
if Path::new(fspath).try_exists()? && !std::fs::read_dir(fspath)?.next().is_none() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor nit, I think std::fs::read_dir(fspath)?.next().is_some() is easier to read (avoids double negation)

As a follow-on to containers#302, we want to also mount the selinuxfs special
filesystem if the host also has that filesystem mounted.

Related containers#303

Signed-off-by: Brad P. Crochet <brad@redhat.com>
@cgwalters cgwalters merged commit e9516ef into containers:main Feb 15, 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.

None yet

2 participants