oficina / equipo Public

hosted: delete the Go tree's testdata in the image, scan the rest

The Dockerfile now deletes every path named testdata under
/usr/local/go/src right after unpacking the toolchain (whose tarball is
already checked by digest), with bash globstar, nullglob and dotglob,
and fails if any is left. The go version check stays.

The payload scan skips exactly those members of the Go tarball
(goTestdata); TestDropGoTestdata runs the Dockerfile's command over a
tree and holds it to the same set. The 43 allowances that covered only
GOROOT testdata are gone, the 2015 hello-world-core.gz among them; 29
remain. TestScanSkipsGoTestdata shows a key in testdata is no longer a
finding and the same key elsewhere in the tree still is.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 4f87a55881e69d2524a909e0563611162020a9e0 parent 5a0986c
7 files changed, +113 −313
  • infra/hosted/image/Dockerfile.tmpl +4 −1
  • infra/hosted/image/manifest.json +0 −301
  • internal/hostedimage/build.go +3 −2
  • internal/hostedimage/nested.go +27 −0
  • internal/hostedimage/scan.go +3 −1
  • internal/hostedimage/scan_test.go +74 −8
  • internal/hostedimage/scanallow_test.go +2 −0
diff --git a/infra/hosted/image/Dockerfile.tmpl b/infra/hosted/image/Dockerfile.tmpl
index ce191ba5..829271cc 100644
--- a/infra/hosted/image/Dockerfile.tmpl
+++ b/infra/hosted/image/Dockerfile.tmpl
@@ -6,7 +6,9 @@
# empty (vm-init's /ready hook refuses the build otherwise). The pinned
# files go in after the packages, bubblewrap at /usr/bin/bwrap where the
# containment suite runs it, and the last step checks each one again at
-# its final path, so no package or later step can stand in for it.
+# its final path, so no package or later step can stand in for it. The
+# Go tree's testdata (test vectors and test keys) is deleted right after
+# the toolchain is unpacked; the payload scan skips exactly those paths.
FROM public.ecr.aws/lambda/microvms:al2023-minimal
COPY files/ /tmp/equipo-image/
RUN set -eu; \
@@ -22,6 +24,7 @@ RUN set -eu; \
install -D -m 0755 -o root -g root codex {{.PathCodex}}; \
install -D -m 0755 -o root -g root containment.test {{.PathContainmentTest}}; \
tar -C /usr/local -xzf go.tar.gz; \
+ {{.DropGoTestdata}}; \
ln -s /usr/local/go/bin/go /usr/local/bin/go; \
ln -s /usr/local/go/bin/gofmt /usr/local/bin/gofmt; \
test "$(/usr/local/go/bin/go version)" = 'go version {{.Manifest.GoToolchain}} linux/amd64'; \
diff --git a/infra/hosted/image/manifest.json b/infra/hosted/image/manifest.json
index e17b58cd..6bfe445d 100644
--- a/infra/hosted/image/manifest.json
+++ b/infra/hosted/image/manifest.json
@@ -76,69 +76,6 @@
"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",
@@ -153,13 +90,6 @@
"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",
@@ -223,27 +153,6 @@
"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",
@@ -286,195 +195,6 @@
"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",
@@ -482,27 +202,6 @@
"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",
diff --git a/internal/hostedimage/build.go b/internal/hostedimage/build.go
index c55c768e..c2982dac 100644
--- a/internal/hostedimage/build.go
+++ b/internal/hostedimage/build.go
@@ -231,7 +231,7 @@ func scanPayload(m Manifest, made []entry) error {
if err != nil {
return err
}
- s := &scanner{d: d}
+ s := &scanner{d: d, goInput: m.GoToolchain + ".linux-amd64.tar.gz"}
for _, e := range made {
s.scanBytes(e.name, "", e.data)
}
@@ -292,6 +292,7 @@ type dockerData struct {
PathRunner, PathVMInit, PathBwrap, PathCodex, PathContainmentTest string
StateDir, ResultsDir, EtcSource, EtcParent, RunnerUser string
Cmd string
+ DropGoTestdata string
}
// VMInitArgs is the image's command: vm-init with every path and address
@@ -329,7 +330,7 @@ func renderDockerfile(m Manifest) ([]byte, error) {
}
d := dockerData{Manifest: m, PathRunner: PathRunner, PathVMInit: PathVMInit, PathBwrap: PathBwrap, PathCodex: PathCodex,
PathContainmentTest: PathContainmentTest, StateDir: StateDir, ResultsDir: ResultsDir, EtcSource: EtcSource,
- EtcParent: path.Dir(EtcSource), RunnerUser: RunnerUser, Cmd: string(cmd)}
+ EtcParent: path.Dir(EtcSource), RunnerUser: RunnerUser, Cmd: string(cmd), DropGoTestdata: DropGoTestdata("/usr/local/go/src")}
for _, f := range m.files() {
d.Sums = append(d.Sums, f.sha+" "+strings.TrimPrefix(f.entry, "files/"))
if f.dest != "" && f.dest != "/usr/local/go" {
diff --git a/internal/hostedimage/nested.go b/internal/hostedimage/nested.go
index a2c3aaaf..e2376a52 100644
--- a/internal/hostedimage/nested.go
+++ b/internal/hostedimage/nested.go
@@ -9,6 +9,7 @@ import (
"errors"
"io"
"path"
+ "slices"
"strconv"
"strings"
@@ -40,6 +41,26 @@ type walk struct {
input string
expanded int64
stopped bool // the expansion limit was reached; nothing more is read
+ // dropped names the input's own members the image deletes before it
+ // is done (goTestdata for the Go toolchain): they are not in the
+ // image, so they are not read.
+ dropped func(name string) bool
+}
+
+// goTestdata reports whether name, a member of the Go toolchain tarball,
+// is or lies under a path named testdata in go/src. The Dockerfile deletes
+// exactly those right after unpacking the toolchain (DropGoTestdata).
+func goTestdata(name string) bool {
+ rest, ok := strings.CutPrefix(name, "go/src/")
+ return ok && slices.Contains(strings.Split(rest, "/"), "testdata")
+}
+
+// DropGoTestdata is the shell command that deletes every path named
+// testdata under src (the unpacked Go tree's source), hidden directories
+// included, and fails unless none is left: what goTestdata skips.
+func DropGoTestdata(src string) string {
+ return "bash -O globstar -O nullglob -O dotglob -c 'rm -rf " + src + "/**/testdata && set -- " + src +
+ "/**/testdata && test $# -eq 0'"
}
func join(member, name string) string {
@@ -75,6 +96,9 @@ func (w *walk) spend(member string, n int64) bool {
// tarball, an RPM.
func (s *scanner) scanInput(input string, b []byte) error {
w := &walk{s: s, input: input}
+ if input != "" && input == s.goInput {
+ w.dropped = goTestdata
+ }
switch {
case strings.HasSuffix(input, ".tar.gz"):
if sniff(b) != kindGzip {
@@ -274,6 +298,9 @@ func (w *walk) tar(member, sum string, b []byte, level int) {
w.finding(join(member, h.Name), sum, "member-leaves-archive")
continue
}
+ if member == "" && w.dropped != nil && w.dropped(name) {
+ continue
+ }
if h.Typeflag != tar.TypeReg {
w.s.scanName(w.input, join(member, name), "")
continue
diff --git a/internal/hostedimage/scan.go b/internal/hostedimage/scan.go
index 5e955968..596dc37d 100644
--- a/internal/hostedimage/scan.go
+++ b/internal/hostedimage/scan.go
@@ -192,9 +192,11 @@ func fragmentPath(input, member string) string {
return input + "/" + member
}
-// scanner collects findings over the inputs.
+// scanner collects findings over the inputs. goInput is the Go
+// toolchain's input name, whose go/src testdata the image deletes.
type scanner struct {
d *detect.Detector
+ goInput string
findings []Finding
}
diff --git a/internal/hostedimage/scan_test.go b/internal/hostedimage/scan_test.go
index e22c93cd..87c0c905 100644
--- a/internal/hostedimage/scan_test.go
+++ b/internal/hostedimage/scan_test.go
@@ -6,6 +6,7 @@ import (
"compress/gzip"
"errors"
"os"
+ "os/exec"
"path/filepath"
"regexp"
"slices"
@@ -104,14 +105,14 @@ func TestScanAllowExact(t *testing.T) {
key := []byte(hostedimagetest.PrivateKey)
plant := func(t *testing.T, m *Manifest) {
setInput(t, m, m.GoToolchain+".linux-amd64.tar.gz", hostedimagetest.TarGz(map[string][]byte{
- "go/bin/go": []byte("fake go\n"), "go/src/crypto/tls/testdata/example-key.pem": key}))
+ "go/bin/go": []byte("fake go\n"), "go/src/crypto/x509/platform_root_key.pem": key}))
}
- allow := ScanAllowed{Input: "go1.26.11.linux-amd64.tar.gz", Member: "go/src/crypto/tls/testdata/example-key.pem",
- Rule: "private-key", SHA256: sum(key), Reason: "the Go tree's TLS test key"}
+ allow := ScanAllowed{Input: "go1.26.11.linux-amd64.tar.gz", Member: "go/src/crypto/x509/platform_root_key.pem",
+ Rule: "private-key", SHA256: sum(key), Reason: "the Go tree's x509 test root 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"
+ named.Rule, named.Reason = "forbidden-path", "the Go tree's x509 test root key file"
m := fixture(t)
plant(t, &m)
@@ -142,8 +143,8 @@ func TestScanAllowExact(t *testing.T) {
// 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"}
+ member := "go/src/crypto/x509/platform_root_key.pem"
+ allow := ScanAllowed{Input: goInput, Member: member, Rule: "private-key", SHA256: sum(key), Reason: "the Go tree's x509 test root key"}
m := fixture(t)
plantGo(t, &m, map[string][]byte{member: key})
@@ -211,10 +212,11 @@ func TestScanAllowMatchDigest(t *testing.T) {
// 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
+// shape is the Go tree's archive/tar/testdata/writer-big.tar (which the
+// image deletes, so it is placed outside testdata here): 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"
+ const member = "go/misc/writer-big.tar"
hugeTar := func(mode int64) []byte {
var b bytes.Buffer
tw := tar.NewWriter(&b)
@@ -537,3 +539,67 @@ func TestRPMExpansionBudget(t *testing.T) {
t.Fatalf("an oversized file: findings %v, want over-limit at a and nothing read after it", fs)
}
}
+
+// TestScanSkipsGoTestdata: the image deletes every testdata directory of
+// the Go tree right after unpacking it (DropGoTestdata), so a key in one
+// is not in the image and no longer a finding. The same key anywhere the
+// image keeps it (go/src outside testdata, the Go tree outside go/src, a
+// name that only contains "testdata") is still refused.
+func TestScanSkipsGoTestdata(t *testing.T) {
+ key := []byte(hostedimagetest.PrivateKey)
+ m := fixture(t)
+ plantGo(t, &m, map[string][]byte{
+ "go/src/crypto/tls/testdata/example-key.pem": key,
+ "go/src/cmd/vendor/x/testdata/deep/key.txt": key,
+ "go/src/debug/elf/testdata/hello-world-core.gz": gz(key),
+ "go/src/archive/tar/testdata/writer-big.tar": []byte("not a tar"),
+ })
+ if _, err := Build(m, filepath.Join(t.TempDir(), "a.zip")); err != nil {
+ t.Fatalf("Build with keys only in go/src testdata = %v, want them dropped", err)
+ }
+ for _, where := range []string{"go/src/crypto/tls/key.txt", "go/lib/testdata/key.txt", "go/src/crypto/testdatax/key.txt", "go/misc/testdata/key.txt"} {
+ m := fixture(t)
+ plantGo(t, &m, map[string][]byte{"go/src/crypto/tls/testdata/example-key.pem": key, where: key})
+ fs := buildFindings(t, m)
+ if !hasFinding(fs, goInput+":"+where, "private-key") || slices.ContainsFunc(fs, func(f Finding) bool { return strings.Contains(f.Member, "/testdata/example-key.pem") }) {
+ t.Fatalf("%s: findings %v, want the key there refused and the testdata one dropped", where, fs)
+ }
+ }
+}
+
+// TestDropGoTestdata: the Dockerfile deletes the Go tree's testdata right
+// after unpacking it and before the go version check, and the command it
+// runs removes exactly what the scan skips (goTestdata): run here over a
+// tree with nested, hidden and look-alike names, the files left are the
+// ones the scan reads.
+func TestDropGoTestdata(t *testing.T) {
+ m := fixture(t)
+ text, err := renderDockerfile(m)
+ if err != nil {
+ t.Fatal(err)
+ }
+ s := string(text)
+ unpack := strings.Index(s, "tar -C /usr/local -xzf go.tar.gz;")
+ drop := strings.Index(s, DropGoTestdata("/usr/local/go/src")+";")
+ version := strings.Index(s, "/usr/local/go/bin/go version")
+ if unpack < 0 || drop < unpack || version < drop || strings.Count(s[unpack:drop], ";") != 1 {
+ t.Fatalf("the Dockerfile does not drop the Go tree's testdata right after unpacking it:\n%s", s)
+ }
+
+ root := t.TempDir()
+ files := []string{"go/src/a/b.go", "go/src/a/testdata/k.pem", "go/src/a/testdata/testdata/k", "go/src/x/y/testdata/z/k",
+ "go/src/testdata", "go/src/.hidden/testdata/k", "go/src/testdatax/k", "go/src/a/testdata.go", "go/lib/testdata/k", "go/bin/go"}
+ for _, f := range files {
+ write(t, filepath.Join(root, f), []byte("x"), 0o644)
+ }
+ cmd := exec.Command("sh", "-c", DropGoTestdata(filepath.Join(root, "go", "src")))
+ if out, err := cmd.CombinedOutput(); err != nil {
+ t.Fatalf("%s: %v %s", cmd, err, out)
+ }
+ for _, f := range files {
+ _, err := os.Stat(filepath.Join(root, f))
+ if kept := err == nil; kept == goTestdata(f) {
+ t.Errorf("%s: kept %v, but the scan skips it: %v", f, kept, goTestdata(f))
+ }
+ }
+}
diff --git a/internal/hostedimage/scanallow_test.go b/internal/hostedimage/scanallow_test.go
index 19eabb82..c197a3b8 100644
--- a/internal/hostedimage/scanallow_test.go
+++ b/internal/hostedimage/scanallow_test.go
@@ -53,6 +53,8 @@ func TestCheckedInScanAllow(t *testing.T) {
}
case a.Member == "" || a.SHA256 == "" || a.MatchSHA256 != "":
t.Errorf("allowance %+v for a pinned input: want a member and its digest", a)
+ case a.Input == m.GoToolchain+".linux-amd64.tar.gz" && goTestdata(strings.SplitN(a.Member, "!/", 2)[0]):
+ t.Errorf("allowance for %s: the image deletes the Go tree's testdata, so the scan never reads it", a.Member)
}
f := Finding{Input: a.Input, Member: a.Member, SHA256: a.SHA256, Rule: a.Rule, MatchSHA256: a.MatchSHA256}
if a.Input == "equipo-runner" {