Skip to content

Commit d9ae696

Browse files
upgrade to latest dependencies (#394)
bumping knative.dev/hack c7cfcb0...199139d: > 199139d Find checksums file works with ARTIFACTS_TO_PUBLISH variable (# 276) > 1384ebd [release-1.9] 🐛 Location-agnostic sign release (# 271) Signed-off-by: Knative Automation <[email protected]>
1 parent 253b7a4 commit d9ae696

File tree

4 files changed

+89
-36
lines changed

4 files changed

+89
-36
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/spf13/cobra v1.6.0
77
gotest.tools/v3 v3.3.0
88
knative.dev/client-pkg v0.0.0-20230120062501-d4ab4e492526
9-
knative.dev/hack v0.0.0-20230113013652-c7cfcb062de9
9+
knative.dev/hack v0.0.0-20230217102752-199139daec7e
1010

1111
)
1212

go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2364,8 +2364,9 @@ knative.dev/control-protocol v0.0.0-20230118172000-03dadc6ffcc9/go.mod h1:qZ6Mq1
23642364
knative.dev/eventing v0.35.1-0.20230118083600-9417125b1468/go.mod h1:PqYrXKXhZU7rQaS5TQuZDSOd9jPX7AegF8uNNUY4kcU=
23652365
knative.dev/hack v0.0.0-20221201154717-7233e77996f1/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
23662366
knative.dev/hack v0.0.0-20230110013548-af8745e34e08/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
2367-
knative.dev/hack v0.0.0-20230113013652-c7cfcb062de9 h1:CDa7s9KspEZqPhk7cN68ZypRLuAvSgr+knoOaXSsrHk=
23682367
knative.dev/hack v0.0.0-20230113013652-c7cfcb062de9/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
2368+
knative.dev/hack v0.0.0-20230217102752-199139daec7e h1:eWgg59nZ5wZK1XMAK1Fiy4+LQSK6kuleM67TOJlSAx8=
2369+
knative.dev/hack v0.0.0-20230217102752-199139daec7e/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
23692370
knative.dev/hack/schema v0.0.0-20230113013652-c7cfcb062de9/go.mod h1:GeIb+PLd5mllawcpHEGF5J5fYTQrvgEO5liao8lUKUs=
23702371
knative.dev/networking v0.0.0-20230118220600-e9d3a55facee/go.mod h1:rn1yRurhkxmSFkpqs/YdG7b9DiYj0VlmLFzBdOQjpOo=
23712372
knative.dev/pkg v0.0.0-20230110013450-dc20e472128f/go.mod h1:IeUSNPPUpQnM35SjpnfCx0w5/V2RpEc+nmke6oPwpD0=

vendor/knative.dev/hack/release.sh

Lines changed: 85 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export KO_DOCKER_REPO="gcr.io/knative-nightly"
111111
# Build stripped binary to reduce size
112112
export GOFLAGS="-ldflags=-s -ldflags=-w"
113113
export GITHUB_TOKEN=""
114+
readonly IMAGES_REFS_FILE="${IMAGES_REFS_FILE:-$(mktemp -d)/images_refs.txt}"
114115

115116
# Convenience function to run the hub tool.
116117
# Parameters: $1..$n - arguments to hub.
@@ -313,64 +314,115 @@ function build_from_source() {
313314
}
314315

315316
function get_images_in_yamls() {
316-
rm -rf imagerefs.txt
317+
rm -rf "$IMAGES_REFS_FILE"
317318
echo "Assembling a list of image refences to sign"
318-
for file in $@; do
319+
for file in "$@"; do
319320
[[ "${file##*.}" != "yaml" ]] && continue
320321
echo "Inspecting ${file}"
321-
for image in $(grep -oh "\S*${KO_DOCKER_REPO}\S*" "${file}"); do
322-
echo $image >> imagerefs.txt
323-
done
322+
while read -r image; do
323+
echo "$image" >> "$IMAGES_REFS_FILE"
324+
done < <(grep -oh "\S*${KO_DOCKER_REPO}\S*" "${file}")
325+
done
326+
if [[ -f "$IMAGES_REFS_FILE" ]]; then
327+
sort -uo "$IMAGES_REFS_FILE" "$IMAGES_REFS_FILE" # Remove duplicate entries
328+
fi
329+
}
330+
331+
# Finds a checksums file within the given list of artifacts (space delimited)
332+
# Parameters: $n - artifact files
333+
function find_checksums_file() {
334+
for arg in "$@"; do
335+
# kinda dirty hack needed as we pass $ARTIFACTS_TO_PUBLISH in space
336+
# delimiter variable, which is vulnerable to all sorts of argument quoting
337+
while read -r file; do
338+
if [[ "${file}" == *"checksums.txt" ]]; then
339+
echo "${file}"
340+
return 0
341+
fi
342+
done < <(echo "$arg" | tr ' ' '\n')
324343
done
325-
sort -uo imagerefs.txt imagerefs.txt # Remove duplicate entries
344+
warning "cannot find checksums file"
326345
}
327346

328347
# Build a release from source.
329348
function sign_release() {
330-
get_images_in_yamls "${ARTIFACTS_TO_PUBLISH}"
331349
if (( ! IS_PROW )); then # This function can't be run by devs on their laptops
332350
return 0
333351
fi
352+
get_images_in_yamls "${ARTIFACTS_TO_PUBLISH}"
353+
local checksums_file
354+
checksums_file="$(find_checksums_file "${ARTIFACTS_TO_PUBLISH}")"
355+
356+
if ! [[ -f "${checksums_file}" ]]; then
357+
echo '>> No checksums file found, generating one'
358+
checksums_file="$(mktemp -d)/checksums.txt"
359+
for file in ${ARTIFACTS_TO_PUBLISH}; do
360+
pushd "$(dirname "$file")" >/dev/null
361+
sha256sum "$(basename "$file")" >> "${checksums_file}"
362+
popd >/dev/null
363+
done
364+
ARTIFACTS_TO_PUBLISH="${ARTIFACTS_TO_PUBLISH} ${checksums_file}"
365+
fi
334366

335367
# Notarizing mac binaries needs to be done before cosign as it changes the checksum values
336368
# of the darwin binaries
337369
if [ -n "${APPLE_CODESIGN_KEY}" ] && [ -n "${APPLE_CODESIGN_PASSWORD_FILE}" ] && [ -n "${APPLE_NOTARY_API_KEY}" ]; then
338370
banner "Notarizing macOS Binaries for the release"
339-
FILES=$(find -- * -type f -name "*darwin*")
340-
for file in $FILES; do
341-
rcodesign sign "${file}" --p12-file="${APPLE_CODESIGN_KEY}" \
342-
--code-signature-flags=runtime \
343-
--p12-password-file="${APPLE_CODESIGN_PASSWORD_FILE}"
344-
done
345-
zip files.zip ${FILES}
346-
rcodesign notary-submit files.zip --api-key-path="${APPLE_NOTARY_API_KEY}" --wait
347-
sha256sum ${ARTIFACTS_TO_PUBLISH//checksums.txt/} > checksums.txt
348-
echo "🧮 Post Notarization Checksum:"
349-
cat checksums.txt
371+
local macos_artifacts
372+
declare -a macos_artifacts=()
373+
while read -r file; do
374+
if echo "$file" | grep -q "darwin"; then
375+
macos_artifacts+=("${file}")
376+
rcodesign sign "${file}" --p12-file="${APPLE_CODESIGN_KEY}" \
377+
--code-signature-flags=runtime \
378+
--p12-password-file="${APPLE_CODESIGN_PASSWORD_FILE}"
379+
fi
380+
done < <(echo "${ARTIFACTS_TO_PUBLISH}" | tr ' ' '\n')
381+
if [[ -z "${macos_artifacts[*]}" ]]; then
382+
warning "No macOS binaries found, skipping notarization"
383+
else
384+
local zip_file
385+
zip_file="$(mktemp -d)/files.zip"
386+
zip "$zip_file" -@ < <(printf "%s\n" "${macos_artifacts[@]}")
387+
rcodesign notary-submit "$zip_file" --api-key-path="${APPLE_NOTARY_API_KEY}" --wait
388+
true > "${checksums_file}" # Clear the checksums file
389+
for file in ${ARTIFACTS_TO_PUBLISH}; do
390+
if echo "$file" | grep -q "checksums.txt"; then
391+
continue # Don't checksum the checksums file
392+
fi
393+
pushd "$(dirname "$file")" >/dev/null
394+
sha256sum "$(basename "$file")" >> "${checksums_file}"
395+
popd >/dev/null
396+
done
397+
echo "🧮 Post Notarization Checksum:"
398+
cat "$checksums_file"
399+
fi
350400
fi
351401

352402
ID_TOKEN=$(gcloud auth print-identity-token --audiences=sigstore \
353403
--include-email \
354404
--impersonate-service-account="${SIGNING_IDENTITY}")
355405
echo "Signing Images with the identity ${SIGNING_IDENTITY}"
356406
## Sign the images with cosign
357-
if [[ -f "imagerefs.txt" ]]; then
358-
COSIGN_EXPERIMENTAL=1 cosign sign $(cat imagerefs.txt) --recursive --identity-token="${ID_TOKEN}"
359-
if [ -n "${ATTEST_IMAGES:-}" ]; then # Temporary Feature Gate
360-
provenance-generator --clone-log=/logs/clone.json \
361-
--image-refs=imagerefs.txt --output=attestation.json
362-
mkdir -p "${ARTIFACTS}"/attestation && cp attestation.json "${ARTIFACTS}"/attestation
363-
COSIGN_EXPERIMENTAL=1 cosign attest $(cat imagerefs.txt) --recursive --identity-token="${ID_TOKEN}" \
364-
--predicate=attestation.json --type=slsaprovenance
365-
fi
407+
if [[ -f "$IMAGES_REFS_FILE" ]]; then
408+
COSIGN_EXPERIMENTAL=1 cosign sign $(cat "$IMAGES_REFS_FILE") \
409+
--recursive --identity-token="${ID_TOKEN}"
410+
if [ -n "${ATTEST_IMAGES:-}" ]; then # Temporary Feature Gate
411+
provenance-generator --clone-log=/logs/clone.json \
412+
--image-refs="$IMAGES_REFS_FILE" --output=attestation.json
413+
mkdir -p "${ARTIFACTS}"/attestation && cp attestation.json "${ARTIFACTS}"/attestation
414+
COSIGN_EXPERIMENTAL=1 cosign attest $(cat "$IMAGES_REFS_FILE") \
415+
--recursive --identity-token="${ID_TOKEN}" \
416+
--predicate=attestation.json --type=slsaprovenance
417+
fi
366418
fi
367419

368-
## Check if there is checksums.txt file. If so, sign the checksum file
369-
if [[ -f "checksums.txt" ]]; then
370-
echo "Signing Images with the identity ${SIGNING_IDENTITY}"
371-
COSIGN_EXPERIMENTAL=1 cosign sign-blob checksums.txt --output-signature=checksums.txt.sig --output-certificate=checksums.txt.pem --identity-token="${ID_TOKEN}"
372-
ARTIFACTS_TO_PUBLISH="${ARTIFACTS_TO_PUBLISH} checksums.txt.sig checksums.txt.pem"
373-
fi
420+
echo "Signing checksums with the identity ${SIGNING_IDENTITY}"
421+
COSIGN_EXPERIMENTAL=1 cosign sign-blob "$checksums_file" \
422+
--output-signature="${checksums_file}.sig" \
423+
--output-certificate="${checksums_file}.pem" \
424+
--identity-token="${ID_TOKEN}"
425+
ARTIFACTS_TO_PUBLISH="${ARTIFACTS_TO_PUBLISH} ${checksums_file}.sig ${checksums_file}.pem"
374426
}
375427

376428
# Copy tagged images from the nightly GCR to the release GCR, tagging them 'latest'.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ gotest.tools/v3/internal/source
2525
# knative.dev/client-pkg v0.0.0-20230120062501-d4ab4e492526
2626
## explicit; go 1.18
2727
knative.dev/client-pkg/pkg/kn/plugin
28-
# knative.dev/hack v0.0.0-20230113013652-c7cfcb062de9
28+
# knative.dev/hack v0.0.0-20230217102752-199139daec7e
2929
## explicit; go 1.18
3030
knative.dev/hack

0 commit comments

Comments
 (0)