From adb3cb2626b3c4fade08f0291d4044aabbf47481 Mon Sep 17 00:00:00 2001 From: Nikolai Emil Damm Date: Sat, 14 Nov 2026 18:30:27 +0100 Subject: [PATCH 1/3] feat(publish-app): pin the app manifest in deploy/base when a product uses base/dev/prod overlays When /base exists, the publisher validates and pins the app container in base/deployment.yaml (prebuilt WebApp mode: base/webapp.yaml). Without a base entry the flat file and its checks are unchanged, so a pin bump is a no-op for flat layouts and can land before a product restructures. The validate step resolves the manifest once and hands the exact path to the pin step through a step output. The prebuilt helper extends its no-link directory walk to the base component. Publication fails before any registry write when a flat manifest sits beside base/, when base is a link or a file, when base/ lacks the manifest, or when that manifest is a link. The whole deploy-path directory remains the signed artifact. Closes #921 Co-Authored-By: Claude Opus 5.5 --- .github/agent-guides/validation.md | 6 +- .github/scripts/prepare-prebuilt-webapp.sh | 10 +- .github/tests/test-prebuilt-webapp.sh | 50 +++++++++ .github/tests/test-publish-preflight.sh | 119 +++++++++++++++++++++ .github/workflows/publish-app.yaml | 33 +++++- README.md | 8 +- 6 files changed, 217 insertions(+), 9 deletions(-) diff --git a/.github/agent-guides/validation.md b/.github/agent-guides/validation.md index 71b79dd6..7d2e1784 100644 --- a/.github/agent-guides/validation.md +++ b/.github/agent-guides/validation.md @@ -59,7 +59,11 @@ tagged source, public artifact digest and fixed caller CI identity. A private, incomplete, failed or changed attempt is unsupported. Do not accept an arbitrary image repository, signer or caller-provided source identity. Pin only the image of one source-owned WebApp whose name, namespace and spec name match the caller; -reject linked/special deployment files. This is not complete controller schema +reject linked/special deployment files. The app manifest rule is shared with +Deployment mode: when `/base` exists, only a regular +`base/webapp.yaml` (or `base/deployment.yaml`) in a regular directory is +accepted, and a flat manifest beside `base/` is ambiguous; without `base` the +flat file is unchanged. This is not complete controller schema validation. Sign and verify both promoted digests with all fourteen paired claims, retaining the original image provenance. Keep helper refusal/pinning, promotion mutation, native cryptographic and workflow-interface controls in diff --git a/.github/scripts/prepare-prebuilt-webapp.sh b/.github/scripts/prepare-prebuilt-webapp.sh index 081eb169..6a2bf029 100644 --- a/.github/scripts/prepare-prebuilt-webapp.sh +++ b/.github/scripts/prepare-prebuilt-webapp.sh @@ -43,7 +43,15 @@ for component in "${components[@]}"; do cursor="$cursor/$component" [[ -d "$cursor" && ! -L "$cursor" ]] || fail 'deployment directories must be regular source directories' done -file="$cursor/webapp.yaml" +# A deployment directory split into base/prod/dev overlays keeps the WebApp in base/. Without a +# base entry the flat layout is unchanged; a flat webapp.yaml beside base/ is ambiguous. +manifest_dir="$cursor" +if [[ -e "$cursor/base" || -L "$cursor/base" ]]; then + [[ -d "$cursor/base" && ! -L "$cursor/base" ]] || fail 'deployment directories must be regular source directories' + [[ ! -e "$cursor/webapp.yaml" && ! -L "$cursor/webapp.yaml" ]] || fail 'ambiguous WebApp manifest: webapp.yaml exists beside base/' + manifest_dir="$cursor/base" +fi +file="$manifest_dir/webapp.yaml" [[ -f "$file" && ! -L "$file" ]] || fail 'require a regular webapp.yaml' unsafe="$(find "$cursor" ! -type f ! -type d -print -quit)" || fail 'cannot inspect the complete deployment directory' [[ -z "$unsafe" ]] || fail 'deployment artifacts cannot contain linked or special files' diff --git a/.github/tests/test-prebuilt-webapp.sh b/.github/tests/test-prebuilt-webapp.sh index e1f85efc..b495a35d 100644 --- a/.github/tests/test-prebuilt-webapp.sh +++ b/.github/tests/test-prebuilt-webapp.sh @@ -354,4 +354,54 @@ reset_fixture ln -s "$work/run.json" "$work/deploy/unrelated.yaml" if invoke none > "$work/log" 2>&1; then fail 'accepted a linked file in the packaged deployment directory'; fi [[ ! -s "$work/output" && ! -s "$work/reads" ]] || fail 'linked deployment file reached verification' +rm "$work/deploy/unrelated.yaml" + +# A base/prod/dev overlay layout keeps the WebApp in base/; the flat layout above is unchanged. +reset_base_fixture() { + rm -rf "$work/deploy" "$work/shared-base" + mkdir -p "$work/deploy" + reset_fixture + mkdir -p "$work/deploy/base" "$work/deploy/prod" "$work/deploy/dev" + mv "$work/deploy/webapp.yaml" "$work/deploy/base/webapp.yaml" + printf 'resources: [webapp.yaml]\n' > "$work/deploy/base/kustomization.yaml" + printf 'resources: [../base]\n' > "$work/deploy/prod/kustomization.yaml" + printf 'resources: [../base]\n' > "$work/deploy/dev/kustomization.yaml" + printf 'resources: [prod]\n' > "$work/deploy/kustomization.yaml" +} +reset_base_fixture +invoke none > "$work/log" 2>&1 || fail "healthy base/prod/dev WebApp refused: $(cat "$work/log")" +yq -o=json -I=0 '.' "$work/deploy/base/webapp.yaml" | jq -s -e --arg image "ghcr.io/devantler-tech/app@$image_digest" ' + . == [ + {apiVersion:"v1",kind:"ConfigMap",metadata:{name:"unrelated"},data:{literal:"keep me"}}, + {apiVersion:"kro.run/v1alpha1",kind:"WebApp",metadata:{name:"app",namespace:"app"}, + spec:{name:"app",image:$image,host:"example.invalid"}} + ]' > /dev/null || fail 'did not pin only the selected image in base/webapp.yaml' +[[ ! -e "$work/deploy/webapp.yaml" ]] || fail 'base layout created a flat webapp.yaml' +grep -qx "digest=$image_digest" "$work/output" || fail 'base layout omitted the verified image output' +# Each ambiguous, linked or incomplete base layout is refused before any external observation +# and leaves every manifest unchanged. +for layout in both flat-beside-empty-base missing-file linked-base dangling-base base-file linked-file; do + reset_base_fixture + case "$layout" in + both) cp "$work/deploy/base/webapp.yaml" "$work/deploy/webapp.yaml" ;; + flat-beside-empty-base) mv "$work/deploy/base/webapp.yaml" "$work/deploy/webapp.yaml" ;; + missing-file) mv "$work/deploy/base/webapp.yaml" "$work/deploy/prod/webapp.yaml" ;; + linked-base) mv "$work/deploy/base" "$work/shared-base" && ln -s ../shared-base "$work/deploy/base" ;; + dangling-base) rm -rf "$work/deploy/base" && ln -s ../missing "$work/deploy/base" ;; + base-file) rm -rf "$work/deploy/base" && cp "$work/before.yaml" "$work/deploy/base" ;; + linked-file) mv "$work/deploy/base/webapp.yaml" "$work/deploy/prod/webapp.yaml" && + ln -s ../prod/webapp.yaml "$work/deploy/base/webapp.yaml" ;; + esac + find "$work/deploy" -type f -exec shasum {} + | sort > "$work/deploy-before.sums" + if invoke none > "$work/log" 2>&1; then fail "accepted base layout: $layout"; fi + [[ ! -s "$work/output" && ! -s "$work/reads" ]] || fail "base layout $layout reached verification" + case "$layout" in + both|flat-beside-empty-base) expected='ambiguous WebApp manifest' ;; + linked-base|dangling-base|base-file) expected='deployment directories must be regular source directories' ;; + missing-file|linked-file) expected='require a regular webapp.yaml' ;; + esac + grep -qF "$expected" "$work/log" || fail "base layout $layout refused for the wrong reason: $(grep '::error::' "$work/log")" + find "$work/deploy" -type f -exec shasum {} + | sort | cmp -s - "$work/deploy-before.sums" || + fail "refused base layout $layout changed manifests" +done echo 'prebuilt-webapp: real YAML pinning and source/CI/provenance/partial-observation refusals pass' diff --git a/.github/tests/test-publish-preflight.sh b/.github/tests/test-publish-preflight.sh index a9d7a268..e0089a9b 100755 --- a/.github/tests/test-publish-preflight.sh +++ b/.github/tests/test-publish-preflight.sh @@ -663,6 +663,125 @@ nothing_pushed "publish-app with an unparsable manifest" refused_with "publish-app with an unparsable manifest" "FAILED at 🔍 Validate the deployment manifest" echo "ok publish-app refuses a bad manifest before pushing anything" +# ---- 2b. publish-app: a base/prod/dev overlay layout keeps the app manifest in base/ ------------ + +new_base_app() { # [deploy dir] — the same app, split into base/prod/dev with the container in base/ + local deploy="$1/${2:-deploy}" + new_app "$1" + [[ "$deploy" == "$1/deploy" ]] || mv "$1/deploy" "$deploy" + mkdir -p "$deploy/base" "$deploy/prod" "$deploy/dev" + mv "$deploy/deployment.yaml" "$deploy/base/deployment.yaml" + printf 'resources: [deployment.yaml]\n' >"$deploy/base/kustomization.yaml" + printf 'resources: [../base]\n' >"$deploy/prod/kustomization.yaml" + printf 'resources: [../base]\n' >"$deploy/dev/kustomization.yaml" + printf 'resources: [prod]\n' >"$deploy/kustomization.yaml" +} + +# The flat layout resolves to the same file as before, and validation hands the pin that file. +wd="$scratch/app-flat" +new_app "$wd" +run_job "$app" publish "$wd" tag v1.2.3 app-name=app || + fail "publish-app failed a good flat release: $(cat "$log")" +grep -qxF 'manifest.file=./deploy/deployment.yaml' "$sim_outputs" || + fail "publish-app did not resolve the flat manifest; outputs: $(cat "$sim_outputs")" +grep -qF "flux push artifact oci://ghcr.io/devantler-tech/app/manifests:default-staging-123-2 --path=./deploy " "$calls" || + fail "publish-app no longer pushes the whole flat deploy-path; calls: $(cat "$calls")" +echo "ok publish-app resolves a flat layout to deploy-path/deployment.yaml, as before" + +for deploy in deploy k8s; do + wd="$scratch/app-base-$deploy" + new_base_app "$wd" "$deploy" + passed=(app-name=app) + [[ "$deploy" == deploy ]] || passed+=("deploy-path=./$deploy") + run_job "$app" publish "$wd" tag v1.2.3 "${passed[@]}" || + fail "publish-app failed a good base/prod/dev release in ./$deploy: $(cat "$log")" + grep -qxF "manifest.file=./$deploy/base/deployment.yaml" "$sim_outputs" || + fail "publish-app did not resolve the base manifest in ./$deploy; outputs: $(cat "$sim_outputs")" + pinned="$(yq '.spec.template.spec.containers[] | select(.name == "app") | .image' \ + "$wd/$deploy/base/deployment.yaml")" + [[ "$pinned" == "ghcr.io/devantler-tech/app@$image_digest" ]] || + fail "publish-app did not pin the built digest into ./$deploy/base/deployment.yaml; got: $pinned" + sidecar="$(yq '.spec.template.spec.containers[] | select(.name == "sidecar") | .image' \ + "$wd/$deploy/base/deployment.yaml")" + [[ "$sidecar" == "ghcr.io/devantler-tech/sidecar:1.0.0" ]] || fail "publish-app changed another container: $sidecar" + [[ ! -e "$wd/$deploy/deployment.yaml" ]] || fail "publish-app created a flat manifest beside base/" + grep -qF "flux push artifact oci://ghcr.io/devantler-tech/app/manifests:default-staging-123-2 --path=./$deploy " "$calls" || + fail "publish-app did not push the whole ./$deploy directory; calls: $(cat "$calls")" + [[ "$(head -n 1 "$calls")" == "image push 🐳 Build & push image" ]] || + fail "publish-app's first registry write is not the image push in the base layout" +done +echo "ok publish-app pins the app container in deploy-path/base/deployment.yaml and pushes the whole directory" + +# Every ambiguous or linked base layout is refused before the first registry write. +wd="$scratch/app-base-and-flat" +new_base_app "$wd" +cp "$wd/deploy/base/deployment.yaml" "$wd/deploy/deployment.yaml" +if run_job "$app" publish "$wd" tag v1.2.3 app-name=app; then + fail "publish-app accepted both a flat and a base app manifest" +fi +nothing_pushed "publish-app with both a flat and a base manifest" +refused_with "publish-app with both a flat and a base manifest" "ambiguous app manifest: ./deploy/deployment.yaml exists beside ./deploy/base" + +wd="$scratch/app-flat-and-empty-base" +new_app "$wd" +mkdir -p "$wd/deploy/base" +if run_job "$app" publish "$wd" tag v1.2.3 app-name=app; then + fail "publish-app accepted a flat app manifest beside a base directory" +fi +nothing_pushed "publish-app with a flat manifest beside base/" +refused_with "publish-app with a flat manifest beside base/" "ambiguous app manifest" + +wd="$scratch/app-base-without-file" +new_base_app "$wd" +mv "$wd/deploy/base/deployment.yaml" "$wd/deploy/prod/deployment.yaml" +if run_job "$app" publish "$wd" tag v1.2.3 app-name=app; then + fail "publish-app accepted a base directory without the app manifest" +fi +nothing_pushed "publish-app with a base directory that lacks the app manifest" +refused_with "publish-app with a base directory that lacks the app manifest" "manifest ./deploy/base/deployment.yaml not found" + +wd="$scratch/app-linked-base" +new_base_app "$wd" +mv "$wd/deploy/base" "$wd/shared-base" +ln -s ../shared-base "$wd/deploy/base" +if run_job "$app" publish "$wd" tag v1.2.3 app-name=app; then + fail "publish-app accepted a linked base directory" +fi +nothing_pushed "publish-app with a linked base directory" +refused_with "publish-app with a linked base directory" "./deploy/base must be a regular directory, not a link or a file" + +wd="$scratch/app-dangling-base" +new_app "$wd" +rm "$wd/deploy/deployment.yaml" +ln -s ../missing "$wd/deploy/base" +if run_job "$app" publish "$wd" tag v1.2.3 app-name=app; then + fail "publish-app accepted a dangling base link" +fi +nothing_pushed "publish-app with a dangling base link" +refused_with "publish-app with a dangling base link" "./deploy/base must be a regular directory" + +wd="$scratch/app-base-file" +new_app "$wd" +mv "$wd/deploy/deployment.yaml" "$wd/deploy/base" +if run_job "$app" publish "$wd" tag v1.2.3 app-name=app; then + fail "publish-app accepted a base file instead of a directory" +fi +nothing_pushed "publish-app with a base file" +refused_with "publish-app with a base file" "./deploy/base must be a regular directory" + +wd="$scratch/app-linked-base-manifest" +new_base_app "$wd" +mv "$wd/deploy/base/deployment.yaml" "$wd/deploy/prod/deployment.yaml" +ln -s ../prod/deployment.yaml "$wd/deploy/base/deployment.yaml" +if run_job "$app" publish "$wd" tag v1.2.3 app-name=app; then + fail "publish-app accepted a linked base app manifest" +fi +nothing_pushed "publish-app with a linked base app manifest" +refused_with "publish-app with a linked base app manifest" "manifest ./deploy/base/deployment.yaml must be a regular file, not a link" +[[ "$(yq '.spec.template.spec.containers[] | select(.name == "app") | .image' "$wd/deploy/prod/deployment.yaml")" == \ + "ghcr.io/devantler-tech/app:placeholder" ]] || fail "publish-app changed the target of a linked base manifest" +echo "ok publish-app refuses an ambiguous, linked or incomplete base layout before pushing anything" + # ---- 3. both workflows: only a complete semantic-version tag publishes -------------------------- # tag|published version. SemVer 2.0.0 examples, including its own edge cases. diff --git a/.github/workflows/publish-app.yaml b/.github/workflows/publish-app.yaml index bfe2ca5e..99b63d87 100644 --- a/.github/workflows/publish-app.yaml +++ b/.github/workflows/publish-app.yaml @@ -210,6 +210,7 @@ jobs: persist-credentials: false - name: 🔍 Validate the deployment manifest + id: manifest if: ${{ !inputs.enable-signed-recovery && !inputs.enable-prebuilt-webapp }} env: APP_NAME: ${{ inputs.app-name }} @@ -220,7 +221,23 @@ jobs: # to go with the image. Only the digest injection waits for the build, because the digest # does not exist before it. set -euo pipefail + # The app manifest is resolved once, here; the pin step reuses this exact path. A product + # that splits deploy-path into base/prod/dev overlays keeps the app container in base/. + # Without a base entry, the flat layout and its checks are unchanged. file="${DEPLOY_PATH}/deployment.yaml" + base="${DEPLOY_PATH}/base" + if [ -e "$base" ] || [ -L "$base" ]; then + if [ -L "$base" ] || [ ! -d "$base" ]; then + echo "::error::$base must be a regular directory, not a link or a file"; exit 1 + fi + if [ -e "$file" ] || [ -L "$file" ]; then + echo "::error::ambiguous app manifest: $file exists beside $base; keep only $base/deployment.yaml"; exit 1 + fi + file="$base/deployment.yaml" + if [ -L "$file" ]; then + echo "::error::manifest $file must be a regular file, not a link"; exit 1 + fi + fi if [ ! -f "$file" ]; then echo "::error::manifest $file not found (check the deploy-path input)"; exit 1 fi @@ -228,6 +245,10 @@ jobs: if [ "$matches" != "1" ]; then echo "::error::expected exactly one container named '$APP_NAME' in $file, found $matches"; exit 1 fi + case "$file" in + *$'\n'* | *$'\r'*) echo "::error::deploy-path must not contain a line break"; exit 1 ;; + esac + echo "file=$file" >> "$GITHUB_OUTPUT" # Installed before anything is pushed, so a failed download also fails the job while the # registry is still untouched. @@ -346,14 +367,18 @@ jobs: IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} DIGEST: ${{ steps.build.outputs.digest }} APP_NAME: ${{ inputs.app-name }} - DEPLOY_PATH: ${{ inputs.deploy-path }} + MANIFEST: ${{ steps.manifest.outputs.file }} run: | # The manifest was validated before the build; this step only injects the digest the build - # produced, and checks that the injection took. A registry reference must be lowercase, - # which is also how docker/metadata-action named the image it pushed. + # produced into the file that validation resolved, and checks that the injection took. A + # registry reference must be lowercase, which is also how docker/metadata-action named the + # image it pushed. set -euo pipefail IMAGE="$(printf '%s' "$IMAGE" | tr '[:upper:]' '[:lower:]')" - file="${DEPLOY_PATH}/deployment.yaml" + file="$MANIFEST" + if [ -z "$file" ]; then + echo "::error::the validation step did not resolve the app manifest"; exit 1 + fi if [ -z "$DIGEST" ]; then echo "::error::build did not produce an image digest"; exit 1 fi diff --git a/README.md b/README.md index ab7f3632..cb453d2c 100644 --- a/README.md +++ b/README.md @@ -633,11 +633,13 @@ jobs: packages: write # push image + manifests OCI artifact id-token: write # keyless cosign signing with: - app-name: my-app # container name in deploy/deployment.yaml + app-name: my-app # container name in deploy/deployment.yaml (or deploy/base/deployment.yaml) deploy-path: ./deploy # optional ``` -> **Note:** Must be invoked from a complete semantic-version tag (`vMAJOR.MINOR.PATCH`, optionally with `-PRERELEASE` and `+BUILD`) — Docker semver tagging and Flux `OCIRepository` semver selection depend on it. Anything else, such as `v1.2.3garbage` or a version whose numbers exceed 15 digits, is refused before publishing; build metadata is dropped from the published version because an OCI tag cannot carry `+`. The `app-name` container check on `deploy-path/deployment.yaml` also runs before anything is pushed, so a bad manifest leaves the registry untouched. The calling job must grant `packages: write` and `id-token: write` (and `contents: read` for checkout); no secrets are required (auth uses the GHCR-scoped `GITHUB_TOKEN`). +> **Note:** Must be invoked from a complete semantic-version tag (`vMAJOR.MINOR.PATCH`, optionally with `-PRERELEASE` and `+BUILD`) — Docker semver tagging and Flux `OCIRepository` semver selection depend on it. Anything else, such as `v1.2.3garbage` or a version whose numbers exceed 15 digits, is refused before publishing; build metadata is dropped from the published version because an OCI tag cannot carry `+`. The `app-name` container check on the app manifest also runs before anything is pushed, so a bad manifest leaves the registry untouched. The calling job must grant `packages: write` and `id-token: write` (and `contents: read` for checkout); no secrets are required (auth uses the GHCR-scoped `GITHUB_TOKEN`). +> +> **App manifest location:** the app manifest is `deploy-path/deployment.yaml` (`webapp.yaml` in prebuilt WebApp mode). A product that splits `deploy-path` into `base`, `prod` and `dev` kustomize overlays keeps it in `deploy-path/base/` instead: whenever `deploy-path/base` exists, only `base/deployment.yaml` (or `base/webapp.yaml`) is validated and pinned. Publication stops before any registry write when a flat manifest sits beside `base/`, when `base` is a link or a file, when `base/` lacks the manifest, or when that manifest is a link. The whole `deploy-path` directory is still the signed manifests artifact. #### Secrets and Inputs @@ -664,7 +666,7 @@ jobs: Enable `enable-prebuilt-webapp`, `enable-caller-pin` and `enable-signed-promotion` together to reuse the caller's tested image without a raw-source build. Supply all four prebuilt evidence inputs. The image must belong to the calling repository, with the same source commit as the release tag. Its original signer must be that repository's exact `.github/workflows/ci.yaml@refs/heads/main` identity. Complete public GitHub observations must establish successful main-push CI at the specified current attempt. Private or unreadable CI is not supported by this mode; it adds no token permissions. -Before any registry content write, Cosign verifies the original signature and SLSA source, subject, build, production-template profile, public digest and CI claims. A regular `webapp.yaml` in the bounded relative deployment directory must contain exactly one `kro.run/v1alpha1` WebApp. Its metadata name, namespace and spec name must equal `app-name`. Only its image is pinned; unrelated document values are preserved. Linked directories, linked files and special files are refused. This validates image selection, not the full Platform schema or controller behavior. +Before any registry content write, Cosign verifies the original signature and SLSA source, subject, build, production-template profile, public digest and CI claims. A regular `webapp.yaml` in the bounded relative deployment directory (in its regular `base/` subdirectory when one exists) must contain exactly one `kro.run/v1alpha1` WebApp. Its metadata name, namespace and spec name must equal `app-name`. Only its image is pinned; unrelated document values are preserved. Linked directories, linked files and special files are refused. This validates image selection, not the full Platform schema or controller behavior. The existing signed-promotion path then signs and verifies both unchanged digests with the paired publication claims plus the public digest, profile and original CI/producer binding. Stable/prerelease tag behavior is unchanged. Prebuilt recovery is unsupported: admission rejects the combined inputs, and legacy recovery independently refuses prebuilt-marked signatures even when the mode input is omitted. Original main-CI provenance remains attached to the image. Caller and Platform verifier adoption require a separately reviewed immutable publisher pin; no consumer is activated here. Rollout review and gate retirement are tracked in #684. From c40840c22ec0bc93955f7cf0d2661a420de6658b Mon Sep 17 00:00:00 2001 From: Nikolai Emil Damm Date: Sat, 14 Nov 2026 18:51:36 +0100 Subject: [PATCH 2/3] feat(publish-app): let callers name the app manifest inside the deploy path Replace the base/ auto-detection with an explicit optional app-manifest input, per the maintainer's decision: it supports future layouts without another publisher change. The value is a path relative to deploy-path; empty keeps deployment.yaml (webapp.yaml in prebuilt mode), so existing callers publish exactly as before. A named path must be plain components (no leading /, empty, ., .. or hidden component, no line break), reached through regular directories to a regular file. Deployment mode checks it once in the validation step and the pin reads that step's output; the prebuilt helper reuses its component walk for the manifest's directories and still scans the whole deploy-path for links. Every refusal happens before any registry write. Refs #921 Co-Authored-By: Claude Opus 5.5 --- .github/agent-guides/validation.md | 11 +- .github/scripts/prepare-prebuilt-webapp.sh | 40 +++-- .github/tests/test-prebuilt-webapp.sh | 109 +++++++----- .github/tests/test-publish-preflight.sh | 185 ++++++++++----------- .github/workflows/publish-app.yaml | 41 +++-- README.md | 8 +- 6 files changed, 215 insertions(+), 179 deletions(-) diff --git a/.github/agent-guides/validation.md b/.github/agent-guides/validation.md index 7d2e1784..688b3139 100644 --- a/.github/agent-guides/validation.md +++ b/.github/agent-guides/validation.md @@ -59,11 +59,12 @@ tagged source, public artifact digest and fixed caller CI identity. A private, incomplete, failed or changed attempt is unsupported. Do not accept an arbitrary image repository, signer or caller-provided source identity. Pin only the image of one source-owned WebApp whose name, namespace and spec name match the caller; -reject linked/special deployment files. The app manifest rule is shared with -Deployment mode: when `/base` exists, only a regular -`base/webapp.yaml` (or `base/deployment.yaml`) in a regular directory is -accepted, and a flat manifest beside `base/` is ambiguous; without `base` the -flat file is unchanged. This is not complete controller schema +reject linked/special deployment files. In both modes the optional +`app-manifest` input names the app manifest relative to `deploy-path`; empty +keeps `deployment.yaml` / `webapp.yaml`. A named path must be plain components +(no leading `/`, empty, `.`, `..` or hidden component, no line break) reached +through regular directories to a regular file, checked once before any registry +write; Deployment mode pins the path its validation step resolved. This is not complete controller schema validation. Sign and verify both promoted digests with all fourteen paired claims, retaining the original image provenance. Keep helper refusal/pinning, promotion mutation, native cryptographic and workflow-interface controls in diff --git a/.github/scripts/prepare-prebuilt-webapp.sh b/.github/scripts/prepare-prebuilt-webapp.sh index 6a2bf029..265afcfa 100644 --- a/.github/scripts/prepare-prebuilt-webapp.sh +++ b/.github/scripts/prepare-prebuilt-webapp.sh @@ -36,24 +36,30 @@ esac [[ -n "${GITHUB_OUTPUT:-}" ]] || fail 'missing workflow output file' path="${DEPLOY_PATH#./}" [[ -n "$path" && "$path" != /* && "$path" != */ && "$path" != *//* ]] || fail 'require a relative deployment directory' +# The WebApp manifest is named relative to the deployment directory; empty keeps webapp.yaml. +manifest="${APP_MANIFEST:-webapp.yaml}" +[[ "$manifest" != *$'\n'* && "$manifest" != *$'\r'* && "$manifest" != /* && "$manifest" != */ && "$manifest" != *//* ]] || + fail 'require a relative app manifest inside the deployment directory' +# Walk below the cursor one component at a time; every directory must be a regular source +# directory and no component may be `.`, `..`, hidden or unusual. +walk() { + local component components + IFS=/ read -r -a components <<< "$1" + for component in "${components[@]}"; do + [[ "$component" =~ ^[A-Za-z0-9_-][A-Za-z0-9_.-]*$ && "$component" != . && "$component" != .. ]] || fail "unsafe $2" + cursor="$cursor/$component" + [[ -d "$cursor" && ! -L "$cursor" ]] || fail 'deployment directories must be regular source directories' + done +} cursor=. -IFS=/ read -r -a components <<< "$path" -for component in "${components[@]}"; do - [[ "$component" =~ ^[A-Za-z0-9_-][A-Za-z0-9_.-]*$ && "$component" != . && "$component" != .. ]] || fail 'unsafe deployment directory' - cursor="$cursor/$component" - [[ -d "$cursor" && ! -L "$cursor" ]] || fail 'deployment directories must be regular source directories' -done -# A deployment directory split into base/prod/dev overlays keeps the WebApp in base/. Without a -# base entry the flat layout is unchanged; a flat webapp.yaml beside base/ is ambiguous. -manifest_dir="$cursor" -if [[ -e "$cursor/base" || -L "$cursor/base" ]]; then - [[ -d "$cursor/base" && ! -L "$cursor/base" ]] || fail 'deployment directories must be regular source directories' - [[ ! -e "$cursor/webapp.yaml" && ! -L "$cursor/webapp.yaml" ]] || fail 'ambiguous WebApp manifest: webapp.yaml exists beside base/' - manifest_dir="$cursor/base" -fi -file="$manifest_dir/webapp.yaml" -[[ -f "$file" && ! -L "$file" ]] || fail 'require a regular webapp.yaml' -unsafe="$(find "$cursor" ! -type f ! -type d -print -quit)" || fail 'cannot inspect the complete deployment directory' +walk "$path" 'deployment directory' +deploy_dir="$cursor" +manifest_name="${manifest##*/}" +[[ "$manifest_name" =~ ^[A-Za-z0-9_-][A-Za-z0-9_.-]*$ ]] || fail 'unsafe app manifest path' +[[ "$manifest" == "$manifest_name" ]] || walk "${manifest%/*}" 'app manifest path' +file="$cursor/$manifest_name" +[[ -f "$file" && ! -L "$file" ]] || fail "require a regular $manifest" +unsafe="$(find "$deploy_dir" ! -type f ! -type d -print -quit)" || fail 'cannot inspect the complete deployment directory' [[ -z "$unsafe" ]] || fail 'deployment artifacts cannot contain linked or special files' work="$(mktemp -d)" trap 'rm -rf "$work"' EXIT diff --git a/.github/tests/test-prebuilt-webapp.sh b/.github/tests/test-prebuilt-webapp.sh index b495a35d..7a57beda 100644 --- a/.github/tests/test-prebuilt-webapp.sh +++ b/.github/tests/test-prebuilt-webapp.sh @@ -26,6 +26,7 @@ yq -o=json '.' "$workflow" | jq -e ' .env == { REPOSITORY:"${{ github.repository }}",SOURCE_SHA:"${{ github.sha }}", APP_NAME:"${{ inputs.app-name }}",DEPLOY_PATH:"${{ inputs.deploy-path }}", + APP_MANIFEST:"${{ inputs.app-manifest }}", PREBUILT_IMAGE_DIGEST:"${{ inputs.prebuilt-image-digest }}", PREBUILT_PUBLIC_DIGEST:"${{ inputs.prebuilt-public-digest }}", PREBUILT_CI_RUN_ID:"${{ inputs.prebuilt-ci-run-id }}", @@ -356,52 +357,76 @@ if invoke none > "$work/log" 2>&1; then fail 'accepted a linked file in the pack [[ ! -s "$work/output" && ! -s "$work/reads" ]] || fail 'linked deployment file reached verification' rm "$work/deploy/unrelated.yaml" -# A base/prod/dev overlay layout keeps the WebApp in base/; the flat layout above is unchanged. -reset_base_fixture() { - rm -rf "$work/deploy" "$work/shared-base" +# app-manifest names the WebApp manifest inside the deployment directory; omitted, webapp.yaml is +# used as above, even beside a base/ copy. +reset_split_fixture() { # — the healthy WebApp moved to deploy/ + rm -rf "$work/deploy" "$work/outside" "$work/outside.yaml" "$work/webapp.yaml" mkdir -p "$work/deploy" reset_fixture - mkdir -p "$work/deploy/base" "$work/deploy/prod" "$work/deploy/dev" - mv "$work/deploy/webapp.yaml" "$work/deploy/base/webapp.yaml" - printf 'resources: [webapp.yaml]\n' > "$work/deploy/base/kustomization.yaml" - printf 'resources: [../base]\n' > "$work/deploy/prod/kustomization.yaml" - printf 'resources: [../base]\n' > "$work/deploy/dev/kustomization.yaml" + mkdir -p "$(dirname "$work/deploy/$1")" + [[ "$1" == webapp.yaml ]] || mv "$work/deploy/webapp.yaml" "$work/deploy/$1" + cp "$work/deploy/$1" "$work/before.yaml" printf 'resources: [prod]\n' > "$work/deploy/kustomization.yaml" } -reset_base_fixture -invoke none > "$work/log" 2>&1 || fail "healthy base/prod/dev WebApp refused: $(cat "$work/log")" -yq -o=json -I=0 '.' "$work/deploy/base/webapp.yaml" | jq -s -e --arg image "ghcr.io/devantler-tech/app@$image_digest" ' - . == [ - {apiVersion:"v1",kind:"ConfigMap",metadata:{name:"unrelated"},data:{literal:"keep me"}}, - {apiVersion:"kro.run/v1alpha1",kind:"WebApp",metadata:{name:"app",namespace:"app"}, - spec:{name:"app",image:$image,host:"example.invalid"}} - ]' > /dev/null || fail 'did not pin only the selected image in base/webapp.yaml' -[[ ! -e "$work/deploy/webapp.yaml" ]] || fail 'base layout created a flat webapp.yaml' -grep -qx "digest=$image_digest" "$work/output" || fail 'base layout omitted the verified image output' -# Each ambiguous, linked or incomplete base layout is refused before any external observation -# and leaves every manifest unchanged. -for layout in both flat-beside-empty-base missing-file linked-base dangling-base base-file linked-file; do - reset_base_fixture - case "$layout" in - both) cp "$work/deploy/base/webapp.yaml" "$work/deploy/webapp.yaml" ;; - flat-beside-empty-base) mv "$work/deploy/base/webapp.yaml" "$work/deploy/webapp.yaml" ;; - missing-file) mv "$work/deploy/base/webapp.yaml" "$work/deploy/prod/webapp.yaml" ;; - linked-base) mv "$work/deploy/base" "$work/shared-base" && ln -s ../shared-base "$work/deploy/base" ;; - dangling-base) rm -rf "$work/deploy/base" && ln -s ../missing "$work/deploy/base" ;; - base-file) rm -rf "$work/deploy/base" && cp "$work/before.yaml" "$work/deploy/base" ;; - linked-file) mv "$work/deploy/base/webapp.yaml" "$work/deploy/prod/webapp.yaml" && - ln -s ../prod/webapp.yaml "$work/deploy/base/webapp.yaml" ;; - esac - find "$work/deploy" -type f -exec shasum {} + | sort > "$work/deploy-before.sums" - if invoke none > "$work/log" 2>&1; then fail "accepted base layout: $layout"; fi - [[ ! -s "$work/output" && ! -s "$work/reads" ]] || fail "base layout $layout reached verification" - case "$layout" in - both|flat-beside-empty-base) expected='ambiguous WebApp manifest' ;; - linked-base|dangling-base|base-file) expected='deployment directories must be regular source directories' ;; - missing-file|linked-file) expected='require a regular webapp.yaml' ;; +pinned_only() { # — the selected image is pinned and every other document value is kept + yq -o=json -I=0 '.' "$1" | jq -s -e --arg image "ghcr.io/devantler-tech/app@$image_digest" ' + . == [ + {apiVersion:"v1",kind:"ConfigMap",metadata:{name:"unrelated"},data:{literal:"keep me"}}, + {apiVersion:"kro.run/v1alpha1",kind:"WebApp",metadata:{name:"app",namespace:"app"}, + spec:{name:"app",image:$image,host:"example.invalid"}} + ]' > /dev/null +} +reset_split_fixture webapp.yaml +mkdir -p "$work/deploy/base" +cp "$work/before.yaml" "$work/deploy/base/webapp.yaml" +invoke none > "$work/log" 2>&1 || fail "flat WebApp beside base/ refused: $(cat "$work/log")" +pinned_only "$work/deploy/webapp.yaml" || fail 'default did not pin the flat webapp.yaml' +cmp -s "$work/before.yaml" "$work/deploy/base/webapp.yaml" || fail 'default pinned a base/ manifest nobody named' +for manifest in base/webapp.yaml overlays/base/webapp.yaml app.yaml; do + reset_split_fixture "$manifest" + invoke none APP_MANIFEST="$manifest" > "$work/log" 2>&1 || fail "healthy WebApp at $manifest refused: $(cat "$work/log")" + pinned_only "$work/deploy/$manifest" || fail "did not pin only the selected image in $manifest" + [[ "$manifest" == app.yaml || ! -e "$work/deploy/webapp.yaml" ]] || fail "$manifest created a flat webapp.yaml" + grep -qx "digest=$image_digest" "$work/output" || fail "$manifest omitted the verified image output" +done +# Unsafe, linked or missing app-manifest values are refused before any external observation and +# change no file. A valid WebApp sits wherever each path would lead. +for case in \ + '../webapp.yaml|unsafe app manifest path' \ + '/webapp.yaml|require a relative app manifest inside the deployment directory' \ + 'base/./webapp.yaml|unsafe app manifest path' \ + 'base/../webapp.yaml|unsafe app manifest path' \ + 'base//webapp.yaml|require a relative app manifest inside the deployment directory' \ + 'base/|require a relative app manifest inside the deployment directory' \ + '.hidden/webapp.yaml|unsafe app manifest path' \ + "base/webapp.yaml"$'\n'"x|require a relative app manifest inside the deployment directory" \ + "base/webapp.yaml"$'\r'"|require a relative app manifest inside the deployment directory" \ + 'linked-dir|deployment directories must be regular source directories' \ + 'linked-file|require a regular base/webapp.yaml' \ + 'missing|require a regular base/webapp.yaml' \ + 'linked-sibling|deployment artifacts cannot contain linked or special files'; do + manifest="${case%%|*}" + expected="${case#*|}" + reset_split_fixture base/webapp.yaml + cp "$work/before.yaml" "$work/deploy/webapp.yaml" + cp "$work/before.yaml" "$work/webapp.yaml" + mkdir -p "$work/deploy/.hidden" + cp "$work/before.yaml" "$work/deploy/.hidden/webapp.yaml" + case "$manifest" in + linked-dir) mv "$work/deploy/base" "$work/outside" && ln -s ../outside "$work/deploy/base" ;; + linked-file) mv "$work/deploy/base/webapp.yaml" "$work/outside.yaml" && + ln -s ../../outside.yaml "$work/deploy/base/webapp.yaml" ;; + missing) rm "$work/deploy/base/webapp.yaml" ;; + # The whole packaged directory is scanned, not only the named manifest's directory. + linked-sibling) mkdir -p "$work/deploy/prod" && ln -s ../../run.json "$work/deploy/prod/linked.yaml" ;; esac - grep -qF "$expected" "$work/log" || fail "base layout $layout refused for the wrong reason: $(grep '::error::' "$work/log")" - find "$work/deploy" -type f -exec shasum {} + | sort | cmp -s - "$work/deploy-before.sums" || - fail "refused base layout $layout changed manifests" + case "$manifest" in linked-dir | linked-file | missing | linked-sibling) manifest=base/webapp.yaml ;; esac + find "$work" -type f -name '*webapp.yaml' -exec shasum {} + | sort > "$work/sums-before" + [[ -s "$work/sums-before" ]] || fail 'the refusal fixture has no manifests to compare' + if invoke none APP_MANIFEST="$manifest" > "$work/log" 2>&1; then fail "accepted app-manifest: $manifest"; fi + [[ ! -s "$work/output" && ! -s "$work/reads" ]] || fail "app-manifest $manifest reached verification" + grep -qF "$expected" "$work/log" || fail "app-manifest $manifest refused for the wrong reason: $(grep '::error::' "$work/log")" + find "$work" -type f -name '*webapp.yaml' -exec shasum {} + | sort | cmp -s - "$work/sums-before" || + fail "refused app-manifest $manifest changed manifests" done echo 'prebuilt-webapp: real YAML pinning and source/CI/provenance/partial-observation refusals pass' diff --git a/.github/tests/test-publish-preflight.sh b/.github/tests/test-publish-preflight.sh index e0089a9b..55b54e39 100755 --- a/.github/tests/test-publish-preflight.sh +++ b/.github/tests/test-publish-preflight.sh @@ -663,124 +663,115 @@ nothing_pushed "publish-app with an unparsable manifest" refused_with "publish-app with an unparsable manifest" "FAILED at 🔍 Validate the deployment manifest" echo "ok publish-app refuses a bad manifest before pushing anything" -# ---- 2b. publish-app: a base/prod/dev overlay layout keeps the app manifest in base/ ------------ +# ---- 2b. publish-app: the app-manifest input names the app manifest inside deploy-path ---------- -new_base_app() { # [deploy dir] — the same app, split into base/prod/dev with the container in base/ - local deploy="$1/${2:-deploy}" +new_split_app() { # — the same app with its Deployment moved to deploy/ new_app "$1" - [[ "$deploy" == "$1/deploy" ]] || mv "$1/deploy" "$deploy" - mkdir -p "$deploy/base" "$deploy/prod" "$deploy/dev" - mv "$deploy/deployment.yaml" "$deploy/base/deployment.yaml" - printf 'resources: [deployment.yaml]\n' >"$deploy/base/kustomization.yaml" - printf 'resources: [../base]\n' >"$deploy/prod/kustomization.yaml" - printf 'resources: [../base]\n' >"$deploy/dev/kustomization.yaml" - printf 'resources: [prod]\n' >"$deploy/kustomization.yaml" + mkdir -p "$(dirname "$1/deploy/$2")" + mv "$1/deploy/deployment.yaml" "$1/deploy/$2" + printf 'resources: [prod]\n' >"$1/deploy/kustomization.yaml" } -# The flat layout resolves to the same file as before, and validation hands the pin that file. +# Without the input the flat file is resolved, checked and pinned exactly as before, even beside a +# base/ directory, and validation hands the pin that file. wd="$scratch/app-flat" new_app "$wd" +mkdir -p "$wd/deploy/base" +cp "$wd/deploy/deployment.yaml" "$wd/deploy/base/deployment.yaml" run_job "$app" publish "$wd" tag v1.2.3 app-name=app || fail "publish-app failed a good flat release: $(cat "$log")" grep -qxF 'manifest.file=./deploy/deployment.yaml' "$sim_outputs" || fail "publish-app did not resolve the flat manifest; outputs: $(cat "$sim_outputs")" +[[ "$(yq '.spec.template.spec.containers[] | select(.name == "app") | .image' "$wd/deploy/deployment.yaml")" == \ + "ghcr.io/devantler-tech/app@$image_digest" ]] || fail "publish-app did not pin the flat manifest by default" +[[ "$(yq '.spec.template.spec.containers[] | select(.name == "app") | .image' "$wd/deploy/base/deployment.yaml")" == \ + "ghcr.io/devantler-tech/app:placeholder" ]] || fail "publish-app pinned a base/ manifest nobody named" grep -qF "flux push artifact oci://ghcr.io/devantler-tech/app/manifests:default-staging-123-2 --path=./deploy " "$calls" || fail "publish-app no longer pushes the whole flat deploy-path; calls: $(cat "$calls")" -echo "ok publish-app resolves a flat layout to deploy-path/deployment.yaml, as before" - -for deploy in deploy k8s; do - wd="$scratch/app-base-$deploy" - new_base_app "$wd" "$deploy" - passed=(app-name=app) +echo "ok publish-app resolves deploy-path/deployment.yaml without app-manifest, as before" + +for case in "deploy|base/deployment.yaml" "deploy|overlays/base/deployment.yaml" "deploy|app.yaml" "k8s|base/deployment.yaml"; do + deploy="${case%%|*}" + manifest="${case#*|}" + wd="$scratch/app-input-$deploy-${manifest//\//-}" + new_split_app "$wd" "$manifest" + [[ "$deploy" == deploy ]] || mv "$wd/deploy" "$wd/$deploy" + passed=(app-name=app "app-manifest=$manifest") [[ "$deploy" == deploy ]] || passed+=("deploy-path=./$deploy") run_job "$app" publish "$wd" tag v1.2.3 "${passed[@]}" || - fail "publish-app failed a good base/prod/dev release in ./$deploy: $(cat "$log")" - grep -qxF "manifest.file=./$deploy/base/deployment.yaml" "$sim_outputs" || - fail "publish-app did not resolve the base manifest in ./$deploy; outputs: $(cat "$sim_outputs")" - pinned="$(yq '.spec.template.spec.containers[] | select(.name == "app") | .image' \ - "$wd/$deploy/base/deployment.yaml")" + fail "publish-app failed a good release with app-manifest=$manifest in ./$deploy: $(cat "$log")" + grep -qxF "manifest.file=./$deploy/$manifest" "$sim_outputs" || + fail "publish-app did not resolve ./$deploy/$manifest; outputs: $(cat "$sim_outputs")" + pinned="$(yq '.spec.template.spec.containers[] | select(.name == "app") | .image' "$wd/$deploy/$manifest")" [[ "$pinned" == "ghcr.io/devantler-tech/app@$image_digest" ]] || - fail "publish-app did not pin the built digest into ./$deploy/base/deployment.yaml; got: $pinned" - sidecar="$(yq '.spec.template.spec.containers[] | select(.name == "sidecar") | .image' \ - "$wd/$deploy/base/deployment.yaml")" + fail "publish-app did not pin the built digest into ./$deploy/$manifest; got: $pinned" + sidecar="$(yq '.spec.template.spec.containers[] | select(.name == "sidecar") | .image' "$wd/$deploy/$manifest")" [[ "$sidecar" == "ghcr.io/devantler-tech/sidecar:1.0.0" ]] || fail "publish-app changed another container: $sidecar" - [[ ! -e "$wd/$deploy/deployment.yaml" ]] || fail "publish-app created a flat manifest beside base/" + [[ "$manifest" == app.yaml || ! -e "$wd/$deploy/deployment.yaml" ]] || fail "publish-app created a flat manifest" grep -qF "flux push artifact oci://ghcr.io/devantler-tech/app/manifests:default-staging-123-2 --path=./$deploy " "$calls" || fail "publish-app did not push the whole ./$deploy directory; calls: $(cat "$calls")" [[ "$(head -n 1 "$calls")" == "image push 🐳 Build & push image" ]] || - fail "publish-app's first registry write is not the image push in the base layout" + fail "publish-app's first registry write is not the image push with app-manifest=$manifest" +done +echo "ok publish-app validates and pins the app-manifest it is given and pushes the whole deploy-path" + +# An unsafe, linked or missing app-manifest is refused before the first registry write. Each case +# keeps a valid Deployment where the path would lead, so only the input check can refuse it. +plain='app-manifest must be a relative path of plain names inside deploy-path' +for case in \ + "../deployment.yaml|$plain" \ + "/deployment.yaml|$plain" \ + "base/./deployment.yaml|$plain" \ + "base/../deployment.yaml|$plain" \ + "base//deployment.yaml|$plain" \ + "base/|$plain" \ + ".hidden/deployment.yaml|$plain" \ + "linked-dir|app-manifest base/deployment.yaml passes through a link at ./deploy/base" \ + "linked-file|app-manifest base/deployment.yaml passes through a link at ./deploy/base/deployment.yaml" \ + "missing|manifest ./deploy/base/deployment.yaml not found"; do + manifest="${case%%|*}" + expected="${case#*|}" + wd="$scratch/app-refused" + rm -rf "$wd" + new_split_app "$wd" base/deployment.yaml + cp "$wd/deploy/base/deployment.yaml" "$wd/deploy/deployment.yaml" + cp "$wd/deploy/base/deployment.yaml" "$wd/deployment.yaml" + mkdir -p "$wd/deploy/.hidden" + cp "$wd/deploy/base/deployment.yaml" "$wd/deploy/.hidden/deployment.yaml" + case "$manifest" in + linked-dir) mv "$wd/deploy/base" "$wd/outside" && ln -s ../outside "$wd/deploy/base" ;; + linked-file) mv "$wd/deploy/base/deployment.yaml" "$wd/outside.yaml" && + ln -s ../../outside.yaml "$wd/deploy/base/deployment.yaml" ;; + missing) rm "$wd/deploy/base/deployment.yaml" ;; + esac + case "$manifest" in linked-dir | linked-file | missing) manifest=base/deployment.yaml ;; esac + if run_job "$app" publish "$wd" tag v1.2.3 app-name=app "app-manifest=$manifest"; then + fail "publish-app accepted app-manifest '$manifest' ($expected)" + fi + nothing_pushed "publish-app with app-manifest '$manifest'" + refused_with "publish-app with app-manifest '$manifest'" "$expected" + refused_with "publish-app with app-manifest '$manifest'" "FAILED at 🔍 Validate the deployment manifest" + ! grep -rqF "@$image_digest" "$wd" || fail "publish-app pinned a file for a refused app-manifest '$manifest'" done -echo "ok publish-app pins the app container in deploy-path/base/deployment.yaml and pushes the whole directory" - -# Every ambiguous or linked base layout is refused before the first registry write. -wd="$scratch/app-base-and-flat" -new_base_app "$wd" -cp "$wd/deploy/base/deployment.yaml" "$wd/deploy/deployment.yaml" -if run_job "$app" publish "$wd" tag v1.2.3 app-name=app; then - fail "publish-app accepted both a flat and a base app manifest" -fi -nothing_pushed "publish-app with both a flat and a base manifest" -refused_with "publish-app with both a flat and a base manifest" "ambiguous app manifest: ./deploy/deployment.yaml exists beside ./deploy/base" - -wd="$scratch/app-flat-and-empty-base" -new_app "$wd" -mkdir -p "$wd/deploy/base" -if run_job "$app" publish "$wd" tag v1.2.3 app-name=app; then - fail "publish-app accepted a flat app manifest beside a base directory" -fi -nothing_pushed "publish-app with a flat manifest beside base/" -refused_with "publish-app with a flat manifest beside base/" "ambiguous app manifest" - -wd="$scratch/app-base-without-file" -new_base_app "$wd" -mv "$wd/deploy/base/deployment.yaml" "$wd/deploy/prod/deployment.yaml" -if run_job "$app" publish "$wd" tag v1.2.3 app-name=app; then - fail "publish-app accepted a base directory without the app manifest" -fi -nothing_pushed "publish-app with a base directory that lacks the app manifest" -refused_with "publish-app with a base directory that lacks the app manifest" "manifest ./deploy/base/deployment.yaml not found" - -wd="$scratch/app-linked-base" -new_base_app "$wd" -mv "$wd/deploy/base" "$wd/shared-base" -ln -s ../shared-base "$wd/deploy/base" -if run_job "$app" publish "$wd" tag v1.2.3 app-name=app; then - fail "publish-app accepted a linked base directory" -fi -nothing_pushed "publish-app with a linked base directory" -refused_with "publish-app with a linked base directory" "./deploy/base must be a regular directory, not a link or a file" - -wd="$scratch/app-dangling-base" -new_app "$wd" -rm "$wd/deploy/deployment.yaml" -ln -s ../missing "$wd/deploy/base" -if run_job "$app" publish "$wd" tag v1.2.3 app-name=app; then - fail "publish-app accepted a dangling base link" -fi -nothing_pushed "publish-app with a dangling base link" -refused_with "publish-app with a dangling base link" "./deploy/base must be a regular directory" - -wd="$scratch/app-base-file" -new_app "$wd" -mv "$wd/deploy/deployment.yaml" "$wd/deploy/base" -if run_job "$app" publish "$wd" tag v1.2.3 app-name=app; then - fail "publish-app accepted a base file instead of a directory" -fi -nothing_pushed "publish-app with a base file" -refused_with "publish-app with a base file" "./deploy/base must be a regular directory" -wd="$scratch/app-linked-base-manifest" -new_base_app "$wd" -mv "$wd/deploy/base/deployment.yaml" "$wd/deploy/prod/deployment.yaml" -ln -s ../prod/deployment.yaml "$wd/deploy/base/deployment.yaml" -if run_job "$app" publish "$wd" tag v1.2.3 app-name=app; then - fail "publish-app accepted a linked base app manifest" -fi -nothing_pushed "publish-app with a linked base app manifest" -refused_with "publish-app with a linked base app manifest" "manifest ./deploy/base/deployment.yaml must be a regular file, not a link" -[[ "$(yq '.spec.template.spec.containers[] | select(.name == "app") | .image' "$wd/deploy/prod/deployment.yaml")" == \ - "ghcr.io/devantler-tech/app:placeholder" ]] || fail "publish-app changed the target of a linked base manifest" -echo "ok publish-app refuses an ambiguous, linked or incomplete base layout before pushing anything" +# A line break cannot be passed through the simulated caller, so run the shipped validation step on +# its own: it refuses the input without echoing it, and resolves no manifest for the pin. +validate="$(yq -r '.jobs.publish.steps[] | select(.id == "manifest") | .run' "$app")" +[[ -n "$validate" ]] || fail "publish-app has no validation step with id manifest" +wd="$scratch/app-line-break" +rm -rf "$wd" +new_split_app "$wd" base/deployment.yaml +for manifest in $'base/deployment.yaml\n::error::injected' $'base/deployment.yaml\r' $'\nbase/deployment.yaml'; do + : >"$scratch/direct-output" + if (cd "$wd" && env -i PATH="$PATH" APP_NAME=app DEPLOY_PATH=./deploy APP_MANIFEST="$manifest" \ + GITHUB_OUTPUT="$scratch/direct-output" bash --noprofile --norc -e -c "$validate") >"$scratch/direct.log" 2>&1; then + fail "publish-app accepted an app-manifest with a line break" + fi + grep -qF "$plain" "$scratch/direct.log" || fail "line break refused for the wrong reason: $(cat "$scratch/direct.log")" + ! grep -qF 'injected' "$scratch/direct.log" || fail "publish-app echoed an unchecked app-manifest" + [[ ! -s "$scratch/direct-output" ]] || fail "a refused app-manifest still resolved a manifest for the pin" +done +echo "ok publish-app refuses an unsafe, linked or missing app-manifest before pushing anything" # ---- 3. both workflows: only a complete semantic-version tag publishes -------------------------- diff --git a/.github/workflows/publish-app.yaml b/.github/workflows/publish-app.yaml index 99b63d87..d92ab2ea 100644 --- a/.github/workflows/publish-app.yaml +++ b/.github/workflows/publish-app.yaml @@ -11,6 +11,11 @@ on: required: false default: ./deploy type: string + app-manifest: + description: "Path, relative to deploy-path, of the manifest holding the app: the Deployment with the app-name container, or the WebApp in prebuilt mode. Empty means deployment.yaml (webapp.yaml in prebuilt mode)." + required: false + default: "" + type: string dry-run: description: "Skip publish (validate workflow interface only)." required: false @@ -215,31 +220,36 @@ jobs: env: APP_NAME: ${{ inputs.app-name }} DEPLOY_PATH: ${{ inputs.deploy-path }} + APP_MANIFEST: ${{ inputs.app-manifest }} run: | # Every manifest check runs here, before anything reaches the registry. A release that fails # after the image push leaves GHCR changed — `latest` included — with no deployable manifest # to go with the image. Only the digest injection waits for the build, because the digest # does not exist before it. set -euo pipefail - # The app manifest is resolved once, here; the pin step reuses this exact path. A product - # that splits deploy-path into base/prod/dev overlays keeps the app container in base/. - # Without a base entry, the flat layout and its checks are unchanged. + export LC_ALL=C + # The app manifest is resolved once, here; the pin step reuses this exact path. Without + # app-manifest it is deploy-path/deployment.yaml, checked as it always was. file="${DEPLOY_PATH}/deployment.yaml" - base="${DEPLOY_PATH}/base" - if [ -e "$base" ] || [ -L "$base" ]; then - if [ -L "$base" ] || [ ! -d "$base" ]; then - echo "::error::$base must be a regular directory, not a link or a file"; exit 1 - fi - if [ -e "$file" ] || [ -L "$file" ]; then - echo "::error::ambiguous app manifest: $file exists beside $base; keep only $base/deployment.yaml"; exit 1 - fi - file="$base/deployment.yaml" - if [ -L "$file" ]; then - echo "::error::manifest $file must be a regular file, not a link"; exit 1 + if [ -n "$APP_MANIFEST" ]; then + # A caller-named manifest is plain names below deploy-path: no leading /, no empty, `.` + # or `..` component, no line break. No component may be a link, so the file cannot leave + # deploy-path. The input is not echoed until it has passed this check. + name='[A-Za-z0-9_-][A-Za-z0-9_.-]*' + if ! [[ "$APP_MANIFEST" =~ ^${name}(/${name})*$ ]]; then + echo "::error::app-manifest must be a relative path of plain names inside deploy-path (letters, digits, '.', '_' and '-'; no leading '/', no empty, '.' or '..' component)"; exit 1 fi + file="$DEPLOY_PATH" + IFS=/ read -r -a components <<< "$APP_MANIFEST" + for component in "${components[@]}"; do + file="$file/$component" + if [ -L "$file" ]; then + echo "::error::app-manifest $APP_MANIFEST passes through a link at $file"; exit 1 + fi + done fi if [ ! -f "$file" ]; then - echo "::error::manifest $file not found (check the deploy-path input)"; exit 1 + echo "::error::manifest $file not found (check the deploy-path and app-manifest inputs)"; exit 1 fi matches=$(yq '[.spec.template.spec.containers[] | select(.name == strenv(APP_NAME))] | length' "$file") if [ "$matches" != "1" ]; then @@ -294,6 +304,7 @@ jobs: SOURCE_SHA: ${{ github.sha }} APP_NAME: ${{ inputs.app-name }} DEPLOY_PATH: ${{ inputs.deploy-path }} + APP_MANIFEST: ${{ inputs.app-manifest }} PREBUILT_IMAGE_DIGEST: ${{ inputs.prebuilt-image-digest }} PREBUILT_PUBLIC_DIGEST: ${{ inputs.prebuilt-public-digest }} PREBUILT_CI_RUN_ID: ${{ inputs.prebuilt-ci-run-id }} diff --git a/README.md b/README.md index cb453d2c..d994921f 100644 --- a/README.md +++ b/README.md @@ -633,13 +633,14 @@ jobs: packages: write # push image + manifests OCI artifact id-token: write # keyless cosign signing with: - app-name: my-app # container name in deploy/deployment.yaml (or deploy/base/deployment.yaml) + app-name: my-app # container name in the app manifest deploy-path: ./deploy # optional + app-manifest: base/deployment.yaml # optional; default deployment.yaml (webapp.yaml in prebuilt mode) ``` > **Note:** Must be invoked from a complete semantic-version tag (`vMAJOR.MINOR.PATCH`, optionally with `-PRERELEASE` and `+BUILD`) — Docker semver tagging and Flux `OCIRepository` semver selection depend on it. Anything else, such as `v1.2.3garbage` or a version whose numbers exceed 15 digits, is refused before publishing; build metadata is dropped from the published version because an OCI tag cannot carry `+`. The `app-name` container check on the app manifest also runs before anything is pushed, so a bad manifest leaves the registry untouched. The calling job must grant `packages: write` and `id-token: write` (and `contents: read` for checkout); no secrets are required (auth uses the GHCR-scoped `GITHUB_TOKEN`). > -> **App manifest location:** the app manifest is `deploy-path/deployment.yaml` (`webapp.yaml` in prebuilt WebApp mode). A product that splits `deploy-path` into `base`, `prod` and `dev` kustomize overlays keeps it in `deploy-path/base/` instead: whenever `deploy-path/base` exists, only `base/deployment.yaml` (or `base/webapp.yaml`) is validated and pinned. Publication stops before any registry write when a flat manifest sits beside `base/`, when `base` is a link or a file, when `base/` lacks the manifest, or when that manifest is a link. The whole `deploy-path` directory is still the signed manifests artifact. +> **App manifest location:** the app manifest is `deploy-path/deployment.yaml` (`webapp.yaml` in prebuilt WebApp mode) unless `app-manifest` names another file, relative to `deploy-path`. A product that splits `deploy-path` into kustomize overlays sets it, for example to `base/deployment.yaml`, in the same change that moves the file. The value must be plain names joined by `/` (letters, digits, `.`, `_` and `-`; no leading `/`, no empty, `.` or `..` component, no line break), and no directory on the way or the file itself may be a link. Anything else, or a missing file, stops publication before any registry write. The whole `deploy-path` directory is still the signed manifests artifact. #### Secrets and Inputs @@ -647,6 +648,7 @@ jobs: |---------------|----------------|------------|----------|----------------------------------------------------------------------------| | `app-name` | Input (string) | - | Yes | Deployment container name, or the matching WebApp metadata name/namespace and spec name | | `deploy-path` | Input (string) | `./deploy` | No | Path to the Kubernetes manifests directory packaged as the OCI artifact | +| `app-manifest` | Input (string) | empty | No | Path, relative to `deploy-path`, of the manifest holding the app (the Deployment, or the WebApp in prebuilt mode). Empty means `deployment.yaml` (`webapp.yaml` in prebuilt mode) | | `dry-run` | Input (boolean) | `false` | No | Skip publication and validate only the workflow interface | | `enable-caller-pin` | Input (boolean) | `true` | No | Require a 40-character commit-SHA caller before signing. The authenticated OIDC calling ref is the certificate identity. Explicit false remains supported during caller cleanup in #284 | | `enable-signed-promotion` | Input (boolean) | `false` | No | Verify both signature identities and paired publication claims before exposing version tags, then move latest only for stable releases. Requires `enable-caller-pin`; rollout is tracked in #371 | @@ -666,7 +668,7 @@ jobs: Enable `enable-prebuilt-webapp`, `enable-caller-pin` and `enable-signed-promotion` together to reuse the caller's tested image without a raw-source build. Supply all four prebuilt evidence inputs. The image must belong to the calling repository, with the same source commit as the release tag. Its original signer must be that repository's exact `.github/workflows/ci.yaml@refs/heads/main` identity. Complete public GitHub observations must establish successful main-push CI at the specified current attempt. Private or unreadable CI is not supported by this mode; it adds no token permissions. -Before any registry content write, Cosign verifies the original signature and SLSA source, subject, build, production-template profile, public digest and CI claims. A regular `webapp.yaml` in the bounded relative deployment directory (in its regular `base/` subdirectory when one exists) must contain exactly one `kro.run/v1alpha1` WebApp. Its metadata name, namespace and spec name must equal `app-name`. Only its image is pinned; unrelated document values are preserved. Linked directories, linked files and special files are refused. This validates image selection, not the full Platform schema or controller behavior. +Before any registry content write, Cosign verifies the original signature and SLSA source, subject, build, production-template profile, public digest and CI claims. A regular `webapp.yaml` in the bounded relative deployment directory (or the file `app-manifest` names inside it, reached only through regular directories) must contain exactly one `kro.run/v1alpha1` WebApp. Its metadata name, namespace and spec name must equal `app-name`. Only its image is pinned; unrelated document values are preserved. Linked directories, linked files and special files are refused. This validates image selection, not the full Platform schema or controller behavior. The existing signed-promotion path then signs and verifies both unchanged digests with the paired publication claims plus the public digest, profile and original CI/producer binding. Stable/prerelease tag behavior is unchanged. Prebuilt recovery is unsupported: admission rejects the combined inputs, and legacy recovery independently refuses prebuilt-marked signatures even when the mode input is omitted. Original main-CI provenance remains attached to the image. Caller and Platform verifier adoption require a separately reviewed immutable publisher pin; no consumer is activated here. Rollout review and gate retirement are tracked in #684. From 4f3c5ac16e73e2d73e082e31ddd9c486e5628917 Mon Sep 17 00:00:00 2001 From: Nikolai Emil Damm Date: Sat, 14 Nov 2026 22:27:23 +0100 Subject: [PATCH 3/3] fix(publish-app): refuse a linked deploy-path before resolving app-manifest A deploy-path that is itself a link (or passes through one) could carry a caller-named manifest outside the deploy tree; the image would push before publication refused the linked directory. Check every deploy-path ancestor first, with a refusal fixture that requires zero registry writes. Co-Authored-By: Claude Opus 5.5 --- .github/tests/test-publish-preflight.sh | 4 +++- .github/workflows/publish-app.yaml | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/tests/test-publish-preflight.sh b/.github/tests/test-publish-preflight.sh index 55b54e39..ca41632c 100755 --- a/.github/tests/test-publish-preflight.sh +++ b/.github/tests/test-publish-preflight.sh @@ -728,6 +728,7 @@ for case in \ ".hidden/deployment.yaml|$plain" \ "linked-dir|app-manifest base/deployment.yaml passes through a link at ./deploy/base" \ "linked-file|app-manifest base/deployment.yaml passes through a link at ./deploy/base/deployment.yaml" \ + "linked-deploy|deploy-path ./deploy passes through a link at ./deploy" \ "missing|manifest ./deploy/base/deployment.yaml not found"; do manifest="${case%%|*}" expected="${case#*|}" @@ -742,9 +743,10 @@ for case in \ linked-dir) mv "$wd/deploy/base" "$wd/outside" && ln -s ../outside "$wd/deploy/base" ;; linked-file) mv "$wd/deploy/base/deployment.yaml" "$wd/outside.yaml" && ln -s ../../outside.yaml "$wd/deploy/base/deployment.yaml" ;; + linked-deploy) mv "$wd/deploy" "$wd/manifests" && ln -s manifests "$wd/deploy" ;; missing) rm "$wd/deploy/base/deployment.yaml" ;; esac - case "$manifest" in linked-dir | linked-file | missing) manifest=base/deployment.yaml ;; esac + case "$manifest" in linked-dir | linked-file | linked-deploy | missing) manifest=base/deployment.yaml ;; esac if run_job "$app" publish "$wd" tag v1.2.3 app-name=app "app-manifest=$manifest"; then fail "publish-app accepted app-manifest '$manifest' ($expected)" fi diff --git a/.github/workflows/publish-app.yaml b/.github/workflows/publish-app.yaml index d92ab2ea..5016d5d1 100644 --- a/.github/workflows/publish-app.yaml +++ b/.github/workflows/publish-app.yaml @@ -239,6 +239,16 @@ jobs: if ! [[ "$APP_MANIFEST" =~ ^${name}(/${name})*$ ]]; then echo "::error::app-manifest must be a relative path of plain names inside deploy-path (letters, digits, '.', '_' and '-'; no leading '/', no empty, '.' or '..' component)"; exit 1 fi + # deploy-path and each of its ancestors must not be a link either: a linked deploy + # directory would carry the named manifest outside the deploy tree just the same. + prefix="${DEPLOY_PATH%/}" + while [ -n "$prefix" ]; do + if [ -L "$prefix" ]; then + echo "::error::deploy-path $DEPLOY_PATH passes through a link at $prefix"; exit 1 + fi + [[ "$prefix" == */* ]] || break + prefix="${prefix%/*}" + done file="$DEPLOY_PATH" IFS=/ read -r -a components <<< "$APP_MANIFEST" for component in "${components[@]}"; do