Skip to content

Commit b7bde43

Browse files
Merge pull request #4426 from ggiguash/quay_sigstore
OCPBUGS-44695: Add signature copy and verification support when working with local Quay registry
2 parents d2cdaaa + 4ba4768 commit b7bde43

28 files changed

+261
-31
lines changed

test/assets/kustomizations/base/pod-base.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
type: RuntimeDefault
1010
containers:
1111
- name: test-container
12-
image: nginxinc/nginx-unprivileged:latest
12+
image: docker.io/nginxinc/nginx-unprivileged:latest
1313
securityContext:
1414
allowPrivilegeEscalation: false
1515
capabilities:

test/assets/reboot/pod-with-pvc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ spec:
2121
type: RuntimeDefault
2222
containers:
2323
- name: test-container
24-
image: nginxinc/nginx-unprivileged:latest
24+
image: docker.io/nginxinc/nginx-unprivileged:latest
2525
securityContext:
2626
allowPrivilegeEscalation: false
2727
capabilities:

test/bin/mirror_registry.sh

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,30 @@ setup_prereqs() {
1818
"${SCRIPTDIR}/../../scripts/dnf_retry.sh" "install" "podman skopeo jq"
1919
fi
2020

21+
# Create registry repository base directory structure
22+
mkdir -p "${MIRROR_REGISTRY_DIR}"
23+
mkdir -p "${QUAY_CONFIG_DIR}"
24+
25+
# Create a new pull secret file containing authentication information for both
26+
# remote (from PULL_SECRET environment) and local registries
27+
cat > "${QUAY_CONFIG_DIR}/microshift_auth.json" <<EOF
28+
{
29+
"auths": {
30+
"${MIRROR_REGISTRY_URL}": {
31+
"auth": "$(echo -n 'microshift:microshift' | base64)"
32+
}
33+
}
34+
}
35+
EOF
36+
jq -s '.[0] * .[1]' "${PULL_SECRET}" "${QUAY_CONFIG_DIR}/microshift_auth.json" > "${QUAY_CONFIG_DIR}/pull_secret.json"
37+
chmod 600 "${QUAY_CONFIG_DIR}/pull_secret.json"
38+
# Reset the pull secret variable to point to the new file
39+
PULL_SECRET="${QUAY_CONFIG_DIR}/pull_secret.json"
40+
2141
# TLS authentication is disabled in Quay local registry. The mirror-images.sh
2242
# helper uses skopeo without TLS options and it defaults to https, so we need
2343
# to configure registries.conf.d for skopeo to try http instead.
24-
sudo bash -c 'cat > /etc/containers/registries.conf.d/900-microshift-mirror.conf' << EOF
44+
sudo bash -c 'cat > /etc/containers/registries.conf.d/900-microshift-mirror.conf' <<EOF
2545
[[registry]]
2646
prefix = ""
2747
location = "${MIRROR_REGISTRY_URL}"
@@ -42,25 +62,41 @@ setup_prereqs() {
4262
insecure = true
4363
EOF
4464

45-
# Create registry repository base directory structure
46-
mkdir -p "${MIRROR_REGISTRY_DIR}"
47-
mkdir -p "${QUAY_CONFIG_DIR}"
65+
# Complete the source registry configuration to use sigstore attachments.
66+
# Note that registry.redhat.io.yaml file already exists, but it is missing the
67+
# sigstore attachment enablement setting.
68+
sudo bash -c 'cat > /etc/containers/registries.d/registry.quay.io.yaml' <<'EOF'
69+
docker:
70+
quay.io:
71+
use-sigstore-attachments: true
72+
EOF
4873

49-
# Create a new pull secret file containing authentication information for both
50-
# remote (from PULL_SECRET environment) and local registries
51-
cat > "${QUAY_CONFIG_DIR}/microshift_auth.json" <<EOF
52-
{
53-
"auths": {
54-
"${MIRROR_REGISTRY_URL}": {
55-
"auth": "$(echo -n 'microshift:microshift' | base64)"
56-
}
57-
}
58-
}
74+
if [ -e /etc/containers/registries.d/registry.redhat.io.yaml ] &&
75+
[ ! -e /etc/containers/registries.d/registry.redhat.io.yaml.orig ]; then
76+
sudo mv /etc/containers/registries.d/registry.redhat.io.yaml /etc/containers/registries.d/registry.redhat.io.yaml.orig
77+
fi
78+
79+
sudo bash -c 'cat > /etc/containers/registries.d/registry.redhat.io.yaml' <<'EOF'
80+
docker:
81+
registry.redhat.io:
82+
use-sigstore-attachments: true
83+
sigstore: https://registry.redhat.io/containers/sigstore
84+
EOF
85+
86+
# Configure the destination local registry to use sigstore attachments.
87+
# Note: The sigstore staging directory is required because not all registries
88+
# support direct copy of signatures. In this case, the signatures are downloaded
89+
# locally and copied to the destination registry.
90+
local -r quay_base="$(dirname "${MIRROR_REGISTRY_URL}")"
91+
local -r sigstore="${MIRROR_REGISTRY_DIR}/sigstore-staging"
92+
93+
mkdir -p "${sigstore}"
94+
sudo bash -c 'cat > /etc/containers/registries.d/registry.quay.local.yaml' <<EOF
95+
docker:
96+
${quay_base}:
97+
use-sigstore-attachments: true
98+
lookaside-staging: file://${sigstore}
5999
EOF
60-
jq -s '.[0] * .[1]' "${PULL_SECRET}" "${QUAY_CONFIG_DIR}/microshift_auth.json" > "${QUAY_CONFIG_DIR}/pull_secret.json"
61-
chmod 600 "${QUAY_CONFIG_DIR}/pull_secret.json"
62-
# Reset the pull secret variable to point to the new file
63-
PULL_SECRET="${QUAY_CONFIG_DIR}/pull_secret.json"
64100
}
65101

66102
setup_registry() {

test/bin/pyutils/build_bootc_images.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ def ostree_rev_in_registry(ce_imgref):
393393
try:
394394
dst_ref_cmd = [
395395
"skopeo", "inspect",
396+
"--authfile", PULL_SECRET,
396397
f"docker://{ce_targetimg}",
397398
"2>/dev/null", "|",
398399
"jq", "-r", "'.Labels[\"ostree.commit\"]'"
@@ -422,9 +423,12 @@ def ostree_rev_in_registry(ce_imgref):
422423
common.record_junit(ce_path, "process-container-encapsulate", "SKIPPED")
423424
return
424425

425-
# Run the container image build command
426+
# Run the container image build command.
427+
# The REGISTRY_AUTH_FILE setting is required for skopeo to succeed
428+
# in accessing container registries that might require authentication.
426429
build_args = [
427-
"sudo", "rpm-ostree", "compose",
430+
"sudo", f"REGISTRY_AUTH_FILE={PULL_SECRET}",
431+
"rpm-ostree", "compose",
428432
"container-encapsulate",
429433
"--repo", os.path.join(IMAGEDIR, "repo"),
430434
ce_imgref,
@@ -438,6 +442,7 @@ def ostree_rev_in_registry(ce_imgref):
438442
# necessary for subsequent builds that depend on this container image
439443
copy_args = [
440444
"sudo", "skopeo", "copy",
445+
"--authfile", PULL_SECRET,
441446
f"docker://{ce_targetimg}",
442447
f"containers-storage:{ce_localimg}"
443448
]

test/bin/scenario.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ VM_BOOT_TIMEOUT=1200 # Overall total boot times are around 15m
2626
VM_GREENBOOT_TIMEOUT=1800 # Greenboot readiness may take up to 15-30m depending on the load
2727
SKIP_SOS=${SKIP_SOS:-false} # may be overridden in global settings file
2828
SKIP_GREENBOOT=${SKIP_GREENBOOT:-false} # may be overridden in scenario file
29+
# Container image signature verification should be disabled by default in the
30+
# main branch because not all the images are signed
31+
IMAGE_SIGSTORE_ENABLED=false # may be overridden in scenario file
2932
VNC_CONSOLE=${VNC_CONSOLE:-false} # may be overridden in global settings file
3033
TEST_RANDOMIZATION="all" # may be overridden in scenario file
3134
TEST_EXECUTION_TIMEOUT="30m" # may be overriden in scenario file
@@ -300,6 +303,7 @@ prepare_kickstart() {
300303
-e "s|REPLACE_MIRROR_HOSTNAME|${hostname}|g" \
301304
-e "s|REPLACE_MIRROR_PORT|${MIRROR_REGISTRY_PORT}|g" \
302305
-e "s|REPLACE_VM_BRIDGE_IP|${VM_BRIDGE_IP}|g" \
306+
-e "s|REPLACE_IMAGE_SIGSTORE_ENABLED|${IMAGE_SIGSTORE_ENABLED}|g" \
303307
"${ifile}" > "${output_file}"
304308
done
305309
record_junit "${vmname}" "prepare_kickstart" "OK"
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Red Hat public keys are published at https://access.redhat.com/security/team/key.
2+
# Currently release key 3 is used.
3+
cat > /etc/containers/RedHat_ReleaseKey3.pub <<'EOF'
4+
pub 4096R/E60D446E63405576 2024-09-20
5+
uid Red Hat, Inc. (release key 3) <[email protected]>
6+
7+
-----BEGIN PUBLIC KEY-----
8+
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA0ASyuH2TLWvBUqPHZ4Ip
9+
75g7EncBkgQHdJnjzxAW5KQTMh/siBoB/BoSrtiPMwnChbTCnQOIQeZuDiFnhuJ7
10+
M/D3b7JoX0m123NcCSn67mAdjBa6Bg6kukZgCP4ZUZeESajWX/EjylFcRFOXW57p
11+
RDCEN42J/jYlVqt+g9+Grker8Sz86H3l0tbqOdjbz/VxHYhwF0ctUMHsyVRDq2QP
12+
tqzNXlmlMhS/PoFr6R4u/7HCn/K+LegcO2fAFOb40KvKSKKVD6lewUZErhop1CgJ
13+
XjDtGmmO9dGMF71mf6HEfaKSdy+EE6iSF2A2Vv9QhBawMiq2kOzEiLg4nAdJT8wg
14+
ZrMAmPCqGIsXNGZ4/Q+YTwwlce3glqb5L9tfNozEdSR9N85DESfQLQEdY3CalwKM
15+
BT1OEhEX1wHRCU4drMOej6BNW0VtscGtHmCrs74jPezhwNT8ypkyS+T0zT4Tsy6f
16+
VXkJ8YSHyenSzMB2Op2bvsE3grY+s74WhG9UIA6DBxcTie15NSzKwfzaoNWODcLF
17+
p7BY8aaHE2MqFxYFX+IbjpkQRfaeQQsouDFdCkXEFVfPpbD2dk6FleaMTPuyxtIT
18+
gjVEtGQK2qGCFGiQHFd4hfV+eCA63Jro1z0zoBM5BbIIQ3+eVFwt3AlZp5UVwr6d
19+
secqki/yrmv3Y0dqZ9VOn3UCAwEAAQ==
20+
-----END PUBLIC KEY-----
21+
EOF
22+
23+
# Configure Red Hat containers policy to use the Red Hat public key, making
24+
# an exception for unofficial / unreleased images that are used by tests
25+
if [ -e /etc/containers/policy.json ] && [ ! -e /etc/containers/policy.json.orig ]; then
26+
mv /etc/containers/policy.json /etc/containers/policy.json.orig
27+
fi
28+
cat > /etc/containers/policy.json <<'EOF'
29+
{
30+
"default": [
31+
{
32+
"type": "reject"
33+
}
34+
],
35+
"transports": {
36+
"docker": {
37+
"quay.io/openshift-release-dev": [{
38+
"type": "sigstoreSigned",
39+
"keyPath": "/etc/containers/RedHat_ReleaseKey3.pub",
40+
"signedIdentity": {
41+
"type": "matchRepoDigestOrExact"
42+
}
43+
}],
44+
"registry.redhat.io": [{
45+
"type": "sigstoreSigned",
46+
"keyPath": "/etc/containers/RedHat_ReleaseKey3.pub",
47+
"signedIdentity": {
48+
"type": "matchRepoDigestOrExact"
49+
}
50+
}],
51+
"quay.io/microshift": [{
52+
"type": "insecureAcceptAnything"
53+
}],
54+
"quay.io/container-perf-tools": [{
55+
"type": "insecureAcceptAnything"
56+
}],
57+
"registry.ci.openshift.org": [{
58+
"type": "insecureAcceptAnything"
59+
}],
60+
"docker.io": [{
61+
"type": "insecureAcceptAnything"
62+
}]
63+
}
64+
}
65+
}
66+
EOF
67+
68+
# Configure the MicroShift remote and local registries to use sigstore attachments
69+
cat > /etc/containers/registries.d/registry.quay.io.yaml <<'EOF'
70+
docker:
71+
quay.io/openshift-release-dev:
72+
use-sigstore-attachments: true
73+
EOF
74+
75+
cat > /etc/containers/registries.d/registry.quay.local.yaml <<'EOF'
76+
docker:
77+
REPLACE_MIRROR_HOSTNAME:REPLACE_MIRROR_PORT:
78+
use-sigstore-attachments: true
79+
EOF

test/kickstart-templates/includes/post-containers.cfg

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
# The pull secret is mandatory for MicroShift builds on top of OpenShift, but not OKD
22
# The /etc/crio/crio.conf.d/microshift.conf references the /etc/crio/openshift-pull-secret file
33
mkdir -p /etc/crio
4-
cat > /etc/crio/openshift-pull-secret <<EOF
4+
cat > /etc/crio/openshift-pull-secret <<'EOF'
55
REPLACE_PULL_SECRET
66
EOF
77
chmod 600 /etc/crio/openshift-pull-secret
88

9+
# Add the mirror registry host name resolution
10+
cat >> /etc/hosts <<'EOF'
11+
REPLACE_VM_BRIDGE_IP REPLACE_MIRROR_HOSTNAME
12+
EOF
13+
914
# Setup mirror registries configuration here, as the hostname is dynamic and the file is verbose.
1015
# Use hostnames as IP addresses are not allowed.
1116
mkdir -p /etc/containers/registries.conf.d
12-
cat > /etc/containers/registries.conf.d/999-microshift-mirror.conf <<EOF
17+
cat > /etc/containers/registries.conf.d/999-microshift-mirror.conf <<'EOF'
1318
[[registry]]
1419
prefix = ""
1520
location = "REPLACE_MIRROR_HOSTNAME:REPLACE_MIRROR_PORT"
1621
mirror-by-digest-only = true
1722
insecure = true
23+
1824
[[registry]]
1925
prefix = ""
2026
location = "quay.io"
2127
mirror-by-digest-only = true
2228
[[registry.mirror]]
2329
location = "REPLACE_MIRROR_HOSTNAME:REPLACE_MIRROR_PORT/microshift"
2430
insecure = true
31+
2532
[[registry]]
2633
prefix = ""
2734
location = "registry.redhat.io"
@@ -31,9 +38,13 @@ cat > /etc/containers/registries.conf.d/999-microshift-mirror.conf <<EOF
3138
insecure = true
3239
EOF
3340

34-
# Skip signature verifying for red hat registries, since the signatures are bound the original
35-
# registry name and mirroring images changes that.
36-
cat > /etc/containers/policy.json <<EOF
41+
# Skip signature verification for all images by default.
42+
# Tests that support signature verification will overwrite this file and reenable
43+
# it for selected Red Hat registries.
44+
if [ -e /etc/containers/policy.json ] && [ ! -e /etc/containers/policy.json.orig ]; then
45+
mv /etc/containers/policy.json /etc/containers/policy.json.orig
46+
fi
47+
cat > /etc/containers/policy.json <<'EOF'
3748
{
3849
"default": [
3950
{
@@ -49,7 +60,3 @@ cat > /etc/containers/policy.json <<EOF
4960
}
5061
}
5162
EOF
52-
53-
cat >> /etc/hosts <<EOF
54-
REPLACE_VM_BRIDGE_IP REPLACE_MIRROR_HOSTNAME
55-
EOF

test/kickstart-templates/kickstart-bootc.ks.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
%post --log=/dev/console --erroronfail
77

88
%include /post-microshift.cfg
9+
910
%include /post-containers.cfg
11+
if REPLACE_IMAGE_SIGSTORE_ENABLED ; then
12+
%include /post-containers-sigstore.cfg
13+
fi
14+
1015
%include /post-system.cfg
1116
%include /post-network.cfg
1217

test/kickstart-templates/kickstart-centos.ks.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
%post --log=/dev/console --erroronfail
66

77
%include /post-microshift.cfg
8+
89
%include /post-containers.cfg
10+
if REPLACE_IMAGE_SIGSTORE_ENABLED ; then
11+
%include /post-containers-sigstore.cfg
12+
fi
13+
914
%include /post-system.cfg
1015
%include /post-network.cfg
1116

test/kickstart-templates/kickstart-liveimg.ks.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
%post --log=/dev/console --erroronfail
66

77
%include /post-microshift.cfg
8+
89
%include /post-containers.cfg
10+
if REPLACE_IMAGE_SIGSTORE_ENABLED ; then
11+
%include /post-containers-sigstore.cfg
12+
fi
13+
914
%include /post-system.cfg
1015
%include /post-network.cfg
1116
%include /post-fips.cfg

0 commit comments

Comments
 (0)