1+ #! /usr/bin/env bash
2+ set -e
3+
4+ # Script to retrieve the sandboxed container operator CSV for the current clusterGroup
5+ # using the pull secret for authentication if needed.
6+
7+ # 1. Locate pull secret
8+ PULL_SECRET_PATH=" ${HOME} /pull-secret.json"
9+ if [ ! -f " $PULL_SECRET_PATH " ]; then
10+ if [ -n " ${PULL_SECRET} " ]; then
11+ PULL_SECRET_PATH=" ${PULL_SECRET} "
12+ if [ ! -f " $PULL_SECRET_PATH " ]; then
13+ echo " ERROR: Pull secret file not found at path specified in PULL_SECRET: $PULL_SECRET_PATH "
14+ exit 1
15+ fi
16+ else
17+ echo " ERROR: Pull secret not found at ~/pull-secret.json"
18+ echo " Please either place your pull secret at ~/pull-secret.json or set the PULL_SECRET environment variable"
19+ exit 1
20+ fi
21+ fi
22+
23+ echo " Using pull secret: $PULL_SECRET_PATH "
24+
25+ # 2. Check for required tools
26+ if ! command -v yq & > /dev/null; then
27+ echo " ERROR: yq is required but not installed"
28+ echo " Please install yq: https://github.com/mikefarah/yq#install"
29+ exit 1
30+ fi
31+
32+ # 3. Check values-global.yaml exists
33+ if [ ! -f " values-global.yaml" ]; then
34+ echo " ERROR: values-global.yaml not found in current directory"
35+ echo " Please run this script from the root directory of the project"
36+ exit 1
37+ fi
38+
39+ # 4. Get the active clusterGroupName from values-global.yaml
40+ CLUSTER_GROUP_NAME=$( yq eval ' .main.clusterGroupName' values-global.yaml)
41+
42+ if [ -z " $CLUSTER_GROUP_NAME " ] || [ " $CLUSTER_GROUP_NAME " == " null" ]; then
43+ echo " ERROR: Could not determine clusterGroupName from values-global.yaml"
44+ echo " Expected: main.clusterGroupName to be set"
45+ exit 1
46+ fi
47+
48+ echo " Active clusterGroup: $CLUSTER_GROUP_NAME "
49+
50+ # 5. Locate the values file for the active clusterGroup
51+ VALUES_FILE=" values-${CLUSTER_GROUP_NAME} .yaml"
52+
53+ if [ ! -f " $VALUES_FILE " ]; then
54+ echo " ERROR: Values file for clusterGroup not found: $VALUES_FILE "
55+ exit 1
56+ fi
57+
58+ # 6. Get the sandboxed container operator CSV from the clusterGroup values
59+ SANDBOX_CSV=$( yq eval ' .clusterGroup.subscriptions.sandbox.csv' " $VALUES_FILE " )
60+
61+ if [ -z " $SANDBOX_CSV " ] || [ " $SANDBOX_CSV " == " null" ]; then
62+ echo " WARNING: No sandboxed container operator CSV found in $VALUES_FILE "
63+ echo " The subscription clusterGroup.subscriptions.sandbox.csv is not defined"
64+ exit 0
65+ fi
66+
67+ # Extract version from CSV (e.g., "sandboxed-containers-operator.v1.11.0" -> "1.11.0")
68+ # Remove everything up to and including ".v"
69+ SANDBOX_VERSION=" ${SANDBOX_CSV##* .v} "
70+
71+ echo " Sandboxed container operator CSV: $SANDBOX_CSV "
72+ echo " Version: $SANDBOX_VERSION "
73+ # alternatively, use the operator-version tag.
74+ # OSC_VERSION=1.11.1
75+ VERITY_IMAGE=registry.redhat.io/openshift-sandboxed-containers/osc-dm-verity-image
76+
77+ TAG=$( skopeo inspect --authfile $PULL_SECRET_PATH docker://${VERITY_IMAGE} :${SANDBOX_VERSION} | jq -r .Digest)
78+
79+ IMAGE=${VERITY_IMAGE} @${TAG}
80+
81+ echo " IMAGE: $IMAGE "
82+
83+ curl -L https://tuf-default.apps.rosa.rekor-prod.2jng.p3.openshiftapps.com/targets/rekor.pub -o rekor.pub
84+ curl -L https://security.access.redhat.com/data/63405576.txt -o cosign-pub-key.pem
85+ # export REGISTRY_AUTH_FILE=${PULL_SECRET_PATH}
86+ # echo "REGISTRY_AUTH_FILE: $REGISTRY_AUTH_FILE"
87+ # export SIGSTORE_REKOR_PUBLIC_KEY=${PWD}/rekor.pub
88+ # echo "SIGSTORE_REKOR_PUBLIC_KEY: $SIGSTORE_REKOR_PUBLIC_KEY"
89+ # cosign verify --key cosign-pub-key.pem --output json --rekor-url=https://rekor-server-default.apps.rosa.rekor-prod.2jng.p3.openshiftapps.com $IMAGE > cosign_verify.log
90+
91+
92+ # Ensure output directory exists
93+ mkdir -p ~ /.coco-pattern
94+
95+ # Download the measurements using podman cp (works on macOS with remote podman)
96+ podman pull --authfile $PULL_SECRET_PATH $IMAGE
97+
98+ cid=$( podman create --entrypoint /bin/true $IMAGE )
99+ echo " CID: ${cid} "
100+ podman cp $cid :/image/measurements.json ~ /.coco-pattern/measurements.json
101+ podman rm $cid
102+
103+ echo " Measurements saved to ~/.coco-pattern/measurements.json"
0 commit comments