From f4d82237a04d368364a64b9fa11d2504696c151b Mon Sep 17 00:00:00 2001 From: Nikolai Emil Damm Date: Mon, 16 Nov 2026 18:32:59 +0100 Subject: [PATCH] fix(release): guard configuration publisher identities --- .github/scripts/check-manifests-caller.sh | 34 ++++++++ .../fixtures/manifests-caller-contract.sh | 9 +- .../fixtures/manifests-own-caller-contract.sh | 85 +++++++++++++++++++ .../tests/test-publish-manifests-promotion.sh | 23 ++--- 4 files changed, 132 insertions(+), 19 deletions(-) create mode 100644 .github/tests/fixtures/manifests-own-caller-contract.sh diff --git a/.github/scripts/check-manifests-caller.sh b/.github/scripts/check-manifests-caller.sh index 69486e14..8e018614 100644 --- a/.github/scripts/check-manifests-caller.sh +++ b/.github/scripts/check-manifests-caller.sh @@ -7,6 +7,40 @@ fail() { } [[ "$#" == 1 ]] || fail 'expected one caller workflow' caller="$1" +documents="$(yq -o=json -I=0 '.' "$caller")" || fail 'cannot read caller workflow' +# Preserve this boundary while the legacy publisher is still in use, before +# consumers begin trusting this workflow as a release signer. +jq -e -s 'length == 1 and (.[0].on == {"push":{"tags":["v*"]}})' \ + <<<"$documents" >/dev/null || fail 'expected the tag-only own-release signing contract' +if jq -e -s 'any(.[]; ((.jobs["publish-manifests"] // {}) | has("steps")))' <<<"$documents" >/dev/null; then + # This exact workflow is a platform-trusted signer. Making it callable would + # let another workflow obtain its identity, so admit only the release-tag path. + jq -e -s ' + length == 1 and + (.[0] | + ((keys - ["name", "on", "permissions", "jobs"]) | length == 0) and + .on == {"push":{"tags":["v*"]}} and + .permissions == {} and + (.jobs | keys) == ["publish-manifests"] and + (.jobs["publish-manifests"] | + ((keys - ["name", "runs-on", "timeout-minutes", "concurrency", "permissions", "steps"]) | length == 0) and + .["runs-on"] == "ubuntu-latest" and .["timeout-minutes"] == 60 and + .concurrency == {"group":"publish-verified-devantler-tech/github-config","queue":"max","cancel-in-progress":false} and + .permissions == {"contents":"read","packages":"write","id-token":"write"} and + (.steps | length == 3) and + all(.steps[]; ((keys - ["name", "uses", "with"]) | length == 0)) and + (.steps[0].uses | test("^step-security/harden-runner@[0-9a-f]{40}$")) and + .steps[0].with == {"egress-policy":"audit"} and + (.steps[1].uses | test("^actions/checkout@[0-9a-f]{40}$")) and + .steps[1].with == {"fetch-depth":0,"persist-credentials":false} and + .steps[2].uses == "$/actions/publish-app" and + .steps[2].with == {"mode":"manifests","oci-name":"devantler-tech/github-config"} + ) + ) + ' <<<"$documents" >/dev/null || fail 'expected the tag-only own-release signing contract' + echo 'ok configuration caller signs its own non-callable release tags with verified publication' + exit 0 +fi encoded_ref="$(yq -o=json -I=0 '.jobs["publish-manifests"].uses // ""' "$caller")" || fail 'cannot read publisher reference' ref_pattern='^"devantler-tech/\.github/\.github/workflows/publish-manifests\.yaml@([0-9a-f]{40})"$' diff --git a/.github/tests/fixtures/manifests-caller-contract.sh b/.github/tests/fixtures/manifests-caller-contract.sh index 3fae136b..1f8b2c3d 100644 --- a/.github/tests/fixtures/manifests-caller-contract.sh +++ b/.github/tests/fixtures/manifests-caller-contract.sh @@ -57,7 +57,11 @@ make_guard() { } make_guard "$work/unavailable" "$work/offline.sh" make_guard "file://$work/source" "$work/fetching.sh" -yq -o=json '.' "$root/.github/workflows/cd.yaml" >"$work/baseline.json" +# The reusable publisher retains its independent legacy admission contract even +# after this repository switches its live caller to its own release identity. +cat >"$work/baseline.json" <<'JSON' +{"on":{"push":{"tags":["v*"]}},"jobs":{"publish-manifests":{"with":{"enable-caller-pin":true,"enable-signed-promotion":true,"oci-name":"devantler-tech/github-config"}}}} +JSON prefix='devantler-tech/.github/.github/workflows/publish-manifests.yaml' mutate() { jq --arg prefix "$prefix" --arg reviewed "$reviewed" --arg release "$release" \ @@ -114,6 +118,8 @@ zero ref .jobs["publish-manifests"].uses=$prefix+"@00000000000000000000000000000 trailing newline .jobs["publish-manifests"].uses=$prefix+"@"+$reviewed+"\n" full immutable publisher reference lookalike owner .jobs["publish-manifests"].uses="outside/.github/.github/workflows/publish-manifests.yaml@"+$reviewed full immutable publisher reference lookalike path .jobs["publish-manifests"].uses="devantler-tech/.github/.github/workflows/publish-manifestsXyaml@"+$reviewed full immutable publisher reference +wrong workflow family .jobs["publish-manifests"].uses="devantler-tech/.github/.github/workflows/publish-app.yaml@"+$reviewed full immutable publisher reference +callable legacy caller .on.workflow_call={} tag-only own-release signing contract missing pin verification del(.jobs["publish-manifests"].with["enable-caller-pin"]) verified-promotion inputs disabled promotion .jobs["publish-manifests"].with["enable-signed-promotion"]=false verified-promotion inputs wrong artifact .jobs["publish-manifests"].with["oci-name"]="devantler-tech/other" verified-promotion inputs @@ -130,3 +136,4 @@ if run_guard "$work/fetching.sh" "$work/consumer" >"$work/result" 2>&1; then fi grep -qF 'unreviewed publisher content' "$work/result" || fail 'fetched content refusal had the wrong cause' echo 'ok caller requires explicit signer approval and reviewed contents, modes and safe inputs' +bash "$root/.github/tests/fixtures/manifests-own-caller-contract.sh" diff --git a/.github/tests/fixtures/manifests-own-caller-contract.sh b/.github/tests/fixtures/manifests-own-caller-contract.sh new file mode 100644 index 00000000..633d0e4c --- /dev/null +++ b/.github/tests/fixtures/manifests-own-caller-contract.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash +# Exercise the configuration publisher's own-release authority boundary. +# shellcheck disable=SC2016 # Literal GitHub expressions and jq variables. +set -euo pipefail +root="$(cd "$(dirname "$0")/../../.." && pwd)" +guard="$root/.github/scripts/check-manifests-caller.sh" +work="$(mktemp -d)" +trap 'rm -rf "$work"' EXIT +fail() { + echo "FAIL: own configuration caller: $*" >&2 + exit 1 +} +cat >"$work/own.yaml" <<'YAML' +name: Configuration release +on: + push: + tags: ["v*"] +permissions: {} +jobs: + publish-manifests: + runs-on: ubuntu-latest + timeout-minutes: 60 + concurrency: + group: publish-verified-devantler-tech/github-config + queue: max + cancel-in-progress: false + permissions: + contents: read + packages: write + id-token: write + steps: + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a + with: + egress-policy: audit + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + fetch-depth: 0 + persist-credentials: false + - uses: $/actions/publish-app + with: + mode: manifests + oci-name: devantler-tech/github-config +YAML +yq -o=json '.' "$work/own.yaml" >"$work/baseline.json" +bash "$guard" "$work/own.yaml" >"$work/result" 2>&1 || { + cat "$work/result" >&2 + fail 'rejected the tag-only own-release publisher' +} +while IFS=$'\t' read -r label mutation; do + jq "$mutation" "$work/baseline.json" >"$work/caller.json" + if bash "$guard" "$work/caller.json" >"$work/result" 2>&1; then fail "accepted $label"; fi + grep -qF 'own-release signing contract' "$work/result" || { + cat "$work/result" >&2 + fail "$label failed for the wrong reason" + } +done <<'CASES' +callable mapping .on.workflow_call={} +callable sequence .on=["push","workflow_call"] +callable scalar .on="workflow_call" +manual trigger .on.workflow_dispatch={} +branch trigger .on.push.branches=["main"] +all tags .on.push.tags=["*"] +workflow permission .permissions.contents="write" +job permission .jobs["publish-manifests"].permissions.contents="write" +extra job .jobs.other={"runs-on":"ubuntu-latest","steps":[{"run":"true"}]} +extra step .jobs["publish-manifests"].steps += [{"run":"true"}] +caller action replacement .jobs["publish-manifests"].steps[2].uses="outside/publish@main" +caller checkout replacement .jobs["publish-manifests"].steps[1].with.repository="outside/source" +mutable checkout .jobs["publish-manifests"].steps[1].with.ref="main" +persisted credential .jobs["publish-manifests"].steps[1].with["persist-credentials"]=true +wrong publication mode .jobs["publish-manifests"].steps[2].with.mode="deployment" +wrong artifact .jobs["publish-manifests"].steps[2].with["oci-name"]="devantler-tech/other" +different lock .jobs["publish-manifests"].concurrency.group="publish-devantler-tech/github-config" +replacing queue .jobs["publish-manifests"].concurrency.queue="single" +cancelling release .jobs["publish-manifests"].concurrency["cancel-in-progress"]=true +ambient environment .env.GITHUB_TOKEN="unexpected" +conditional publication .jobs["publish-manifests"].steps[2].if="false" +CASES +{ + cat "$work/own.yaml" + printf '\n---\n' + cat "$work/own.yaml" +} >"$work/multiple.yaml" +if bash "$guard" "$work/multiple.yaml" >"$work/result" 2>&1; then fail 'accepted multiple documents'; fi +echo 'ok own configuration publisher is tag-only, non-callable and bound to its own source and shared publication lock' diff --git a/.github/tests/test-publish-manifests-promotion.sh b/.github/tests/test-publish-manifests-promotion.sh index 45d7ce3a..34aa302c 100644 --- a/.github/tests/test-publish-manifests-promotion.sh +++ b/.github/tests/test-publish-manifests-promotion.sh @@ -2,12 +2,13 @@ # Exercise the shipped publication step against an offline registry boundary. # Signing/verification failure must not expose an unsigned semantic-version tag. set -euo pipefail -# The live configuration caller must opt in only through a SHA-pinned publisher. +# The live caller must satisfy its tag-only signing contract. Legacy reusable +# callers retain independently approved signer and publisher-content checks. validate_caller() { bash .github/scripts/check-manifests-caller.sh "$1" } validate_caller .github/workflows/cd.yaml || { - echo 'FAIL: configuration publication requires a SHA-pinned, verified-promotion caller' >&2 + echo 'FAIL: configuration publication requires the verified signing contract' >&2 exit 1 } bash .github/tests/fixtures/manifests-caller-contract.sh @@ -162,22 +163,8 @@ run_case none 1.2.3 "$default_mode" '' 123 || fail 'legacy default changed' echo 'ok default-off preserves existing callers; opted-in malformed identities fail before writes' echo 'ok default manifests latest is signed, stable-only and bound to the produced digest' -# Keep these controls in required CI, using the same predicate as the real caller. -for mutation in promotion pin moving family revision; do - fixture="$scratch/caller-$mutation.yaml" - cp .github/workflows/cd.yaml "$fixture" - case "$mutation" in - promotion) yq -i '.jobs["publish-manifests"].with["enable-signed-promotion"] = false' "$fixture" ;; - pin) yq -i '.jobs["publish-manifests"].with["enable-caller-pin"] = false' "$fixture" ;; - moving) yq -i '.jobs["publish-manifests"].uses |= sub("@[0-9a-f]{40}$"; "@main")' "$fixture" ;; - family) yq -i '.jobs["publish-manifests"].uses |= sub("publish-manifests"; "publish-app")' "$fixture" ;; - revision) yq -i '.jobs["publish-manifests"].uses |= sub("@[0-9a-f]{40}$"; "@0000000000000000000000000000000000000000")' "$fixture" ;; - esac - if validate_caller "$fixture" 2>/dev/null; then - fail "configuration caller accepted the $mutation regression" - fi -done -echo 'ok configuration caller refuses missing controls, moving refs and the wrong workflow family' +# The caller fixture above covers both signing families, including missing +# controls, moving refs, the wrong publisher, callable triggers and source swaps. if [[ "$#" == 0 ]]; then for mutation in early-version early-latest prerelease-latest mutable-alias; do