ci: support isolated TCP Docker scanners
GeoIntel release gates / Trusted workflow source (pull_request) Canceled after 0s
GeoIntel release gates / Compile, test, contracts and builds (pull_request) Canceled after 0s
GeoIntel release gates / Python and npm vulnerability policy (pull_request) Canceled after 0s
GeoIntel release gates / GIS image, SBOM and container scan (pull_request) Canceled after 0s
GeoIntel release gates / AI image, SBOM and container scan (pull_request) Canceled after 0s

This commit is contained in:
ChatGPT MCP
2026-08-28 18:12:58 +00:00
parent 771cfb9f12
commit 27bc2ebf70
2 changed files with 56 additions and 10 deletions
+27 -5
View File
@@ -5,6 +5,7 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
TARGET_IMAGE="${1:-geointel-ci:local}" TARGET_IMAGE="${1:-geointel-ci:local}"
OUTPUT="${2:-artifacts/geointel-sbom.spdx.json}" OUTPUT="${2:-artifacts/geointel-sbom.spdx.json}"
SYFT_IMAGE="anchore/syft:v1.44.0@sha256:86fde6445b483d902fe011dd9f68c4987dd94e07da1e9edc004e3c2422650de6" SYFT_IMAGE="anchore/syft:v1.44.0@sha256:86fde6445b483d902fe011dd9f68c4987dd94e07da1e9edc004e3c2422650de6"
SCANNER_ENGINE_ARGS=()
case "$OUTPUT" in case "$OUTPUT" in
/*|*..*) /*|*..*)
@@ -13,17 +14,38 @@ case "$OUTPUT" in
;; ;;
esac esac
configure_scanner_engine() {
local docker_host="${DOCKER_HOST:-}"
if [[ "$docker_host" == tcp://* ]]; then
local port="${docker_host##*:}"
if ! [[ "$port" =~ ^[0-9]+$ ]] || (( port < 1 || port > 65535 )); then
echo "Unsupported TCP Docker host for nested scanner: $docker_host" >&2
exit 1
fi
SCANNER_ENGINE_ARGS=(
--add-host host.docker.internal:host-gateway
-e "DOCKER_HOST=tcp://host.docker.internal:${port}"
)
elif [[ -z "$docker_host" || "$docker_host" == unix:///var/run/docker.sock ]]; then
SCANNER_ENGINE_ARGS=(-v /var/run/docker.sock:/var/run/docker.sock)
else
echo "Unsupported Docker host for nested scanner: $docker_host" >&2
exit 1
fi
}
docker image inspect "$TARGET_IMAGE" >/dev/null docker image inspect "$TARGET_IMAGE" >/dev/null
mkdir -p "$ROOT/$(dirname "$OUTPUT")" mkdir -p "$ROOT/$(dirname "$OUTPUT")"
configure_scanner_engine
# Gitea/act executes jobs inside a container while Docker commands target the # Native/local runs use the normal Unix socket. Gitea jobs can target the
# host daemon. Host-path binds to $ROOT therefore do not point at the checkout. # isolated TCP DinD daemon; scanner containers then reach that same daemon via
# Stream the SPDX document over stdout instead; only the Docker socket crosses # Docker's host-gateway alias instead of receiving the Unraid host socket.
# the nested-runner boundary.
docker run --rm \ docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \ "${SCANNER_ENGINE_ARGS[@]}" \
"$SYFT_IMAGE" \ "$SYFT_IMAGE" \
"$TARGET_IMAGE" \ "$TARGET_IMAGE" \
--from docker \
-o spdx-json > "$ROOT/$OUTPUT" -o spdx-json > "$ROOT/$OUTPUT"
test -s "$ROOT/$OUTPUT" test -s "$ROOT/$OUTPUT"
+29 -5
View File
@@ -10,6 +10,7 @@ PYTHON_CMD="${PYTHON_BIN:-python3}"
IGNORE_FILE="$(mktemp)" IGNORE_FILE="$(mktemp)"
CONTAINER_IGNORE_FILE="/tmp/geointel-trivy-ignore.txt" CONTAINER_IGNORE_FILE="/tmp/geointel-trivy-ignore.txt"
POLICY_CONTAINER="" POLICY_CONTAINER=""
SCANNER_ENGINE_ARGS=()
cleanup() { cleanup() {
rm -f "$IGNORE_FILE" rm -f "$IGNORE_FILE"
@@ -26,22 +27,44 @@ case "$OUTPUT" in
;; ;;
esac esac
configure_scanner_engine() {
local docker_host="${DOCKER_HOST:-}"
if [[ "$docker_host" == tcp://* ]]; then
local port="${docker_host##*:}"
if ! [[ "$port" =~ ^[0-9]+$ ]] || (( port < 1 || port > 65535 )); then
echo "Unsupported TCP Docker host for nested scanner: $docker_host" >&2
exit 1
fi
SCANNER_ENGINE_ARGS=(
--add-host host.docker.internal:host-gateway
-e "DOCKER_HOST=tcp://host.docker.internal:${port}"
)
elif [[ -z "$docker_host" || "$docker_host" == unix:///var/run/docker.sock ]]; then
SCANNER_ENGINE_ARGS=(-v /var/run/docker.sock:/var/run/docker.sock)
else
echo "Unsupported Docker host for nested scanner: $docker_host" >&2
exit 1
fi
}
docker image inspect "$TARGET_IMAGE" >/dev/null docker image inspect "$TARGET_IMAGE" >/dev/null
mkdir -p "$ROOT/$(dirname "$OUTPUT")" mkdir -p "$ROOT/$(dirname "$OUTPUT")"
"$PYTHON_CMD" "$ROOT/scripts/verify_security_exceptions.py" "$PYTHON_CMD" "$ROOT/scripts/verify_security_exceptions.py"
"$PYTHON_CMD" "$ROOT/scripts/verify_security_exceptions.py" \ "$PYTHON_CMD" "$ROOT/scripts/verify_security_exceptions.py" \
--print-container-ids > "$IGNORE_FILE" --print-container-ids > "$IGNORE_FILE"
configure_scanner_engine
docker volume create "$CACHE_VOLUME" >/dev/null docker volume create "$CACHE_VOLUME" >/dev/null
# Keep the complete report, including vulnerabilities without an available fix. # Keep the complete report, including vulnerabilities without an available fix.
# Stream JSON over stdout so no checkout path has to be mounted through the # The pinned scanner receives access only to the selected Docker engine. Native
# nested Gitea/act container boundary. # runs use the local socket; Gitea TCP-DinD runs use the daemon's host-gateway.
docker run --rm \ docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \ "${SCANNER_ENGINE_ARGS[@]}" \
-v "$CACHE_VOLUME:/root/.cache/trivy" \ -v "$CACHE_VOLUME:/root/.cache/trivy" \
"$TRIVY_IMAGE" \ "$TRIVY_IMAGE" \
image \ image \
--image-src docker \
--scanners vuln \ --scanners vuln \
--timeout 20m \ --timeout 20m \
--skip-version-check \ --skip-version-check \
@@ -51,12 +74,13 @@ docker run --rm \
# Release policy: fixed HIGH/CRITICAL findings block the build. Unfixed findings # Release policy: fixed HIGH/CRITICAL findings block the build. Unfixed findings
# remain visible in the full report and must be reviewed before release. Copy # remain visible in the full report and must be reviewed before release. Copy
# the verified exception IDs into a stopped scanner container before starting # the verified exception IDs into a stopped scanner container before starting
# it; `docker cp` works when the job checkout itself lives in another container. # it; `docker cp` avoids mounting the job checkout through the nested runner.
POLICY_CONTAINER="$(docker create \ POLICY_CONTAINER="$(docker create \
-v /var/run/docker.sock:/var/run/docker.sock \ "${SCANNER_ENGINE_ARGS[@]}" \
-v "$CACHE_VOLUME:/root/.cache/trivy" \ -v "$CACHE_VOLUME:/root/.cache/trivy" \
"$TRIVY_IMAGE" \ "$TRIVY_IMAGE" \
image \ image \
--image-src docker \
--scanners vuln \ --scanners vuln \
--timeout 20m \ --timeout 20m \
--skip-version-check \ --skip-version-check \