Scan only the WHP scan scope (whp-scan-scope + clamscan --file-list) and attest it in report.json #2

Merged
jknapp merged 5 commits from feat/whp-scan-scope into main 2026-11-22 21:00:44 +00:00
Owner

Implements section E of the WHP change request (docs/go-port/cpimport-importer-image-change-request.md) with the 2000 MiB limit Josh approved on 2026-11-22. Companion WHP PR: cloud-hosting-platform/whp feat/scan-scope-2gib (limit 256 MiB -> 2000 MiB).

What the image does now

  1. Dockerfile: multi-stage build of whp-scan-scope (Go 1.27 alpine, CGO off, stdlib only, GOPROXY=off) from a pinned commit of the WHP repo (ARG WHP_COMMIT, full 40-hex sha, verified after fetch). Currently the merge of WHP #331 (e668e25dc, limit still 256 MiB): bump it to the merge commit of the WHP 2000 MiB PR before publishing an image meant to enforce 2000 MiB. The repo is private: CI passes CI_TOKEN as the BuildKit secret whp_token (assumption: that token can read cloud-hosting-platform/whp); local builds use --build-context whp-src=<checkout>.
  2. scan-files.php: whp-scan-scope --extract … --file-list /tmp/scan.list --stats /tmp/scan-scope.json [--skip-mail], then nice -n 19 ionice -c3 clamscan --infected --stdout --file-list=… --max-filesize=2000M --max-scansize=4000M --max-scantime=0 --max-recursion=8 --max-files=10000 --alert-exceeds-max=yes --tempdir=<disk scratch>. Hits are parsed from the output as before; quarantine is unchanged.
  3. Fail closed: tool missing/not startable, non-zero exit, unusable stats, clamscan exit >= 2, or 0 loaded signatures -> exit 1 -> the entrypoint dies -> status: failed. There is no fall back to the old unscoped scan.
  4. Attestation: the tool's whole stats object plus engine_version and signature_db_version (from clamscan --version), signatures_loaded ("Known viruses:") and clamscan_exit becomes report.json scan. Note the old image wrote no scan object at all (privd judged from the log); this adds the whole object. Empty skipped_by_class stays {}.
  5. clamscan's --tempdir is $SANITIZED_DIR/work/clamtmp on the disk-backed mount (the RAM /tmp would count against --memory 2g when archives unpack), removed after the scan. scan-files.php no longer uses is_executable probes (open_basedir refuses them: found by the end-to-end run, which failed closed as designed).

Tests

  • tests/run-tests.sh (host side, stub clamscan, real tool): 153 checks, ALL PASS, incl. fail-closed cases (tool missing / exits 3 / junk stats / clamscan exit 2 / 0 signatures / no clamscan) and a mutation check that dropping the exit >= 2 guard fails one.
  • tests/build-scope-tree.sh: synthetic tree with the polyglot JPEG+php, small clean media under a web root, a web-root symlink to ~/tmp/work/payload.txt, a docroot under ~/tmp (from userdata), an .htaccess handler directory, an uploads dir, mail, logs, a 22 MB clean mp4, EICAR, and a sparse 2001 MiB mp4.
  • tests/image-scope-test.sh <image> (CI runs it on the smoke image): real entrypoint with the panel's flags (--read-only --user 999:999 --cap-drop=ALL --memory 2g --tmpfs /tmp), real ClamAV 1.4.6 and signatures. Result: exit 0; EICAR quarantined; polyglot still present (scanned, no signature); huge.mp4 in oversize_unscanned_files; in_scope_unscanned 0; scratch removed. ALL PASS (about 50 s).
  • privd validation: the resulting report.json was decoded with the WHP phparray and passed to scanAttested (privd sandboxreport.go/checkScope): attested with require_scan_scope false and true (scanned=11 skipped=6 oversize=1, name preserved); refused when the mail tree is skipped but mail was not included (as designed).
  • Local image build with docker: ok (cpanel-importer:scope-test, not pushed).

CI / publishing

The workflow only publishes on pushes to main and version tags, so this PR publishes nothing. Do not merge to main until the WHP PR is merged and WHP_COMMIT is bumped to its merge commit: a push to main retags :latest, which hosts pull.

Enabling (WHP side)

  1. Merge the WHP PR; bump WHP_COMMIT here to its merge commit; merge this PR (or publish a TEST tag from a branch build).
  2. Publish under a test tag; pull it on the canary host only; run a canary import with a synthetic backup; confirm the results page/report shows the scope (scan.policy code-risky-v1) and the oversize warning behaves.
  3. Then publish :latest/pin the digest in privd.json for the fleet, and only after a successful import per host set require_scan_scope: true.

