Preparation for an install; validates and prepares some (thereafter immutable) global state.
(
mut config_opts: InstallConfigOpts,
source_opts: InstallSourceOpts,
mut target_opts: InstallTargetOpts,
mut composefs_options: InstallComposefsOpts,
target_fs: Option<FilesystemE
| 1542 | |
| 1543 | /// Preparation for an install; validates and prepares some (thereafter immutable) global state. |
| 1544 | async fn prepare_install( |
| 1545 | mut config_opts: InstallConfigOpts, |
| 1546 | source_opts: InstallSourceOpts, |
| 1547 | mut target_opts: InstallTargetOpts, |
| 1548 | mut composefs_options: InstallComposefsOpts, |
| 1549 | target_fs: Option<FilesystemEnum>, |
| 1550 | ) -> Result<Arc<State>> { |
| 1551 | tracing::trace!("Preparing install"); |
| 1552 | let rootfs = cap_std::fs::Dir::open_ambient_dir("/", cap_std::ambient_authority()) |
| 1553 | .context("Opening /")?; |
| 1554 | |
| 1555 | let host_is_container = crate::containerenv::is_container(&rootfs); |
| 1556 | let external_source = source_opts.source_imgref.is_some(); |
| 1557 | let (source, target_rootfs) = match source_opts.source_imgref { |
| 1558 | None => { |
| 1559 | ensure!( |
| 1560 | host_is_container, |
| 1561 | "Either --source-imgref must be defined or this command must be executed inside a podman container." |
| 1562 | ); |
| 1563 | |
| 1564 | crate::cli::require_root(true)?; |
| 1565 | |
| 1566 | require_host_pidns()?; |
| 1567 | // Out of conservatism we only verify the host userns path when we're expecting |
| 1568 | // to do a self-install (e.g. not bootc-image-builder or equivalent). |
| 1569 | require_host_userns()?; |
| 1570 | let container_info = crate::containerenv::get_container_execution_info(&rootfs)?; |
| 1571 | // This command currently *must* be run inside a privileged container. |
| 1572 | match container_info.rootless.as_deref() { |
| 1573 | Some("1") => anyhow::bail!( |
| 1574 | "Cannot install from rootless podman; this command must be run as root" |
| 1575 | ), |
| 1576 | Some(o) => tracing::debug!("rootless={o}"), |
| 1577 | // This one shouldn't happen except on old podman |
| 1578 | None => tracing::debug!( |
| 1579 | "notice: Did not find rootless= entry in {}", |
| 1580 | crate::containerenv::PATH, |
| 1581 | ), |
| 1582 | }; |
| 1583 | tracing::trace!("Read container engine info {:?}", container_info); |
| 1584 | |
| 1585 | let source = SourceInfo::from_container(&rootfs, &container_info)?; |
| 1586 | (source, Some(rootfs.try_clone()?)) |
| 1587 | } |
| 1588 | Some(source) => { |
| 1589 | crate::cli::require_root(false)?; |
| 1590 | let source = SourceInfo::from_imageref(&source, &rootfs)?; |
| 1591 | (source, None) |
| 1592 | } |
| 1593 | }; |
| 1594 | |
| 1595 | // Load install configuration from TOML drop-in files early, so that |
| 1596 | // config values are available when constructing the target image reference. |
| 1597 | let install_config = config::load_config()?; |
| 1598 | if let Some(ref config) = install_config { |
| 1599 | tracing::debug!("Loaded install configuration"); |
| 1600 | // Merge config file values into config_opts (CLI takes precedence) |
| 1601 | // Only apply config file value if CLI didn't explicitly set it |
no test coverage detected