-
Notifications
You must be signed in to change notification settings - Fork 83
ci(renovate): auto-update SHA256 checksums for tirith and cosign #5851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #!/usr/bin/env bash | ||
| # Called by Renovate postUpgradeTasks after a cosign version bump. | ||
| # Downloads the new cosign binary, verifies its sigstore bundle signature | ||
| # using the old (currently installed) cosign binary, then updates | ||
| # COSIGN_SHA256 in update-tirith-checksums.sh. | ||
| set -euo pipefail | ||
|
|
||
| SCRIPT="scripts/renovate/update-tirith-checksums.sh" | ||
|
|
||
| # --- Read old and new versions --- | ||
| OLD_VERSION=$(git show HEAD:"${SCRIPT}" | grep -oP '^COSIGN_VERSION=\K\S+' || true) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [MEDIUM] OLD_VERSION extraction via
Suggestion: confirm Renovate's actual commit ordering for |
||
| if [[ -z "${OLD_VERSION}" ]]; then | ||
| echo "error: could not extract COSIGN_VERSION from committed ${SCRIPT}" >&2 | ||
| exit 1 | ||
| fi | ||
| if [[ ! "${OLD_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
| echo "error: OLD_VERSION is not a valid semver: ${OLD_VERSION}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| OLD_SHA256=$(git show HEAD:"${SCRIPT}" | grep -oP '^COSIGN_SHA256=\K\S+' || true) | ||
| if [[ -z "${OLD_SHA256}" ]]; then | ||
| echo "error: could not extract COSIGN_SHA256 from committed ${SCRIPT}" >&2 | ||
| exit 1 | ||
| fi | ||
| if [[ ! "${OLD_SHA256}" =~ ^[0-9a-f]{64}$ ]]; then | ||
| echo "error: OLD_SHA256 is not a valid sha256 hex digest: ${OLD_SHA256}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| NEW_VERSION=$(grep -oP '^COSIGN_VERSION=\K\S+' "${SCRIPT}" || true) | ||
| if [[ -z "${NEW_VERSION}" ]]; then | ||
| echo "error: could not extract COSIGN_VERSION from working-tree ${SCRIPT}" >&2 | ||
| exit 1 | ||
| fi | ||
| if [[ ! "${NEW_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
| echo "error: NEW_VERSION is not a valid semver: ${NEW_VERSION}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ "${OLD_VERSION}" == "${NEW_VERSION}" ]]; then | ||
| echo "cosign version unchanged (${OLD_VERSION}), nothing to do" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "cosign: ${OLD_VERSION} -> ${NEW_VERSION}" | ||
|
|
||
| WORKDIR="$(mktemp -d)" | ||
| trap 'rm -rf "${WORKDIR}"' EXIT | ||
|
|
||
| BASE_URL="https://github.com/sigstore/cosign/releases/download" | ||
|
|
||
| # --- Bootstrap the old cosign binary to use as verifier --- | ||
| OLD_BINARY="${WORKDIR}/cosign-old" | ||
| curl -fsSL "${BASE_URL}/v${OLD_VERSION}/cosign-linux-amd64" -o "${OLD_BINARY}" | ||
| echo "${OLD_SHA256} ${OLD_BINARY}" | sha256sum -c - | ||
| chmod +x "${OLD_BINARY}" | ||
|
|
||
| # --- Download new cosign binary and its sigstore bundle --- | ||
| NEW_BINARY="${WORKDIR}/cosign-linux-amd64" | ||
| curl -fsSL "${BASE_URL}/v${NEW_VERSION}/cosign-linux-amd64" -o "${NEW_BINARY}" | ||
| curl -fsSL "${BASE_URL}/v${NEW_VERSION}/cosign-linux-amd64.sigstore.json" -o "${NEW_BINARY}.sigstore.json" | ||
|
|
||
| # --- Verify the new binary's signature using the old cosign --- | ||
| "${OLD_BINARY}" verify-blob \ | ||
| --bundle "${NEW_BINARY}.sigstore.json" \ | ||
| --certificate-identity "keyless@projectsigstore.iam.gserviceaccount.com" \ | ||
| --certificate-oidc-issuer "https://accounts.google.com" \ | ||
| "${NEW_BINARY}" | ||
|
|
||
| echo "cosign signature verified for v${NEW_VERSION}" | ||
|
|
||
| # --- Compute and update the SHA256 --- | ||
| NEW_SHA256=$(sha256sum "${NEW_BINARY}" | awk '{print $1}') | ||
|
|
||
| if [[ ! "${NEW_SHA256}" =~ ^[0-9a-f]{64}$ ]]; then | ||
| echo "error: computed checksum is not a valid sha256 hex digest: ${NEW_SHA256}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| sed -i "s/^COSIGN_SHA256=.*/COSIGN_SHA256=${NEW_SHA256}/" "${SCRIPT}" | ||
|
|
||
| echo "updated COSIGN_SHA256 to ${NEW_SHA256}" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| #!/usr/bin/env bash | ||
| # Called by Renovate postUpgradeTasks after a tirith version bump. | ||
|
rh-hemartin marked this conversation as resolved.
rh-hemartin marked this conversation as resolved.
|
||
| # Fetches the new release's checksums.txt, verifies its cosign signature | ||
| # against the Sigstore transparency log, and patches the Containerfile | ||
| # so the SHA256 ARGs match the bumped version. | ||
| set -euo pipefail | ||
|
|
||
| # --- Retrieve the new Tirith version --- | ||
| FILE="images/sandbox/Containerfile" | ||
| VERSION=$(grep -oP 'ARG TIRITH_VERSION=\K\S+' "${FILE}" || true) | ||
| if [[ -z "${VERSION}" ]]; then | ||
| echo "Tried to retrieve Tirith version from ${FILE}, couldn't do it. Exiting." | ||
|
waynesun09 marked this conversation as resolved.
|
||
| exit 1 | ||
| fi | ||
| if [[ ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
| echo "error: VERSION is not a valid semver: ${VERSION}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| BASE_URL="https://github.com/sheeki03/tirith/releases/download/v${VERSION}" | ||
|
rh-hemartin marked this conversation as resolved.
|
||
|
|
||
| # --- Bootstrap cosign if not already available --- | ||
| # Pinned version + SHA256 so this script is self-contained inside the | ||
| # Renovate container, which does not ship cosign. | ||
| COSIGN_VERSION=3.1.2 | ||
|
rh-hemartin marked this conversation as resolved.
|
||
| COSIGN_SHA256=f7622ed3cf22e55e1ae6377c080979ff77a22da9981c11df222a2e444991e7cf | ||
|
rh-hemartin marked this conversation as resolved.
|
||
|
|
||
| WORKDIR="$(mktemp -d)" | ||
| trap 'rm -rf "${WORKDIR}"' EXIT | ||
|
|
||
| if command -v cosign &>/dev/null; then | ||
|
rh-hemartin marked this conversation as resolved.
|
||
| COSIGN=cosign | ||
| else | ||
| COSIGN="${WORKDIR}/cosign" | ||
| curl -fsSL "https://github.com/sigstore/cosign/releases/download/v${COSIGN_VERSION}/cosign-linux-amd64" \ | ||
| -o "${COSIGN}" | ||
| echo "${COSIGN_SHA256} ${COSIGN}" | sha256sum -c - | ||
| chmod +x "${COSIGN}" | ||
| fi | ||
|
|
||
| # --- Fetch checksums and cosign verification artifacts --- | ||
| for f in checksums.txt checksums.txt.sig checksums.txt.pem; do | ||
| if ! curl -fsSL "${BASE_URL}/${f}" -o "${WORKDIR}/${f}"; then | ||
| echo "error: failed to fetch ${BASE_URL}/${f}" >&2 | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| # --- Verify the cosign signature on checksums.txt --- | ||
| # Pin the certificate SAN to tirith's .github/workflows/ path (not the whole | ||
| # repo), matching the upstream install.sh scope. | ||
| "${COSIGN}" verify-blob \ | ||
| --certificate "${WORKDIR}/checksums.txt.pem" \ | ||
| --signature "${WORKDIR}/checksums.txt.sig" \ | ||
| --certificate-identity-regexp "^https://github\\.com/sheeki03/tirith/\\.github/workflows/" \ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [MEDIUM] cosign certificate-identity-regexp for tirith accepts any Independently verified by decoding the real Suggestion: anchor the regex to the exact release workflow and version being fetched, e.g. |
||
| --certificate-oidc-issuer "https://token.actions.githubusercontent.com" \ | ||
| "${WORKDIR}/checksums.txt" | ||
|
|
||
| echo "cosign signature verified for tirith v${VERSION} checksums.txt" | ||
|
|
||
| # --- Extract per-architecture SHA256 hashes --- | ||
| AMD64=$(grep -E '^[0-9a-f]{64} tirith-x86_64-unknown-linux-gnu\.tar\.gz$' "${WORKDIR}/checksums.txt" | awk '{print $1}' || true) | ||
| ARM64=$(grep -E '^[0-9a-f]{64} tirith-aarch64-unknown-linux-gnu\.tar\.gz$' "${WORKDIR}/checksums.txt" | awk '{print $1}' || true) | ||
|
|
||
| if [[ ! "${AMD64}" =~ ^[0-9a-f]{64}$ ]]; then | ||
| echo "error: amd64 checksum is not a valid sha256 hex digest: ${AMD64}" >&2 | ||
| exit 1 | ||
| fi | ||
| if [[ ! "${ARM64}" =~ ^[0-9a-f]{64}$ ]]; then | ||
| echo "error: arm64 checksum is not a valid sha256 hex digest: ${ARM64}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
|
rh-hemartin marked this conversation as resolved.
|
||
| sed -i "s/^ARG TIRITH_SHA256_AMD64=.*/ARG TIRITH_SHA256_AMD64=${AMD64}/" "${FILE}" | ||
| sed -i "s/^ARG TIRITH_SHA256_ARM64=.*/ARG TIRITH_SHA256_ARM64=${ARM64}/" "${FILE}" | ||
|
|
||
| echo "updated tirith checksums to v${VERSION}: amd64=${AMD64} arm64=${ARM64}" | ||
Uh oh!
There was an error while loading. Please reload this page.