Skip to content

Commit 6648d6c

Browse files
committed
imgstore: Fallback to container root sepolicy
Prior to this, get_ensure_imgstore would fail when run from a non-bootc system. Instead, in an attempt to make this function idempotent, let's fallback to the container root sepolicy instead of failing. This should only happen when running cleanup() during a to-existing install (i.e. there is not yet a bootc system). Signed-off-by: ckyrouac <[email protected]>
1 parent 3dbff8c commit 6648d6c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/src/store/mod.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::env;
33
use std::ops::Deref;
44

55
use anyhow::{Context, Result};
6+
use cap_std_ext::cap_std;
67
use cap_std_ext::cap_std::fs::Dir;
78
use cap_std_ext::dirext::CapStdExtDirExt;
89
use clap::ValueEnum;
@@ -88,15 +89,18 @@ impl Storage {
8889
}
8990
let sysroot_dir = crate::utils::sysroot_dir(&self.sysroot)?;
9091

91-
if self.sysroot.booted_deployment().is_none() {
92-
anyhow::bail!("Not a bootc system (this shouldn't be possible)");
93-
}
94-
95-
// load the sepolicy from the booted ostree deployment so the imgstorage can be
96-
// properly labeled with /var/lib/container/storage labels
97-
let dep = self.sysroot.booted_deployment().unwrap();
98-
let dep_fs = deployment_fd(&self.sysroot, &dep)?;
99-
let sepolicy = &ostree::SePolicy::new_at(dep_fs.as_raw_fd(), gio::Cancellable::NONE)?;
92+
let sepolicy = if self.sysroot.booted_deployment().is_none() {
93+
// fallback to policy from container root
94+
// this should only happen during cleanup of a broken install
95+
let container_root = Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
96+
&ostree::SePolicy::new_at(container_root.as_raw_fd(), gio::Cancellable::NONE)?
97+
} else {
98+
// load the sepolicy from the booted ostree deployment so the imgstorage can be
99+
// properly labeled with /var/lib/container/storage labels
100+
let dep = self.sysroot.booted_deployment().unwrap();
101+
let dep_fs = deployment_fd(&self.sysroot, &dep)?;
102+
&ostree::SePolicy::new_at(dep_fs.as_raw_fd(), gio::Cancellable::NONE)?
103+
};
100104

101105
let imgstore = crate::imgstorage::Storage::create(&sysroot_dir, &self.run, Some(sepolicy))?;
102106
Ok(self.imgstore.get_or_init(|| imgstore))

0 commit comments

Comments
 (0)