Skip to content

Commit fa0221b

Browse files
image-proxy: Use privileged user when pull from containers storage
We were defaulting to unprivileged user "nobody" when pulling an image, but pulling from containers-storage was failing as it requires extra privileges. Default to the current user, usually root, when pulling from containers-storage Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent f4fb7b9 commit fa0221b

5 files changed

Lines changed: 25 additions & 15 deletions

File tree

crates/lib/src/bootc_composefs/status.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ use bootc_utils::try_deserialize_timestamp;
3636
use cap_std_ext::{cap_std::fs::Dir, dirext::CapStdExtDirExt};
3737
use ostree_container::OstreeImageReference;
3838
use ostree_ext::container::{self as ostree_container};
39-
use ostree_ext::containers_image_proxy;
39+
use ostree_ext::containers_image_proxy::{ImageProxy, ImageReference};
40+
4041
use ostree_ext::oci_spec;
4142
use ostree_ext::{container::deploy::ORIGIN_CONTAINER, oci_spec::image::ImageConfiguration};
4243

@@ -379,14 +380,16 @@ pub(crate) fn list_bootloader_entries(storage: &Storage) -> Result<Vec<Bootloade
379380
/// imgref = transport:image_name
380381
#[context("Getting container info")]
381382
pub(crate) async fn get_container_manifest_and_config(
382-
imgref: &String,
383+
imgref: &ImageReference,
383384
) -> Result<ImgConfigManifest> {
384385
let mut config = crate::deploy::new_proxy_config();
385-
ostree_ext::container::merge_default_container_proxy_opts(&mut config)?;
386-
let proxy = containers_image_proxy::ImageProxy::new_with_config(config).await?;
386+
387+
ostree_ext::container::apply_container_proxy_opts_for_transport(&mut config, imgref.transport)?;
388+
389+
let proxy = ImageProxy::new_with_config(config).await?;
387390

388391
let img = proxy
389-
.open_image(&imgref)
392+
.open_image_ref(&imgref)
390393
.await
391394
.with_context(|| format!("Opening image {imgref}"))?;
392395

crates/lib/src/bootc_composefs/update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(crate) async fn is_image_pulled(
5858
imgref: &ImageReference,
5959
) -> Result<(Option<Sha512HashValue>, ImgConfigManifest)> {
6060
let imgref_repr = imgref.to_image_proxy_ref()?;
61-
let img_config_manifest = get_container_manifest_and_config(&imgref_repr.to_string()).await?;
61+
let img_config_manifest = get_container_manifest_and_config(&imgref_repr).await?;
6262

6363
let img_digest = img_config_manifest.manifest.config().digest().digest();
6464

crates/lib/src/install.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,8 +2017,7 @@ async fn install_to_filesystem_impl(
20172017
// Pre-flight disk space check for native composefs install path.
20182018
{
20192019
let imgref = &state.source.imageref;
2020-
let imgref_repr = imgref.to_string();
2021-
let img_manifest_config = get_container_manifest_and_config(&imgref_repr).await?;
2020+
let img_manifest_config = get_container_manifest_and_config(&imgref).await?;
20222021
crate::store::ensure_composefs_dir(&rootfs.physical_root)?;
20232022
// Use init_path since the repo may not exist yet during install
20242023
let (cfs_repo, _created) = crate::store::ComposefsRepository::init_path(

crates/ostree-ext/src/container/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,20 @@ pub fn version_for_config(config: &oci_spec::image::ImageConfiguration) -> Optio
496496
None
497497
}
498498

499+
/// Apply appropriate container proxy options based on transport type
500+
pub fn apply_container_proxy_opts_for_transport(
501+
config: &mut containers_image_proxy::ImageProxyConfig,
502+
transport: Transport,
503+
) -> Result<()> {
504+
if transport == Transport::ContainerStorage {
505+
// Fetching from containers-storage, may require privileges to read files
506+
merge_default_container_proxy_opts_with_isolation(config, None)
507+
} else {
508+
// Apply our defaults to the proxy config
509+
merge_default_container_proxy_opts(config)
510+
}
511+
}
512+
499513
pub mod deploy;
500514
mod encapsulate;
501515
pub use encapsulate::*;

crates/ostree-ext/src/container/store.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -635,13 +635,7 @@ impl ImageImporter {
635635
imgref: &OstreeImageReference,
636636
mut config: ImageProxyConfig,
637637
) -> Result<Self> {
638-
if imgref.imgref.transport == Transport::ContainerStorage {
639-
// Fetching from containers-storage, may require privileges to read files
640-
merge_default_container_proxy_opts_with_isolation(&mut config, None)?;
641-
} else {
642-
// Apply our defaults to the proxy config
643-
merge_default_container_proxy_opts(&mut config)?;
644-
}
638+
apply_container_proxy_opts_for_transport(&mut config, imgref.imgref.transport)?;
645639
let proxy = ImageProxy::new_with_config(config).await?;
646640

647641
system_repo_journal_print(

0 commit comments

Comments
 (0)