Skip to content

Commit edb88ea

Browse files
committed
to-disk: Fix signature validation error with signed images
Copy images to local storage without signatures before bootc install to avoid errors with images like RHEL. Creates a permissive policy.json on the VM and uses skopeo to copy the image without signatures, then runs bootc install on the unsigned local copy. Signed-off-by: gursewak1997 <gursmangat@gmail.com>
1 parent b664ecb commit edb88ea

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

crates/kit/src/to_disk.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,17 @@ impl ToDiskOpts {
202202
.map_err(|e| eyre!("Failed to quote source imgref '{}': {}", source_imgref, e))?
203203
.to_string();
204204

205+
// Quote the source image name for local storage operations
206+
let quoted_source_image = shlex::try_quote(&self.source_image)
207+
.map_err(|e| {
208+
eyre!(
209+
"Failed to quote source image '{}': {}",
210+
self.source_image,
211+
e
212+
)
213+
})?
214+
.to_string();
215+
205216
let install_log = self
206217
.additional
207218
.install_log
@@ -247,15 +258,31 @@ impl ToDiskOpts {
247258
tty=--tty
248259
fi
249260
250-
# Execute bootc installation, having the outer podman pull from
251-
# the virtiofs store on the host, as well as the inner bootc.
252-
# Mount /var/tmp into inner container to avoid cross-device link errors (issue #125)
261+
# Workaround for issue #126: Copy image to local storage without signatures.
262+
# Write permissive policy to VM's /etc/containers/policy.json and use it for copy.
253263
export STORAGE_OPTS=additionalimagestore=${AIS}
264+
mkdir -p /etc/containers
265+
cat > /etc/containers/policy.json <<'EOF'
266+
{
267+
"default": [{"type": "insecureAcceptAnything"}],
268+
"transports": {
269+
"containers-storage": {"": [{"type": "insecureAcceptAnything"}]},
270+
"docker": {"": [{"type": "insecureAcceptAnything"}]}
271+
}
272+
}
273+
EOF
274+
275+
# Copy image without signatures to avoid "Would invalidate signatures" error
276+
skopeo copy --remove-signatures {SOURCE_IMGREF} containers-storage:{SOURCE_IMAGE}
277+
278+
# Execute bootc installation using the unsigned local copy
279+
# Mount /var/tmp into inner container to avoid cross-device link errors (issue #125)
254280
podman run --rm -i ${tty} --privileged --pid=host --net=none -v /sys:/sys:ro \
255-
-v /var/lib/containers:/var/lib/containers -v /var/tmp:/var/tmp -v /dev:/dev -v ${AIS}:${AIS} --security-opt label=type:unconfined_t \
281+
-v /var/lib/containers:/var/lib/containers -v /var/tmp:/var/tmp -v /dev:/dev -v "${AIS}:${AIS}" \
282+
--security-opt label=type:unconfined_t \
256283
--env=STORAGE_OPTS \
257284
{INSTALL_LOG} \
258-
{SOURCE_IMGREF} \
285+
containers-storage:{SOURCE_IMAGE} \
259286
bootc install to-disk \
260287
--generic-image \
261288
--skip-fetch-check \
@@ -266,6 +293,7 @@ impl ToDiskOpts {
266293
"#}
267294
.replace("{TMPFS_SIZE}", &tmpfs_size_quoted)
268295
.replace("{SOURCE_IMGREF}", &quoted_source_imgref)
296+
.replace("{SOURCE_IMAGE}", &quoted_source_image)
269297
.replace("{INSTALL_LOG}", &install_log)
270298
.replace("{BOOTC_ARGS}", &bootc_args);
271299

0 commit comments

Comments
 (0)