oficina / equipo Public

hosted: bind image scan allowances to rule and bytes

The release dry run's payload scan refused 158 findings: Go toolchain
test vectors and test keys, OpenSSH's PROTOCOL.key document, and two in
the runner. The runner's two are not secrets: gitleaks' own default rule
for Bedrock keys (a fixed prefix, base64 of bedrock.amazonaws.com) linked
into the runner's scanner, and golang.org/x/oauth2's h1: module checksum
in the Go build information.

A ScanAllow entry now names the rule it excuses as well as the input and
member, and binds bytes: the member's SHA-256 for a pinned input, or for
a binary built here (its bytes change every commit) the matched text's
SHA-256 alone. A finding carries the match's digest, never its text. An
oversized member's finding is bound to its container's digest. The
checked-in manifest lists 72 reviewed entries, each with a reason.

TestCheckedInScanAllow holds the list to that shape and refuses a new
member, rule, digest or runner match; TestScanAssembledInputs (given a
release bundle) builds the real inputs and refuses a planted key.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 9b36915c619f0fdab81c0359c3b8845f77d309e8 parent 801a311
11 files changed, +904 −35
  • Makefile +5 −3
  • cmd/equipo-hosted-image/main_test.go +4 −2
  • docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md +21 −0
  • infra/hosted/image/manifest.json +506 −1
  • internal/hostedimage/assemble_test.go +3 −0
  • internal/hostedimage/manifest.go +19 −4
  • internal/hostedimage/manifest_test.go +41 −4
  • internal/hostedimage/nested.go +4 −2
  • internal/hostedimage/scan.go +44 −12
  • internal/hostedimage/scan_test.go +118 −7
  • internal/hostedimage/scanallow_test.go +139 −0

CI failed — run details

CI log
=== prepare ===
ci-box: machine: aarch64, 32 CPUs, 62 GiB memory, kernel 7.0.0-1017-aws
ci-box: python 3.12.3; Docker version 29.1.3, build 29.1.3-0ubuntu3~24.04.2
ci-box: user namespaces allowed: 233151
ci-box: cgroup: cgroup2fs
ci-box: disk /home/ci/work/repos/oficina__equipo/wt/hosted-runners-2: Type  Size Avail | ext4   96G   84G
ci-box: disk /home/ci/.cache/equipo-ci-box: Type  Size Avail | ext4   96G   84G
ci-box: bwrap: fetched and verified in 0.3s
ci-box: claude: fetched and verified in 2.1s
ci-box: codex: fetched and verified in 4.7s
ci-box: codex-code-mode-host: fetched and verified in 1.8s
ci-box: libwrap: fetched and verified in 0.3s
ci-box: socat: fetched and verified in 0.4s
ci-box: tofu: fetched and verified in 2.0s
npm warn deprecated node-domexception@1.0.0: Use your platform's native DOMException instead
ci-box: image pulled in 9.8s
ci-box: pi: installed and verified in 7.4s
ci-box: opencode: installed and verified in 2.3s
ci-box: chromium 156.0.8078.79-1~deb13u1: 76 packages fetched, verified and unpacked in 9.5s
ci-box: clone deepened in 5.0s
ci-box: file times set from content: 4051 files, 303 directories
ci-box: ready in 19.7s
=== copy ===
EQUIPO_RELEASE_COPY_CHECK=1 CGO_ENABLED=0 go test ./internal/equipotest -run '^TestReleaseCopyReviewed$' -count=1
--- FAIL: TestReleaseCopyReviewed (0.09s)
    task_pages_test.go:236: COPY REVIEW REQUIRED: copy-status.py verify found copy pending review or stale bookkeeping
FAIL
rastrillo-budget/v1 ran 88ms
FAIL	amadan.net/oficina/equipo/internal/equipotest	0.241s
FAIL
make: *** [Makefile:324: copy-release-check] Error 1

amadan: step copy failed: exit status 2

