Skip to content

Commit fb29b58

Browse files
committed
install: Add final SELinux relabel of the physical root filesystem
Perform a full SELinux relabel pass over the physical root filesystem as the very last step before filesystem finalization. This ensures all files on the physical root have correct SELinux labels. The ostree/deploy directory is skipped since its contents are already correctly labeled as part of the container image deployment. If ostree/deploy doesn't exist (e.g. composefs backend), the entire tree is relabeled. Assisted-by: OpenCode (claude-opus-4-6) Signed-off-by: John Eckersberg <jeckersb@redhat.com>
1 parent 26bdef2 commit fb29b58

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

crates/lib/src/install.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,33 @@ async fn install_to_filesystem_impl(
19701970
ostree_install(state, rootfs, cleanup).await?;
19711971
}
19721972

1973+
// As the very last step before filesystem finalization, do a full SELinux
1974+
// relabel of the physical root filesystem. We skip ostree/deploy because
1975+
// the contents there are already correctly labeled as part of the
1976+
// container image deployment.
1977+
if let Some(policy) = state.load_policy()? {
1978+
tracing::info!("Performing final SELinux relabeling of physical root");
1979+
let skip_devino = if let Some(deploy_dir) =
1980+
rootfs.physical_root.open_dir_optional("ostree/deploy")?
1981+
{
1982+
let deploy_meta = deploy_dir.dir_metadata()?;
1983+
Some((deploy_meta.dev(), deploy_meta.ino()))
1984+
} else {
1985+
tracing::debug!("No ostree/deploy directory found; relabeling everything");
1986+
None
1987+
};
1988+
let mut path = Utf8PathBuf::from("");
1989+
crate::lsm::ensure_dir_labeled_recurse(
1990+
&rootfs.physical_root,
1991+
&mut path,
1992+
&policy,
1993+
skip_devino,
1994+
)
1995+
.context("Final SELinux relabeling of physical root")?;
1996+
} else {
1997+
tracing::debug!("Skipping final SELinux relabel (SELinux is disabled)");
1998+
}
1999+
19732000
// Finalize mounted filesystems
19742001
if !rootfs.skip_finalize {
19752002
let bootfs = rootfs.boot.as_ref().map(|_| ("boot", "boot"));

0 commit comments

Comments
 (0)