Skip to content

Commit cd535ff

Browse files
committed
chore: add more comments and error handling
1 parent 2278b39 commit cd535ff

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

.github/actions/sbom-and-attest/action.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ inputs:
2525
registry_password:
2626
description: 'Registry password for authentication'
2727
required: true
28+
crane_version:
29+
description: 'Version of crane to install (default: v0.20.2)'
30+
required: false
31+
default: 'v0.20.2'
2832

2933
runs:
3034
using: 'composite'
@@ -68,9 +72,8 @@ runs:
6872
shell: bash
6973
run: |
7074
if ! command -v crane &> /dev/null; then
71-
echo "Installing crane..."
72-
CRANE_VERSION="v0.20.2"
73-
curl -sL "https://github.com/google/go-containerregistry/releases/download/${CRANE_VERSION}/go-containerregistry_Linux_x86_64.tar.gz" | tar -xz crane
75+
echo "Installing crane ${{ inputs.crane_version }}..."
76+
curl -sL "https://github.com/google/go-containerregistry/releases/download/${{ inputs.crane_version }}/go-containerregistry_Linux_x86_64.tar.gz" | tar -xz crane
7477
sudo mv crane /usr/local/bin/crane
7578
sudo chmod +x /usr/local/bin/crane
7679
fi
@@ -98,14 +101,14 @@ runs:
98101
PLATFORM_DIGESTS=$(crane manifest "$IMAGE_REF" | \
99102
jq -r '.manifests[] | select((.annotations."vnd.docker.reference.type" // "") != "attestation-manifest") | .digest')
100103
101-
for DIGEST in $PLATFORM_DIGESTS; do
104+
while IFS= read -r DIGEST; do
102105
echo "Attesting ${{ inputs.image_name }}@${DIGEST}"
103106
cosign attest \
104107
--yes \
105108
--predicate "$SBOM_FILE" \
106109
--type cyclonedx \
107110
"${{ inputs.image_name }}@${DIGEST}"
108-
done
111+
done <<< "$PLATFORM_DIGESTS"
109112
else
110113
# Single-platform: attest directly
111114
echo "Attesting $IMAGE_REF"

scripts/verify-image-attestations.sh

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
set -euo pipefail
3838

39+
40+
3941
# Color codes for output
4042
RED='\033[0;31m'
4143
GREEN='\033[0;32m'
@@ -203,22 +205,29 @@ verify_cosign_attestation() {
203205
media_type=$(echo "$index_manifest" | jq -r '.mediaType')
204206

205207
if [[ "$media_type" == "application/vnd.oci.image.index.v1+json" ]]; then
206-
# Get the first attestation manifest digest from the index
207-
local att_digest
208-
att_digest=$(echo "$index_manifest" | jq -r '.manifests[0].digest')
208+
# Get all attestation manifest digests from the index
209+
local att_digests
210+
att_digests=$(echo "$index_manifest" | jq -r '.manifests[].digest')
209211

210-
if [ -z "$att_digest" ] || [ "$att_digest" == "null" ]; then
212+
if [ -z "$att_digests" ]; then
211213
return 1
212214
fi
213215

214-
# Check the actual attestation manifest for Sigstore bundle
215-
local att_manifest
216-
att_manifest=$(crane manifest "${image_name}@${att_digest}" 2>/dev/null || echo "")
217-
218-
# Verify it contains Sigstore bundle layers
219-
if echo "$att_manifest" | jq -e '.layers[].mediaType | select(. == "application/vnd.dev.sigstore.bundle.v0.3+json")' &>/dev/null; then
220-
return 0
221-
fi
216+
# Check if any attestation manifest contains Sigstore bundle
217+
# (there may be multiple attestations from different runs)
218+
while IFS= read -r att_digest; do
219+
if [ -z "$att_digest" ] || [ "$att_digest" == "null" ]; then
220+
continue
221+
fi
222+
223+
local att_manifest
224+
att_manifest=$(crane manifest "${image_name}@${att_digest}" 2>/dev/null || echo "")
225+
226+
# Verify it contains Sigstore bundle layers
227+
if echo "$att_manifest" | jq -e '.layers[].mediaType | select(. == "application/vnd.dev.sigstore.bundle.v0.3+json")' &>/dev/null; then
228+
return 0
229+
fi
230+
done <<< "$att_digests"
222231
fi
223232

224233
return 1

0 commit comments

Comments
 (0)