Skip to content

Commit

Permalink
Merge pull request #96 from cgwalters/selinux-disabled
Browse files Browse the repository at this point in the history
install: Only invoke `chcon` if SELinux enabled in the source
  • Loading branch information
jmarrero authored Apr 28, 2023
2 parents 9cc9fee + fede3b7 commit a0f1035
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
18 changes: 16 additions & 2 deletions lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use serde::{Deserialize, Serialize};

use self::baseline::InstallBlockDeviceOpts;
use crate::containerenv::ContainerExecutionInfo;
use crate::lsm::lsm_label;
use crate::task::Task;
use crate::utils::run_in_host_mountns;

Expand Down Expand Up @@ -185,6 +184,21 @@ pub(crate) struct State {
pub(crate) install_config: config::InstallConfiguration,
}

impl State {
// Wraps core lsm labeling functionality, conditionalizing based on source state
pub(crate) fn lsm_label(
&self,
target: &Utf8Path,
as_path: &Utf8Path,
recurse: bool,
) -> Result<()> {
if !self.source.selinux {
return Ok(());
}
crate::lsm::lsm_label(target, as_path, recurse)
}
}

/// Path to initially deployed version information
const BOOTC_ALEPH_PATH: &str = ".bootc-aleph.json";

Expand Down Expand Up @@ -438,7 +452,7 @@ async fn initialize_ostree_root_from_self(
.run()?;

// Ensure everything in the ostree repo is labeled
lsm_label(&rootfs.join("ostree"), "/usr".into(), true)?;
state.lsm_label(&rootfs.join("ostree"), "/usr".into(), true)?;

let sysroot = ostree::Sysroot::new(Some(&gio::File::for_path(rootfs)));
sysroot.load(cancellable)?;
Expand Down
7 changes: 3 additions & 4 deletions lib/src/install/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use super::RootSetup;
use super::State;
use super::RUN_BOOTC;
use super::RW_KARG;
use crate::lsm::lsm_label;
use crate::mount;
use crate::task::Task;

Expand Down Expand Up @@ -346,15 +345,15 @@ pub(crate) fn install_create_rootfs(
.collect::<Vec<_>>();

mount::mount(&rootdev, &rootfs)?;
lsm_label(&rootfs, "/".into(), false)?;
state.lsm_label(&rootfs, "/".into(), false)?;
let rootfs_fd = Dir::open_ambient_dir(&rootfs, cap_std::ambient_authority())?;
let bootfs = rootfs.join("boot");
std::fs::create_dir(&bootfs).context("Creating /boot")?;
// The underlying directory on the root should be labeled
lsm_label(&bootfs, "/boot".into(), false)?;
state.lsm_label(&bootfs, "/boot".into(), false)?;
mount::mount(bootdev, &bootfs)?;
// And we want to label the root mount of /boot
lsm_label(&bootfs, "/boot".into(), false)?;
state.lsm_label(&bootfs, "/boot".into(), false)?;

// Create the EFI system partition, if applicable
if let Some(espdev) = espdev {
Expand Down

0 comments on commit a0f1035

Please sign in to comment.