amadan: job failed at step copy — its output is above, not at the tail of this log
diff --git a/Makefile b/Makefile
index 9bfdbe99..c7088ee8 100644
--- a/Makefile
+++ b/Makefile
@@ -235,11 +235,13 @@ gitleaks:
# payload scan refusing a secret or forbidden path inside a pinned binary,
# tarball or RPM, and bubblewrap installed where the containment suite
# runs it. The real payloads are scanned by the build itself
-# (equipo-hosted-image build), with this repository's .gitleaks.toml. No
-# AWS call. .amadan/ci.d/15-hosted-image runs it on CI.
+# (equipo-hosted-image build), with this repository's .gitleaks.toml;
+# TestScanAssembledInputs repeats that over a release's bundle when
+# EQUIPO_HOSTED_IMAGE_BUNDLE names one. No AWS call.
+# .amadan/ci.d/15-hosted-image runs it on CI.
hosted-image-check:
go run $(GITLEAKS) dir --no-banner --redact --config .gitleaks.toml infra/hosted/image
- CGO_ENABLED=0 go test ./internal/hostedimage -run '^(TestManifestPinsEverything|TestBuildReproducible|TestBuildChecksPins|TestImageInputsHaveNoSecrets|TestBuildScansPayload|TestScanAllowExact|TestBuildNeedsGitleaksConfig|TestImageLayoutMatchesContainmentSuite|TestScanIgnoresGitleaksAllowances|TestScanRPMScriptlets|TestScanNestedArchives|TestScanPathRules|TestScanV7Tar|TestRPMExpansionBudget)$$' -count=1
+ CGO_ENABLED=0 go test ./internal/hostedimage -run '^(TestManifestPinsEverything|TestBuildReproducible|TestBuildChecksPins|TestImageInputsHaveNoSecrets|TestBuildScansPayload|TestScanAllowExact|TestScanAllowBindsRule|TestScanAllowMatchDigest|TestScanOverLimitBoundToContainer|TestCheckedInScanAllow|TestBuildNeedsGitleaksConfig|TestImageLayoutMatchesContainmentSuite|TestScanIgnoresGitleaksAllowances|TestScanRPMScriptlets|TestScanNestedArchives|TestScanPathRules|TestScanV7Tar|TestRPMExpansionBudget)$$' -count=1
# hosted-infra-check is the OpenTofu for the hosted stack (infra/hosted):
# plan-check.py's tests on fresh-plan fixtures, then each root formatted,
diff --git a/cmd/equipo-hosted-image/main_test.go b/cmd/equipo-hosted-image/main_test.go
index 9a804f66..fa64a844 100644
--- a/cmd/equipo-hosted-image/main_test.go
+++ b/cmd/equipo-hosted-image/main_test.go
@@ -288,7 +288,9 @@ func TestAssembleThenBuildFromBundle(t *testing.T) {
for _, n := range hostedimage.BuiltInputs {
put(filepath.Join(built, n), []byte("built "+n))
}
- // The checked-in manifest, with this test's bubblewrap and codex.
+ // The checked-in manifest, with this test's bubblewrap and codex, and
+ // no allowances: those are the real inputs' reviewed findings, and
+ // these made-up inputs have none.
src := filepath.Join(dir, "src")
raw, err := os.ReadFile("../../infra/hosted/image/manifest.json")
if err != nil {
@@ -298,7 +300,7 @@ func TestAssembleThenBuildFromBundle(t *testing.T) {
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
- m["BubblewrapSHA256"], m["CodexSHA256"] = bwrapSum, codexSum
+ m["BubblewrapSHA256"], m["CodexSHA256"], m["ScanAllow"] = bwrapSum, codexSum, []any{}
mb, _ := json.Marshal(m)
put(filepath.Join(src, "manifest.json"), mb)
tmpl, _ := os.ReadFile("../../infra/hosted/image/Dockerfile.tmpl")
diff --git a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
index c0728a72..5826f724 100644
--- a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
+++ b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
@@ -3208,3 +3208,24 @@ Mutation checks (`CGO_ENABLED=0 go test ./<pkg> -run <Test> -count=1`, restored
Upstream pins filled in infra/hosted/release-pins.json (HostAMI eu-west-1, BaseImageVersion 4) and infra/hosted/image/pins.json (23 AL2023 2023.12.20261102 RPMs, GitSHA256, resolver 169.254.169.253); bubblewrap and codex keep no URL (no URL serves the pinned member bytes; a release passes them with `--image-inputs`). Full sources and verification: .superpowers/sdd/2026-11-30-hosted-runners-slice-2/pins-report.md.
- `TestAssembleThenBuildFromBundle` now runs the checked-in pins without `-have` and requires "bubblewrap has no URL" and "codex has no URL". Mutation: Codex.URL set to the GitHub tarball URL in pins.json; `go test ./cmd/equipo-hosted-image -run TestAssembleThenBuildFromBundle -count=1` FAILED at main_test.go "assemble with the checked-in pins = 1 ...; want the pins refused as incomplete". Restored from a copy; passes.
+
+## Image release blockers (2026-12-01)
+
+Two blockers from the release pins dry run, fixed. Report: .superpowers/sdd/2026-11-30-hosted-runners-slice-2/image-blockers-report.md.
+
+1. The hosted image's bubblewrap. scripts/build-hosted-bwrap.sh builds upstream bubblewrap 0.11.0 (release tarball 988fd6b2..., the same bytes as Debian's orig tarball) inside public.ecr.aws/amazonlinux/amazonlinux:2023.12.20261102.0 by digest, with pinned build packages and build-root digest, twice in fresh containers; both builds are 1ebd5a3d3d9f2ece1032af3ba3993edac3fb8c189cf2e49bbc06fc8362fc81e2 (four builds over two runs). It needs GLIBC_2.34 at most, libcap.so.2 and libc.so.6 only. That digest is now manifest.json's and pins.json's BubblewrapSHA256 and containment.HostedBubblewrapSHA256; internal/release/manifest.json (personal runners) is unchanged. containment.Config.Hosted selects the hosted pin; the hosted runner (serveChecks, certification's sandbox) sets it through hostedContainment. The image's containment suite is built with -tags hostedimage (its managers are hosted ones); a hostedchain build (the chain test's VM runner) also accepts the personal pin, and release-hosted.sh refuses a runner or vm-init built with any tag.
+2. The payload scan's 158 findings. ScanAllow entries now name the rule and bind bytes: the member's SHA-256 for a pinned input, or for a binary built here (equipo-runner) the matched text's SHA-256 alone. 72 entries: 70 for the Go toolchain and openssh's PROTOCOL.key (member, rule and digest each), 2 for the runner (gitleaks' own Bedrock rule prefix; golang.org/x/oauth2's h1: checksum in the build information). Neither runner finding is a secret. An oversized member's finding is bound to its container's digest.
+
+Mutation checks (each restored from a copy and the file compared to the original; the tests pass again):
+
+- `covers` without the rule (`a.Rule != f.Rule` removed): `go test ./internal/hostedimage -run '^TestScanAllowBindsRule$' -count=1` FAILED at scan_test.go:154 "Build with the bytes allowed but not the name = <nil>, want the forbidden-path finding alone".
+- `covers` without the match digest check: `-run '^TestScanAllowMatchDigest$'` FAILED at scan_test.go:203 "Build with a second match = <nil>, want that match alone refused".
+- Validate without the "pinned input binds its member's digest" case: `-run '^TestManifestPinsEverything$'` FAILED at manifest_test.go:123 "match-only allowance for a pinned input: Validate = nil, want a refusal".
+- tar's over-limit finding bound to "" again: `-run '^TestScanOverLimitBoundToContainer$'` FAILED at scan_test.go:231 "want over-limit at the member, bound to its tar's digest".
+- checked-in godebug.md allowance with Member "": `-run '^TestCheckedInScanAllow$'` FAILED at scanallow_test.go:55 "for a pinned input: want a member and its digest".
+- judge skipping every equipo-runner finding (a blanket allowance): `EQUIPO_HOSTED_IMAGE_BUNDLE=<dry run>/image-source.tar go test ./internal/hostedimage -run '^TestScanAssembledInputs$' -count=1` FAILED at scanallow_test.go:120 "allowance for equipo-runner: matched nothing" (twice).
+- bubblewrapPins accepting the personal pin for a hosted manager: `go test ./internal/runner/containment -run '^(TestBubblewrapPinsByPlace|TestNamespaceBubblewrapOtherPlace)$' -count=1` FAILED at bubblewrap_pin_test.go:84 "a hosted manager accepts [1ebd5a3d... 0dfa36b9...]" and :102 "a manager for the other place started on this bubblewrap: <nil>".
+- New ignoring cfg.Hosted: `-run '^TestNamespaceBubblewrapOtherPlace$'` FAILED at bubblewrap_pin_test.go:102.
+- hostedContainment without Hosted: `go test ./cmd/equipo-runner -run '^TestHostedContainmentUsesHostedPin$' -count=1` FAILED at hosted_test.go:222.
+- manifest.json still pinning the Debian build (red before the repin): `go test ./internal/hostedimage -run TestManifestPinsEverything -count=1` FAILED at manifest_test.go:195 "checked-in bwrap=0dfa36b9..., want the hosted build 1ebd5a3d...".
+- The chain test's runner built without -tags hostedchain: `make hosted-chain-test` FAILED (TestChainHostedCheckPasses, TestChainFailingCheck, TestChainNewModule: "the step ended and its VMs stopped with proof: not within 3m0s"; the VM runner's log: err=namespace_bubblewrap_digest).
diff --git a/infra/hosted/image/manifest.json b/infra/hosted/image/manifest.json
index 4968ae12..e17b58cd 100644
--- a/infra/hosted/image/manifest.json
+++ b/infra/hosted/image/manifest.json
@@ -12,5 +12,510 @@
"Policies": ["/usr/bin/bwrap"],
"Resolvers": [],
"Metadata": ["169.254.169.254:80"],
- "ScanAllow": []
+ "ScanAllow": [
+ {
+ "Input": "equipo-runner",
+ "Member": "",
+ "Rule": "aws-amazon-bedrock-api-key-short-lived",
+ "MatchSHA256": "522e9347612951b131245a2959b343538f901b0c06ecf47f537f215d49d11b4f",
+ "Reason": "gitleaks' own default rule for Bedrock keys, linked into the runner's scanner: the fixed prefix, base64 of bedrock.amazonaws.com"
+ },
+ {
+ "Input": "equipo-runner",
+ "Member": "",
+ "Rule": "generic-api-key",
+ "MatchSHA256": "9a285e94910858574be6e6aa5dc841d8b4e29304bb60502ad46dcd35f121e53e",
+ "Reason": "golang.org/x/oauth2 v0.35.0's module checksum (h1:) in the runner's Go build information"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/doc/godebug.md",
+ "Rule": "generic-api-key",
+ "SHA256": "59c3f14be9f72660af49be6c3a19900565e8513990e96e80c57cb20d63eb544d",
+ "Reason": "Go's GODEBUG documentation naming key exchange mechanisms, no key material"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/lib/fips140/v1.0.0-c2097c7c.zip!/golang.org/fips140@v1.0.0-c2097c7c/fips140/v1.0.0-c2097c7c/mlkem/generate1024.go",
+ "Rule": "generic-api-key",
+ "SHA256": "f0e56d86d417e61e27543d8b8e6cd6b4aa4f87126d6f7dacebcc580bff29a60a",
+ "Reason": "ML-KEM source: identifiers such as encryptionKey1024 and error text, no key material"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/lib/fips140/v1.0.0-c2097c7c.zip!/golang.org/fips140@v1.0.0-c2097c7c/fips140/v1.0.0-c2097c7c/mlkem/mlkem1024.go",
+ "Rule": "generic-api-key",
+ "SHA256": "8cd0c6f16cb34d02f03846c64a6a83db73f904a4233c07e6da83cda7e5718b07",
+ "Reason": "ML-KEM source: identifiers such as encryptionKey1024 and error text, no key material"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/lib/fips140/v1.0.0-c2097c7c.zip!/golang.org/fips140@v1.0.0-c2097c7c/fips140/v1.0.0-c2097c7c/mlkem/mlkem768.go",
+ "Rule": "generic-api-key",
+ "SHA256": "ac5c818cc515f0c9abea22886a54945584441acddf8be58866601f8e49eb6a29",
+ "Reason": "ML-KEM source: identifiers such as encryptionKey1024 and error text, no key material"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/lib/fips140/v1.26.0.zip!/golang.org/fips140@v1.26.0/fips140/v1.26.0/mlkem/generate1024.go",
+ "Rule": "generic-api-key",
+ "SHA256": "f0e56d86d417e61e27543d8b8e6cd6b4aa4f87126d6f7dacebcc580bff29a60a",
+ "Reason": "ML-KEM source: identifiers such as encryptionKey1024 and error text, no key material"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/lib/fips140/v1.26.0.zip!/golang.org/fips140@v1.26.0/fips140/v1.26.0/mlkem/mlkem1024.go",
+ "Rule": "generic-api-key",
+ "SHA256": "c312f9b86cdbd2cacf0cbf76f77852fe15460288c13a4726621dee4630e2d0a9",
+ "Reason": "ML-KEM source: identifiers such as encryptionKey1024 and error text, no key material"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/lib/fips140/v1.26.0.zip!/golang.org/fips140@v1.26.0/fips140/v1.26.0/mlkem/mlkem768.go",
+ "Rule": "generic-api-key",
+ "SHA256": "03c5f6deebc67d64dc912e5a0e950711e2f149ad9e49352903eb41a13945ed3d",
+ "Reason": "ML-KEM source: identifiers such as encryptionKey1024 and error text, no key material"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/archive/tar/testdata/gnu-sparse-many-zeros.tar.bz2",
+ "Rule": "unreadable-container",
+ "SHA256": "feda80eeea9e32a018368eb03891df21691764bf99095153d30fb3712e1d6ae6",
+ "Reason": "archive/tar's deliberately malformed or truncated test archive (testdata)"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/archive/tar/testdata/pax-bad-hdr-file.tar",
+ "Rule": "unreadable-container",
+ "SHA256": "63d5e53472b1ea35cd8814f9d4dee7597601c99eca367177bbaaab1e09d30468",
+ "Reason": "archive/tar's deliberately malformed or truncated test archive (testdata)"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/archive/tar/testdata/pax-bad-hdr-large.tar.bz2",
+ "Rule": "unreadable-container",
+ "SHA256": "288b91b2158a442be820d7ba40b3185c158d2a8b371ce0f37475ca4557a15968",
+ "Reason": "archive/tar's deliberately malformed or truncated test archive (testdata)"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/archive/tar/testdata/pax-bad-mtime-file.tar",
+ "Rule": "unreadable-container",
+ "SHA256": "02e95784ed0c0a6c028eb2959c2c6393094d9687cfb44100fd7305955dbe6b0a",
+ "Reason": "archive/tar's deliberately malformed or truncated test archive (testdata)"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/archive/tar/testdata/pax-nul-path.tar",
+ "Rule": "unreadable-container",
+ "SHA256": "a47d0adca51594bf284a2a1c50286f877a3718766dae1b262c4568ecd0bfa5e7",
+ "Reason": "archive/tar's deliberately malformed or truncated test archive (testdata)"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/archive/tar/testdata/pax-nul-xattrs.tar",
+ "Rule": "unreadable-container",
+ "SHA256": "d2a5221cdcd6bd73be8301f02c266fb13a2cba400d6836cce86ba9b6e044937a",
+ "Reason": "archive/tar's deliberately malformed or truncated test archive (testdata)"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/archive/tar/testdata/writer-big.tar",
+ "Rule": "unreadable-container",
+ "SHA256": "5a0bee74a7bd0caa1d572ff1ae58c3c79310c8fc646a5e84fb5e1eea488ea4b5",
+ "Reason": "archive/tar's deliberately malformed or truncated test archive (testdata)"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/archive/tar/testdata/writer-big.tar!/tmp/16gig.txt",
+ "Rule": "over-limit",
+ "SHA256": "5a0bee74a7bd0caa1d572ff1ae58c3c79310c8fc646a5e84fb5e1eea488ea4b5",
+ "Reason": "archive/tar's writer-big.tar test: a header claiming a 16 GiB file with no body"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/archive/zip/testdata/comment-truncated.zip",
+ "Rule": "unreadable-container",
+ "SHA256": "898b98f14b279d1a79c9e9d3e15d92f7ec630bb6990226ecb693a80c4bf0696c",
+ "Reason": "archive/zip's deliberately malformed or truncated test archive (testdata)"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/cmd/vendor/golang.org/x/mod/sumdb/note/note.go",
+ "Rule": "generic-api-key",
+ "SHA256": "5d0612c1993bff1951f782b5965490a82be4872065919963e5ce1313d12f9945",
+ "Reason": "x/mod/sumdb/note's documented example signer and verifier keys"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/ecdh/ecdh_test.go",
+ "Rule": "generic-api-key",
+ "SHA256": "3366e12a5e4a9634c89ceab9e3eadbe0bf07fc9cd72697e2699a513355519680",
+ "Reason": "crypto/ecdh's published test vectors (private keys, shared secrets) in a _test.go file"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/hpke/testdata/hpke-pq.json",
+ "Rule": "generic-api-key",
+ "SHA256": "963d5c3130d42d150ab0c70379c37b025effe0fa16efc9a15a9b5600a4981c95",
+ "Reason": "crypto/hpke's published test vectors (testdata): keys and shared secrets of the test cases"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/internal/fips140/mlkem/generate1024.go",
+ "Rule": "generic-api-key",
+ "SHA256": "f0e56d86d417e61e27543d8b8e6cd6b4aa4f87126d6f7dacebcc580bff29a60a",
+ "Reason": "ML-KEM source: identifiers such as encryptionKey1024 and error text, no key material"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/internal/fips140/mlkem/mlkem1024.go",
+ "Rule": "generic-api-key",
+ "SHA256": "5e97ea477987789e62ea31493fc524d5a933f1440e981c6e8dba5ef043f7a159",
+ "Reason": "ML-KEM source: identifiers such as encryptionKey1024 and error text, no key material"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/internal/fips140/mlkem/mlkem768.go",
+ "Rule": "generic-api-key",
+ "SHA256": "d34ced8104013131e938ee65b097e829dfb33af2f0b98146e1e3c2a60bfcf3a3",
+ "Reason": "ML-KEM source: identifiers such as encryptionKey1024 and error text, no key material"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/internal/fips140test/mldsa_test.go",
+ "Rule": "generic-api-key",
+ "SHA256": "8d8427adcca9a31aa22804957015172bd23f525efc64504c9021331f10b18f01",
+ "Reason": "ML-DSA known-answer test digests in a _test.go file"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/mlkem/mlkem.go",
+ "Rule": "generic-api-key",
+ "SHA256": "710c6cffef8e809e16263797808f9c1dce3b746e733ac12d3bec47c5ee9b604e",
+ "Reason": "crypto/mlkem's error text naming NewEncapsulationKey, no key material"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/tls/example_test.go",
+ "Rule": "private-key",
+ "SHA256": "0c1c065aea98125a16fe59fe30df13e57400179fa5b3c2503fb3b98dcc99457d",
+ "Reason": "crypto/tls's example test key in a _test.go file, published in Go's source"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/tls/fips140_test.go",
+ "Rule": "generic-api-key",
+ "SHA256": "c76f0e6c2effae3d4fc8295df8de286fe90ea0fcbf3bbbbc0370acadb72a20d4",
+ "Reason": "crypto/tls test code assigning its test keys (testRSA2048PrivateKey and the like)"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/tls/handshake_client_test.go",
+ "Rule": "generic-api-key",
+ "SHA256": "7fb4895d669ea88b260c6cd5578e3fc3a9c810aca5db65ddca432c45ffc02e4e",
+ "Reason": "crypto/tls test code assigning its test keys (testRSA2048PrivateKey and the like)"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/tls/handshake_server_test.go",
+ "Rule": "generic-api-key",
+ "SHA256": "3369ba9a522e766a6af86516ef4d3aa529e2e73c2db4294c78790e6b6722a0e1",
+ "Reason": "crypto/tls test code assigning its test keys (testRSA2048PrivateKey and the like)"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/tls/testdata/example-cert.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "c0e6d056e7bb46ef45fae41d3bd85305a6dcd281fd59afb007af6c89b3de7f38",
+ "Reason": "crypto/tls's example test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/tls/testdata/example-key.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "4280dcaf02ddf203cc1e3179b872f2e2f130662437b2f525bb24dfab4e7fade3",
+ "Reason": "crypto/tls's example test key (testdata), published in Go's source for its tests"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/tls/testdata/example-key.pem",
+ "Rule": "private-key",
+ "SHA256": "4280dcaf02ddf203cc1e3179b872f2e2f130662437b2f525bb24dfab4e7fade3",
+ "Reason": "crypto/tls's example test key (testdata), published in Go's source for its tests"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/tls/tls_test.go",
+ "Rule": "generic-api-key",
+ "SHA256": "43816194afc1d4979ea3cc5d30d02f99875a72eabdb96e22b46daeaa541e1f57",
+ "Reason": "crypto/tls test code assigning its test keys (testRSA2048PrivateKey and the like)"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/pkcs8_test.go",
+ "Rule": "generic-api-key",
+ "SHA256": "2697e68c351ba904d8f2f46a97fd66e35366434756094dc4985c9288bcc37984",
+ "Reason": "crypto/x509's hex-encoded test keys in a _test.go file, published in Go's source"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/platform_root_cert.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "e6b43cf846bb7b96d40320aa04715e97f21865d49170231ed15903240b2f8c1b",
+ "Reason": "crypto/x509's platform-verifier test root certificate: a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/platform_root_key.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "2fea2ebe77388df61566fcd43eb0070dbff2842c8786a0e7906a13e5f10c3e65",
+ "Reason": "crypto/x509's platform-verifier test root key, published in Go's source for its tests"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/platform_root_key.pem",
+ "Rule": "private-key",
+ "SHA256": "2fea2ebe77388df61566fcd43eb0070dbff2842c8786a0e7906a13e5f10c3e65",
+ "Reason": "crypto/x509's platform-verifier test root key, published in Go's source for its tests"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/sec1_test.go",
+ "Rule": "generic-api-key",
+ "SHA256": "9405912c47cd428c9bd4e65fab33e3ced23b585319cbf041c14a459f141fd7cd",
+ "Reason": "crypto/x509's hex-encoded test keys in a _test.go file, published in Go's source"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_intermediate.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "45ee26fd51fc8c52a0a20851344e11a91741a1a82d66848d2ae515cb67dd4ec0",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_intermediate_any.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "db91de07aa8da5ff6f9c0251ffb02db7da420f2e74faf1ca010e4b5c3e2f4991",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_intermediate_duplicate.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "d430e4f9fff1500a621e5ad2d00f6ee6a318d3c9850d9fd53e5f57aa0c950b02",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_intermediate_invalid.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "7695dc65af7478da2a9ead8f4b5fb0e70c7d36f7e34ef2fd683723cafaa8d62a",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_intermediate_mapped.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "9262f2d3f9d725c93bcdf988f2e7ae1cf4dd399f436becbcb9229c82cafdc8e0",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_intermediate_mapped_any.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "26c838b57996aea4c087fce8888a3559fb05f37ae6ec21229ed61d7291208cd1",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_intermediate_mapped_oid3.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "4592e8b9279d586d6e6462643cbeb75491b7c341ecee2c601cd52f4e51d4160b",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_intermediate_require.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "8fca9bf70a05d8aca23abc11cb7158b621bbc29454a3a5ebc35c57ca8e19a3ad",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_intermediate_require1.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "17815509f7cdad0acea8df6d4eee206eb0074c1dfdb36a3253ccbbaaf81718f5",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_intermediate_require2.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "819aa37b765de9514a97d09c0074cb9523a0da226ec6e57c776ffb871d922735",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_intermediate_require_duplicate.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "77a896bf8fe5279403820eeddaffb59e21aedf77ba97d6f86717cec20649403d",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_intermediate_require_no_policies.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "e8d999f775dcbf1066b663d9bd8caec332878e55bdf7bbf13980033c0095da78",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_leaf.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "6be74746088ccf2bca5eaa53c63bcaa108457d55b7527e92ceb3168fb90f5b95",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_leaf_any.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "48a7caa53ded51773b10bb79a06d9d8dfdc25a132a7c61635bb02c0ec1ceb2fb",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_leaf_duplicate.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "e323f690c6ce5104a816400d5526444ef927ad0a4e69dd84e92f4331b66438df",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_leaf_invalid.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "10115190be2937ed16c331f9c94d6fcb6f178dcd063132bf5f61f32edf60076b",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_leaf_none.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "aa6a7cc689d36cecfe75791f5224d1ca179561126ce573554ae692e3575bc08a",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_leaf_oid1.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "2c3496771ec04a176bb36838ebfe8168af1f495b7ed5f97b448e11717b981a0b",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_leaf_oid2.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "385b452652c93bc06924f18246ba10e1a2342d8086906c049b10af9094b10ffa",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_leaf_oid3.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "37acffb8789f5701469bad199b6369ee2e6b83b7cd921f977fef7223f91afb6b",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_leaf_oid4.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "b7b6faecae112d4ce95a894482c295ce7f01b0ec746d3f77168437bfe3dcb358",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_leaf_oid5.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "76bc28635c9ddd25f75c4dce0c628450b0f88b187bad434bfda8abcd1385bbd3",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_leaf_require.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "4e3dafd87f9e6e2179f7d56774f2a92ba8079165cffe092e6e80c2e4358c92f6",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_leaf_require1.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "17f2a4c92957bb4d3f058f72ab3620e799d5ad07767b26e9d6e0e2693bbb508b",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_root.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "cebf963dd58c8740b80fcd72115dbbc93a01c689e35b6cb0ee4234562ca5b013",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_root2.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "b18f33714620cb7f97d55eecd6b3a4e2e03322e54810cb7131493b6b2b948303",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/testdata/policy_root_cross_inhibit_mapping.pem",
+ "Rule": "forbidden-path",
+ "SHA256": "2e4fb4c1dfc6322262acc84617b95bf705522d1e67f6f422e3c5ff3bacf9f80e",
+ "Reason": "crypto/x509's certificate-policy test certificate (testdata): a .pem name, a public certificate"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/crypto/x509/x509_test.go",
+ "Rule": "generic-api-key",
+ "SHA256": "be49e404d0dacf8c41fde35d2e44f2b9a8683d9a8538da89caf112abab1b3bd9",
+ "Reason": "crypto/x509's hex-encoded test keys in a _test.go file, published in Go's source"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/debug/buildinfo/testdata/go117/go117.base64",
+ "Rule": "square-access-token",
+ "SHA256": "d700d16512bc8fb57b8f9d4f2a88242814e9b62ee2be7ad96907a93d26f2b138",
+ "Reason": "debug/buildinfo's base64-encoded test binary: random base64 text, no token"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/debug/elf/testdata/hello-world-core.gz",
+ "Rule": "aws-access-token",
+ "SHA256": "54f64d4ea6a14d2d02ab8d0ecef5cfcd7f901e9c56ce4090b0b1117c5b9f6725",
+ "Reason": "debug/elf's core-dump test file (in Go since 2015): its author's shell environment, an AWS key included, public in every Go release; not ours and grants nothing of ours"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/internal/trace/testdata/testprog/annotations.go",
+ "Rule": "generic-api-key",
+ "SHA256": "91796ba58dae8ee24f7ac03be0d4929f425dd6d4e7621772211b34ff712c81ec",
+ "Reason": "internal/trace test strings (\"key0\", \"0123456789abcdef\"), no key"
+ },
+ {
+ "Input": "go1.26.11.linux-amd64.tar.gz",
+ "Member": "go/src/internal/trace/trace_test.go",
+ "Rule": "generic-api-key",
+ "SHA256": "3323684ba65ec988ddff55d117bdeb690c8b398929ef265421ffca319d1de746",
+ "Reason": "internal/trace test strings (\"key0\", \"0123456789abcdef\"), no key"
+ },
+ {
+ "Input": "pkgs/openssh-9.9p1-16.amzn2023.0.1.x86_64.rpm",
+ "Member": "usr/share/doc/openssh/PROTOCOL.key",
+ "Rule": "forbidden-path",
+ "SHA256": "8479c767aeb256e4b2465d23f96dd98998d4210f12c0c9b41bd0a6f1f2e6f17c",
+ "Reason": "OpenSSH's document describing its private key format (a .key name): prose, no key"
+ }
+ ]
}
diff --git a/internal/hostedimage/assemble_test.go b/internal/hostedimage/assemble_test.go
index 9cd3d399..881887c5 100644
--- a/internal/hostedimage/assemble_test.go
+++ b/internal/hostedimage/assemble_test.go
@@ -48,6 +48,9 @@ func newAssembleFixture(t *testing.T) *assembleFixture {
t.Fatal(err)
}
m.GitleaksConfig = filepath.Join(repoRoot, ".gitleaks.toml")
+ // The checked-in allowances are the real inputs' reviewed findings;
+ // these made-up inputs have none, and an unused allowance is refused.
+ m.ScanAllow = nil
bwrap, codex := []byte("fake bwrap\n"), []byte("fake codex\n")
m.BubblewrapSHA256, m.CodexSHA256 = sum(bwrap), sum(codex)
rpm := hostedimagetest.RPM(map[string][]byte{"/usr/bin/git": []byte("fake git\n")}, "gzip")
diff --git a/internal/hostedimage/manifest.go b/internal/hostedimage/manifest.go
index 3dfcacdf..f3e3fa97 100644
--- a/internal/hostedimage/manifest.go
+++ b/internal/hostedimage/manifest.go
@@ -132,6 +132,7 @@ var (
releaseName = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$`)
goRelease = regexp.MustCompile(`^go1\.[0-9]+(\.[0-9]+)?$`)
rpmName = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._+-]*\.rpm$`)
+ ruleID = regexp.MustCompile(`^[a-z0-9][a-z0-9-]{0,63}$`)
)
// releaseFilled are the fields a runner release fills in: the checked-in
@@ -193,18 +194,32 @@ func (m Manifest) validate(static bool) error {
}
seen = map[string]bool{}
for _, a := range m.ScanAllow {
- key := a.Input + "\x00" + a.Member
+ key := a.Input + "\x00" + a.Member + "\x00" + a.Rule + "\x00" + a.MatchSHA256
+ // Between releases the packages are release-filled (from
+ // pins.json), so a package's allowance can only name one; the
+ // full check holds it to the pinned list.
+ pkg, isPkg := strings.CutPrefix(a.Input, "pkgs/")
switch {
- case !inputs[a.Input]:
+ case !inputs[a.Input] && !(static && len(m.Packages) == 0 && isPkg && rpmName.MatchString(pkg)):
return bad("ScanAllow", "%q is not a pinned input", a.Input)
case a.Member != "" && (path.IsAbs(a.Member) || path.Clean(a.Member) != a.Member || strings.HasPrefix(a.Member, "../")):
return bad("ScanAllow", "member %q is not a clean relative path", a.Member)
- case !hexDigest.MatchString(a.SHA256):
+ case !ruleID.MatchString(a.Rule):
+ return bad("ScanAllow", "%s:%s names no rule (%q)", a.Input, a.Member, a.Rule)
+ case a.SHA256 == "" && a.MatchSHA256 == "":
+ return bad("ScanAllow", "%s:%s binds no bytes: it needs SHA256 or MatchSHA256", a.Input, a.Member)
+ case a.SHA256 != "" && !hexDigest.MatchString(a.SHA256):
return bad("ScanAllow", "%s:%s's digest %q is not 64 lower-case hex digits", a.Input, a.Member, a.SHA256)
+ case a.MatchSHA256 != "" && !hexDigest.MatchString(a.MatchSHA256):
+ return bad("ScanAllow", "%s:%s's match digest %q is not 64 lower-case hex digits", a.Input, a.Member, a.MatchSHA256)
+ case a.MatchSHA256 != "" && slices.Contains(structuralRules, a.Rule):
+ return bad("ScanAllow", "%s:%s: a %s finding has no match to bind", a.Input, a.Member, a.Rule)
+ case a.SHA256 == "" && !slices.Contains(BuiltInputs, a.Input):
+ return bad("ScanAllow", "%s:%s: a pinned input's allowance binds the member's digest", a.Input, a.Member)
case strings.TrimSpace(a.Reason) == "":
return bad("ScanAllow", "%s:%s has no reason", a.Input, a.Member)
case seen[key]:
- return bad("ScanAllow", "%s:%s is listed twice", a.Input, a.Member)
+ return bad("ScanAllow", "%s:%s (%s) is listed twice", a.Input, a.Member, a.Rule)
}
seen[key] = true
}
diff --git a/internal/hostedimage/manifest_test.go b/internal/hostedimage/manifest_test.go
index 1fa88c19..0ebe73ce 100644
--- a/internal/hostedimage/manifest_test.go
+++ b/internal/hostedimage/manifest_test.go
@@ -85,11 +85,35 @@ func TestManifestPinsEverything(t *testing.T) {
"metadata without a port": func(m *Manifest) { m.Metadata = []string{"169.254.169.254"} },
"toolchain not a Go release": func(m *Manifest) { m.GoToolchain = "latest" },
"no packages": func(m *Manifest) { m.Packages = nil },
- "allowance for no input": func(m *Manifest) { m.ScanAllow = []ScanAllowed{{Input: "other", SHA256: hex64('a'), Reason: "r"}} },
- "allowance without a reason": func(m *Manifest) { m.ScanAllow = []ScanAllowed{{Input: "codex", SHA256: hex64('a')}} },
- "allowance without a digest": func(m *Manifest) { m.ScanAllow = []ScanAllowed{{Input: "codex", Reason: "r"}} },
+ "allowance for no input": func(m *Manifest) {
+ m.ScanAllow = []ScanAllowed{{Input: "other", Rule: "private-key", SHA256: hex64('a'), Reason: "r"}}
+ },
+ "allowance without a reason": func(m *Manifest) {
+ m.ScanAllow = []ScanAllowed{{Input: "codex", Rule: "private-key", SHA256: hex64('a')}}
+ },
+ "allowance without a digest": func(m *Manifest) { m.ScanAllow = []ScanAllowed{{Input: "codex", Rule: "private-key", Reason: "r"}} },
"allowance escaping its input": func(m *Manifest) {
- m.ScanAllow = []ScanAllowed{{Input: "codex", Member: "../x", SHA256: hex64('a'), Reason: "r"}}
+ m.ScanAllow = []ScanAllowed{{Input: "codex", Member: "../x", Rule: "private-key", SHA256: hex64('a'), Reason: "r"}}
+ },
+ "allowance without a rule": func(m *Manifest) { m.ScanAllow = []ScanAllowed{{Input: "codex", SHA256: hex64('a'), Reason: "r"}} },
+ "allowance for any rule": func(m *Manifest) {
+ m.ScanAllow = []ScanAllowed{{Input: "codex", Rule: "*", SHA256: hex64('a'), Reason: "r"}}
+ },
+ "allowance with a bad match digest": func(m *Manifest) {
+ m.ScanAllow = []ScanAllowed{{Input: "equipo-runner", Rule: "generic-api-key", MatchSHA256: "zz", Reason: "r"}}
+ },
+ // A pinned third-party input's bytes never change, so its
+ // allowance binds them; only a binary built here may be excused by
+ // the match alone.
+ "match-only allowance for a pinned input": func(m *Manifest) {
+ m.ScanAllow = []ScanAllowed{{Input: "codex", Rule: "generic-api-key", MatchSHA256: hex64('a'), Reason: "r"}}
+ },
+ "match digest for a name finding": func(m *Manifest) {
+ m.ScanAllow = []ScanAllowed{{Input: "equipo-runner", Rule: "forbidden-path", MatchSHA256: hex64('a'), Reason: "r"}}
+ },
+ "allowance listed twice": func(m *Manifest) {
+ a := ScanAllowed{Input: "codex", Member: "x", Rule: "private-key", SHA256: hex64('a'), Reason: "r"}
+ m.ScanAllow = []ScanAllowed{a, a}
},
} {
m := validManifest()
@@ -100,6 +124,19 @@ func TestManifestPinsEverything(t *testing.T) {
}
}
+ // A member may be allowed under two rules, and a runner's match by
+ // its digest alone.
+ ok := validManifest()
+ ok.ScanAllow = []ScanAllowed{
+ {Input: "codex", Member: "x.pem", Rule: "private-key", SHA256: hex64('a'), Reason: "r"},
+ {Input: "codex", Member: "x.pem", Rule: "forbidden-path", SHA256: hex64('a'), Reason: "r"},
+ {Input: "equipo-runner", Rule: "generic-api-key", MatchSHA256: hex64('b'), Reason: "r"},
+ {Input: "equipo-runner", Rule: "generic-api-key", MatchSHA256: hex64('c'), Reason: "r"},
+ }
+ if err := ok.Validate(); err != nil {
+ t.Errorf("rule-bound allowances: Validate = %v", err)
+ }
+
// Strict decoding: an unknown key (a misspelt pin) is refused.
dir := t.TempDir()
b, _ := json.Marshal(validManifest())
diff --git a/internal/hostedimage/nested.go b/internal/hostedimage/nested.go
index fc413644..a2c3aaaf 100644
--- a/internal/hostedimage/nested.go
+++ b/internal/hostedimage/nested.go
@@ -279,7 +279,9 @@ func (w *walk) tar(member, sum string, b []byte, level int) {
continue
}
if h.Size > maxMember {
- w.finding(join(member, name), "", "over-limit")
+ // Its body is never read, so it has no digest; its header is
+ // in the container's bytes, which bind any allowance.
+ w.finding(join(member, name), sum, "over-limit")
continue
}
if !w.spend(join(member, name), h.Size) {
@@ -311,7 +313,7 @@ func (w *walk) zip(member, sum string, b []byte, level int) {
continue
}
if f.UncompressedSize64 > uint64(maxMember) {
- w.finding(join(member, name), "", "over-limit")
+ w.finding(join(member, name), sum, "over-limit")
continue
}
if !w.spend(join(member, name), int64(f.UncompressedSize64)) {
diff --git a/internal/hostedimage/scan.go b/internal/hostedimage/scan.go
index 89fca40b..5e955968 100644
--- a/internal/hostedimage/scan.go
+++ b/internal/hostedimage/scan.go
@@ -37,10 +37,10 @@ import (
// (.gitleaks.toml, extending gitleaks' defaults), with inline
// "gitleaks:allow" comments ignored and no path given, so no path
// allowlist applies; names go through ForbiddenPath. A finding stops the
-// build unless the manifest's ScanAllow names that exact member and its
-// SHA-256 (a reviewed false positive, such as a test key in the Go tree's
-// testdata); an allowance that matches nothing also stops it, so the
-// list stays exact.
+// build unless the manifest's ScanAllow names that exact member, the rule
+// that fired and the bytes it fired on (a reviewed false positive, such
+// as a test key in the Go tree's testdata); an allowance that matches
+// nothing also stops it, so the list stays exact.
// ForbiddenPath matches paths that would put a credential, a person's
// configuration or a repository in the image: SSH, AWS, Codex, Claude and
@@ -50,15 +50,25 @@ var ForbiddenPath = regexp.MustCompile(`(?i)(^|/)(\.ssh|\.aws|\.codex|\.claude|\
// ScanAllowed is one reviewed scan finding the build accepts: the input
// (its name in the inputs directory), the member inside it ("" for the
-// file itself), that member's SHA-256, and why.
+// file itself), the rule that fired, the bytes it fired on, and why. The
+// bytes are the member's SHA-256 (SHA256) for a pinned input, whose bytes
+// never change. A binary this repository builds (BuiltInputs) has other
+// bytes at every commit, so its allowance may instead bind the matched
+// text's SHA-256 (MatchSHA256): that rule, that text, in that input, and
+// nothing else. Where both are set, both must match.
type ScanAllowed struct {
- Input, Member, SHA256, Reason string
+ Input, Member, Rule string
+ SHA256 string `json:",omitempty"`
+ MatchSHA256 string `json:",omitempty"`
+ Reason string
}
-// Finding is one scan result. It names the rule, never the matched text.
+// Finding is one scan result. It names the rule, never the matched text:
+// a gitleaks finding carries the text's SHA-256 (MatchSHA256) instead.
type Finding struct {
Input, Member, SHA256 string
- Rule string // a gitleaks rule ID, or "forbidden-path"
+ Rule string // a gitleaks rule ID, or a structural one (structuralRules)
+ MatchSHA256 string
Line int
}
@@ -70,9 +80,17 @@ func (f Finding) String() string {
if f.Line > 0 {
where += fmt.Sprintf(" line %d", f.Line)
}
+ if f.MatchSHA256 != "" {
+ where += " match sha256:" + f.MatchSHA256
+ }
return where + " (" + f.Rule + ")"
}
+// structuralRules are the scan's own findings, about a name or a
+// container rather than matched text: they carry no match digest.
+var structuralRules = []string{"forbidden-path", "over-limit", "unreadable-container", "nested-too-deep",
+ "unsupported-container", "member-leaves-archive"}
+
// scanChunk and scanOverlap split large members for gitleaks: each chunk
// overlaps the next, so a secret across a boundary is still seen whole.
const (
@@ -207,7 +225,7 @@ func (s *scanner) scanBytes(input, member string, b []byte) {
}
seen[key] = true
s.findings = append(s.findings, Finding{Input: input, Member: member, SHA256: sum, Rule: f.RuleID,
- Line: f.StartLine + 1})
+ MatchSHA256: sha256Hex([]byte(f.Match)), Line: f.StartLine + 1})
}
if end == len(b) {
return
@@ -219,14 +237,28 @@ func (s *scanner) scanBytes(input, member string, b []byte) {
// into memory. A var so tests can use a small one.
var maxMember int64 = 1 << 30
+// covers reports whether a excuses f: the same input, member and rule,
+// and the bytes a binds (the member's digest, the match's, or both).
+func (a ScanAllowed) covers(f Finding) bool {
+ switch {
+ case a.Input != f.Input || a.Member != f.Member || a.Rule != f.Rule:
+ return false
+ case a.SHA256 == "" && a.MatchSHA256 == "":
+ return false
+ case a.SHA256 != "" && a.SHA256 != f.SHA256:
+ return false
+ case a.MatchSHA256 != "" && a.MatchSHA256 != f.MatchSHA256:
+ return false
+ }
+ return true
+}
+
// judge drops the findings allow covers and returns what is left, plus
// any allowance that matched nothing.
func judge(findings []Finding, allow []ScanAllowed) (left []Finding, unused []ScanAllowed) {
used := make([]bool, len(allow))
for _, f := range findings {
- i := slices.IndexFunc(allow, func(a ScanAllowed) bool {
- return a.Input == f.Input && a.Member == f.Member && a.SHA256 == f.SHA256 && f.SHA256 != ""
- })
+ i := slices.IndexFunc(allow, func(a ScanAllowed) bool { return a.covers(f) })
if i < 0 {
left = append(left, f)
continue
diff --git a/internal/hostedimage/scan_test.go b/internal/hostedimage/scan_test.go
index 185d6997..e22c93cd 100644
--- a/internal/hostedimage/scan_test.go
+++ b/internal/hostedimage/scan_test.go
@@ -1,6 +1,7 @@
package hostedimage
import (
+ "archive/tar"
"bytes"
"compress/gzip"
"errors"
@@ -106,22 +107,26 @@ func TestScanAllowExact(t *testing.T) {
"go/bin/go": []byte("fake go\n"), "go/src/crypto/tls/testdata/example-key.pem": key}))
}
allow := ScanAllowed{Input: "go1.26.11.linux-amd64.tar.gz", Member: "go/src/crypto/tls/testdata/example-key.pem",
- SHA256: sum(key), Reason: "the Go tree's TLS test key"}
+ Rule: "private-key", SHA256: sum(key), Reason: "the Go tree's TLS test key"}
+ // The member is a finding twice: its bytes (private-key) and its name
+ // (forbidden-path). Each rule needs its own allowance.
+ named := allow
+ named.Rule, named.Reason = "forbidden-path", "the Go tree's TLS test key file"
m := fixture(t)
plant(t, &m)
- m.ScanAllow = []ScanAllowed{allow}
+ m.ScanAllow = []ScanAllowed{allow, named}
if _, err := Build(m, filepath.Join(t.TempDir(), "a.zip")); err != nil {
- t.Fatalf("Build with the exact allowance = %v", err)
+ t.Fatalf("Build with the exact allowances = %v", err)
}
m = fixture(t)
plant(t, &m)
wrong := allow
wrong.SHA256 = hex64('e')
- m.ScanAllow = []ScanAllowed{wrong}
+ m.ScanAllow = []ScanAllowed{wrong, named}
var se *ScanError
- if _, err := Build(m, filepath.Join(t.TempDir(), "b.zip")); !errors.As(err, &se) || len(se.Findings) == 0 || len(se.Unused) != 1 {
+ if _, err := Build(m, filepath.Join(t.TempDir(), "b.zip")); !errors.As(err, &se) || len(se.Findings) != 1 || len(se.Unused) != 1 {
t.Fatalf("Build with an allowance for other bytes = %v, want the finding and the unused allowance", err)
}
@@ -132,6 +137,112 @@ func TestScanAllowExact(t *testing.T) {
}
}
+// TestScanAllowBindsRule: an allowance excuses the one rule it names. The
+// right member and bytes under another rule excuse nothing, so a member
+// with two findings stays refused until each has its own allowance.
+func TestScanAllowBindsRule(t *testing.T) {
+ key := []byte(hostedimagetest.PrivateKey)
+ member := "go/src/crypto/tls/testdata/example-key.pem"
+ allow := ScanAllowed{Input: goInput, Member: member, Rule: "private-key", SHA256: sum(key), Reason: "the Go tree's TLS test key"}
+
+ m := fixture(t)
+ plantGo(t, &m, map[string][]byte{member: key})
+ m.ScanAllow = []ScanAllowed{allow}
+ var se *ScanError
+ if _, err := Build(m, filepath.Join(t.TempDir(), "a.zip")); !errors.As(err, &se) || len(se.Unused) != 0 ||
+ len(se.Findings) != 1 || se.Findings[0].Rule != "forbidden-path" {
+ t.Fatalf("Build with the bytes allowed but not the name = %v, want the forbidden-path finding alone", err)
+ }
+
+ other := allow
+ other.Rule = "generic-api-key"
+ m = fixture(t)
+ plantGo(t, &m, map[string][]byte{member: key})
+ m.ScanAllow = []ScanAllowed{other, {Input: goInput, Member: member, Rule: "forbidden-path", SHA256: sum(key), Reason: "r"}}
+ if _, err := Build(m, filepath.Join(t.TempDir(), "b.zip")); !errors.As(err, &se) || len(se.Unused) != 1 ||
+ len(se.Findings) != 1 || se.Findings[0].Rule != "private-key" {
+ t.Fatalf("Build with the member allowed under another rule = %v, want the private-key finding and the unused allowance", err)
+ }
+}
+
+// TestScanAllowMatchDigest: a binary this repository builds has other
+// bytes at every commit, so its allowance binds the rule and the matched
+// text's SHA-256 instead of the file's. Another match under the same rule
+// in the same binary is still refused, and the refusal names the match's
+// digest, never its text.
+func TestScanAllowMatchDigest(t *testing.T) {
+ // The module line Go stamps into a binary that links
+ // golang.org/x/oauth2, assembled so this file holds no such line.
+ reviewed := "oauth2\tv0.35.0\th1:" + "Mv2mzuHuZuY2+bkyWXIHMf" + "hNdJAdwW3FuWeCPYN5GVQ="
+ runner := []byte("\x7fELF a runner\ndep\tgolang.org/x/" + reviewed + "\n")
+ m := fixture(t)
+ setInput(t, &m, "equipo-runner", runner)
+ fs := buildFindings(t, m)
+ if len(fs) != 1 || fs[0].Rule != "generic-api-key" || fs[0].MatchSHA256 != sum([]byte(reviewed)) {
+ t.Fatalf("findings %+v, want one generic-api-key finding bound to the match's digest", fs)
+ }
+ allow := ScanAllowed{Input: "equipo-runner", Rule: "generic-api-key", MatchSHA256: sum([]byte(reviewed)),
+ Reason: "golang.org/x/oauth2's module checksum in the build information"}
+ m.ScanAllow = []ScanAllowed{allow}
+ if _, err := Build(m, filepath.Join(t.TempDir(), "a.zip")); err != nil {
+ t.Fatalf("Build with the match allowed = %v", err)
+ }
+
+ // A new build of the runner: other bytes, the same reviewed match.
+ setInput(t, &m, "equipo-runner", append([]byte("\x7fELF the next build\n"), runner...))
+ if _, err := Build(m, filepath.Join(t.TempDir(), "b.zip")); err != nil {
+ t.Fatalf("Build of another runner with the same match = %v", err)
+ }
+
+ // Another value under the same rule in the same runner.
+ fresh := "oauth2\tv0.36.0\th1:" + "Zq7xYk2pW9vN4rT8sL1mB6c" + "D3fH5jK0aE2gU7iO9yR4w="
+ setInput(t, &m, "equipo-runner", append(runner, "dep\tgolang.org/x/"+fresh+"\n"...))
+ var se *ScanError
+ _, err := Build(m, filepath.Join(t.TempDir(), "c.zip"))
+ if !errors.As(err, &se) || len(se.Unused) != 0 || len(se.Findings) != 1 || se.Findings[0].MatchSHA256 != sum([]byte(fresh)) {
+ t.Fatalf("Build with a second match = %v, want that match alone refused", err)
+ }
+ if strings.Contains(err.Error(), "Zq7xYk2pW9vN4rT8sL1mB6c") || !strings.Contains(err.Error(), sum([]byte(fresh))) {
+ t.Fatalf("the refusal %q quotes the match or omits its digest", err)
+ }
+}
+
+// TestScanOverLimitBoundToContainer: a member too large to read has no
+// digest of its own. Its finding names its container's, whose bytes fix
+// the member's header, so a reviewed allowance binds to those bytes and
+// another container with the same oversized member stays refused. The
+// shape is the Go tree's archive/tar/testdata/writer-big.tar: a header
+// claiming 16 GiB and no body, so the tar is also unreadable.
+func TestScanOverLimitBoundToContainer(t *testing.T) {
+ const member = "go/src/archive/tar/testdata/writer-big.tar"
+ hugeTar := func(mode int64) []byte {
+ var b bytes.Buffer
+ tw := tar.NewWriter(&b)
+ _ = tw.WriteHeader(&tar.Header{Name: "tmp/16gig.txt", Typeflag: tar.TypeReg, Mode: mode, Size: 16 << 30})
+ _ = tw.Flush()
+ return b.Bytes()
+ }
+ big := hugeTar(0o644)
+ m := fixture(t)
+ plantGo(t, &m, map[string][]byte{member: big})
+ fs := buildFindings(t, m)
+ i := slices.IndexFunc(fs, func(f Finding) bool { return f.Rule == "over-limit" })
+ if i < 0 || fs[i].Member != member+"!/tmp/16gig.txt" || fs[i].SHA256 != sum(big) {
+ t.Fatalf("findings %+v, want over-limit at the member, bound to its tar's digest %s", fs, sum(big))
+ }
+ m.ScanAllow = []ScanAllowed{
+ {Input: goInput, Member: member + "!/tmp/16gig.txt", Rule: "over-limit", SHA256: sum(big), Reason: "the tar package's 16 GiB test header"},
+ {Input: goInput, Member: member, Rule: "unreadable-container", SHA256: sum(big), Reason: "the tar package's truncated test archive"},
+ }
+ if _, err := Build(m, filepath.Join(t.TempDir(), "a.zip")); err != nil {
+ t.Fatalf("Build with the oversized member allowed by its tar's digest = %v", err)
+ }
+ plantGo(t, &m, map[string][]byte{member: hugeTar(0o600)})
+ if fs := buildFindings(t, m); !hasFinding(fs, goInput+":"+member+"!/tmp/16gig.txt", "over-limit") {
+ t.Fatalf("findings %v, want the other tar's oversized member refused", fs)
+ }
+}
+
// TestBuildNeedsGitleaksConfig: without the configuration, or with one
// that does not parse, nothing is built.
func TestBuildNeedsGitleaksConfig(t *testing.T) {
@@ -335,8 +446,8 @@ func TestScanNestedArchives(t *testing.T) {
plantGo(t, &m, map[string][]byte{"go/a.tar.gz": hostedimagetest.TarGz(map[string][]byte{"b.tar.gz": hostedimagetest.TarGz(map[string][]byte{"c.tar.gz": deep})}),
"go/x.7z": hostedimagetest.SevenZip()})
m.ScanAllow = []ScanAllowed{
- {Input: goInput, Member: "go/a.tar.gz!/b.tar.gz!/c.tar.gz", SHA256: sum(deep), Reason: "reviewed by hand"},
- {Input: goInput, Member: "go/x.7z", SHA256: sum(hostedimagetest.SevenZip()), Reason: "reviewed by hand"},
+ {Input: goInput, Member: "go/a.tar.gz!/b.tar.gz!/c.tar.gz", Rule: "nested-too-deep", SHA256: sum(deep), Reason: "reviewed by hand"},
+ {Input: goInput, Member: "go/x.7z", Rule: "unsupported-container", SHA256: sum(hostedimagetest.SevenZip()), Reason: "reviewed by hand"},
}
if _, err := Build(m, filepath.Join(t.TempDir(), "ok.zip")); err != nil {
t.Fatalf("Build with the containers allowed by hash = %v", err)
diff --git a/internal/hostedimage/scanallow_test.go b/internal/hostedimage/scanallow_test.go
new file mode 100644
index 00000000..19eabb82
--- /dev/null
+++ b/internal/hostedimage/scanallow_test.go
@@ -0,0 +1,139 @@
+package hostedimage
+
+import (
+ "errors"
+ "os"
+ "path/filepath"
+ "slices"
+ "strings"
+ "testing"
+)
+
+// checkedInAllow is infra/hosted/image/manifest.json's ScanAllow.
+func checkedInAllow(t *testing.T) Manifest {
+ t.Helper()
+ m, err := LoadManifest(filepath.Join(repoRoot, "infra", "hosted", "image", "manifest.json"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := m.ValidateStatic(); err != nil {
+ t.Fatalf("the checked-in manifest: %v", err)
+ }
+ return m
+}
+
+// TestCheckedInScanAllow holds the checked-in allowances to their shape:
+// each names its input, member, rule and a reason, and binds bytes. The
+// pinned inputs' allowances name a member and its digest (none excuses a
+// whole input); the runner's, whose bytes change with every build, name
+// the match's digest. Each allowance excuses exactly its own finding, and
+// a finding outside the list (a new member, a listed member under another
+// rule or with other bytes, another match in the runner) is refused.
+func TestCheckedInScanAllow(t *testing.T) {
+ m := checkedInAllow(t)
+ if len(m.ScanAllow) == 0 {
+ t.Fatal("the checked-in manifest allows nothing; the pinned Go toolchain needs its reviewed test vectors")
+ }
+ pins, err := LoadPins(filepath.Join(repoRoot, "infra", "hosted", "image", "pins.json"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ var findings []Finding
+ for _, a := range m.ScanAllow {
+ if pkg, ok := strings.CutPrefix(a.Input, "pkgs/"); ok &&
+ !slices.ContainsFunc(pins.Packages, func(p PackageSource) bool { return p.Name == pkg }) {
+ t.Errorf("allowance for %s: pins.json pins no such package", a.Input)
+ }
+ switch {
+ case strings.TrimSpace(a.Reason) == "" || a.Rule == "":
+ t.Errorf("%s:%s has no rule or reason", a.Input, a.Member)
+ case a.Input == "equipo-runner":
+ if a.Member != "" || a.SHA256 != "" || a.MatchSHA256 == "" {
+ t.Errorf("runner allowance %+v: want the match's digest alone", a)
+ }
+ case a.Member == "" || a.SHA256 == "" || a.MatchSHA256 != "":
+ t.Errorf("allowance %+v for a pinned input: want a member and its digest", a)
+ }
+ f := Finding{Input: a.Input, Member: a.Member, SHA256: a.SHA256, Rule: a.Rule, MatchSHA256: a.MatchSHA256}
+ if a.Input == "equipo-runner" {
+ f.SHA256 = hex64('9') // any build of the runner
+ }
+ findings = append(findings, f)
+ }
+ if left, unused := judge(findings, m.ScanAllow); len(left) != 0 || len(unused) != 0 {
+ t.Fatalf("the allowances' own findings: left %v, unused %v", left, unused)
+ }
+
+ goTar := m.GoToolchain + ".linux-amd64.tar.gz"
+ var listed ScanAllowed
+ for _, a := range m.ScanAllow {
+ if a.Input == goTar && a.Rule == "private-key" {
+ listed = a
+ }
+ }
+ if listed.Member == "" {
+ t.Fatal("no private-key allowance for the Go toolchain's test keys")
+ }
+ var runner ScanAllowed
+ for _, a := range m.ScanAllow {
+ if a.Input == "equipo-runner" {
+ runner = a
+ }
+ }
+ for name, f := range map[string]Finding{
+ "a new member": {Input: goTar, Member: "go/src/crypto/tls/testdata/new-key.pem", SHA256: hex64('1'), Rule: "private-key"},
+ "a listed member under another rule": {Input: goTar, Member: listed.Member, SHA256: listed.SHA256, Rule: "aws-access-token"},
+ "a listed member with other bytes": {Input: goTar, Member: listed.Member, SHA256: hex64('2'), Rule: "private-key"},
+ "the member's name in another input": {Input: "codex", Member: listed.Member, SHA256: listed.SHA256, Rule: "private-key"},
+ "another match in the runner": {Input: "equipo-runner", SHA256: hex64('3'), Rule: runner.Rule, MatchSHA256: hex64('4')},
+ "the runner's match under another rule": {Input: "equipo-runner", SHA256: hex64('3'), Rule: "aws-access-token",
+ MatchSHA256: runner.MatchSHA256},
+ } {
+ left, unused := judge(append(slices.Clone(findings), f), m.ScanAllow)
+ if len(left) != 1 || left[0] != f || len(unused) != 0 {
+ t.Errorf("%s: left %v, unused %v; want it refused alone", name, left, unused)
+ }
+ }
+}
+
+// TestScanAssembledInputs runs the payload scan over a release's real
+// image inputs, the bundle scripts/release-hosted.sh writes
+// (image-source.tar), named by EQUIPO_HOSTED_IMAGE_BUNDLE: the image
+// builds with the checked-in allowances, and the same inputs with one new
+// secret in the runner are refused for that finding alone. It needs the
+// real inputs (the Go toolchain, the packages, the built binaries), so it
+// runs only when given a bundle, and takes minutes (go test -timeout 30m).
+func TestScanAssembledInputs(t *testing.T) {
+ bundle := os.Getenv("EQUIPO_HOSTED_IMAGE_BUNDLE")
+ if bundle == "" {
+ t.Skip("EQUIPO_HOSTED_IMAGE_BUNDLE names no image-source.tar")
+ }
+ m, err := OpenBundle(bundle, filepath.Join(t.TempDir(), "bundle"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ m.GitleaksConfig = filepath.Join(repoRoot, ".gitleaks.toml")
+ if want := checkedInAllow(t).ScanAllow; !slices.Equal(m.ScanAllow, want) {
+ t.Fatalf("the bundle's ScanAllow is not the checked-in one")
+ }
+ if _, err := Build(m, filepath.Join(t.TempDir(), "image.zip")); err != nil {
+ t.Fatalf("Build of the assembled inputs = %v", err)
+ }
+
+ runner, err := os.ReadFile(filepath.Join(m.Inputs, "equipo-runner"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ // An AWS key ID that is no key, assembled so this file holds none.
+ planted := append(runner, "\naws_access_key_id = "+"AKIA"+"QX7RT2MZK4VN3LPW\n"...)
+ if err := os.WriteFile(filepath.Join(m.Inputs, "equipo-runner"), planted, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ m.RunnerSHA256 = sum(planted)
+ _, err = Build(m, filepath.Join(t.TempDir(), "planted.zip"))
+ var se *ScanError
+ if !errors.As(err, &se) || len(se.Unused) != 0 || len(se.Findings) == 0 ||
+ slices.ContainsFunc(se.Findings, func(f Finding) bool { return f.Input != "equipo-runner" }) {
+ t.Fatalf("Build with a new secret in the runner = %v, want it refused and nothing else", err)
+ }
+}