Skip to content

Commit feccad9

Browse files
committed
coco: add get-pcr.sh script for attestation measurements
1 parent 4779010 commit feccad9

1 file changed

Lines changed: 103 additions & 0 deletions

File tree

scripts/get-pcr.sh

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Retrieve PCR measurements from the sandboxed container operator's dm-verity image.
5+
# These measurements are required for the pcrStash secret used by Trustee for attestation.
6+
# Run this before ./pattern.sh make load-secrets.
7+
8+
OUTPUT_DIR="${HOME}/.config/validated-patterns/trustee"
9+
10+
# 1. Locate pull secret
11+
PULL_SECRET_PATH="${HOME}/pull-secret.json"
12+
if [ ! -f "$PULL_SECRET_PATH" ]; then
13+
if [ -n "${PULL_SECRET}" ]; then
14+
PULL_SECRET_PATH="${PULL_SECRET}"
15+
if [ ! -f "$PULL_SECRET_PATH" ]; then
16+
echo "ERROR: Pull secret file not found at path specified in PULL_SECRET: $PULL_SECRET_PATH"
17+
exit 1
18+
fi
19+
else
20+
echo "ERROR: Pull secret not found at ~/pull-secret.json"
21+
echo "Please either place your pull secret at ~/pull-secret.json or set the PULL_SECRET environment variable"
22+
exit 1
23+
fi
24+
fi
25+
26+
echo "Using pull secret: $PULL_SECRET_PATH"
27+
28+
# 2. Check for required tools
29+
for cmd in yq skopeo jq podman; do
30+
if ! command -v "$cmd" &> /dev/null; then
31+
echo "ERROR: $cmd is required but not installed"
32+
exit 1
33+
fi
34+
done
35+
36+
# 3. Check values-global.yaml exists
37+
if [ ! -f "values-global.yaml" ]; then
38+
echo "ERROR: values-global.yaml not found in current directory"
39+
echo "Please run this script from the root directory of the project"
40+
exit 1
41+
fi
42+
43+
# 4. Get the active clusterGroupName from values-global.yaml
44+
CLUSTER_GROUP_NAME=$(yq eval '.main.clusterGroupName' values-global.yaml)
45+
46+
if [ -z "$CLUSTER_GROUP_NAME" ] || [ "$CLUSTER_GROUP_NAME" == "null" ]; then
47+
echo "ERROR: Could not determine clusterGroupName from values-global.yaml"
48+
echo "Expected: main.clusterGroupName to be set"
49+
exit 1
50+
fi
51+
52+
echo "Active clusterGroup: $CLUSTER_GROUP_NAME"
53+
54+
# 5. Locate the values file for the active clusterGroup
55+
VALUES_FILE="values-${CLUSTER_GROUP_NAME}.yaml"
56+
57+
if [ ! -f "$VALUES_FILE" ]; then
58+
echo "ERROR: Values file for clusterGroup not found: $VALUES_FILE"
59+
exit 1
60+
fi
61+
62+
# 6. Get the sandboxed container operator CSV from the clusterGroup values
63+
SANDBOX_CSV=$(yq eval '.clusterGroup.subscriptions.sandbox.csv // .clusterGroup.subscriptions.sandboxed.csv' "$VALUES_FILE")
64+
65+
if [ -z "$SANDBOX_CSV" ] || [ "$SANDBOX_CSV" == "null" ]; then
66+
echo "ERROR: No sandboxed container operator CSV found in $VALUES_FILE"
67+
echo "The subscription clusterGroup.subscriptions.sandbox.csv (or .sandboxed.csv) is not defined"
68+
exit 1
69+
fi
70+
71+
# Extract version from CSV (e.g., "sandboxed-containers-operator.v1.11.0" -> "1.11.0")
72+
SANDBOX_VERSION="${SANDBOX_CSV##*.v}"
73+
74+
echo "Sandboxed container operator CSV: $SANDBOX_CSV"
75+
echo "Version: $SANDBOX_VERSION"
76+
77+
VERITY_IMAGE=registry.redhat.io/openshift-sandboxed-containers/osc-dm-verity-image
78+
79+
TAG=$(skopeo inspect --authfile "$PULL_SECRET_PATH" "docker://${VERITY_IMAGE}:${SANDBOX_VERSION}" | jq -r .Digest)
80+
81+
IMAGE=${VERITY_IMAGE}@${TAG}
82+
83+
echo "IMAGE: $IMAGE"
84+
85+
# Ensure output directory exists
86+
mkdir -p "$OUTPUT_DIR"
87+
88+
# Clean up any existing measurement files
89+
rm -f "$OUTPUT_DIR/measurements-raw.json" "$OUTPUT_DIR/measurements.json"
90+
91+
# Download the measurements using podman cp
92+
podman pull --authfile "$PULL_SECRET_PATH" "$IMAGE"
93+
94+
cid=$(podman create --entrypoint /bin/true "$IMAGE")
95+
echo "CID: ${cid}"
96+
podman cp "$cid:/image/measurements.json" "$OUTPUT_DIR/measurements-raw.json"
97+
podman rm "$cid"
98+
99+
# Trim leading "0x" from all measurement values
100+
jq 'walk(if type == "string" and startswith("0x") then .[2:] else . end)' \
101+
"$OUTPUT_DIR/measurements-raw.json" > "$OUTPUT_DIR/measurements.json"
102+
103+
echo "Measurements saved to $OUTPUT_DIR/measurements.json (0x prefixes removed)"

0 commit comments

Comments
 (0)