@@ -29,6 +29,10 @@ readonly REPO_UPSTREAM="https://github.com/${ORG_NAME}/${REPO_NAME}"
29
29
readonly NIGHTLY_GCR=" gcr.io/knative-nightly/github.com/${ORG_NAME} /${REPO_NAME} "
30
30
readonly RELEASE_GCR=" gcr.io/knative-releases/github.com/${ORG_NAME} /${REPO_NAME} "
31
31
32
+ # Signing identities for knative releases.
33
+ readonly NIGHTLY_SIGNING_IDENTITY=
" [email protected] "
34
+ readonly RELEASE_SIGNING_IDENTITY=
" [email protected] "
35
+
32
36
# Georeplicate images to {us,eu,asia}.gcr.io
33
37
readonly GEO_REPLICATION=(us eu asia)
34
38
@@ -99,6 +103,7 @@ VALIDATION_TESTS="./test/presubmit-tests.sh"
99
103
ARTIFACTS_TO_PUBLISH=" "
100
104
FROM_NIGHTLY_RELEASE=" "
101
105
FROM_NIGHTLY_RELEASE_GCS=" "
106
+ SIGNING_IDENTITY=" "
102
107
export KO_DOCKER_REPO=" gcr.io/knative-nightly"
103
108
# Build stripped binary to reduce size
104
109
export GOFLAGS=" -ldflags=-s -ldflags=-w"
@@ -301,6 +306,34 @@ function build_from_source() {
301
306
if [[ $? -ne 0 ]]; then
302
307
abort " error building the release"
303
308
fi
309
+ sign_release || abort " error signing the release"
310
+ }
311
+
312
+ # Build a release from source.
313
+ function sign_release() {
314
+ if [ -z " $SIGN_IMAGES " ]; then # Temporary Feature Gate
315
+ return 0
316
+ fi
317
+ # # Sign the images with cosign
318
+ # # For now, check if ko has created imagerefs.txt file. In the future, missing image refs will break
319
+ # # the release for all jobs that publish images.
320
+ if [[ -f " imagerefs.txt" ]]; then
321
+ echo " Signing Images with the identity ${SIGNING_IDENTITY} "
322
+ COSIGN_EXPERIMENTAL=1 cosign sign $( cat imagerefs.txt) --recursive --identity-token=" $(
323
+ gcloud auth print-identity-token --audiences=sigstore \
324
+ --include-email \
325
+ --impersonate-service-account=" ${SIGNING_IDENTITY} " ) "
326
+ fi
327
+
328
+ # # Check if there is checksums.txt file. If so, sign the checksum file
329
+ if [[ -f " checksums.txt" ]]; then
330
+ echo " Signing Images with the identity ${SIGNING_IDENTITY} "
331
+ COSIGN_EXPERIMENTAL=1 cosign sign-blob checksums.txt --output-signature checksums.txt.sig --identity-token=" $(
332
+ gcloud auth print-identity-token --audiences=sigstore \
333
+ --include-email \
334
+ --impersonate-service-account=" ${SIGNING_IDENTITY} " ) "
335
+ ARTIFACTS_TO_PUBLISH=" ${ARTIFACTS_TO_PUBLISH} checksums.txt.sig"
336
+ fi
304
337
}
305
338
306
339
# Copy tagged images from the nightly GCR to the release GCR, tagging them 'latest'.
@@ -375,10 +408,12 @@ function parse_flags() {
375
408
;;
376
409
--release-gcr)
377
410
KO_DOCKER_REPO=$1
411
+ SIGNING_IDENTITY=$RELEASE_SIGNING_IDENTITY
378
412
has_gcr_flag=1
379
413
;;
380
414
--release-gcs)
381
415
RELEASE_GCS_BUCKET=$1
416
+ SIGNING_IDENTITY=$RELEASE_SIGNING_IDENTITY
382
417
RELEASE_DIR=" "
383
418
has_gcs_flag=1
384
419
;;
@@ -449,6 +484,11 @@ function parse_flags() {
449
484
[[ -z " ${RELEASE_DIR} " ]] && RELEASE_DIR=" ${REPO_ROOT_DIR} "
450
485
fi
451
486
487
+ # Set signing identity for cosign, it would already be set to the RELEASE one if the release-gcr/release-gcs flags are set
488
+ if [[ -z " ${SIGNING_IDENTITY} " ]]; then
489
+ SIGNING_IDENTITY=" ${NIGHTLY_SIGNING_IDENTITY} "
490
+ fi
491
+
452
492
[[ -z " ${RELEASE_GCS_BUCKET} " && -z " ${RELEASE_DIR} " ]] && abort " --release-gcs or --release-dir must be used"
453
493
if [[ -n " ${RELEASE_DIR} " ]]; then
454
494
mkdir -p " ${RELEASE_DIR} " || abort " cannot create release dir '${RELEASE_DIR} '"
@@ -481,6 +521,7 @@ function parse_flags() {
481
521
readonly RELEASE_DIR
482
522
readonly VALIDATION_TESTS
483
523
readonly FROM_NIGHTLY_RELEASE
524
+ readonly SIGNING_IDENTITY
484
525
}
485
526
486
527
# Run tests (unless --skip-tests was passed). Conveniently displays a banner indicating so.
0 commit comments