From 3321176b4dff644b43cf8ee69f443e520c682222 Mon Sep 17 00:00:00 2001 From: Josh Knapp Date: Sun, 22 Nov 2026 07:30:19 -0800 Subject: [PATCH] build: pin the Go image by digest; WHP source token via a read-only secret and a credential helper - GO_IMAGE was the floating tag golang:1.27-alpine: now pinned to the index digest sha256:70bd7dde... (resolved 2026-11-22). - The WHP fetch passed the token on git's command line (-c http.extraHeader=...$(cat secret)): now a credential helper reads the BuildKit secret file at fetch time (GIT_TERMINAL_PROMPT=0). Verified on a local build: the token is in no layer blob, not in docker history, not in docker inspect, not in /whp/.git/config, not in the build log. - CI passed CI_TOKEN (registry push rights) as whp_token: now the repo secret WHP_READ_TOKEN (a read-only token for cloud-hosting-platform/whp, to be created by an admin); the workflow fails at its first step with a clear error while it is not set. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6 --- .gitea/workflows/build-push.yaml | 16 ++++++++++++++-- Dockerfile | 18 +++++++++++++----- README.md | 10 ++++++++-- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/.gitea/workflows/build-push.yaml b/.gitea/workflows/build-push.yaml index 099ef2b..03f4f17 100644 --- a/.gitea/workflows/build-push.yaml +++ b/.gitea/workflows/build-push.yaml @@ -14,6 +14,18 @@ jobs: - name: Checkout uses: actions/checkout@v4 + # The image builds whp-scan-scope from the private WHP repo at the pinned WHP_COMMIT. It needs a + # READ-ONLY token scoped to cloud-hosting-platform/whp (repo secret WHP_READ_TOKEN), never the + # registry-push CI_TOKEN. Fail here, clearly, instead of half-way through the build. + - name: Require WHP_READ_TOKEN + env: + WHP_READ_TOKEN: ${{ secrets.WHP_READ_TOKEN }} + run: | + if [ -z "${WHP_READ_TOKEN:-}" ]; then + echo "::error::repo secret WHP_READ_TOKEN is not set: create a read-only token for cloud-hosting-platform/whp and add it as WHP_READ_TOKEN (see README.md)" + exit 1 + fi + # Base image pinned by DIGEST, looked up directly at Docker Hub (never via # the pkg-cache mirror), so the mirror can only serve content-addressed # blobs that BuildKit verifies. If the lookup fails this job does NOT use @@ -116,7 +128,7 @@ jobs: BASE_IMAGE=${{ steps.base.outputs.image }} PKG_CACHE=${{ steps.pkgcache.outputs.url }} secrets: | - whp_token=${{ secrets.CI_TOKEN }} + whp_token=${{ secrets.WHP_READ_TOKEN }} tags: cpanel-importer:smoke no-cache: true @@ -170,7 +182,7 @@ jobs: BASE_IMAGE=${{ steps.base.outputs.image }} PKG_CACHE=${{ steps.pkgcache.outputs.url }} secrets: | - whp_token=${{ secrets.CI_TOKEN }} + whp_token=${{ secrets.WHP_READ_TOKEN }} tags: ${{ steps.tags.outputs.tags }} cache-from: type=registry,ref=repo.anhonesthost.net/cloud-hosting-platform/cpanel-importer:latest cache-to: type=inline diff --git a/Dockerfile b/Dockerfile index 2b9565f..faaa26d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,11 +23,17 @@ ARG BASE_IMAGE=almalinux:10-minimal # scan policy changes. It is currently the merge of WHP PR #331 (limit 256 MiB); # bump it to the merge commit of the WHP PR that raises the limit to 2000 MiB # (feat/scan-scope-2gib) BEFORE publishing an image that is meant to enforce it. -# CI passes the repo token as the BuildKit secret `whp_token` (read access to -# cloud-hosting-platform/whp). For a local build without network access to the +# CI passes a READ-ONLY token for cloud-hosting-platform/whp as the BuildKit +# secret `whp_token` (repo secret WHP_READ_TOKEN: never the registry-push +# CI_TOKEN). The token is handed to git by a credential helper that reads the +# secret file at fetch time: it is never on a command line, in an ENV/ARG, in +# .git/config or in a layer. For a local build without network access to the # repo, override the whole source stage with a checkout: # docker buildx build --build-context whp-src=/path/to/whp-checkout ... -ARG GO_IMAGE=golang:1.27-alpine +# +# GO_IMAGE is pinned by DIGEST (the multi-arch index of golang:1.27-alpine, +# resolved 2026-11-22 from registry-1.docker.io). Bump tag and digest together. +ARG GO_IMAGE=golang:1.27-alpine@sha256:70bd7ddea8b6cbe5d6943cde279d6b67feb10cc924fb9100d1d8757c1575b280 ARG WHP_REPO=https://repo.anhonesthost.net/cloud-hosting-platform/whp.git ARG WHP_COMMIT=e668e25dcdc1938d9d9399ea904daba71c0f0778 @@ -36,12 +42,14 @@ ARG WHP_REPO ARG WHP_COMMIT RUN apk add --no-cache git RUN --mount=type=secret,id=whp_token,required=false \ - set -eu; \ + set -eu; export GIT_TERMINAL_PROMPT=0; \ case "${WHP_COMMIT}" in *[!0-9a-f]*|"") echo "WHP_COMMIT must be a full lowercase hex sha" >&2; exit 1;; esac; \ [ "${#WHP_COMMIT}" -eq 40 ] || { echo "WHP_COMMIT must be 40 hex chars" >&2; exit 1; }; \ git init -q /whp && cd /whp; \ if [ -s /run/secrets/whp_token ]; then \ - git -c "http.extraHeader=Authorization: token $(cat /run/secrets/whp_token)" fetch -q --depth 1 "${WHP_REPO}" "${WHP_COMMIT}"; \ + git -c credential.helper= \ + -c 'credential.helper=!f() { [ "$1" = get ] || exit 0; echo username=whp-read; printf "password=%s\n" "$(cat /run/secrets/whp_token)"; }; f' \ + fetch -q --depth 1 "${WHP_REPO}" "${WHP_COMMIT}"; \ else \ git fetch -q --depth 1 "${WHP_REPO}" "${WHP_COMMIT}"; \ fi; \ diff --git a/README.md b/README.md index b66d8e9..63db790 100644 --- a/README.md +++ b/README.md @@ -79,13 +79,19 @@ named by `userdata`; NOT the mail tree, logs, clean bulk media or plain data out (`oversize_unscanned_files` for clean media/archives: a staff-review warning; `in_scope_unscanned_files` for anything else: the panel refuses the import). `report.json` carries the tool's whole stats object plus the engine fields as its `scan` object; the panel's privd validates it. **No tool, no scan:** a missing or failing -`whp-scan-scope`, or clamscan exit >= 2, fails the run (`status: failed`), there is no fall back to an unscoped scan. +`whp-scan-scope`, clamscan exit >= 2, a summary with `Total errors` > 0 (clamscan exits 1, not 2, when one file is +infected and another could not be read), a hit line that is not an exact entry of the list, a list entry that is not +a plain path below the extract, or a hit that cannot be moved to quarantine fails the run (`status: failed`); there +is no fall back to an unscoped or partial scan. `--tempdir` of clamscan is the disk scratch `/host/sanitized//work/clamtmp` (removed after the scan), never the RAM `/tmp`. Bump `WHP_COMMIT` whenever the WHP scan policy or limits change (it must be a full 40-hex sha). Local build without access to the private repo: `docker buildx build --build-context whp-src=/path/to/whp-checkout -t cpanel-importer:dev .`. -In CI the repo token is the BuildKit secret `whp_token`. +In CI the BuildKit secret `whp_token` comes from the repo secret **`WHP_READ_TOKEN`**: a READ-ONLY token for +`cloud-hosting-platform/whp` (never the registry-push `CI_TOKEN`); the workflow fails at its first step when it is +not set. It reaches git through a credential helper that reads the secret file, so it is never on a command line or +in a layer. The Go build image is pinned by digest (`GO_IMAGE`). Container exits with status `0` on success, non-zero on any failure (missing/unreadable backup, dangerous symlink found, scanner error).