Skip to content

Commit a0f1035

Browse files
authored
Merge pull request #96 from cgwalters/selinux-disabled
install: Only invoke `chcon` if SELinux enabled in the source
2 parents 9cc9fee + fede3b7 commit a0f1035

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

lib/src/install.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use serde::{Deserialize, Serialize};
3232

3333
use self::baseline::InstallBlockDeviceOpts;
3434
use crate::containerenv::ContainerExecutionInfo;
35-
use crate::lsm::lsm_label;
3635
use crate::task::Task;
3736
use crate::utils::run_in_host_mountns;
3837

@@ -185,6 +184,21 @@ pub(crate) struct State {
185184
pub(crate) install_config: config::InstallConfiguration,
186185
}
187186

187+
impl State {
188+
// Wraps core lsm labeling functionality, conditionalizing based on source state
189+
pub(crate) fn lsm_label(
190+
&self,
191+
target: &Utf8Path,
192+
as_path: &Utf8Path,
193+
recurse: bool,
194+
) -> Result<()> {
195+
if !self.source.selinux {
196+
return Ok(());
197+
}
198+
crate::lsm::lsm_label(target, as_path, recurse)
199+
}
200+
}
201+
188202
/// Path to initially deployed version information
189203
const BOOTC_ALEPH_PATH: &str = ".bootc-aleph.json";
190204

@@ -438,7 +452,7 @@ async fn initialize_ostree_root_from_self(
438452
.run()?;
439453

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

443457
let sysroot = ostree::Sysroot::new(Some(&gio::File::for_path(rootfs)));
444458
sysroot.load(cancellable)?;

lib/src/install/baseline.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use super::RootSetup;
2626
use super::State;
2727
use super::RUN_BOOTC;
2828
use super::RW_KARG;
29-
use crate::lsm::lsm_label;
3029
use crate::mount;
3130
use crate::task::Task;
3231

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

348347
mount::mount(&rootdev, &rootfs)?;
349-
lsm_label(&rootfs, "/".into(), false)?;
348+
state.lsm_label(&rootfs, "/".into(), false)?;
350349
let rootfs_fd = Dir::open_ambient_dir(&rootfs, cap_std::ambient_authority())?;
351350
let bootfs = rootfs.join("boot");
352351
std::fs::create_dir(&bootfs).context("Creating /boot")?;
353352
// The underlying directory on the root should be labeled
354-
lsm_label(&bootfs, "/boot".into(), false)?;
353+
state.lsm_label(&bootfs, "/boot".into(), false)?;
355354
mount::mount(bootdev, &bootfs)?;
356355
// And we want to label the root mount of /boot
357-
lsm_label(&bootfs, "/boot".into(), false)?;
356+
state.lsm_label(&bootfs, "/boot".into(), false)?;
358357

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

0 commit comments

Comments
 (0)