From 5294a0ccd7318b69192d4b185892e4d0efd3302c Mon Sep 17 00:00:00 2001 From: Jon Thia Date: Wed, 16 Sep 2026 17:21:04 +1000 Subject: [PATCH 1/4] =?UTF-8?q?feat(publish-image):=20mirror=20mode=20?= =?UTF-8?q?=E2=80=94=20copy=20+=20sign=20a=20digest-pinned=20upstream=20im?= =?UTF-8?q?age?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit source_image (a ref pinned by digest) skips the build and crane-copies that exact manifest into our ECR, then signs it under this workflow's identity — so third-party images we run (first user: the SEDA data proxy, ghcr.io/sedaprotocol/seda-data-proxy) pass the same admission policy as images we build, with the digest reviewed in the caller's PR. source_verify_identity/issuer are the future hook: set once the upstream signs their releases, and the mirror cosign-verifies the source before copying (fails closed). Unset today — SEDA doesn't sign yet (asked); the run summary carries an explicit warning. Digest handling is unified in a resolve step (build output or upstream pin); the prod copy + both sign steps read from it, preserving the digest-end-to-end invariant. setup-crane moves earlier and runs unconditionally since mirror mode needs it before the prod section. --- .github/workflows/publish-image.yml | 101 ++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml index 0e4b8cc..aacfa96 100644 --- a/.github/workflows/publish-image.yml +++ b/.github/workflows/publish-image.yml @@ -59,6 +59,33 @@ on: required: false type: string default: '' + # MIRROR MODE: set source_image (a full ref pinned by digest, + # e.g. ghcr.io/org/name:1.2.3@sha256:...) to SKIP the build and + # instead crane-copy that exact manifest into our ECR, then sign + # it under this workflow's identity like any built image. Trust + # model: the digest is reviewed in the caller repo (PR that bumps + # it) and the copy cannot rewrite the manifest, so what lands is + # bit-for-bit what was reviewed; our signature attests "we chose + # this digest", not that we built it. + source_image: + description: Digest-pinned upstream ref to mirror instead of building + required: false + type: string + default: '' + # Future hook — once the upstream signs their releases, set both + # and the mirror VERIFIES the upstream cosign signature before + # copying (fails closed on mismatch). Empty = verification + # skipped with a warning in the run summary (upstream unsigned). + source_verify_identity: + description: cosign certificate identity regexp for the upstream signature + required: false + type: string + default: '' + source_verify_issuer: + description: cosign certificate OIDC issuer for the upstream signature + required: false + type: string + default: '' checkout_submodules: description: actions/checkout submodules value ('false', 'true' or 'recursive') required: false @@ -114,9 +141,13 @@ jobs: id: login-ecr uses: aws-actions/amazon-ecr-login@19d944daaa35f0fa1d3f7f8af1d3f2e5de25c5b7 # v2.1.4 + - uses: imjasonh/setup-crane@feee3b6bb0d4c68370f256a4502498c9227e5c6b # v0.7 + - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 + if: inputs.source_image == '' - name: Build and push (non-prod) + if: inputs.source_image == '' id: build uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6 with: @@ -130,11 +161,72 @@ jobs: cache-to: ${{ inputs.cache_scope != '' && format('type=gha,mode=max,scope={0}', inputs.cache_scope) || '' }} secrets: ${{ secrets.build_secrets }} + # Mirror mode: verify (when the upstream signs), then copy the + # exact reviewed digest. crane copy cannot rewrite the manifest, + # and the assertion catches any tool regression — same rationale + # as the prod copy below. + - name: Verify upstream signature (mirror) + if: inputs.source_image != '' + env: + SOURCE: ${{ inputs.source_image }} + IDENTITY: ${{ inputs.source_verify_identity }} + ISSUER: ${{ inputs.source_verify_issuer }} + run: | + set -euo pipefail + if [ -z "$IDENTITY" ] || [ -z "$ISSUER" ]; then + echo "::warning::Upstream signature NOT verified for ${SOURCE} — source_verify_identity/issuer unset (upstream doesn't sign releases yet). The digest itself is still the reviewed pin." + echo "⚠ Mirrored WITHOUT upstream signature verification: \`${SOURCE}\`" >> "$GITHUB_STEP_SUMMARY" + exit 0 + fi + cosign verify \ + --certificate-identity-regexp "$IDENTITY" \ + --certificate-oidc-issuer "$ISSUER" \ + "$SOURCE" + echo "Upstream signature verified: \`${SOURCE}\`" >> "$GITHUB_STEP_SUMMARY" + + - name: Mirror image (non-prod, digest-preserving) + if: inputs.source_image != '' + id: mirror + env: + SOURCE: ${{ inputs.source_image }} + DST: ${{ steps.login-ecr.outputs.registry }}/${{ inputs.ecr_repository }} + TAG: ${{ inputs.image_tag }} + run: | + set -euo pipefail + digest="${SOURCE##*@}" + case "$digest" in + sha256:*) ;; + *) echo "::error::source_image must be pinned by digest (…@sha256:…): ${SOURCE}"; exit 1 ;; + esac + crane copy "${SOURCE}" "${DST}:${TAG}" + copied=$(crane digest "${DST}:${TAG}") + if [ "$copied" != "$digest" ]; then + echo "::error::mirrored tag ${TAG} points at ${copied}, expected source digest ${digest} — copy did not preserve the digest." + exit 1 + fi + echo "digest=${digest}" >> "$GITHUB_OUTPUT" + + # Single source of truth for the published digest: the build's in + # build mode, the upstream pin's in mirror mode. Every sign/copy + # step below uses this. + - name: Resolve published digest + id: digest + env: + BUILD_DIGEST: ${{ steps.build.outputs.digest }} + MIRROR_DIGEST: ${{ steps.mirror.outputs.digest }} + run: | + set -euo pipefail + digest="${BUILD_DIGEST:-$MIRROR_DIGEST}" + if [ -z "$digest" ]; then + echo "::error::no digest produced (neither build nor mirror ran)"; exit 1 + fi + echo "digest=${digest}" >> "$GITHUB_OUTPUT" + - name: Sign image (non-prod) env: REF: ${{ steps.login-ecr.outputs.registry }}/${{ inputs.ecr_repository }} TAG: ${{ inputs.image_tag }} - DIGEST: ${{ steps.build.outputs.digest }} + DIGEST: ${{ steps.digest.outputs.digest }} run: | set -euo pipefail cosign sign --yes "${REF}@${DIGEST}" @@ -153,9 +245,6 @@ jobs: id: login-ecr-prod uses: aws-actions/amazon-ecr-login@19d944daaa35f0fa1d3f7f8af1d3f2e5de25c5b7 # v2.1.4 - - uses: imjasonh/setup-crane@feee3b6bb0d4c68370f256a4502498c9227e5c6b # v0.7 - if: vars.VELOCITY_PROD_ECR_PUBLISH_ROLE != '' - # Copy BY THE BUILT DIGEST with crane — a pure registry-to-registry # copy that CANNOT rewrite the manifest, so the prod tag points at # exactly the (signed) manifest this run built. `imagetools create` @@ -170,7 +259,7 @@ jobs: SRC: ${{ steps.login-ecr.outputs.registry }}/${{ inputs.ecr_repository }} DST: ${{ steps.login-ecr-prod.outputs.registry }}/${{ inputs.ecr_repository }} TAG: ${{ inputs.image_tag }} - DIGEST: ${{ steps.build.outputs.digest }} + DIGEST: ${{ steps.digest.outputs.digest }} run: | set -euo pipefail crane copy "${SRC}@${DIGEST}" "${DST}:${TAG}" @@ -182,4 +271,4 @@ jobs: - name: Sign image (prod) if: vars.VELOCITY_PROD_ECR_PUBLISH_ROLE != '' - run: cosign sign --yes "${{ steps.login-ecr-prod.outputs.registry }}/${{ inputs.ecr_repository }}@${{ steps.build.outputs.digest }}" + run: cosign sign --yes "${{ steps.login-ecr-prod.outputs.registry }}/${{ inputs.ecr_repository }}@${{ steps.digest.outputs.digest }}" From 47e911c5c2ea20ce20e6e453e2492adb35294d21 Mon Sep 17 00:00:00 2001 From: Jon Thia Date: Wed, 16 Sep 2026 17:54:32 +1000 Subject: [PATCH 2/4] =?UTF-8?q?Revert=20"feat(publish-image):=20mirror=20m?= =?UTF-8?q?ode=20=E2=80=94=20copy=20+=20sign=20a=20digest-pinned=20upstrea?= =?UTF-8?q?m=20image"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 5294a0ccd7318b69192d4b185892e4d0efd3302c. --- .github/workflows/publish-image.yml | 101 ++-------------------------- 1 file changed, 6 insertions(+), 95 deletions(-) diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml index aacfa96..0e4b8cc 100644 --- a/.github/workflows/publish-image.yml +++ b/.github/workflows/publish-image.yml @@ -59,33 +59,6 @@ on: required: false type: string default: '' - # MIRROR MODE: set source_image (a full ref pinned by digest, - # e.g. ghcr.io/org/name:1.2.3@sha256:...) to SKIP the build and - # instead crane-copy that exact manifest into our ECR, then sign - # it under this workflow's identity like any built image. Trust - # model: the digest is reviewed in the caller repo (PR that bumps - # it) and the copy cannot rewrite the manifest, so what lands is - # bit-for-bit what was reviewed; our signature attests "we chose - # this digest", not that we built it. - source_image: - description: Digest-pinned upstream ref to mirror instead of building - required: false - type: string - default: '' - # Future hook — once the upstream signs their releases, set both - # and the mirror VERIFIES the upstream cosign signature before - # copying (fails closed on mismatch). Empty = verification - # skipped with a warning in the run summary (upstream unsigned). - source_verify_identity: - description: cosign certificate identity regexp for the upstream signature - required: false - type: string - default: '' - source_verify_issuer: - description: cosign certificate OIDC issuer for the upstream signature - required: false - type: string - default: '' checkout_submodules: description: actions/checkout submodules value ('false', 'true' or 'recursive') required: false @@ -141,13 +114,9 @@ jobs: id: login-ecr uses: aws-actions/amazon-ecr-login@19d944daaa35f0fa1d3f7f8af1d3f2e5de25c5b7 # v2.1.4 - - uses: imjasonh/setup-crane@feee3b6bb0d4c68370f256a4502498c9227e5c6b # v0.7 - - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 - if: inputs.source_image == '' - name: Build and push (non-prod) - if: inputs.source_image == '' id: build uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6 with: @@ -161,72 +130,11 @@ jobs: cache-to: ${{ inputs.cache_scope != '' && format('type=gha,mode=max,scope={0}', inputs.cache_scope) || '' }} secrets: ${{ secrets.build_secrets }} - # Mirror mode: verify (when the upstream signs), then copy the - # exact reviewed digest. crane copy cannot rewrite the manifest, - # and the assertion catches any tool regression — same rationale - # as the prod copy below. - - name: Verify upstream signature (mirror) - if: inputs.source_image != '' - env: - SOURCE: ${{ inputs.source_image }} - IDENTITY: ${{ inputs.source_verify_identity }} - ISSUER: ${{ inputs.source_verify_issuer }} - run: | - set -euo pipefail - if [ -z "$IDENTITY" ] || [ -z "$ISSUER" ]; then - echo "::warning::Upstream signature NOT verified for ${SOURCE} — source_verify_identity/issuer unset (upstream doesn't sign releases yet). The digest itself is still the reviewed pin." - echo "⚠ Mirrored WITHOUT upstream signature verification: \`${SOURCE}\`" >> "$GITHUB_STEP_SUMMARY" - exit 0 - fi - cosign verify \ - --certificate-identity-regexp "$IDENTITY" \ - --certificate-oidc-issuer "$ISSUER" \ - "$SOURCE" - echo "Upstream signature verified: \`${SOURCE}\`" >> "$GITHUB_STEP_SUMMARY" - - - name: Mirror image (non-prod, digest-preserving) - if: inputs.source_image != '' - id: mirror - env: - SOURCE: ${{ inputs.source_image }} - DST: ${{ steps.login-ecr.outputs.registry }}/${{ inputs.ecr_repository }} - TAG: ${{ inputs.image_tag }} - run: | - set -euo pipefail - digest="${SOURCE##*@}" - case "$digest" in - sha256:*) ;; - *) echo "::error::source_image must be pinned by digest (…@sha256:…): ${SOURCE}"; exit 1 ;; - esac - crane copy "${SOURCE}" "${DST}:${TAG}" - copied=$(crane digest "${DST}:${TAG}") - if [ "$copied" != "$digest" ]; then - echo "::error::mirrored tag ${TAG} points at ${copied}, expected source digest ${digest} — copy did not preserve the digest." - exit 1 - fi - echo "digest=${digest}" >> "$GITHUB_OUTPUT" - - # Single source of truth for the published digest: the build's in - # build mode, the upstream pin's in mirror mode. Every sign/copy - # step below uses this. - - name: Resolve published digest - id: digest - env: - BUILD_DIGEST: ${{ steps.build.outputs.digest }} - MIRROR_DIGEST: ${{ steps.mirror.outputs.digest }} - run: | - set -euo pipefail - digest="${BUILD_DIGEST:-$MIRROR_DIGEST}" - if [ -z "$digest" ]; then - echo "::error::no digest produced (neither build nor mirror ran)"; exit 1 - fi - echo "digest=${digest}" >> "$GITHUB_OUTPUT" - - name: Sign image (non-prod) env: REF: ${{ steps.login-ecr.outputs.registry }}/${{ inputs.ecr_repository }} TAG: ${{ inputs.image_tag }} - DIGEST: ${{ steps.digest.outputs.digest }} + DIGEST: ${{ steps.build.outputs.digest }} run: | set -euo pipefail cosign sign --yes "${REF}@${DIGEST}" @@ -245,6 +153,9 @@ jobs: id: login-ecr-prod uses: aws-actions/amazon-ecr-login@19d944daaa35f0fa1d3f7f8af1d3f2e5de25c5b7 # v2.1.4 + - uses: imjasonh/setup-crane@feee3b6bb0d4c68370f256a4502498c9227e5c6b # v0.7 + if: vars.VELOCITY_PROD_ECR_PUBLISH_ROLE != '' + # Copy BY THE BUILT DIGEST with crane — a pure registry-to-registry # copy that CANNOT rewrite the manifest, so the prod tag points at # exactly the (signed) manifest this run built. `imagetools create` @@ -259,7 +170,7 @@ jobs: SRC: ${{ steps.login-ecr.outputs.registry }}/${{ inputs.ecr_repository }} DST: ${{ steps.login-ecr-prod.outputs.registry }}/${{ inputs.ecr_repository }} TAG: ${{ inputs.image_tag }} - DIGEST: ${{ steps.digest.outputs.digest }} + DIGEST: ${{ steps.build.outputs.digest }} run: | set -euo pipefail crane copy "${SRC}@${DIGEST}" "${DST}:${TAG}" @@ -271,4 +182,4 @@ jobs: - name: Sign image (prod) if: vars.VELOCITY_PROD_ECR_PUBLISH_ROLE != '' - run: cosign sign --yes "${{ steps.login-ecr-prod.outputs.registry }}/${{ inputs.ecr_repository }}@${{ steps.digest.outputs.digest }}" + run: cosign sign --yes "${{ steps.login-ecr-prod.outputs.registry }}/${{ inputs.ecr_repository }}@${{ steps.build.outputs.digest }}" From 4273eacdd0477e3736582569c6c6dcd4246ae77c Mon Sep 17 00:00:00 2001 From: Jon Thia Date: Wed, 16 Sep 2026 17:55:40 +1000 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20dedicated=20mirror-image=20workflow?= =?UTF-8?q?=20=E2=80=94=20a=20separate=20signing=20identity=20for=20third-?= =?UTF-8?q?party=20mirrors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces the mirror mode previously added inside publish-image.yml (reverted here): a mirror signature means 'we reviewed and chose this upstream digest', which is weaker than 'built from reviewed source' and must not be interchangeable with it. The split is enforced two ways: this workflow signs with its own identity (mirror-image.yml@refs/heads/master), accepted only by the mirror ClusterImagePolicy whose glob is /mirror/*; and the mirror/ ECR path prefix is forced inside this workflow rather than taken from the caller, so this identity can never sign a ref the app-image policy matches. publish-image.yml stays byte-identical to master — build mode untouched. Same invariants otherwise: master-ancestry gate, cosign v2 pin, digest-preserving crane copies asserted end-to-end, and the source_verify_identity/issuer hook that turns on upstream cosign verification once the upstream (SEDA) signs releases. --- .github/workflows/mirror-image.yml | 178 +++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 .github/workflows/mirror-image.yml diff --git a/.github/workflows/mirror-image.yml b/.github/workflows/mirror-image.yml new file mode 100644 index 0000000..8a32662 --- /dev/null +++ b/.github/workflows/mirror-image.yml @@ -0,0 +1,178 @@ +# The central third-party image MIRROR — a SEPARATE signing identity from +# publish-image.yml, on purpose. Callers use +# uses: velocity-exchange/shared-workflows/.github/workflows/mirror-image.yml@master +# so the cosign keyless certificate's job_workflow_ref is THIS FILE AT +# refs/heads/master, and the mirror ClusterImagePolicy (infrastructure-v3, +# gitops//platform/policy-controller/) pins to exactly that. MOVING OR +# RENAMING THIS FILE CHANGES THE IDENTITY — same migration rules as +# publish-image.yml's header. +# +# Why a separate identity: publish-image.yml's signature means "built from +# reviewed source in a velocity repo". A mirror signature can only ever mean +# "we reviewed and chose this upstream digest" — weaker, so it must not be +# interchangeable. The split is enforced two ways: +# - this workflow signs with a different identity, accepted ONLY by the +# mirror ClusterImagePolicy, whose image glob is /mirror/*; +# - the mirror/ ECR path prefix is FORCED here (not caller input), so this +# identity physically never signs a ref that the app-image policy globs +# match, and a compromised mirror flow cannot impersonate a built image. +# The inverse also holds: publish-image.yml never signs third-party bytes. +# +# Same invariants as publish-image.yml: master-ancestry gate, cosign v2 pin, +# digest-end-to-end (the digest is the caller's reviewed pin; every copy is +# asserted against it). +name: Mirror image (reusable) + +on: + workflow_call: + inputs: + name: + description: Image name; lands at mirror/ in both ECRs + required: true + type: string + image_tag: + description: ECR tag to publish, e.g. v1.2.3 + required: true + type: string + source_image: + description: Digest-pinned upstream ref (…:tag@sha256:…) to mirror + required: true + type: string + # Future hook — set both once the upstream signs their releases: + # the mirror then cosign-verifies the upstream signature before + # copying and fails closed on mismatch. Empty = verification + # skipped with a warning in the run summary (upstream unsigned). + source_verify_identity: + description: cosign certificate identity regexp for the upstream signature + required: false + type: string + default: '' + source_verify_issuer: + description: cosign certificate OIDC issuer for the upstream signature + required: false + type: string + default: '' + +jobs: + mirror: + runs-on: ubicloud + steps: + # Mirror tags must point at reviewed code: the digest being + # mirrored is pinned in a file on the CALLER repo's master, so + # the tagged commit must be on master. Runs here — not in the + # caller — so it can't be stripped by editing a branch's + # workflow file. + - name: Require tagged commit to be on master + env: + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + status=$(curl -sf -H "Authorization: Bearer ${GH_TOKEN}" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/${GITHUB_REPOSITORY}/compare/master...${GITHUB_SHA}" | jq -r '.status') + if [ "$status" != "identical" ] && [ "$status" != "behind" ]; then + echo "::error::${GITHUB_REF_NAME} points at ${GITHUB_SHA}, which is not on master (compare status: ${status}). Mirror tags must point at reviewed master commits." + exit 1 + fi + + - uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 + with: + cosign-release: 'v2.6.5' + + - uses: imjasonh/setup-crane@feee3b6bb0d4c68370f256a4502498c9227e5c6b # v0.7 + + - name: Verify upstream signature + env: + SOURCE: ${{ inputs.source_image }} + IDENTITY: ${{ inputs.source_verify_identity }} + ISSUER: ${{ inputs.source_verify_issuer }} + run: | + set -euo pipefail + if [ -z "$IDENTITY" ] || [ -z "$ISSUER" ]; then + echo "::warning::Upstream signature NOT verified for ${SOURCE} — source_verify_identity/issuer unset (upstream doesn't sign releases yet). The digest itself is still the reviewed pin." + echo "⚠ Mirrored WITHOUT upstream signature verification: \`${SOURCE}\`" >> "$GITHUB_STEP_SUMMARY" + exit 0 + fi + cosign verify \ + --certificate-identity-regexp "$IDENTITY" \ + --certificate-oidc-issuer "$ISSUER" \ + "$SOURCE" + echo "Upstream signature verified: \`${SOURCE}\`" >> "$GITHUB_STEP_SUMMARY" + + - name: Configure AWS credentials (non-prod) + uses: aws-actions/configure-aws-credentials@ec61189d14ec14c8efccab744f656cffd0e33f37 # v6.1.0 + with: + role-to-assume: ${{ vars.VELOCITY_NON_PROD_ECR_PUBLISH_ROLE }} + role-session-name: gha-${{ github.run_id }} + aws-region: eu-west-1 + + - name: Log in to Amazon ECR (non-prod) + id: login-ecr + uses: aws-actions/amazon-ecr-login@19d944daaa35f0fa1d3f7f8af1d3f2e5de25c5b7 # v2.1.4 + + # crane copy is a pure registry-to-registry copy that cannot + # rewrite the manifest; the assertion turns any tool regression + # into a failed run instead of a silently different digest. + - name: Mirror image (non-prod, digest-preserving) + id: mirror + env: + SOURCE: ${{ inputs.source_image }} + DST: ${{ steps.login-ecr.outputs.registry }}/mirror/${{ inputs.name }} + TAG: ${{ inputs.image_tag }} + run: | + set -euo pipefail + digest="${SOURCE##*@}" + case "$digest" in + sha256:*) ;; + *) echo "::error::source_image must be pinned by digest (…@sha256:…): ${SOURCE}"; exit 1 ;; + esac + crane copy "${SOURCE}" "${DST}:${TAG}" + copied=$(crane digest "${DST}:${TAG}") + if [ "$copied" != "$digest" ]; then + echo "::error::mirrored tag ${TAG} points at ${copied}, expected source digest ${digest} — copy did not preserve the digest." + exit 1 + fi + echo "digest=${digest}" >> "$GITHUB_OUTPUT" + + - name: Sign image (non-prod) + env: + REF: ${{ steps.login-ecr.outputs.registry }}/mirror/${{ inputs.name }} + TAG: ${{ inputs.image_tag }} + DIGEST: ${{ steps.mirror.outputs.digest }} + run: | + set -euo pipefail + cosign sign --yes "${REF}@${DIGEST}" + echo "Signed \`${TAG}\` — gitops pin: \`${REF}:${TAG}@${DIGEST}\`" >> "$GITHUB_STEP_SUMMARY" + + - name: Configure AWS credentials (prod) + if: vars.VELOCITY_PROD_ECR_PUBLISH_ROLE != '' + uses: aws-actions/configure-aws-credentials@ec61189d14ec14c8efccab744f656cffd0e33f37 # v6.1.0 + with: + role-to-assume: ${{ vars.VELOCITY_PROD_ECR_PUBLISH_ROLE }} + role-session-name: gha-${{ github.run_id }} + aws-region: eu-west-1 + + - name: Log in to Amazon ECR (prod) + if: vars.VELOCITY_PROD_ECR_PUBLISH_ROLE != '' + id: login-ecr-prod + uses: aws-actions/amazon-ecr-login@19d944daaa35f0fa1d3f7f8af1d3f2e5de25c5b7 # v2.1.4 + + - name: Mirror image (prod, digest-preserving) + if: vars.VELOCITY_PROD_ECR_PUBLISH_ROLE != '' + env: + SOURCE: ${{ inputs.source_image }} + DST: ${{ steps.login-ecr-prod.outputs.registry }}/mirror/${{ inputs.name }} + TAG: ${{ inputs.image_tag }} + DIGEST: ${{ steps.mirror.outputs.digest }} + run: | + set -euo pipefail + crane copy "${SOURCE}" "${DST}:${TAG}" + copied=$(crane digest "${DST}:${TAG}") + if [ "$copied" != "$DIGEST" ]; then + echo "::error::prod tag ${TAG} points at ${copied}, expected ${DIGEST} — copy did not preserve the digest." + exit 1 + fi + + - name: Sign image (prod) + if: vars.VELOCITY_PROD_ECR_PUBLISH_ROLE != '' + run: cosign sign --yes "${{ steps.login-ecr-prod.outputs.registry }}/mirror/${{ inputs.name }}@${{ steps.mirror.outputs.digest }}" From a9860377c4102cc1a57c6a9db87857c53461f75f Mon Sep 17 00:00:00 2001 From: Chester Sim Date: Wed, 16 Sep 2026 16:19:00 +0800 Subject: [PATCH 4/4] fix(mirror-image): fail closed on half-set upstream verify; sign prod via env Two review findings, both flagged independently by the Opus and Codex review passes: - the upstream-verification guard skipped when EITHER identity or issuer was empty, so a caller that set one and typo'd the other got a green run with verification silently off. Skip only when both are empty; error when exactly one is set. - the prod signing step interpolated inputs.name straight into the run script, one step after the prod AWS credentials are configured. Pass it through env: and quote it, matching the non-prod signing step. --- .github/workflows/mirror-image.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/mirror-image.yml b/.github/workflows/mirror-image.yml index 8a32662..bb3933b 100644 --- a/.github/workflows/mirror-image.yml +++ b/.github/workflows/mirror-image.yml @@ -88,11 +88,17 @@ jobs: ISSUER: ${{ inputs.source_verify_issuer }} run: | set -euo pipefail - if [ -z "$IDENTITY" ] || [ -z "$ISSUER" ]; then + if [ -z "$IDENTITY" ] && [ -z "$ISSUER" ]; then echo "::warning::Upstream signature NOT verified for ${SOURCE} — source_verify_identity/issuer unset (upstream doesn't sign releases yet). The digest itself is still the reviewed pin." echo "⚠ Mirrored WITHOUT upstream signature verification: \`${SOURCE}\`" >> "$GITHUB_STEP_SUMMARY" exit 0 fi + # Half-configured is a caller mistake, not an unsigned + # upstream — fail closed rather than skipping silently. + if [ -z "$IDENTITY" ] || [ -z "$ISSUER" ]; then + echo "::error::source_verify_identity and source_verify_issuer must be set together (got identity='${IDENTITY}', issuer='${ISSUER}')." + exit 1 + fi cosign verify \ --certificate-identity-regexp "$IDENTITY" \ --certificate-oidc-issuer "$ISSUER" \ @@ -175,4 +181,9 @@ jobs: - name: Sign image (prod) if: vars.VELOCITY_PROD_ECR_PUBLISH_ROLE != '' - run: cosign sign --yes "${{ steps.login-ecr-prod.outputs.registry }}/mirror/${{ inputs.name }}@${{ steps.mirror.outputs.digest }}" + env: + REF: ${{ steps.login-ecr-prod.outputs.registry }}/mirror/${{ inputs.name }} + DIGEST: ${{ steps.mirror.outputs.digest }} + run: | + set -euo pipefail + cosign sign --yes "${REF}@${DIGEST}"