oficina / equipo Public

hosted: refuse hardlinks in the Go archive the image prunes

Review img-r1 (2): the scan skips go/src testdata because the image
deletes it, but a hardlink at a kept name would keep a testdata file's
bytes in the image unscanned. The Go toolchain archive may now hold no
hardlink at all (a structural finding, rule hardlink); the pinned
go1.26.11 tarball has none. TestScanRefusesGoHardlinks: a secret at
go/src/x/testdata/value.txt linked from go/src/x/value.txt is refused.
Both new tests join make hosted-image-check, and the progress record
lists the fixes' mutation checks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 3193a57fe69e50712e7b30dd394a30ae66fe3666 parent b0b5cd4
5 files changed, +50 −4
  • Makefile +1 −1
  • docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md +13 −0
  • internal/hostedimage/nested.go +11 −2
  • internal/hostedimage/scan.go +1 −1
  • internal/hostedimage/scan_test.go +24 −0

CI cancelled — superseded by a newer push — 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: image pulled in 9.7s
ci-box: claude: fetched and verified in 13.4s
ci-box: codex: fetched and verified in 4.5s
ci-box: codex-code-mode-host: fetched and verified in 1.5s
ci-box: libwrap: fetched and verified in 0.3s
ci-box: socat: fetched and verified in 0.3s
ci-box: tofu: fetched and verified in 1.7s
npm warn deprecated node-domexception@1.0.0: Use your platform's native DOMException instead
ci-box: pi: installed and verified in 7.1s
ci-box: opencode: installed and verified in 2.2s
ci-box: chromium 156.0.8078.79-1~deb13u1: 76 packages fetched, verified and unpacked in 8.5s

