Skip to content

Commit 29e9a4e

Browse files
authored
Merge pull request #844 from cgwalters/install-selinux-check-generic
install: Just check etc/selinux/config if we don't have ostree
2 parents af4c07b + 7d0660b commit 29e9a4e

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

lib/src/install.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use serde::{Deserialize, Serialize};
4545

4646
use self::baseline::InstallBlockDeviceOpts;
4747
use crate::containerenv::ContainerExecutionInfo;
48+
use crate::lsm;
4849
use crate::mount::Filesystem;
4950
use crate::spec::ImageReference;
5051
use crate::store::Storage;
@@ -525,15 +526,9 @@ impl SourceInfo {
525526
Self::new(imageref, None, root, false, false)
526527
}
527528

528-
/// Construct a new source information structure
529-
fn new(
530-
imageref: ostree_container::ImageReference,
531-
digest: Option<String>,
532-
root: &Dir,
533-
in_host_mountns: bool,
534-
have_host_container_storage: bool,
535-
) -> Result<Self> {
529+
fn have_selinux_from_repo(root: &Dir) -> Result<bool> {
536530
let cancellable = ostree::gio::Cancellable::NONE;
531+
537532
let commit = Task::new("Reading ostree commit", "ostree")
538533
.args(["--repo=/ostree/repo", "rev-parse", "--single"])
539534
.quiet()
@@ -545,7 +540,22 @@ impl SourceInfo {
545540
.0;
546541
let root = root.downcast_ref::<ostree::RepoFile>().unwrap();
547542
let xattrs = root.xattrs(cancellable)?;
548-
let selinux = crate::lsm::xattrs_have_selinux(&xattrs);
543+
Ok(crate::lsm::xattrs_have_selinux(&xattrs))
544+
}
545+
546+
/// Construct a new source information structure
547+
fn new(
548+
imageref: ostree_container::ImageReference,
549+
digest: Option<String>,
550+
root: &Dir,
551+
in_host_mountns: bool,
552+
have_host_container_storage: bool,
553+
) -> Result<Self> {
554+
let selinux = if Path::new("/ostree/repo").try_exists()? {
555+
Self::have_selinux_from_repo(root)?
556+
} else {
557+
lsm::have_selinux_policy(root)?
558+
};
549559
Ok(Self {
550560
imageref,
551561
digest,

lib/src/lsm.rs

+7
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ pub(crate) fn selinux_ensure_install() -> Result<bool> {
9898
Err(anyhow::Error::msg(cmd.exec()).context("execve"))
9999
}
100100

101+
/// Query whether SELinux is apparently enabled in the target root
102+
#[cfg(feature = "install")]
103+
pub(crate) fn have_selinux_policy(root: &Dir) -> Result<bool> {
104+
// TODO use ostree::SePolicy and query policy name
105+
root.try_exists("etc/selinux/config").map_err(Into::into)
106+
}
107+
101108
/// A type which will reset SELinux back to enforcing mode when dropped.
102109
/// This is a workaround for the deep difficulties in trying to reliably
103110
/// gain the `mac_admin` permission (install_t).

0 commit comments

Comments
 (0)