Repository navigation
Add local image secret scanning with cog scan - #3228
markphelps wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
Review summary
cog scan scans every layer of a local Docker image with Gitleaks, fails closed on anything it cannot scan, and has solid unit tests (all pass, including -race).
Findings:
- warning (pkg/scan/scan.go:136): data after the outer tar's end-of-archive marker is silently discarded and reported as clean.
- suggestion (pkg/cli/scan.go:43): Docker client errors are replaced with static messages, losing the underlying error.
Note (already disclosed in the PR description): the 8 MiB per-file / 2 GiB per-layer / 8 GiB total limits mean most real ML model images (weight files are typically far larger than 8 MiB) will report incomplete scan rather than useful results. The fail-closed direction is the right call; the limits themselves need validation before this can scan real images.
|
I'm Bonk, and I've done a quick review of your PR. Summary: Adds Issues (ranked):
Both inline findings were posted as a single COMMENT review (2 comments). |
|
Review: 1 finding. One inline finding posted: |
|
Since last review: 0 resolved, 3 still open, 0 new. The three findings from the previous reviews are all still present at the current head (7b80f19), and commit 7b80f19 (parallel workers) does not touch any of these paths:
I reviewed the new |
|
Since last review: 3 resolved, 0 still open, 0 new. |
|
APIError: Gone: AiError: Model has been deprecated: @cf/deepseek-ai/deepseek-v4-flash-0731 was deprecated on 2026-11-20. See the model catalog for alternatives: https://developers.cloudflare.com/workers-ai/models/ (4a88061f-254a-43ea-b4ac-10104c763fde) |
|
APIError: Gone: AiError: Model has been deprecated: @cf/deepseek-ai/deepseek-v4-flash-0731 was deprecated on 2026-11-20. See the model catalog for alternatives: https://developers.cloudflare.com/workers-ai/models/ (099fb3c8-46e6-4b95-a187-1d1fbaddd3df) |
|
APIError: Gone: AiError: Model has been deprecated: @cf/deepseek-ai/deepseek-v4-flash-0731 was deprecated on 2026-11-20. See the model catalog for alternatives: https://developers.cloudflare.com/workers-ai/models/ (07e74c75-c178-4fcb-941f-1fc85a8cdb0f) |
|
@markphelps Bonk workflow failed. Check the logs for details. View workflow run · To retry, trigger Bonk again. |
|
LGTM |
| // Consume and validate the complete compressed stream (including gzip checksum). | ||
| trailing, err := io.Copy(io.Discard, counted) | ||
| if err != nil { | ||
| return errors.New("incomplete scan: truncated or oversized layer") | ||
| } | ||
| if trailing != 0 { | ||
| return errors.New("incomplete scan: trailing layer data") | ||
| } |
There was a problem hiding this comment.
After tar.Reader returns EOF it has consumed exactly the two zero end-of-archive blocks, but valid tar archives may carry additional zero-block padding (GNU tar writes a full 10 KiB record, and layers imported via docker import can retain it). Those zero bytes cannot contain a secret, yet this check counts them and returns incomplete scan: trailing layer data, so cog scan fails on otherwise valid images. I reproduced this by appending 18 zero blocks to a layer and got incomplete scan: trailing layer data.
Drain the stream and reject only non-zero trailing bytes:
| // Consume and validate the complete compressed stream (including gzip checksum). | |
| trailing, err := io.Copy(io.Discard, counted) | |
| if err != nil { | |
| return errors.New("incomplete scan: truncated or oversized layer") | |
| } | |
| if trailing != 0 { | |
| return errors.New("incomplete scan: trailing layer data") | |
| } | |
| // Consume and validate the complete compressed stream (including gzip checksum). | |
| // tar.Reader stops after the two end-of-archive blocks, but valid archives may | |
| // carry additional zero-block padding (GNU tar, and layers produced via | |
| // docker import). Zero bytes cannot contain a secret, so allow zero padding | |
| // while still rejecting any non-zero trailing data. | |
| trailing := make([]byte, 32<<10) | |
| for { | |
| n, err := counted.Read(trailing) | |
| if err != nil && err != io.EOF { | |
| return errors.New("incomplete scan: truncated or oversized layer") | |
| } | |
| for _, b := range trailing[:n] { | |
| if b != 0 { | |
| return errors.New("incomplete scan: trailing layer data") | |
| } | |
| } | |
| if err == io.EOF { | |
| break | |
| } | |
| } |
A regression test with extra zero blocks would lock this in.
|
I'm Bonk, and I've done a quick review of your PR. Summary: Adds Issues (ranked):
The dispatch/build-first flow, Docker error wrapping, spool/manifest handling, worker concurrency, JSON/exit-code paths, and the manifest-filename constant extraction all looked correct. |
Summary
cog scanandcog scan .to build the current project and scan its immutable image ID.cog scan IMAGEscans an existing local image without building or pulling. Neither mode pushes.--json.Review follow-up
--show-pathsexplicitly reveals local paths.Validation
mise run test:gogo test -race ./pkg/scan -count=1mise run lint:gomise run docs:cli:checkgo test ./pkg/scan -run TestScanDockerSaveWhenAvailable -count=1 -vgo run ./cmd/cog scan alpine:3.20 --jsonreturned{"version":1,"findings":[]}against local Docker.Notes
cog pushor enforce a registry policy.CI and review follow-up
chronoandpin-utils, neither with a safe upgrade.crates/deny.tomlacknowledges only RUSTSEC-2026-0543 and RUSTSEC-2026-0441. This does not remove those dependencies; migration needs separate follow-up.Build-first scanning
--secret,--no-cache, and--file/--config. Build errors stop the scan.