Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/agent-guides/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +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. 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
Expand Down
32 changes: 23 additions & 9 deletions .github/scripts/prepare-prebuilt-webapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +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 <path> 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
file="$cursor/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
Expand Down
75 changes: 75 additions & 0 deletions .github/tests/test-prebuilt-webapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}",
Expand Down Expand Up @@ -354,4 +355,78 @@ 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"

# 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() { # <app-manifest> — the healthy WebApp moved to deploy/<app-manifest>
rm -rf "$work/deploy" "$work/outside" "$work/outside.yaml" "$work/webapp.yaml"
mkdir -p "$work/deploy"
reset_fixture
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"
}
pinned_only() { # <file> — 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
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'
112 changes: 112 additions & 0 deletions .github/tests/test-publish-preflight.sh
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,118 @@ 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: the app-manifest input names the app manifest inside deploy-path ----------

new_split_app() { # <dir> <app-manifest> — the same app with its Deployment moved to deploy/<app-manifest>
new_app "$1"
mkdir -p "$(dirname "$1/deploy/$2")"
mv "$1/deploy/deployment.yaml" "$1/deploy/$2"
printf 'resources: [prod]\n' >"$1/deploy/kustomization.yaml"
}

# 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 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 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/$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"
[[ "$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 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" \
"linked-deploy|deploy-path ./deploy passes through a link at ./deploy" \
"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" ;;
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 | 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
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

# 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 --------------------------

# tag|published version. SemVer 2.0.0 examples, including its own edge cases.
Expand Down
Loading
Loading