From 6bfa05bf2ece227f4369202adb9bb04fddb9d1dd Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 12 Nov 2026 21:59:10 +0000 Subject: [PATCH 1/2] Verify SHA-256 checksums for yq, grpcurl and stern downloads Previously only kubectl was checksum verified. The other three binaries were fetched over HTTPS with no integrity check, so a tampered release asset would have been baked into the image silently. Each download now goes to /tmp, is verified against the upstream checksums file, and only then installed/extracted. yq publishes a multi-hash table, so the SHA-256 column is located via checksums_hashes_order instead of hard-coding a column index. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_014iDTyB5N8EdZyyZo4ymUVR --- Dockerfile | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4eedb03..ef0c2f1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,27 +42,45 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && rm -rf /var/lib/apt/lists/* # ---- Static binaries -------------------------------------------------------- -# kubectl (checksum verified) +# All binaries below are checksum verified against the upstream release. +# kubectl RUN set -eux; \ curl -fsSLo /usr/local/bin/kubectl "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/${TARGETARCH}/kubectl"; \ echo "$(curl -fsSL "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/${TARGETARCH}/kubectl.sha256") /usr/local/bin/kubectl" | sha256sum -c -; \ chmod +x /usr/local/bin/kubectl -# yq (YAML processor) +# yq (YAML processor). The checksums file lists many hash algorithms per binary; +# the column for SHA-256 is found via checksums_hashes_order. RUN set -eux; \ - curl -fsSLo /usr/local/bin/yq "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${TARGETARCH}"; \ - chmod +x /usr/local/bin/yq + base="https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}"; \ + curl -fsSLo /tmp/yq "${base}/yq_linux_${TARGETARCH}"; \ + col="$(curl -fsSL "${base}/checksums_hashes_order" | grep -nx 'SHA-256' | cut -d: -f1)"; \ + want="$(curl -fsSL "${base}/checksums" | awk -v f="yq_linux_${TARGETARCH}" -v c="$((col + 1))" '$1 == f {print $c}')"; \ + test -n "$want"; \ + echo "${want} /tmp/yq" | sha256sum -c -; \ + install -m 0755 /tmp/yq /usr/local/bin/yq; \ + rm -f /tmp/yq -# grpcurl (gRPC debugging; release uses x86_64 / arm64 naming) +# grpcurl (gRPC debugging; release uses x86_64 / arm64 naming), checksum verified RUN set -eux; \ case "${TARGETARCH}" in amd64) A=x86_64;; arm64) A=arm64;; *) echo "unsupported arch ${TARGETARCH}"; exit 1;; esac; \ - curl -fsSL "https://github.com/fullstorydev/grpcurl/releases/download/v${GRPCURL_VERSION}/grpcurl_${GRPCURL_VERSION}_linux_${A}.tar.gz" \ - | tar -xz -C /usr/local/bin grpcurl + base="https://github.com/fullstorydev/grpcurl/releases/download/v${GRPCURL_VERSION}"; \ + f="grpcurl_${GRPCURL_VERSION}_linux_${A}.tar.gz"; \ + curl -fsSLo "/tmp/${f}" "${base}/${f}"; \ + curl -fsSL "${base}/grpcurl_${GRPCURL_VERSION}_checksums.txt" | grep " ${f}\$" > /tmp/grpcurl.sha256; \ + (cd /tmp && sha256sum -c grpcurl.sha256); \ + tar -xz -C /usr/local/bin -f "/tmp/${f}" grpcurl; \ + rm -f "/tmp/${f}" /tmp/grpcurl.sha256 -# stern (multi-pod log tailing) +# stern (multi-pod log tailing), checksum verified RUN set -eux; \ - curl -fsSL "https://github.com/stern/stern/releases/download/v${STERN_VERSION}/stern_${STERN_VERSION}_linux_${TARGETARCH}.tar.gz" \ - | tar -xz -C /usr/local/bin stern + base="https://github.com/stern/stern/releases/download/v${STERN_VERSION}"; \ + f="stern_${STERN_VERSION}_linux_${TARGETARCH}.tar.gz"; \ + curl -fsSLo "/tmp/${f}" "${base}/${f}"; \ + curl -fsSL "${base}/checksums.txt" | grep " ${f}\$" > /tmp/stern.sha256; \ + (cd /tmp && sha256sum -c stern.sha256); \ + tar -xz -C /usr/local/bin -f "/tmp/${f}" stern; \ + rm -f "/tmp/${f}" /tmp/stern.sha256 # ---- Shell experience ------------------------------------------------------- COPY motd.txt /etc/motd From 890e2a8c945cffe683ded3aaa9329ef43ed99164 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 12 Nov 2026 22:05:58 +0000 Subject: [PATCH 2/2] Avoid `cd` in checksum verification (hadolint DL3003) The grpcurl and stern blocks used `(cd /tmp && sha256sum -c ...)`, which hadolint flags as DL3003. Look up the expected hash with awk and verify by absolute path instead, as the yq block already does. This also drops the temporary .sha256 files. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_014iDTyB5N8EdZyyZo4ymUVR --- Dockerfile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index ef0c2f1..88b23e7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -67,20 +67,22 @@ RUN set -eux; \ base="https://github.com/fullstorydev/grpcurl/releases/download/v${GRPCURL_VERSION}"; \ f="grpcurl_${GRPCURL_VERSION}_linux_${A}.tar.gz"; \ curl -fsSLo "/tmp/${f}" "${base}/${f}"; \ - curl -fsSL "${base}/grpcurl_${GRPCURL_VERSION}_checksums.txt" | grep " ${f}\$" > /tmp/grpcurl.sha256; \ - (cd /tmp && sha256sum -c grpcurl.sha256); \ + want="$(curl -fsSL "${base}/grpcurl_${GRPCURL_VERSION}_checksums.txt" | awk -v f="${f}" '$2 == f {print $1}')"; \ + test -n "$want"; \ + echo "${want} /tmp/${f}" | sha256sum -c -; \ tar -xz -C /usr/local/bin -f "/tmp/${f}" grpcurl; \ - rm -f "/tmp/${f}" /tmp/grpcurl.sha256 + rm -f "/tmp/${f}" # stern (multi-pod log tailing), checksum verified RUN set -eux; \ base="https://github.com/stern/stern/releases/download/v${STERN_VERSION}"; \ f="stern_${STERN_VERSION}_linux_${TARGETARCH}.tar.gz"; \ curl -fsSLo "/tmp/${f}" "${base}/${f}"; \ - curl -fsSL "${base}/checksums.txt" | grep " ${f}\$" > /tmp/stern.sha256; \ - (cd /tmp && sha256sum -c stern.sha256); \ + want="$(curl -fsSL "${base}/checksums.txt" | awk -v f="${f}" '$2 == f {print $1}')"; \ + test -n "$want"; \ + echo "${want} /tmp/${f}" | sha256sum -c -; \ tar -xz -C /usr/local/bin -f "/tmp/${f}" stern; \ - rm -f "/tmp/${f}" /tmp/stern.sha256 + rm -f "/tmp/${f}" # ---- Shell experience ------------------------------------------------------- COPY motd.txt /etc/motd