-
Notifications
You must be signed in to change notification settings - Fork 9
Adding npm release service catalog scripts to utils #367
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
Merged
dperaza4dustbit
merged 1 commit into
calungaproject:main
from
dperaza4dustbit:rsc_util_image_update_npm
Aug 4, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #!/usr/bin/env bash | ||
| # Shared helpers for npm pulp release scripts. Source from other scripts: | ||
| # # shellcheck source=npm-common.sh | ||
| # source "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/npm-common.sh" | ||
|
|
||
| # Fail if the named tar member is missing, empty, or larger than max_bytes. | ||
| # Probes with head -c so we never buffer more than max+1 bytes. | ||
| assert_tar_member_size() { | ||
| local archive="${1}" | ||
| local member="${2}" | ||
| local max_bytes="${3}" | ||
| local tmp size | ||
| tmp="$(mktemp)" | ||
| # Process substitution avoids a pipefail-sensitive tar|head pipeline: | ||
| # head closes early on truncate; tar's SIGPIPE stays in the subshell. | ||
| head -c "$((max_bytes + 1))" \ | ||
| < <(tar -xOf "${archive}" "${member}" 2>/dev/null) \ | ||
| > "${tmp}" || true | ||
| size="$(wc -c < "${tmp}" | tr -d ' ')" | ||
| rm -f "${tmp}" | ||
| if [[ -z "${size}" || "${size}" -eq 0 ]]; then | ||
| return 1 | ||
| fi | ||
| if [[ "${size}" -gt "${max_bytes}" ]]; then | ||
| echo "ERROR: ${member} in $(basename "${archive}") exceeds" \ | ||
| "${max_bytes} bytes" >&2 | ||
| return 1 | ||
| fi | ||
| return 0 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| #!/usr/bin/env bash | ||
| # Verify and store Tekton Chains SLSA provenance for snapshot images. | ||
| # | ||
| # Env: | ||
| # FILES_DIR Extracted files root (required) | ||
| # IMAGES_TXT File listing digest-pinned images (required) | ||
| # TRUSTED_PROVENANCE_NAMESPACES Comma-separated namespaces (default: calunga-tenant) | ||
| # | ||
| set -euo pipefail | ||
|
|
||
| FILES_DIR="${FILES_DIR:?FILES_DIR required}" | ||
| IMAGES_TXT="${IMAGES_TXT:?IMAGES_TXT required}" | ||
| TRUSTED_PROVENANCE_NAMESPACES="${TRUSTED_PROVENANCE_NAMESPACES:-calunga-tenant}" | ||
|
|
||
| PROVENANCE_DIR="${FILES_DIR}/chains-provenance" | ||
| DOCKER_CONFIG="$(mktemp -d)" | ||
| export DOCKER_CONFIG | ||
| on_exit() { | ||
| rm -rf "${DOCKER_CONFIG}" | ||
| } | ||
| trap 'on_exit' EXIT | ||
| mkdir -p "${PROVENANCE_DIR}" | ||
|
|
||
| # Trusted Chains identity for npm snapshot images (promote or build). | ||
| readonly EXPECTED_BUILDER_ID="https://konflux-ci.dev/chains/v2" | ||
| readonly EXPECTED_BUILD_TYPE="https://tekton.dev/chains/v2/slsa" | ||
| TRUSTED_NS_JSON="$(jq -nc --arg s "${TRUSTED_PROVENANCE_NAMESPACES}" ' | ||
| $s | ||
| | split(",") | ||
| | map(gsub("^\\s+|\\s+$"; "")) | ||
| | map(select(length > 0)) | ||
| ')" | ||
| if [[ "$(jq 'length' <<<"${TRUSTED_NS_JSON}")" -eq 0 ]]; then | ||
| echo "ERROR: trustedProvenanceNamespaces must list at least one namespace" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| while read -r IMAGE; do | ||
| [[ -n "${IMAGE}" ]] || continue | ||
| echo "Fetching Chains provenance for ${IMAGE}" | ||
|
|
||
| select-oci-auth "${IMAGE}" > "${DOCKER_CONFIG}/config.json" | ||
|
|
||
| DIGEST="${IMAGE##*@}" | ||
| if [[ ! "${DIGEST}" =~ ^sha256:[a-fA-F0-9]{64}$ ]]; then | ||
| echo "ERROR: image must be digest-pinned (got ${IMAGE})" >&2 | ||
| exit 1 | ||
| fi | ||
| DIGEST_SAFE="${DIGEST//[:\/]/_}" | ||
| PROVENANCE_FILE="${PROVENANCE_DIR}/${DIGEST_SAFE}.json" | ||
|
|
||
| COSIGN_STDERR="/tmp/cosign-stderr-${DIGEST_SAFE}.log" | ||
| COSIGN_STDOUT="/tmp/cosign-stdout-${DIGEST_SAFE}.jsonl" | ||
| # Chains uses AWS KMS for signing, not public Sigstore/Rekor, | ||
| # so transparency log and SCT verification are skipped (same as | ||
| # extract-py-artifacts). Trust is the cluster Chains key plus | ||
| # subject digest and builder/pipeline/namespace checks below. | ||
| if ! cosign verify-attestation \ | ||
| --type=slsaprovenance \ | ||
| --insecure-ignore-tlog=true \ | ||
| --insecure-ignore-sct=true \ | ||
| --key k8s://openshift-pipelines/public-key \ | ||
| "${IMAGE}" >"${COSIGN_STDOUT}" 2>"${COSIGN_STDERR}"; then | ||
| echo "ERROR: Failed to fetch Chains provenance for ${IMAGE}" >&2 | ||
| cat "${COSIGN_STDERR}" >&2 | ||
| exit 1 | ||
| fi | ||
| # Capture full cosign output (avoid SIGPIPE from head under pipefail), | ||
| # then keep a SLSA statement that: | ||
| # - has buildDefinition | ||
| # - subject digest matches this image | ||
| # - was produced by Konflux Chains with a trusted npm pipeline | ||
| # - invocationId is in an authorized tenant namespace | ||
| DIGEST_HEX="${DIGEST#sha256:}" | ||
| if ! jq -s -e \ | ||
| --arg want "${DIGEST_HEX}" \ | ||
| --arg builder "${EXPECTED_BUILDER_ID}" \ | ||
| --arg buildType "${EXPECTED_BUILD_TYPE}" \ | ||
| --argjson trustedNs "${TRUSTED_NS_JSON}" ' | ||
| map(try (.payload | @base64d | fromjson) catch empty) | ||
| | map(select( | ||
| .predicate.buildDefinition != null | ||
| and (.predicate.buildDefinition.buildType // "") == $buildType | ||
| and (.predicate.runDetails.builder.id // "") == $builder | ||
| and ( | ||
| (.predicate.buildDefinition.externalParameters.runSpec.pipelineRef.name // "") as $pn | ||
| | ($pn == "promote-npm" or $pn == "build-npm") | ||
| ) | ||
| and ( | ||
| (.predicate.runDetails.metadata.invocationId // "") as $id | ||
| | any($trustedNs[]; . as $ns | ($id | startswith($ns + "/"))) | ||
| ) | ||
| and any( | ||
| .subject[]?; | ||
| (.digest.sha256 // "") == $want | ||
| ) | ||
| )) | ||
| | .[0] // empty | ||
| | select(. != null and . != {}) | ||
| ' "${COSIGN_STDOUT}" > "${PROVENANCE_FILE}"; then | ||
| echo "ERROR: No trusted Chains SLSA provenance for ${DIGEST}" >&2 | ||
| echo " expected builder=${EXPECTED_BUILDER_ID}" >&2 | ||
| echo " expected buildType=${EXPECTED_BUILD_TYPE}" >&2 | ||
| echo " expected pipelineRef.name in {promote-npm,build-npm}" >&2 | ||
| echo " expected invocationId namespace in ${TRUSTED_NS_JSON}" >&2 | ||
| cat "${COSIGN_STDERR}" >&2 | ||
| cat "${COSIGN_STDOUT}" >&2 | ||
| exit 1 | ||
| fi | ||
| echo " Saved Chains provenance to ${PROVENANCE_FILE}" | ||
| rm -f "${COSIGN_STDERR}" "${COSIGN_STDOUT}" | ||
| done < "${IMAGES_TXT}" | ||
|
|
||
| echo "Chains provenance files:" | ||
| ls -la "${PROVENANCE_DIR}" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.