release: held recovery refuses a retained rootfs image for a binary row
Fix round 1 (Astra P1-5, census reject on stageHeld). The held stage serves binary rows only: its stage check names no runtime, so stageFrom refuses a rootfs release before any download. The recovery this branch added for a digestless held build with no promotion record returned retainedOrRefused's manifest straight to the caller, past that rule, and RetainedStaged accepts a rootfs image. So a box holding a retained rootfs image for the version, a digestless pointer naming it and a missing record handed a binary held row the image as staged. The recovered manifest now goes through runtimeMatches(m, "") before stageHeld returns it, the rule stageFrom applies, and is refused otherwise; nothing is published. Test: TestHunt_H3_M1_HeldRecoveryRefusesARetainedRootfsImageForABinaryRow (MaterializeHeld and StageHeldVerified). It failed before (the rootfs manifest came back with no error) and passes now.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+59
−1
internal/release/hunt_H3-M1_held_test.go+46 −0internal/release/materializeheld.go+13 −1
diff --git a/internal/release/hunt_H3-M1_held_test.go b/internal/release/hunt_H3-M1_held_test.go| index e17222fc5..a0d7a1c2e 100644 |
| --- a/internal/release/hunt_H3-M1_held_test.go |
| +++ b/internal/release/hunt_H3-M1_held_test.go |
| @@ -3,6 +3,9 @@ package release |
| import ( |
| "bytes" |
| "context" |
| + "crypto/sha256" |
| + "encoding/hex" |
| + "encoding/json" |
| "errors" |
| "os" |
| "path/filepath" |
| @@ -185,3 +188,46 @@ func heldDownloadedNothingOf(t *testing.T, rec *heldRecordingStore, version stri |
| } |
| } |
| } |
| + |
| +// Astra P1-5: the held stage serves binary rows only (its stage check names |
| +// no runtime), and stageFrom refuses a rootfs release for one. The record |
| +// path's recovery returned this box's retained copy straight to the caller, |
| +// past that check: with a retained rootfs image for the version, a |
| +// digestless pointer naming it and no promotion record, a binary held row |
| +// was handed the image as staged. It must be refused, and nothing published. |
| +func TestHunt_H3_M1_HeldRecoveryRefusesARetainedRootfsImageForABinaryRow(t *testing.T) { |
| + onArm64(t) |
| + for name, entry := range huntHeldEntries { |
| + t.Run(name, func(t *testing.T) { |
| + ctx, s, pub, rat, opt, rt := huntHeldBox(t) |
| + image := []byte("a retained rootfs image") |
| + sum := sha256.Sum256(image) |
| + m := &Manifest{Schema: 1, App: "km", Version: "v1", Kind: KindRootfs, |
| + Artifacts: map[string]Artifact{RootfsArtifactKey: {File: "rootfs.squashfs", SHA256: hex.EncodeToString(sum[:]), Size: int64(len(image))}}, |
| + Processes: map[string]Process{ProcessWeb: {Command: []string{"/app/serve"}}}} |
| + raw, err := json.Marshal(m) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := StageArtifact(opt, "bab", "v1", "km", image); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := StageManifest(opt, "bab", "v1", "km", raw); err != nil { |
| + t.Fatal(err) |
| + } |
| + if id, got := RetainedStaged(opt, "bab", "km", "v1"); id == nil || got == nil || !got.IsRootfs() { |
| + t.Fatal("setup: the rootfs image is not a retained copy") |
| + } |
| + huntDropRecord(t, ctx, s) |
| + var out bytes.Buffer |
| + var staged *Manifest |
| + withCapturedStdout(t, &out, func() { |
| + staged, err = entry(ctx, s, pub, rat, opt, rt, offGate(t)) |
| + }) |
| + if err == nil || !errors.Is(err, errRuntimeMismatch) { |
| + t.Fatalf("a binary held row recovered a rootfs image: manifest %+v, err %v\n%s", staged, err, out.String()) |
| + } |
| + gone(t, LiveLink(opt, rt.Host)) |
| + }) |
| + } |
| +} |
diff --git a/internal/release/materializeheld.go b/internal/release/materializeheld.go| index a2ece0fce..7a9063494 100644 |
| --- a/internal/release/materializeheld.go |
| +++ b/internal/release/materializeheld.go |
| @@ -426,7 +426,19 @@ func stageHeld(ctx context.Context, s Store, pub ed25519.PublicKey, r *DigestRat |
| if want == "" { |
| var refused error |
| if want, refused = recordBinding(ctx, s, pub, RouteAccount(rt), rt.App, version); refused != nil { |
| - return retainedOrRefused(optDir, RouteAccount(rt), rt.App, version, rt.Host, want, refused) |
| + m, err := retainedOrRefused(optDir, RouteAccount(rt), rt.App, version, rt.Host, want, refused) |
| + if err != nil { |
| + return nil, err |
| + } |
| + // The held stage serves binary rows only: its stage check names |
| + // no runtime, so stageFrom refuses a rootfs release before any |
| + // download. A recovered copy never passed stageFrom, so the same |
| + // rule is applied to it here (Astra P1-5): a retained rootfs |
| + // image is not a binary row's build. |
| + if err := runtimeMatches(m, ""); err != nil { |
| + return nil, fmt.Errorf("%s/%s: %w; not recovered from this box's staged copy", rt.App, version, err) |
| + } |
| + return m, nil |
| } |
| } |
| var m *Manifest |