amadan: job cancelled — a newer push superseded it
diff --git a/Makefile b/Makefile
index 93996a56..418f79de 100644
--- a/Makefile
+++ b/Makefile
@@ -241,7 +241,7 @@ gitleaks:
# .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|TestScanAllowBindsRule|TestScanAllowMatchDigest|TestScanOverLimitBoundToContainer|TestCheckedInScanAllow|TestScanSkipsGoTestdata|TestDropGoTestdata|TestPinsCarryContainmentSuiteTools|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|TestScanSkipsGoTestdata|TestDropGoTestdata|TestPinsCarryContainmentSuiteTools|TestScanRefusesGoHardlinks|TestBuildHostedBwrapPinsItsClosure|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/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
index 65da49e8..a0d15b20 100644
--- a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
+++ b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
@@ -3243,3 +3243,16 @@ Mutation checks (each restored from a copy; tests pass again):
- Dockerfile.tmpl without the `{{.DropGoTestdata}}` line: `-run '^TestDropGoTestdata$'` FAILED at scan_test.go:586 "the Dockerfile does not drop the Go tree's testdata right after unpacking it".
- a checked-in allowance moved under go/src/x/testdata: `-run '^TestCheckedInScanAllow$'` FAILED at scanallow_test.go:57 "the image deletes the Go tree's testdata, so the scan never reads it".
- pins.json without python3-libs (renamed pythonX-libs): `-run '^TestPinsCarryContainmentSuiteTools$'` FAILED at assemble_test.go:344 "pins.json carries no python3-libs-3.* package".
+
+### Review img-r1 fixes
+
+- build-hosted-bwrap.sh pins the build's whole RPM closure: 48 RPMs (gcc, binutils, glibc-devel, libcap-devel, meson, ninja-build, tar, xz and their dependencies over the pinned container, no weak dependencies), each by its repository pkgId from release 2023.12.20261102 (repoguid 0d08b707..., the image packages' release and the container's own). The host fetches each from its content-addressed URL and checks its SHA-256; in the container, with --network=none, SHA256SUMS is checked again, Amazon Linux 2023's key (d832c631) imported, `rpm -K` must report "digests signatures OK" for each, and `rpm --install --define '_pkgverify_level all'` installs them. No dnf. Two builds, identical, still 1ebd5a3d... (the pin is unchanged), build-root digest unchanged.
+- The Go archive scan refuses any hardlink (rule hardlink): the image deletes testdata, so a link from a kept name to a testdata file would carry unscanned bytes. The pinned go1.26.11 tarball holds 15048 regular files and 1667 directories and no link of any kind.
+
+Mutation checks (restored from a copy; tests pass again):
+
+- `--network=none` removed from the build's podman run: `go test ./internal/hostedimage -run '^TestBuildHostedBwrapPinsItsClosure$' -count=1` FAILED at bwrapbuild_test.go:68 "reaches the network".
+- the pinned install replaced by `dnf -y install ...`: same test FAILED at bwrapbuild_test.go:56 (no `_pkgverify_level all`) and :72 "a package manager resolves packages during the build".
+- an RPMS entry without its digest form: same test FAILED at bwrapbuild_test.go:41 "is not NAME.rpm and its SHA-256".
+- cpp's pinned digest changed by one digit: `scripts/build-hosted-bwrap.sh` stopped before any container ran ("downloading cpp-11.5.0-5.amzn2023.0.5.x86_64.rpm failed": the content-addressed URL serves nothing else).
+- the hardlink refusal removed: `-run '^TestScanRefusesGoHardlinks$'` FAILED at scan_test.go:626 "Build = <nil>, want a payload scan refusal".
diff --git a/internal/hostedimage/nested.go b/internal/hostedimage/nested.go
index e2376a52..dffe4438 100644
--- a/internal/hostedimage/nested.go
+++ b/internal/hostedimage/nested.go
@@ -298,8 +298,17 @@ 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 member == "" && w.dropped != nil {
+ // The image deletes the dropped members, but a hardlink would
+ // keep a dropped file's bytes under a kept name, so an input
+ // with dropped members may hold no hardlink at all.
+ if h.Typeflag == tar.TypeLink {
+ w.finding(name, sum, "hardlink")
+ continue
+ }
+ if w.dropped(name) {
+ continue
+ }
}
if h.Typeflag != tar.TypeReg {
w.s.scanName(w.input, join(member, name), "")
diff --git a/internal/hostedimage/scan.go b/internal/hostedimage/scan.go
index 596dc37d..817cf151 100644
--- a/internal/hostedimage/scan.go
+++ b/internal/hostedimage/scan.go
@@ -89,7 +89,7 @@ func (f Finding) String() string {
// 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"}
+ "unsupported-container", "member-leaves-archive", "hardlink"}
// scanChunk and scanOverlap split large members for gitleaks: each chunk
// overlaps the next, so a secret across a boundary is still seen whole.
diff --git a/internal/hostedimage/scan_test.go b/internal/hostedimage/scan_test.go
index 87c0c905..d8416f68 100644
--- a/internal/hostedimage/scan_test.go
+++ b/internal/hostedimage/scan_test.go
@@ -603,3 +603,27 @@ func TestDropGoTestdata(t *testing.T) {
}
}
}
+
+// TestScanRefusesGoHardlinks (review img-r1): the scan skips the Go
+// tree's testdata because the image deletes it, but a hardlink elsewhere
+// would keep a testdata file's bytes in the image under another name, so
+// the Go toolchain may hold no hardlink at all. A secret at
+// go/src/x/testdata/value.txt linked from go/src/x/value.txt is refused.
+func TestScanRefusesGoHardlinks(t *testing.T) {
+ secret := []byte(hostedimagetest.PrivateKey)
+ var b bytes.Buffer
+ gw := gzip.NewWriter(&b)
+ tw := tar.NewWriter(gw)
+ _ = tw.WriteHeader(&tar.Header{Name: "go/bin/go", Typeflag: tar.TypeReg, Mode: 0o755, Size: 8})
+ _, _ = tw.Write([]byte("fake go\n"))
+ _ = tw.WriteHeader(&tar.Header{Name: "go/src/x/testdata/value.txt", Typeflag: tar.TypeReg, Mode: 0o644, Size: int64(len(secret))})
+ _, _ = tw.Write(secret)
+ _ = tw.WriteHeader(&tar.Header{Name: "go/src/x/value.txt", Typeflag: tar.TypeLink, Linkname: "go/src/x/testdata/value.txt"})
+ _ = tw.Close()
+ _ = gw.Close()
+ m := fixture(t)
+ setInput(t, &m, goInput, b.Bytes())
+ if fs := buildFindings(t, m); !hasFinding(fs, goInput+":go/src/x/value.txt", "hardlink") {
+ t.Fatalf("findings %v, want the hardlink to testdata refused", fs)
+ }
+}