Skip to content

Commit 4d3dc91

Browse files
committed
Harden manifest verification with error handling and HTTP status checks
Add set -euo pipefail, validate token retrieval, check HTTP status code before inspecting content-type, and use case-insensitive grep for the manifest.list.v2 check. Addresses Copilot review feedback on PR #1047.
1 parent 6602aaa commit 4d3dc91

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

.github/actions/create-manifest/action.yml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,36 @@ runs:
3131
- name: Verify Docker Manifest List v2 format
3232
shell: bash
3333
run: |
34-
TOKEN=$(curl -s "https://ghcr.io/token?service=ghcr.io&scope=repository:${REPO#ghcr.io/}:pull" | jq -r .token)
35-
CONTENT_TYPE=$(curl -s -D- -o /dev/null \
34+
set -euo pipefail
35+
36+
REPO_PATH="${REPO#ghcr.io/}"
37+
38+
# Fetch registry access token
39+
TOKEN=$(curl -fsS "https://ghcr.io/token?service=ghcr.io&scope=repository:${REPO_PATH}:pull" | jq -er .token) || {
40+
echo "FAIL: Unable to retrieve token from ghcr.io"
41+
exit 1
42+
}
43+
44+
# Fetch manifest and capture HTTP status code + content type
45+
HTTP_STATUS=$(curl -sS -o /dev/null -w '%{http_code}' \
46+
-H "Authorization: Bearer $TOKEN" \
47+
-H "Accept: application/vnd.docker.distribution.manifest.list.v2+json" \
48+
"https://ghcr.io/v2/${REPO_PATH}/manifests/${{ inputs.target-tag }}") || {
49+
echo "FAIL: Unable to retrieve manifest from ghcr.io for tag '${{ inputs.target-tag }}'"
50+
exit 1
51+
}
52+
53+
if [ "$HTTP_STATUS" != "200" ]; then
54+
echo "FAIL: Expected HTTP 200 when fetching manifest, got: $HTTP_STATUS"
55+
exit 1
56+
fi
57+
58+
CONTENT_TYPE=$(curl -sS -D- -o /dev/null \
3659
-H "Authorization: Bearer $TOKEN" \
3760
-H "Accept: application/vnd.docker.distribution.manifest.list.v2+json" \
38-
"https://ghcr.io/v2/${REPO#ghcr.io/}/manifests/${{ inputs.target-tag }}" | grep -i content-type)
39-
if echo "$CONTENT_TYPE" | grep -q "manifest.list.v2"; then
61+
"https://ghcr.io/v2/${REPO_PATH}/manifests/${{ inputs.target-tag }}" | grep -i content-type)
62+
63+
if echo "$CONTENT_TYPE" | grep -qi "manifest.list.v2"; then
4064
echo "OK: Docker Manifest List v2 format confirmed"
4165
else
4266
echo "FAIL: Expected Docker Manifest List v2, got: $CONTENT_TYPE"

0 commit comments

Comments
 (0)