Skip to content

Commit f539730

Browse files
author
Wolfgang Romanowski
committed
Snyk Dockerfile Scan v5 with base image display fix & security vulnerability fix
1 parent 6d7ee33 commit f539730

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

.github/workflows/snyk-dockerfile-scan.yml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Snyk scan for training‑runtime Dockerfiles
2-
# push to main, nightly 03:00 UTC, fork PRs after label `safe-to-test`
2+
# push to main, nightly 03:00UTC, fork PRs after label `run‑snyk`
33
# Fails on High/Critical CVEs
44

5-
name: Snyk Dockerfile Security Scan
5+
name: Snyk Dockerfile Scan
66

77
on:
88
push:
@@ -35,7 +35,7 @@ jobs:
3535
runs-on: ubuntu-latest
3636
if: >
3737
github.event_name != 'pull_request_target' ||
38-
github.event.label.name == 'safe-to-test' ||
38+
github.event.label.name == 'run‑snyk' ||
3939
github.event.pull_request.head.repo.owner.login == github.repository_owner
4040
permissions:
4141
contents: read
@@ -392,6 +392,28 @@ jobs:
392392
run: |
393393
RESULTS_DIR="scan_results"
394394
395+
get_display_name() {
396+
local dockerfile="$1"
397+
local base_image=$(grep -m 1 "^FROM" "$dockerfile" | awk '{print $2}' | sed 's/ AS .*//g')
398+
399+
# Try to resolve ARG variables from the Dockerfile
400+
while IFS= read -r line; do
401+
if [[ "$line" =~ ^ARG[[:space:]]+([^=[:space:]]+)=(.+)$ ]]; then
402+
local var_name="${BASH_REMATCH[1]}"
403+
local var_value="${BASH_REMATCH[2]//[\"\']}"
404+
base_image="${base_image//\$\{$var_name\}/$var_value}"
405+
base_image="${base_image//\$var_name/$var_value}"
406+
fi
407+
done < "$dockerfile"
408+
409+
# If still contains variables, add note for display
410+
if [[ "$base_image" =~ \$\{.*\} ]] || [[ "$base_image" =~ \$[A-Z_]+ ]]; then
411+
echo "$base_image (contains build-time variables)"
412+
else
413+
echo "$base_image"
414+
fi
415+
}
416+
395417
get_base_vulns() {
396418
local json_file="$1"
397419
local count="${2:-999999}"
@@ -698,10 +720,11 @@ jobs:
698720
NEW_LOW=$(get_new_vuln_count "$FULL_SCAN_JSON" "$BASE_SCAN_JSON" "low")
699721
NEW_TOTAL=$((NEW_CRITICAL + NEW_HIGH + NEW_MEDIUM + NEW_LOW))
700722
701-
# Get display name for base image
723+
# Get display name for base image from stored names
702724
DISPLAY_BASE_IMAGE="${BASE_IMAGE_NAMES[$BASE_SCAN_KEY]}"
703725
if [ -z "$DISPLAY_BASE_IMAGE" ]; then
704-
DISPLAY_BASE_IMAGE="$BASE_IMAGE"
726+
# If not found in stored names, generate it directly
727+
DISPLAY_BASE_IMAGE=$(get_display_name "$DOCKERFILE_PATH")
705728
fi
706729
else
707730
NEW_CRITICAL=0; NEW_HIGH=0; NEW_MEDIUM=0; NEW_LOW=0; NEW_TOTAL=0

0 commit comments

Comments
 (0)