Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(nginx): one grep scanner and a shared release policy for the image guard

Alfredo Lopezffd80d5f47b7
diff --git a/nginx-egress-proxy/README.md b/nginx-egress-proxy/README.md
index f86fec69a..ebc994c45 100644
--- a/nginx-egress-proxy/README.md
+++ b/nginx-egress-proxy/README.md
@@ -9,12 +9,13 @@ lives in [host-context-controller](../host-context-controller/) (`src/reconciler
## The image
-- Base: `nginx:1.30.6-alpine`, pinned by multi-arch index digest — kept because
- its entrypoint runs `envsubst` on `/etc/nginx/templates/*.template` at
- startup, which HCC relies on for credential injection. 1.30.6 is the stable
- release that fixes CVE-2026-15176, CVE-2026-93479, CVE-2026-95101,
- CVE-2026-97629 and CVE-2026-97205; `scripts/validate-nginx-images.sh`
- rejects older platform references.
+- Base: the official `nginx:<x.y.z>-alpine` image named by the `FROM` line of
+ the [Dockerfile](./Dockerfile), pinned by multi-arch index digest. It is kept
+ because its entrypoint runs `envsubst` on `/etc/nginx/templates/*.template`
+ at startup, which HCC relies on for credential injection. The minimum NGINX
+ release per line, and the CVEs behind it, are in
+ [scripts/nginx-image-policy.sh](../scripts/nginx-image-policy.sh);
+ `scripts/validate-nginx-images.sh` rejects older platform references.
- Hardened to run as non-root (`USER 101:101`): the `user` directive is removed
from `nginx.conf`, the PID file moves to `/tmp/nginx.pid`, the shipped
`default.conf` is removed, and nginx dirs plus `/tmp` temp dirs are chowned
@@ -87,6 +88,26 @@ against a local TLS upstream: a trusted chain (direct and with two
intermediates) is accepted; an untrusted CA, an expired certificate, a hostname
mismatch, and the test CA without the mounted trust store are rejected.
+## Updating NGINX
+
+A newer fixed release on an accepted line (for example 1.30.6 → 1.30.7):
+
+1. Resolve the index digest of the new tag:
+ `docker buildx imagetools inspect nginx:<x.y.z>-alpine` (the `Digest:` line).
+2. Replace the old tag everywhere it is written (`git grep -n 'nginx:<old>-alpine'`):
+ `FIXED_NGINX_IMAGE` in `scripts/validate-nginx-images.sh`, the Dockerfile
+ `FROM` (tag and digest), the four gateway manifests under `deploy/base`,
+ `scripts/minikube/build-images.sh` and `scripts/bootstrap-cluster.sh`.
+3. Run `bash scripts/validate-nginx-images.sh`,
+ `bash scripts/tests/test-validate-nginx-images.sh` and
+ `bash scripts/verify-nginx-image-digests.sh`.
+
+No test or CI file changes for such a bump. When a new CVE raises the minimum,
+also edit `NGINX_RELEASE_FLOORS` and its CVE comment in
+`scripts/nginx-image-policy.sh`, the floor cases in
+`scripts/tests/test-validate-nginx-images.sh`, and every reference the
+validator then reports as below the new floor.
+
## Build & deploy
CI builds and publishes the image via
diff --git a/scripts/nginx-image-policy.sh b/scripts/nginx-image-policy.sh
new file mode 100755
index 000000000..6146f2c7c
--- /dev/null
+++ b/scripts/nginx-image-policy.sh
@@ -0,0 +1,88 @@
+# shellcheck shell=bash
+# NGINX image policy shared by scripts/validate-nginx-images.sh (tags in the
+# tree) and scripts/verify-nginx-image-digests.sh (digests in the registry).
+# Source it; it defines data and functions only.
+#
+# NGINX_RELEASE_FLOORS holds, per release line, the first release that fixes
+# CVE-2026-15176, CVE-2026-93479, CVE-2026-95101, CVE-2026-97629 and
+# CVE-2026-97205 (and the older CVE-2026-42945). A release on a listed line
+# must be at or above that line's floor; a line newer than the last entry is
+# accepted; any other line is rejected. Raise a floor here when a new CVE
+# requires it.
+NGINX_RELEASE_FLOORS=(1.30.6 1.31.7 1.32.0)
+
+BASELINE_TEXT=""
+for _floor in "${NGINX_RELEASE_FLOORS[@]}"; do
+ BASELINE_TEXT="${BASELINE_TEXT:+$BASELINE_TEXT, }$_floor (${_floor%.*} line)"
+done
+BASELINE_TEXT="$BASELINE_TEXT or a newer line"
+unset _floor
+
+# Prints why an x.y.z[-suffix] tag is not acceptable; prints nothing if it is.
+nginx_tag_problem() {
+ local tag="$1" major minor patch floor floor_major floor_minor floor_patch
+ if ! [[ "$tag" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(-[[:alnum:]_.-]+)?$ ]]; then
+ echo "tag '$tag' is not a fixed x.y.z release"
+ return
+ fi
+ major=$((10#${BASH_REMATCH[1]}))
+ minor=$((10#${BASH_REMATCH[2]}))
+ patch=$((10#${BASH_REMATCH[3]}))
+ for floor in "${NGINX_RELEASE_FLOORS[@]}"; do
+ IFS=. read -r floor_major floor_minor floor_patch <<<"$floor"
+ if [ "$major" -eq "$floor_major" ] && [ "$minor" -eq "$floor_minor" ]; then
+ [ "$patch" -ge "$floor_patch" ] && return
+ echo "release $major.$minor.$patch is below $BASELINE_TEXT"
+ return
+ fi
+ done
+ # Not on a listed line: accepted only when newer than the last listed line.
+ if [ "$major" -gt "$floor_major" ] || { [ "$major" -eq "$floor_major" ] && [ "$minor" -gt "$floor_minor" ]; }; then
+ return
+ fi
+ echo "release $major.$minor.$patch is below $BASELINE_TEXT"
+}
+
+# Splits [registry/]name[:tag][@digest] into the globals ref_tag, ref_digest
+# and ref_at (1 when the reference has an '@', even with nothing after it).
+split_ref() {
+ local last="${1##*/}" rest
+ rest="${last#"${last%%[:@]*}"}"
+ ref_tag=""
+ ref_digest=""
+ ref_at=0
+ case "$rest" in
+ :*@*) ref_tag="${rest#:}"; ref_tag="${ref_tag%%@*}"; ref_digest="${rest#*@}"; ref_at=1 ;;
+ :*) ref_tag="${rest#:}" ;;
+ @*) ref_digest="${rest#@}"; ref_at=1 ;;
+ esac
+}
+
+# Prints why an NGINX reference is not acceptable; prints nothing if it is.
+nginx_ref_problem() {
+ split_ref "$1"
+ if [ "$ref_at" -eq 1 ] && [ -z "$ref_digest" ]; then
+ echo "'@' without a digest"
+ return
+ fi
+ if [ -n "$ref_digest" ]; then
+ if [ -z "$ref_tag" ]; then
+ echo "digest without a version tag (write nginx:<x.y.z>[-suffix]@sha256:...)"
+ return
+ fi
+ if ! [[ "$ref_digest" =~ ^sha256:[0-9a-f]{64}$ ]]; then
+ echo "malformed digest '$ref_digest'"
+ return
+ fi
+ fi
+ nginx_tag_problem "$ref_tag"
+}
+
+# Any image named nginx or nginxinc/nginx-unprivileged, under any registry
+# path, is treated as upstream NGINX and held to the floors.
+is_nginx_name() {
+ case "$1" in
+ nginx | */nginx | nginxinc/nginx-unprivileged | */nginxinc/nginx-unprivileged) return 0 ;;
+ esac
+ return 1
+}
diff --git a/scripts/tests/test-validate-nginx-images.sh b/scripts/tests/test-validate-nginx-images.sh
index 33660c1e6..7c165c0ac 100755
--- a/scripts/tests/test-validate-nginx-images.sh
+++ b/scripts/tests/test-validate-nginx-images.sh
@@ -4,17 +4,21 @@
# reference in both image families and names the file and line that carry it,
# accepts the fixed releases (with or without a digest), checks kustomize
# images: entries, enforces the pinned egress-proxy FROM line, fails on a
-# missing scan path, and reports a failed scan.
+# missing scan path or an empty scan scope, and reports a failed scan.
#
# The validator runs on a copy of the files it reads, so injected cases never
# touch the checkout. Every injected case writes into a path the validator
# scans. Every rejection must name that path; every accepted injection must
-# raise the validator's reference count by one, which proves the injected
-# reference was read rather than skipped.
+# raise the validator's reference count by the number of references it adds,
+# which proves the injected reference was read rather than skipped.
+#
+# Tree values (the release floors, the Dockerfile pin) are read from the
+# policy file and the Dockerfile, so a routine NGINX bump needs no edit here.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
VALIDATOR_REL="scripts/validate-nginx-images.sh"
+POLICY_REL="scripts/nginx-image-policy.sh"
WORK="$(mktemp -d)"
trap 'chmod -R u+rwX "$WORK" 2>/dev/null; rm -rf "$WORK"' EXIT
COPY="$WORK/repo"
@@ -23,18 +27,18 @@ failures=0
cases=0
baseline_refs=""
+# shellcheck source=scripts/nginx-image-policy.sh
+source "$REPO_ROOT/$POLICY_REL"
+
# The scan list the validator must carry. A path dropped from, or added to,
# the validator fails here until this list is updated with it.
EXPECTED_SCAN_PATHS="deploy
host-context-controller/src/config.ts
-host-context-controller/src/__tests__/reconciler.remote.test.ts
-host-context-controller/src/__tests__/reconciler.sanitize.test.ts
control-api/src/routes/admin/registry.ts
control-api/src/routes/admin/remoteMcp.ts
nginx-egress-proxy/Dockerfile
control-ui/e2e/registry-install.spec.ts
control-ui/e2e/qa-recorder-recipe-scope-copy.spec.ts
-control-ui/components/__tests__/RegistryCatalog.test.tsx
desktop-app/test/e2e-playwright/sandbox-ui-apps-catalog-authz.test.ts
scripts/minikube/build-images.sh
scripts/bootstrap-cluster.sh
@@ -42,12 +46,11 @@ scripts/e2e
docs/deploy/workflow-recipes-guide.md
docs/agents/CLERUM_WORKFLOW_RECIPE_GUIDE.md
workflow-recipes/samples
-workflow-recipes/src
tests/e2e/integration/control-api-k8s.test.ts
tests/e2e/playwright/control-ui/recipes.spec.ts
+tests/e2e/playwright/control-ui/recipe-scope-copy.spec.ts
tests/e2e/playwright/control-ui/workflow-recipe-egressbindings.spec.ts
-workflow-recipes/tests/e2e
-workflow-recipes/tests/fixtures/workflow/invalid-scheduling-no-steps.yaml"
+workflow-recipes/tests/e2e"
fail() {
echo "FAIL: $*" >&2
@@ -55,15 +58,15 @@ fail() {
}
validator_scan_paths() {
- sed -n '/^scan_paths=(/,/^)/p' "$REPO_ROOT/$VALIDATOR_REL" | sed -n 's/^[[:space:]]*"\([^"]*\)"$/\1/p'
+ sed -n '/^scan_paths=(/,/^)/p' "$1" | sed -n 's/^[[:space:]]*"\([^"]*\)"$/\1/p'
}
-# Copy the validator and every path it scans or requires, read from the
-# validator itself so the copy cannot drift from what it checks.
+# Copy the validator, its policy file and every path it scans or requires,
+# read from the validator itself so the copy cannot drift from what it checks.
copy_inputs() {
local paths p
paths="$(
- validator_scan_paths
+ validator_scan_paths "$REPO_ROOT/$VALIDATOR_REL"
sed -n 's/^require_[a-z_]* "\([^"]*\)".*/\1/p' "$REPO_ROOT/$VALIDATOR_REL"
)"
if [ -z "$paths" ]; then
@@ -72,6 +75,11 @@ copy_inputs() {
fi
mkdir -p "$COPY/scripts"
cp "$REPO_ROOT/$VALIDATOR_REL" "$COPY/$VALIDATOR_REL"
+ cp "$REPO_ROOT/$POLICY_REL" "$COPY/$POLICY_REL"
+ if [ ! -s "$COPY/$POLICY_REL" ]; then
+ echo "FAIL: the copy has no $POLICY_REL" >&2
+ exit 1
+ fi
while IFS= read -r p; do
if [ ! -e "$REPO_ROOT/$p" ]; then
echo "FAIL: $VALIDATOR_REL names $p, which does not exist in the repository" >&2
@@ -83,19 +91,19 @@ copy_inputs() {
}
run_validator() {
- PATH="$1" bash "$COPY/$VALIDATOR_REL" "${@:2}" >"$OUT" 2>&1
+ bash "$COPY/$VALIDATOR_REL" "$@" >"$OUT" 2>&1
}
reported_refs() {
sed -n 's/^OK -- .*(\([0-9][0-9]*\) references checked)$/\1/p' "$OUT"
}
-# expect_pass PATH NAME [EXTRA_REFS]: the validator passes, prints the OK line,
-# and reports the baseline reference count plus EXTRA_REFS.
+# expect_pass NAME [EXTRA_REFS]: the validator passes, prints the OK line, and
+# reports the baseline reference count plus EXTRA_REFS.
expect_pass() {
- local scanner_path="$1" name="$2" extra="${3:-0}" got
+ local name="$1" extra="${2:-0}" got
cases=$((cases + 1))
- if ! run_validator "$scanner_path"; then
+ if ! run_validator; then
fail "$name should pass: $(cat "$OUT")"
return
fi
@@ -107,11 +115,13 @@ expect_pass() {
fi
}
+# expect_fail_naming NAME EXPECTED...: the validator fails and its output holds
+# every EXPECTED string.
expect_fail_naming() {
- local scanner_path="$1" name="$2" expected
- shift 2
+ local name="$1" expected
+ shift
cases=$((cases + 1))
- if run_validator "$scanner_path"; then
+ if run_validator; then
fail "$name should fail: $(cat "$OUT")"
return
fi
@@ -122,211 +132,284 @@ expect_fail_naming() {
done
}
-# Scanned by the validator only since the October 2026 baseline: the whole
-# recipe samples directory, scripts/e2e, all of deploy/ and the deploying
-# E2E specs.
SAMPLE_REL="workflow-recipes/samples/zz-injected-nginx.yaml"
E2E_REL="scripts/e2e/zz-injected-nginx.sh"
+E2E_DOCKERFILE_REL="scripts/e2e/zz-injected-nginx.Dockerfile"
+HIDDEN_REL="deploy/.zz-injected-hidden.yaml"
REMOTE_MCP_REL="control-api/src/routes/admin/remoteMcp.ts"
DOCKERFILE_REL="nginx-egress-proxy/Dockerfile"
-KUSTOMIZE_REL="deploy/overlays/zz-injected/kustomization.yaml"
-FIXED_DIGEST="sha256:c59d1f8b1e0e42da75be973424cd72e23f7f8adfb54e982f4d1cd0216a5a5576"
+KUSTOMIZE_DIR="deploy/overlays/zz-injected"
+KUSTOMIZE_REL="$KUSTOMIZE_DIR/kustomization.yaml"
+FIXED_PIN="$(sed -n 's/^FROM //p' "$REPO_ROOT/$DOCKERFILE_REL")"
+FIXED_DIGEST="${FIXED_PIN#*@}"
+# Published digest of nginx:1.30.1-alpine; a negative fixture only.
OLD_DIGEST="sha256:c819f83c54b0361f5557601bf5eb4943d09360e7a7fdf426afc466570f45874d"
-BELOW="is below 1.30.6"
+BELOW="is below $BASELINE_TEXT"
NOT_FIXED="is not a fixed x.y.z release"
UNTAGGED="untagged NGINX image (implicit :latest)"
+SAME_LINE="write the image reference on the same line as image:"
+EMPTY_DIGEST="'@' without a digest"
+if ! [[ "$FIXED_DIGEST" =~ ^sha256:[0-9a-f]{64}$ ]]; then
+ echo "FAIL: could not read the pinned digest from $DOCKERFILE_REL: '$FIXED_PIN'" >&2
+ exit 1
+fi
+
+# inject REL IMAGE: one YAML image field.
inject() {
local rel="$1" image="$2"
mkdir -p "$COPY/$(dirname "$rel")"
printf ' image: %s\n' "$image" >"$COPY/$rel"
}
+# inject_text REL TEXT: the file holds TEXT exactly.
+inject_text() {
+ local rel="$1"
+ mkdir -p "$COPY/$(dirname "$rel")"
+ printf '%s\n' "$2" >"$COPY/$rel"
+}
+
inject_kustomize() {
- mkdir -p "$COPY/$(dirname "$KUSTOMIZE_REL")"
- printf 'apiVersion: kustomize.config.k8s.io/v1beta1\nkind: Kustomization\n%s\n' "$1" >"$COPY/$KUSTOMIZE_REL"
+ inject_text "${2:-$KUSTOMIZE_REL}" $'apiVersion: kustomize.config.k8s.io/v1beta1\nkind: Kustomization\n'"$1"
}
-run_matrix() {
- local scanner="$1" scanner_path="$2" family tag image target rel line
+if [ "$(validator_scan_paths "$REPO_ROOT/$VALIDATOR_REL")" != "$EXPECTED_SCAN_PATHS" ]; then
+ echo "FAIL: $VALIDATOR_REL scan_paths differ from this test's list:" >&2
+ diff <(printf '%s\n' "$EXPECTED_SCAN_PATHS") <(validator_scan_paths "$REPO_ROOT/$VALIDATOR_REL") >&2 || true
+ exit 1
+fi
- baseline_refs=""
- expect_pass "$scanner_path" "[$scanner] the current tree"
- baseline_refs="$(reported_refs)"
- if [ -z "$baseline_refs" ] || [ "$baseline_refs" -eq 0 ]; then
- echo "FAIL: [$scanner] the current tree reported no checked references: $(cat "$OUT")" >&2
- exit 1
- fi
+copy_inputs
- for family in nginx nginxinc/nginx-unprivileged docker.io/library/nginx; do
- for tag in 1.30.0 1.30.1 1.30.2 1.30.3 1.30.4 1.30.5 1.30.5-alpine \
- 1.31.0 1.31.1 1.31.2 1.31.3 1.31.4 1.31.5 1.31.6 1.31.6-alpine 1.27.5-alpine 1.29.9; do
- image="$family:$tag"
- inject "$SAMPLE_REL" "$image"
- expect_fail_naming "$scanner_path" "[$scanner] $image in a recipe sample" "$SAMPLE_REL:1: " "$BELOW"
- rm -f "$COPY/$SAMPLE_REL"
- done
-
- # shellcheck disable=SC2016 # variable tags are injected literally
- for tag in latest alpine stable mainline stable-alpine bookworm trixie alpine-slim \
- 1 1-alpine 1.30 1.30-alpine 1.31 1.27-alpine '${NGINX_TAG}' '$NGINX_TAG' '${TAG:-1.30.6}'; do
- image="$family:$tag"
- inject "$SAMPLE_REL" "$image"
- expect_fail_naming "$scanner_path" "[$scanner] $image in a recipe sample" "$SAMPLE_REL:1: " "$NOT_FIXED"
- rm -f "$COPY/$SAMPLE_REL"
- done
-
- for tag in 1.30.6 1.30.6-alpine 1.30.7 1.31.7 1.31.8 1.31.8-alpine 1.30.50 1.30.60 1.31.60 1.32.0 2.0.0; do
- image="$family:$tag"
- inject "$SAMPLE_REL" "$image"
- expect_pass "$scanner_path" "[$scanner] $image in a recipe sample" 1
- rm -f "$COPY/$SAMPLE_REL"
- done
-
- # An untagged image field pulls :latest.
- inject "$SAMPLE_REL" "$family"
- expect_fail_naming "$scanner_path" "[$scanner] untagged $family in a recipe sample" "$SAMPLE_REL:1: " "$UNTAGGED"
+if [ "$(id -u)" -eq 0 ]; then
+ echo "FAIL: run as a non-root user; root reads chmod 000 files and the scan-error case cannot fail" >&2
+ exit 1
+fi
+
+expect_pass "the current tree"
+baseline_refs="$(reported_refs)"
+if [ -z "$baseline_refs" ] || [ "$baseline_refs" -eq 0 ]; then
+ echo "FAIL: the current tree reported no checked references: $(cat "$OUT")" >&2
+ exit 1
+fi
+
+for family in nginx nginxinc/nginx-unprivileged docker.io/library/nginx; do
+ for tag in 1.30.0 1.30.1 1.30.2 1.30.3 1.30.4 1.30.5 1.30.5-alpine \
+ 1.31.0 1.31.1 1.31.2 1.31.3 1.31.4 1.31.5 1.31.6 1.31.6-alpine 1.27.5-alpine 1.29.9; do
+ image="$family:$tag"
+ inject "$SAMPLE_REL" "$image"
+ expect_fail_naming "$image in a recipe sample" "$SAMPLE_REL:1: " "$BELOW"
rm -f "$COPY/$SAMPLE_REL"
done
- for line in '"image": "nginx",' '--image=nginx' 'IMAGE=nginx' "image: 'nginx'"; do
- mkdir -p "$COPY/$(dirname "$E2E_REL")"
- printf '%s\n' "$line" >"$COPY/$E2E_REL"
- expect_fail_naming "$scanner_path" "[$scanner] untagged $line in scripts/e2e" "$E2E_REL:1: " "$UNTAGGED"
- rm -f "$COPY/$E2E_REL"
+ # shellcheck disable=SC2016 # variable tags are injected literally
+ for tag in latest alpine stable mainline stable-alpine bookworm trixie alpine-slim \
+ 1 1-alpine 1.30 1.30-alpine 1.31 1.27-alpine '${NGINX_TAG}' '$NGINX_TAG' '${TAG:-1.30.6}'; do
+ image="$family:$tag"
+ inject "$SAMPLE_REL" "$image"
+ expect_fail_naming "$image in a recipe sample" "$SAMPLE_REL:1: " "$NOT_FIXED"
+ rm -f "$COPY/$SAMPLE_REL"
done
- # Digests: accepted only next to a fixed tag, and only well formed.
- inject "$SAMPLE_REL" "nginx:1.30.6-alpine@$FIXED_DIGEST"
- expect_pass "$scanner_path" "[$scanner] fixed tag with a digest" 1
- inject "$SAMPLE_REL" "nginx@$FIXED_DIGEST"
- expect_fail_naming "$scanner_path" "[$scanner] digest without a tag" "$SAMPLE_REL:1: " "digest without a version tag"
- inject "$SAMPLE_REL" "nginx:1.30.1-alpine@$OLD_DIGEST"
- expect_fail_naming "$scanner_path" "[$scanner] old tag with its digest" "$SAMPLE_REL:1: " "$BELOW"
- inject "$SAMPLE_REL" "nginx:1.30.6-alpine@sha256:c59d1f8b"
- expect_fail_naming "$scanner_path" "[$scanner] malformed digest" "$SAMPLE_REL:1: " "malformed digest"
- rm -f "$COPY/$SAMPLE_REL"
-
- # Strings that are not image references are left alone; the count shows they
- # were not counted as references either.
- for image in nginx-egress-proxy clerum/nginx-egress-proxy:0.1.0 'nginx:*' 'nginx:'; do
+ for tag in 1.30.6 1.30.6-alpine 1.30.7 1.31.7 1.31.8 1.31.8-alpine 1.30.50 1.30.60 1.31.60 1.32.0 2.0.0; do
+ image="$family:$tag"
inject "$SAMPLE_REL" "$image"
- expect_pass "$scanner_path" "[$scanner] non-reference string $image" 0
+ expect_pass "$image in a recipe sample" 1
rm -f "$COPY/$SAMPLE_REL"
done
- # Paths that deploy or install platform NGINX.
- for rel in "$E2E_REL" deploy/base/profiles/zz-injected.yaml deploy/components/ghcr-images/zz-injected.yaml \
- deploy/overlays/zz-injected/zz-injected.yaml; do
- inject "$rel" "nginx:1.30.5-alpine"
- expect_fail_naming "$scanner_path" "[$scanner] nginx:1.30.5-alpine in $rel" "$rel:1: " "$BELOW"
- rm -f "$COPY/$rel"
- done
- for rel in "$REMOTE_MCP_REL" tests/e2e/playwright/control-ui/recipes.spec.ts \
- tests/e2e/playwright/control-ui/workflow-recipe-egressbindings.spec.ts \
- tests/e2e/integration/control-api-k8s.test.ts docs/agents/CLERUM_WORKFLOW_RECIPE_GUIDE.md; do
- cp "$COPY/$rel" "$WORK/appended.orig"
- printf '// image: nginx:1.31.6\n' >>"$COPY/$rel"
- expect_fail_naming "$scanner_path" "[$scanner] nginx:1.31.6 appended to $rel" "$rel:" "nginx:1.31.6: release 1.31.6 $BELOW"
- cp "$WORK/appended.orig" "$COPY/$rel"
- done
+ # An untagged image field pulls :latest.
+ inject "$SAMPLE_REL" "$family"
+ expect_fail_naming "untagged $family in a recipe sample" "$SAMPLE_REL:1: " "$UNTAGGED"
+ rm -f "$COPY/$SAMPLE_REL"
+done
- # kustomize images: entries rewrite an image without naming its tag inline.
- inject_kustomize $'images:\n- name: nginx\n newTag: 1.30.1-alpine'
- expect_fail_naming "$scanner_path" "[$scanner] kustomize newTag below the baseline" "$KUSTOMIZE_REL:4: nginx:1.30.1-alpine: " "$BELOW"
- inject_kustomize $'images:\n - name: clerum/gateway\n newName: docker.io/library/nginx\n newTag: "1.31.6"'
- expect_fail_naming "$scanner_path" "[$scanner] kustomize newName to NGINX below the baseline" "$KUSTOMIZE_REL:4: docker.io/library/nginx:1.31.6: " "$BELOW"
- inject_kustomize $'images:\n- name: clerum/gateway\n newName: nginx'
- expect_fail_naming "$scanner_path" "[$scanner] kustomize newName to NGINX with no newTag" "$KUSTOMIZE_REL:4: nginx:<no newTag>: " "$NOT_FIXED"
- inject_kustomize $'images:\n- name: nginx\n newTag: stable-alpine'
- expect_fail_naming "$scanner_path" "[$scanner] kustomize floating newTag" "$KUSTOMIZE_REL:4: nginx:stable-alpine: " "$NOT_FIXED"
- inject_kustomize $'images:\n- name: nginx\n digest: '"$FIXED_DIGEST"
- expect_fail_naming "$scanner_path" "[$scanner] kustomize digest without newTag" "$KUSTOMIZE_REL:4: nginx@$FIXED_DIGEST: " "digest without a version tag"
- inject_kustomize $'images:\n- name: nginx\n newTag: 1.30.6-alpine # fixed baseline'
- expect_pass "$scanner_path" "[$scanner] kustomize newTag on the baseline" 1
- inject_kustomize $'images:\n- name: clerum/control-api\n newName: ghcr.io/evenfire-ai/control-api\n newTag: v0.11.0'
- expect_pass "$scanner_path" "[$scanner] kustomize entry for another image" 0
- rm -rf "${COPY:?}/$(dirname "$KUSTOMIZE_REL")"
-
- # Scan errors must fail the guard instead of reading as "nothing found".
- target="$COPY/$(dirname "$E2E_REL")/zz-unreadable.sh"
- printf 'echo unreadable\n' >"$target"
- chmod 000 "$target"
- expect_fail_naming "$scanner_path" "[$scanner] unreadable scanned file" "platform NGINX image scan (scan_refs) failed with status"
- chmod 600 "$target"
- rm -f "$target"
-
- expect_pass "$scanner_path" "[$scanner] the restored tree" 0
-}
+# Untagged references in every recognised position.
+# shellcheck disable=SC2016 # $P is injected literally
+for line in 'image: nginx # x' '"image": "nginx"' '- {name: gw, image: nginx}' 'image: nginx}' \
+ '"image": "nginx",' '--image=nginx' 'IMAGE=nginx' "image: 'nginx'"; do
+ inject_text "$SAMPLE_REL" "$line"
+ expect_fail_naming "untagged $line" "$SAMPLE_REL:1: " "$UNTAGGED"
+ rm -f "$COPY/$SAMPLE_REL"
+done
+# shellcheck disable=SC2016 # $P is injected literally
+for line in 'FROM nginx' 'from nginx AS b' 'FROM --platform=$P nginx'; do
+ inject_text "$E2E_DOCKERFILE_REL" "$line"
+ expect_fail_naming "untagged $line" "$E2E_DOCKERFILE_REL:1: " "$UNTAGGED"
+ rm -f "$COPY/$E2E_DOCKERFILE_REL"
+done
+for line in 'PUBLIC_IMAGES=("nginx")' 'PUBLIC_IMAGES=(nginx)' 'PUBLIC_IMAGES+=("busybox:1.36" nginx)'; do
+ inject_text "$E2E_REL" "$line"
+ expect_fail_naming "untagged $line in a shell script" "$E2E_REL:1: " "$UNTAGGED"
+ rm -f "$COPY/$E2E_REL"
+done
+for element in ' nginx' ' "nginx"'; do
+ inject_text "$E2E_REL" $'PUBLIC_IMAGES=(\n "busybox:1.36"\n'"$element"$'\n)'
+ expect_fail_naming "untagged array line '$element' in a shell script" "$E2E_REL:3: " "$UNTAGGED"
+ rm -f "$COPY/$E2E_REL"
+done
-if [ "$(validator_scan_paths)" != "$EXPECTED_SCAN_PATHS" ]; then
- echo "FAIL: $VALIDATOR_REL scan_paths differ from this test's list:" >&2
- diff <(printf '%s\n' "$EXPECTED_SCAN_PATHS") <(validator_scan_paths) >&2 || true
- exit 1
-fi
+# An image: key whose value is on the next lines cannot be read by the scan.
+for text in $'image: >-\n nginx' $'image:\n nginx'; do
+ inject_text "$SAMPLE_REL" "$text"
+ expect_fail_naming "image: with its value on the next line" "$SAMPLE_REL:1: " "$SAME_LINE"
+ rm -f "$COPY/$SAMPLE_REL"
+done
-copy_inputs
+# Digests: accepted only next to a fixed tag, and only well formed.
+inject "$SAMPLE_REL" "nginx:1.30.6-alpine@$FIXED_DIGEST"
+expect_pass "fixed tag with a digest" 1
+inject "$SAMPLE_REL" "nginx@$FIXED_DIGEST"
+expect_fail_naming "digest without a tag" "$SAMPLE_REL:1: " "digest without a version tag"
+inject "$SAMPLE_REL" "nginx:1.30.1-alpine@$OLD_DIGEST"
+expect_fail_naming "old tag with its digest" "$SAMPLE_REL:1: " "$BELOW"
+inject "$SAMPLE_REL" "nginx:1.30.6-alpine@sha256:c59d1f8b"
+expect_fail_naming "malformed digest" "$SAMPLE_REL:1: " "malformed digest"
+inject "$SAMPLE_REL" "nginx:1.30.6-alpine@"
+expect_fail_naming "fixed tag with an empty digest" "$SAMPLE_REL:1: " "$EMPTY_DIGEST"
+inject "$SAMPLE_REL" "nginx@"
+expect_fail_naming "untagged name with an empty digest" "$SAMPLE_REL:1: " "$EMPTY_DIGEST"
+rm -f "$COPY/$SAMPLE_REL"
-if [ "$(id -u)" -eq 0 ]; then
- echo "FAIL: run as a non-root user; root reads chmod 000 files and the scan-error case cannot fail" >&2
- exit 1
-fi
+# Strings that are not image references are left alone; the count shows they
+# were not counted as references either.
+for image in nginx-egress-proxy clerum/nginx-egress-proxy:0.1.0 'nginx:*' 'nginx:'; do
+ inject "$SAMPLE_REL" "$image"
+ expect_pass "non-reference string $image" 0
+ rm -f "$COPY/$SAMPLE_REL"
+done
+for line in "id: 'nginx'" "if name == 'nginx'"; do
+ inject_text "$SAMPLE_REL" "$line"
+ expect_pass "non-reference line $line" 0
+ rm -f "$COPY/$SAMPLE_REL"
+done
+inject_text "$E2E_REL" $'NAMES=("nginx-egress-proxy")\nNAMES=(\n nginx-egress-proxy\n)'
+expect_pass "nginx-egress-proxy shell-array elements" 0
+rm -f "$COPY/$E2E_REL"
+inject_text "$SAMPLE_REL" '- {name: gw, image: nginx:1.30.6-alpine}'
+expect_pass "fixed tag in a flow map" 1
+rm -f "$COPY/$SAMPLE_REL"
-# The validator uses rg when it is installed and grep -R otherwise. Run the
-# matrix with each scanner that this host can provide.
-no_rg_path=""
-IFS=: read -r -a path_dirs <<<"$PATH"
-for d in "${path_dirs[@]}"; do
- [ -x "$d/rg" ] && continue
- no_rg_path="${no_rg_path:+$no_rg_path:}$d"
+# Paths that deploy or install platform NGINX, hidden files included.
+for rel in "$E2E_REL" deploy/base/profiles/zz-injected.yaml deploy/components/ghcr-images/zz-injected.yaml \
+ deploy/overlays/zz-injected/zz-injected.yaml "$HIDDEN_REL"; do
+ inject "$rel" "nginx:1.30.5-alpine"
+ expect_fail_naming "nginx:1.30.5-alpine in $rel" "$rel:1: " "$BELOW"
+ rm -f "$COPY/$rel"
+done
+for rel in "$REMOTE_MCP_REL" tests/e2e/playwright/control-ui/recipes.spec.ts \
+ tests/e2e/playwright/control-ui/recipe-scope-copy.spec.ts \
+ tests/e2e/playwright/control-ui/workflow-recipe-egressbindings.spec.ts \
+ tests/e2e/integration/control-api-k8s.test.ts docs/agents/CLERUM_WORKFLOW_RECIPE_GUIDE.md; do
+ cp "$COPY/$rel" "$WORK/appended.orig"
+ printf '// image: nginx:1.31.6\n' >>"$COPY/$rel"
+ expect_fail_naming "nginx:1.31.6 appended to $rel" "$rel:" "nginx:1.31.6: release 1.31.6 $BELOW"
+ cp "$WORK/appended.orig" "$COPY/$rel"
done
-scanners=0
-if command -v rg >/dev/null 2>&1; then
- run_matrix rg "$PATH"
- scanners=$((scanners + 1))
-fi
-run_matrix grep "$no_rg_path"
-scanners=$((scanners + 1))
+
+# kustomize images: entries rewrite an image without naming its tag inline.
+inject_kustomize $'images:\n- name: nginx\n newTag: 1.30.1-alpine'
+expect_fail_naming "kustomize newTag below the baseline" "$KUSTOMIZE_REL:4: nginx:1.30.1-alpine: " "$BELOW"
+inject_kustomize $'images: [{name: nginx, newTag: 1.30.1-alpine}]'
+expect_fail_naming "kustomize flow list below the baseline" "$KUSTOMIZE_REL:3: nginx:1.30.1-alpine: " "$BELOW"
+inject_kustomize $'images:\n- {name: nginx, newTag: 1.30.1-alpine}'
+expect_fail_naming "kustomize flow map item below the baseline" "$KUSTOMIZE_REL:4: nginx:1.30.1-alpine: " "$BELOW"
+inject_text "$KUSTOMIZE_REL" '{"apiVersion": "kustomize.config.k8s.io/v1beta1", "kind": "Kustomization", "images": [{"name": "nginx", "newTag": "1.30.1-alpine"}]}'
+expect_fail_naming "kustomize JSON body below the baseline" "$KUSTOMIZE_REL:" "nginx:1.30.1-alpine: " "$BELOW"
+rm -f "$COPY/$KUSTOMIZE_REL"
+inject_kustomize $'images:\n- name: nginx\n newTag: 1.30.1-alpine' "$KUSTOMIZE_DIR/Kustomization"
+expect_fail_naming "Kustomization file name below the baseline" "$KUSTOMIZE_DIR/Kustomization:4: nginx:1.30.1-alpine: " "$BELOW"
+rm -f "$COPY/$KUSTOMIZE_DIR/Kustomization"
+inject_kustomize $'images:\n- name: "ngin\\u0078"\n newTag: 1.30.1-alpine'
+expect_fail_naming "kustomize escaped name below the baseline" "$KUSTOMIZE_REL:4: nginx:1.30.1-alpine: " "$BELOW"
+inject_kustomize $'images:\n- name: nginx\n newTag: "null"'
+expect_fail_naming "kustomize newTag \"null\"" "$KUSTOMIZE_REL:4: nginx:null: " "$NOT_FIXED"
+inject_kustomize $'images: [unclosed'
+expect_fail_naming "unparsable kustomization" "yq could not read the images: entries of $KUSTOMIZE_REL"
+inject_kustomize $'images:\n - name: clerum/gateway\n newName: docker.io/library/nginx\n newTag: "1.31.6"'
+expect_fail_naming "kustomize newName to NGINX below the baseline" "$KUSTOMIZE_REL:4: docker.io/library/nginx:1.31.6: " "$BELOW"
+inject_kustomize $'images:\n- name: clerum/gateway\n newName: nginx'
+expect_fail_naming "kustomize newName to NGINX with no newTag" "$KUSTOMIZE_REL:4: nginx:<no newTag>: " "$NOT_FIXED"
+inject_kustomize $'images:\n- name: nginx\n newTag: stable-alpine'
+expect_fail_naming "kustomize floating newTag" "$KUSTOMIZE_REL:4: nginx:stable-alpine: " "$NOT_FIXED"
+inject_kustomize $'images:\n- name: nginx\n digest: '"$FIXED_DIGEST"
+expect_fail_naming "kustomize digest without newTag" "$KUSTOMIZE_REL:4: nginx@$FIXED_DIGEST: " "digest without a version tag"
+inject_kustomize $'images:\n- name: nginx\n newTag: 1.30.6-alpine # fixed baseline'
+expect_pass "kustomize newTag on the baseline" 1
+inject_kustomize $'images:\n- name: nginx\n newTag: 1.30.6-alpine '
+expect_pass "kustomize unquoted newTag with trailing spaces" 1
+inject_kustomize $'images:\n- name: nginx\n newName: clerum/nginx-egress-proxy\n newTag: 0.1.0'
+expect_pass "kustomize rewrite of nginx to another image" 0
+inject_kustomize $'images:\n- name: clerum/control-api\n newName: ghcr.io/evenfire-ai/control-api\n newTag: v0.11.0'
+expect_pass "kustomize entry for another image" 0
+rm -rf "${COPY:?}/$KUSTOMIZE_DIR"
+
+# Scan errors must fail the guard instead of reading as "nothing found".
+target="$COPY/$(dirname "$E2E_REL")/zz-unreadable.sh"
+printf 'echo unreadable\n' >"$target"
+chmod 000 "$target"
+expect_fail_naming "unreadable scanned file" "platform NGINX image scan (candidates) failed with status"
+chmod 600 "$target"
+rm -f "$target"
+
+expect_pass "the restored tree" 0
# A scan path that no longer exists is an error, never a silent skip.
moved="tests/e2e/integration/control-api-k8s.test.ts"
mv "$COPY/$moved" "$WORK/moved.orig"
-expect_fail_naming "$PATH" "missing scan path" "scan path $moved does not exist"
+expect_fail_naming "missing scan path" "scan path $moved does not exist"
mv "$WORK/moved.orig" "$COPY/$moved"
-# Dockerfile FROM contract (independent of the scanner).
+# A scope that holds no NGINX file is an error, never a pass over nothing.
+cp "$COPY/$VALIDATOR_REL" "$WORK/validator.orig"
+mkdir -p "$COPY/zz-empty"
+awk '
+ /^scan_paths=\(/ { print; print " \"zz-empty\""; skip = 1; replaced++; next }
+ skip && /^\)/ { skip = 0 }
+ !skip { print }
+ END { if (replaced != 1) exit 1 }
+' "$WORK/validator.orig" >"$COPY/$VALIDATOR_REL"
+if [ "$(validator_scan_paths "$COPY/$VALIDATOR_REL")" != "zz-empty" ]; then
+ echo "FAIL: could not point the copied validator at an empty scan scope" >&2
+ exit 1
+fi
+expect_fail_naming "empty scan scope" "platform NGINX image scan (candidates) found no file"
+cp "$WORK/validator.orig" "$COPY/$VALIDATOR_REL"
+
+# Dockerfile FROM contract.
expected_from="$(grep -E '^FROM ' "$COPY/$DOCKERFILE_REL")"
cp "$COPY/$DOCKERFILE_REL" "$WORK/Dockerfile.orig"
-sed 's/@sha256:[0-9a-f]*/@sha256:0000000000000000000000000000000000000000000000000000000000000000/' \
- "$WORK/Dockerfile.orig" >"$COPY/$DOCKERFILE_REL"
-expect_fail_naming "$PATH" "Dockerfile with a wrong digest" "$DOCKERFILE_REL must have exactly one FROM line"
+sed 's/@sha256:[0-9a-f]*/@sha256:'"$(printf '%063d' 0)"'/' "$WORK/Dockerfile.orig" >"$COPY/$DOCKERFILE_REL"
+expect_fail_naming "Dockerfile with a malformed digest" "$DOCKERFILE_REL must have exactly one FROM line"
sed 's/@sha256:[0-9a-f]*//' "$WORK/Dockerfile.orig" >"$COPY/$DOCKERFILE_REL"
-expect_fail_naming "$PATH" "Dockerfile pinned by tag only" "$DOCKERFILE_REL must have exactly one FROM line"
+expect_fail_naming "Dockerfile pinned by tag only" "$DOCKERFILE_REL must have exactly one FROM line"
{ cat "$WORK/Dockerfile.orig"; echo "$expected_from AS second"; } >"$COPY/$DOCKERFILE_REL"
-expect_fail_naming "$PATH" "Dockerfile with a second FROM" "$DOCKERFILE_REL must have exactly one FROM line"
+expect_fail_naming "Dockerfile with a second FROM" "$DOCKERFILE_REL must have exactly one FROM line"
# Dockerfile instructions are case-insensitive; a lowercase stage still runs.
{ cat "$WORK/Dockerfile.orig"; echo "from busybox:1.36 AS second"; } >"$COPY/$DOCKERFILE_REL"
-expect_fail_naming "$PATH" "Dockerfile with a lowercase second from" "$DOCKERFILE_REL must have exactly one FROM line" "from busybox:1.36"
+expect_fail_naming "Dockerfile with a lowercase second from" "$DOCKERFILE_REL must have exactly one FROM line" "from busybox:1.36"
cp "$WORK/Dockerfile.orig" "$COPY/$DOCKERFILE_REL"
-expect_pass "$PATH" "Dockerfile restored" 0
+expect_pass "Dockerfile restored" 0
# --list-digest-pins feeds verify-nginx-image-digests.sh: every valid tag@digest
-# once, nothing else.
-inject "$SAMPLE_REL" "${expected_from#FROM }"
+# once, with its registry path, nothing else.
+inject "$SAMPLE_REL" "$FIXED_PIN"
+registry_pin="registry.internal:5000/mirror/$FIXED_PIN"
+inject_text "$E2E_REL" "IMAGE=$registry_pin"
cases=$((cases + 1))
-if ! run_validator "$PATH" --list-digest-pins; then
+if ! run_validator --list-digest-pins; then
fail "--list-digest-pins failed: $(cat "$OUT")"
-elif [ "$(cat "$OUT")" != "${expected_from#FROM }" ]; then
- fail "--list-digest-pins should print '${expected_from#FROM }' once: $(cat "$OUT")"
+elif [ "$(cat "$OUT")" != "$(printf '%s\n' "$FIXED_PIN" "$registry_pin" | sort -u)" ]; then
+ fail "--list-digest-pins should print '$FIXED_PIN' and '$registry_pin' once each: $(cat "$OUT")"
fi
-rm -f "$COPY/$SAMPLE_REL"
+rm -f "$COPY/$SAMPLE_REL" "$COPY/$E2E_REL"
-echo "cases=$cases scanners=$scanners failures=$failures"
+echo "cases=$cases failures=$failures"
if [ "$cases" -eq 0 ]; then
echo "FAIL: no cases ran" >&2
exit 1
diff --git a/scripts/validate-nginx-images.sh b/scripts/validate-nginx-images.sh
index fd6d808bd..6373f8eaf 100755
--- a/scripts/validate-nginx-images.sh
+++ b/scripts/validate-nginx-images.sh
@@ -1,17 +1,25 @@
#!/usr/bin/env bash
# Validate platform-owned NGINX runtime images stay on the fixed security
-# baseline: stable 1.30.6, which fixes CVE-2026-15176, CVE-2026-93479,
-# CVE-2026-95101, CVE-2026-97629 and CVE-2026-97205 (and the older
-# CVE-2026-42945). User-authored arbitrary workload image tests are
-# intentionally out of scope; this guard covers manifests, generated proxy
-# defaults, deploy helpers, shipped recipe samples, and E2E fixtures that
-# install platform-owned NGINX surfaces.
+# baseline defined in scripts/nginx-image-policy.sh. User-authored arbitrary
+# workload image tests are intentionally out of scope: this guard scans the
+# surfaces that are deployed, pulled or copied by users (manifests, generated
+# proxy defaults, deploy helpers, shipped recipe samples and docs, and the E2E
+# fixtures that install platform NGINX). Unit tests that never pull an image
+# are not scanned.
#
# Every nginx / nginxinc/nginx-unprivileged reference in the scanned paths must
-# carry a full x.y.z tag at or above the fixed release of its line (1.30.6,
-# 1.31.7, or any 1.32+). Floating, untagged and variable tags are rejected. A
-# digest is accepted only next to such a tag; scripts/verify-nginx-image-digests.sh
-# checks in CI that each pinned digest really is that NGINX version.
+# carry a full x.y.z tag at or above the floor of its release line. Floating,
+# untagged and variable tags are rejected. A digest is accepted only next to
+# such a tag; scripts/verify-nginx-image-digests.sh checks in CI that each
+# pinned digest really is that NGINX version. Any image named nginx, under any
+# registry path, is treated as upstream NGINX.
+#
+# This is a static text scan plus a yq parse of kustomization images: entries,
+# not a renderer. It reads literal spellings: escape sequences in text files
+# are not decoded (yq decodes them only in kustomization images: entries).
+# Untagged references are recognised in an image field (YAML, JSON, flow maps,
+# --image=, IMAGE=), a Dockerfile FROM, and a shell array element in *.sh files;
+# an image: key whose value is not on the same line is rejected.
#
# --list-digest-pins print every tag@digest reference and exit
# (input for verify-nginx-image-digests.sh)
@@ -20,21 +28,38 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
+# shellcheck source=scripts/nginx-image-policy.sh
+source "$SCRIPT_DIR/nginx-image-policy.sh"
FIXED_NGINX_IMAGE="nginx:1.30.6-alpine"
-FIXED_NGINX_IMAGE_DIGEST="sha256:c59d1f8b1e0e42da75be973424cd72e23f7f8adfb54e982f4d1cd0216a5a5576"
EGRESS_PROXY_IMAGE="clerum/nginx-egress-proxy:0.1.0"
-BASELINE_TEXT="1.30.6 (1.30 line), 1.31.7 (1.31 line) or 1.32+"
+
+# Pieces of the reference patterns. An optional literal registry[:port]/path/
+# prefix may precede the repository name.
+NGINX_NAME='(nginx|nginxinc/nginx-unprivileged)'
+REGISTRY_PREFIX='([[:alnum:]_.-]+(:[0-9]+)?/)*'
+# After an untagged name: anything that cannot continue a reference ('}' ends it).
+# shellcheck disable=SC2016 # literal '$' and '{' in a regular expression
+UNTAGGED_END='([^[:alnum:]_.:@/${-]|$)'
+QUOTE="[\"']"
# An NGINX image reference: the repository name, then a tag and/or digest. The
-# leading group keeps clerum/nginx-egress-proxy and foo-nginx:1 out and lets a
-# registry prefix (docker.io/library/nginx:...) match after its '/'. '$', '{',
-# '}' and '*' are captured so variable and glob tags are seen.
-# shellcheck disable=SC2016 # literal '$', '{' and '}' in a regular expression
-NGINX_REF_REGEX='(^|[^[:alnum:]_.-])(nginx|nginxinc/nginx-unprivileged)[:@][[:alnum:]_.:@${}*-]*'
-# An untagged NGINX image in an image field: image: nginx, "image": "nginx",
-# --image=nginx, IMAGE=docker.io/library/nginx (implicitly :latest).
-NGINX_UNTAGGED_REGEX='image["'"'"']?[[:space:]]*[:=][[:space:]]*["'"'"']?([[:alnum:]_.-]+(:[0-9]+)?/)*(nginx|nginxinc/nginx-unprivileged)["'"'"']?[[:space:]]*,?[[:space:]]*$'
+# leading group keeps clerum/nginx-egress-proxy and foo-nginx:1 out. '$', '{'
+# and '*' are captured so variable and glob tags are seen; '}' ends the token
+# so a flow map such as {image: nginx:1.30.6-alpine} yields the reference.
+# shellcheck disable=SC2016 # literal '$' and '{' in a regular expression
+NGINX_REF_REGEX='(^|[^[:alnum:]_.-])'"$REGISTRY_PREFIX$NGINX_NAME"'[:@][[:alnum:]_.:@${*-]*'
+# An untagged NGINX image (implicitly :latest) in an image field or a
+# Dockerfile FROM (keywords in any case, optional --flag=value words).
+NGINX_UNTAGGED_REGEX="[Ii][Mm][Aa][Gg][Ee]$QUOTE?[[:space:]]*[:=][[:space:]]*$QUOTE?$REGISTRY_PREFIX$NGINX_NAME$UNTAGGED_END"
+NGINX_UNTAGGED_REGEX="$NGINX_UNTAGGED_REGEX|^[[:space:]]*[Ff][Rr][Oo][Mm][[:space:]]+(--[^[:space:]]+[[:space:]]+)*$REGISTRY_PREFIX$NGINX_NAME$UNTAGGED_END"
+# An untagged NGINX shell-array element, quoted or not: after =( or +=( on the
+# same line, or alone on its own line.
+NGINX_UNTAGGED_ARRAY_REGEX="=\\(([^)]*[[:space:]])?$QUOTE?$REGISTRY_PREFIX$NGINX_NAME([\"'[:space:])]|\$)"
+NGINX_UNTAGGED_ARRAY_REGEX="$NGINX_UNTAGGED_ARRAY_REGEX|^[[:space:]]*$QUOTE?$REGISTRY_PREFIX$NGINX_NAME$QUOTE?[[:space:]]*\\)?[[:space:]]*\$"
+# A YAML image key with no value on its line (empty or a block scalar): the
+# reference on the following lines cannot be read by the patterns above.
+IMAGE_KEY_WITHOUT_VALUE_REGEX="^[[:space:]-]*$QUOTE?image$QUOTE?[[:space:]]*:[[:space:]]*([>|][-+0-9]*)?[[:space:]]*(#.*)?\$"
# Every path must exist: a renamed or deleted path is an error, never a
# silent skip. deploy/ covers base, components and every overlay, including
@@ -42,14 +67,11 @@ NGINX_UNTAGGED_REGEX='image["'"'"']?[[:space:]]*[:=][[:space:]]*["'"'"']?([[:aln
scan_paths=(
"deploy"
"host-context-controller/src/config.ts"
- "host-context-controller/src/__tests__/reconciler.remote.test.ts"
- "host-context-controller/src/__tests__/reconciler.sanitize.test.ts"
"control-api/src/routes/admin/registry.ts"
"control-api/src/routes/admin/remoteMcp.ts"
"nginx-egress-proxy/Dockerfile"
"control-ui/e2e/registry-install.spec.ts"
"control-ui/e2e/qa-recorder-recipe-scope-copy.spec.ts"
- "control-ui/components/__tests__/RegistryCatalog.test.tsx"
"desktop-app/test/e2e-playwright/sandbox-ui-apps-catalog-authz.test.ts"
"scripts/minikube/build-images.sh"
"scripts/bootstrap-cluster.sh"
@@ -57,17 +79,18 @@ scan_paths=(
"docs/deploy/workflow-recipes-guide.md"
"docs/agents/CLERUM_WORKFLOW_RECIPE_GUIDE.md"
"workflow-recipes/samples"
- "workflow-recipes/src"
"tests/e2e/integration/control-api-k8s.test.ts"
"tests/e2e/playwright/control-ui/recipes.spec.ts"
+ "tests/e2e/playwright/control-ui/recipe-scope-copy.spec.ts"
"tests/e2e/playwright/control-ui/workflow-recipe-egressbindings.spec.ts"
"workflow-recipes/tests/e2e"
- "workflow-recipes/tests/fixtures/workflow/invalid-scheduling-no-steps.yaml"
)
+cd "$PROJECT_DIR"
+
failed=0
for _p in "${scan_paths[@]}"; do
- if [ ! -e "$PROJECT_DIR/$_p" ]; then
+ if [ ! -e "$_p" ]; then
echo "ERROR: scan path $_p does not exist; update scan_paths" >&2
failed=1
fi
@@ -76,146 +99,102 @@ if [ "$failed" -ne 0 ]; then
exit 1
fi
-# Prints why an x.y.z[-suffix] tag is not acceptable; prints nothing if it is.
-nginx_tag_problem() {
- local tag="$1" major minor patch
- if ! [[ "$tag" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(-[[:alnum:]_.-]+)?$ ]]; then
- echo "tag '$tag' is not a fixed x.y.z release"
- return
- fi
- major=$((10#${BASH_REMATCH[1]}))
- minor=$((10#${BASH_REMATCH[2]}))
- patch=$((10#${BASH_REMATCH[3]}))
- if [ "$major" -gt 1 ] ||
- { [ "$major" -eq 1 ] && [ "$minor" -ge 32 ]; } ||
- { [ "$major" -eq 1 ] && [ "$minor" -eq 31 ] && [ "$patch" -ge 7 ]; } ||
- { [ "$major" -eq 1 ] && [ "$minor" -eq 30 ] && [ "$patch" -ge 6 ]; }; then
- return
+# scan_or_fail STAGE GREP_ARGS...: runs grep and prints its output. Status 1
+# means "no match"; above 1 is a scan error (an unreadable file, a bad
+# pattern), which fails the guard naming the stage instead of reading as
+# "nothing found". Hidden and gitignored files are read like any other.
+scan_or_fail() {
+ local stage="$1" out status=0
+ shift
+ out="$(grep "$@")" || status=$?
+ if [ "$status" -gt 1 ]; then
+ echo "ERROR: platform NGINX image scan ($stage) failed with status $status." >&2
+ return 1
fi
- echo "release $major.$minor.$patch is below $BASELINE_TEXT"
-}
-
-# Splits [registry/]name[:tag][@digest] into the globals ref_tag and ref_digest.
-split_ref() {
- local last="${1##*/}" rest
- rest="${last#"${last%%[:@]*}"}"
- ref_tag=""
- ref_digest=""
- case "$rest" in
- :*@*) ref_tag="${rest#:}"; ref_tag="${ref_tag%%@*}"; ref_digest="${rest#*@}" ;;
- :*) ref_tag="${rest#:}" ;;
- @*) ref_digest="${rest#@}" ;;
- esac
+ printf '%s' "$out"
}
-# Prints why an NGINX reference is not acceptable; prints nothing if it is.
-nginx_ref_problem() {
- split_ref "$1"
- if [ -n "$ref_digest" ]; then
- if [ -z "$ref_tag" ]; then
- echo "digest without a version tag (write nginx:<x.y.z>[-suffix]@sha256:...)"
- return
- fi
- if ! [[ "$ref_digest" =~ ^sha256:[0-9a-f]{64}$ ]]; then
- echo "malformed digest '$ref_digest'"
- return
- fi
- fi
- nginx_tag_problem "$ref_tag"
-}
+# Files that mention nginx at all; the pattern scans read only these.
+candidate_list="$(scan_or_fail candidates -RlF -e nginx -- "${scan_paths[@]}")" || exit 1
+if [ -z "$candidate_list" ]; then
+ echo "ERROR: platform NGINX image scan (candidates) found no file mentioning nginx; check scan_paths." >&2
+ exit 1
+fi
+candidates=()
+shell_candidates=()
+while IFS= read -r _f; do
+ candidates+=("$_f")
+ case "$_f" in *.sh) shell_candidates+=("$_f") ;; esac
+done <<<"$candidate_list"
-is_nginx_name() {
- case "$1" in
- nginx | */nginx | nginxinc/nginx-unprivileged | */nginxinc/nginx-unprivileged) return 0 ;;
- esac
- return 1
-}
+# Kustomizations by file name, not content: a YAML escape such as "ngin\x78"
+# carries no literal "nginx" but kustomize decodes it to nginx.
+kustomization_list="$(scan_or_fail kustomizations -Rl --include=kustomization.yaml \
+ --include=kustomization.yml --include=Kustomization -e '' -- "${scan_paths[@]}")" || exit 1
-# path:line:token for every tagged or digested NGINX reference.
-scan_refs() {
- cd "$PROJECT_DIR"
- if command -v rg >/dev/null 2>&1; then
- rg --with-filename --line-number --only-matching --no-heading "$NGINX_REF_REGEX" "${scan_paths[@]}"
- else
- grep -RHnoE "$NGINX_REF_REGEX" "${scan_paths[@]}"
- fi
-}
+ref_hits="$(scan_or_fail tagged -HnoE "$NGINX_REF_REGEX" -- "${candidates[@]}")" || failed=1
+untagged_hits="$(scan_or_fail untagged -HnE "$NGINX_UNTAGGED_REGEX" -- "${candidates[@]}")" || failed=1
+if [ "${#shell_candidates[@]}" -gt 0 ]; then
+ array_hits="$(scan_or_fail shell-array -HnE "$NGINX_UNTAGGED_ARRAY_REGEX" -- "${shell_candidates[@]}")" || failed=1
+else
+ array_hits=""
+fi
+image_key_hits="$(scan_or_fail image-key -HnE "$IMAGE_KEY_WITHOUT_VALUE_REGEX" -- "${candidates[@]}")" || failed=1
+if [ "$failed" -ne 0 ]; then
+ exit 1
+fi
-scan_untagged() {
- cd "$PROJECT_DIR"
- if command -v rg >/dev/null 2>&1; then
- rg --with-filename --line-number --no-heading --ignore-case "$NGINX_UNTAGGED_REGEX" "${scan_paths[@]}"
- else
- grep -RHniE "$NGINX_UNTAGGED_REGEX" "${scan_paths[@]}"
+# line|name|newName|newTag|digest for each entry of a top-level images: list.
+# yq's join writes an absent or null field as an empty string.
+kustomize_hits=""
+if [ -n "$kustomization_list" ]; then
+ if ! command -v yq >/dev/null 2>&1; then
+ echo "ERROR: yq is required to read kustomization images: entries (first file: ${kustomization_list%%$'\n'*})" >&2
+ exit 1
fi
-}
-
-# path:line:name|newName|newTag|digest for each entry of a top-level images:
-# list in every kustomization file under the scanned paths.
-scan_kustomize_images() {
- local files
- cd "$PROJECT_DIR"
- files="$(find "${scan_paths[@]}" -type f \( -name kustomization.yaml -o -name kustomization.yml \))"
- [ -n "$files" ] || return 1
- # shellcheck disable=SC2086 # repository paths contain no whitespace
- awk '
- # flush() runs on the first line of the next file too, so the entry keeps
- # the file it was read from.
- function flush() {
- if (entry_line) print entry_file ":" entry_line ":" name "|" newname "|" newtag "|" digest
- entry_line = 0; name = ""; newname = ""; newtag = ""; digest = ""
- }
- function value(line) {
- sub(/^[^:]*:[[:space:]]*/, "", line); sub(/[[:space:]]+#.*$/, "", line)
- gsub(/^["\047]|["\047][[:space:]]*$/, "", line); return line
- }
- FNR == 1 { flush(); in_images = 0 }
- /^images:/ { flush(); in_images = 1; next }
- /^[^[:space:]#-]/ { flush(); in_images = 0 }
- !in_images { next }
- /^[[:space:]]*-[[:space:]]/ { flush(); entry_file = FILENAME; entry_line = FNR; sub(/-[[:space:]]+/, "") }
- /^[[:space:]]*name:/ { name = value($0) }
- /^[[:space:]]*newName:/ { newname = value($0) }
- /^[[:space:]]*newTag:/ { newtag = value($0) }
- /^[[:space:]]*digest:/ { digest = value($0) }
- END { flush() }
- ' $files
-}
-
-# Runs a scan and prints its output. Status 1 means "no match"; above 1 is a
-# scan error, which must fail the guard instead of reading as "nothing found".
-scan_or_fail() {
- local out status=0
- out="$("$1")" || status=$?
- if [ "$status" -gt 1 ]; then
- printf '%s\n' "$out"
- echo "ERROR: platform NGINX image scan ($1) failed with status $status." >&2
- return 1
+ while IFS= read -r _f; do
+ if ! _entries="$(yq '(.images // [])[] | [line, .name, .newName, .newTag, .digest] | join("|")' "$_f")"; then
+ echo "ERROR: yq could not read the images: entries of $_f" >&2
+ failed=1
+ continue
+ fi
+ while IFS= read -r _e; do
+ if [ -n "$_e" ]; then
+ kustomize_hits="$kustomize_hits$_f|$_e"$'\n'
+ fi
+ done <<<"$_entries"
+ done <<<"$kustomization_list"
+ if [ "$failed" -ne 0 ]; then
+ exit 1
fi
- printf '%s' "$out"
-}
+fi
# Turns scan hits into "path:line<TAB>ref" lines: tagged references as written,
# kustomize images entries composed into newName-or-name[:newTag][@digest].
collect_refs() {
- local hit path rest line token entry name newname newtag digest ref
+ local hit path rest line token name newname newtag digest ref
while IFS= read -r hit; do
[ -n "$hit" ] || continue
path="${hit%%:*}"; rest="${hit#*:}"; line="${rest%%:*}"; token="${rest#*:}"
case "$token" in [!A-Za-z0-9_.-]*) token="${token#?}" ;; esac
split_ref "$token"
+ # "nginx@" has an empty digest: report it before the skip below drops it.
+ if [ "$ref_at" -eq 1 ] && [ -z "$ref_digest" ]; then
+ printf '%s:%s\t%s\n' "$path" "$line" "$token"
+ continue
+ fi
# "nginx:" alone is a YAML key or prose; a '*' tag is a policy glob.
[ -z "$ref_tag" ] && [ -z "$ref_digest" ] && continue
case "$ref_tag" in *'*'*) continue ;; esac
printf '%s:%s\t%s\n' "$path" "$line" "$token"
done <<<"$ref_hits"
- while IFS= read -r entry; do
- [ -n "$entry" ] || continue
- path="${entry%%:*}"; rest="${entry#*:}"; line="${rest%%:*}"; rest="${rest#*:}"
- IFS='|' read -r name newname newtag digest <<<"$rest"
- is_nginx_name "$name" || is_nginx_name "$newname" || continue
+ while IFS='|' read -r path line name newname newtag digest; do
+ [ -n "$path" ] || continue
ref="${newname:-$name}"
+ is_nginx_name "$ref" || continue
if [ -z "$newtag" ] && [ -z "$digest" ]; then
+ # A plain name entry leaves the source tag to the text scan; a rewrite
+ # of another image to NGINX without a tag pulls :latest.
if ! is_nginx_name "$name"; then
printf '%s:%s\t%s\n' "$path" "$line" "$ref:<no newTag>"
fi
@@ -227,12 +206,6 @@ collect_refs() {
done <<<"$kustomize_hits"
}
-if ! ref_hits="$(scan_or_fail scan_refs)"; then failed=1; fi
-if ! untagged_hits="$(scan_or_fail scan_untagged)"; then failed=1; fi
-if ! kustomize_hits="$(scan_or_fail scan_kustomize_images)"; then failed=1; fi
-if [ "$failed" -ne 0 ]; then
- exit 1
-fi
refs="$(collect_refs)"
if [ "${1:-}" = "--list-digest-pins" ]; then
@@ -261,7 +234,12 @@ while IFS= read -r hit; do
[ -n "$hit" ] || continue
echo "ERROR: ${hit%%:*}:$(printf '%s' "${hit#*:}" | cut -d: -f1): untagged NGINX image (implicit :latest)" >&2
bad=1
-done <<<"$untagged_hits"
+done <<<"$untagged_hits"$'\n'"$array_hits"
+while IFS= read -r hit; do
+ [ -n "$hit" ] || continue
+ echo "ERROR: ${hit%%:*}:$(printf '%s' "${hit#*:}" | cut -d: -f1): write the image reference on the same line as image:" >&2
+ bad=1
+done <<<"$image_key_hits"
if [ "$bad" -ne 0 ]; then
echo "ERROR: vulnerable or floating platform NGINX image reference found; use $BASELINE_TEXT." >&2
failed=1
@@ -277,15 +255,15 @@ require_text() {
}
# The egress proxy Dockerfile must have exactly one FROM instruction (Dockerfile
-# instructions are case-insensitive), equal to the fixed image pinned by its
-# multi-arch index digest.
+# instructions are case-insensitive): the fixed image pinned by a multi-arch
+# index digest. verify-nginx-image-digests.sh proves the digest is that release.
require_single_from() {
local path="$1"
- local expected="$2"
- local from_lines
+ local from_lines digest
from_lines="$(grep -iE '^[[:space:]]*FROM[[:space:]]' "$PROJECT_DIR/$path" || true)"
- if [ "$from_lines" != "$expected" ]; then
- echo "ERROR: $path must have exactly one FROM line, '$expected'; found: ${from_lines:-<none>}" >&2
+ digest="${from_lines#"FROM $FIXED_NGINX_IMAGE@"}"
+ if [ "$digest" = "$from_lines" ] || ! [[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]]; then
+ echo "ERROR: $path must have exactly one FROM line, 'FROM $FIXED_NGINX_IMAGE@sha256:<64 hex>'; found: ${from_lines:-<none>}" >&2
return 1
fi
}
@@ -304,11 +282,16 @@ require_text "deploy/base/control-plane/host-context-controller.yaml" "$EGRESS_P
require_text "host-context-controller/src/config.ts" "$EGRESS_PROXY_IMAGE" || failed=1
require_text "control-api/src/routes/admin/registry.ts" "$EGRESS_PROXY_IMAGE" || failed=1
require_text "control-api/src/routes/admin/remoteMcp.ts" "$EGRESS_PROXY_IMAGE" || failed=1
-require_single_from "nginx-egress-proxy/Dockerfile" "FROM ${FIXED_NGINX_IMAGE}@${FIXED_NGINX_IMAGE_DIGEST}" || failed=1
+require_single_from "nginx-egress-proxy/Dockerfile" || failed=1
+
+checked="$(printf '%s\n' "$refs" | grep -c . || true)"
+if [ "$checked" -eq 0 ]; then
+ echo "ERROR: no platform NGINX image reference was checked; the scan read nothing." >&2
+ failed=1
+fi
if [ "$failed" -ne 0 ]; then
exit 1
fi
-checked="$(printf '%s\n' "$refs" | grep -c . || true)"
echo "OK -- platform NGINX images use fixed ${FIXED_NGINX_IMAGE} security baseline ($checked references checked)"