Skip to content

Commit 83a57e5

Browse files
authored
Merge pull request #707 from cgwalters/bound-install-time-prep
install: Two prep changes for pulling bound images at install time
2 parents 532fbcc + 5a0b50d commit 83a57e5

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

lib/src/install.rs

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -542,15 +542,9 @@ pub(crate) fn print_configuration() -> Result<()> {
542542
}
543543

544544
#[context("Creating ostree deployment")]
545-
async fn initialize_ostree_root_from_self(
546-
state: &State,
547-
root_setup: &RootSetup,
548-
) -> Result<InstallAleph> {
545+
async fn initialize_ostree_root(state: &State, root_setup: &RootSetup) -> Result<ostree::Sysroot> {
549546
let sepolicy = state.load_policy()?;
550547
let sepolicy = sepolicy.as_ref();
551-
552-
let container_rootfs = &Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
553-
554548
// Load a fd for the mounted target physical root
555549
let rootfs_dir = &root_setup.rootfs_fd;
556550
let rootfs = root_setup.rootfs.as_path();
@@ -607,6 +601,20 @@ async fn initialize_ostree_root_from_self(
607601

608602
let sysroot = ostree::Sysroot::new(Some(&gio::File::for_path(rootfs)));
609603
sysroot.load(cancellable)?;
604+
Ok(sysroot)
605+
}
606+
607+
#[context("Creating ostree deployment")]
608+
async fn install_container(
609+
state: &State,
610+
root_setup: &RootSetup,
611+
sysroot: &ostree::Sysroot,
612+
) -> Result<(ostree::Deployment, InstallAleph)> {
613+
let sepolicy = state.load_policy()?;
614+
let sepolicy = sepolicy.as_ref();
615+
let stateroot = STATEROOT_DEFAULT;
616+
617+
let container_rootfs = &Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
610618

611619
let (src_imageref, proxy_cfg) = if !state.source.in_host_mountns {
612620
(state.source.imageref.clone(), None)
@@ -692,15 +700,15 @@ async fn initialize_ostree_root_from_self(
692700
)
693701
.await?;
694702

695-
sysroot.load(cancellable)?;
696703
let deployment = sysroot
697704
.deployments()
698705
.into_iter()
699706
.next()
700707
.ok_or_else(|| anyhow::anyhow!("Failed to find deployment"))?;
701708
// SAFETY: There must be a path
702709
let path = sysroot.deployment_dirpath(&deployment);
703-
let root = rootfs_dir
710+
let root = root_setup
711+
.rootfs_fd
704712
.open_dir(path.as_str())
705713
.context("Opening deployment dir")?;
706714

@@ -713,7 +721,7 @@ async fn initialize_ostree_root_from_self(
713721
for d in ["ostree", "boot"] {
714722
let mut pathbuf = Utf8PathBuf::from(d);
715723
crate::lsm::ensure_dir_labeled_recurse(
716-
rootfs_dir,
724+
&root_setup.rootfs_fd,
717725
&mut pathbuf,
718726
policy,
719727
Some(deployment_root_devino),
@@ -758,7 +766,7 @@ async fn initialize_ostree_root_from_self(
758766
selinux: state.selinux_state.to_aleph().to_string(),
759767
};
760768

761-
Ok(aleph)
769+
Ok((deployment, aleph))
762770
}
763771

764772
/// Run a command in the host mount namespace
@@ -1223,17 +1231,19 @@ async fn install_to_filesystem_impl(state: &State, rootfs: &mut RootSetup) -> Re
12231231
.ok_or_else(|| anyhow!("No uuid for boot/root"))?;
12241232
tracing::debug!("boot uuid={boot_uuid}");
12251233

1234+
// Initialize the ostree sysroot (repo, stateroot, etc.)
1235+
let sysroot = initialize_ostree_root(state, rootfs).await?;
1236+
// And actually set up the container in that root, returning a deployment and
1237+
// the aleph state (see below).
1238+
let (deployment, aleph) = install_container(state, rootfs, &sysroot).await?;
12261239
// Write the aleph data that captures the system state at the time of provisioning for aid in future debugging.
1227-
{
1228-
let aleph = initialize_ostree_root_from_self(state, rootfs).await?;
1229-
rootfs
1230-
.rootfs_fd
1231-
.atomic_replace_with(BOOTC_ALEPH_PATH, |f| {
1232-
serde_json::to_writer(f, &aleph)?;
1233-
anyhow::Ok(())
1234-
})
1235-
.context("Writing aleph version")?;
1236-
}
1240+
rootfs
1241+
.rootfs_fd
1242+
.atomic_replace_with(BOOTC_ALEPH_PATH, |f| {
1243+
serde_json::to_writer(f, &aleph)?;
1244+
anyhow::Ok(())
1245+
})
1246+
.context("Writing aleph version")?;
12371247
if cfg!(target_arch = "s390x") {
12381248
// TODO: Integrate s390x support into install_via_bootupd
12391249
crate::bootloader::install_via_zipl(&rootfs.device_info, boot_uuid)?;
@@ -1245,6 +1255,10 @@ async fn install_to_filesystem_impl(state: &State, rootfs: &mut RootSetup) -> Re
12451255
)?;
12461256
}
12471257

1258+
// After this point, we need to drop all open references to the filesystem
1259+
drop(deployment);
1260+
drop(sysroot);
1261+
12481262
tracing::debug!("Installed bootloader");
12491263

12501264
// Finalize mounted filesystems

0 commit comments

Comments
 (0)