Skip to content

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

TypeScript

fix(nginx): reject glob tags, tagged newName, COPY --from and YAML node properties

Alfredo Lopez4836f569ae95
diff --git a/scripts/tests/test-validate-nginx-images.sh b/scripts/tests/test-validate-nginx-images.sh
index 7c165c0ac..6d80801e2 100755
--- a/scripts/tests/test-validate-nginx-images.sh
+++ b/scripts/tests/test-validate-nginx-images.sh
@@ -227,13 +227,15 @@ done
# 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
+ '"image": "nginx",' '--image=nginx' 'IMAGE=nginx' "image: 'nginx'" 'image: &web_image nginx' \
+ 'image: !!str nginx' 'image: !!str &web "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
+for line in 'FROM nginx' 'from nginx AS b' 'FROM --platform=$P nginx' 'COPY --from=nginx /usr/sbin/nginx /x' \
+ 'copy --from="nginx" /a /b' 'RUN --mount=type=bind,from=nginx,target=/n true' 'RUN --mount=from=nginx,target=/n true'; do
inject_text "$E2E_DOCKERFILE_REL" "$line"
expect_fail_naming "untagged $line" "$E2E_DOCKERFILE_REL:1: " "$UNTAGGED"
rm -f "$COPY/$E2E_DOCKERFILE_REL"
@@ -273,11 +275,19 @@ 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 image in nginx-egress-proxy clerum/nginx-egress-proxy:0.1.0 'nginx:'; do
inject "$SAMPLE_REL" "$image"
expect_pass "non-reference string $image" 0
rm -f "$COPY/$SAMPLE_REL"
done
+# A '*' tag is a glob, never a fixed release, wherever it is written.
+inject "$SAMPLE_REL" 'nginx:*'
+expect_fail_naming "glob tag nginx:* in a recipe sample" "$SAMPLE_REL:1: " "$NOT_FIXED"
+rm -f "$COPY/$SAMPLE_REL"
+# shellcheck disable=SC2016 # the variable is injected literally
+inject_text "$E2E_REL" 'PUBLIC_IMAGES=("nginx:${NGINX_TAG:-1.30.*}")'
+expect_fail_naming "variable tag with a glob default in a shell script" "$E2E_REL:1: " "$NOT_FIXED"
+rm -f "$COPY/$E2E_REL"
for line in "id: 'nginx'" "if name == 'nginx'"; do
inject_text "$SAMPLE_REL" "$line"
expect_pass "non-reference line $line" 0
@@ -330,6 +340,12 @@ inject_kustomize $'images:\n - name: clerum/gateway\n newName: docker.io/lib
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: example/web\n newName: "ngin\\u0078:1.30.5-alpine"'
+expect_fail_naming "kustomize escaped newName carrying a tag below the baseline" "$KUSTOMIZE_REL:4: nginx:1.30.5-alpine: " "$BELOW"
+inject_kustomize $'images:\n- name: nginx\n newName: nginx:1.30.5-alpine'
+expect_fail_naming "kustomize newName carrying a tag below the baseline" "$KUSTOMIZE_REL:4: nginx:1.30.5-alpine: " "$BELOW"
+inject_kustomize $'images:\n- name: example/web\n newName: nginx:1.30.5-alpine\n newTag: 1.30.6-alpine'
+expect_fail_naming "kustomize tagged newName plus newTag" "$KUSTOMIZE_REL:4: nginx:1.30.5-alpine:1.30.6-alpine: " "$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"
@@ -338,6 +354,8 @@ inject_kustomize $'images:\n- name: nginx\n newTag: 1.30.6-alpine # fixed basel
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: example/web\n newName: "ngin\\u0078:1.30.6-alpine"'
+expect_pass "kustomize escaped newName carrying the baseline tag" 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'
diff --git a/scripts/validate-nginx-images.sh b/scripts/validate-nginx-images.sh
index 6373f8eaf..840cc9824 100755
--- a/scripts/validate-nginx-images.sh
+++ b/scripts/validate-nginx-images.sh
@@ -18,8 +18,10 @@
# 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.
+# --image=, IMAGE=, after an optional YAML anchor or tag), a Dockerfile FROM or
+# COPY --from= / --mount=...,from= source, and a shell array element in *.sh
+# files; an image: key whose value is not on the same line is rejected. A name
+# reached through indirection (a YAML alias, a shell variable) is not resolved.
#
# --list-digest-pins print every tag@digest reference and exit
# (input for verify-nginx-image-digests.sh)
@@ -49,10 +51,14 @@ QUOTE="[\"']"
# 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"
+# An untagged NGINX image (implicitly :latest) in an image field (after an
+# optional YAML anchor or tag such as &img or !!str), a Dockerfile FROM
+# (keywords in any case, optional --flag=value words), or a Dockerfile
+# COPY --from= / RUN --mount=...,from= source.
+YAML_NODE_PROPERTIES='([&!][^[:space:]]*[[:space:]]+)*'
+NGINX_UNTAGGED_REGEX="[Ii][Mm][Aa][Gg][Ee]$QUOTE?[[:space:]]*[:=][[:space:]]*$YAML_NODE_PROPERTIES$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"
+NGINX_UNTAGGED_REGEX="$NGINX_UNTAGGED_REGEX|(--|[,=])[Ff][Rr][Oo][Mm]=$QUOTE?$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:])]|\$)"
@@ -172,7 +178,7 @@ 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 name newname newtag digest ref
+ local hit path rest line token name newname newtag digest ref last repo
while IFS= read -r hit; do
[ -n "$hit" ] || continue
path="${hit%%:*}"; rest="${hit#*:}"; line="${rest%%:*}"; token="${rest#*:}"
@@ -183,16 +189,18 @@ collect_refs() {
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.
+ # "nginx:" alone is a YAML key or prose.
[ -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 path line name newname newtag digest; do
[ -n "$path" ] || continue
ref="${newname:-$name}"
- is_nginx_name "$ref" || continue
- if [ -z "$newtag" ] && [ -z "$digest" ]; then
+ # newName may carry its own tag or digest; classify the repository part.
+ last="${ref##*/}"
+ repo="${ref%"$last"}${last%%[:@]*}"
+ is_nginx_name "$repo" || continue
+ if [ "$ref" = "$repo" ] && [ -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