Skip to content

Commit 0c5dbc4

Browse files
fix: make PURLs use oci type / fixed SBOM component name (#11)
* fix: make PURLs use oci type * fix: use product name as source name in syft / SBOMs * fix: addressed review comments * fix: addressed comments from @NickLarsenNZ * chore: removed unnecessary curly braces * fix: curly braces syntax Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com> --------- Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com>
1 parent 0ffa976 commit 0c5dbc4

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

publish-image/action.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,33 @@ runs:
109109
# Extract the digest from the image repo digest (right side of '@')
110110
DIGEST=${IMAGE_REPO_DIGEST#*@}
111111
112+
# URL encode the digest and image repository, needed for the purl
113+
URLENCODED_DIGEST=$(jq -rn --arg input "$DIGEST" '$input | @uri')
114+
URLENCODED_IMAGE_REPOSITORY=$(jq -rn --arg input "$IMAGE_REPOSITORY" '$input | @uri')
115+
# Last item, split by /
116+
# Example: sdp/kafka -> kafka
117+
SOURCE_NAME=$(echo "$IMAGE_REPOSITORY" | awk -F'/' '{print $NF}')
118+
# Extract architecture from image tag
119+
ARCH=$(echo "$IMAGE_MANIFEST_TAG" | awk -F'-' '{print $NF}')
120+
if [ "$ARCH" != "amd64" ] && [ "$ARCH" != "arm64" ]; then
121+
echo "Invalid architecture obtained from image tag. IMAGE_MANIFEST_TAG: $IMAGE_MANIFEST_TAG, ARCH: $ARCH"
122+
exit 1
123+
fi
112124
# Construct the package url (purl)
113-
# TODO (@Techassi): Can we use 'oci' instead of 'docker' as the type?
114-
PURL="pkg:docker/$IMAGE_REPOSITORY@$DIGEST?repository_url=$REGISTRY_URI"
125+
PURL="pkg:oci/${SOURCE_NAME}@${URLENCODED_DIGEST}?arch=${ARCH}&repository_url=${REGISTRY_URI}%2F${URLENCODED_IMAGE_REPOSITORY}"
115126
116127
# Get metadata from the image
117128
# NOTE (@Techassi): Maybe we should run this command only once
118-
IMAGE_METADATA_DESCRIPTION=$(docker inspect --format='{{.Config.Labels.description}}' "${IMAGE_REPO_DIGEST}")
119-
IMAGE_METADATA_NAME=$(docker inspect --format='{{.Config.Labels.name}}' "${IMAGE_REPO_DIGEST}")
129+
IMAGE_METADATA_DESCRIPTION=$(docker inspect --format='{{.Config.Labels.description}}' "$IMAGE_REPO_DIGEST")
130+
IMAGE_METADATA_NAME=$(docker inspect --format='{{.Config.Labels.name}}' "$IMAGE_REPO_DIGEST")
120131
121132
# Generate the SBOM
122133
syft scan \
123134
--output cyclonedx-json@1.5=sbom_raw.json \
124135
--select-catalogers "-cargo-auditable-binary-cataloger,+sbom-cataloger" \
125136
--scope all-layers \
126-
--source-name "$IMAGE_REPOSITORY" \
127-
--source-version "$IMAGE_MANIFEST_TAG" "${IMAGE_REPO_DIGEST}"
137+
--source-name "$SOURCE_NAME" \
138+
--source-version "$IMAGE_MANIFEST_TAG" "$IMAGE_REPO_DIGEST"
128139
129140
# Merge SBOM components using https://github.com/stackabletech/mergebom
130141
curl --fail -L -o mergebom https://repo.stackable.tech/repository/packages/mergebom/stable-$(uname -m)

0 commit comments

Comments
 (0)