Skip to content

Commit 67cf436

Browse files
committed
Fix: Check for container signature during release
Previously, container releases checked for the container on the remote server, and skip the release process if it is found. However, a failure in signing could occur after the push to remote, and if this step failed, it would never re-run because the entire release step would be skipped. This change adds a step to also verify that the signature is also on the remote if the image is found, and then attempts to sign the image if the signature is not present. To do this, the following changes were made: * Move installation of cosign binary to before image check * Add public key credential for verification * Run only cosign command if image is found on remote but not sig Issue: IT-29095 Change-Id: I025b1662238df38d558e2a31c96f4fa223d8ca3f Signed-off-by: Eric Ball <eball@linuxfoundation.org>
1 parent 9a80001 commit 67cf436

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

jjb/lf-release-jobs.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
build-timeout: 15
198198
cosign-password-id: cosign-password
199199
cosign-private-key-id: cosign-private-key
200+
cosign-public-key-id: cosign-public-key
200201
disable-job: false
201202
git-url: "$GIT_URL/$PROJECT"
202203
stream: master
@@ -278,6 +279,9 @@
278279
- text:
279280
credential-id: "{cosign-password-id}"
280281
variable: COSIGN_PASSWORD
282+
- file:
283+
credential-id: "{cosign-public-key-id}"
284+
variable: COSIGN_PUBLIC_KEY
281285

282286
scm:
283287
- lf-infra-gerrit-scm:
@@ -329,6 +333,9 @@
329333
- text:
330334
credential-id: "{cosign-password-id}"
331335
variable: COSIGN_PASSWORD
336+
- file:
337+
credential-id: "{cosign-public-key-id}"
338+
variable: COSIGN_PUBLIC_KEY
332339

333340
scm:
334341
- lf-infra-github-scm:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
fixes:
3+
- |
4+
When a container release is checked, the job will also check for a cosign
5+
signature. This fixes an issue where a docker image could be successfully
6+
pushed, but cosign would fail. This would lead to a failed job, and upon
7+
re-running the job, it would pass when the container was found on the server,
8+
without ever checking the status of the signature.

shell/release-job.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,26 @@ container_release_file(){
432432
echo "$name"
433433
echo "$version"
434434
echo "INFO: Merge will release $name $version as $VERSION"
435+
curl -O -L "https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64"
436+
sudo mv cosign-linux-amd64 /usr/local/bin/cosign
437+
sudo chmod +x /usr/local/bin/cosign
435438
# Attempt to pull from releases registry to see if the image has been released.
436439
if docker pull "$CONTAINER_PUSH_REGISTRY"/"$lfn_umbrella"/"$name":"$VERSION"; then
437-
echo "INFO: $VERSION is already released for image $name, Continuing..."
440+
echo "INFO: $VERSION is already released for image $name, checking signature..."
441+
image_digest=$(docker inspect --format='{{index .RepoDigests 0}}' \
442+
"$CONTAINER_PUSH_REGISTRY"/"$lfn_umbrella"/"$name":"$VERSION")
443+
cosign verify --key "$COSIGN_PUBLIC_KEY" "$image_digest"
444+
cosign_verified=$?
445+
if [ "$cosign_verified" -eq 0 ]; then
446+
echo "INFO: $name:$VERSION is already signed, continuing..."
447+
elif [ "$cosign_verified" -eq 10 ] && [[ "$JOB_NAME" =~ "merge" ]]; then
448+
# Exit code 10 indicates the package was found without signature
449+
echo "INFO: No signature found for $name:$VERSION. Attempting to sign..."
450+
export COSIGN_PASSWORD
451+
cosign sign -y --key "$COSIGN_PRIVATE_KEY" "$image_digest"
452+
else
453+
echo "INFO: Could not verify signature, cosign exited with code $cosign_verified."
454+
fi
438455
else
439456
echo "INFO: $VERSION not found in releases, release will be prepared. Continuing..."
440457
docker pull "$CONTAINER_PULL_REGISTRY"/"$lfn_umbrella"/"$name":"$version"
@@ -443,14 +460,11 @@ container_release_file(){
443460
echo "docker tag $container_image_id $CONTAINER_PUSH_REGISTRY/$lfn_umbrella/$name:$VERSION"
444461
echo "docker push $CONTAINER_PUSH_REGISTRY/$lfn_umbrella/$name:$VERSION"
445462
if [[ "$JOB_NAME" =~ "merge" ]]; then
446-
curl -O -L "https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64"
447-
sudo mv cosign-linux-amd64 /usr/local/bin/cosign
448-
sudo chmod +x /usr/local/bin/cosign
449-
export COSIGN_PASSWORD
450463
docker tag "$container_image_id" "$CONTAINER_PUSH_REGISTRY"/"$lfn_umbrella"/"$name":"$VERSION"
451464
docker push "$CONTAINER_PUSH_REGISTRY"/"$lfn_umbrella"/"$name":"$VERSION"
452465
image_digest=$(docker inspect --format='{{index .RepoDigests 0}}' \
453466
"$CONTAINER_PUSH_REGISTRY"/"$lfn_umbrella"/"$name":"$VERSION")
467+
export COSIGN_PASSWORD
454468
cosign sign -y --key "$COSIGN_PRIVATE_KEY" "$image_digest"
455469
fi
456470
echo "#########################"

0 commit comments

Comments
 (0)