Unable to mirror the repository using cloudctl CASE launch as a non-root user

The command cloudctl case launch --action mirror-images fails when using Skopeo as a non-root user while trying to mirror the images.

Problem

When you run the cloudctl CASE launch command (cloudctl case launch --action mirror-images) as a non-root user, the command fails with the following error:

level=fatal msg="writing signatures: mkdir /var/lib/containers/sigstore/cp: permission denied"
[INFO] Deleting mirrored image csv files created during this mirror attempt

Symptom

The cloudctl CASE launch command fails in the file /tmp/CASE.log with the following error:

    time="2022-02-15T12:54:06Z" level=debug msg="Using registries.d directory /etc/containers/registries.d for sigstore configuration"
    time="2022-02-15T12:57:37Z" level=fatal msg="writing signatures: mkdir /var/lib/containers/sigstore/cp: permission denied"
    [INFO] Deleting mirrored image csv files created during this mirror attempt

Cause

By default, the registries configuration directory is $HOME/.config/containers/registries.d, otherwise it is /etc/containers/registries.d.

If /etc/containers/registries.d exists, then the files inside that directory are processed to find out where to store the signatures. The default.yaml file inside /etc/containers/registries.d almost always refers to /var/lib/containers/. Hence, using the default.yaml file, the signature will be stored at /var/lib/containers/sigstore.

    time="2022-02-15T12:54:06Z" level=debug msg="Using registries.d directory /etc/containers/registries.d for sigstore configuration"
    time="2022-02-15T12:57:37Z" level=fatal msg="writing signatures: mkdir /var/lib/containers/sigstore/cp: permission denied"
    [INFO] Deleting mirrored image csv files created during this mirror attempt

Skopeo infers it has to write to /var/lib/containers/sigstore but that file is owned by root and cannot write to that location, causing the failure.

For more information about the Skopeo non-root behavior, see containers-registries.d.5.md.

Environment

Diagnosing the problem

There are two ways to diagnose the problem. You can choose to review the /tmp/CASE.logs or check your write access to /var/lib/containers/sigstore.

Resolving the problem