Risks

  • Throughput: about 20-30 MB/s measured here, so many multi-GB videos could approach the 7200 s sandbox timeout (the run then fails, fail-closed).
  • A file that exceeds a ClamAV limit is reported as a detection and quarantined (not copied to the customer's site): loud, but it removes a legitimate file.
  • ClamAV 1.4 cannot scan >= 2 GiB, so 2 GiB+ files stay refused or warned; the limit cannot be raised further.
  • CI secret assumption (CI_TOKEN reads the private WHP repo) is untested; the workflow edit is untested in Gitea (only builds on main).
  • This PR edits existing PHP in the image (scan-files.php, entrypoint.sh inline report merge); no new PHP files.

🤖 Generated with Claude Code

https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6

Implements section E of the WHP change request (`docs/go-port/cpimport-importer-image-change-request.md`) with the 2000 MiB limit Josh approved on 2026-11-22. Companion WHP PR: cloud-hosting-platform/whp `feat/scan-scope-2gib` (limit 256 MiB -> 2000 MiB). ## What the image does now 1. **Dockerfile**: multi-stage build of `whp-scan-scope` (Go 1.27 alpine, CGO off, stdlib only, `GOPROXY=off`) from a **pinned commit** of the WHP repo (`ARG WHP_COMMIT`, full 40-hex sha, verified after fetch). Currently the merge of WHP #331 (`e668e25dc`, limit still 256 MiB): **bump it to the merge commit of the WHP 2000 MiB PR before publishing an image meant to enforce 2000 MiB.** The repo is private: CI passes `CI_TOKEN` as the BuildKit secret `whp_token` (assumption: that token can read `cloud-hosting-platform/whp`); local builds use `--build-context whp-src=<checkout>`. 2. **scan-files.php**: `whp-scan-scope --extract … --file-list /tmp/scan.list --stats /tmp/scan-scope.json [--skip-mail]`, then `nice -n 19 ionice -c3 clamscan --infected --stdout --file-list=… --max-filesize=2000M --max-scansize=4000M --max-scantime=0 --max-recursion=8 --max-files=10000 --alert-exceeds-max=yes --tempdir=<disk scratch>`. Hits are parsed from the output as before; quarantine is unchanged. 3. **Fail closed**: tool missing/not startable, non-zero exit, unusable stats, clamscan exit >= 2, or 0 loaded signatures -> `exit 1` -> the entrypoint dies -> `status: failed`. There is no fall back to the old unscoped scan. 4. **Attestation**: the tool's whole stats object plus `engine_version` and `signature_db_version` (from `clamscan --version`), `signatures_loaded` ("Known viruses:") and `clamscan_exit` becomes `report.json` `scan`. Note the old image wrote no `scan` object at all (privd judged from the log); this adds the whole object. Empty `skipped_by_class` stays `{}`. 5. clamscan's `--tempdir` is `$SANITIZED_DIR/work/clamtmp` on the disk-backed mount (the RAM `/tmp` would count against `--memory 2g` when archives unpack), removed after the scan. `scan-files.php` no longer uses `is_executable` probes (open_basedir refuses them: found by the end-to-end run, which failed closed as designed). ## Tests - `tests/run-tests.sh` (host side, stub clamscan, real tool): 153 checks, ALL PASS, incl. fail-closed cases (tool missing / exits 3 / junk stats / clamscan exit 2 / 0 signatures / no clamscan) and a mutation check that dropping the exit >= 2 guard fails one. - `tests/build-scope-tree.sh`: synthetic tree with the polyglot JPEG+php, small clean media under a web root, a web-root symlink to `~/tmp/work/payload.txt`, a docroot under `~/tmp` (from userdata), an `.htaccess` handler directory, an uploads dir, mail, logs, a 22 MB clean mp4, EICAR, and a sparse 2001 MiB mp4. - `tests/image-scope-test.sh <image>` (CI runs it on the smoke image): real entrypoint with the panel's flags (`--read-only --user 999:999 --cap-drop=ALL --memory 2g --tmpfs /tmp`), real ClamAV 1.4.6 and signatures. Result: exit 0; EICAR quarantined; polyglot still present (scanned, no signature); huge.mp4 in `oversize_unscanned_files`; `in_scope_unscanned` 0; scratch removed. ALL PASS (about 50 s). - **privd validation**: the resulting `report.json` was decoded with the WHP `phparray` and passed to `scanAttested` (privd `sandboxreport.go`/`checkScope`): attested with `require_scan_scope` false and true (scanned=11 skipped=6 oversize=1, name preserved); refused when the mail tree is skipped but mail was not included (as designed). - Local image build with docker: ok (`cpanel-importer:scope-test`, not pushed). ## CI / publishing The workflow only publishes on pushes to `main` and version tags, so this PR publishes nothing. **Do not merge to main until the WHP PR is merged and `WHP_COMMIT` is bumped to its merge commit**: a push to main retags `:latest`, which hosts pull. ## Enabling (WHP side) 1. Merge the WHP PR; bump `WHP_COMMIT` here to its merge commit; merge this PR (or publish a TEST tag from a branch build). 2. Publish under a test tag; pull it on the canary host only; run a canary import with a synthetic backup; confirm the results page/report shows the scope (`scan.policy` code-risky-v1) and the oversize warning behaves. 3. Then publish `:latest`/pin the digest in privd.json for the fleet, and only after a successful import per host set `require_scan_scope: true`. ## Risks - Throughput: about 20-30 MB/s measured here, so many multi-GB videos could approach the 7200 s sandbox timeout (the run then fails, fail-closed). - A file that exceeds a ClamAV limit is reported as a detection and quarantined (not copied to the customer's site): loud, but it removes a legitimate file. - ClamAV 1.4 cannot scan >= 2 GiB, so 2 GiB+ files stay refused or warned; the limit cannot be raised further. - CI secret assumption (`CI_TOKEN` reads the private WHP repo) is untested; the workflow edit is untested in Gitea (only builds on main). - This PR edits existing PHP in the image (`scan-files.php`, `entrypoint.sh` inline report merge); no new PHP files. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
jknapp added 1 commit 2026-11-22 15:05:59 +00:00
- Dockerfile: multi-stage Go build of whp-scan-scope (CGO off, stdlib only) from a PINNED
  commit of the WHP repo (ARG WHP_COMMIT, currently the merge of WHP #331; bump it to the merge
  of the 2000 MiB limit PR before publishing an image meant to enforce it). Private repo: the
  BuildKit secret whp_token in CI; --build-context whp-src=<checkout> for local builds.
- scan-files.php: whp-scan-scope -> /tmp/scan.list + stats, then clamscan --file-list with
  --max-filesize=2000M --max-scansize=4000M --max-scantime=0 --alert-exceeds-max=yes --tempdir on
  the disk scratch. A missing/failing tool, clamscan exit >= 2 or 0 loaded signatures is FATAL
  (no fall back to an unscoped scan). Writes the attestation (the tool's stats + engine_version,
  signature_db_version, signatures_loaded, clamscan_exit).
- entrypoint.sh: passes --attestation/--scratch, removes the scratch, embeds the attestation as
  report.json "scan" (objects kept as objects).
- Tests: tests/run-tests.sh (stub clamscan, real tool, fail-closed cases), tests/build-scope-tree.sh
  (polyglot, web-root symlink, docroot under tmp, handler dir, uploads, EICAR, sparse 2001 MiB mp4),
  tests/image-scope-test.sh (end to end on the built image; CI runs it).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
jknapp added 2 commits 2026-11-22 15:30:21 +00:00
Review of the scan-scope change (measured on ClamAV 1.4.6 in this image):
- clamscan exits 1, not 2, when one listed file is infected and another
  cannot be read: only the summary says "Total errors: 1". A mode-000
  webshell next to any detected file went unscanned and the run passed
  (privd accepted the attestation, require_scan_scope=true included).
  Now: a summary with Total errors > 0, or no summary at all, fails the run.
- Every hit line must name an EXACT entry of the scan list (the last ": "
  ends the path; signature names never contain one); anything else fails
  the run instead of being skipped.
- The list itself is checked before clamscan sees it: each entry a plain
  absolute path below the extract, <= 1022 bytes, no control character,
  and exactly files_scanned entries.
- A hit that cannot be moved to quarantine fails the run (it used to log a
  WARN and leave the infected file in the tree to be imported). Duplicate
  hits (a link target listed twice) are one action.
- Tests: names with ': ' + ' FOUND', leading '-', \n, \r, >= 1023 bytes;
  rogue hit, Total errors, no summary, unquarantinable hit, list longer
  than files_scanned, entry outside the extract (red on the old script);
  image-scope-test.sh runs a mode-000 file next to EICAR end to end.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
- 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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
jknapp added 1 commit 2026-11-22 15:34:13 +00:00
It was logged as a WARN and dropped from the report: a web-root link
into a Maildir (x.php -> ../mail/<d>/<u>/cur/<msg>) got the message
listed as the link's target, and an infected message vanished from what
privd sees. Now fatal (the message is still never moved out of the
Maildir). whp-scan-scope (WHP #334) refuses such links by name as well.
Tests: relative, absolute and chained web-root links to an EICAR message
(red on the pre-review script with the pre-review tool), and a listed
mail-tree hit (red on the pre-review script).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
jknapp added 1 commit 2026-11-22 15:37:56 +00:00
whp-scan-scope with the 2000 MiB limit and the review fixes (unreadable
files, control characters, >= 1023-byte paths and web-root links into
the skipped mail tree refused by name). Verified: full build through the
fetch path with a token secret (token in no layer, history, inspect or
build log), tests/run-tests.sh and tests/image-scope-test.sh ALL PASS on
the built image.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
jknapp merged commit 54d027e94a into main 2026-11-22 21:00:44 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: cloud-hosting-platform/cpanel-importer#2