Created
February 17, 2022 04:03
-
-
Save dmikusa/02d6db255b396b14ed6822dafcb8cc3c to your computer and use it in GitHub Desktop.
A script that uses `curl` to download the SBOM layer of an OCI image created with Cloud-Native buildpacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eio pipefail | |
IMAGE="$1" | |
TAG="$2" | |
TOKEN=$(curl -s "https://auth.docker.io/token?scope=repository:$IMAGE:pull&service=registry.docker.io" | jq -r .token) | |
MANIFEST=$(curl -s -L -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -H "Authorization: Bearer $TOKEN" https://registry-1.docker.io/v2/$IMAGE/manifests/$TAG) | |
CONFIG_DIGEST=$(echo "$MANIFEST" | jq -r '.config.digest') | |
CONFIG=$(curl -s -L -H "Authorization: Bearer $TOKEN" "https://registry-1.docker.io/v2/$IMAGE/blobs/$CONFIG_DIGEST") | |
DIFFID=$(echo "$CONFIG" | jq -r '.config.Labels["io.buildpacks.lifecycle.metadata"]' | jq -r '.sbom.sha') | |
DIFFID_INDEX=$(echo "$CONFIG" | jq -r ".rootfs.diff_ids | index(\"$DIFFID\")") | |
LAYER=$(echo "$MANIFEST" | jq -r ".layers[$DIFFID_INDEX]") | |
MEDIA_TYPE=$(echo "$LAYER" | jq -r '.mediaType') | |
DIGEST=$(echo "$LAYER" | jq -r '.digest') | |
curl -s -L -H "Accept: $MEDIA_TYPE" -H "Authorization: Bearer $TOKEN" "https://registry-1.docker.io/v2/$IMAGE/blobs/$DIGEST" -o "$(echo "$DIGEST" | cut -d ':' -f 2).tgz" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment