forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify-image.sh
More file actions
executable file
·58 lines (49 loc) · 1.73 KB
/
Copy pathverify-image.sh
File metadata and controls
executable file
·58 lines (49 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
set -euo pipefail
IMAGE="${1:-}"
if [[ -z "${IMAGE}" ]]; then
echo "Usage: verify-image.sh <image:tag>"
exit 1
fi
PUBLIC_KEY="${COSIGN_PUBLIC_KEY:-${HOME}/.cosign/cosign.pub}"
COSIGN_BIN="${HOME}/.local/bin/cosign"
log() { echo "[$(date +%H:%M:%S)] $*"; }
# Check if cosign is installed
if ! command -v cosign &>/dev/null; then
log "cosign not found, installing to ${COSIGN_BIN}..."
mkdir -p "$(dirname "${COSIGN_BIN}")"
curl -sSfL https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64 \
-o "${COSIGN_BIN}" 2>/dev/null || {
log "Download failed, attempting go install..."
if command -v go &>/dev/null; then
go install github.com/sigstore/cosign/v2/cmd/cosign@latest
else
log "ERROR: Cannot install cosign — install manually"
exit 1
fi
}
chmod +x "${COSIGN_BIN}" 2>/dev/null || true
fi
log "Verifying image: ${IMAGE}"
# Verify signature
if [[ -f "${PUBLIC_KEY}" ]]; then
log "Verifying with public key: ${PUBLIC_KEY}"
cosign verify \
--key "${PUBLIC_KEY}" \
"${IMAGE}"
else
log "No public key found, attempting keyless verification..."
cosign verify \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
--certificate-identity "https://github.com/PinSpace-Org/GistPin/.github/workflows/" \
"${IMAGE}" || {
log "Keyless verification failed — image may be unsigned or signed with a different identity"
exit 1
}
fi
log "Verification passed ✓"
# Verify attestations if SBOM attestation exists
cosign verify-attestation \
--type custom \
"${IMAGE}" 2>/dev/null && log "Attestations verified ✓" || log "No attestations found (non-blocking)"
log "Image signature and attestations verified: ${IMAGE}"